From dee96fc5d71b46a92bb214870b15aba5254ddd2f Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 2 Dec 2020 07:28:34 +0100 Subject: [PATCH] Always respect synthetic namespaces in namespace reexports --- src/Module.ts | 30 +++++++++---------- .../reexport-from-synthetic/_config.js | 14 +++++++++ .../samples/reexport-from-synthetic/main.js | 2 ++ .../reexport-from-synthetic/reexport.js | 1 + .../reexport-from-synthetic/synthetic.js | 1 + 5 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 test/function/samples/reexport-from-synthetic/_config.js create mode 100644 test/function/samples/reexport-from-synthetic/main.js create mode 100644 test/function/samples/reexport-from-synthetic/reexport.js create mode 100644 test/function/samples/reexport-from-synthetic/synthetic.js diff --git a/src/Module.ts b/src/Module.ts index 8510b24920d..ea2c09dd3df 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -539,24 +539,24 @@ export default class Module { } } - // we don't want to create shims when we are just - // probing export * modules for exports - if (!isExportAllSearch) { - if (this.info.syntheticNamedExports) { - let syntheticExport = this.syntheticExports.get(name); - if (!syntheticExport) { - const syntheticNamespace = this.getSyntheticNamespace(); - syntheticExport = new SyntheticNamedExportVariable( - this.astContext, - name, - syntheticNamespace - ); - this.syntheticExports.set(name, syntheticExport); - return syntheticExport; - } + if (this.info.syntheticNamedExports) { + let syntheticExport = this.syntheticExports.get(name); + if (!syntheticExport) { + const syntheticNamespace = this.getSyntheticNamespace(); + syntheticExport = new SyntheticNamedExportVariable( + this.astContext, + name, + syntheticNamespace + ); + this.syntheticExports.set(name, syntheticExport); return syntheticExport; } + return syntheticExport; + } + // we don't want to create shims when we are just + // probing export * modules for exports + if (!isExportAllSearch) { if (this.options.shimMissingExports) { this.shimMissingExport(name); return this.exportShimVariable; diff --git a/test/function/samples/reexport-from-synthetic/_config.js b/test/function/samples/reexport-from-synthetic/_config.js new file mode 100644 index 00000000000..18cfd06f36a --- /dev/null +++ b/test/function/samples/reexport-from-synthetic/_config.js @@ -0,0 +1,14 @@ +module.exports = { + description: 'handles reexporting a synthetic namespace from a non-synthetic module', + options: { + plugins: [ + { + transform(code, id) { + if (id.endsWith('synthetic.js')) { + return { syntheticNamedExports: '__synth' }; + } + } + } + ] + } +}; diff --git a/test/function/samples/reexport-from-synthetic/main.js b/test/function/samples/reexport-from-synthetic/main.js new file mode 100644 index 00000000000..203a76d25f4 --- /dev/null +++ b/test/function/samples/reexport-from-synthetic/main.js @@ -0,0 +1,2 @@ +import { q } from './reexport.js'; +assert.equal(q, 42); diff --git a/test/function/samples/reexport-from-synthetic/reexport.js b/test/function/samples/reexport-from-synthetic/reexport.js new file mode 100644 index 00000000000..18f74a64559 --- /dev/null +++ b/test/function/samples/reexport-from-synthetic/reexport.js @@ -0,0 +1 @@ +export * from './synthetic.js'; diff --git a/test/function/samples/reexport-from-synthetic/synthetic.js b/test/function/samples/reexport-from-synthetic/synthetic.js new file mode 100644 index 00000000000..e5407b28f96 --- /dev/null +++ b/test/function/samples/reexport-from-synthetic/synthetic.js @@ -0,0 +1 @@ +export const __synth = { q: 42 };