Skip to content

Commit

Permalink
Always respect synthetic namespaces in namespace reexports
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 19, 2021
1 parent 5d33573 commit c43556b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/Module.ts
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions 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' };
}
}
}
]
}
};
2 changes: 2 additions & 0 deletions test/function/samples/reexport-from-synthetic/main.js
@@ -0,0 +1,2 @@
import { q } from './reexport.js';
assert.equal(q, 42);
1 change: 1 addition & 0 deletions test/function/samples/reexport-from-synthetic/reexport.js
@@ -0,0 +1 @@
export * from './synthetic.js';
1 change: 1 addition & 0 deletions test/function/samples/reexport-from-synthetic/synthetic.js
@@ -0,0 +1 @@
export const __synth = { q: 42 };

0 comments on commit c43556b

Please sign in to comment.