Skip to content

Commit a8b7ea0

Browse files
committed
Update cssparser to the latest version, relax nesting rules and enable by default
Closes parcel-bundler#576
1 parent b645c7f commit a8b7ea0

29 files changed

+852
-803
lines changed

Cargo.lock

Lines changed: 15 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ substitute_variables = ["visitor", "into_owned"]
4646

4747
[dependencies]
4848
serde = { version = "1.0.123", features = ["derive"], optional = true }
49-
cssparser = "0.29.1"
49+
cssparser = "0.33.0"
50+
cssparser-color = "0.1.0"
5051
parcel_selectors = { version = "0.26.1", path = "./selectors" }
5152
itertools = "0.10.1"
5253
smallvec = { version = "1.7.0", features = ["union"] }

c/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ pub extern "C" fn lightningcss_stylesheet_parse(
256256
let code = unsafe { std::str::from_utf8_unchecked(slice) };
257257
let warnings = Arc::new(RwLock::new(Vec::new()));
258258
let mut flags = ParserFlags::empty();
259-
flags.set(ParserFlags::NESTING, options.nesting);
260259
flags.set(ParserFlags::CUSTOM_MEDIA, options.custom_media);
261260
let opts = ParserOptions {
262261
filename: if options.filename.is_null() {

examples/custom_at_rule.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ use lightningcss::{
88
properties::custom::{Token, TokenOrValue},
99
rules::{style::StyleRule, CssRule, CssRuleList, Location},
1010
selector::{Component, Selector},
11-
stylesheet::{ParserFlags, ParserOptions, PrinterOptions, StyleSheet},
11+
stylesheet::{ParserOptions, PrinterOptions, StyleSheet},
1212
targets::Browsers,
1313
traits::{AtRuleParser, ToCss},
14-
values::{color::CssColor, length::LengthValue},
14+
values::{
15+
color::{CssColor, RGBA},
16+
length::LengthValue,
17+
},
1518
vendor_prefix::VendorPrefix,
1619
visit_types,
1720
visitor::{Visit, VisitTypes, Visitor},
@@ -22,7 +25,6 @@ fn main() {
2225
let source = std::fs::read_to_string(&args[1]).unwrap();
2326
let opts = ParserOptions {
2427
filename: args[1].clone(),
25-
flags: ParserFlags::NESTING,
2628
..Default::default()
2729
};
2830

@@ -266,8 +268,8 @@ impl<'a, 'i> Visitor<'i, AtRule> for ApplyVisitor<'a, 'i> {
266268
match token {
267269
TokenOrValue::Function(f) if f.name == "theme" => match f.arguments.0.first() {
268270
Some(TokenOrValue::Token(Token::String(s))) => match s.as_ref() {
269-
"blue-500" => *token = TokenOrValue::Color(CssColor::RGBA(RGBA::new(0, 0, 255, 255))),
270-
"red-500" => *token = TokenOrValue::Color(CssColor::RGBA(RGBA::new(255, 0, 0, 255))),
271+
"blue-500" => *token = TokenOrValue::Color(CssColor::RGBA(RGBA::new(0, 0, 255, 1.0))),
272+
"red-500" => *token = TokenOrValue::Color(CssColor::RGBA(RGBA::new(255, 0, 0, 1.0))),
271273
_ => {}
272274
},
273275
_ => {}

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
serde = { version = "1.0.123", features = ["derive"] }
1313
serde_bytes = "0.11.5"
14-
cssparser = "0.29.1"
14+
cssparser = "0.33.0"
1515
lightningcss = { path = "../", features = ["nodejs", "serde", "visitor"] }
1616
parcel_sourcemap = { version = "2.1.1", features = ["json"] }
1717
serde-detach = "0.0.1"

node/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,6 @@ impl<'a> Into<PseudoClasses<'a>> for &'a OwnedPseudoClasses {
705705
#[derive(Serialize, Debug, Deserialize, Default)]
706706
#[serde(rename_all = "camelCase")]
707707
struct Drafts {
708-
#[serde(default)]
709-
nesting: bool,
710708
#[serde(default)]
711709
custom_media: bool,
712710
}
@@ -740,7 +738,6 @@ fn compile<'i>(
740738

741739
let res = {
742740
let mut flags = ParserFlags::empty();
743-
flags.set(ParserFlags::NESTING, matches!(drafts, Some(d) if d.nesting));
744741
flags.set(ParserFlags::CUSTOM_MEDIA, matches!(drafts, Some(d) if d.custom_media));
745742
flags.set(
746743
ParserFlags::DEEP_SELECTOR_COMBINATOR,
@@ -867,7 +864,6 @@ fn compile_bundle<
867864
let drafts = config.drafts.as_ref();
868865
let non_standard = config.non_standard.as_ref();
869866
let mut flags = ParserFlags::empty();
870-
flags.set(ParserFlags::NESTING, matches!(drafts, Some(d) if d.nesting));
871867
flags.set(ParserFlags::CUSTOM_MEDIA, matches!(drafts, Some(d) if d.custom_media));
872868
flags.set(
873869
ParserFlags::DEEP_SELECTOR_COMBINATOR,

node/test/customAtRules.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ test('mixin', () => {
8888
@apply color;
8989
}
9090
`),
91-
drafts: { nesting: true },
9291
targets: { chrome: 100 << 16 },
9392
customAtRules: {
9493
mixin: {
@@ -171,9 +170,6 @@ test('style block', () => {
171170
}
172171
}
173172
`),
174-
drafts: {
175-
nesting: true
176-
},
177173
targets: {
178174
chrome: 105 << 16
179175
},
@@ -217,9 +213,6 @@ test('style block top level', () => {
217213
}
218214
}
219215
`),
220-
drafts: {
221-
nesting: true
222-
},
223216
customAtRules: {
224217
test: {
225218
body: 'style-block'
@@ -289,7 +282,6 @@ test('bundler', () => {
289282
let res = bundle({
290283
filename: 'tests/testdata/apply.css',
291284
minify: true,
292-
drafts: { nesting: true },
293285
targets: { chrome: 100 << 16 },
294286
customAtRules: {
295287
mixin: {

node/test/transform.test.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ test('can enable features without targets', () => {
3030
filename: 'test.css',
3131
code: Buffer.from('.foo { .bar { color: red }}'),
3232
minify: true,
33-
drafts: {
34-
nesting: true
35-
},
3633
include: Features.Nesting
3734
});
3835

node/test/visitor.test.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,6 @@ test('apply', () => {
325325
let res = transform({
326326
filename: 'test.css',
327327
minify: true,
328-
drafts: {
329-
nesting: true
330-
},
331328
code: Buffer.from(`
332329
--toolbar-theme {
333330
color: white;

selectors/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jsonschema = ["serde", "schemars"]
2020

2121
[dependencies]
2222
bitflags = "2.2.1"
23-
cssparser = "0.29"
23+
cssparser = "0.33.0"
2424
fxhash = "0.2"
2525
log = "0.4"
2626
phf = "0.10"

0 commit comments

Comments
 (0)