A CSS selector parser, integrates with postcss but does not require it.
MIT License
Bot releases are hidden (Show)
index
argument to each
/walk
callback types (#289)Published by alexander-akait 10 months ago
Published by alexander-akait 10 months ago
Published by alexander-akait over 1 year ago
Published by alexander-akait over 1 year ago
clone
arguments should be optionalPublished by alexander-akait almost 2 years ago
Published by alexander-akait over 2 years ago
isPseudoElement()
supports :first-letter
and :first-line
Published by alexander-akait almost 3 years ago
Combinator.raws
property typePublished by alexander-akait almost 3 years ago
Published by alexander-akait almost 3 years ago
Published by alexander-akait over 3 years ago
Published by alexander-akait over 3 years ago
Published by alexander-akait about 4 years ago
Published by alexander-akait about 4 years ago
Published by alexander-akait over 4 years ago
dot-prop
to 5.2.0
8
.Published by jonathantneal over 5 years ago
Published by jonathantneal over 5 years ago
Published by jonathantneal over 5 years ago
cssesc
to 3.0.0 (major)id
and class
selectorsPublished by jonathantneal almost 6 years ago
.a .b
) is stored in the AST has changed..a /for/ .b
) are now properly parsed as a combinator./
was encountered have been fixed.v6.0.0
.In prior releases, the value of a descendant combinator with multiple spaces included all the spaces.
.a .b
: Extra spaces are now stored as space before.
combinator.value === " "
combinator.value === " " && combinator.spaces.before === " "
.a /*comment*/.b
: A comment at the end of the combinator causes extra space to become after space.
combinator.value === " "
combinator.raws.value === " /*comment/"
combinator.value === " "
combinator.spaces.after === " "
combinator.raws.spaces.after === " /*comment*/"
.a<newline>.b
: whitespace that doesn't start or end with a single space character is stored as a raw value.
combinator.value === "\n"
combinator.raws.value === undefined
combinator.value === " "
combinator.raws.value === "\n"
Although, nonstandard and unlikely to ever become a standard, combinators like /deep/
and /for/
are now properly supported.
Because they've been taken off the standardization track, there is no spec-official name for combinators of the form /<ident>/
. However, I talked to Tab Atkins and we agreed to call them "named combinators" so now they are called that.
Before this release such named combinators were parsed without intention and generated three nodes of type "tag"
where the first and last nodes had a value of "/"
.
.a /for/ .b
is parsed as a combinator.
root.nodes[0].nodes[1].type === "tag"
root.nodes[0].nodes[1].value === "/"
root.nodes[0].nodes[1].type === "combinator"
root.nodes[0].nodes[1].value === "/for/"
.a /F\6fR/ .b
escapes are handled and uppercase is normalized.
root.nodes[0].nodes[2].type === "tag"
root.nodes[0].nodes[2].value === "F\\6fR"
root.nodes[0].nodes[1].type === "combinator"
root.nodes[0].nodes[1].value === "/for/"
root.nodes[0].nodes[1].raws.value === "/F\\6fR/"
A new API was added to look up a node based on the source location.
const selectorParser = require("postcss-selector-parser");
// You can find the most specific node for any given character
let combinator = selectorParser.astSync(".a > .b").atPosition(1,4);
combinator.toString() === " > ";
// You can check if a node includes a specific character
// Whitespace surrounding the node that is owned by that node
// is included in the check.
[2,3,4,5,6].map(column => combinator.isAtPosition(1, column));
// => [false, true, true, true, false]
This release has BREAKING CHANGES that were required to fix regressions
in 4.0.0 and to make the Combinator Node API consistent for all combinator
types. Please read carefully.
To ease adoption of the v5.0 release, we have relaxed the node version
check performed by npm at installation time to allow for node 4, which
remains officially unsupported, but likely to continue working for the
time being.
cssesc
to 2.0.0 (major).Published by jonathantneal almost 6 years ago
cssesc
to 2.0.0 (major).