@jsenv/core 33.0.2 → 34.0.1
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/autoreload.js +1 -4
- package/dist/js/supervisor.js +498 -290
- package/dist/jsenv.js +938 -370
- package/package.json +2 -3
- package/src/basic_fetch.js +23 -13
- package/src/build/start_build_server.js +3 -2
- package/src/dev/file_service.js +1 -1
- package/src/dev/start_dev_server.js +9 -6
- package/src/execute/execute.js +7 -18
- package/src/execute/runtimes/browsers/from_playwright.js +168 -32
- package/src/execute/runtimes/browsers/webkit.js +1 -1
- package/src/execute/web_server_param.js +68 -0
- package/src/kitchen/compat/features_compatibility.js +3 -0
- package/src/plugins/autoreload/client/reload.js +1 -4
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +30 -18
- package/src/plugins/plugins.js +1 -1
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +3 -2
- package/src/plugins/supervisor/client/supervisor.js +467 -287
- package/src/plugins/supervisor/html_supervisor_injection.js +281 -0
- package/src/plugins/supervisor/js_supervisor_injection.js +283 -0
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +48 -233
- package/src/plugins/transpilation/as_js_classic/convert_js_module_to_js_classic.js +67 -30
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +1 -1
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -1
- package/src/test/execute_steps.js +10 -18
- package/src/test/execute_test_plan.js +12 -60
- package/src/test/logs_file_execution.js +74 -28
- package/dist/js/babel_plugin_transform_modules_systemjs.cjs +0 -392
- package/dist/js/script_type_module_supervisor.js +0 -109
- package/src/plugins/supervisor/client/script_type_module_supervisor.js +0 -98
- package/src/plugins/transpilation/as_js_classic/babel_plugin_transform_modules_systemjs.cjs +0 -608
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// https://twitter.com/damienmaillard/status/1554752482273787906
|
|
2
|
-
const isWebkitOrSafari =
|
|
3
|
-
typeof window.webkitConvertPointFromNodeToPage === "function"
|
|
4
|
-
|
|
5
|
-
export const superviseScriptTypeModule = async ({ src, async }) => {
|
|
6
|
-
const currentScript = document.querySelector(
|
|
7
|
-
`script[type="module"][inlined-from-src="${src}"]`,
|
|
8
|
-
)
|
|
9
|
-
const execute = isWebkitOrSafari
|
|
10
|
-
? createExecuteWithDynamicImport({ src })
|
|
11
|
-
: createExecuteWithScript({ currentScript, src })
|
|
12
|
-
return window.__supervisor__.addExecution({
|
|
13
|
-
src,
|
|
14
|
-
async,
|
|
15
|
-
type: "js_module",
|
|
16
|
-
execute,
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const createExecuteWithScript = ({ currentScript, src }) => {
|
|
21
|
-
const parentNode = currentScript.parentNode
|
|
22
|
-
let nodeToReplace
|
|
23
|
-
let currentScriptClone
|
|
24
|
-
return async ({ isReload }) => {
|
|
25
|
-
const urlObject = new URL(src, window.location)
|
|
26
|
-
const loadPromise = new Promise((resolve, reject) => {
|
|
27
|
-
currentScriptClone = document.createElement("script")
|
|
28
|
-
// browsers set async by default when creating script(s)
|
|
29
|
-
// we want an exact copy to preserves how code is executed
|
|
30
|
-
currentScriptClone.async = false
|
|
31
|
-
Array.from(currentScript.attributes).forEach((attribute) => {
|
|
32
|
-
currentScriptClone.setAttribute(attribute.nodeName, attribute.nodeValue)
|
|
33
|
-
})
|
|
34
|
-
if (isReload) {
|
|
35
|
-
urlObject.searchParams.set("hmr", Date.now())
|
|
36
|
-
nodeToReplace = currentScriptClone
|
|
37
|
-
currentScriptClone.src = urlObject.href
|
|
38
|
-
} else {
|
|
39
|
-
currentScriptClone.removeAttribute("jsenv-cooked-by")
|
|
40
|
-
currentScriptClone.removeAttribute("jsenv-inlined-by")
|
|
41
|
-
currentScriptClone.removeAttribute("jsenv-injected-by")
|
|
42
|
-
currentScriptClone.removeAttribute("inlined-from-src")
|
|
43
|
-
currentScriptClone.removeAttribute("original-position")
|
|
44
|
-
currentScriptClone.removeAttribute("original-src-position")
|
|
45
|
-
nodeToReplace = currentScript
|
|
46
|
-
currentScriptClone.src = src
|
|
47
|
-
}
|
|
48
|
-
currentScriptClone.addEventListener("error", reject)
|
|
49
|
-
currentScriptClone.addEventListener("load", resolve)
|
|
50
|
-
parentNode.replaceChild(currentScriptClone, nodeToReplace)
|
|
51
|
-
})
|
|
52
|
-
try {
|
|
53
|
-
await loadPromise
|
|
54
|
-
} catch (e) {
|
|
55
|
-
// eslint-disable-next-line no-throw-literal
|
|
56
|
-
throw {
|
|
57
|
-
message: `Failed to fetch module: ${urlObject.href}`,
|
|
58
|
-
reportedBy: "script_error_event",
|
|
59
|
-
url: urlObject.href,
|
|
60
|
-
// window.error won't be dispatched for this error
|
|
61
|
-
needsReport: true,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
return {
|
|
66
|
-
executionPromise: import(urlObject.href),
|
|
67
|
-
}
|
|
68
|
-
} catch (e) {
|
|
69
|
-
e.reportedBy = "dynamic_import"
|
|
70
|
-
throw e
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const createExecuteWithDynamicImport = ({ src }) => {
|
|
76
|
-
return async ({ isReload }) => {
|
|
77
|
-
const urlObject = new URL(src, window.location)
|
|
78
|
-
if (isReload) {
|
|
79
|
-
urlObject.searchParams.set("hmr", Date.now())
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
const namespace = await import(urlObject.href)
|
|
83
|
-
return {
|
|
84
|
-
executionPromise: Promise.resolve(namespace),
|
|
85
|
-
}
|
|
86
|
-
} catch (e) {
|
|
87
|
-
e.reportedBy = "dynamic_import"
|
|
88
|
-
// dynamic import would hide the error to the browser
|
|
89
|
-
// so it must be re-reported using window.reportError
|
|
90
|
-
if (typeof window.reportError === "function") {
|
|
91
|
-
window.reportError(e)
|
|
92
|
-
} else {
|
|
93
|
-
console.error(e)
|
|
94
|
-
}
|
|
95
|
-
throw e
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,608 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true,
|
|
5
|
-
})
|
|
6
|
-
exports.default = void 0
|
|
7
|
-
exports.getExportSpecifierName = getExportSpecifierName
|
|
8
|
-
var _helperPluginUtils = require("@babel/helper-plugin-utils")
|
|
9
|
-
var _helperHoistVariables = require("@babel/helper-hoist-variables")
|
|
10
|
-
var _core = require("@babel/core")
|
|
11
|
-
var _helperModuleTransforms = require("@babel/helper-module-transforms")
|
|
12
|
-
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier")
|
|
13
|
-
const buildTemplate = _core.template.statement(`
|
|
14
|
-
SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
|
|
15
|
-
"use strict";
|
|
16
|
-
BEFORE_BODY;
|
|
17
|
-
return {
|
|
18
|
-
setters: SETTERS,
|
|
19
|
-
execute: EXECUTE,
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
`)
|
|
23
|
-
const buildExportAll = _core.template.statement(`
|
|
24
|
-
for (var KEY in TARGET) {
|
|
25
|
-
if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY];
|
|
26
|
-
}
|
|
27
|
-
`)
|
|
28
|
-
const MISSING_PLUGIN_WARNING = `\
|
|
29
|
-
WARNING: Dynamic import() transformation must be enabled using the
|
|
30
|
-
@babel/plugin-proposal-dynamic-import plugin. Babel 8 will
|
|
31
|
-
no longer transform import() without using that plugin.
|
|
32
|
-
`
|
|
33
|
-
const MISSING_PLUGIN_ERROR = `\
|
|
34
|
-
ERROR: Dynamic import() transformation must be enabled using the
|
|
35
|
-
@babel/plugin-proposal-dynamic-import plugin. Babel 8
|
|
36
|
-
no longer transforms import() without using that plugin.
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
function getExportSpecifierName(node, stringSpecifiers) {
|
|
40
|
-
if (node.type === "Identifier") {
|
|
41
|
-
return node.name
|
|
42
|
-
} else if (node.type === "StringLiteral") {
|
|
43
|
-
const stringValue = node.value
|
|
44
|
-
if (!(0, _helperValidatorIdentifier.isIdentifierName)(stringValue)) {
|
|
45
|
-
stringSpecifiers.add(stringValue)
|
|
46
|
-
}
|
|
47
|
-
return stringValue
|
|
48
|
-
} else {
|
|
49
|
-
throw new Error(
|
|
50
|
-
`Expected export specifier to be either Identifier or StringLiteral, got ${node.type}`,
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function constructExportCall(
|
|
55
|
-
path,
|
|
56
|
-
exportIdent,
|
|
57
|
-
exportNames,
|
|
58
|
-
exportValues,
|
|
59
|
-
exportStarTarget,
|
|
60
|
-
stringSpecifiers,
|
|
61
|
-
) {
|
|
62
|
-
const statements = []
|
|
63
|
-
if (!exportStarTarget) {
|
|
64
|
-
if (exportNames.length === 1) {
|
|
65
|
-
statements.push(
|
|
66
|
-
_core.types.expressionStatement(
|
|
67
|
-
_core.types.callExpression(exportIdent, [
|
|
68
|
-
_core.types.stringLiteral(exportNames[0]),
|
|
69
|
-
exportValues[0],
|
|
70
|
-
]),
|
|
71
|
-
),
|
|
72
|
-
)
|
|
73
|
-
} else {
|
|
74
|
-
const objectProperties = []
|
|
75
|
-
for (let i = 0; i < exportNames.length; i++) {
|
|
76
|
-
const exportName = exportNames[i]
|
|
77
|
-
const exportValue = exportValues[i]
|
|
78
|
-
objectProperties.push(
|
|
79
|
-
_core.types.objectProperty(
|
|
80
|
-
stringSpecifiers.has(exportName)
|
|
81
|
-
? _core.types.stringLiteral(exportName)
|
|
82
|
-
: _core.types.identifier(exportName),
|
|
83
|
-
exportValue,
|
|
84
|
-
),
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
|
-
statements.push(
|
|
88
|
-
_core.types.expressionStatement(
|
|
89
|
-
_core.types.callExpression(exportIdent, [
|
|
90
|
-
_core.types.objectExpression(objectProperties),
|
|
91
|
-
]),
|
|
92
|
-
),
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
const exportObj = path.scope.generateUid("exportObj")
|
|
97
|
-
statements.push(
|
|
98
|
-
_core.types.variableDeclaration("var", [
|
|
99
|
-
_core.types.variableDeclarator(
|
|
100
|
-
_core.types.identifier(exportObj),
|
|
101
|
-
_core.types.objectExpression([]),
|
|
102
|
-
),
|
|
103
|
-
]),
|
|
104
|
-
)
|
|
105
|
-
statements.push(
|
|
106
|
-
buildExportAll({
|
|
107
|
-
KEY: path.scope.generateUidIdentifier("key"),
|
|
108
|
-
EXPORT_OBJ: _core.types.identifier(exportObj),
|
|
109
|
-
TARGET: exportStarTarget,
|
|
110
|
-
}),
|
|
111
|
-
)
|
|
112
|
-
for (let i = 0; i < exportNames.length; i++) {
|
|
113
|
-
const exportName = exportNames[i]
|
|
114
|
-
const exportValue = exportValues[i]
|
|
115
|
-
statements.push(
|
|
116
|
-
_core.types.expressionStatement(
|
|
117
|
-
_core.types.assignmentExpression(
|
|
118
|
-
"=",
|
|
119
|
-
_core.types.memberExpression(
|
|
120
|
-
_core.types.identifier(exportObj),
|
|
121
|
-
_core.types.identifier(exportName),
|
|
122
|
-
),
|
|
123
|
-
exportValue,
|
|
124
|
-
),
|
|
125
|
-
),
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
statements.push(
|
|
129
|
-
_core.types.expressionStatement(
|
|
130
|
-
_core.types.callExpression(exportIdent, [
|
|
131
|
-
_core.types.identifier(exportObj),
|
|
132
|
-
]),
|
|
133
|
-
),
|
|
134
|
-
)
|
|
135
|
-
}
|
|
136
|
-
return statements
|
|
137
|
-
}
|
|
138
|
-
var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
|
139
|
-
api.assertVersion(7)
|
|
140
|
-
const { systemGlobal = "System", allowTopLevelThis = false } = options
|
|
141
|
-
const reassignmentVisited = new WeakSet()
|
|
142
|
-
const reassignmentVisitor = {
|
|
143
|
-
"AssignmentExpression|UpdateExpression"(path) {
|
|
144
|
-
if (reassignmentVisited.has(path.node)) return
|
|
145
|
-
reassignmentVisited.add(path.node)
|
|
146
|
-
const arg = path.isAssignmentExpression()
|
|
147
|
-
? path.get("left")
|
|
148
|
-
: path.get("argument")
|
|
149
|
-
if (arg.isObjectPattern() || arg.isArrayPattern()) {
|
|
150
|
-
const exprs = [path.node]
|
|
151
|
-
for (const name of Object.keys(arg.getBindingIdentifiers())) {
|
|
152
|
-
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) {
|
|
153
|
-
return
|
|
154
|
-
}
|
|
155
|
-
const exportedNames = this.exports[name]
|
|
156
|
-
if (!exportedNames) continue
|
|
157
|
-
for (const exportedName of exportedNames) {
|
|
158
|
-
exprs.push(
|
|
159
|
-
this.buildCall(exportedName, _core.types.identifier(name))
|
|
160
|
-
.expression,
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
path.replaceWith(_core.types.sequenceExpression(exprs))
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
if (!arg.isIdentifier()) return
|
|
168
|
-
const name = arg.node.name
|
|
169
|
-
|
|
170
|
-
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return
|
|
171
|
-
const exportedNames = this.exports[name]
|
|
172
|
-
if (!exportedNames) return
|
|
173
|
-
let node = path.node
|
|
174
|
-
|
|
175
|
-
const isPostUpdateExpression = _core.types.isUpdateExpression(node, {
|
|
176
|
-
prefix: false,
|
|
177
|
-
})
|
|
178
|
-
if (isPostUpdateExpression) {
|
|
179
|
-
node = _core.types.binaryExpression(
|
|
180
|
-
node.operator[0],
|
|
181
|
-
_core.types.unaryExpression(
|
|
182
|
-
"+",
|
|
183
|
-
_core.types.cloneNode(node.argument),
|
|
184
|
-
),
|
|
185
|
-
_core.types.numericLiteral(1),
|
|
186
|
-
)
|
|
187
|
-
}
|
|
188
|
-
for (const exportedName of exportedNames) {
|
|
189
|
-
node = this.buildCall(exportedName, node).expression
|
|
190
|
-
}
|
|
191
|
-
if (isPostUpdateExpression) {
|
|
192
|
-
node = _core.types.sequenceExpression([node, path.node])
|
|
193
|
-
}
|
|
194
|
-
path.replaceWith(node)
|
|
195
|
-
},
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
name: "transform-modules-systemjs",
|
|
199
|
-
pre() {
|
|
200
|
-
this.file.set("@babel/plugin-transform-modules-*", "systemjs")
|
|
201
|
-
},
|
|
202
|
-
visitor: {
|
|
203
|
-
CallExpression(path, state) {
|
|
204
|
-
if (_core.types.isImport(path.node.callee)) {
|
|
205
|
-
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) {
|
|
206
|
-
{
|
|
207
|
-
console.warn(MISSING_PLUGIN_WARNING)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
path.replaceWith(
|
|
211
|
-
(0, _helperModuleTransforms.buildDynamicImport)(
|
|
212
|
-
path.node,
|
|
213
|
-
false,
|
|
214
|
-
true,
|
|
215
|
-
(specifier) =>
|
|
216
|
-
_core.types.callExpression(
|
|
217
|
-
_core.types.memberExpression(
|
|
218
|
-
_core.types.identifier(state.contextIdent),
|
|
219
|
-
_core.types.identifier("import"),
|
|
220
|
-
),
|
|
221
|
-
[specifier],
|
|
222
|
-
),
|
|
223
|
-
),
|
|
224
|
-
)
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
MetaProperty(path, state) {
|
|
228
|
-
if (
|
|
229
|
-
path.node.meta.name === "import" &&
|
|
230
|
-
path.node.property.name === "meta"
|
|
231
|
-
) {
|
|
232
|
-
path.replaceWith(
|
|
233
|
-
_core.types.memberExpression(
|
|
234
|
-
_core.types.identifier(state.contextIdent),
|
|
235
|
-
_core.types.identifier("meta"),
|
|
236
|
-
),
|
|
237
|
-
)
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
ReferencedIdentifier(path, state) {
|
|
241
|
-
if (
|
|
242
|
-
path.node.name === "__moduleName" &&
|
|
243
|
-
!path.scope.hasBinding("__moduleName")
|
|
244
|
-
) {
|
|
245
|
-
path.replaceWith(
|
|
246
|
-
_core.types.memberExpression(
|
|
247
|
-
_core.types.identifier(state.contextIdent),
|
|
248
|
-
_core.types.identifier("id"),
|
|
249
|
-
),
|
|
250
|
-
)
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
Program: {
|
|
254
|
-
enter(path, state) {
|
|
255
|
-
state.contextIdent = path.scope.generateUid("context")
|
|
256
|
-
state.stringSpecifiers = new Set()
|
|
257
|
-
if (!allowTopLevelThis) {
|
|
258
|
-
;(0, _helperModuleTransforms.rewriteThis)(path)
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
exit(path, state) {
|
|
262
|
-
const scope = path.scope
|
|
263
|
-
const exportIdent = scope.generateUid("export")
|
|
264
|
-
const { contextIdent, stringSpecifiers } = state
|
|
265
|
-
const exportMap = Object.create(null)
|
|
266
|
-
const modules = []
|
|
267
|
-
const beforeBody = []
|
|
268
|
-
const setters = []
|
|
269
|
-
const sources = []
|
|
270
|
-
const variableIds = []
|
|
271
|
-
const removedPaths = []
|
|
272
|
-
function addExportName(key, val) {
|
|
273
|
-
exportMap[key] = exportMap[key] || []
|
|
274
|
-
exportMap[key].push(val)
|
|
275
|
-
}
|
|
276
|
-
function pushModule(source, key, specifiers) {
|
|
277
|
-
let module
|
|
278
|
-
modules.forEach(function (m) {
|
|
279
|
-
if (m.key === source) {
|
|
280
|
-
module = m
|
|
281
|
-
}
|
|
282
|
-
})
|
|
283
|
-
if (!module) {
|
|
284
|
-
modules.push(
|
|
285
|
-
(module = {
|
|
286
|
-
key: source,
|
|
287
|
-
imports: [],
|
|
288
|
-
exports: [],
|
|
289
|
-
}),
|
|
290
|
-
)
|
|
291
|
-
}
|
|
292
|
-
module[key] = module[key].concat(specifiers)
|
|
293
|
-
}
|
|
294
|
-
function buildExportCall(name, val) {
|
|
295
|
-
return _core.types.expressionStatement(
|
|
296
|
-
_core.types.callExpression(_core.types.identifier(exportIdent), [
|
|
297
|
-
_core.types.stringLiteral(name),
|
|
298
|
-
val,
|
|
299
|
-
]),
|
|
300
|
-
)
|
|
301
|
-
}
|
|
302
|
-
const exportNames = []
|
|
303
|
-
const exportValues = []
|
|
304
|
-
const body = path.get("body")
|
|
305
|
-
for (const path of body) {
|
|
306
|
-
if (path.isFunctionDeclaration()) {
|
|
307
|
-
beforeBody.push(path.node)
|
|
308
|
-
removedPaths.push(path)
|
|
309
|
-
} else if (path.isClassDeclaration()) {
|
|
310
|
-
variableIds.push(_core.types.cloneNode(path.node.id))
|
|
311
|
-
path.replaceWith(
|
|
312
|
-
_core.types.expressionStatement(
|
|
313
|
-
_core.types.assignmentExpression(
|
|
314
|
-
"=",
|
|
315
|
-
_core.types.cloneNode(path.node.id),
|
|
316
|
-
_core.types.toExpression(path.node),
|
|
317
|
-
),
|
|
318
|
-
),
|
|
319
|
-
)
|
|
320
|
-
} else if (path.isVariableDeclaration()) {
|
|
321
|
-
path.node.kind = "var"
|
|
322
|
-
} else if (path.isImportDeclaration()) {
|
|
323
|
-
const source = path.node.source.value
|
|
324
|
-
pushModule(source, "imports", path.node.specifiers)
|
|
325
|
-
for (const name of Object.keys(path.getBindingIdentifiers())) {
|
|
326
|
-
scope.removeBinding(name)
|
|
327
|
-
variableIds.push(_core.types.identifier(name))
|
|
328
|
-
}
|
|
329
|
-
path.remove()
|
|
330
|
-
} else if (path.isExportAllDeclaration()) {
|
|
331
|
-
pushModule(path.node.source.value, "exports", path.node)
|
|
332
|
-
path.remove()
|
|
333
|
-
} else if (path.isExportDefaultDeclaration()) {
|
|
334
|
-
const declar = path.node.declaration
|
|
335
|
-
if (_core.types.isClassDeclaration(declar)) {
|
|
336
|
-
const id = declar.id
|
|
337
|
-
if (id) {
|
|
338
|
-
exportNames.push("default")
|
|
339
|
-
exportValues.push(scope.buildUndefinedNode())
|
|
340
|
-
variableIds.push(_core.types.cloneNode(id))
|
|
341
|
-
addExportName(id.name, "default")
|
|
342
|
-
path.replaceWith(
|
|
343
|
-
_core.types.expressionStatement(
|
|
344
|
-
_core.types.assignmentExpression(
|
|
345
|
-
"=",
|
|
346
|
-
_core.types.cloneNode(id),
|
|
347
|
-
_core.types.toExpression(declar),
|
|
348
|
-
),
|
|
349
|
-
),
|
|
350
|
-
)
|
|
351
|
-
} else {
|
|
352
|
-
exportNames.push("default")
|
|
353
|
-
exportValues.push(_core.types.toExpression(declar))
|
|
354
|
-
removedPaths.push(path)
|
|
355
|
-
}
|
|
356
|
-
} else if (_core.types.isFunctionDeclaration(declar)) {
|
|
357
|
-
const id = declar.id
|
|
358
|
-
if (id) {
|
|
359
|
-
beforeBody.push(declar)
|
|
360
|
-
exportNames.push("default")
|
|
361
|
-
exportValues.push(_core.types.cloneNode(id))
|
|
362
|
-
addExportName(id.name, "default")
|
|
363
|
-
} else {
|
|
364
|
-
exportNames.push("default")
|
|
365
|
-
exportValues.push(_core.types.toExpression(declar))
|
|
366
|
-
}
|
|
367
|
-
removedPaths.push(path)
|
|
368
|
-
} else {
|
|
369
|
-
path.replaceWith(buildExportCall("default", declar))
|
|
370
|
-
}
|
|
371
|
-
} else if (path.isExportNamedDeclaration()) {
|
|
372
|
-
const declar = path.node.declaration
|
|
373
|
-
if (declar) {
|
|
374
|
-
path.replaceWith(declar)
|
|
375
|
-
if (_core.types.isFunction(declar)) {
|
|
376
|
-
const name = declar.id.name
|
|
377
|
-
addExportName(name, name)
|
|
378
|
-
beforeBody.push(declar)
|
|
379
|
-
exportNames.push(name)
|
|
380
|
-
exportValues.push(_core.types.cloneNode(declar.id))
|
|
381
|
-
removedPaths.push(path)
|
|
382
|
-
} else if (_core.types.isClass(declar)) {
|
|
383
|
-
const name = declar.id.name
|
|
384
|
-
exportNames.push(name)
|
|
385
|
-
exportValues.push(scope.buildUndefinedNode())
|
|
386
|
-
variableIds.push(_core.types.cloneNode(declar.id))
|
|
387
|
-
path.replaceWith(
|
|
388
|
-
_core.types.expressionStatement(
|
|
389
|
-
_core.types.assignmentExpression(
|
|
390
|
-
"=",
|
|
391
|
-
_core.types.cloneNode(declar.id),
|
|
392
|
-
_core.types.toExpression(declar),
|
|
393
|
-
),
|
|
394
|
-
),
|
|
395
|
-
)
|
|
396
|
-
addExportName(name, name)
|
|
397
|
-
} else {
|
|
398
|
-
if (_core.types.isVariableDeclaration(declar)) {
|
|
399
|
-
declar.kind = "var"
|
|
400
|
-
}
|
|
401
|
-
for (const name of Object.keys(
|
|
402
|
-
_core.types.getBindingIdentifiers(declar),
|
|
403
|
-
)) {
|
|
404
|
-
addExportName(name, name)
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
} else {
|
|
408
|
-
const specifiers = path.node.specifiers
|
|
409
|
-
if (specifiers != null && specifiers.length) {
|
|
410
|
-
if (path.node.source) {
|
|
411
|
-
pushModule(path.node.source.value, "exports", specifiers)
|
|
412
|
-
path.remove()
|
|
413
|
-
} else {
|
|
414
|
-
const nodes = []
|
|
415
|
-
for (const specifier of specifiers) {
|
|
416
|
-
const { local, exported } = specifier
|
|
417
|
-
const binding = scope.getBinding(local.name)
|
|
418
|
-
const exportedName = getExportSpecifierName(
|
|
419
|
-
exported,
|
|
420
|
-
stringSpecifiers,
|
|
421
|
-
)
|
|
422
|
-
if (
|
|
423
|
-
binding &&
|
|
424
|
-
_core.types.isFunctionDeclaration(binding.path.node)
|
|
425
|
-
) {
|
|
426
|
-
exportNames.push(exportedName)
|
|
427
|
-
exportValues.push(_core.types.cloneNode(local))
|
|
428
|
-
} else if (!binding) {
|
|
429
|
-
nodes.push(buildExportCall(exportedName, local))
|
|
430
|
-
}
|
|
431
|
-
addExportName(local.name, exportedName)
|
|
432
|
-
}
|
|
433
|
-
path.replaceWithMultiple(nodes)
|
|
434
|
-
}
|
|
435
|
-
} else {
|
|
436
|
-
path.remove()
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
modules.forEach(function (specifiers) {
|
|
442
|
-
const setterBody = []
|
|
443
|
-
// --- START FORK CHANGES ---
|
|
444
|
-
const targetHint = state.opts.generateIdentifierHint
|
|
445
|
-
? state.opts.generateIdentifierHint(specifiers.key)
|
|
446
|
-
: specifiers.key
|
|
447
|
-
const target = scope.generateUid(targetHint)
|
|
448
|
-
// --- END FORK CHANGES ---
|
|
449
|
-
for (let specifier of specifiers.imports) {
|
|
450
|
-
if (_core.types.isImportNamespaceSpecifier(specifier)) {
|
|
451
|
-
setterBody.push(
|
|
452
|
-
_core.types.expressionStatement(
|
|
453
|
-
_core.types.assignmentExpression(
|
|
454
|
-
"=",
|
|
455
|
-
specifier.local,
|
|
456
|
-
_core.types.identifier(target),
|
|
457
|
-
),
|
|
458
|
-
),
|
|
459
|
-
)
|
|
460
|
-
} else if (_core.types.isImportDefaultSpecifier(specifier)) {
|
|
461
|
-
specifier = _core.types.importSpecifier(
|
|
462
|
-
specifier.local,
|
|
463
|
-
_core.types.identifier("default"),
|
|
464
|
-
)
|
|
465
|
-
}
|
|
466
|
-
if (_core.types.isImportSpecifier(specifier)) {
|
|
467
|
-
const { imported } = specifier
|
|
468
|
-
setterBody.push(
|
|
469
|
-
_core.types.expressionStatement(
|
|
470
|
-
_core.types.assignmentExpression(
|
|
471
|
-
"=",
|
|
472
|
-
specifier.local,
|
|
473
|
-
_core.types.memberExpression(
|
|
474
|
-
_core.types.identifier(target),
|
|
475
|
-
specifier.imported,
|
|
476
|
-
imported.type === "StringLiteral",
|
|
477
|
-
),
|
|
478
|
-
),
|
|
479
|
-
),
|
|
480
|
-
)
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
if (specifiers.exports.length) {
|
|
484
|
-
const exportNames = []
|
|
485
|
-
const exportValues = []
|
|
486
|
-
let hasExportStar = false
|
|
487
|
-
for (const node of specifiers.exports) {
|
|
488
|
-
if (_core.types.isExportAllDeclaration(node)) {
|
|
489
|
-
hasExportStar = true
|
|
490
|
-
} else if (_core.types.isExportSpecifier(node)) {
|
|
491
|
-
const exportedName = getExportSpecifierName(
|
|
492
|
-
node.exported,
|
|
493
|
-
stringSpecifiers,
|
|
494
|
-
)
|
|
495
|
-
exportNames.push(exportedName)
|
|
496
|
-
exportValues.push(
|
|
497
|
-
_core.types.memberExpression(
|
|
498
|
-
_core.types.identifier(target),
|
|
499
|
-
node.local,
|
|
500
|
-
_core.types.isStringLiteral(node.local),
|
|
501
|
-
),
|
|
502
|
-
)
|
|
503
|
-
} else {
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
setterBody.push(
|
|
508
|
-
...constructExportCall(
|
|
509
|
-
path,
|
|
510
|
-
_core.types.identifier(exportIdent),
|
|
511
|
-
exportNames,
|
|
512
|
-
exportValues,
|
|
513
|
-
hasExportStar ? _core.types.identifier(target) : null,
|
|
514
|
-
stringSpecifiers,
|
|
515
|
-
),
|
|
516
|
-
)
|
|
517
|
-
}
|
|
518
|
-
sources.push(_core.types.stringLiteral(specifiers.key))
|
|
519
|
-
setters.push(
|
|
520
|
-
_core.types.functionExpression(
|
|
521
|
-
null,
|
|
522
|
-
[_core.types.identifier(target)],
|
|
523
|
-
_core.types.blockStatement(setterBody),
|
|
524
|
-
),
|
|
525
|
-
)
|
|
526
|
-
})
|
|
527
|
-
let moduleName = (0, _helperModuleTransforms.getModuleName)(
|
|
528
|
-
this.file.opts,
|
|
529
|
-
options,
|
|
530
|
-
)
|
|
531
|
-
if (moduleName) moduleName = _core.types.stringLiteral(moduleName)
|
|
532
|
-
;(0, _helperHoistVariables.default)(path, (id, name, hasInit) => {
|
|
533
|
-
variableIds.push(id)
|
|
534
|
-
if (!hasInit && name in exportMap) {
|
|
535
|
-
for (const exported of exportMap[name]) {
|
|
536
|
-
exportNames.push(exported)
|
|
537
|
-
exportValues.push(scope.buildUndefinedNode())
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
})
|
|
541
|
-
if (variableIds.length) {
|
|
542
|
-
beforeBody.unshift(
|
|
543
|
-
_core.types.variableDeclaration(
|
|
544
|
-
"var",
|
|
545
|
-
variableIds.map((id) => _core.types.variableDeclarator(id)),
|
|
546
|
-
),
|
|
547
|
-
)
|
|
548
|
-
}
|
|
549
|
-
if (exportNames.length) {
|
|
550
|
-
beforeBody.push(
|
|
551
|
-
...constructExportCall(
|
|
552
|
-
path,
|
|
553
|
-
_core.types.identifier(exportIdent),
|
|
554
|
-
exportNames,
|
|
555
|
-
exportValues,
|
|
556
|
-
null,
|
|
557
|
-
stringSpecifiers,
|
|
558
|
-
),
|
|
559
|
-
)
|
|
560
|
-
}
|
|
561
|
-
path.traverse(reassignmentVisitor, {
|
|
562
|
-
exports: exportMap,
|
|
563
|
-
buildCall: buildExportCall,
|
|
564
|
-
scope,
|
|
565
|
-
})
|
|
566
|
-
for (const path of removedPaths) {
|
|
567
|
-
path.remove()
|
|
568
|
-
}
|
|
569
|
-
let hasTLA = false
|
|
570
|
-
path.traverse({
|
|
571
|
-
AwaitExpression(path) {
|
|
572
|
-
hasTLA = true
|
|
573
|
-
path.stop()
|
|
574
|
-
},
|
|
575
|
-
Function(path) {
|
|
576
|
-
path.skip()
|
|
577
|
-
},
|
|
578
|
-
noScope: true,
|
|
579
|
-
})
|
|
580
|
-
path.node.body = [
|
|
581
|
-
buildTemplate({
|
|
582
|
-
SYSTEM_REGISTER: _core.types.memberExpression(
|
|
583
|
-
_core.types.identifier(systemGlobal),
|
|
584
|
-
_core.types.identifier("register"),
|
|
585
|
-
),
|
|
586
|
-
BEFORE_BODY: beforeBody,
|
|
587
|
-
MODULE_NAME: moduleName,
|
|
588
|
-
SETTERS: _core.types.arrayExpression(setters),
|
|
589
|
-
EXECUTE: _core.types.functionExpression(
|
|
590
|
-
null,
|
|
591
|
-
[],
|
|
592
|
-
_core.types.blockStatement(path.node.body),
|
|
593
|
-
false,
|
|
594
|
-
hasTLA,
|
|
595
|
-
),
|
|
596
|
-
SOURCES: _core.types.arrayExpression(sources),
|
|
597
|
-
EXPORT_IDENTIFIER: _core.types.identifier(exportIdent),
|
|
598
|
-
CONTEXT_IDENTIFIER: _core.types.identifier(contextIdent),
|
|
599
|
-
}),
|
|
600
|
-
]
|
|
601
|
-
},
|
|
602
|
-
},
|
|
603
|
-
},
|
|
604
|
-
}
|
|
605
|
-
})
|
|
606
|
-
exports.default = _default
|
|
607
|
-
|
|
608
|
-
//# sourceMappingURL=index.js.map
|