Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(css/parser): Add legacy_ie to the ParserConfig #7109

Merged
merged 9 commits into from Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 0 additions & 29 deletions .github/workflows/bench.yml
Expand Up @@ -11,35 +11,6 @@ env:
RUST_LOG: "off"

jobs:
binary-size:
name: Binary size
if: >-
${{ !contains(github.event.head_commit.message, 'chore: ') && github.repository_owner == 'swc-project' }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Cache
uses: actions/cache@v1
with:
path: |
./cache
~/.cargo/
target
key: cargo-release-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-release-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Build (release)
run: |
yarn
yarn build

- name: Print binary size
run: ls -al ./bindings/target/release/libbinding*

benchmark:
name: Performance regression check
if: >-
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_css_parser/src/parser/mod.rs
Expand Up @@ -47,6 +47,10 @@ pub struct ParserConfig {
/// Defaults to `false`.
#[serde(default)]
pub legacy_nesting: bool,

/// If this is `true`, the legacy syntax for IE will be parsed.
#[serde(default)]
pub legacy_ie: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_css_parser/src/parser/values_and_units/mod.rs
Expand Up @@ -1704,7 +1704,7 @@ where
let value = match self.try_parse(|p| p.parse_generic_value()) {
Some(v) => v,
None => {
if is_one_of!(self, ";", ":") {
if is_one_of!(self, ";", ":") || (self.config.legacy_ie && is!(self, "=")) {
let tok = self.input.bump().unwrap();

ComponentValue::PreservedToken(Box::new(tok))
Expand Down
17 changes: 15 additions & 2 deletions crates/swc_css_parser/tests/fixture.rs
Expand Up @@ -518,6 +518,7 @@ fn stylesheet_span_visualizer(input: PathBuf, config: Option<ParserConfig>) {
let config = match config {
Some(config) => config,
_ => ParserConfig {
legacy_ie: true,
..Default::default()
},
};
Expand Down Expand Up @@ -551,8 +552,20 @@ fn stylesheet_span_visualizer(input: PathBuf, config: Option<ParserConfig>) {

#[testing::fixture("tests/fixture/**/input.css")]
fn pass(input: PathBuf) {
stylesheet_test(input.clone(), Default::default());
stylesheet_test_tokens(input, Default::default());
stylesheet_test(
input.clone(),
ParserConfig {
legacy_ie: true,
..Default::default()
},
);
stylesheet_test_tokens(
input,
ParserConfig {
legacy_ie: true,
..Default::default()
},
);
}

#[testing::fixture("tests/line-comment/**/input.css")]
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_css_parser/tests/fixture/turbo/4092/input.css
@@ -0,0 +1,4 @@
.carousel .control-dots .dot.selected, .carousel .control-dots .dot:hover {
opacity: 1;
filter: alpha(opacity=100);
kdy1 marked this conversation as resolved.
Show resolved Hide resolved
}