You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1320792
Browse filesBrowse the repository at this point in the historyBrowse files
feat(parser): add specNamespaceObject for spec namespace objects (#22049)
* feat(parser): add specNamespaceObject for spec namespace objects
`import * as ns` hands out `__webpack_exports__`, a plain object carrying
`__esModule`, where the spec hands out a Module Namespace Exotic Object with
a null prototype, sorted keys and non-writable bindings. The new parser
option wraps it in a proxy that reports those, per module rather than per
build: a spec namespace keeps every exported name, so it blocks pruning and
costs runtime code that a normal build should not pay for.
The option is read from the module being imported, never the importer, so
every importer of one module is handed the same namespace object. A module
that opts in also stops being concatenated, since concatenation would
materialize the namespace inline and drop the exotic object silently.
Takes 35 test262 cases off the skip list.
* feat(parser): wrap a concatenated importer's namespace reference too
A concatenation root reads an external module through its own binding, so
the option was ignored exactly where production puts it. Wrapping that
binding covers every reference at once and the runtime caches per exports
object, so identity holds. Guarded on a namespace exportsType, since
wrapping an interop path would hide `__esModule` from it.
* fix(parser): return from the namespace callbacks, and key by the module
Two real defects a review caught. `expressionFunction` emits no `return`
when arrow functions are off, so with `output.environment.arrowFunction`
false the filter dropped every export name and the proxy read through to
the target: both callbacks now use `returningFunction`.
The materialized namespace is built per importer, so caching by it handed
two importers two proxies for one module; the cache now takes the module's
own exports object as its key. Mangling and the decoupled namespace object
are skipped for such a module besides, since a spec namespace has to report
the names the module actually exports.
* refactor(parser): drop the unreachable spec namespace materialization
`MangleExportsPlugin` never mangles a module that hands out a spec
namespace, so `_materializedNamespaceObject` always declines for one and
the branch wrapping its result could not run. Removing it leaves the
runtime helper keyed by the exports object alone.
A strict CommonJS `require` inside a concatenation reaches the imported
module through a lazy accessor rather than an eager binding; no case
drove that path, so add one.
* fix(parser): wrap a namespace re-exported as a named export
`export { ns }` emitted the raw exports object, so an importer reading it
was handed a different object than `import * as ns` gives, breaking the
single namespace per module that test262 instn-star-equality.js asks for.
The schema note saying named re-exports were not wrapped goes with it.
* feat(parser): drop the experimental marker from specNamespaceObject
Module Namespace Exotic Objects are ECMA-262 10.4.6 and have been stable
since ES2015, so the option implements a settled spec rather than a
proposal. The one caveat the marker stood for, a namespace re-exported as
a named export, is fixed.
* fix(parser): keep require() on the exports object inside a concatenation
Concatenation wrapped the shared external binding, so a CommonJS `require`
in the same group was handed the spec namespace and lost `__esModule`,
which a default-interop helper reads. The same sources built without
concatenation gave it the exports object, so the option's behaviour
depended on whether concatenation ran.
Wrap at the reference instead, where `moduleExportsAccess` already marks a
`require` apart from an import. Costs 3-5 gzip bytes on the cases that
concatenate.
* Enable experimental tc39 proposal https://github.com/tc39/proposal-source-phase-imports. This allows importing modules at source phase.
4860
4860
*/
4861
4861
sourceImport?: boolean;
4862
+
/**
4863
+
* Hand out a spec-compliant Module Namespace Exotic Object for 'import * as ns' and 'import()' of this module instead of the plain exports object. Requires 'Proxy' in the target environment, keeps every exported name, and costs runtime code, so enable it per module. Set it on the imported module, not on the importer.
4864
+
* @since 5.111.0
4865
+
*/
4866
+
specNamespaceObject?: boolean;
4862
4867
/**
4863
4868
* @deprecated
4864
4869
* Deprecated in favor of "exportsPresence". Emit errors instead of warnings when imported names don't exist in imported module.
* @property {boolean} deferred the module is deferred at least once
249
249
* @property {boolean} deferredNamespaceObjectUsed deferred namespace object that being used in a not-analyzable way so it must be materialized
250
250
* @property {string | undefined} deferredNamespaceObjectName deferred namespace object that being used in a not-analyzable way so it must be materialized
251
+
* @property {boolean} specNamespaceObjectUsed an import reads the spec namespace object the module hands out
0 commit comments