Skip to content

Commit 7e50ee2

Browse files
authored
feat: add noIncompleteNsImportDetection assumption to plugin-transform-modules-commonjs (#13290)
1 parent c35637e commit 7e50ee2

File tree

12 files changed

+64
-11
lines changed

12 files changed

+64
-11
lines changed

packages/babel-core/src/config/validation/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export const assumptionsNames = new Set<string>([
265265
"mutableTemplateObject",
266266
"noClassCalls",
267267
"noDocumentAll",
268+
"noIncompleteNsImportDetection",
268269
"noNewArrows",
269270
"objectRestNoSymbols",
270271
"privateFieldsAsProperties",

packages/babel-helper-create-class-features-plugin/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function createClassFeaturePlugin({
4646
feature,
4747
loose,
4848
manipulateOptions,
49-
// TODO(Babel 8): Remove the default falue
49+
// TODO(Babel 8): Remove the default value
5050
api = { assumption: () => void 0 },
5151
}: Options) {
5252
const setPublicClassFields = api.assumption("setPublicClassFields");

packages/babel-helper-module-transforms/src/index.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function rewriteModuleStatementsAndPrepareHeader(
4545

4646
constantReexports = loose,
4747
enumerableModuleMeta = loose,
48+
noIncompleteNsImportDetection,
4849
}: {
4950
exportName?;
5051
strict;
@@ -57,6 +58,7 @@ export function rewriteModuleStatementsAndPrepareHeader(
5758
esNamespaceOnly?;
5859
constantReexports?;
5960
enumerableModuleMeta?;
61+
noIncompleteNsImportDetection?: boolean;
6062
},
6163
) {
6264
validateImportInteropOption(importInterop);
@@ -102,7 +104,12 @@ export function rewriteModuleStatementsAndPrepareHeader(
102104

103105
// Create all of the statically known named exports.
104106
headers.push(
105-
...buildExportInitializationStatements(path, meta, constantReexports),
107+
...buildExportInitializationStatements(
108+
path,
109+
meta,
110+
constantReexports,
111+
noIncompleteNsImportDetection,
112+
),
106113
);
107114

108115
return { meta, headers };
@@ -388,6 +395,7 @@ function buildExportInitializationStatements(
388395
programPath: NodePath,
389396
metadata: ModuleMetadata,
390397
constantReexports: boolean = false,
398+
noIncompleteNsImportDetection = false,
391399
) {
392400
const initStatements = [];
393401

@@ -413,15 +421,17 @@ function buildExportInitializationStatements(
413421
}
414422
}
415423

416-
initStatements.push(
417-
...chunk(exportNames, 100).map(members => {
418-
return buildInitStatement(
419-
metadata,
420-
members,
421-
programPath.scope.buildUndefinedNode(),
422-
);
423-
}),
424-
);
424+
if (!noIncompleteNsImportDetection) {
425+
initStatements.push(
426+
...chunk(exportNames, 100).map(members => {
427+
return buildInitStatement(
428+
metadata,
429+
members,
430+
programPath.scope.buildUndefinedNode(),
431+
);
432+
}),
433+
);
434+
}
425435

426436
return initStatements;
427437
}

packages/babel-plugin-transform-modules-commonjs/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export default declare((api, options) => {
4040
api.assumption("constantReexports") ?? options.loose;
4141
const enumerableModuleMeta =
4242
api.assumption("enumerableModuleMeta") ?? options.loose;
43+
const noIncompleteNsImportDetection =
44+
api.assumption("noIncompleteNsImportDetection") ?? false;
4345

4446
if (
4547
typeof lazy !== "boolean" &&
@@ -186,6 +188,7 @@ export default declare((api, options) => {
186188
/\.mjs$/.test(state.filename)
187189
? mjsStrictNamespace
188190
: strictNamespace,
191+
noIncompleteNsImportDetection,
189192
},
190193
);
191194

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
var _default = foo;
7+
exports.default = _default;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { foo } from "foo";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"assumptions": {
3+
"noIncompleteNsImportDetection": true,
4+
"constantReexports": true
5+
},
6+
"plugins": ["transform-modules-commonjs"]
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _foo = require("foo");
8+
9+
exports.foo = _foo.foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var foo = 2;

0 commit comments

Comments
 (0)