-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
improve dynamic reexporting #5452
Conversation
`__turbopack_export_namespace__` counts as dynamic use Proxy to correctly reexport non-enumerable or changing objects
The latest updates on your projects. Learn more about Vercel for Git ↗︎
10 Ignored Deployments
|
|
✅ This change can build |
Linux Benchmark for 53242ecClick to view benchmark
|
Linux Benchmark for 63badc6Click to view benchmark
|
Windows Benchmark for 63badc6
Click to view full benchmark
|
crates/turbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
Outdated
Show resolved
Hide resolved
crates/turbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
Outdated
Show resolved
Hide resolved
crates/turbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
Outdated
Show resolved
Hide resolved
crates/turbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
Outdated
Show resolved
Hide resolved
asserts.props.iter().any(|assert| { | ||
assert | ||
.as_prop() | ||
.and_then(|prop| prop.as_key_value()) | ||
.and_then(|kv| kv.key.as_ident()) | ||
.map_or(true, |ident| &*ident.sym != TURBOPACK_HELPER) | ||
.map_or(false, |ident| &*ident.sym == TURBOPACK_HELPER) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this broken before, or was it used some other way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was broken before
|| &*i.sym == "exports" | ||
|| &*i.sym == "__turbopack_export_value__" | ||
{ | ||
if &*i.sym == "module" || &*i.sym == "exports" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this only work if the ident is unresolved? e.g. will it false positive const module = {}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's broken in that case. It's only a difference between no exports and commonjs exports, and doesn't matter at runtime. It generates a bit less code for "no exports", but nevermind...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining this, so we know that this is broken but it doesn't actually matter?
Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
Linux Benchmark for b1a8180Click to view benchmark
|
@@ -99,15 +99,15 @@ function dynamicExport(module: Module, object: Record<string, any>) { | |||
) { | |||
return Reflect.get(target, prop); | |||
} | |||
for (const obj of reexportedObjects) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think you'd need this with reexportedObjects
being clearly set to a defined value above.
Linux Benchmark for 89ed02bClick to view benchmark
|
DetectedDynamicExportType::Namespace => EcmascriptExports::DynamicNamespace, | ||
DetectedDynamicExportType::Value => EcmascriptExports::Value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I think this unfortunately breaks my async module implementation 🙃
### Description This fixes some problems when `export * from "client component"`, as `"use client"` creates a non-enumerable Proxy object, so we need to really redirect property access. * `__turbopack_export_namespace__` counts as dynamic * use Proxy to correctly reexport non-enumerable or changing objects --------- Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
### Description This fixes some problems when `export * from "client component"`, as `"use client"` creates a non-enumerable Proxy object, so we need to really redirect property access. * `__turbopack_export_namespace__` counts as dynamic * use Proxy to correctly reexport non-enumerable or changing objects --------- Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
### Description This fixes some problems when `export * from "client component"`, as `"use client"` creates a non-enumerable Proxy object, so we need to really redirect property access. * `__turbopack_export_namespace__` counts as dynamic * use Proxy to correctly reexport non-enumerable or changing objects --------- Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
Description
This fixes some problems when
export * from "client component"
, as"use client"
creates a non-enumerable Proxy object, so we need to really redirect property access.__turbopack_export_namespace__
counts as dynamic