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
7 changes: 0 additions & 7 deletions src/__tests__/property/known.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@
// tracks it and matches only the failures it explains, so anything new still
// fails the run. Remove an entry when its fix lands; a stale entry is harmless
// but hides nothing either, since it no longer matches.
const PR = "https://github.com/postcss/postcss-selector-parser/pull/";
const ISSUE = "https://github.com/postcss/postcss-selector-parser/issues/";

export const KNOWN = [
{
property: "sourceIndex points at the node",
tracking: `${PR}359`,
note: "a namespaced tag or universal starts at its name instead of its namespace",
match: (f) => (f.type === "tag" || f.type === "universal") && f.text.includes("|"),
},
{
property: "sourceIndex points at the node",
tracking: `${ISSUE}357`,
Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/sourceIndex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,33 @@ test("pseudo with arguments spanning multiple lines", "h1:not(\n\t.one,\n\t.two\
t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].source.end.column, 5, ".two end column");
t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].sourceIndex, 16, ".two sourceIndex");
});

test("namespaced tag starts at its namespace", "a ns|b", (t, tree) => {
const node = tree.nodes[0].nodes[2];
t.deepEqual(node.sourceIndex, 2);
t.deepEqual(node.source.start.column, 3);
t.deepEqual(node.source.end.column, 6);
});

test("namespaced universal starts at its namespace", "*|*", (t, tree) => {
const node = tree.nodes[0].nodes[0];
t.deepEqual(node.sourceIndex, 0);
t.deepEqual(node.source.start.column, 1);
t.deepEqual(node.source.end.column, 3);
});

test("tag with an empty namespace starts at the pipe", "|b.c", (t, tree) => {
const [tag, cls] = tree.nodes[0].nodes;
t.deepEqual(tag.sourceIndex, 0);
t.deepEqual(tag.source.start.column, 1);
t.deepEqual(tag.source.end.column, 2);
t.deepEqual(cls.sourceIndex, 2);
t.deepEqual(cls.source.start.column, 3);
});

test("namespaced tag on a later line starts at its namespace", "a,\n ns|b", (t, tree) => {
const node = tree.nodes[1].nodes[0];
t.deepEqual(node.sourceIndex, 5);
t.deepEqual(node.source.start.line, 2);
t.deepEqual(node.source.start.column, 3);
});
27 changes: 19 additions & 8 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,15 +889,26 @@ export default class Parser {
// `currToken`, which is the pipe itself and always present here.
return this.unexpectedPipe();
}
if (this.nextToken[TOKEN.TYPE] === tokens.word) {
this.position++;
return this.word(before);
} else if (this.nextToken[TOKEN.TYPE] === tokens.asterisk) {
this.position++;
return this.universal(before);
const type = this.nextToken[TOKEN.TYPE];
if (type !== tokens.word && type !== tokens.asterisk) {
return this.unexpectedPipe();
}
// The node starts at its prefix, or at the `|` when there is none, but
// `word()` and `universal()` only see the name after the `|`.
const start = before === true ? this.currToken : prev;
const nodes = this.current.nodes;
const index = nodes.length;
this.position++;
if (type === tokens.word) {
this.word(before);
} else {
this.universal(before);
}
const node = nodes[index];
if (node) {
node.sourceIndex = start[TOKEN.START_POS];
node.source.start = { line: start[TOKEN.START_LINE], column: start[TOKEN.START_COL] };
}

this.unexpectedPipe();
}

nesting() {
Expand Down
Loading