Skip to content
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

Handle shimming missing exports when preserving modules #4971

Merged
merged 1 commit into from May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);