2020-05-22 14:36:39 +03:00
|
|
|
const swc = require("../../");
|
|
|
|
|
|
|
|
it("should emit _interopRequireDefault", () => {
|
2020-07-28 15:56:19 +03:00
|
|
|
const out = swc.transformSync(`import foo from "foo"`, {
|
2020-05-22 14:36:39 +03:00
|
|
|
module: {
|
|
|
|
type: "commonjs"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expect(out.map).toBeFalsy();
|
|
|
|
|
|
|
|
expect(out.code).toContain(`function _interopRequireDefault`);
|
2022-07-03 08:54:07 +03:00
|
|
|
expect(out.code).toContain(`_interopRequireDefault(require("foo"))`);
|
2020-05-22 14:36:39 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should emit _interopRequireWildcard", () => {
|
|
|
|
const out = swc.transformSync('import * as foo from "foo"', {
|
|
|
|
module: {
|
|
|
|
type: "commonjs"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expect(out.map).toBeFalsy();
|
|
|
|
|
|
|
|
expect(out.code).toContain(`function _interopRequireWildcard`);
|
|
|
|
expect(out.code).toContain(
|
2022-06-27 15:32:06 +03:00
|
|
|
`_interopRequireWildcard(require("foo"))`
|
2020-05-22 14:36:39 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-04-11 21:45:58 +03:00
|
|
|
it("should work with amd and external helpers", () => {
|
2020-05-22 14:36:39 +03:00
|
|
|
const out = swc.transformSync(
|
|
|
|
`class Foo {}
|
|
|
|
class Bar extends Foo {}`,
|
|
|
|
{
|
|
|
|
jsc: {
|
|
|
|
externalHelpers: true
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
type: "amd",
|
|
|
|
moduleId: "a"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(out.map).toBeFalsy();
|
|
|
|
|
2020-07-28 15:56:19 +03:00
|
|
|
expect(out.code).toContain(`define("a",`);
|
2022-06-27 15:32:06 +03:00
|
|
|
expect(out.code).toContain(`_classCallCheck(this, Foo);`);
|
2022-05-24 07:09:59 +03:00
|
|
|
expect(out.code).toContain(`_inherits(Bar, Foo);`);
|
2020-05-22 14:36:39 +03:00
|
|
|
});
|