Skip to content

JS: keep import attributes (with clause) of import and export statements, fixes #786 - #1084

Merged
tdewolff merged 2 commits into
tdewolff:masterfrom
bardrop-oss:import-attributes
Nov 12, 2026
Merged

tdewolff merged 2 commits into
tdewolff:masterfrom
bardrop-oss:import-attributes

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #786 (the minify half; the issue was auto-closed when tdewolff/parse#138 merged).

tdewolff/parse#138 added Attributes to ImportStmt and ExportStmt, so the parser now accepts with { type: "json" }. But the minifier does not write the clause back yet, so once the parse dependency is bumped the attributes are silently dropped:

input:  import x from "./a.json" with { type: "json" }
now:    import x from"./a.json"          (browsers refuse to load JSON without the type)
after:  import x from"./a.json"with{type:"json"}

Changes:

  • minifyImportAttributes writes with{key:"value",...} after the module specifier of import ... from, bare import "x", and export ... from. nil means no clause, so with {} is kept as with{}. String keys and values go through minifyString like the module name.
  • Second commit bumps github.com/tdewolff/parse/v2 to the current parse master (pseudo-version for 8a0e1cb). If you'd rather tag a parse release and bump it yourself, feel free to drop that commit.

Testing: five new TestJS cases (import with attributes, bare import with {}, string keys + trailing comma, export * and export {} from). All fail on master with the new parse version and pass with this change. go test ./... is green and gofmt -l js/ is clean. Output checked in node 24 (import x from"./a.json"with{type:"json"} loads).

@tdewolff
tdewolff merged commit ddd31cb into tdewolff:master Nov 12, 2026
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS minify fails on import attributes

2 participants