Skip to content

Commit

Permalink
fix: legacy octal escape is not permitted in strict mode (#1736)
Browse files Browse the repository at this point in the history
* fix: legacy octal escape is not permitted in strict mode

* fix: e2e inline css
  • Loading branch information
xusd320 authored Dec 27, 2024
1 parent 3dd6d9d commit 7757bfe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
15 changes: 14 additions & 1 deletion crates/mako/src/ast/js_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ impl JsAst {
// handle ast errors
let mut ast_errors = parser.take_errors();
// ignore with syntax error in strict mode
ast_errors.retain_mut(|error| !matches!(error.kind(), SyntaxError::WithInStrict));
ast_errors.retain(|error| {
!matches!(
error.kind(),
SyntaxError::WithInStrict | SyntaxError::LegacyOctal
)
});
if ast.is_err() {
ast_errors.push(ast.clone().unwrap_err());
}
Expand Down Expand Up @@ -271,6 +276,14 @@ class Bar {}
"#);
}

#[test]
fn test_legacy_octal() {
// no panic
run(r#"
console.log("\002F");
"#);
}

fn run(js_code: &str) -> String {
let mut test_utils = TestUtils::gen_js_ast(js_code);
let code = test_utils.js_ast_to_code();
Expand Down
7 changes: 3 additions & 4 deletions crates/mako/src/build/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ impl Parse {
r#"
import {{ moduleToDom }} from 'virtual:inline_css:runtime';
{}
moduleToDom(`
{}
`);
moduleToDom({});
"#,
deps, code
deps,
serde_json::to_string(&code)?
),
..Default::default()
}));
Expand Down
2 changes: 1 addition & 1 deletion e2e/fixtures/config.inline_css/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ assert(
content.includes(`__mako_require__("src/b.css")`, `should support deps in css`),
);
assert(
content.includes(`@import "//c";`, `should keep remote imports`),
content.includes(`@import \\"\/\/c\\";`, `should keep remote imports`),
);
4 changes: 4 additions & 0 deletions e2e/fixtures/config.inline_css/src/a.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
.a {
color: red;
}

.a:before {
content: "\002F";
}

0 comments on commit 7757bfe

Please sign in to comment.