2020-05-22 14:36:39 +03:00
|
|
|
const swc = require("../../");
|
|
|
|
|
2023-03-31 09:15:21 +03:00
|
|
|
it("should emit _interop_require_default", () => {
|
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();
|
|
|
|
|
2023-03-31 09:15:21 +03:00
|
|
|
expect(out.code).toContain(`function _interop_require_default`);
|
|
|
|
expect(out.code).toContain(`_interop_require_default(require("foo"))`);
|
2020-05-22 14:36:39 +03:00
|
|
|
});
|
|
|
|
|
2023-03-31 09:15:21 +03:00
|
|
|
it("should emit _interop_require_wildcard", () => {
|
2020-05-22 14:36:39 +03:00
|
|
|
const out = swc.transformSync('import * as foo from "foo"', {
|
|
|
|
module: {
|
|
|
|
type: "commonjs"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expect(out.map).toBeFalsy();
|
|
|
|
|
2023-03-31 09:15:21 +03:00
|
|
|
expect(out.code).toContain(`function _interop_require_wildcard`);
|
2020-05-22 14:36:39 +03:00
|
|
|
expect(out.code).toContain(
|
2023-03-31 09:15:21 +03:00
|
|
|
`_interop_require_wildcard(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",`);
|
2023-04-04 06:05:47 +03:00
|
|
|
expect(out.code).toContain(`_class_call_check._(this, Foo);`);
|
|
|
|
expect(out.code).toContain(`_inherits._(Bar, Foo);`);
|
2020-05-22 14:36:39 +03:00
|
|
|
});
|
2023-07-28 08:20:16 +03:00
|
|
|
|
|
|
|
it('should not require filename if no exports in umd', () => {
|
|
|
|
const code = `console.log('test')`;
|
|
|
|
|
|
|
|
const out = swc.transformSync(code, {
|
|
|
|
jsc: {
|
|
|
|
parser: {
|
|
|
|
syntax: 'ecmascript',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
type: 'umd',
|
|
|
|
},
|
|
|
|
isModule: true,
|
|
|
|
});
|
|
|
|
expect(out.code).toContain(`function(global`);
|
|
|
|
});
|