-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
module_test.js
51 lines (44 loc) · 1.33 KB
/
module_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const swc = require("../../");
it("should emit _interopRequireDefault", () => {
const out = swc.transformSync(`import foo from "foo"`, {
module: {
type: "commonjs"
}
});
expect(out.map).toBeFalsy();
expect(out.code).toContain(`function _interopRequireDefault`);
expect(out.code).toContain(
`var _foo = _interopRequireDefault(require("foo"))`
);
});
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(
`var foo = _interopRequireWildcard(require("foo"))`
);
});
it("should work with amd and expternal helpers", () => {
const out = swc.transformSync(
`class Foo {}
class Bar extends Foo {}`,
{
jsc: {
externalHelpers: true
},
module: {
type: "amd",
moduleId: "a"
}
}
);
expect(out.map).toBeFalsy();
expect(out.code).toContain(`define("a",`);
expect(out.code).toContain(`swcHelpers.classCallCheck(this, Foo);`);
expect(out.code).toContain(`swcHelpers.inherits(Bar, Foo);`);
});