diff --git a/src/Module.ts b/src/Module.ts index 8d539ad2c90..55cec222fe9 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -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) ); } diff --git a/test/function/samples/missing-export-preserve-modules/_config.js b/test/function/samples/missing-export-preserve-modules/_config.js new file mode 100644 index 00000000000..cd10b25726d --- /dev/null +++ b/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".' + } + ] +}); diff --git a/test/function/samples/missing-export-preserve-modules/foo.js b/test/function/samples/missing-export-preserve-modules/foo.js new file mode 100644 index 00000000000..3329a7d972f --- /dev/null +++ b/test/function/samples/missing-export-preserve-modules/foo.js @@ -0,0 +1 @@ +export const foo = 'foo'; diff --git a/test/function/samples/missing-export-preserve-modules/main.js b/test/function/samples/missing-export-preserve-modules/main.js new file mode 100644 index 00000000000..352d9782b70 --- /dev/null +++ b/test/function/samples/missing-export-preserve-modules/main.js @@ -0,0 +1,2 @@ +import { bar } from './foo'; +assert.strictEqual(bar, undefined);