About Boundaries for Transpiling import.meta
#10989
magic-akari
started this conversation in
General
Replies: 1 comment 3 replies
-
|
I think we should not support destructuring now. It may be worth supporting if we have a general way to transform everything with a single code, but we don't have a such way at the moment |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In SWC's current implementation, we transpile certain
import.metasyntax likeimport.meta.url, including similar forms such asimport.meta.dirnameandimport.meta.resolve.However, this doesn't cover all cases. Consider
import.meta?.url:{ url: some_expr }?.urlwould be redundant—it always simplifies tosome_expr.import.meta?.urlis indeed always equivalent toimport.meta.url. This is becauseimport.metais guaranteed to be a non-null ObjectNote
"Object" in the ECMAScript spec excludes
null; reference:Related issues:
import.metaresults inimport.metanot getting transformed despitepreserveImportMeta: false#10988import.meta#10985Rollup's playground appears to handle both identically—as if
import.meta?.urlgets evaluated toimport.meta.urlduring transpilation. Should we adopt similar simplification?The boundary cases extend further:
Destructuring:
Could this be transpiled to:
Should we support this?
Destructuring in For-Loop:
Transpilation becomes increasingly challenging here.
Reference Passing & Runtime Checks:
Cases where correctness is unattainable:
For this direct references to
import.metaitself (rather than its properties), I recommend leaving the syntax untranspiled (as-is) for the runtime to handle. Rollup's transpilation of similar cases has proven error-prone.Core Question: Where should we draw the line for
import.metatranspilation?Beta Was this translation helpful? Give feedback.
All reactions