/
plugin-ordering.test.js
136 lines (132 loc) 路 4.24 KB
/
plugin-ordering.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import * as babel from "@babel/core";
import proposalClassStaticBlock from "..";
describe("plugin ordering", () => {
it("should work when @babel/plugin-proposal-class-static-block is after class features plugin", () => {
const source = `class Foo {
static {
this.foo = Foo.bar;
}
static bar = 42;
}
`;
expect(
babel.transform(source, {
filename: "example.js",
highlightCode: false,
configFile: false,
babelrc: false,
plugins: [
"@babel/plugin-proposal-class-properties",
proposalClassStaticBlock,
],
}),
).toMatchInlineSnapshot(`
Object {
"ast": null,
"code": "function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
class Foo {}
var _ = {
writable: true,
value: (() => {
Foo.foo = Foo.bar;
})()
};
_defineProperty(Foo, \\"bar\\", 42);",
"map": null,
"metadata": Object {},
"options": Object {
"assumptions": Object {},
"babelrc": false,
"browserslistConfigFile": false,
"cloneInputAst": true,
"configFile": false,
"cwd": "/home/nicolo/Documenti/dev/babel/babel",
"envName": "test",
"filename": "/home/nicolo/Documenti/dev/babel/babel/example.js",
"generatorOpts": Object {
"auxiliaryCommentAfter": undefined,
"auxiliaryCommentBefore": undefined,
"comments": true,
"compact": "auto",
"filename": "/home/nicolo/Documenti/dev/babel/babel/example.js",
"minified": undefined,
"retainLines": undefined,
"shouldPrintComment": undefined,
"sourceFileName": "example.js",
"sourceMaps": false,
"sourceRoot": undefined,
},
"highlightCode": false,
"parserOpts": Object {
"plugins": Array [
"classProperties",
"classPrivateProperties",
"classStaticBlock",
],
"sourceFileName": "/home/nicolo/Documenti/dev/babel/babel/example.js",
"sourceType": "module",
},
"passPerPreset": false,
"plugins": Array [
Plugin {
"generatorOverride": undefined,
"key": "proposal-class-properties",
"manipulateOptions": [Function],
"options": Object {},
"parserOverride": undefined,
"post": undefined,
"pre": [Function],
"visitor": Object {
"ClassDeclaration": Object {
"enter": Array [
[Function],
],
},
"ClassExpression": Object {
"enter": Array [
[Function],
],
},
"ExportDefaultDeclaration": Object {
"enter": Array [
[Function],
],
},
"PrivateName": Object {
"enter": Array [
[Function],
],
},
"_exploded": true,
"_verified": true,
},
},
Plugin {
"generatorOverride": undefined,
"key": "proposal-class-static-block",
"manipulateOptions": [Function],
"options": Object {},
"parserOverride": undefined,
"post": undefined,
"pre": undefined,
"visitor": Object {
"Program": Object {
"enter": Array [
[Function],
],
},
"_exploded": Object {},
"_verified": Object {},
},
},
],
"presets": Array [],
"root": "/home/nicolo/Documenti/dev/babel/babel",
"rootMode": "root",
"targets": Object {},
},
"sourceType": "module",
}
`);
});
});