Skip to content

Commit de367ca

Browse files
committed
refactor: Set empty namespace to null in attributes
They are equivalent as per CSS selector spec
1 parent 5cad07b commit de367ca

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/__fixtures__/tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ export const tests: [
895895
action: AttributeAction.Exists,
896896
name: "bar",
897897
type: SelectorType.Attribute,
898-
namespace: "",
898+
namespace: null,
899899
value: "",
900900
ignoreCase: IgnoreCaseMode.Unknown,
901901
},

src/parse.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,25 +297,26 @@ function parseSelector(
297297

298298
// Determine attribute name and namespace
299299

300+
let name: string;
300301
let namespace: string | null = null;
301302

302303
if (selector.charCodeAt(selectorIndex) === CharCode.Pipe) {
303-
namespace = "";
304-
selectorIndex += 1;
304+
// Equivalent to no namespace
305+
name = getName(1);
305306
} else if (selector.startsWith("*|", selectorIndex)) {
306307
namespace = "*";
307-
selectorIndex += 2;
308-
}
309-
310-
let name = getName(0);
308+
name = getName(2);
309+
} else {
310+
name = getName(0);
311311

312-
if (
313-
namespace === null &&
314-
selector.charCodeAt(selectorIndex) === CharCode.Pipe &&
315-
selector.charCodeAt(selectorIndex + 1) !== CharCode.Equal
316-
) {
317-
namespace = name;
318-
name = getName(1);
312+
if (
313+
selector.charCodeAt(selectorIndex) === CharCode.Pipe &&
314+
selector.charCodeAt(selectorIndex + 1) !==
315+
CharCode.Equal
316+
) {
317+
namespace = name;
318+
name = getName(1);
319+
}
319320
}
320321

321322
stripWhitespace(0);

0 commit comments

Comments
 (0)