wc-compiler 0.12.0 → 0.13.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/wcc.dist.cjs +816 -559
- package/package.json +9 -4
- package/src/dom-shim.js +11 -1
- package/src/jsx-loader.js +5 -3
- package/src/wcc.js +10 -7
package/dist/wcc.dist.cjs
CHANGED
|
@@ -4,6 +4,14 @@ var fs = require('fs');
|
|
|
4
4
|
|
|
5
5
|
function noop() { }
|
|
6
6
|
|
|
7
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet
|
|
8
|
+
class CSSStyleSheet {
|
|
9
|
+
insertRule() { }
|
|
10
|
+
deleteRule() { }
|
|
11
|
+
replace() { }
|
|
12
|
+
replaceSync() { }
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
|
|
8
16
|
class EventTarget {
|
|
9
17
|
constructor() {
|
|
@@ -97,6 +105,7 @@ class ShadowRoot extends DocumentFragment {
|
|
|
97
105
|
constructor(options) {
|
|
98
106
|
super();
|
|
99
107
|
this.mode = options.mode || 'closed';
|
|
108
|
+
this.adoptedStyleSheets = [];
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
111
|
|
|
@@ -151,6 +160,7 @@ globalThis.addEventListener = globalThis.addEventListener ?? noop;
|
|
|
151
160
|
globalThis.document = globalThis.document ?? new Document();
|
|
152
161
|
globalThis.customElements = globalThis.customElements ?? new CustomElementsRegistry();
|
|
153
162
|
globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement;
|
|
163
|
+
globalThis.CSSStyleSheet = globalThis.CSSStyleSheet ?? CSSStyleSheet;
|
|
154
164
|
|
|
155
165
|
// Reserved word lists for various dialects of the language
|
|
156
166
|
|
|
@@ -1199,7 +1209,7 @@ pp$8.parseForStatement = function(node) {
|
|
|
1199
1209
|
|
|
1200
1210
|
pp$8.parseFunctionStatement = function(node, isAsync, declarationPosition) {
|
|
1201
1211
|
this.next();
|
|
1202
|
-
return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
|
|
1212
|
+
return this.parseFunction(node, FUNC_STATEMENT$1 | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
|
|
1203
1213
|
};
|
|
1204
1214
|
|
|
1205
1215
|
pp$8.parseIfStatement = function(node) {
|
|
@@ -1463,7 +1473,7 @@ pp$8.parseVarId = function(decl, kind) {
|
|
|
1463
1473
|
this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
|
|
1464
1474
|
};
|
|
1465
1475
|
|
|
1466
|
-
var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
|
|
1476
|
+
var FUNC_STATEMENT$1 = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID$1 = 4;
|
|
1467
1477
|
|
|
1468
1478
|
// Parse a function declaration or literal (depending on the
|
|
1469
1479
|
// `statement & FUNC_STATEMENT`).
|
|
@@ -1479,8 +1489,8 @@ pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, for
|
|
|
1479
1489
|
if (this.options.ecmaVersion >= 8)
|
|
1480
1490
|
{ node.async = !!isAsync; }
|
|
1481
1491
|
|
|
1482
|
-
if (statement & FUNC_STATEMENT) {
|
|
1483
|
-
node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types$1.name ? null : this.parseIdent();
|
|
1492
|
+
if (statement & FUNC_STATEMENT$1) {
|
|
1493
|
+
node.id = (statement & FUNC_NULLABLE_ID$1) && this.type !== types$1.name ? null : this.parseIdent();
|
|
1484
1494
|
if (node.id && !(statement & FUNC_HANGING_STATEMENT))
|
|
1485
1495
|
// If it is a regular function declaration in sloppy mode, then it is
|
|
1486
1496
|
// subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
|
|
@@ -1495,7 +1505,7 @@ pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, for
|
|
|
1495
1505
|
this.awaitIdentPos = 0;
|
|
1496
1506
|
this.enterScope(functionFlags(node.async, node.generator));
|
|
1497
1507
|
|
|
1498
|
-
if (!(statement & FUNC_STATEMENT))
|
|
1508
|
+
if (!(statement & FUNC_STATEMENT$1))
|
|
1499
1509
|
{ node.id = this.type === types$1.name ? this.parseIdent() : null; }
|
|
1500
1510
|
|
|
1501
1511
|
this.parseFunctionParams(node);
|
|
@@ -1504,7 +1514,7 @@ pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, for
|
|
|
1504
1514
|
this.yieldPos = oldYieldPos;
|
|
1505
1515
|
this.awaitPos = oldAwaitPos;
|
|
1506
1516
|
this.awaitIdentPos = oldAwaitIdentPos;
|
|
1507
|
-
return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
|
|
1517
|
+
return this.finishNode(node, (statement & FUNC_STATEMENT$1) ? "FunctionDeclaration" : "FunctionExpression")
|
|
1508
1518
|
};
|
|
1509
1519
|
|
|
1510
1520
|
pp$8.parseFunctionParams = function(node) {
|
|
@@ -1810,7 +1820,7 @@ pp$8.parseExport = function(node, exports) {
|
|
|
1810
1820
|
var fNode = this.startNode();
|
|
1811
1821
|
this.next();
|
|
1812
1822
|
if (isAsync) { this.next(); }
|
|
1813
|
-
node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
|
|
1823
|
+
node.declaration = this.parseFunction(fNode, FUNC_STATEMENT$1 | FUNC_NULLABLE_ID$1, false, isAsync);
|
|
1814
1824
|
} else if (this.type === types$1._class) {
|
|
1815
1825
|
var cNode = this.startNode();
|
|
1816
1826
|
node.declaration = this.parseClass(cNode, "nullableID");
|
|
@@ -5739,7 +5749,7 @@ function tokenizer$1(input, options) {
|
|
|
5739
5749
|
return Parser$2.tokenizer(input, options)
|
|
5740
5750
|
}
|
|
5741
5751
|
|
|
5742
|
-
var
|
|
5752
|
+
var _acorn = /*#__PURE__*/Object.freeze({
|
|
5743
5753
|
__proto__: null,
|
|
5744
5754
|
Node: Node,
|
|
5745
5755
|
Parser: Parser$2,
|
|
@@ -6055,35 +6065,6 @@ base$1.MethodDefinition = base$1.PropertyDefinition = base$1.Property = function
|
|
|
6055
6065
|
if (node.value) { c(node.value, st, "Expression"); }
|
|
6056
6066
|
};
|
|
6057
6067
|
|
|
6058
|
-
function getDefaultExportFromCjs (x) {
|
|
6059
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
6060
|
-
}
|
|
6061
|
-
|
|
6062
|
-
function getAugmentedNamespace(n) {
|
|
6063
|
-
if (n.__esModule) return n;
|
|
6064
|
-
var f = n.default;
|
|
6065
|
-
if (typeof f == "function") {
|
|
6066
|
-
var a = function a () {
|
|
6067
|
-
if (this instanceof a) {
|
|
6068
|
-
return Reflect.construct(f, arguments, this.constructor);
|
|
6069
|
-
}
|
|
6070
|
-
return f.apply(this, arguments);
|
|
6071
|
-
};
|
|
6072
|
-
a.prototype = f.prototype;
|
|
6073
|
-
} else a = {};
|
|
6074
|
-
Object.defineProperty(a, '__esModule', {value: true});
|
|
6075
|
-
Object.keys(n).forEach(function (k) {
|
|
6076
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
6077
|
-
Object.defineProperty(a, k, d.get ? d : {
|
|
6078
|
-
enumerable: true,
|
|
6079
|
-
get: function () {
|
|
6080
|
-
return n[k];
|
|
6081
|
-
}
|
|
6082
|
-
});
|
|
6083
|
-
});
|
|
6084
|
-
return a;
|
|
6085
|
-
}
|
|
6086
|
-
|
|
6087
6068
|
var estraverse = {};
|
|
6088
6069
|
|
|
6089
6070
|
/*
|
|
@@ -7114,7 +7095,7 @@ var Syntax,
|
|
|
7114
7095
|
quotes,
|
|
7115
7096
|
escapeless,
|
|
7116
7097
|
newline,
|
|
7117
|
-
space,
|
|
7098
|
+
space$1,
|
|
7118
7099
|
parentheses,
|
|
7119
7100
|
semicolons,
|
|
7120
7101
|
safeConcatenation,
|
|
@@ -7594,7 +7575,7 @@ function toSourceNodeWhenNeeded(generated, node) {
|
|
|
7594
7575
|
}
|
|
7595
7576
|
|
|
7596
7577
|
function noEmptySpace() {
|
|
7597
|
-
return (space) ? space : ' ';
|
|
7578
|
+
return (space$1) ? space$1 : ' ';
|
|
7598
7579
|
}
|
|
7599
7580
|
|
|
7600
7581
|
function join(left, right) {
|
|
@@ -7624,7 +7605,7 @@ function join(left, right) {
|
|
|
7624
7605
|
code.isWhiteSpace(rightCharCode) || code.isLineTerminator(rightCharCode)) {
|
|
7625
7606
|
return [left, right];
|
|
7626
7607
|
}
|
|
7627
|
-
return [left, space, right];
|
|
7608
|
+
return [left, space$1, right];
|
|
7628
7609
|
}
|
|
7629
7610
|
|
|
7630
7611
|
function addIndent(stmt) {
|
|
@@ -7890,7 +7871,7 @@ CodeGenerator.prototype.maybeBlock = function(stmt, flags) {
|
|
|
7890
7871
|
noLeadingComment = !extra.comment || !stmt.leadingComments;
|
|
7891
7872
|
|
|
7892
7873
|
if (stmt.type === Syntax.BlockStatement && noLeadingComment) {
|
|
7893
|
-
return [space, this.generateStatement(stmt, flags)];
|
|
7874
|
+
return [space$1, this.generateStatement(stmt, flags)];
|
|
7894
7875
|
}
|
|
7895
7876
|
|
|
7896
7877
|
if (stmt.type === Syntax.EmptyStatement && noLeadingComment) {
|
|
@@ -7910,7 +7891,7 @@ CodeGenerator.prototype.maybeBlock = function(stmt, flags) {
|
|
|
7910
7891
|
CodeGenerator.prototype.maybeBlockSuffix = function (stmt, result) {
|
|
7911
7892
|
var ends = endsWithLineTerminator(toSourceNodeWhenNeeded(result).toString());
|
|
7912
7893
|
if (stmt.type === Syntax.BlockStatement && (!extra.comment || !stmt.leadingComments) && !ends) {
|
|
7913
|
-
return [result, space];
|
|
7894
|
+
return [result, space$1];
|
|
7914
7895
|
}
|
|
7915
7896
|
if (ends) {
|
|
7916
7897
|
return [result, base];
|
|
@@ -7923,12 +7904,12 @@ function generateIdentifier(node) {
|
|
|
7923
7904
|
}
|
|
7924
7905
|
|
|
7925
7906
|
function generateAsyncPrefix(node, spaceRequired) {
|
|
7926
|
-
return node.async ? 'async' + (spaceRequired ? noEmptySpace() : space) : '';
|
|
7907
|
+
return node.async ? 'async' + (spaceRequired ? noEmptySpace() : space$1) : '';
|
|
7927
7908
|
}
|
|
7928
7909
|
|
|
7929
7910
|
function generateStarSuffix(node) {
|
|
7930
7911
|
var isGenerator = node.generator && !extra.moz.starlessGenerator;
|
|
7931
|
-
return isGenerator ? '*' + space : '';
|
|
7912
|
+
return isGenerator ? '*' + space$1 : '';
|
|
7932
7913
|
}
|
|
7933
7914
|
|
|
7934
7915
|
function generateMethodPrefix(prop) {
|
|
@@ -7974,13 +7955,13 @@ CodeGenerator.prototype.generateFunctionParams = function (node) {
|
|
|
7974
7955
|
result.push(this.generatePattern(node.params[i], Precedence.Assignment, E_TTT));
|
|
7975
7956
|
}
|
|
7976
7957
|
if (i + 1 < iz) {
|
|
7977
|
-
result.push(',' + space);
|
|
7958
|
+
result.push(',' + space$1);
|
|
7978
7959
|
}
|
|
7979
7960
|
}
|
|
7980
7961
|
|
|
7981
7962
|
if (node.rest) {
|
|
7982
7963
|
if (node.params.length) {
|
|
7983
|
-
result.push(',' + space);
|
|
7964
|
+
result.push(',' + space$1);
|
|
7984
7965
|
}
|
|
7985
7966
|
result.push('...');
|
|
7986
7967
|
result.push(generateIdentifier(node.rest));
|
|
@@ -7998,12 +7979,12 @@ CodeGenerator.prototype.generateFunctionBody = function (node) {
|
|
|
7998
7979
|
result = this.generateFunctionParams(node);
|
|
7999
7980
|
|
|
8000
7981
|
if (node.type === Syntax.ArrowFunctionExpression) {
|
|
8001
|
-
result.push(space);
|
|
7982
|
+
result.push(space$1);
|
|
8002
7983
|
result.push('=>');
|
|
8003
7984
|
}
|
|
8004
7985
|
|
|
8005
7986
|
if (node.expression) {
|
|
8006
|
-
result.push(space);
|
|
7987
|
+
result.push(space$1);
|
|
8007
7988
|
expr = this.generateExpression(node.body, Precedence.Assignment, E_TTT);
|
|
8008
7989
|
if (expr.toString().charAt(0) === '{') {
|
|
8009
7990
|
expr = ['(', expr, ')'];
|
|
@@ -8017,7 +7998,7 @@ CodeGenerator.prototype.generateFunctionBody = function (node) {
|
|
|
8017
7998
|
};
|
|
8018
7999
|
|
|
8019
8000
|
CodeGenerator.prototype.generateIterationForStatement = function (operator, stmt, flags) {
|
|
8020
|
-
var result = ['for' + (stmt.await ? noEmptySpace() + 'await' : '') + space + '('], that = this;
|
|
8001
|
+
var result = ['for' + (stmt.await ? noEmptySpace() + 'await' : '') + space$1 + '('], that = this;
|
|
8021
8002
|
withIndent(function () {
|
|
8022
8003
|
if (stmt.left.type === Syntax.VariableDeclaration) {
|
|
8023
8004
|
withIndent(function () {
|
|
@@ -8062,7 +8043,7 @@ CodeGenerator.prototype.generateAssignment = function (left, right, operator, pr
|
|
|
8062
8043
|
return parenthesize(
|
|
8063
8044
|
[
|
|
8064
8045
|
this.generateExpression(left, Precedence.Call, flags),
|
|
8065
|
-
space + operator + space,
|
|
8046
|
+
space$1 + operator + space$1,
|
|
8066
8047
|
this.generateExpression(right, Precedence.Assignment, flags)
|
|
8067
8048
|
],
|
|
8068
8049
|
Precedence.Assignment,
|
|
@@ -8212,7 +8193,7 @@ CodeGenerator.Statement = {
|
|
|
8212
8193
|
fragment = join('extends', this.generateExpression(stmt.superClass, Precedence.Unary, E_TTT));
|
|
8213
8194
|
result = join(result, fragment);
|
|
8214
8195
|
}
|
|
8215
|
-
result.push(space);
|
|
8196
|
+
result.push(space$1);
|
|
8216
8197
|
result.push(this.generateStatement(stmt.body, S_TFFT));
|
|
8217
8198
|
return result;
|
|
8218
8199
|
},
|
|
@@ -8229,7 +8210,7 @@ CodeGenerator.Statement = {
|
|
|
8229
8210
|
var result = join('do', this.maybeBlock(stmt.body, S_TFFF));
|
|
8230
8211
|
result = this.maybeBlockSuffix(stmt.body, result);
|
|
8231
8212
|
return join(result, [
|
|
8232
|
-
'while' + space + '(',
|
|
8213
|
+
'while' + space$1 + '(',
|
|
8233
8214
|
this.generateExpression(stmt.test, Precedence.Sequence, E_TTT),
|
|
8234
8215
|
')' + this.semicolon(flags)
|
|
8235
8216
|
]);
|
|
@@ -8242,7 +8223,7 @@ CodeGenerator.Statement = {
|
|
|
8242
8223
|
|
|
8243
8224
|
if (stmt.param) {
|
|
8244
8225
|
result = [
|
|
8245
|
-
'catch' + space + '(',
|
|
8226
|
+
'catch' + space$1 + '(',
|
|
8246
8227
|
that.generateExpression(stmt.param, Precedence.Sequence, E_TTT),
|
|
8247
8228
|
')'
|
|
8248
8229
|
];
|
|
@@ -8298,7 +8279,7 @@ CodeGenerator.Statement = {
|
|
|
8298
8279
|
// export ExportClause ;
|
|
8299
8280
|
if (stmt.specifiers) {
|
|
8300
8281
|
if (stmt.specifiers.length === 0) {
|
|
8301
|
-
result = join(result, '{' + space + '}');
|
|
8282
|
+
result = join(result, '{' + space$1 + '}');
|
|
8302
8283
|
} else if (stmt.specifiers[0].type === Syntax.ExportBatchSpecifier) {
|
|
8303
8284
|
result = join(result, this.generateExpression(stmt.specifiers[0], Precedence.Sequence, E_TTT));
|
|
8304
8285
|
} else {
|
|
@@ -8322,7 +8303,7 @@ CodeGenerator.Statement = {
|
|
|
8322
8303
|
|
|
8323
8304
|
if (stmt.source) {
|
|
8324
8305
|
result = join(result, [
|
|
8325
|
-
'from' + space,
|
|
8306
|
+
'from' + space$1,
|
|
8326
8307
|
// ModuleSpecifier
|
|
8327
8308
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8328
8309
|
this.semicolon(flags)
|
|
@@ -8337,9 +8318,9 @@ CodeGenerator.Statement = {
|
|
|
8337
8318
|
ExportAllDeclaration: function (stmt, flags) {
|
|
8338
8319
|
// export * FromClause ;
|
|
8339
8320
|
return [
|
|
8340
|
-
'export' + space,
|
|
8341
|
-
'*' + space,
|
|
8342
|
-
'from' + space,
|
|
8321
|
+
'export' + space$1,
|
|
8322
|
+
'*' + space$1,
|
|
8323
|
+
'from' + space$1,
|
|
8343
8324
|
// ModuleSpecifier
|
|
8344
8325
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8345
8326
|
this.semicolon(flags)
|
|
@@ -8419,7 +8400,7 @@ CodeGenerator.Statement = {
|
|
|
8419
8400
|
// import ModuleSpecifier ;
|
|
8420
8401
|
return [
|
|
8421
8402
|
'import',
|
|
8422
|
-
space,
|
|
8403
|
+
space$1,
|
|
8423
8404
|
// ModuleSpecifier
|
|
8424
8405
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8425
8406
|
this.semicolon(flags)
|
|
@@ -8448,18 +8429,18 @@ CodeGenerator.Statement = {
|
|
|
8448
8429
|
if (stmt.specifiers[cursor].type === Syntax.ImportNamespaceSpecifier) {
|
|
8449
8430
|
// NameSpaceImport
|
|
8450
8431
|
result = join(result, [
|
|
8451
|
-
space,
|
|
8432
|
+
space$1,
|
|
8452
8433
|
this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT)
|
|
8453
8434
|
]);
|
|
8454
8435
|
} else {
|
|
8455
8436
|
// NamedImports
|
|
8456
|
-
result.push(space + '{');
|
|
8437
|
+
result.push(space$1 + '{');
|
|
8457
8438
|
|
|
8458
8439
|
if ((stmt.specifiers.length - cursor) === 1) {
|
|
8459
8440
|
// import { ... } from "...";
|
|
8460
|
-
result.push(space);
|
|
8441
|
+
result.push(space$1);
|
|
8461
8442
|
result.push(this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT));
|
|
8462
|
-
result.push(space + '}' + space);
|
|
8443
|
+
result.push(space$1 + '}' + space$1);
|
|
8463
8444
|
} else {
|
|
8464
8445
|
// import {
|
|
8465
8446
|
// ...,
|
|
@@ -8479,13 +8460,13 @@ CodeGenerator.Statement = {
|
|
|
8479
8460
|
if (!endsWithLineTerminator(toSourceNodeWhenNeeded(result).toString())) {
|
|
8480
8461
|
result.push(newline);
|
|
8481
8462
|
}
|
|
8482
|
-
result.push(base + '}' + space);
|
|
8463
|
+
result.push(base + '}' + space$1);
|
|
8483
8464
|
}
|
|
8484
8465
|
}
|
|
8485
8466
|
}
|
|
8486
8467
|
|
|
8487
8468
|
result = join(result, [
|
|
8488
|
-
'from' + space,
|
|
8469
|
+
'from' + space$1,
|
|
8489
8470
|
// ModuleSpecifier
|
|
8490
8471
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8491
8472
|
this.semicolon(flags)
|
|
@@ -8498,9 +8479,9 @@ CodeGenerator.Statement = {
|
|
|
8498
8479
|
if (stmt.init) {
|
|
8499
8480
|
return [
|
|
8500
8481
|
this.generateExpression(stmt.id, Precedence.Assignment, itemFlags),
|
|
8501
|
-
space,
|
|
8482
|
+
space$1,
|
|
8502
8483
|
'=',
|
|
8503
|
-
space,
|
|
8484
|
+
space$1,
|
|
8504
8485
|
this.generateExpression(stmt.init, Precedence.Assignment, itemFlags)
|
|
8505
8486
|
];
|
|
8506
8487
|
}
|
|
@@ -8533,7 +8514,7 @@ CodeGenerator.Statement = {
|
|
|
8533
8514
|
result.push(',' + newline);
|
|
8534
8515
|
result.push(addIndent(that.generateStatement(node, bodyFlags)));
|
|
8535
8516
|
} else {
|
|
8536
|
-
result.push(',' + space);
|
|
8517
|
+
result.push(',' + space$1);
|
|
8537
8518
|
result.push(that.generateStatement(node, bodyFlags));
|
|
8538
8519
|
}
|
|
8539
8520
|
}
|
|
@@ -8608,9 +8589,9 @@ CodeGenerator.Statement = {
|
|
|
8608
8589
|
var result, fragment, i, iz, bodyFlags, that = this;
|
|
8609
8590
|
withIndent(function () {
|
|
8610
8591
|
result = [
|
|
8611
|
-
'switch' + space + '(',
|
|
8592
|
+
'switch' + space$1 + '(',
|
|
8612
8593
|
that.generateExpression(stmt.discriminant, Precedence.Sequence, E_TTT),
|
|
8613
|
-
')' + space + '{' + newline
|
|
8594
|
+
')' + space$1 + '{' + newline
|
|
8614
8595
|
];
|
|
8615
8596
|
});
|
|
8616
8597
|
if (stmt.cases) {
|
|
@@ -8673,7 +8654,7 @@ CodeGenerator.Statement = {
|
|
|
8673
8654
|
var result, bodyFlags, semicolonOptional, that = this;
|
|
8674
8655
|
withIndent(function () {
|
|
8675
8656
|
result = [
|
|
8676
|
-
'if' + space + '(',
|
|
8657
|
+
'if' + space$1 + '(',
|
|
8677
8658
|
that.generateExpression(stmt.test, Precedence.Sequence, E_TTT),
|
|
8678
8659
|
')'
|
|
8679
8660
|
];
|
|
@@ -8700,7 +8681,7 @@ CodeGenerator.Statement = {
|
|
|
8700
8681
|
ForStatement: function (stmt, flags) {
|
|
8701
8682
|
var result, that = this;
|
|
8702
8683
|
withIndent(function () {
|
|
8703
|
-
result = ['for' + space + '('];
|
|
8684
|
+
result = ['for' + space$1 + '('];
|
|
8704
8685
|
if (stmt.init) {
|
|
8705
8686
|
if (stmt.init.type === Syntax.VariableDeclaration) {
|
|
8706
8687
|
result.push(that.generateStatement(stmt.init, S_FFFF));
|
|
@@ -8714,7 +8695,7 @@ CodeGenerator.Statement = {
|
|
|
8714
8695
|
}
|
|
8715
8696
|
|
|
8716
8697
|
if (stmt.test) {
|
|
8717
|
-
result.push(space);
|
|
8698
|
+
result.push(space$1);
|
|
8718
8699
|
result.push(that.generateExpression(stmt.test, Precedence.Sequence, E_TTT));
|
|
8719
8700
|
result.push(';');
|
|
8720
8701
|
} else {
|
|
@@ -8722,7 +8703,7 @@ CodeGenerator.Statement = {
|
|
|
8722
8703
|
}
|
|
8723
8704
|
|
|
8724
8705
|
if (stmt.update) {
|
|
8725
|
-
result.push(space);
|
|
8706
|
+
result.push(space$1);
|
|
8726
8707
|
result.push(that.generateExpression(stmt.update, Precedence.Sequence, E_TTT));
|
|
8727
8708
|
result.push(')');
|
|
8728
8709
|
} else {
|
|
@@ -8820,7 +8801,7 @@ CodeGenerator.Statement = {
|
|
|
8820
8801
|
var result, that = this;
|
|
8821
8802
|
withIndent(function () {
|
|
8822
8803
|
result = [
|
|
8823
|
-
'while' + space + '(',
|
|
8804
|
+
'while' + space$1 + '(',
|
|
8824
8805
|
that.generateExpression(stmt.test, Precedence.Sequence, E_TTT),
|
|
8825
8806
|
')'
|
|
8826
8807
|
];
|
|
@@ -8833,7 +8814,7 @@ CodeGenerator.Statement = {
|
|
|
8833
8814
|
var result, that = this;
|
|
8834
8815
|
withIndent(function () {
|
|
8835
8816
|
result = [
|
|
8836
|
-
'with' + space + '(',
|
|
8817
|
+
'with' + space$1 + '(',
|
|
8837
8818
|
that.generateExpression(stmt.object, Precedence.Sequence, E_TTT),
|
|
8838
8819
|
')'
|
|
8839
8820
|
];
|
|
@@ -8859,7 +8840,7 @@ CodeGenerator.Expression = {
|
|
|
8859
8840
|
for (i = 0, iz = expr.expressions.length; i < iz; ++i) {
|
|
8860
8841
|
result.push(this.generateExpression(expr.expressions[i], Precedence.Assignment, flags));
|
|
8861
8842
|
if (i + 1 < iz) {
|
|
8862
|
-
result.push(',' + space);
|
|
8843
|
+
result.push(',' + space$1);
|
|
8863
8844
|
}
|
|
8864
8845
|
}
|
|
8865
8846
|
return parenthesize(result, Precedence.Sequence, precedence);
|
|
@@ -8880,9 +8861,9 @@ CodeGenerator.Expression = {
|
|
|
8880
8861
|
return parenthesize(
|
|
8881
8862
|
[
|
|
8882
8863
|
this.generateExpression(expr.test, Precedence.Coalesce, flags),
|
|
8883
|
-
space + '?' + space,
|
|
8864
|
+
space$1 + '?' + space$1,
|
|
8884
8865
|
this.generateExpression(expr.consequent, Precedence.Assignment, flags),
|
|
8885
|
-
space + ':' + space,
|
|
8866
|
+
space$1 + ':' + space$1,
|
|
8886
8867
|
this.generateExpression(expr.alternate, Precedence.Assignment, flags)
|
|
8887
8868
|
],
|
|
8888
8869
|
Precedence.Conditional,
|
|
@@ -8951,7 +8932,7 @@ CodeGenerator.Expression = {
|
|
|
8951
8932
|
for (i = 0, iz = expr['arguments'].length; i < iz; ++i) {
|
|
8952
8933
|
result.push(this.generateExpression(expr['arguments'][i], Precedence.Assignment, E_TTT));
|
|
8953
8934
|
if (i + 1 < iz) {
|
|
8954
|
-
result.push(',' + space);
|
|
8935
|
+
result.push(',' + space$1);
|
|
8955
8936
|
}
|
|
8956
8937
|
}
|
|
8957
8938
|
result.push(')');
|
|
@@ -8991,7 +8972,7 @@ CodeGenerator.Expression = {
|
|
|
8991
8972
|
for (i = 0, iz = length; i < iz; ++i) {
|
|
8992
8973
|
result.push(this.generateExpression(expr['arguments'][i], Precedence.Assignment, E_TTT));
|
|
8993
8974
|
if (i + 1 < iz) {
|
|
8994
|
-
result.push(',' + space);
|
|
8975
|
+
result.push(',' + space$1);
|
|
8995
8976
|
}
|
|
8996
8977
|
}
|
|
8997
8978
|
result.push(')');
|
|
@@ -9052,7 +9033,7 @@ CodeGenerator.Expression = {
|
|
|
9052
9033
|
var result, fragment, rightCharCode, leftSource, leftCharCode;
|
|
9053
9034
|
fragment = this.generateExpression(expr.argument, Precedence.Unary, E_TTT);
|
|
9054
9035
|
|
|
9055
|
-
if (space === '') {
|
|
9036
|
+
if (space$1 === '') {
|
|
9056
9037
|
result = join(expr.operator, fragment);
|
|
9057
9038
|
} else {
|
|
9058
9039
|
result = [expr.operator];
|
|
@@ -9133,7 +9114,7 @@ CodeGenerator.Expression = {
|
|
|
9133
9114
|
result.push(generateStarSuffix(expr) || noEmptySpace());
|
|
9134
9115
|
result.push(generateIdentifier(expr.id));
|
|
9135
9116
|
} else {
|
|
9136
|
-
result.push(generateStarSuffix(expr) || space);
|
|
9117
|
+
result.push(generateStarSuffix(expr) || space$1);
|
|
9137
9118
|
}
|
|
9138
9119
|
result.push(this.generateFunctionBody(expr));
|
|
9139
9120
|
return result;
|
|
@@ -9165,7 +9146,7 @@ CodeGenerator.Expression = {
|
|
|
9165
9146
|
result.push(that.generateExpression(expr.elements[i], Precedence.Assignment, E_TTT));
|
|
9166
9147
|
}
|
|
9167
9148
|
if (i + 1 < iz) {
|
|
9168
|
-
result.push(',' + (multiline ? newline : space));
|
|
9149
|
+
result.push(',' + (multiline ? newline : space$1));
|
|
9169
9150
|
}
|
|
9170
9151
|
}
|
|
9171
9152
|
});
|
|
@@ -9191,7 +9172,7 @@ CodeGenerator.Expression = {
|
|
|
9191
9172
|
fragment = join('extends', this.generateExpression(expr.superClass, Precedence.Unary, E_TTT));
|
|
9192
9173
|
result = join(result, fragment);
|
|
9193
9174
|
}
|
|
9194
|
-
result.push(space);
|
|
9175
|
+
result.push(space$1);
|
|
9195
9176
|
result.push(this.generateStatement(expr.body, S_TFFT));
|
|
9196
9177
|
return result;
|
|
9197
9178
|
},
|
|
@@ -9199,7 +9180,7 @@ CodeGenerator.Expression = {
|
|
|
9199
9180
|
MethodDefinition: function (expr, precedence, flags) {
|
|
9200
9181
|
var result, fragment;
|
|
9201
9182
|
if (expr['static']) {
|
|
9202
|
-
result = ['static' + space];
|
|
9183
|
+
result = ['static' + space$1];
|
|
9203
9184
|
} else {
|
|
9204
9185
|
result = [];
|
|
9205
9186
|
}
|
|
@@ -9244,7 +9225,7 @@ CodeGenerator.Expression = {
|
|
|
9244
9225
|
|
|
9245
9226
|
return [
|
|
9246
9227
|
this.generatePropertyKey(expr.key, expr.computed),
|
|
9247
|
-
':' + space,
|
|
9228
|
+
':' + space$1,
|
|
9248
9229
|
this.generateExpression(expr.value, Precedence.Assignment, E_TTT)
|
|
9249
9230
|
];
|
|
9250
9231
|
},
|
|
@@ -9271,7 +9252,7 @@ CodeGenerator.Expression = {
|
|
|
9271
9252
|
// dejavu.Class.declare({method2: function () {
|
|
9272
9253
|
// }});
|
|
9273
9254
|
if (!hasLineTerminator(toSourceNodeWhenNeeded(fragment).toString())) {
|
|
9274
|
-
return [ '{', space, fragment, space, '}' ];
|
|
9255
|
+
return [ '{', space$1, fragment, space$1, '}' ];
|
|
9275
9256
|
}
|
|
9276
9257
|
}
|
|
9277
9258
|
|
|
@@ -9338,7 +9319,7 @@ CodeGenerator.Expression = {
|
|
|
9338
9319
|
result.push(multiline ? indent : '');
|
|
9339
9320
|
result.push(that.generateExpression(expr.properties[i], Precedence.Sequence, E_TTT));
|
|
9340
9321
|
if (i + 1 < iz) {
|
|
9341
|
-
result.push(',' + (multiline ? newline : space));
|
|
9322
|
+
result.push(',' + (multiline ? newline : space$1));
|
|
9342
9323
|
}
|
|
9343
9324
|
}
|
|
9344
9325
|
});
|
|
@@ -9371,7 +9352,7 @@ CodeGenerator.Expression = {
|
|
|
9371
9352
|
var result = ['*'];
|
|
9372
9353
|
var id = expr.id || expr.local;
|
|
9373
9354
|
if (id) {
|
|
9374
|
-
result.push(space + 'as' + noEmptySpace() + generateIdentifier(id));
|
|
9355
|
+
result.push(space$1 + 'as' + noEmptySpace() + generateIdentifier(id));
|
|
9375
9356
|
}
|
|
9376
9357
|
return result;
|
|
9377
9358
|
},
|
|
@@ -9474,7 +9455,7 @@ CodeGenerator.Expression = {
|
|
|
9474
9455
|
}
|
|
9475
9456
|
|
|
9476
9457
|
if (expr.filter) {
|
|
9477
|
-
result = join(result, 'if' + space);
|
|
9458
|
+
result = join(result, 'if' + space$1);
|
|
9478
9459
|
fragment = this.generateExpression(expr.filter, Precedence.Sequence, E_TTT);
|
|
9479
9460
|
result = join(result, [ '(', fragment, ')' ]);
|
|
9480
9461
|
}
|
|
@@ -9503,7 +9484,7 @@ CodeGenerator.Expression = {
|
|
|
9503
9484
|
fragment = join(fragment, expr.of ? 'of' : 'in');
|
|
9504
9485
|
fragment = join(fragment, this.generateExpression(expr.right, Precedence.Sequence, E_TTT));
|
|
9505
9486
|
|
|
9506
|
-
return [ 'for' + space + '(', fragment, ')' ];
|
|
9487
|
+
return [ 'for' + space$1 + '(', fragment, ')' ];
|
|
9507
9488
|
},
|
|
9508
9489
|
|
|
9509
9490
|
SpreadElement: function (expr, precedence, flags) {
|
|
@@ -9537,9 +9518,9 @@ CodeGenerator.Expression = {
|
|
|
9537
9518
|
for (i = 0, iz = expr.quasis.length; i < iz; ++i) {
|
|
9538
9519
|
result.push(this.generateExpression(expr.quasis[i], Precedence.Primary, E_TTT));
|
|
9539
9520
|
if (i + 1 < iz) {
|
|
9540
|
-
result.push('${' + space);
|
|
9521
|
+
result.push('${' + space$1);
|
|
9541
9522
|
result.push(this.generateExpression(expr.expressions[i], Precedence.Sequence, E_TTT));
|
|
9542
|
-
result.push(space + '}');
|
|
9523
|
+
result.push(space$1 + '}');
|
|
9543
9524
|
}
|
|
9544
9525
|
}
|
|
9545
9526
|
result.push('`');
|
|
@@ -9648,9 +9629,9 @@ function generate(node, options) {
|
|
|
9648
9629
|
quotes = json ? 'double' : options.format.quotes;
|
|
9649
9630
|
escapeless = options.format.escapeless;
|
|
9650
9631
|
newline = options.format.newline;
|
|
9651
|
-
space = options.format.space;
|
|
9632
|
+
space$1 = options.format.space;
|
|
9652
9633
|
if (options.format.compact) {
|
|
9653
|
-
newline = space = indent = base = '';
|
|
9634
|
+
newline = space$1 = indent = base = '';
|
|
9654
9635
|
}
|
|
9655
9636
|
parentheses = options.format.parentheses;
|
|
9656
9637
|
semicolons = options.format.semicolons;
|
|
@@ -9700,9 +9681,7 @@ function generate(node, options) {
|
|
|
9700
9681
|
getDefaultOptions().format;
|
|
9701
9682
|
updateDeeply({}, Precedence);
|
|
9702
9683
|
|
|
9703
|
-
var
|
|
9704
|
-
|
|
9705
|
-
var xhtml = {
|
|
9684
|
+
var XHTMLEntities = {
|
|
9706
9685
|
quot: '\u0022',
|
|
9707
9686
|
amp: '&',
|
|
9708
9687
|
apos: '\u0027',
|
|
@@ -9958,500 +9937,489 @@ var xhtml = {
|
|
|
9958
9937
|
diams: '\u2666'
|
|
9959
9938
|
};
|
|
9960
9939
|
|
|
9961
|
-
|
|
9962
|
-
|
|
9963
|
-
|
|
9940
|
+
const hexNumber = /^[\da-fA-F]+$/;
|
|
9941
|
+
const decimalNumber = /^\d+$/;
|
|
9942
|
+
|
|
9943
|
+
// The map to `acorn-jsx` tokens from `acorn` namespace objects.
|
|
9944
|
+
const acornJsxMap = new WeakMap();
|
|
9945
|
+
|
|
9946
|
+
// Get the original tokens for the given `acorn` namespace object.
|
|
9947
|
+
function getJsxTokens(acorn) {
|
|
9948
|
+
acorn = acorn.Parser.acorn || acorn;
|
|
9949
|
+
let acornJsx = acornJsxMap.get(acorn);
|
|
9950
|
+
if (!acornJsx) {
|
|
9951
|
+
const tt = acorn.tokTypes;
|
|
9952
|
+
const TokContext = acorn.TokContext;
|
|
9953
|
+
const TokenType = acorn.TokenType;
|
|
9954
|
+
const tc_oTag = new TokContext('<tag', false);
|
|
9955
|
+
const tc_cTag = new TokContext('</tag', false);
|
|
9956
|
+
const tc_expr = new TokContext('<tag>...</tag>', true, true);
|
|
9957
|
+
const tokContexts = {
|
|
9958
|
+
tc_oTag: tc_oTag,
|
|
9959
|
+
tc_cTag: tc_cTag,
|
|
9960
|
+
tc_expr: tc_expr
|
|
9961
|
+
};
|
|
9962
|
+
const tokTypes = {
|
|
9963
|
+
jsxName: new TokenType('jsxName'),
|
|
9964
|
+
jsxText: new TokenType('jsxText', {beforeExpr: true}),
|
|
9965
|
+
jsxTagStart: new TokenType('jsxTagStart', {startsExpr: true}),
|
|
9966
|
+
jsxTagEnd: new TokenType('jsxTagEnd')
|
|
9967
|
+
};
|
|
9964
9968
|
|
|
9965
|
-
|
|
9969
|
+
tokTypes.jsxTagStart.updateContext = function() {
|
|
9970
|
+
this.context.push(tc_expr); // treat as beginning of JSX expression
|
|
9971
|
+
this.context.push(tc_oTag); // start opening tag context
|
|
9972
|
+
this.exprAllowed = false;
|
|
9973
|
+
};
|
|
9974
|
+
tokTypes.jsxTagEnd.updateContext = function(prevType) {
|
|
9975
|
+
let out = this.context.pop();
|
|
9976
|
+
if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
|
|
9977
|
+
this.context.pop();
|
|
9978
|
+
this.exprAllowed = this.curContext() === tc_expr;
|
|
9979
|
+
} else {
|
|
9980
|
+
this.exprAllowed = true;
|
|
9981
|
+
}
|
|
9982
|
+
};
|
|
9966
9983
|
|
|
9967
|
-
|
|
9968
|
-
|
|
9984
|
+
acornJsx = { tokContexts: tokContexts, tokTypes: tokTypes };
|
|
9985
|
+
acornJsxMap.set(acorn, acornJsx);
|
|
9986
|
+
}
|
|
9969
9987
|
|
|
9970
|
-
|
|
9971
|
-
|
|
9988
|
+
return acornJsx;
|
|
9989
|
+
}
|
|
9972
9990
|
|
|
9973
|
-
|
|
9974
|
-
function getJsxTokens(acorn) {
|
|
9975
|
-
acorn = acorn.Parser.acorn || acorn;
|
|
9976
|
-
let acornJsx = acornJsxMap.get(acorn);
|
|
9977
|
-
if (!acornJsx) {
|
|
9978
|
-
const tt = acorn.tokTypes;
|
|
9979
|
-
const TokContext = acorn.TokContext;
|
|
9980
|
-
const TokenType = acorn.TokenType;
|
|
9981
|
-
const tc_oTag = new TokContext('<tag', false);
|
|
9982
|
-
const tc_cTag = new TokContext('</tag', false);
|
|
9983
|
-
const tc_expr = new TokContext('<tag>...</tag>', true, true);
|
|
9984
|
-
const tokContexts = {
|
|
9985
|
-
tc_oTag: tc_oTag,
|
|
9986
|
-
tc_cTag: tc_cTag,
|
|
9987
|
-
tc_expr: tc_expr
|
|
9988
|
-
};
|
|
9989
|
-
const tokTypes = {
|
|
9990
|
-
jsxName: new TokenType('jsxName'),
|
|
9991
|
-
jsxText: new TokenType('jsxText', {beforeExpr: true}),
|
|
9992
|
-
jsxTagStart: new TokenType('jsxTagStart', {startsExpr: true}),
|
|
9993
|
-
jsxTagEnd: new TokenType('jsxTagEnd')
|
|
9994
|
-
};
|
|
9991
|
+
// Transforms JSX element name to string.
|
|
9995
9992
|
|
|
9996
|
-
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
this.exprAllowed = false;
|
|
10000
|
-
};
|
|
10001
|
-
tokTypes.jsxTagEnd.updateContext = function(prevType) {
|
|
10002
|
-
let out = this.context.pop();
|
|
10003
|
-
if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
|
|
10004
|
-
this.context.pop();
|
|
10005
|
-
this.exprAllowed = this.curContext() === tc_expr;
|
|
10006
|
-
} else {
|
|
10007
|
-
this.exprAllowed = true;
|
|
10008
|
-
}
|
|
10009
|
-
};
|
|
9993
|
+
function getQualifiedJSXName(object) {
|
|
9994
|
+
if (!object)
|
|
9995
|
+
return object;
|
|
10010
9996
|
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
}
|
|
10014
|
-
|
|
10015
|
-
return acornJsx;
|
|
10016
|
-
}
|
|
10017
|
-
|
|
10018
|
-
// Transforms JSX element name to string.
|
|
10019
|
-
|
|
10020
|
-
function getQualifiedJSXName(object) {
|
|
10021
|
-
if (!object)
|
|
10022
|
-
return object;
|
|
10023
|
-
|
|
10024
|
-
if (object.type === 'JSXIdentifier')
|
|
10025
|
-
return object.name;
|
|
10026
|
-
|
|
10027
|
-
if (object.type === 'JSXNamespacedName')
|
|
10028
|
-
return object.namespace.name + ':' + object.name.name;
|
|
10029
|
-
|
|
10030
|
-
if (object.type === 'JSXMemberExpression')
|
|
10031
|
-
return getQualifiedJSXName(object.object) + '.' +
|
|
10032
|
-
getQualifiedJSXName(object.property);
|
|
10033
|
-
}
|
|
10034
|
-
|
|
10035
|
-
module.exports = function(options) {
|
|
10036
|
-
options = options || {};
|
|
10037
|
-
return function(Parser) {
|
|
10038
|
-
return plugin({
|
|
10039
|
-
allowNamespaces: options.allowNamespaces !== false,
|
|
10040
|
-
allowNamespacedObjects: !!options.allowNamespacedObjects
|
|
10041
|
-
}, Parser);
|
|
10042
|
-
};
|
|
10043
|
-
};
|
|
10044
|
-
|
|
10045
|
-
// This is `tokTypes` of the peer dep.
|
|
10046
|
-
// This can be different instances from the actual `tokTypes` this plugin uses.
|
|
10047
|
-
Object.defineProperty(module.exports, "tokTypes", {
|
|
10048
|
-
get: function get_tokTypes() {
|
|
10049
|
-
return getJsxTokens(require$$1).tokTypes;
|
|
10050
|
-
},
|
|
10051
|
-
configurable: true,
|
|
10052
|
-
enumerable: true
|
|
10053
|
-
});
|
|
10054
|
-
|
|
10055
|
-
function plugin(options, Parser) {
|
|
10056
|
-
const acorn = Parser.acorn || require$$1;
|
|
10057
|
-
const acornJsx = getJsxTokens(acorn);
|
|
10058
|
-
const tt = acorn.tokTypes;
|
|
10059
|
-
const tok = acornJsx.tokTypes;
|
|
10060
|
-
const tokContexts = acorn.tokContexts;
|
|
10061
|
-
const tc_oTag = acornJsx.tokContexts.tc_oTag;
|
|
10062
|
-
const tc_cTag = acornJsx.tokContexts.tc_cTag;
|
|
10063
|
-
const tc_expr = acornJsx.tokContexts.tc_expr;
|
|
10064
|
-
const isNewLine = acorn.isNewLine;
|
|
10065
|
-
const isIdentifierStart = acorn.isIdentifierStart;
|
|
10066
|
-
const isIdentifierChar = acorn.isIdentifierChar;
|
|
10067
|
-
|
|
10068
|
-
return class extends Parser {
|
|
10069
|
-
// Expose actual `tokTypes` and `tokContexts` to other plugins.
|
|
10070
|
-
static get acornJsx() {
|
|
10071
|
-
return acornJsx;
|
|
10072
|
-
}
|
|
9997
|
+
if (object.type === 'JSXIdentifier')
|
|
9998
|
+
return object.name;
|
|
10073
9999
|
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
let out = '', chunkStart = this.pos;
|
|
10077
|
-
for (;;) {
|
|
10078
|
-
if (this.pos >= this.input.length)
|
|
10079
|
-
this.raise(this.start, 'Unterminated JSX contents');
|
|
10080
|
-
let ch = this.input.charCodeAt(this.pos);
|
|
10081
|
-
|
|
10082
|
-
switch (ch) {
|
|
10083
|
-
case 60: // '<'
|
|
10084
|
-
case 123: // '{'
|
|
10085
|
-
if (this.pos === this.start) {
|
|
10086
|
-
if (ch === 60 && this.exprAllowed) {
|
|
10087
|
-
++this.pos;
|
|
10088
|
-
return this.finishToken(tok.jsxTagStart);
|
|
10089
|
-
}
|
|
10090
|
-
return this.getTokenFromCode(ch);
|
|
10091
|
-
}
|
|
10092
|
-
out += this.input.slice(chunkStart, this.pos);
|
|
10093
|
-
return this.finishToken(tok.jsxText, out);
|
|
10094
|
-
|
|
10095
|
-
case 38: // '&'
|
|
10096
|
-
out += this.input.slice(chunkStart, this.pos);
|
|
10097
|
-
out += this.jsx_readEntity();
|
|
10098
|
-
chunkStart = this.pos;
|
|
10099
|
-
break;
|
|
10100
|
-
|
|
10101
|
-
case 62: // '>'
|
|
10102
|
-
case 125: // '}'
|
|
10103
|
-
this.raise(
|
|
10104
|
-
this.pos,
|
|
10105
|
-
"Unexpected token `" + this.input[this.pos] + "`. Did you mean `" +
|
|
10106
|
-
(ch === 62 ? ">" : "}") + "` or " + "`{\"" + this.input[this.pos] + "\"}" + "`?"
|
|
10107
|
-
);
|
|
10108
|
-
|
|
10109
|
-
default:
|
|
10110
|
-
if (isNewLine(ch)) {
|
|
10111
|
-
out += this.input.slice(chunkStart, this.pos);
|
|
10112
|
-
out += this.jsx_readNewLine(true);
|
|
10113
|
-
chunkStart = this.pos;
|
|
10114
|
-
} else {
|
|
10115
|
-
++this.pos;
|
|
10116
|
-
}
|
|
10117
|
-
}
|
|
10118
|
-
}
|
|
10119
|
-
}
|
|
10000
|
+
if (object.type === 'JSXNamespacedName')
|
|
10001
|
+
return object.namespace.name + ':' + object.name.name;
|
|
10120
10002
|
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
|
10126
|
-
++this.pos;
|
|
10127
|
-
out = normalizeCRLF ? '\n' : '\r\n';
|
|
10128
|
-
} else {
|
|
10129
|
-
out = String.fromCharCode(ch);
|
|
10130
|
-
}
|
|
10131
|
-
if (this.options.locations) {
|
|
10132
|
-
++this.curLine;
|
|
10133
|
-
this.lineStart = this.pos;
|
|
10134
|
-
}
|
|
10135
|
-
|
|
10136
|
-
return out;
|
|
10137
|
-
}
|
|
10003
|
+
if (object.type === 'JSXMemberExpression')
|
|
10004
|
+
return getQualifiedJSXName(object.object) + '.' +
|
|
10005
|
+
getQualifiedJSXName(object.property);
|
|
10006
|
+
}
|
|
10138
10007
|
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
}
|
|
10158
|
-
out += this.input.slice(chunkStart, this.pos++);
|
|
10159
|
-
return this.finishToken(tt.string, out);
|
|
10160
|
-
}
|
|
10008
|
+
function acornJsx(options) {
|
|
10009
|
+
options = options || {};
|
|
10010
|
+
return function(Parser) {
|
|
10011
|
+
return plugin$1({
|
|
10012
|
+
allowNamespaces: options.allowNamespaces !== false,
|
|
10013
|
+
allowNamespacedObjects: !!options.allowNamespacedObjects
|
|
10014
|
+
}, Parser);
|
|
10015
|
+
};
|
|
10016
|
+
}
|
|
10017
|
+
// This is `tokTypes` of the peer dep.
|
|
10018
|
+
// This can be different instances from the actual `tokTypes` this plugin uses.
|
|
10019
|
+
Object.defineProperty(acornJsx, "tokTypes", {
|
|
10020
|
+
get: function get_tokTypes() {
|
|
10021
|
+
return getJsxTokens(_acorn).tokTypes
|
|
10022
|
+
},
|
|
10023
|
+
configurable: true,
|
|
10024
|
+
enumerable: true
|
|
10025
|
+
});
|
|
10161
10026
|
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
|
|
10027
|
+
function plugin$1(options, Parser) {
|
|
10028
|
+
const acorn = Parser.acorn || require("acorn");
|
|
10029
|
+
const acornJsx = getJsxTokens(acorn);
|
|
10030
|
+
const tt = acorn.tokTypes;
|
|
10031
|
+
const tok = acornJsx.tokTypes;
|
|
10032
|
+
const tokContexts = acorn.tokContexts;
|
|
10033
|
+
const tc_oTag = acornJsx.tokContexts.tc_oTag;
|
|
10034
|
+
const tc_cTag = acornJsx.tokContexts.tc_cTag;
|
|
10035
|
+
const tc_expr = acornJsx.tokContexts.tc_expr;
|
|
10036
|
+
const isNewLine = acorn.isNewLine;
|
|
10037
|
+
const isIdentifierStart = acorn.isIdentifierStart;
|
|
10038
|
+
const isIdentifierChar = acorn.isIdentifierChar;
|
|
10039
|
+
|
|
10040
|
+
return class extends Parser {
|
|
10041
|
+
// Expose actual `tokTypes` and `tokContexts` to other plugins.
|
|
10042
|
+
static get acornJsx() {
|
|
10043
|
+
return acornJsx;
|
|
10044
|
+
}
|
|
10045
|
+
|
|
10046
|
+
// Reads inline JSX contents token.
|
|
10047
|
+
jsx_readToken() {
|
|
10048
|
+
let out = '', chunkStart = this.pos;
|
|
10049
|
+
for (;;) {
|
|
10050
|
+
if (this.pos >= this.input.length)
|
|
10051
|
+
this.raise(this.start, 'Unterminated JSX contents');
|
|
10052
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
10053
|
+
|
|
10054
|
+
switch (ch) {
|
|
10055
|
+
case 60: // '<'
|
|
10056
|
+
case 123: // '{'
|
|
10057
|
+
if (this.pos === this.start) {
|
|
10058
|
+
if (ch === 60 && this.exprAllowed) {
|
|
10059
|
+
++this.pos;
|
|
10060
|
+
return this.finishToken(tok.jsxTagStart);
|
|
10061
|
+
}
|
|
10062
|
+
return this.getTokenFromCode(ch);
|
|
10063
|
+
}
|
|
10064
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
10065
|
+
return this.finishToken(tok.jsxText, out);
|
|
10066
|
+
|
|
10067
|
+
case 38: // '&'
|
|
10068
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
10069
|
+
out += this.jsx_readEntity();
|
|
10070
|
+
chunkStart = this.pos;
|
|
10071
|
+
break;
|
|
10072
|
+
|
|
10073
|
+
case 62: // '>'
|
|
10074
|
+
case 125: // '}'
|
|
10075
|
+
this.raise(
|
|
10076
|
+
this.pos,
|
|
10077
|
+
"Unexpected token `" + this.input[this.pos] + "`. Did you mean `" +
|
|
10078
|
+
(ch === 62 ? ">" : "}") + "` or " + "`{\"" + this.input[this.pos] + "\"}" + "`?"
|
|
10079
|
+
);
|
|
10194
10080
|
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
} while (isIdentifierChar(ch) || ch === 45); // '-'
|
|
10207
|
-
return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
|
|
10208
|
-
}
|
|
10081
|
+
default:
|
|
10082
|
+
if (isNewLine(ch)) {
|
|
10083
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
10084
|
+
out += this.jsx_readNewLine(true);
|
|
10085
|
+
chunkStart = this.pos;
|
|
10086
|
+
} else {
|
|
10087
|
+
++this.pos;
|
|
10088
|
+
}
|
|
10089
|
+
}
|
|
10090
|
+
}
|
|
10091
|
+
}
|
|
10209
10092
|
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
|
|
10222
|
-
|
|
10093
|
+
jsx_readNewLine(normalizeCRLF) {
|
|
10094
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
10095
|
+
let out;
|
|
10096
|
+
++this.pos;
|
|
10097
|
+
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
|
10098
|
+
++this.pos;
|
|
10099
|
+
out = normalizeCRLF ? '\n' : '\r\n';
|
|
10100
|
+
} else {
|
|
10101
|
+
out = String.fromCharCode(ch);
|
|
10102
|
+
}
|
|
10103
|
+
if (this.options.locations) {
|
|
10104
|
+
++this.curLine;
|
|
10105
|
+
this.lineStart = this.pos;
|
|
10106
|
+
}
|
|
10223
10107
|
|
|
10224
|
-
|
|
10108
|
+
return out;
|
|
10109
|
+
}
|
|
10110
|
+
|
|
10111
|
+
jsx_readString(quote) {
|
|
10112
|
+
let out = '', chunkStart = ++this.pos;
|
|
10113
|
+
for (;;) {
|
|
10114
|
+
if (this.pos >= this.input.length)
|
|
10115
|
+
this.raise(this.start, 'Unterminated string constant');
|
|
10116
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
10117
|
+
if (ch === quote) break;
|
|
10118
|
+
if (ch === 38) { // '&'
|
|
10119
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
10120
|
+
out += this.jsx_readEntity();
|
|
10121
|
+
chunkStart = this.pos;
|
|
10122
|
+
} else if (isNewLine(ch)) {
|
|
10123
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
10124
|
+
out += this.jsx_readNewLine(false);
|
|
10125
|
+
chunkStart = this.pos;
|
|
10126
|
+
} else {
|
|
10127
|
+
++this.pos;
|
|
10128
|
+
}
|
|
10129
|
+
}
|
|
10130
|
+
out += this.input.slice(chunkStart, this.pos++);
|
|
10131
|
+
return this.finishToken(tt.string, out);
|
|
10132
|
+
}
|
|
10133
|
+
|
|
10134
|
+
jsx_readEntity() {
|
|
10135
|
+
let str = '', count = 0, entity;
|
|
10136
|
+
let ch = this.input[this.pos];
|
|
10137
|
+
if (ch !== '&')
|
|
10138
|
+
this.raise(this.pos, 'Entity must start with an ampersand');
|
|
10139
|
+
let startPos = ++this.pos;
|
|
10140
|
+
while (this.pos < this.input.length && count++ < 10) {
|
|
10141
|
+
ch = this.input[this.pos++];
|
|
10142
|
+
if (ch === ';') {
|
|
10143
|
+
if (str[0] === '#') {
|
|
10144
|
+
if (str[1] === 'x') {
|
|
10145
|
+
str = str.substr(2);
|
|
10146
|
+
if (hexNumber.test(str))
|
|
10147
|
+
entity = String.fromCharCode(parseInt(str, 16));
|
|
10148
|
+
} else {
|
|
10149
|
+
str = str.substr(1);
|
|
10150
|
+
if (decimalNumber.test(str))
|
|
10151
|
+
entity = String.fromCharCode(parseInt(str, 10));
|
|
10152
|
+
}
|
|
10153
|
+
} else {
|
|
10154
|
+
entity = XHTMLEntities[str];
|
|
10155
|
+
}
|
|
10156
|
+
break;
|
|
10157
|
+
}
|
|
10158
|
+
str += ch;
|
|
10159
|
+
}
|
|
10160
|
+
if (!entity) {
|
|
10161
|
+
this.pos = startPos;
|
|
10162
|
+
return '&';
|
|
10163
|
+
}
|
|
10164
|
+
return entity;
|
|
10165
|
+
}
|
|
10225
10166
|
|
|
10226
|
-
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10230
|
-
|
|
10231
|
-
|
|
10232
|
-
node.name = this.jsx_parseIdentifier();
|
|
10233
|
-
return this.finishNode(node, 'JSXNamespacedName');
|
|
10234
|
-
}
|
|
10167
|
+
// Read a JSX identifier (valid tag or attribute name).
|
|
10168
|
+
//
|
|
10169
|
+
// Optimized version since JSX identifiers can't contain
|
|
10170
|
+
// escape characters and so can be read as single slice.
|
|
10171
|
+
// Also assumes that first character was already checked
|
|
10172
|
+
// by isIdentifierStart in readToken.
|
|
10235
10173
|
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !options.allowNamespacedObjects) {
|
|
10244
|
-
this.unexpected();
|
|
10245
|
-
}
|
|
10246
|
-
while (this.eat(tt.dot)) {
|
|
10247
|
-
let newNode = this.startNodeAt(startPos, startLoc);
|
|
10248
|
-
newNode.object = node;
|
|
10249
|
-
newNode.property = this.jsx_parseIdentifier();
|
|
10250
|
-
node = this.finishNode(newNode, 'JSXMemberExpression');
|
|
10251
|
-
}
|
|
10252
|
-
return node;
|
|
10253
|
-
}
|
|
10174
|
+
jsx_readWord() {
|
|
10175
|
+
let ch, start = this.pos;
|
|
10176
|
+
do {
|
|
10177
|
+
ch = this.input.charCodeAt(++this.pos);
|
|
10178
|
+
} while (isIdentifierChar(ch) || ch === 45); // '-'
|
|
10179
|
+
return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
|
|
10180
|
+
}
|
|
10254
10181
|
|
|
10255
|
-
|
|
10182
|
+
// Parse next token as JSX identifier
|
|
10256
10183
|
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10184
|
+
jsx_parseIdentifier() {
|
|
10185
|
+
let node = this.startNode();
|
|
10186
|
+
if (this.type === tok.jsxName)
|
|
10187
|
+
node.name = this.value;
|
|
10188
|
+
else if (this.type.keyword)
|
|
10189
|
+
node.name = this.type.keyword;
|
|
10190
|
+
else
|
|
10191
|
+
this.unexpected();
|
|
10192
|
+
this.next();
|
|
10193
|
+
return this.finishNode(node, 'JSXIdentifier');
|
|
10194
|
+
}
|
|
10264
10195
|
|
|
10265
|
-
|
|
10266
|
-
case tt.string:
|
|
10267
|
-
return this.parseExprAtom();
|
|
10196
|
+
// Parse namespaced identifier.
|
|
10268
10197
|
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
|
|
10198
|
+
jsx_parseNamespacedName() {
|
|
10199
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
10200
|
+
let name = this.jsx_parseIdentifier();
|
|
10201
|
+
if (!options.allowNamespaces || !this.eat(tt.colon)) return name;
|
|
10202
|
+
var node = this.startNodeAt(startPos, startLoc);
|
|
10203
|
+
node.namespace = name;
|
|
10204
|
+
node.name = this.jsx_parseIdentifier();
|
|
10205
|
+
return this.finishNode(node, 'JSXNamespacedName');
|
|
10206
|
+
}
|
|
10273
10207
|
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
// at the beginning of the next one (right brace).
|
|
10208
|
+
// Parses element name in any form - namespaced, member
|
|
10209
|
+
// or single identifier.
|
|
10277
10210
|
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10211
|
+
jsx_parseElementName() {
|
|
10212
|
+
if (this.type === tok.jsxTagEnd) return '';
|
|
10213
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
10214
|
+
let node = this.jsx_parseNamespacedName();
|
|
10215
|
+
if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !options.allowNamespacedObjects) {
|
|
10216
|
+
this.unexpected();
|
|
10217
|
+
}
|
|
10218
|
+
while (this.eat(tt.dot)) {
|
|
10219
|
+
let newNode = this.startNodeAt(startPos, startLoc);
|
|
10220
|
+
newNode.object = node;
|
|
10221
|
+
newNode.property = this.jsx_parseIdentifier();
|
|
10222
|
+
node = this.finishNode(newNode, 'JSXMemberExpression');
|
|
10223
|
+
}
|
|
10224
|
+
return node;
|
|
10225
|
+
}
|
|
10282
10226
|
|
|
10283
|
-
|
|
10227
|
+
// Parses any type of JSX attribute value.
|
|
10284
10228
|
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
return this.finishNode(node, 'JSXExpressionContainer');
|
|
10293
|
-
}
|
|
10229
|
+
jsx_parseAttributeValue() {
|
|
10230
|
+
switch (this.type) {
|
|
10231
|
+
case tt.braceL:
|
|
10232
|
+
let node = this.jsx_parseExpressionContainer();
|
|
10233
|
+
if (node.expression.type === 'JSXEmptyExpression')
|
|
10234
|
+
this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
|
|
10235
|
+
return node;
|
|
10294
10236
|
|
|
10295
|
-
|
|
10296
|
-
|
|
10297
|
-
|
|
10298
|
-
let node = this.startNode();
|
|
10299
|
-
if (this.eat(tt.braceL)) {
|
|
10300
|
-
this.expect(tt.ellipsis);
|
|
10301
|
-
node.argument = this.parseMaybeAssign();
|
|
10302
|
-
this.expect(tt.braceR);
|
|
10303
|
-
return this.finishNode(node, 'JSXSpreadAttribute');
|
|
10304
|
-
}
|
|
10305
|
-
node.name = this.jsx_parseNamespacedName();
|
|
10306
|
-
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
|
10307
|
-
return this.finishNode(node, 'JSXAttribute');
|
|
10308
|
-
}
|
|
10237
|
+
case tok.jsxTagStart:
|
|
10238
|
+
case tt.string:
|
|
10239
|
+
return this.parseExprAtom();
|
|
10309
10240
|
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
node.attributes = [];
|
|
10315
|
-
let nodeName = this.jsx_parseElementName();
|
|
10316
|
-
if (nodeName) node.name = nodeName;
|
|
10317
|
-
while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
|
|
10318
|
-
node.attributes.push(this.jsx_parseAttribute());
|
|
10319
|
-
node.selfClosing = this.eat(tt.slash);
|
|
10320
|
-
this.expect(tok.jsxTagEnd);
|
|
10321
|
-
return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
|
|
10322
|
-
}
|
|
10241
|
+
default:
|
|
10242
|
+
this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
|
|
10243
|
+
}
|
|
10244
|
+
}
|
|
10323
10245
|
|
|
10324
|
-
|
|
10246
|
+
// JSXEmptyExpression is unique type since it doesn't actually parse anything,
|
|
10247
|
+
// and so it should start at the end of last read token (left brace) and finish
|
|
10248
|
+
// at the beginning of the next one (right brace).
|
|
10325
10249
|
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
this.expect(tok.jsxTagEnd);
|
|
10331
|
-
return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
|
|
10332
|
-
}
|
|
10250
|
+
jsx_parseEmptyExpression() {
|
|
10251
|
+
let node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
|
|
10252
|
+
return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
|
|
10253
|
+
}
|
|
10333
10254
|
|
|
10334
|
-
|
|
10335
|
-
// (starting after '<'), attributes, contents and closing tag.
|
|
10336
|
-
|
|
10337
|
-
jsx_parseElementAt(startPos, startLoc) {
|
|
10338
|
-
let node = this.startNodeAt(startPos, startLoc);
|
|
10339
|
-
let children = [];
|
|
10340
|
-
let openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
|
|
10341
|
-
let closingElement = null;
|
|
10342
|
-
|
|
10343
|
-
if (!openingElement.selfClosing) {
|
|
10344
|
-
contents: for (;;) {
|
|
10345
|
-
switch (this.type) {
|
|
10346
|
-
case tok.jsxTagStart:
|
|
10347
|
-
startPos = this.start; startLoc = this.startLoc;
|
|
10348
|
-
this.next();
|
|
10349
|
-
if (this.eat(tt.slash)) {
|
|
10350
|
-
closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
|
|
10351
|
-
break contents;
|
|
10352
|
-
}
|
|
10353
|
-
children.push(this.jsx_parseElementAt(startPos, startLoc));
|
|
10354
|
-
break;
|
|
10255
|
+
// Parses JSX expression enclosed into curly brackets.
|
|
10355
10256
|
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
|
|
10257
|
+
jsx_parseExpressionContainer() {
|
|
10258
|
+
let node = this.startNode();
|
|
10259
|
+
this.next();
|
|
10260
|
+
node.expression = this.type === tt.braceR
|
|
10261
|
+
? this.jsx_parseEmptyExpression()
|
|
10262
|
+
: this.parseExpression();
|
|
10263
|
+
this.expect(tt.braceR);
|
|
10264
|
+
return this.finishNode(node, 'JSXExpressionContainer');
|
|
10265
|
+
}
|
|
10266
|
+
|
|
10267
|
+
// Parses following JSX attribute name-value pair.
|
|
10268
|
+
|
|
10269
|
+
jsx_parseAttribute() {
|
|
10270
|
+
let node = this.startNode();
|
|
10271
|
+
if (this.eat(tt.braceL)) {
|
|
10272
|
+
this.expect(tt.ellipsis);
|
|
10273
|
+
node.argument = this.parseMaybeAssign();
|
|
10274
|
+
this.expect(tt.braceR);
|
|
10275
|
+
return this.finishNode(node, 'JSXSpreadAttribute');
|
|
10276
|
+
}
|
|
10277
|
+
node.name = this.jsx_parseNamespacedName();
|
|
10278
|
+
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
|
10279
|
+
return this.finishNode(node, 'JSXAttribute');
|
|
10280
|
+
}
|
|
10281
|
+
|
|
10282
|
+
// Parses JSX opening tag starting after '<'.
|
|
10283
|
+
|
|
10284
|
+
jsx_parseOpeningElementAt(startPos, startLoc) {
|
|
10285
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
10286
|
+
node.attributes = [];
|
|
10287
|
+
let nodeName = this.jsx_parseElementName();
|
|
10288
|
+
if (nodeName) node.name = nodeName;
|
|
10289
|
+
while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
|
|
10290
|
+
node.attributes.push(this.jsx_parseAttribute());
|
|
10291
|
+
node.selfClosing = this.eat(tt.slash);
|
|
10292
|
+
this.expect(tok.jsxTagEnd);
|
|
10293
|
+
return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
|
|
10294
|
+
}
|
|
10295
|
+
|
|
10296
|
+
// Parses JSX closing tag starting after '</'.
|
|
10297
|
+
|
|
10298
|
+
jsx_parseClosingElementAt(startPos, startLoc) {
|
|
10299
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
10300
|
+
let nodeName = this.jsx_parseElementName();
|
|
10301
|
+
if (nodeName) node.name = nodeName;
|
|
10302
|
+
this.expect(tok.jsxTagEnd);
|
|
10303
|
+
return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
|
|
10304
|
+
}
|
|
10305
|
+
|
|
10306
|
+
// Parses entire JSX element, including it's opening tag
|
|
10307
|
+
// (starting after '<'), attributes, contents and closing tag.
|
|
10308
|
+
|
|
10309
|
+
jsx_parseElementAt(startPos, startLoc) {
|
|
10310
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
10311
|
+
let children = [];
|
|
10312
|
+
let openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
|
|
10313
|
+
let closingElement = null;
|
|
10314
|
+
|
|
10315
|
+
if (!openingElement.selfClosing) {
|
|
10316
|
+
contents: for (;;) {
|
|
10317
|
+
switch (this.type) {
|
|
10318
|
+
case tok.jsxTagStart:
|
|
10319
|
+
startPos = this.start; startLoc = this.startLoc;
|
|
10320
|
+
this.next();
|
|
10321
|
+
if (this.eat(tt.slash)) {
|
|
10322
|
+
closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
|
|
10323
|
+
break contents;
|
|
10324
|
+
}
|
|
10325
|
+
children.push(this.jsx_parseElementAt(startPos, startLoc));
|
|
10326
|
+
break;
|
|
10359
10327
|
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
|
|
10328
|
+
case tok.jsxText:
|
|
10329
|
+
children.push(this.parseExprAtom());
|
|
10330
|
+
break;
|
|
10363
10331
|
|
|
10364
|
-
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
}
|
|
10368
|
-
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
|
|
10369
|
-
this.raise(
|
|
10370
|
-
closingElement.start,
|
|
10371
|
-
'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
|
|
10372
|
-
}
|
|
10373
|
-
}
|
|
10374
|
-
let fragmentOrElement = openingElement.name ? 'Element' : 'Fragment';
|
|
10375
|
-
|
|
10376
|
-
node['opening' + fragmentOrElement] = openingElement;
|
|
10377
|
-
node['closing' + fragmentOrElement] = closingElement;
|
|
10378
|
-
node.children = children;
|
|
10379
|
-
if (this.type === tt.relational && this.value === "<") {
|
|
10380
|
-
this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
|
|
10381
|
-
}
|
|
10382
|
-
return this.finishNode(node, 'JSX' + fragmentOrElement);
|
|
10383
|
-
}
|
|
10332
|
+
case tt.braceL:
|
|
10333
|
+
children.push(this.jsx_parseExpressionContainer());
|
|
10334
|
+
break;
|
|
10384
10335
|
|
|
10385
|
-
|
|
10336
|
+
default:
|
|
10337
|
+
this.unexpected();
|
|
10338
|
+
}
|
|
10339
|
+
}
|
|
10340
|
+
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
|
|
10341
|
+
this.raise(
|
|
10342
|
+
closingElement.start,
|
|
10343
|
+
'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
|
|
10344
|
+
}
|
|
10345
|
+
}
|
|
10346
|
+
let fragmentOrElement = openingElement.name ? 'Element' : 'Fragment';
|
|
10386
10347
|
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10348
|
+
node['opening' + fragmentOrElement] = openingElement;
|
|
10349
|
+
node['closing' + fragmentOrElement] = closingElement;
|
|
10350
|
+
node.children = children;
|
|
10351
|
+
if (this.type === tt.relational && this.value === "<") {
|
|
10352
|
+
this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
|
|
10353
|
+
}
|
|
10354
|
+
return this.finishNode(node, 'JSX' + fragmentOrElement);
|
|
10355
|
+
}
|
|
10392
10356
|
|
|
10393
|
-
|
|
10357
|
+
// Parse JSX text
|
|
10394
10358
|
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10359
|
+
jsx_parseText() {
|
|
10360
|
+
let node = this.parseLiteral(this.value);
|
|
10361
|
+
node.type = "JSXText";
|
|
10362
|
+
return node;
|
|
10363
|
+
}
|
|
10400
10364
|
|
|
10401
|
-
|
|
10402
|
-
if (this.type === tok.jsxText)
|
|
10403
|
-
return this.jsx_parseText();
|
|
10404
|
-
else if (this.type === tok.jsxTagStart)
|
|
10405
|
-
return this.jsx_parseElement();
|
|
10406
|
-
else
|
|
10407
|
-
return super.parseExprAtom(refShortHandDefaultPos);
|
|
10408
|
-
}
|
|
10365
|
+
// Parses entire JSX element from current position.
|
|
10409
10366
|
|
|
10410
|
-
|
|
10411
|
-
|
|
10367
|
+
jsx_parseElement() {
|
|
10368
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
10369
|
+
this.next();
|
|
10370
|
+
return this.jsx_parseElementAt(startPos, startLoc);
|
|
10371
|
+
}
|
|
10412
10372
|
|
|
10413
|
-
|
|
10373
|
+
parseExprAtom(refShortHandDefaultPos) {
|
|
10374
|
+
if (this.type === tok.jsxText)
|
|
10375
|
+
return this.jsx_parseText();
|
|
10376
|
+
else if (this.type === tok.jsxTagStart)
|
|
10377
|
+
return this.jsx_parseElement();
|
|
10378
|
+
else
|
|
10379
|
+
return super.parseExprAtom(refShortHandDefaultPos);
|
|
10380
|
+
}
|
|
10414
10381
|
|
|
10415
|
-
|
|
10416
|
-
|
|
10382
|
+
readToken(code) {
|
|
10383
|
+
let context = this.curContext();
|
|
10417
10384
|
|
|
10418
|
-
|
|
10419
|
-
++this.pos;
|
|
10420
|
-
return this.finishToken(tok.jsxTagEnd);
|
|
10421
|
-
}
|
|
10385
|
+
if (context === tc_expr) return this.jsx_readToken();
|
|
10422
10386
|
|
|
10423
|
-
|
|
10424
|
-
|
|
10425
|
-
}
|
|
10387
|
+
if (context === tc_oTag || context === tc_cTag) {
|
|
10388
|
+
if (isIdentifierStart(code)) return this.jsx_readWord();
|
|
10426
10389
|
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
return super.readToken(code);
|
|
10432
|
-
}
|
|
10390
|
+
if (code == 62) {
|
|
10391
|
+
++this.pos;
|
|
10392
|
+
return this.finishToken(tok.jsxTagEnd);
|
|
10393
|
+
}
|
|
10433
10394
|
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10437
|
-
if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
|
|
10438
|
-
else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
|
|
10439
|
-
else super.updateContext(prevType);
|
|
10440
|
-
this.exprAllowed = true;
|
|
10441
|
-
} else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
|
|
10442
|
-
this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
|
|
10443
|
-
this.context.push(tc_cTag); // reconsider as closing tag context
|
|
10444
|
-
this.exprAllowed = false;
|
|
10445
|
-
} else {
|
|
10446
|
-
return super.updateContext(prevType);
|
|
10447
|
-
}
|
|
10448
|
-
}
|
|
10449
|
-
};
|
|
10450
|
-
}
|
|
10451
|
-
} (acornJsx));
|
|
10395
|
+
if ((code === 34 || code === 39) && context == tc_oTag)
|
|
10396
|
+
return this.jsx_readString(code);
|
|
10397
|
+
}
|
|
10452
10398
|
|
|
10453
|
-
|
|
10454
|
-
|
|
10399
|
+
if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
|
|
10400
|
+
++this.pos;
|
|
10401
|
+
return this.finishToken(tok.jsxTagStart);
|
|
10402
|
+
}
|
|
10403
|
+
return super.readToken(code);
|
|
10404
|
+
}
|
|
10405
|
+
|
|
10406
|
+
updateContext(prevType) {
|
|
10407
|
+
if (this.type == tt.braceL) {
|
|
10408
|
+
var curContext = this.curContext();
|
|
10409
|
+
if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
|
|
10410
|
+
else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
|
|
10411
|
+
else super.updateContext(prevType);
|
|
10412
|
+
this.exprAllowed = true;
|
|
10413
|
+
} else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
|
|
10414
|
+
this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
|
|
10415
|
+
this.context.push(tc_cTag); // reconsider as closing tag context
|
|
10416
|
+
this.exprAllowed = false;
|
|
10417
|
+
} else {
|
|
10418
|
+
return super.updateContext(prevType);
|
|
10419
|
+
}
|
|
10420
|
+
}
|
|
10421
|
+
};
|
|
10422
|
+
}
|
|
10455
10423
|
|
|
10456
10424
|
var unicode$3 = {};
|
|
10457
10425
|
|
|
@@ -18373,6 +18341,294 @@ var serialize = function(node, options) {
|
|
|
18373
18341
|
return serializer.serialize();
|
|
18374
18342
|
};
|
|
18375
18343
|
|
|
18344
|
+
const leftCurlyBrace = "{".charCodeAt(0);
|
|
18345
|
+
const space = " ".charCodeAt(0);
|
|
18346
|
+
|
|
18347
|
+
const withKeyword = "with";
|
|
18348
|
+
const assertKeyword = "assert";
|
|
18349
|
+
const FUNC_STATEMENT = 1, FUNC_NULLABLE_ID = 4;
|
|
18350
|
+
|
|
18351
|
+
const importAttributes = plugin({ keyword: "with" });
|
|
18352
|
+
|
|
18353
|
+
function plugin(options) {
|
|
18354
|
+
return function(Parser) {
|
|
18355
|
+
return pluginImpl(options, Parser);
|
|
18356
|
+
};
|
|
18357
|
+
}
|
|
18358
|
+
|
|
18359
|
+
function pluginImpl(options, Parser) {
|
|
18360
|
+
// Use supplied version acorn version if present, to avoid
|
|
18361
|
+
// reference mismatches due to different acorn versions. This
|
|
18362
|
+
// allows this plugin to be used with Rollup which supplies
|
|
18363
|
+
// its own internal version of acorn and thereby sidesteps
|
|
18364
|
+
// the package manager.
|
|
18365
|
+
const acorn = Parser.acorn || _acorn;
|
|
18366
|
+
const { tokTypes: tt, TokenType } = acorn;
|
|
18367
|
+
const { keyword } = options;
|
|
18368
|
+
const isWithKeyword = keyword.includes(withKeyword);
|
|
18369
|
+
const isAssertKeyword = keyword.includes(assertKeyword);
|
|
18370
|
+
const isWithOrAssertKeyword = isWithKeyword && isAssertKeyword;
|
|
18371
|
+
|
|
18372
|
+
return class extends Parser {
|
|
18373
|
+
constructor(...args) {
|
|
18374
|
+
super(...args);
|
|
18375
|
+
this.withToken = isWithKeyword && new TokenType(withKeyword);
|
|
18376
|
+
this.assertToken = isAssertKeyword && new TokenType(assertKeyword);
|
|
18377
|
+
}
|
|
18378
|
+
|
|
18379
|
+
_codeAt(i) {
|
|
18380
|
+
return this.input.charCodeAt(i);
|
|
18381
|
+
}
|
|
18382
|
+
|
|
18383
|
+
_eat(t) {
|
|
18384
|
+
if (this.type !== t) {
|
|
18385
|
+
this.unexpected();
|
|
18386
|
+
}
|
|
18387
|
+
this.next();
|
|
18388
|
+
}
|
|
18389
|
+
|
|
18390
|
+
_matchKeywordToken() {
|
|
18391
|
+
return (isWithOrAssertKeyword && (this.type === this.withToken || this.type === this.assertToken))
|
|
18392
|
+
|| (isWithKeyword && this.type === this.withToken)
|
|
18393
|
+
|| (isAssertKeyword && this.type === this.assertToken)
|
|
18394
|
+
}
|
|
18395
|
+
|
|
18396
|
+
_getProperty() {
|
|
18397
|
+
if (isWithOrAssertKeyword) {
|
|
18398
|
+
return this.type === this.withToken ? "attributes" : "assertions";
|
|
18399
|
+
}
|
|
18400
|
+
return isWithKeyword ? "attributes" : "assertions";
|
|
18401
|
+
}
|
|
18402
|
+
|
|
18403
|
+
readToken(code) {
|
|
18404
|
+
let i = 0;
|
|
18405
|
+
let keyword;
|
|
18406
|
+
let token;
|
|
18407
|
+
if (isWithOrAssertKeyword) {
|
|
18408
|
+
if (this.input.slice(this.pos, this.pos + withKeyword.length) === withKeyword) {
|
|
18409
|
+
keyword = withKeyword;
|
|
18410
|
+
token = this.withToken;
|
|
18411
|
+
} else if (this.input.slice(this.pos, this.pos + assertKeyword.length) === assertKeyword) {
|
|
18412
|
+
keyword = assertKeyword;
|
|
18413
|
+
token = this.assertToken;
|
|
18414
|
+
} else {
|
|
18415
|
+
return super.readToken(code);
|
|
18416
|
+
}
|
|
18417
|
+
i += keyword.length;
|
|
18418
|
+
} else {
|
|
18419
|
+
keyword = isWithKeyword ? withKeyword : assertKeyword;
|
|
18420
|
+
token = isWithKeyword ? this.withToken : this.assertToken;
|
|
18421
|
+
for (; i < keyword.length; i++) {
|
|
18422
|
+
if (this._codeAt(this.pos + i) !== keyword.charCodeAt(i)) {
|
|
18423
|
+
return super.readToken(code);
|
|
18424
|
+
}
|
|
18425
|
+
}
|
|
18426
|
+
}
|
|
18427
|
+
|
|
18428
|
+
// ensure that the keyword is at the correct location
|
|
18429
|
+
// ie `with{...` or `with {...`
|
|
18430
|
+
for (;; i++) {
|
|
18431
|
+
if (this._codeAt(this.pos + i) === leftCurlyBrace) {
|
|
18432
|
+
// Found '{'
|
|
18433
|
+
break;
|
|
18434
|
+
} else if (this._codeAt(this.pos + i) === space) {
|
|
18435
|
+
// white space is allowed between `with` and `{`, so continue.
|
|
18436
|
+
continue;
|
|
18437
|
+
} else {
|
|
18438
|
+
return super.readToken(code);
|
|
18439
|
+
}
|
|
18440
|
+
}
|
|
18441
|
+
|
|
18442
|
+
// If we're inside a dynamic import expression we'll parse
|
|
18443
|
+
// the `with` keyword as a standard object property name
|
|
18444
|
+
// ie `import(""./foo.json", { with: { type: "json" } })`
|
|
18445
|
+
if (this.type.label === "{") {
|
|
18446
|
+
return super.readToken(code);
|
|
18447
|
+
}
|
|
18448
|
+
|
|
18449
|
+
this.pos += keyword.length;
|
|
18450
|
+
return this.finishToken(token);
|
|
18451
|
+
}
|
|
18452
|
+
|
|
18453
|
+
parseDynamicImport(node) {
|
|
18454
|
+
this.next(); // skip `(`
|
|
18455
|
+
|
|
18456
|
+
// Parse node.source.
|
|
18457
|
+
node.source = this.parseMaybeAssign();
|
|
18458
|
+
|
|
18459
|
+
if (this.eat(tt.comma)) {
|
|
18460
|
+
const expr = this.parseExpression();
|
|
18461
|
+
node.arguments = [expr];
|
|
18462
|
+
}
|
|
18463
|
+
this._eat(tt.parenR);
|
|
18464
|
+
return this.finishNode(node, "ImportExpression");
|
|
18465
|
+
}
|
|
18466
|
+
|
|
18467
|
+
// ported from acorn/src/statement.js pp.parseExport
|
|
18468
|
+
parseExport(node, exports) {
|
|
18469
|
+
this.next();
|
|
18470
|
+
// export * from '...'
|
|
18471
|
+
if (this.eat(tt.star)) {
|
|
18472
|
+
if (this.options.ecmaVersion >= 11) {
|
|
18473
|
+
if (this.eatContextual("as")) {
|
|
18474
|
+
node.exported = this.parseIdent(true);
|
|
18475
|
+
this.checkExport(exports, node.exported.name, this.lastTokStart);
|
|
18476
|
+
} else {
|
|
18477
|
+
node.exported = null;
|
|
18478
|
+
}
|
|
18479
|
+
}
|
|
18480
|
+
this.expectContextual("from");
|
|
18481
|
+
if (this.type !== tt.string) { this.unexpected(); }
|
|
18482
|
+
node.source = this.parseExprAtom();
|
|
18483
|
+
|
|
18484
|
+
if (this._matchKeywordToken()) {
|
|
18485
|
+
const property = this._getProperty();
|
|
18486
|
+
this.next();
|
|
18487
|
+
const attributes = this.parseImportAttributes();
|
|
18488
|
+
if (attributes) {
|
|
18489
|
+
node[property] = attributes;
|
|
18490
|
+
}
|
|
18491
|
+
}
|
|
18492
|
+
|
|
18493
|
+
this.semicolon();
|
|
18494
|
+
return this.finishNode(node, "ExportAllDeclaration")
|
|
18495
|
+
}
|
|
18496
|
+
if (this.eat(tt._default)) { // export default ...
|
|
18497
|
+
this.checkExport(exports, "default", this.lastTokStart);
|
|
18498
|
+
var isAsync;
|
|
18499
|
+
if (this.type === tt._function || (isAsync = this.isAsyncFunction())) {
|
|
18500
|
+
var fNode = this.startNode();
|
|
18501
|
+
this.next();
|
|
18502
|
+
if (isAsync) { this.next(); }
|
|
18503
|
+
node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
|
|
18504
|
+
} else if (this.type === tt._class) {
|
|
18505
|
+
var cNode = this.startNode();
|
|
18506
|
+
node.declaration = this.parseClass(cNode, "nullableID");
|
|
18507
|
+
} else {
|
|
18508
|
+
node.declaration = this.parseMaybeAssign();
|
|
18509
|
+
this.semicolon();
|
|
18510
|
+
}
|
|
18511
|
+
return this.finishNode(node, "ExportDefaultDeclaration")
|
|
18512
|
+
}
|
|
18513
|
+
// export var|const|let|function|class ...
|
|
18514
|
+
if (this.shouldParseExportStatement()) {
|
|
18515
|
+
node.declaration = this.parseStatement(null);
|
|
18516
|
+
if (node.declaration.type === "VariableDeclaration")
|
|
18517
|
+
{ this.checkVariableExport(exports, node.declaration.declarations); }
|
|
18518
|
+
else
|
|
18519
|
+
{ this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
|
|
18520
|
+
node.specifiers = [];
|
|
18521
|
+
node.source = null;
|
|
18522
|
+
} else { // export { x, y as z } [from '...']
|
|
18523
|
+
node.declaration = null;
|
|
18524
|
+
node.specifiers = this.parseExportSpecifiers(exports);
|
|
18525
|
+
if (this.eatContextual("from")) {
|
|
18526
|
+
if (this.type !== tt.string) { this.unexpected(); }
|
|
18527
|
+
node.source = this.parseExprAtom();
|
|
18528
|
+
|
|
18529
|
+
if (this._matchKeywordToken()) {
|
|
18530
|
+
const property = this._getProperty();
|
|
18531
|
+
this.next();
|
|
18532
|
+
const attributes = this.parseImportAttributes();
|
|
18533
|
+
if (attributes) {
|
|
18534
|
+
node[property] = attributes;
|
|
18535
|
+
}
|
|
18536
|
+
}
|
|
18537
|
+
} else {
|
|
18538
|
+
for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
|
|
18539
|
+
// check for keywords used as local names
|
|
18540
|
+
var spec = list[i];
|
|
18541
|
+
|
|
18542
|
+
this.checkUnreserved(spec.local);
|
|
18543
|
+
// check if export is defined
|
|
18544
|
+
this.checkLocalExport(spec.local);
|
|
18545
|
+
}
|
|
18546
|
+
|
|
18547
|
+
node.source = null;
|
|
18548
|
+
}
|
|
18549
|
+
this.semicolon();
|
|
18550
|
+
}
|
|
18551
|
+
return this.finishNode(node, "ExportNamedDeclaration")
|
|
18552
|
+
}
|
|
18553
|
+
|
|
18554
|
+
parseImport(node) {
|
|
18555
|
+
this.next();
|
|
18556
|
+
// import '...'
|
|
18557
|
+
if (this.type === tt.string) {
|
|
18558
|
+
node.specifiers = [];
|
|
18559
|
+
node.source = this.parseExprAtom();
|
|
18560
|
+
} else {
|
|
18561
|
+
node.specifiers = this.parseImportSpecifiers();
|
|
18562
|
+
this.expectContextual("from");
|
|
18563
|
+
node.source =
|
|
18564
|
+
this.type === tt.string ? this.parseExprAtom() : this.unexpected();
|
|
18565
|
+
}
|
|
18566
|
+
|
|
18567
|
+
if (this._matchKeywordToken()) {
|
|
18568
|
+
const property = this._getProperty();
|
|
18569
|
+
this.next();
|
|
18570
|
+
const attributes = this.parseImportAttributes();
|
|
18571
|
+
if (attributes) {
|
|
18572
|
+
node[property] = attributes;
|
|
18573
|
+
}
|
|
18574
|
+
}
|
|
18575
|
+
this.semicolon();
|
|
18576
|
+
return this.finishNode(node, "ImportDeclaration");
|
|
18577
|
+
}
|
|
18578
|
+
|
|
18579
|
+
parseImportAttributes() {
|
|
18580
|
+
this._eat(tt.braceL);
|
|
18581
|
+
const attrs = this.parsewithEntries();
|
|
18582
|
+
this._eat(tt.braceR);
|
|
18583
|
+
return attrs;
|
|
18584
|
+
}
|
|
18585
|
+
|
|
18586
|
+
parsewithEntries() {
|
|
18587
|
+
const attrs = [];
|
|
18588
|
+
const attrNames = new Set();
|
|
18589
|
+
|
|
18590
|
+
do {
|
|
18591
|
+
if (this.type === tt.braceR) {
|
|
18592
|
+
break;
|
|
18593
|
+
}
|
|
18594
|
+
|
|
18595
|
+
const node = this.startNode();
|
|
18596
|
+
|
|
18597
|
+
// parse withionKey : IdentifierName, StringLiteral
|
|
18598
|
+
let withionKeyNode;
|
|
18599
|
+
if (this.type === tt.string) {
|
|
18600
|
+
withionKeyNode = this.parseLiteral(this.value);
|
|
18601
|
+
} else {
|
|
18602
|
+
withionKeyNode = this.parseIdent(true);
|
|
18603
|
+
}
|
|
18604
|
+
this.next();
|
|
18605
|
+
node.key = withionKeyNode;
|
|
18606
|
+
|
|
18607
|
+
// check if we already have an entry for an attribute
|
|
18608
|
+
// if a duplicate entry is found, throw an error
|
|
18609
|
+
// for now this logic will come into play only when someone declares `type` twice
|
|
18610
|
+
if (attrNames.has(node.key.name)) {
|
|
18611
|
+
this.raise(this.pos, "Duplicated key in attributes");
|
|
18612
|
+
}
|
|
18613
|
+
attrNames.add(node.key.name);
|
|
18614
|
+
|
|
18615
|
+
if (this.type !== tt.string) {
|
|
18616
|
+
this.raise(
|
|
18617
|
+
this.pos,
|
|
18618
|
+
"Only string is supported as an attribute value"
|
|
18619
|
+
);
|
|
18620
|
+
}
|
|
18621
|
+
|
|
18622
|
+
node.value = this.parseLiteral(this.value);
|
|
18623
|
+
|
|
18624
|
+
attrs.push(this.finishNode(node, "ImportAttribute"));
|
|
18625
|
+
} while (this.eat(tt.comma));
|
|
18626
|
+
|
|
18627
|
+
return attrs;
|
|
18628
|
+
}
|
|
18629
|
+
};
|
|
18630
|
+
}
|
|
18631
|
+
|
|
18376
18632
|
/* eslint-disable max-depth, complexity */
|
|
18377
18633
|
// https://nodejs.org/api/esm.html#esm_loaders
|
|
18378
18634
|
|
|
@@ -18396,7 +18652,7 @@ function getParser(moduleURL) {
|
|
|
18396
18652
|
}
|
|
18397
18653
|
|
|
18398
18654
|
return {
|
|
18399
|
-
parser: Parser$2.extend(
|
|
18655
|
+
parser: Parser$2.extend(acornJsx(), importAttributes),
|
|
18400
18656
|
config: {
|
|
18401
18657
|
// https://github.com/acornjs/acorn/issues/829#issuecomment-1172586171
|
|
18402
18658
|
...base$1,
|
|
@@ -18603,7 +18859,7 @@ function parseJsx(moduleURL) {
|
|
|
18603
18859
|
const hasOwnObservedAttributes = undefined;
|
|
18604
18860
|
let inferredObservability = false;
|
|
18605
18861
|
let observedAttributes = [];
|
|
18606
|
-
let tree = Parser$2.extend(
|
|
18862
|
+
let tree = Parser$2.extend(acornJsx(), importAttributes).parse(moduleContents, {
|
|
18607
18863
|
ecmaVersion: 'latest',
|
|
18608
18864
|
sourceType: 'module'
|
|
18609
18865
|
});
|
|
@@ -18728,7 +18984,7 @@ function parseJsx(moduleURL) {
|
|
|
18728
18984
|
`;
|
|
18729
18985
|
/* eslint-enable indent */
|
|
18730
18986
|
|
|
18731
|
-
tree = Parser$2.extend(
|
|
18987
|
+
tree = Parser$2.extend(acornJsx()).parse(newModuleContents, {
|
|
18732
18988
|
ecmaVersion: 'latest',
|
|
18733
18989
|
sourceType: 'module'
|
|
18734
18990
|
});
|
|
@@ -18792,12 +19048,12 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
|
|
|
18792
19048
|
const moduleContents = fs.readFileSync(moduleURL, 'utf-8');
|
|
18793
19049
|
const nextDepth = depth += 1;
|
|
18794
19050
|
const customParser = getParser(moduleURL);
|
|
18795
|
-
const parser = customParser ? customParser.parser :
|
|
19051
|
+
const parser = customParser ? customParser.parser : Parser$2;
|
|
18796
19052
|
const config = customParser ? customParser.config : {
|
|
18797
19053
|
...base$1
|
|
18798
19054
|
};
|
|
18799
19055
|
|
|
18800
|
-
simple(parser.parse(moduleContents, {
|
|
19056
|
+
simple(parser.extend(importAttributes).parse(moduleContents, {
|
|
18801
19057
|
ecmaVersion: 'latest',
|
|
18802
19058
|
sourceType: 'module'
|
|
18803
19059
|
}), {
|
|
@@ -18837,13 +19093,13 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
|
|
|
18837
19093
|
async function getTagName(moduleURL) {
|
|
18838
19094
|
const moduleContents = await fs.promises.readFile(moduleURL, 'utf-8');
|
|
18839
19095
|
const customParser = getParser(moduleURL);
|
|
18840
|
-
const parser = customParser ? customParser.parser :
|
|
19096
|
+
const parser = customParser ? customParser.parser : Parser$2;
|
|
18841
19097
|
const config = customParser ? customParser.config : {
|
|
18842
19098
|
...base$1
|
|
18843
19099
|
};
|
|
18844
19100
|
let tagName;
|
|
18845
19101
|
|
|
18846
|
-
simple(parser.parse(moduleContents, {
|
|
19102
|
+
simple(parser.extend(importAttributes).parse(moduleContents, {
|
|
18847
19103
|
ecmaVersion: 'latest',
|
|
18848
19104
|
sourceType: 'module'
|
|
18849
19105
|
}), {
|
|
@@ -18864,9 +19120,10 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
18864
19120
|
}
|
|
18865
19121
|
|
|
18866
19122
|
// https://github.com/ProjectEvergreen/wcc/pull/67/files#r902061804
|
|
18867
|
-
|
|
18868
|
-
const
|
|
18869
|
-
const
|
|
19123
|
+
// https://github.com/ProjectEvergreen/wcc/pull/159
|
|
19124
|
+
const { href } = elementURL;
|
|
19125
|
+
const element = customElements.get(tagName) ?? (await import(href)).default;
|
|
19126
|
+
const dataLoader = (await import(href)).getData;
|
|
18870
19127
|
const data = props
|
|
18871
19128
|
? props
|
|
18872
19129
|
: dataLoader
|