From e4d054afe0196d5d4e0ca0a16d17142ba834752f Mon Sep 17 00:00:00 2001 From: xusd320 Date: Thu, 9 Oct 2025 12:09:33 +0800 Subject: [PATCH] fix: import with { type: json } and css module parse --- crates/mako/src/ast/css_ast.rs | 1 + crates/mako/src/ast/js_ast.rs | 3 +++ e2e/fixtures/css.css-modules/src/index.css | 4 ++++ e2e/fixtures/css.css-modules/src/index.tsx | 3 ++- e2e/fixtures/json/node_modules/data/foo.json | 3 +++ e2e/fixtures/json/node_modules/data/index.js | 2 ++ e2e/fixtures/json/src/index.tsx | 2 ++ 7 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 e2e/fixtures/json/node_modules/data/foo.json create mode 100644 e2e/fixtures/json/node_modules/data/index.js diff --git a/crates/mako/src/ast/css_ast.rs b/crates/mako/src/ast/css_ast.rs index 931ae6b99..7252c11aa 100644 --- a/crates/mako/src/ast/css_ast.rs +++ b/crates/mako/src/ast/css_ast.rs @@ -43,6 +43,7 @@ impl CssAst { let config = parser::parser::ParserConfig { css_modules, legacy_ie: true, + legacy_nesting: true, ..Default::default() }; diff --git a/crates/mako/src/ast/js_ast.rs b/crates/mako/src/ast/js_ast.rs index 551018cfe..7ef965294 100644 --- a/crates/mako/src/ast/js_ast.rs +++ b/crates/mako/src/ast/js_ast.rs @@ -61,6 +61,9 @@ impl JsAst { jsx, decorators: true, decorators_before_export: true, + // temporarily parse import xx.json with { type: "json" } + // e.g. https://github.com/zen-fs/core/blob/80d32c4807df4a0e887f5c33afae82fde8e62191/src/index.ts#L19 + import_attributes: true, ..Default::default() }) }; diff --git a/e2e/fixtures/css.css-modules/src/index.css b/e2e/fixtures/css.css-modules/src/index.css index 06fdb679d..d9cf5c1b9 100644 --- a/e2e/fixtures/css.css-modules/src/index.css +++ b/e2e/fixtures/css.css-modules/src/index.css @@ -1,3 +1,7 @@ .container { padding-top: 80px; + + h1 { + font-size: 18px; + } } diff --git a/e2e/fixtures/css.css-modules/src/index.tsx b/e2e/fixtures/css.css-modules/src/index.tsx index 9bbe1f77c..33da2c407 100644 --- a/e2e/fixtures/css.css-modules/src/index.tsx +++ b/e2e/fixtures/css.css-modules/src/index.tsx @@ -1,6 +1,7 @@ import styles from "./index.css"; console.log(styles); - +import pkg from "../mako.config.json" with { type: "json"}; +console.log(pkg); import('./a.css'); require('./b.css'); import "./c.css"; diff --git a/e2e/fixtures/json/node_modules/data/foo.json b/e2e/fixtures/json/node_modules/data/foo.json new file mode 100644 index 000000000..6c10d6d28 --- /dev/null +++ b/e2e/fixtures/json/node_modules/data/foo.json @@ -0,0 +1,3 @@ +{ + "value": "foo" +} diff --git a/e2e/fixtures/json/node_modules/data/index.js b/e2e/fixtures/json/node_modules/data/index.js new file mode 100644 index 000000000..26936128e --- /dev/null +++ b/e2e/fixtures/json/node_modules/data/index.js @@ -0,0 +1,2 @@ +import foo from "./foo.json" with { type: "json" }; +export { foo }; diff --git a/e2e/fixtures/json/src/index.tsx b/e2e/fixtures/json/src/index.tsx index b7fa2d28f..3c6315d5d 100644 --- a/e2e/fixtures/json/src/index.tsx +++ b/e2e/fixtures/json/src/index.tsx @@ -1,2 +1,4 @@ import json from "./example.json"; +import data from "data"; console.log(json); +console.log(data)