Repository navigation
JS: parse import attributes (with clause) in import and export statements - #138
Merged
Merged
Conversation
…ents
`import json from "./a.json" with { type: "json" }` failed with
"expected ( instead of { in with statement". Parse the WithClause after
the module specifier of import and export-from statements into a new
Attributes field (nil when there is no clause) and write it back in
String() and JS().
Fixes tdewolff/minify#786
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes tdewolff/minify#786
Import attributes (ES2025) fail to parse:
This parses the
WithClauseafter the module specifier ofimportandexport ... fromstatements:ImportAttribute{Key, Value};Keyis an identifier name or a string literal,Valuea string literalAttributes []ImportAttributefield onImportStmtandExportStmt; it is nil without a clause and an empty slice forwith {}, sowith {}is not lostString()andJS()write the clause backexport {a} with {...}(nofrom) is still an errorTests: five cases in
TestParse, six inTestParseErrorand three inTestJS, failing before the change.go test ./...passes.minify prints the statement field by field, so it needs a small change to write
Attributes; otherwise it would now output the import without its clause. I have that change ready on bardrop/minify@import-attributes (import x from"./a.json"with{type:"json"}, tests included, checked in node) and will open it once this is merged, or you can pick it up directly if that is easier.