Implement importInterop: "node" option for module transforms (#12838)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export { default } from 'dep';
|
||||
@@ -0,0 +1,8 @@
|
||||
define(["exports", "dep"], function (_exports, _dep) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(_exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
_exports.default = _dep;
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
export { default, name } from 'dep';
|
||||
@@ -0,0 +1,20 @@
|
||||
define(["exports", "dep"], function (_exports, _dep) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(_exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(_exports, "default", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _dep.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(_exports, "name", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _dep.name;
|
||||
}
|
||||
});
|
||||
_dep = babelHelpers.interopRequireWildcard(_dep, true);
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
export { name } from 'dep';
|
||||
@@ -0,0 +1,13 @@
|
||||
define(["exports", "dep"], function (_exports, _dep) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(_exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(_exports, "name", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _dep.name;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
import foo from "foo";
|
||||
|
||||
foo();
|
||||
@@ -0,0 +1,5 @@
|
||||
define(["foo"], function (_foo) {
|
||||
"use strict";
|
||||
|
||||
_foo();
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
import foo, { named } from "foo";
|
||||
|
||||
foo();
|
||||
named();
|
||||
@@ -0,0 +1,7 @@
|
||||
define(["foo"], function (_foo) {
|
||||
"use strict";
|
||||
|
||||
_foo = babelHelpers.interopRequireWildcard(_foo, true);
|
||||
(0, _foo.default)();
|
||||
(0, _foo.named)();
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
import { named } from "foo";
|
||||
|
||||
named();
|
||||
@@ -0,0 +1,5 @@
|
||||
define(["foo"], function (_foo) {
|
||||
"use strict";
|
||||
|
||||
(0, _foo.named)();
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
import * as foo from 'foo';
|
||||
|
||||
foo.bar();
|
||||
foo.baz();
|
||||
@@ -0,0 +1,7 @@
|
||||
define(["foo"], function (foo) {
|
||||
"use strict";
|
||||
|
||||
foo = babelHelpers.interopRequireWildcard(foo, true);
|
||||
foo.bar();
|
||||
foo.baz();
|
||||
});
|
||||
3
packages/babel-plugin-transform-modules-amd/test/fixtures/importInterop-node/options.json
vendored
Normal file
3
packages/babel-plugin-transform-modules-amd/test/fixtures/importInterop-node/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": [["transform-modules-amd", { "importInterop": "node" }]]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'foo';
|
||||
@@ -0,0 +1,13 @@
|
||||
define(["exports", "foo"], function (_exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(_exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(_exports, "default", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _foo.default;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
import foo from "foo";
|
||||
|
||||
foo();
|
||||
@@ -0,0 +1,5 @@
|
||||
define(["foo"], function (_foo) {
|
||||
"use strict";
|
||||
|
||||
(0, _foo.default)();
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
import * as foo from 'foo';
|
||||
|
||||
foo.bar();
|
||||
foo.baz();
|
||||
@@ -0,0 +1,6 @@
|
||||
define(["foo"], function (foo) {
|
||||
"use strict";
|
||||
|
||||
foo.bar();
|
||||
foo.baz();
|
||||
});
|
||||
3
packages/babel-plugin-transform-modules-amd/test/fixtures/importInterop-none/options.json
vendored
Normal file
3
packages/babel-plugin-transform-modules-amd/test/fixtures/importInterop-none/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": [["transform-modules-amd", { "importInterop": "none" }]]
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import * as babel from "@babel/core";
|
||||
import transformAmd from "../lib";
|
||||
import externalHelpers from "@babel/plugin-external-helpers";
|
||||
|
||||
it("'importInterop' accepts a function", function () {
|
||||
const code = `
|
||||
import a from "a";
|
||||
import b from "b";
|
||||
import c from "c";
|
||||
|
||||
a();
|
||||
b();
|
||||
c();
|
||||
`;
|
||||
|
||||
const importInterop = source => {
|
||||
if (source === "a") return "babel";
|
||||
else if (source === "b") return "node";
|
||||
else if (source === "c") return "none";
|
||||
};
|
||||
|
||||
const output = babel.transformSync(code, {
|
||||
configFile: false,
|
||||
ast: false,
|
||||
plugins: [
|
||||
[externalHelpers, { helperVersion: "7.100.0" }],
|
||||
[transformAmd, { importInterop }],
|
||||
],
|
||||
}).code;
|
||||
|
||||
expect(output).toMatchInlineSnapshot(`
|
||||
"define([\\"a\\", \\"b\\", \\"c\\"], function (_a, _b, _c) {
|
||||
\\"use strict\\";
|
||||
|
||||
_a = babelHelpers.interopRequireDefault(_a);
|
||||
(0, _a.default)();
|
||||
|
||||
_b();
|
||||
|
||||
(0, _c.default)();
|
||||
});"
|
||||
`);
|
||||
});
|
||||
Reference in New Issue
Block a user