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

Support string module name and export * as #1336

Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jan 27, 2023

In this PR we implement the support of ES2022 string module names and ES2020 export * as ns. These two features are highly related so it end up in a single PR.

Summary

  • AST changes: .quote is introduced to AST_SymbolImportForeign, AST_SymbolExportForeign and AST_SymbolExport. It will be " or ' if the module name is a string, otherwise it is undefined. I am not sure if we want to stick with the AST_Symbol prefix now that it can be a string, too. Anyway I will wait for more feedback before any drastic AST change
  • Added new parser method as_symbol_or_string to handle export * as "f-oo"
  • Added specific handling to differentiate between import { * as foo } and import { "*" as foo }

Limitation

The parser currently do not validate that module names should be a valid UTF16 string (no lone surrogate). It seems good to me since our parser is already a bit loose: cases like export { * as foo } from "x" will not throw.

Fixes #1137
Fixes #1231

@fabiosantoscode
Copy link
Collaborator

Excellent! I have no notes.

Not validating module names is fine, as you say. Terser doesn't validate a lot of things, because that's really not what it's built to do. It's garbage in, garbage out :)

I greatly appreciate this PR, thank you very much!

@fabiosantoscode fabiosantoscode merged commit c53b5bc into terser:master Jan 29, 2023
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.

Support ES2020 export * as ns from 'module' syntax import/export name can be string now (ES2022)
2 participants