Skip to content

Commit

Permalink
refactor: Set empty namespace to null in attributes
Browse files Browse the repository at this point in the history
They are equivalent as per CSS selector spec
  • Loading branch information
fb55 committed Dec 26, 2021
1 parent 5cad07b commit de367ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/__fixtures__/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ export const tests: [
action: AttributeAction.Exists,
name: "bar",
type: SelectorType.Attribute,
namespace: "",
namespace: null,
value: "",
ignoreCase: IgnoreCaseMode.Unknown,
},
Expand Down
27 changes: 14 additions & 13 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,26 @@ function parseSelector(

// Determine attribute name and namespace

let name: string;
let namespace: string | null = null;

if (selector.charCodeAt(selectorIndex) === CharCode.Pipe) {
namespace = "";
selectorIndex += 1;
// Equivalent to no namespace
name = getName(1);
} else if (selector.startsWith("*|", selectorIndex)) {
namespace = "*";
selectorIndex += 2;
}

let name = getName(0);
name = getName(2);
} else {
name = getName(0);

if (
namespace === null &&
selector.charCodeAt(selectorIndex) === CharCode.Pipe &&
selector.charCodeAt(selectorIndex + 1) !== CharCode.Equal
) {
namespace = name;
name = getName(1);
if (
selector.charCodeAt(selectorIndex) === CharCode.Pipe &&
selector.charCodeAt(selectorIndex + 1) !==
CharCode.Equal
) {
namespace = name;
name = getName(1);
}
}

stripWhitespace(0);
Expand Down

0 comments on commit de367ca

Please sign in to comment.