Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ describe("Parse", () => {

expect(() => parse("/*/")).toThrowError("Comment was not terminated");
});

it("should support legacy pseudo-elements with single colon", () => {
expect(parse(":before")).toEqual([
[{ name: "before", data: null, type: "pseudo-element" }],
]);
});
});
25 changes: 24 additions & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ const unpackPseudos = new Set([
"host-context",
]);

/**
* Pseudo elements defined in CSS Level 1 and CSS Level 2 can be written with
* a single colon; eg. :before will turn into ::before.
*
* @see {@link https://www.w3.org/TR/2018/WD-selectors-4-20181121/#pseudo-element-syntax}
*/
const pseudosToPseudoElements = new Set([
"before",
"after",
"first-line",
"first-letter",
]);

/**
* Checks whether a specific selector is a traversal.
* This is useful eg. in swapping the order of elements that
Expand Down Expand Up @@ -472,10 +485,20 @@ function parseSelector(
? readValueWithParenthesis()
: null,
});
continue;
break;
}

const name = getName(1).toLowerCase();

if (pseudosToPseudoElements.has(name)) {
tokens.push({
type: SelectorType.PseudoElement,
name,
data: null,
});
break;
}

let data: DataType = null;

if (
Expand Down