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.meta
syntax likeimport.meta.url
, including similar forms such asimport.meta.dirname
andimport.meta.resolve
.However, this doesn't cover all cases. Consider
import.meta?.url
:{ url: some_expr }?.url
would be redundant—it always simplifies tosome_expr
.import.meta?.url
is indeed always equivalent toimport.meta.url
. This is becauseimport.meta
is guaranteed to be a non-null ObjectNote
"Object" in the ECMAScript spec excludes
null
; reference:Related issues:
import.meta
results inimport.meta
not getting transformed despitepreserveImportMeta: false
#10988import.meta
#10985Rollup's playground appears to handle both identically—as if
import.meta?.url
gets evaluated toimport.meta.url
during 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.meta
itself (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.meta
transpilation?Beta Was this translation helpful? Give feedback.
All reactions