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

feat: add noIncompleteNsImportDetection assumption to plugin-transform-modules-commonjs #13290

Merged
merged 1 commit into from
Aug 3, 2021
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
1 change: 1 addition & 0 deletions packages/babel-core/src/config/validation/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export const assumptionsNames = new Set<string>([
"mutableTemplateObject",
"noClassCalls",
"noDocumentAll",
"noIncompleteNsImportDetection",
"noNewArrows",
"objectRestNoSymbols",
"privateFieldsAsProperties",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function createClassFeaturePlugin({
feature,
loose,
manipulateOptions,
// TODO(Babel 8): Remove the default falue
// TODO(Babel 8): Remove the default value
api = { assumption: () => void 0 },
}: Options) {
const setPublicClassFields = api.assumption("setPublicClassFields");
Expand Down
30 changes: 20 additions & 10 deletions packages/babel-helper-module-transforms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function rewriteModuleStatementsAndPrepareHeader(

constantReexports = loose,
enumerableModuleMeta = loose,
noIncompleteNsImportDetection,
}: {
exportName?;
strict;
Expand All @@ -57,6 +58,7 @@ export function rewriteModuleStatementsAndPrepareHeader(
esNamespaceOnly?;
constantReexports?;
enumerableModuleMeta?;
noIncompleteNsImportDetection?: boolean;
},
) {
validateImportInteropOption(importInterop);
Expand Down Expand Up @@ -102,7 +104,12 @@ export function rewriteModuleStatementsAndPrepareHeader(

// Create all of the statically known named exports.
headers.push(
...buildExportInitializationStatements(path, meta, constantReexports),
...buildExportInitializationStatements(
path,
meta,
constantReexports,
noIncompleteNsImportDetection,
),
);

return { meta, headers };
Expand Down Expand Up @@ -388,6 +395,7 @@ function buildExportInitializationStatements(
programPath: NodePath,
metadata: ModuleMetadata,
constantReexports: boolean = false,
noIncompleteNsImportDetection = false,
) {
const initStatements = [];

Expand All @@ -413,15 +421,17 @@ function buildExportInitializationStatements(
}
}

initStatements.push(
...chunk(exportNames, 100).map(members => {
return buildInitStatement(
metadata,
members,
programPath.scope.buildUndefinedNode(),
);
}),
);
if (!noIncompleteNsImportDetection) {
fedeci marked this conversation as resolved.
Show resolved Hide resolved
initStatements.push(
...chunk(exportNames, 100).map(members => {
return buildInitStatement(
metadata,
members,
programPath.scope.buildUndefinedNode(),
);
}),
);
}

return initStatements;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-plugin-transform-modules-commonjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default declare((api, options) => {
api.assumption("constantReexports") ?? options.loose;
const enumerableModuleMeta =
api.assumption("enumerableModuleMeta") ?? options.loose;
const noIncompleteNsImportDetection =
api.assumption("noIncompleteNsImportDetection") ?? false;

if (
typeof lazy !== "boolean" &&
Expand Down Expand Up @@ -186,6 +188,7 @@ export default declare((api, options) => {
/\.mjs$/.test(state.filename)
? mjsStrictNamespace
: strictNamespace,
noIncompleteNsImportDetection,
},
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

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

Object.defineProperty(exports, "__esModule", {
value: true
});

var _foo = require("foo");

exports.foo = _foo.foo;
fedeci marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var foo = 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
var foo = 2;
exports.foo = foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"assumptions": {
"noIncompleteNsImportDetection": true
},
"plugins": ["transform-modules-commonjs"]
}