@jsenv/core 36.1.3 → 36.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/{global_this.js → global_this_js_classic.js} +3 -3
- package/dist/js/global_this_js_module.js +20 -0
- package/dist/js/inline_content.js +10 -0
- package/dist/jsenv_core.js +7479 -7675
- package/package.json +20 -20
- package/src/build/build.js +4 -4
- package/src/dev/file_service.js +1 -1
- package/src/kitchen/client/inline_content.js +17 -0
- package/src/kitchen/kitchen.js +7 -1
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +4 -1
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +4 -1
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +4 -1
- package/src/plugins/plugins.js +1 -1
- package/src/kitchen/compat/features_compatibility.js +0 -220
- package/src/kitchen/compat/runtime_compat.js +0 -56
- package/src/plugins/reference_analysis/inline_content.js +0 -7
- package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +0 -45
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +0 -78
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -34
- package/src/plugins/transpilation/babel/global_this/client/global_this.js +0 -25
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -52
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +0 -173
- package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +0 -432
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +0 -100
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +0 -142
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +0 -381
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -33
- package/src/plugins/transpilation/babel/regenerator_runtime/client/regenerator_runtime.js +0 -748
- package/src/plugins/transpilation/babel/require_babel_plugin.js +0 -8
- package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +0 -54
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +0 -248
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +0 -119
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +0 -46
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +0 -240
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +0 -62
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +0 -48
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +0 -87
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +0 -56
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
// copied from
|
|
3
|
-
// https://github.com/babel/babel/blob/e498bee10f0123bb208baa228ce6417542a2c3c4/packages/babel-compat-data/data/plugins.json#L1
|
|
4
|
-
// https://github.com/babel/babel/blob/master/packages/babel-compat-data/data/plugins.json#L1
|
|
5
|
-
// Because this is an hidden implementation detail of @babel/preset-env
|
|
6
|
-
// it could be deprecated or moved anytime.
|
|
7
|
-
// For that reason it makes more sens to have it inlined here
|
|
8
|
-
// than importing it from an undocumented location.
|
|
9
|
-
// Ideally it would be documented or a separate module
|
|
10
|
-
|
|
11
|
-
export const babelPluginCompatMap = {
|
|
12
|
-
"proposal-numeric-separator": {
|
|
13
|
-
chrome: "75",
|
|
14
|
-
opera: "62",
|
|
15
|
-
edge: "79",
|
|
16
|
-
firefox: "70",
|
|
17
|
-
safari: "13",
|
|
18
|
-
node: "12.5",
|
|
19
|
-
ios: "13",
|
|
20
|
-
samsung: "11",
|
|
21
|
-
electron: "6",
|
|
22
|
-
},
|
|
23
|
-
"proposal-class-properties": {
|
|
24
|
-
chrome: "74",
|
|
25
|
-
opera: "61",
|
|
26
|
-
edge: "79",
|
|
27
|
-
node: "12",
|
|
28
|
-
electron: "6.1",
|
|
29
|
-
},
|
|
30
|
-
"proposal-private-methods": {
|
|
31
|
-
chrome: "84",
|
|
32
|
-
opera: "71",
|
|
33
|
-
},
|
|
34
|
-
"proposal-nullish-coalescing-operator": {
|
|
35
|
-
chrome: "80",
|
|
36
|
-
opera: "67",
|
|
37
|
-
edge: "80",
|
|
38
|
-
firefox: "72",
|
|
39
|
-
safari: "13.1",
|
|
40
|
-
node: "14",
|
|
41
|
-
electron: "8.1",
|
|
42
|
-
},
|
|
43
|
-
"proposal-optional-chaining": {
|
|
44
|
-
chrome: "80",
|
|
45
|
-
opera: "67",
|
|
46
|
-
edge: "80",
|
|
47
|
-
firefox: "74",
|
|
48
|
-
safari: "13.1",
|
|
49
|
-
node: "14",
|
|
50
|
-
electron: "8.1",
|
|
51
|
-
},
|
|
52
|
-
"proposal-json-strings": {
|
|
53
|
-
chrome: "66",
|
|
54
|
-
opera: "53",
|
|
55
|
-
edge: "79",
|
|
56
|
-
firefox: "62",
|
|
57
|
-
safari: "12",
|
|
58
|
-
node: "10",
|
|
59
|
-
ios: "12",
|
|
60
|
-
samsung: "9",
|
|
61
|
-
electron: "3",
|
|
62
|
-
},
|
|
63
|
-
"proposal-optional-catch-binding": {
|
|
64
|
-
chrome: "66",
|
|
65
|
-
opera: "53",
|
|
66
|
-
edge: "79",
|
|
67
|
-
firefox: "58",
|
|
68
|
-
safari: "11.1",
|
|
69
|
-
node: "10",
|
|
70
|
-
ios: "11.3",
|
|
71
|
-
samsung: "9",
|
|
72
|
-
electron: "3",
|
|
73
|
-
},
|
|
74
|
-
"transform-parameters": {
|
|
75
|
-
chrome: "49",
|
|
76
|
-
opera: "36",
|
|
77
|
-
edge: "18",
|
|
78
|
-
firefox: "53",
|
|
79
|
-
safari: "10",
|
|
80
|
-
node: "6",
|
|
81
|
-
ios: "10",
|
|
82
|
-
samsung: "5",
|
|
83
|
-
electron: "0.37",
|
|
84
|
-
},
|
|
85
|
-
"proposal-async-generator-functions": {
|
|
86
|
-
chrome: "63",
|
|
87
|
-
opera: "50",
|
|
88
|
-
edge: "79",
|
|
89
|
-
firefox: "57",
|
|
90
|
-
safari: "12",
|
|
91
|
-
node: "10",
|
|
92
|
-
ios: "12",
|
|
93
|
-
samsung: "8",
|
|
94
|
-
electron: "3",
|
|
95
|
-
},
|
|
96
|
-
"proposal-object-rest-spread": {
|
|
97
|
-
chrome: "60",
|
|
98
|
-
opera: "47",
|
|
99
|
-
edge: "79",
|
|
100
|
-
firefox: "55",
|
|
101
|
-
safari: "11.1",
|
|
102
|
-
node: "8.3",
|
|
103
|
-
ios: "11.3",
|
|
104
|
-
samsung: "8",
|
|
105
|
-
electron: "2",
|
|
106
|
-
},
|
|
107
|
-
"transform-dotall-regex": {
|
|
108
|
-
chrome: "62",
|
|
109
|
-
opera: "49",
|
|
110
|
-
edge: "79",
|
|
111
|
-
firefox: "78",
|
|
112
|
-
safari: "11.1",
|
|
113
|
-
node: "8.10",
|
|
114
|
-
ios: "11.3",
|
|
115
|
-
samsung: "8",
|
|
116
|
-
electron: "3",
|
|
117
|
-
},
|
|
118
|
-
"proposal-unicode-property-regex": {
|
|
119
|
-
chrome: "64",
|
|
120
|
-
opera: "51",
|
|
121
|
-
edge: "79",
|
|
122
|
-
firefox: "78",
|
|
123
|
-
safari: "11.1",
|
|
124
|
-
node: "10",
|
|
125
|
-
ios: "11.3",
|
|
126
|
-
samsung: "9",
|
|
127
|
-
electron: "3",
|
|
128
|
-
},
|
|
129
|
-
"transform-named-capturing-groups-regex": {
|
|
130
|
-
chrome: "64",
|
|
131
|
-
opera: "51",
|
|
132
|
-
edge: "79",
|
|
133
|
-
safari: "11.1",
|
|
134
|
-
node: "10",
|
|
135
|
-
ios: "11.3",
|
|
136
|
-
samsung: "9",
|
|
137
|
-
electron: "3",
|
|
138
|
-
},
|
|
139
|
-
"transform-async-to-generator": {
|
|
140
|
-
chrome: "55",
|
|
141
|
-
opera: "42",
|
|
142
|
-
edge: "15",
|
|
143
|
-
firefox: "52",
|
|
144
|
-
safari: "11",
|
|
145
|
-
node: "7.6",
|
|
146
|
-
ios: "11",
|
|
147
|
-
samsung: "6",
|
|
148
|
-
electron: "1.6",
|
|
149
|
-
},
|
|
150
|
-
"transform-exponentiation-operator": {
|
|
151
|
-
chrome: "52",
|
|
152
|
-
opera: "39",
|
|
153
|
-
edge: "14",
|
|
154
|
-
firefox: "52",
|
|
155
|
-
safari: "10.1",
|
|
156
|
-
node: "7",
|
|
157
|
-
ios: "10.3",
|
|
158
|
-
samsung: "6",
|
|
159
|
-
electron: "1.3",
|
|
160
|
-
},
|
|
161
|
-
"transform-template-literals": {
|
|
162
|
-
chrome: "41",
|
|
163
|
-
opera: "28",
|
|
164
|
-
edge: "13",
|
|
165
|
-
electron: "0.22",
|
|
166
|
-
firefox: "34",
|
|
167
|
-
safari: "13",
|
|
168
|
-
node: "4",
|
|
169
|
-
ios: "13",
|
|
170
|
-
samsung: "3.4",
|
|
171
|
-
},
|
|
172
|
-
"transform-literals": {
|
|
173
|
-
chrome: "44",
|
|
174
|
-
opera: "31",
|
|
175
|
-
edge: "12",
|
|
176
|
-
firefox: "53",
|
|
177
|
-
safari: "9",
|
|
178
|
-
node: "4",
|
|
179
|
-
ios: "9",
|
|
180
|
-
samsung: "4",
|
|
181
|
-
electron: "0.30",
|
|
182
|
-
},
|
|
183
|
-
"transform-function-name": {
|
|
184
|
-
chrome: "51",
|
|
185
|
-
opera: "38",
|
|
186
|
-
edge: "79",
|
|
187
|
-
firefox: "53",
|
|
188
|
-
safari: "10",
|
|
189
|
-
node: "6.5",
|
|
190
|
-
ios: "10",
|
|
191
|
-
samsung: "5",
|
|
192
|
-
electron: "1.2",
|
|
193
|
-
},
|
|
194
|
-
"transform-arrow-functions": {
|
|
195
|
-
chrome: "47",
|
|
196
|
-
opera: "34",
|
|
197
|
-
edge: "13",
|
|
198
|
-
firefox: "45",
|
|
199
|
-
safari: "10",
|
|
200
|
-
node: "6",
|
|
201
|
-
ios: "10",
|
|
202
|
-
samsung: "5",
|
|
203
|
-
electron: "0.36",
|
|
204
|
-
},
|
|
205
|
-
"transform-block-scoped-functions": {
|
|
206
|
-
chrome: "41",
|
|
207
|
-
opera: "28",
|
|
208
|
-
edge: "12",
|
|
209
|
-
firefox: "46",
|
|
210
|
-
safari: "10",
|
|
211
|
-
node: "4",
|
|
212
|
-
ie: "11",
|
|
213
|
-
ios: "10",
|
|
214
|
-
samsung: "3.4",
|
|
215
|
-
electron: "0.22",
|
|
216
|
-
},
|
|
217
|
-
"transform-classes": {
|
|
218
|
-
chrome: "46",
|
|
219
|
-
opera: "33",
|
|
220
|
-
edge: "13",
|
|
221
|
-
firefox: "45",
|
|
222
|
-
safari: "10",
|
|
223
|
-
node: "5",
|
|
224
|
-
ios: "10",
|
|
225
|
-
samsung: "5",
|
|
226
|
-
electron: "0.36",
|
|
227
|
-
},
|
|
228
|
-
"transform-object-super": {
|
|
229
|
-
chrome: "46",
|
|
230
|
-
opera: "33",
|
|
231
|
-
edge: "13",
|
|
232
|
-
firefox: "45",
|
|
233
|
-
safari: "10",
|
|
234
|
-
node: "5",
|
|
235
|
-
ios: "10",
|
|
236
|
-
samsung: "5",
|
|
237
|
-
electron: "0.36",
|
|
238
|
-
},
|
|
239
|
-
"transform-shorthand-properties": {
|
|
240
|
-
chrome: "43",
|
|
241
|
-
opera: "30",
|
|
242
|
-
edge: "12",
|
|
243
|
-
firefox: "33",
|
|
244
|
-
safari: "9",
|
|
245
|
-
node: "4",
|
|
246
|
-
ios: "9",
|
|
247
|
-
samsung: "4",
|
|
248
|
-
electron: "0.28",
|
|
249
|
-
},
|
|
250
|
-
"transform-duplicate-keys": {
|
|
251
|
-
chrome: "42",
|
|
252
|
-
opera: "29",
|
|
253
|
-
edge: "12",
|
|
254
|
-
firefox: "34",
|
|
255
|
-
safari: "9",
|
|
256
|
-
node: "4",
|
|
257
|
-
ios: "9",
|
|
258
|
-
samsung: "3.4",
|
|
259
|
-
electron: "0.25",
|
|
260
|
-
},
|
|
261
|
-
"transform-computed-properties": {
|
|
262
|
-
chrome: "44",
|
|
263
|
-
opera: "31",
|
|
264
|
-
edge: "12",
|
|
265
|
-
firefox: "34",
|
|
266
|
-
safari: "7.1",
|
|
267
|
-
node: "4",
|
|
268
|
-
ios: "8",
|
|
269
|
-
samsung: "4",
|
|
270
|
-
electron: "0.30",
|
|
271
|
-
},
|
|
272
|
-
"transform-for-of": {
|
|
273
|
-
chrome: "51",
|
|
274
|
-
opera: "38",
|
|
275
|
-
edge: "15",
|
|
276
|
-
firefox: "53",
|
|
277
|
-
safari: "10",
|
|
278
|
-
node: "6.5",
|
|
279
|
-
ios: "10",
|
|
280
|
-
samsung: "5",
|
|
281
|
-
electron: "1.2",
|
|
282
|
-
},
|
|
283
|
-
"transform-sticky-regex": {
|
|
284
|
-
chrome: "49",
|
|
285
|
-
opera: "36",
|
|
286
|
-
edge: "13",
|
|
287
|
-
firefox: "3",
|
|
288
|
-
safari: "10",
|
|
289
|
-
node: "6",
|
|
290
|
-
ios: "10",
|
|
291
|
-
samsung: "5",
|
|
292
|
-
electron: "0.37",
|
|
293
|
-
},
|
|
294
|
-
"transform-unicode-escapes": {
|
|
295
|
-
chrome: "44",
|
|
296
|
-
opera: "31",
|
|
297
|
-
edge: "12",
|
|
298
|
-
firefox: "53",
|
|
299
|
-
safari: "9",
|
|
300
|
-
node: "4",
|
|
301
|
-
ios: "9",
|
|
302
|
-
samsung: "4",
|
|
303
|
-
electron: "0.30",
|
|
304
|
-
},
|
|
305
|
-
"transform-unicode-regex": {
|
|
306
|
-
chrome: "50",
|
|
307
|
-
opera: "37",
|
|
308
|
-
edge: "13",
|
|
309
|
-
firefox: "46",
|
|
310
|
-
safari: "12",
|
|
311
|
-
node: "6",
|
|
312
|
-
ios: "12",
|
|
313
|
-
samsung: "5",
|
|
314
|
-
electron: "1.1",
|
|
315
|
-
},
|
|
316
|
-
"transform-spread": {
|
|
317
|
-
chrome: "46",
|
|
318
|
-
opera: "33",
|
|
319
|
-
edge: "13",
|
|
320
|
-
firefox: "36",
|
|
321
|
-
safari: "10",
|
|
322
|
-
node: "5",
|
|
323
|
-
ios: "10",
|
|
324
|
-
samsung: "5",
|
|
325
|
-
electron: "0.36",
|
|
326
|
-
},
|
|
327
|
-
"transform-destructuring": {
|
|
328
|
-
chrome: "51",
|
|
329
|
-
opera: "38",
|
|
330
|
-
edge: "15",
|
|
331
|
-
firefox: "53",
|
|
332
|
-
safari: "10",
|
|
333
|
-
node: "6.5",
|
|
334
|
-
ios: "10",
|
|
335
|
-
samsung: "5",
|
|
336
|
-
electron: "1.2",
|
|
337
|
-
},
|
|
338
|
-
"transform-block-scoping": {
|
|
339
|
-
chrome: "49",
|
|
340
|
-
opera: "36",
|
|
341
|
-
edge: "14",
|
|
342
|
-
firefox: "51",
|
|
343
|
-
safari: "11",
|
|
344
|
-
node: "6",
|
|
345
|
-
ios: "11",
|
|
346
|
-
samsung: "5",
|
|
347
|
-
electron: "0.37",
|
|
348
|
-
},
|
|
349
|
-
"transform-typeof-symbol": {
|
|
350
|
-
chrome: "38",
|
|
351
|
-
opera: "25",
|
|
352
|
-
edge: "12",
|
|
353
|
-
firefox: "36",
|
|
354
|
-
safari: "9",
|
|
355
|
-
node: "0.12",
|
|
356
|
-
ios: "9",
|
|
357
|
-
samsung: "3",
|
|
358
|
-
electron: "0.20",
|
|
359
|
-
},
|
|
360
|
-
"transform-new-target": {
|
|
361
|
-
chrome: "46",
|
|
362
|
-
opera: "33",
|
|
363
|
-
edge: "14",
|
|
364
|
-
firefox: "41",
|
|
365
|
-
safari: "10",
|
|
366
|
-
node: "5",
|
|
367
|
-
ios: "10",
|
|
368
|
-
samsung: "5",
|
|
369
|
-
electron: "0.36",
|
|
370
|
-
},
|
|
371
|
-
"transform-regenerator": {
|
|
372
|
-
chrome: "50",
|
|
373
|
-
opera: "37",
|
|
374
|
-
edge: "13",
|
|
375
|
-
firefox: "53",
|
|
376
|
-
safari: "10",
|
|
377
|
-
node: "6",
|
|
378
|
-
ios: "10",
|
|
379
|
-
samsung: "5",
|
|
380
|
-
electron: "1.1",
|
|
381
|
-
},
|
|
382
|
-
"transform-member-expression-literals": {
|
|
383
|
-
chrome: "7",
|
|
384
|
-
opera: "12",
|
|
385
|
-
edge: "12",
|
|
386
|
-
firefox: "2",
|
|
387
|
-
safari: "5.1",
|
|
388
|
-
node: "0.10",
|
|
389
|
-
ie: "9",
|
|
390
|
-
android: "4",
|
|
391
|
-
ios: "6",
|
|
392
|
-
phantom: "2",
|
|
393
|
-
samsung: "1",
|
|
394
|
-
electron: "0.20",
|
|
395
|
-
},
|
|
396
|
-
"transform-property-literals": {
|
|
397
|
-
chrome: "7",
|
|
398
|
-
opera: "12",
|
|
399
|
-
edge: "12",
|
|
400
|
-
firefox: "2",
|
|
401
|
-
safari: "5.1",
|
|
402
|
-
node: "0.10",
|
|
403
|
-
ie: "9",
|
|
404
|
-
android: "4",
|
|
405
|
-
ios: "6",
|
|
406
|
-
phantom: "2",
|
|
407
|
-
samsung: "1",
|
|
408
|
-
electron: "0.20",
|
|
409
|
-
},
|
|
410
|
-
"transform-reserved-words": {
|
|
411
|
-
chrome: "13",
|
|
412
|
-
opera: "10.50",
|
|
413
|
-
edge: "12",
|
|
414
|
-
firefox: "2",
|
|
415
|
-
safari: "3.1",
|
|
416
|
-
node: "0.10",
|
|
417
|
-
ie: "9",
|
|
418
|
-
android: "4.4",
|
|
419
|
-
ios: "6",
|
|
420
|
-
phantom: "2",
|
|
421
|
-
samsung: "1",
|
|
422
|
-
electron: "0.20",
|
|
423
|
-
},
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
// copy of transform-async-to-generator
|
|
427
|
-
// so that async is not transpiled when supported
|
|
428
|
-
babelPluginCompatMap["transform-async-to-promises"] =
|
|
429
|
-
babelPluginCompatMap["transform-async-to-generator"];
|
|
430
|
-
|
|
431
|
-
babelPluginCompatMap["regenerator-transform"] =
|
|
432
|
-
babelPluginCompatMap["transform-regenerator"];
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { applyBabelPlugins } from "@jsenv/ast";
|
|
2
|
-
|
|
3
|
-
import { RUNTIME_COMPAT } from "@jsenv/core/src/kitchen/compat/runtime_compat.js";
|
|
4
|
-
import { getBaseBabelPluginStructure } from "./helpers/babel_plugin_structure.js";
|
|
5
|
-
import { babelPluginBabelHelpersAsJsenvImports } from "./helpers/babel_plugin_babel_helpers_as_jsenv_imports.js";
|
|
6
|
-
import { babelPluginNewStylesheetAsJsenvImport } from "./new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js";
|
|
7
|
-
import { babelPluginGlobalThisAsJsenvImport } from "./global_this/babel_plugin_global_this_as_jsenv_import.js";
|
|
8
|
-
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js";
|
|
9
|
-
|
|
10
|
-
export const jsenvPluginBabel = ({
|
|
11
|
-
getCustomBabelPlugins,
|
|
12
|
-
babelHelpersAsImport = true,
|
|
13
|
-
} = {}) => {
|
|
14
|
-
const transformWithBabel = async (urlInfo, context) => {
|
|
15
|
-
const isJsModule = urlInfo.type === "js_module";
|
|
16
|
-
|
|
17
|
-
const isSupported = (feature) =>
|
|
18
|
-
RUNTIME_COMPAT.isSupported(context.clientRuntimeCompat, feature);
|
|
19
|
-
const getImportSpecifier = (clientFileUrl) => {
|
|
20
|
-
const [reference] = context.referenceUtils.inject({
|
|
21
|
-
type: "js_import",
|
|
22
|
-
expectedType: "js_module",
|
|
23
|
-
specifier: clientFileUrl,
|
|
24
|
-
});
|
|
25
|
-
return JSON.parse(reference.generatedSpecifier);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const babelPluginStructure = getBaseBabelPluginStructure({
|
|
29
|
-
url: urlInfo.url,
|
|
30
|
-
isSupported,
|
|
31
|
-
isJsModule,
|
|
32
|
-
getImportSpecifier,
|
|
33
|
-
});
|
|
34
|
-
if (getCustomBabelPlugins) {
|
|
35
|
-
Object.assign(babelPluginStructure, getCustomBabelPlugins(context));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isJsModule && babelHelpersAsImport) {
|
|
39
|
-
if (!isSupported("global_this")) {
|
|
40
|
-
babelPluginStructure["global-this-as-jsenv-import"] = [
|
|
41
|
-
babelPluginGlobalThisAsJsenvImport,
|
|
42
|
-
{
|
|
43
|
-
getImportSpecifier,
|
|
44
|
-
},
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
if (!isSupported("async_generator_function")) {
|
|
48
|
-
babelPluginStructure["regenerator-runtime-as-jsenv-import"] = [
|
|
49
|
-
babelPluginRegeneratorRuntimeAsJsenvImport,
|
|
50
|
-
{
|
|
51
|
-
getImportSpecifier,
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
if (!isSupported("new_stylesheet")) {
|
|
56
|
-
babelPluginStructure["new-stylesheet-as-jsenv-import"] = [
|
|
57
|
-
babelPluginNewStylesheetAsJsenvImport,
|
|
58
|
-
{
|
|
59
|
-
getImportSpecifier,
|
|
60
|
-
},
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
if (Object.keys(babelPluginStructure).length > 0) {
|
|
64
|
-
babelPluginStructure["babel-helper-as-jsenv-import"] = [
|
|
65
|
-
babelPluginBabelHelpersAsJsenvImports,
|
|
66
|
-
{
|
|
67
|
-
getImportSpecifier,
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// otherwise, concerning global_this, and new_stylesheet we must inject the code
|
|
73
|
-
// (we cannot inject an import)
|
|
74
|
-
|
|
75
|
-
const babelPlugins = Object.keys(babelPluginStructure).map(
|
|
76
|
-
(babelPluginName) => babelPluginStructure[babelPluginName],
|
|
77
|
-
);
|
|
78
|
-
const { code, map } = await applyBabelPlugins({
|
|
79
|
-
babelPlugins,
|
|
80
|
-
urlInfo,
|
|
81
|
-
options: {
|
|
82
|
-
generatorOpts: {
|
|
83
|
-
retainLines: context.dev,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
content: code,
|
|
89
|
-
sourcemap: map,
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
name: "jsenv:babel",
|
|
94
|
-
appliesDuring: "*",
|
|
95
|
-
transformUrlContent: {
|
|
96
|
-
js_classic: transformWithBabel,
|
|
97
|
-
js_module: transformWithBabel,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url";
|
|
2
|
-
import { injectJsImport } from "@jsenv/ast";
|
|
3
|
-
|
|
4
|
-
export const newStylesheetClientFileUrl = new URL(
|
|
5
|
-
"./client/new_stylesheet.js",
|
|
6
|
-
import.meta.url,
|
|
7
|
-
).href;
|
|
8
|
-
|
|
9
|
-
export const babelPluginNewStylesheetAsJsenvImport = (
|
|
10
|
-
babel,
|
|
11
|
-
{ getImportSpecifier },
|
|
12
|
-
) => {
|
|
13
|
-
return {
|
|
14
|
-
name: "new-stylesheet-as-jsenv-import",
|
|
15
|
-
visitor: {
|
|
16
|
-
Program: (programPath, babelState) => {
|
|
17
|
-
if (babelState.filename) {
|
|
18
|
-
const fileUrl = pathToFileURL(babelState.filename).href;
|
|
19
|
-
if (fileUrl === newStylesheetClientFileUrl) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
let usesNewStylesheet = false;
|
|
24
|
-
programPath.traverse({
|
|
25
|
-
NewExpression: (path) => {
|
|
26
|
-
usesNewStylesheet = isNewCssStyleSheetCall(path.node);
|
|
27
|
-
if (usesNewStylesheet) {
|
|
28
|
-
path.stop();
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
MemberExpression: (path) => {
|
|
32
|
-
usesNewStylesheet = isDocumentAdoptedStyleSheets(path.node);
|
|
33
|
-
if (usesNewStylesheet) {
|
|
34
|
-
path.stop();
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
CallExpression: (path) => {
|
|
38
|
-
if (path.node.callee.type !== "Import") {
|
|
39
|
-
// Some other function call, not import();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (path.node.arguments[0].type !== "StringLiteral") {
|
|
43
|
-
// Non-string argument, probably a variable or expression, e.g.
|
|
44
|
-
// import(moduleId)
|
|
45
|
-
// import('./' + moduleName)
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const sourcePath = path.get("arguments")[0];
|
|
49
|
-
usesNewStylesheet =
|
|
50
|
-
hasCssModuleQueryParam(sourcePath) ||
|
|
51
|
-
hasImportTypeCssAssertion(path);
|
|
52
|
-
if (usesNewStylesheet) {
|
|
53
|
-
path.stop();
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
ImportDeclaration: (path) => {
|
|
57
|
-
const sourcePath = path.get("source");
|
|
58
|
-
usesNewStylesheet =
|
|
59
|
-
hasCssModuleQueryParam(sourcePath) ||
|
|
60
|
-
hasImportTypeCssAssertion(path);
|
|
61
|
-
if (usesNewStylesheet) {
|
|
62
|
-
path.stop();
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
ExportAllDeclaration: (path) => {
|
|
66
|
-
const sourcePath = path.get("source");
|
|
67
|
-
usesNewStylesheet = hasCssModuleQueryParam(sourcePath);
|
|
68
|
-
if (usesNewStylesheet) {
|
|
69
|
-
path.stop();
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
ExportNamedDeclaration: (path) => {
|
|
73
|
-
if (!path.node.source) {
|
|
74
|
-
// This export has no "source", so it's probably
|
|
75
|
-
// a local variable or function, e.g.
|
|
76
|
-
// export { varName }
|
|
77
|
-
// export const constName = ...
|
|
78
|
-
// export function funcName() {}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const sourcePath = path.get("source");
|
|
82
|
-
usesNewStylesheet = hasCssModuleQueryParam(sourcePath);
|
|
83
|
-
if (usesNewStylesheet) {
|
|
84
|
-
path.stop();
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
if (usesNewStylesheet) {
|
|
89
|
-
injectJsImport({
|
|
90
|
-
programPath,
|
|
91
|
-
from: getImportSpecifier(newStylesheetClientFileUrl),
|
|
92
|
-
sideEffect: true,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const isNewCssStyleSheetCall = (node) => {
|
|
101
|
-
return (
|
|
102
|
-
node.type === "NewExpression" &&
|
|
103
|
-
node.callee.type === "Identifier" &&
|
|
104
|
-
node.callee.name === "CSSStyleSheet"
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const isDocumentAdoptedStyleSheets = (node) => {
|
|
109
|
-
return (
|
|
110
|
-
node.type === "MemberExpression" &&
|
|
111
|
-
node.object.type === "Identifier" &&
|
|
112
|
-
node.object.name === "document" &&
|
|
113
|
-
node.property.type === "Identifier" &&
|
|
114
|
-
node.property.name === "adoptedStyleSheets"
|
|
115
|
-
);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const hasCssModuleQueryParam = (path) => {
|
|
119
|
-
const { node } = path;
|
|
120
|
-
return (
|
|
121
|
-
node.type === "StringLiteral" &&
|
|
122
|
-
new URL(node.value, "https://jsenv.dev").searchParams.has(`css_module`)
|
|
123
|
-
);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const hasImportTypeCssAssertion = (path) => {
|
|
127
|
-
const importAssertionsDescriptor = getImportAssertionsDescriptor(
|
|
128
|
-
path.node.assertions,
|
|
129
|
-
);
|
|
130
|
-
return Boolean(importAssertionsDescriptor.type === "css");
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const getImportAssertionsDescriptor = (importAssertions) => {
|
|
134
|
-
const importAssertionsDescriptor = {};
|
|
135
|
-
if (importAssertions) {
|
|
136
|
-
importAssertions.forEach((importAssertion) => {
|
|
137
|
-
importAssertionsDescriptor[importAssertion.key.name] =
|
|
138
|
-
importAssertion.value.value;
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return importAssertionsDescriptor;
|
|
142
|
-
};
|