Skip to content

Commit

Permalink
Handle shimming missing exports when preserving modules (#4971)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 3, 2023
1 parent 5628d16 commit 14e9d2d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Module.ts
Expand Up @@ -747,7 +747,11 @@ export default class Module {
// Modules where this.ast is missing have been loaded via this.load and are
// not yet fully processed, hence they cannot be included.
return (
this.ast && (this.ast.included || this.namespace.included || this.importedFromNotTreeshaken)
this.ast &&
(this.ast.included ||
this.namespace.included ||
this.importedFromNotTreeshaken ||
this.exportShimVariable.included)
);
}

Expand Down
19 changes: 19 additions & 0 deletions test/function/samples/missing-export-preserve-modules/_config.js
@@ -0,0 +1,19 @@
const path = require('node:path');

module.exports = defineTest({
description: 'supports shimming missing exports when preserving modules',
options: {
shimMissingExports: true,
output: {
preserveModules: true
}
},
warnings: [
{
binding: 'bar',
code: 'SHIMMED_EXPORT',
exporter: path.join(__dirname, 'foo.js'),
message: 'Missing export "bar" has been shimmed in module "foo.js".'
}
]
});
@@ -0,0 +1 @@
export const foo = 'foo';
2 changes: 2 additions & 0 deletions test/function/samples/missing-export-preserve-modules/main.js
@@ -0,0 +1,2 @@
import { bar } from './foo';
assert.strictEqual(bar, undefined);

0 comments on commit 14e9d2d

Please sign in to comment.