@marko/compiler 5.39.49 → 5.39.51
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/babel-plugin/file.js +2 -2
- package/dist/babel-plugin/index.js +24 -19
- package/dist/babel-plugin/parser.js +39 -39
- package/dist/babel-plugin/plugins/migrate.js +4 -4
- package/dist/babel-plugin/plugins/transform.js +4 -4
- package/dist/babel-utils/imports.js +2 -2
- package/dist/babel-utils/parse.js +12 -9
- package/dist/babel-utils/tags.js +2 -2
- package/dist/babel-utils/template-string.js +2 -2
- package/dist/babel.js +65127 -0
- package/dist/config.js +2 -2
- package/dist/index.js +18 -10
- package/dist/taglib/index.js +2 -2
- package/dist/types.d.ts +11 -11
- package/dist/util/build-code-frame.js +3 -3
- package/dist/util/try-load-translator.js +2 -2
- package/internal/babel/index.ts +22 -0
- package/internal/babel/modules.d.ts +3 -0
- package/internal/babel/package.json +5 -0
- package/package.json +8 -15
- package/dist/babel-types/generator/patch.js +0 -377
- package/dist/babel-types/index.js +0 -5
- package/dist/babel-types/traverse/patch.js +0 -133
- package/dist/babel-types/types/definitions.js +0 -254
- package/dist/babel-types/types/patch.js +0 -122
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");require("../types/patch");
|
|
2
|
-
|
|
3
|
-
var _printer = _interopRequireDefault(require("@babel/generator/lib/printer"));
|
|
4
|
-
var t = _interopRequireWildcard(require("@babel/types"));
|
|
5
|
-
var _selfClosingTags = _interopRequireDefault(require("self-closing-tags"));function _interopRequireWildcard(e, t) {if ("function" == typeof WeakMap) var r = new WeakMap(),n = new WeakMap();return (_interopRequireWildcard = function (e, t) {if (!t && e && e.__esModule) return e;var o,i,f = { __proto__: null, default: e };if (null === e || "object" != typeof e && "function" != typeof e) return f;if (o = t ? n : r) {if (o.has(e)) return o.get(e);o.set(e, f);}for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);return f;})(e, t);}
|
|
6
|
-
|
|
7
|
-
Object.assign(_printer.default.prototype, {
|
|
8
|
-
MarkoParseError(node) {
|
|
9
|
-
this.token(node.source);
|
|
10
|
-
},
|
|
11
|
-
MarkoDocumentType(node) {
|
|
12
|
-
this.token("<!");
|
|
13
|
-
this.token(node.value);
|
|
14
|
-
this.token(">");
|
|
15
|
-
},
|
|
16
|
-
MarkoDeclaration(node) {
|
|
17
|
-
this.token("<?");
|
|
18
|
-
this.token(node.value);
|
|
19
|
-
this.token("?>");
|
|
20
|
-
},
|
|
21
|
-
MarkoCDATA(node) {
|
|
22
|
-
this.token("<![CDATA[");
|
|
23
|
-
this.token(node.value);
|
|
24
|
-
this.token("]]>");
|
|
25
|
-
},
|
|
26
|
-
MarkoComment(node) {
|
|
27
|
-
this.token("<!--");
|
|
28
|
-
this.token(node.value);
|
|
29
|
-
this.token("-->");
|
|
30
|
-
},
|
|
31
|
-
MarkoPlaceholder(node, parent) {
|
|
32
|
-
if (parent) {
|
|
33
|
-
const parentBody = getBody(parent);
|
|
34
|
-
const prev = parentBody[parentBody.indexOf(node) - 1];
|
|
35
|
-
|
|
36
|
-
if (prev && (t.isMarkoText(prev) || t.isMarkoPlaceholder(prev))) {
|
|
37
|
-
this.removeTrailingNewline();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.token(node.escape ? "${" : "$!{");
|
|
42
|
-
this.print(node.value);
|
|
43
|
-
this.token("}");
|
|
44
|
-
},
|
|
45
|
-
MarkoScriptlet(node, parent) {
|
|
46
|
-
this.removeTrailingNewline();
|
|
47
|
-
|
|
48
|
-
if (!(t.isProgram(parent) && getBody(parent)[0] === node)) {
|
|
49
|
-
this.token("\n");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.token(`${node.static ? node.target ?? "static" : "$"} `);
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
node.body.length === 1 &&
|
|
56
|
-
!statementCouldHaveUnenclosedNewline(node.body[0]))
|
|
57
|
-
{
|
|
58
|
-
// TODO should determine if node has unenclosed newlines.
|
|
59
|
-
this.print(node.body[0]);
|
|
60
|
-
} else {
|
|
61
|
-
this.token("{");
|
|
62
|
-
this.newline();
|
|
63
|
-
this.indent();
|
|
64
|
-
this.printSequence(node.body);
|
|
65
|
-
this.dedent();
|
|
66
|
-
this.token("}");
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
MarkoClass(node) {
|
|
70
|
-
this.token("class");
|
|
71
|
-
this.token(" ");
|
|
72
|
-
this.print(node.body);
|
|
73
|
-
},
|
|
74
|
-
MarkoAttribute(node) {
|
|
75
|
-
const value = node.value;
|
|
76
|
-
|
|
77
|
-
if (!node.default) {
|
|
78
|
-
this.token(node.name);
|
|
79
|
-
|
|
80
|
-
if (node.modifier) {
|
|
81
|
-
this.token(":");
|
|
82
|
-
this.token(node.modifier);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (node.arguments && node.arguments.length) {
|
|
86
|
-
this.token("(");
|
|
87
|
-
this.printList(node.arguments);
|
|
88
|
-
this.token(")");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (node.default || !t.isBooleanLiteral(value, { value: true })) {
|
|
93
|
-
if (
|
|
94
|
-
t.isFunctionExpression(value) &&
|
|
95
|
-
!(value.id || value.async || value.generator))
|
|
96
|
-
{
|
|
97
|
-
this.token("(");
|
|
98
|
-
this.printList(value.params);
|
|
99
|
-
this.token(") ");
|
|
100
|
-
this.print(value.body);
|
|
101
|
-
} else {
|
|
102
|
-
this.token(node.bound ? ":=" : "=");
|
|
103
|
-
printWithParansIfNeeded.call(this, value);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
MarkoSpreadAttribute(node) {
|
|
108
|
-
this.token("...");
|
|
109
|
-
printWithParansIfNeeded.call(this, node.value);
|
|
110
|
-
},
|
|
111
|
-
MarkoText(node, parent) {
|
|
112
|
-
const parentBody = getBody(parent);
|
|
113
|
-
const prev = parentBody[parentBody.indexOf(node) - 1];
|
|
114
|
-
const concatToPrev = prev && t.isMarkoPlaceholder(prev);
|
|
115
|
-
let { value } = node;
|
|
116
|
-
|
|
117
|
-
if (concatToPrev) {
|
|
118
|
-
this.removeTrailingNewline();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const isMultiLine = /[\r\n]/g.test(value);
|
|
122
|
-
const isRootLevel = !concatToPrev && t.isProgram(parent);
|
|
123
|
-
|
|
124
|
-
if (isRootLevel) {
|
|
125
|
-
if (isMultiLine) {
|
|
126
|
-
this.token("---\n");
|
|
127
|
-
} else {
|
|
128
|
-
this.token("-- ");
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this.word(value);
|
|
133
|
-
|
|
134
|
-
if (isMultiLine && isRootLevel) {
|
|
135
|
-
this.token("\n---");
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
MarkoTagBody(node) {
|
|
139
|
-
this.printSequence(node.body, true);
|
|
140
|
-
},
|
|
141
|
-
MarkoTag(node) {
|
|
142
|
-
const isDynamicTag = !t.isStringLiteral(node.name);
|
|
143
|
-
const tagName = !isDynamicTag && node.name.value;
|
|
144
|
-
const rawValue = node.rawValue;
|
|
145
|
-
let bodyOverride;
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
tagName === "style" &&
|
|
149
|
-
/^style(?:\.[^\s]+)?\s*\{[\s\S]*}$/.test(rawValue))
|
|
150
|
-
{
|
|
151
|
-
this.token(rawValue);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
this.token("<");
|
|
156
|
-
|
|
157
|
-
if (rawValue) {
|
|
158
|
-
this.token(rawValue);
|
|
159
|
-
} else {
|
|
160
|
-
if (isDynamicTag) {
|
|
161
|
-
this.token("${");
|
|
162
|
-
this.print(node.name);
|
|
163
|
-
this.token("}");
|
|
164
|
-
} else {
|
|
165
|
-
this.token(tagName);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (node.typeArguments) {
|
|
169
|
-
this.token("<");
|
|
170
|
-
this.printList(node.typeArguments.params);
|
|
171
|
-
this.token(">");
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (node.var) {
|
|
175
|
-
this.token("/");
|
|
176
|
-
this.print(node.var);
|
|
177
|
-
|
|
178
|
-
if (node.var.typeAnnotation) {
|
|
179
|
-
this.print(node.var.typeAnnotation);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (node.arguments && node.arguments.length) {
|
|
184
|
-
this.token("(");
|
|
185
|
-
this.printList(node.arguments);
|
|
186
|
-
this.token(")");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (node.body.params.length) {
|
|
190
|
-
if (node.body.typeParameters) {
|
|
191
|
-
if (!node.typeArguments) {
|
|
192
|
-
this.token(" ");
|
|
193
|
-
}
|
|
194
|
-
this.token("<");
|
|
195
|
-
this.printList(node.body.typeParameters.params);
|
|
196
|
-
this.token(">");
|
|
197
|
-
}
|
|
198
|
-
this.token("|");
|
|
199
|
-
this.printList(node.body.params);
|
|
200
|
-
this.token("|");
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let { attributes } = node;
|
|
204
|
-
if (attributes.length) {
|
|
205
|
-
if (tagName === "script") {
|
|
206
|
-
for (let i = attributes.length; i--;) {
|
|
207
|
-
const attr = attributes[i];
|
|
208
|
-
if (
|
|
209
|
-
attr.name === "value" && (
|
|
210
|
-
attr.value.type === "ArrowFunctionExpression" ||
|
|
211
|
-
attr.value.type === "FunctionExpression") &&
|
|
212
|
-
!(
|
|
213
|
-
attr.value.generator ||
|
|
214
|
-
attr.value.returnType ||
|
|
215
|
-
attr.value.typeParameters))
|
|
216
|
-
|
|
217
|
-
{
|
|
218
|
-
bodyOverride = attributes[i].value.body.body;
|
|
219
|
-
attributes = toSpliced(attributes, i);
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (!(attributes && attributes[0] && attributes[0].default)) {
|
|
226
|
-
this.token(" ");
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
this.printJoin(attributes, undefined, undefined, spaceSeparator);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (_selfClosingTags.default.voidElements.includes(tagName)) {
|
|
234
|
-
this.token(">");
|
|
235
|
-
} else if (
|
|
236
|
-
!(bodyOverride || node.body.body.length || node.attributeTags.length) ||
|
|
237
|
-
_selfClosingTags.default.svgElements.includes(tagName))
|
|
238
|
-
{
|
|
239
|
-
this.token("/>");
|
|
240
|
-
} else {
|
|
241
|
-
this.token(">");
|
|
242
|
-
this.newline();
|
|
243
|
-
this.printSequence(bodyOverride || zipAttributeTagsAndBody(node), true);
|
|
244
|
-
this.token("</");
|
|
245
|
-
if (!isDynamicTag) {
|
|
246
|
-
this.token(tagName);
|
|
247
|
-
}
|
|
248
|
-
this.token(">");
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
function spaceSeparator() {
|
|
254
|
-
this.token(" ");
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function printWithParansIfNeeded(value) {
|
|
258
|
-
const needsParans = expressionCouldHaveUnenclosedWhitespace(value);
|
|
259
|
-
|
|
260
|
-
if (needsParans) {
|
|
261
|
-
this.token("(");
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
this.print(value);
|
|
265
|
-
|
|
266
|
-
if (needsParans) {
|
|
267
|
-
this.token(")");
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function expressionCouldHaveUnenclosedWhitespace(node) {
|
|
272
|
-
switch (node.type) {
|
|
273
|
-
case "AssignmentExpression":
|
|
274
|
-
case "BinaryExpression":
|
|
275
|
-
case "ConditionalExpression":
|
|
276
|
-
case "Function":
|
|
277
|
-
case "LogicalExpression":
|
|
278
|
-
case "NewExpression":
|
|
279
|
-
return true;
|
|
280
|
-
default:
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* @param {import("@marko/compiler").types.Expression} node
|
|
287
|
-
*/
|
|
288
|
-
function statementCouldHaveUnenclosedNewline(node) {
|
|
289
|
-
if (node.leadingComments?.length || node.trailingComments?.length) {
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
switch (node.type) {
|
|
294
|
-
case "VariableDeclaration":
|
|
295
|
-
return node.declarations.length > 1;
|
|
296
|
-
default:
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function zipAttributeTagsAndBody(tag) {
|
|
302
|
-
const {
|
|
303
|
-
attributeTags,
|
|
304
|
-
body: { body }
|
|
305
|
-
} = tag;
|
|
306
|
-
const bodyLen = body.length;
|
|
307
|
-
const attributeTagsLen = attributeTags.length;
|
|
308
|
-
if (!attributeTagsLen) return body;
|
|
309
|
-
if (!bodyLen) return attributeTags;
|
|
310
|
-
|
|
311
|
-
const result = [];
|
|
312
|
-
let i = 0;
|
|
313
|
-
let j = 0;
|
|
314
|
-
|
|
315
|
-
while (i < bodyLen && j < attributeTagsLen) {
|
|
316
|
-
const bodyNode = body[i];
|
|
317
|
-
const attributeTag = attributeTags[j];
|
|
318
|
-
|
|
319
|
-
if (bodyNode.loc != null && attributeTag.loc != null) {
|
|
320
|
-
if (compareStartLoc(bodyNode, attributeTag) < 0) {
|
|
321
|
-
result.push(bodyNode);
|
|
322
|
-
i++;
|
|
323
|
-
} else {
|
|
324
|
-
result.push(attributeTag);
|
|
325
|
-
j++;
|
|
326
|
-
}
|
|
327
|
-
} else if (j < attributeTagsLen) {
|
|
328
|
-
result.push(attributeTag);
|
|
329
|
-
j++;
|
|
330
|
-
} else {
|
|
331
|
-
result.push(bodyNode);
|
|
332
|
-
i++;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
while (j < attributeTagsLen) {
|
|
337
|
-
result.push(attributeTags[j++]);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
while (i < bodyLen) {
|
|
341
|
-
result.push(body[i++]);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return result;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function getBody(parent) {
|
|
348
|
-
switch (parent.type) {
|
|
349
|
-
case "MarkoTag":
|
|
350
|
-
return parent.body.body;
|
|
351
|
-
default:
|
|
352
|
-
return parent.body;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function compareStartLoc(a, b) {
|
|
357
|
-
return (
|
|
358
|
-
a.loc.start.line - b.loc.start.line ||
|
|
359
|
-
a.loc.start.column - b.loc.start.column);
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function toSpliced(arr, index) {
|
|
364
|
-
const len = arr.length;
|
|
365
|
-
const result = new Array(len - 1);
|
|
366
|
-
let i = 0;
|
|
367
|
-
|
|
368
|
-
for (; i < index; i++) {
|
|
369
|
-
result[i] = arr[i];
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
for (i++; i < len; i++) {
|
|
373
|
-
result[i - 1] = arr[i];
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return result;
|
|
377
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";exports.__esModule = true;var _exportNames = { MARKO_TYPES: true };exports.MARKO_TYPES = void 0;require("./types/patch");
|
|
2
|
-
require("./traverse/patch");
|
|
3
|
-
require("./generator/patch");
|
|
4
|
-
var _definitions = require("./types/definitions");exports.MARKO_TYPES = _definitions.MARKO_TYPES;
|
|
5
|
-
var _types = require("@babel/types");Object.keys(_types).forEach(function (key) {if (key === "default" || key === "__esModule") return;if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;if (key in exports && exports[key] === _types[key]) return;exports[key] = _types[key];});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";require("../types/patch");
|
|
2
|
-
|
|
3
|
-
var _traverse = _interopRequireWildcard(require("@babel/traverse"));
|
|
4
|
-
var t = _interopRequireWildcard(require("@babel/types"));
|
|
5
|
-
|
|
6
|
-
var _definitions = require("../types/definitions");function _interopRequireWildcard(e, t) {if ("function" == typeof WeakMap) var r = new WeakMap(),n = new WeakMap();return (_interopRequireWildcard = function (e, t) {if (!t && e && e.__esModule) return e;var o,i,f = { __proto__: null, default: e };if (null === e || "object" != typeof e && "function" != typeof e) return f;if (o = t ? n : r) {if (o.has(e)) return o.get(e);o.set(e, f);}for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);return f;})(e, t);}
|
|
7
|
-
|
|
8
|
-
_definitions.MARKO_TYPES.forEach((typeName) => {
|
|
9
|
-
const checkKey = `is${typeName}`;
|
|
10
|
-
const assertKey = `assert${typeName}`;
|
|
11
|
-
const checkFn = t[checkKey];
|
|
12
|
-
const assertFn = t[assertKey];
|
|
13
|
-
_traverse.NodePath.prototype[checkKey] = function (opts) {
|
|
14
|
-
return checkFn(this.node, opts);
|
|
15
|
-
};
|
|
16
|
-
_traverse.NodePath.prototype[assertKey] = function (opts) {
|
|
17
|
-
assertFn(this.node, opts);
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
_definitions.MARKO_ALIAS_TYPES.forEach((aliasName) => {
|
|
22
|
-
const checkKey = `is${aliasName}`;
|
|
23
|
-
const originalProtoCheck = _traverse.NodePath.prototype[checkKey];
|
|
24
|
-
_traverse.NodePath.prototype[checkKey] = function (opts) {
|
|
25
|
-
return (
|
|
26
|
-
t.is(aliasName, this.node, opts) ||
|
|
27
|
-
originalProtoCheck.call(this, this.node, opts));
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Adds a one time patch to the scope collector visitors to include
|
|
33
|
-
// Marko bindings for params and tag vars.
|
|
34
|
-
const originalCrawl = _traverse.Scope.prototype.crawl;
|
|
35
|
-
const patchedVisitors = new WeakSet();
|
|
36
|
-
|
|
37
|
-
_traverse.Scope.prototype.crawl = function () {
|
|
38
|
-
const path = this.path;
|
|
39
|
-
const originalTraverse = path.traverse;
|
|
40
|
-
path.traverse = function (visitor, state) {
|
|
41
|
-
state.hoistableTagVarsByScope = new Map();
|
|
42
|
-
path.traverse = originalTraverse;
|
|
43
|
-
|
|
44
|
-
if (!patchedVisitors.has(visitor)) {
|
|
45
|
-
patchedVisitors.add(visitor);
|
|
46
|
-
Object.assign(
|
|
47
|
-
_traverse.default.explode(visitor),
|
|
48
|
-
_traverse.default.explode({
|
|
49
|
-
MarkoTagBody(body) {
|
|
50
|
-
for (const param of body.get("params")) {
|
|
51
|
-
body.scope.registerBinding("param", param);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
MarkoTag(tag, state) {
|
|
55
|
-
const tagVar = tag.get("var");
|
|
56
|
-
if (tagVar.node) {
|
|
57
|
-
tag.scope.registerBinding("local", tagVar, tag);
|
|
58
|
-
for (const name in tagVar.getBindingIdentifiers()) {
|
|
59
|
-
let curScope = tag.scope;
|
|
60
|
-
const binding = curScope.getBinding(name);
|
|
61
|
-
|
|
62
|
-
while (curScope = curScope.parent) {
|
|
63
|
-
const hoistableTagVars =
|
|
64
|
-
state.hoistableTagVarsByScope.get(curScope);
|
|
65
|
-
|
|
66
|
-
if (hoistableTagVars) {
|
|
67
|
-
hoistableTagVars[name] = hoistableTagVars[name] ?
|
|
68
|
-
true :
|
|
69
|
-
binding;
|
|
70
|
-
} else {
|
|
71
|
-
state.hoistableTagVarsByScope.set(curScope, {
|
|
72
|
-
[name]: binding
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (this.type === "Program" && this.node.params?.length) {
|
|
84
|
-
this.scope.registerBinding("params", this);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.traverse(visitor, state);
|
|
88
|
-
|
|
89
|
-
if (state.references.length) {
|
|
90
|
-
const movedBindings = new Map();
|
|
91
|
-
for (const ref of state.references) {
|
|
92
|
-
const { name } = ref.node;
|
|
93
|
-
let curScope = ref.scope;
|
|
94
|
-
if (curScope.hasBinding(name)) continue;
|
|
95
|
-
|
|
96
|
-
do {
|
|
97
|
-
const hoistableBinding =
|
|
98
|
-
state.hoistableTagVarsByScope.get(curScope)?.[name];
|
|
99
|
-
|
|
100
|
-
if (hoistableBinding) {
|
|
101
|
-
if (hoistableBinding === true) {
|
|
102
|
-
throw ref.buildCodeFrameError(
|
|
103
|
-
"Ambiguous reference, variable was defined in multiple places and was not shadowed."
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const movedBinding = movedBindings.get(hoistableBinding);
|
|
108
|
-
if (
|
|
109
|
-
!movedBinding ||
|
|
110
|
-
getScopeDepth(movedBinding) > getScopeDepth(curScope))
|
|
111
|
-
{
|
|
112
|
-
movedBindings.set(hoistableBinding, curScope);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} while (curScope = curScope.parent);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
for (const [binding, scope] of movedBindings) {
|
|
119
|
-
binding.scope.moveBindingTo(binding.identifier.name, scope);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
originalCrawl.call(this);
|
|
125
|
-
path.traverse = originalTraverse;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
function getScopeDepth(scope) {
|
|
129
|
-
let depth = 0;
|
|
130
|
-
let cur = scope;
|
|
131
|
-
while (cur = cur.parent) depth++;
|
|
132
|
-
return depth;
|
|
133
|
-
}
|