wc-compiler 0.12.1 → 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 +378 -79
- package/package.json +9 -4
- package/src/dom-shim.js +11 -1
- package/src/jsx-loader.js +4 -2
- 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,
|
|
@@ -7085,7 +7095,7 @@ var Syntax,
|
|
|
7085
7095
|
quotes,
|
|
7086
7096
|
escapeless,
|
|
7087
7097
|
newline,
|
|
7088
|
-
space,
|
|
7098
|
+
space$1,
|
|
7089
7099
|
parentheses,
|
|
7090
7100
|
semicolons,
|
|
7091
7101
|
safeConcatenation,
|
|
@@ -7565,7 +7575,7 @@ function toSourceNodeWhenNeeded(generated, node) {
|
|
|
7565
7575
|
}
|
|
7566
7576
|
|
|
7567
7577
|
function noEmptySpace() {
|
|
7568
|
-
return (space) ? space : ' ';
|
|
7578
|
+
return (space$1) ? space$1 : ' ';
|
|
7569
7579
|
}
|
|
7570
7580
|
|
|
7571
7581
|
function join(left, right) {
|
|
@@ -7595,7 +7605,7 @@ function join(left, right) {
|
|
|
7595
7605
|
code.isWhiteSpace(rightCharCode) || code.isLineTerminator(rightCharCode)) {
|
|
7596
7606
|
return [left, right];
|
|
7597
7607
|
}
|
|
7598
|
-
return [left, space, right];
|
|
7608
|
+
return [left, space$1, right];
|
|
7599
7609
|
}
|
|
7600
7610
|
|
|
7601
7611
|
function addIndent(stmt) {
|
|
@@ -7861,7 +7871,7 @@ CodeGenerator.prototype.maybeBlock = function(stmt, flags) {
|
|
|
7861
7871
|
noLeadingComment = !extra.comment || !stmt.leadingComments;
|
|
7862
7872
|
|
|
7863
7873
|
if (stmt.type === Syntax.BlockStatement && noLeadingComment) {
|
|
7864
|
-
return [space, this.generateStatement(stmt, flags)];
|
|
7874
|
+
return [space$1, this.generateStatement(stmt, flags)];
|
|
7865
7875
|
}
|
|
7866
7876
|
|
|
7867
7877
|
if (stmt.type === Syntax.EmptyStatement && noLeadingComment) {
|
|
@@ -7881,7 +7891,7 @@ CodeGenerator.prototype.maybeBlock = function(stmt, flags) {
|
|
|
7881
7891
|
CodeGenerator.prototype.maybeBlockSuffix = function (stmt, result) {
|
|
7882
7892
|
var ends = endsWithLineTerminator(toSourceNodeWhenNeeded(result).toString());
|
|
7883
7893
|
if (stmt.type === Syntax.BlockStatement && (!extra.comment || !stmt.leadingComments) && !ends) {
|
|
7884
|
-
return [result, space];
|
|
7894
|
+
return [result, space$1];
|
|
7885
7895
|
}
|
|
7886
7896
|
if (ends) {
|
|
7887
7897
|
return [result, base];
|
|
@@ -7894,12 +7904,12 @@ function generateIdentifier(node) {
|
|
|
7894
7904
|
}
|
|
7895
7905
|
|
|
7896
7906
|
function generateAsyncPrefix(node, spaceRequired) {
|
|
7897
|
-
return node.async ? 'async' + (spaceRequired ? noEmptySpace() : space) : '';
|
|
7907
|
+
return node.async ? 'async' + (spaceRequired ? noEmptySpace() : space$1) : '';
|
|
7898
7908
|
}
|
|
7899
7909
|
|
|
7900
7910
|
function generateStarSuffix(node) {
|
|
7901
7911
|
var isGenerator = node.generator && !extra.moz.starlessGenerator;
|
|
7902
|
-
return isGenerator ? '*' + space : '';
|
|
7912
|
+
return isGenerator ? '*' + space$1 : '';
|
|
7903
7913
|
}
|
|
7904
7914
|
|
|
7905
7915
|
function generateMethodPrefix(prop) {
|
|
@@ -7945,13 +7955,13 @@ CodeGenerator.prototype.generateFunctionParams = function (node) {
|
|
|
7945
7955
|
result.push(this.generatePattern(node.params[i], Precedence.Assignment, E_TTT));
|
|
7946
7956
|
}
|
|
7947
7957
|
if (i + 1 < iz) {
|
|
7948
|
-
result.push(',' + space);
|
|
7958
|
+
result.push(',' + space$1);
|
|
7949
7959
|
}
|
|
7950
7960
|
}
|
|
7951
7961
|
|
|
7952
7962
|
if (node.rest) {
|
|
7953
7963
|
if (node.params.length) {
|
|
7954
|
-
result.push(',' + space);
|
|
7964
|
+
result.push(',' + space$1);
|
|
7955
7965
|
}
|
|
7956
7966
|
result.push('...');
|
|
7957
7967
|
result.push(generateIdentifier(node.rest));
|
|
@@ -7969,12 +7979,12 @@ CodeGenerator.prototype.generateFunctionBody = function (node) {
|
|
|
7969
7979
|
result = this.generateFunctionParams(node);
|
|
7970
7980
|
|
|
7971
7981
|
if (node.type === Syntax.ArrowFunctionExpression) {
|
|
7972
|
-
result.push(space);
|
|
7982
|
+
result.push(space$1);
|
|
7973
7983
|
result.push('=>');
|
|
7974
7984
|
}
|
|
7975
7985
|
|
|
7976
7986
|
if (node.expression) {
|
|
7977
|
-
result.push(space);
|
|
7987
|
+
result.push(space$1);
|
|
7978
7988
|
expr = this.generateExpression(node.body, Precedence.Assignment, E_TTT);
|
|
7979
7989
|
if (expr.toString().charAt(0) === '{') {
|
|
7980
7990
|
expr = ['(', expr, ')'];
|
|
@@ -7988,7 +7998,7 @@ CodeGenerator.prototype.generateFunctionBody = function (node) {
|
|
|
7988
7998
|
};
|
|
7989
7999
|
|
|
7990
8000
|
CodeGenerator.prototype.generateIterationForStatement = function (operator, stmt, flags) {
|
|
7991
|
-
var result = ['for' + (stmt.await ? noEmptySpace() + 'await' : '') + space + '('], that = this;
|
|
8001
|
+
var result = ['for' + (stmt.await ? noEmptySpace() + 'await' : '') + space$1 + '('], that = this;
|
|
7992
8002
|
withIndent(function () {
|
|
7993
8003
|
if (stmt.left.type === Syntax.VariableDeclaration) {
|
|
7994
8004
|
withIndent(function () {
|
|
@@ -8033,7 +8043,7 @@ CodeGenerator.prototype.generateAssignment = function (left, right, operator, pr
|
|
|
8033
8043
|
return parenthesize(
|
|
8034
8044
|
[
|
|
8035
8045
|
this.generateExpression(left, Precedence.Call, flags),
|
|
8036
|
-
space + operator + space,
|
|
8046
|
+
space$1 + operator + space$1,
|
|
8037
8047
|
this.generateExpression(right, Precedence.Assignment, flags)
|
|
8038
8048
|
],
|
|
8039
8049
|
Precedence.Assignment,
|
|
@@ -8183,7 +8193,7 @@ CodeGenerator.Statement = {
|
|
|
8183
8193
|
fragment = join('extends', this.generateExpression(stmt.superClass, Precedence.Unary, E_TTT));
|
|
8184
8194
|
result = join(result, fragment);
|
|
8185
8195
|
}
|
|
8186
|
-
result.push(space);
|
|
8196
|
+
result.push(space$1);
|
|
8187
8197
|
result.push(this.generateStatement(stmt.body, S_TFFT));
|
|
8188
8198
|
return result;
|
|
8189
8199
|
},
|
|
@@ -8200,7 +8210,7 @@ CodeGenerator.Statement = {
|
|
|
8200
8210
|
var result = join('do', this.maybeBlock(stmt.body, S_TFFF));
|
|
8201
8211
|
result = this.maybeBlockSuffix(stmt.body, result);
|
|
8202
8212
|
return join(result, [
|
|
8203
|
-
'while' + space + '(',
|
|
8213
|
+
'while' + space$1 + '(',
|
|
8204
8214
|
this.generateExpression(stmt.test, Precedence.Sequence, E_TTT),
|
|
8205
8215
|
')' + this.semicolon(flags)
|
|
8206
8216
|
]);
|
|
@@ -8213,7 +8223,7 @@ CodeGenerator.Statement = {
|
|
|
8213
8223
|
|
|
8214
8224
|
if (stmt.param) {
|
|
8215
8225
|
result = [
|
|
8216
|
-
'catch' + space + '(',
|
|
8226
|
+
'catch' + space$1 + '(',
|
|
8217
8227
|
that.generateExpression(stmt.param, Precedence.Sequence, E_TTT),
|
|
8218
8228
|
')'
|
|
8219
8229
|
];
|
|
@@ -8269,7 +8279,7 @@ CodeGenerator.Statement = {
|
|
|
8269
8279
|
// export ExportClause ;
|
|
8270
8280
|
if (stmt.specifiers) {
|
|
8271
8281
|
if (stmt.specifiers.length === 0) {
|
|
8272
|
-
result = join(result, '{' + space + '}');
|
|
8282
|
+
result = join(result, '{' + space$1 + '}');
|
|
8273
8283
|
} else if (stmt.specifiers[0].type === Syntax.ExportBatchSpecifier) {
|
|
8274
8284
|
result = join(result, this.generateExpression(stmt.specifiers[0], Precedence.Sequence, E_TTT));
|
|
8275
8285
|
} else {
|
|
@@ -8293,7 +8303,7 @@ CodeGenerator.Statement = {
|
|
|
8293
8303
|
|
|
8294
8304
|
if (stmt.source) {
|
|
8295
8305
|
result = join(result, [
|
|
8296
|
-
'from' + space,
|
|
8306
|
+
'from' + space$1,
|
|
8297
8307
|
// ModuleSpecifier
|
|
8298
8308
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8299
8309
|
this.semicolon(flags)
|
|
@@ -8308,9 +8318,9 @@ CodeGenerator.Statement = {
|
|
|
8308
8318
|
ExportAllDeclaration: function (stmt, flags) {
|
|
8309
8319
|
// export * FromClause ;
|
|
8310
8320
|
return [
|
|
8311
|
-
'export' + space,
|
|
8312
|
-
'*' + space,
|
|
8313
|
-
'from' + space,
|
|
8321
|
+
'export' + space$1,
|
|
8322
|
+
'*' + space$1,
|
|
8323
|
+
'from' + space$1,
|
|
8314
8324
|
// ModuleSpecifier
|
|
8315
8325
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8316
8326
|
this.semicolon(flags)
|
|
@@ -8390,7 +8400,7 @@ CodeGenerator.Statement = {
|
|
|
8390
8400
|
// import ModuleSpecifier ;
|
|
8391
8401
|
return [
|
|
8392
8402
|
'import',
|
|
8393
|
-
space,
|
|
8403
|
+
space$1,
|
|
8394
8404
|
// ModuleSpecifier
|
|
8395
8405
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8396
8406
|
this.semicolon(flags)
|
|
@@ -8419,18 +8429,18 @@ CodeGenerator.Statement = {
|
|
|
8419
8429
|
if (stmt.specifiers[cursor].type === Syntax.ImportNamespaceSpecifier) {
|
|
8420
8430
|
// NameSpaceImport
|
|
8421
8431
|
result = join(result, [
|
|
8422
|
-
space,
|
|
8432
|
+
space$1,
|
|
8423
8433
|
this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT)
|
|
8424
8434
|
]);
|
|
8425
8435
|
} else {
|
|
8426
8436
|
// NamedImports
|
|
8427
|
-
result.push(space + '{');
|
|
8437
|
+
result.push(space$1 + '{');
|
|
8428
8438
|
|
|
8429
8439
|
if ((stmt.specifiers.length - cursor) === 1) {
|
|
8430
8440
|
// import { ... } from "...";
|
|
8431
|
-
result.push(space);
|
|
8441
|
+
result.push(space$1);
|
|
8432
8442
|
result.push(this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT));
|
|
8433
|
-
result.push(space + '}' + space);
|
|
8443
|
+
result.push(space$1 + '}' + space$1);
|
|
8434
8444
|
} else {
|
|
8435
8445
|
// import {
|
|
8436
8446
|
// ...,
|
|
@@ -8450,13 +8460,13 @@ CodeGenerator.Statement = {
|
|
|
8450
8460
|
if (!endsWithLineTerminator(toSourceNodeWhenNeeded(result).toString())) {
|
|
8451
8461
|
result.push(newline);
|
|
8452
8462
|
}
|
|
8453
|
-
result.push(base + '}' + space);
|
|
8463
|
+
result.push(base + '}' + space$1);
|
|
8454
8464
|
}
|
|
8455
8465
|
}
|
|
8456
8466
|
}
|
|
8457
8467
|
|
|
8458
8468
|
result = join(result, [
|
|
8459
|
-
'from' + space,
|
|
8469
|
+
'from' + space$1,
|
|
8460
8470
|
// ModuleSpecifier
|
|
8461
8471
|
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
|
|
8462
8472
|
this.semicolon(flags)
|
|
@@ -8469,9 +8479,9 @@ CodeGenerator.Statement = {
|
|
|
8469
8479
|
if (stmt.init) {
|
|
8470
8480
|
return [
|
|
8471
8481
|
this.generateExpression(stmt.id, Precedence.Assignment, itemFlags),
|
|
8472
|
-
space,
|
|
8482
|
+
space$1,
|
|
8473
8483
|
'=',
|
|
8474
|
-
space,
|
|
8484
|
+
space$1,
|
|
8475
8485
|
this.generateExpression(stmt.init, Precedence.Assignment, itemFlags)
|
|
8476
8486
|
];
|
|
8477
8487
|
}
|
|
@@ -8504,7 +8514,7 @@ CodeGenerator.Statement = {
|
|
|
8504
8514
|
result.push(',' + newline);
|
|
8505
8515
|
result.push(addIndent(that.generateStatement(node, bodyFlags)));
|
|
8506
8516
|
} else {
|
|
8507
|
-
result.push(',' + space);
|
|
8517
|
+
result.push(',' + space$1);
|
|
8508
8518
|
result.push(that.generateStatement(node, bodyFlags));
|
|
8509
8519
|
}
|
|
8510
8520
|
}
|
|
@@ -8579,9 +8589,9 @@ CodeGenerator.Statement = {
|
|
|
8579
8589
|
var result, fragment, i, iz, bodyFlags, that = this;
|
|
8580
8590
|
withIndent(function () {
|
|
8581
8591
|
result = [
|
|
8582
|
-
'switch' + space + '(',
|
|
8592
|
+
'switch' + space$1 + '(',
|
|
8583
8593
|
that.generateExpression(stmt.discriminant, Precedence.Sequence, E_TTT),
|
|
8584
|
-
')' + space + '{' + newline
|
|
8594
|
+
')' + space$1 + '{' + newline
|
|
8585
8595
|
];
|
|
8586
8596
|
});
|
|
8587
8597
|
if (stmt.cases) {
|
|
@@ -8644,7 +8654,7 @@ CodeGenerator.Statement = {
|
|
|
8644
8654
|
var result, bodyFlags, semicolonOptional, that = this;
|
|
8645
8655
|
withIndent(function () {
|
|
8646
8656
|
result = [
|
|
8647
|
-
'if' + space + '(',
|
|
8657
|
+
'if' + space$1 + '(',
|
|
8648
8658
|
that.generateExpression(stmt.test, Precedence.Sequence, E_TTT),
|
|
8649
8659
|
')'
|
|
8650
8660
|
];
|
|
@@ -8671,7 +8681,7 @@ CodeGenerator.Statement = {
|
|
|
8671
8681
|
ForStatement: function (stmt, flags) {
|
|
8672
8682
|
var result, that = this;
|
|
8673
8683
|
withIndent(function () {
|
|
8674
|
-
result = ['for' + space + '('];
|
|
8684
|
+
result = ['for' + space$1 + '('];
|
|
8675
8685
|
if (stmt.init) {
|
|
8676
8686
|
if (stmt.init.type === Syntax.VariableDeclaration) {
|
|
8677
8687
|
result.push(that.generateStatement(stmt.init, S_FFFF));
|
|
@@ -8685,7 +8695,7 @@ CodeGenerator.Statement = {
|
|
|
8685
8695
|
}
|
|
8686
8696
|
|
|
8687
8697
|
if (stmt.test) {
|
|
8688
|
-
result.push(space);
|
|
8698
|
+
result.push(space$1);
|
|
8689
8699
|
result.push(that.generateExpression(stmt.test, Precedence.Sequence, E_TTT));
|
|
8690
8700
|
result.push(';');
|
|
8691
8701
|
} else {
|
|
@@ -8693,7 +8703,7 @@ CodeGenerator.Statement = {
|
|
|
8693
8703
|
}
|
|
8694
8704
|
|
|
8695
8705
|
if (stmt.update) {
|
|
8696
|
-
result.push(space);
|
|
8706
|
+
result.push(space$1);
|
|
8697
8707
|
result.push(that.generateExpression(stmt.update, Precedence.Sequence, E_TTT));
|
|
8698
8708
|
result.push(')');
|
|
8699
8709
|
} else {
|
|
@@ -8791,7 +8801,7 @@ CodeGenerator.Statement = {
|
|
|
8791
8801
|
var result, that = this;
|
|
8792
8802
|
withIndent(function () {
|
|
8793
8803
|
result = [
|
|
8794
|
-
'while' + space + '(',
|
|
8804
|
+
'while' + space$1 + '(',
|
|
8795
8805
|
that.generateExpression(stmt.test, Precedence.Sequence, E_TTT),
|
|
8796
8806
|
')'
|
|
8797
8807
|
];
|
|
@@ -8804,7 +8814,7 @@ CodeGenerator.Statement = {
|
|
|
8804
8814
|
var result, that = this;
|
|
8805
8815
|
withIndent(function () {
|
|
8806
8816
|
result = [
|
|
8807
|
-
'with' + space + '(',
|
|
8817
|
+
'with' + space$1 + '(',
|
|
8808
8818
|
that.generateExpression(stmt.object, Precedence.Sequence, E_TTT),
|
|
8809
8819
|
')'
|
|
8810
8820
|
];
|
|
@@ -8830,7 +8840,7 @@ CodeGenerator.Expression = {
|
|
|
8830
8840
|
for (i = 0, iz = expr.expressions.length; i < iz; ++i) {
|
|
8831
8841
|
result.push(this.generateExpression(expr.expressions[i], Precedence.Assignment, flags));
|
|
8832
8842
|
if (i + 1 < iz) {
|
|
8833
|
-
result.push(',' + space);
|
|
8843
|
+
result.push(',' + space$1);
|
|
8834
8844
|
}
|
|
8835
8845
|
}
|
|
8836
8846
|
return parenthesize(result, Precedence.Sequence, precedence);
|
|
@@ -8851,9 +8861,9 @@ CodeGenerator.Expression = {
|
|
|
8851
8861
|
return parenthesize(
|
|
8852
8862
|
[
|
|
8853
8863
|
this.generateExpression(expr.test, Precedence.Coalesce, flags),
|
|
8854
|
-
space + '?' + space,
|
|
8864
|
+
space$1 + '?' + space$1,
|
|
8855
8865
|
this.generateExpression(expr.consequent, Precedence.Assignment, flags),
|
|
8856
|
-
space + ':' + space,
|
|
8866
|
+
space$1 + ':' + space$1,
|
|
8857
8867
|
this.generateExpression(expr.alternate, Precedence.Assignment, flags)
|
|
8858
8868
|
],
|
|
8859
8869
|
Precedence.Conditional,
|
|
@@ -8922,7 +8932,7 @@ CodeGenerator.Expression = {
|
|
|
8922
8932
|
for (i = 0, iz = expr['arguments'].length; i < iz; ++i) {
|
|
8923
8933
|
result.push(this.generateExpression(expr['arguments'][i], Precedence.Assignment, E_TTT));
|
|
8924
8934
|
if (i + 1 < iz) {
|
|
8925
|
-
result.push(',' + space);
|
|
8935
|
+
result.push(',' + space$1);
|
|
8926
8936
|
}
|
|
8927
8937
|
}
|
|
8928
8938
|
result.push(')');
|
|
@@ -8962,7 +8972,7 @@ CodeGenerator.Expression = {
|
|
|
8962
8972
|
for (i = 0, iz = length; i < iz; ++i) {
|
|
8963
8973
|
result.push(this.generateExpression(expr['arguments'][i], Precedence.Assignment, E_TTT));
|
|
8964
8974
|
if (i + 1 < iz) {
|
|
8965
|
-
result.push(',' + space);
|
|
8975
|
+
result.push(',' + space$1);
|
|
8966
8976
|
}
|
|
8967
8977
|
}
|
|
8968
8978
|
result.push(')');
|
|
@@ -9023,7 +9033,7 @@ CodeGenerator.Expression = {
|
|
|
9023
9033
|
var result, fragment, rightCharCode, leftSource, leftCharCode;
|
|
9024
9034
|
fragment = this.generateExpression(expr.argument, Precedence.Unary, E_TTT);
|
|
9025
9035
|
|
|
9026
|
-
if (space === '') {
|
|
9036
|
+
if (space$1 === '') {
|
|
9027
9037
|
result = join(expr.operator, fragment);
|
|
9028
9038
|
} else {
|
|
9029
9039
|
result = [expr.operator];
|
|
@@ -9104,7 +9114,7 @@ CodeGenerator.Expression = {
|
|
|
9104
9114
|
result.push(generateStarSuffix(expr) || noEmptySpace());
|
|
9105
9115
|
result.push(generateIdentifier(expr.id));
|
|
9106
9116
|
} else {
|
|
9107
|
-
result.push(generateStarSuffix(expr) || space);
|
|
9117
|
+
result.push(generateStarSuffix(expr) || space$1);
|
|
9108
9118
|
}
|
|
9109
9119
|
result.push(this.generateFunctionBody(expr));
|
|
9110
9120
|
return result;
|
|
@@ -9136,7 +9146,7 @@ CodeGenerator.Expression = {
|
|
|
9136
9146
|
result.push(that.generateExpression(expr.elements[i], Precedence.Assignment, E_TTT));
|
|
9137
9147
|
}
|
|
9138
9148
|
if (i + 1 < iz) {
|
|
9139
|
-
result.push(',' + (multiline ? newline : space));
|
|
9149
|
+
result.push(',' + (multiline ? newline : space$1));
|
|
9140
9150
|
}
|
|
9141
9151
|
}
|
|
9142
9152
|
});
|
|
@@ -9162,7 +9172,7 @@ CodeGenerator.Expression = {
|
|
|
9162
9172
|
fragment = join('extends', this.generateExpression(expr.superClass, Precedence.Unary, E_TTT));
|
|
9163
9173
|
result = join(result, fragment);
|
|
9164
9174
|
}
|
|
9165
|
-
result.push(space);
|
|
9175
|
+
result.push(space$1);
|
|
9166
9176
|
result.push(this.generateStatement(expr.body, S_TFFT));
|
|
9167
9177
|
return result;
|
|
9168
9178
|
},
|
|
@@ -9170,7 +9180,7 @@ CodeGenerator.Expression = {
|
|
|
9170
9180
|
MethodDefinition: function (expr, precedence, flags) {
|
|
9171
9181
|
var result, fragment;
|
|
9172
9182
|
if (expr['static']) {
|
|
9173
|
-
result = ['static' + space];
|
|
9183
|
+
result = ['static' + space$1];
|
|
9174
9184
|
} else {
|
|
9175
9185
|
result = [];
|
|
9176
9186
|
}
|
|
@@ -9215,7 +9225,7 @@ CodeGenerator.Expression = {
|
|
|
9215
9225
|
|
|
9216
9226
|
return [
|
|
9217
9227
|
this.generatePropertyKey(expr.key, expr.computed),
|
|
9218
|
-
':' + space,
|
|
9228
|
+
':' + space$1,
|
|
9219
9229
|
this.generateExpression(expr.value, Precedence.Assignment, E_TTT)
|
|
9220
9230
|
];
|
|
9221
9231
|
},
|
|
@@ -9242,7 +9252,7 @@ CodeGenerator.Expression = {
|
|
|
9242
9252
|
// dejavu.Class.declare({method2: function () {
|
|
9243
9253
|
// }});
|
|
9244
9254
|
if (!hasLineTerminator(toSourceNodeWhenNeeded(fragment).toString())) {
|
|
9245
|
-
return [ '{', space, fragment, space, '}' ];
|
|
9255
|
+
return [ '{', space$1, fragment, space$1, '}' ];
|
|
9246
9256
|
}
|
|
9247
9257
|
}
|
|
9248
9258
|
|
|
@@ -9309,7 +9319,7 @@ CodeGenerator.Expression = {
|
|
|
9309
9319
|
result.push(multiline ? indent : '');
|
|
9310
9320
|
result.push(that.generateExpression(expr.properties[i], Precedence.Sequence, E_TTT));
|
|
9311
9321
|
if (i + 1 < iz) {
|
|
9312
|
-
result.push(',' + (multiline ? newline : space));
|
|
9322
|
+
result.push(',' + (multiline ? newline : space$1));
|
|
9313
9323
|
}
|
|
9314
9324
|
}
|
|
9315
9325
|
});
|
|
@@ -9342,7 +9352,7 @@ CodeGenerator.Expression = {
|
|
|
9342
9352
|
var result = ['*'];
|
|
9343
9353
|
var id = expr.id || expr.local;
|
|
9344
9354
|
if (id) {
|
|
9345
|
-
result.push(space + 'as' + noEmptySpace() + generateIdentifier(id));
|
|
9355
|
+
result.push(space$1 + 'as' + noEmptySpace() + generateIdentifier(id));
|
|
9346
9356
|
}
|
|
9347
9357
|
return result;
|
|
9348
9358
|
},
|
|
@@ -9445,7 +9455,7 @@ CodeGenerator.Expression = {
|
|
|
9445
9455
|
}
|
|
9446
9456
|
|
|
9447
9457
|
if (expr.filter) {
|
|
9448
|
-
result = join(result, 'if' + space);
|
|
9458
|
+
result = join(result, 'if' + space$1);
|
|
9449
9459
|
fragment = this.generateExpression(expr.filter, Precedence.Sequence, E_TTT);
|
|
9450
9460
|
result = join(result, [ '(', fragment, ')' ]);
|
|
9451
9461
|
}
|
|
@@ -9474,7 +9484,7 @@ CodeGenerator.Expression = {
|
|
|
9474
9484
|
fragment = join(fragment, expr.of ? 'of' : 'in');
|
|
9475
9485
|
fragment = join(fragment, this.generateExpression(expr.right, Precedence.Sequence, E_TTT));
|
|
9476
9486
|
|
|
9477
|
-
return [ 'for' + space + '(', fragment, ')' ];
|
|
9487
|
+
return [ 'for' + space$1 + '(', fragment, ')' ];
|
|
9478
9488
|
},
|
|
9479
9489
|
|
|
9480
9490
|
SpreadElement: function (expr, precedence, flags) {
|
|
@@ -9508,9 +9518,9 @@ CodeGenerator.Expression = {
|
|
|
9508
9518
|
for (i = 0, iz = expr.quasis.length; i < iz; ++i) {
|
|
9509
9519
|
result.push(this.generateExpression(expr.quasis[i], Precedence.Primary, E_TTT));
|
|
9510
9520
|
if (i + 1 < iz) {
|
|
9511
|
-
result.push('${' + space);
|
|
9521
|
+
result.push('${' + space$1);
|
|
9512
9522
|
result.push(this.generateExpression(expr.expressions[i], Precedence.Sequence, E_TTT));
|
|
9513
|
-
result.push(space + '}');
|
|
9523
|
+
result.push(space$1 + '}');
|
|
9514
9524
|
}
|
|
9515
9525
|
}
|
|
9516
9526
|
result.push('`');
|
|
@@ -9619,9 +9629,9 @@ function generate(node, options) {
|
|
|
9619
9629
|
quotes = json ? 'double' : options.format.quotes;
|
|
9620
9630
|
escapeless = options.format.escapeless;
|
|
9621
9631
|
newline = options.format.newline;
|
|
9622
|
-
space = options.format.space;
|
|
9632
|
+
space$1 = options.format.space;
|
|
9623
9633
|
if (options.format.compact) {
|
|
9624
|
-
newline = space = indent = base = '';
|
|
9634
|
+
newline = space$1 = indent = base = '';
|
|
9625
9635
|
}
|
|
9626
9636
|
parentheses = options.format.parentheses;
|
|
9627
9637
|
semicolons = options.format.semicolons;
|
|
@@ -9998,7 +10008,7 @@ function getQualifiedJSXName(object) {
|
|
|
9998
10008
|
function acornJsx(options) {
|
|
9999
10009
|
options = options || {};
|
|
10000
10010
|
return function(Parser) {
|
|
10001
|
-
return plugin({
|
|
10011
|
+
return plugin$1({
|
|
10002
10012
|
allowNamespaces: options.allowNamespaces !== false,
|
|
10003
10013
|
allowNamespacedObjects: !!options.allowNamespacedObjects
|
|
10004
10014
|
}, Parser);
|
|
@@ -10008,13 +10018,13 @@ function acornJsx(options) {
|
|
|
10008
10018
|
// This can be different instances from the actual `tokTypes` this plugin uses.
|
|
10009
10019
|
Object.defineProperty(acornJsx, "tokTypes", {
|
|
10010
10020
|
get: function get_tokTypes() {
|
|
10011
|
-
return getJsxTokens(
|
|
10021
|
+
return getJsxTokens(_acorn).tokTypes
|
|
10012
10022
|
},
|
|
10013
10023
|
configurable: true,
|
|
10014
10024
|
enumerable: true
|
|
10015
10025
|
});
|
|
10016
10026
|
|
|
10017
|
-
function plugin(options, Parser) {
|
|
10027
|
+
function plugin$1(options, Parser) {
|
|
10018
10028
|
const acorn = Parser.acorn || require("acorn");
|
|
10019
10029
|
const acornJsx = getJsxTokens(acorn);
|
|
10020
10030
|
const tt = acorn.tokTypes;
|
|
@@ -18331,6 +18341,294 @@ var serialize = function(node, options) {
|
|
|
18331
18341
|
return serializer.serialize();
|
|
18332
18342
|
};
|
|
18333
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
|
+
|
|
18334
18632
|
/* eslint-disable max-depth, complexity */
|
|
18335
18633
|
// https://nodejs.org/api/esm.html#esm_loaders
|
|
18336
18634
|
|
|
@@ -18354,7 +18652,7 @@ function getParser(moduleURL) {
|
|
|
18354
18652
|
}
|
|
18355
18653
|
|
|
18356
18654
|
return {
|
|
18357
|
-
parser: Parser$2.extend(acornJsx()),
|
|
18655
|
+
parser: Parser$2.extend(acornJsx(), importAttributes),
|
|
18358
18656
|
config: {
|
|
18359
18657
|
// https://github.com/acornjs/acorn/issues/829#issuecomment-1172586171
|
|
18360
18658
|
...base$1,
|
|
@@ -18561,7 +18859,7 @@ function parseJsx(moduleURL) {
|
|
|
18561
18859
|
const hasOwnObservedAttributes = undefined;
|
|
18562
18860
|
let inferredObservability = false;
|
|
18563
18861
|
let observedAttributes = [];
|
|
18564
|
-
let tree = Parser$2.extend(acornJsx()).parse(moduleContents, {
|
|
18862
|
+
let tree = Parser$2.extend(acornJsx(), importAttributes).parse(moduleContents, {
|
|
18565
18863
|
ecmaVersion: 'latest',
|
|
18566
18864
|
sourceType: 'module'
|
|
18567
18865
|
});
|
|
@@ -18750,12 +19048,12 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
|
|
|
18750
19048
|
const moduleContents = fs.readFileSync(moduleURL, 'utf-8');
|
|
18751
19049
|
const nextDepth = depth += 1;
|
|
18752
19050
|
const customParser = getParser(moduleURL);
|
|
18753
|
-
const parser = customParser ? customParser.parser :
|
|
19051
|
+
const parser = customParser ? customParser.parser : Parser$2;
|
|
18754
19052
|
const config = customParser ? customParser.config : {
|
|
18755
19053
|
...base$1
|
|
18756
19054
|
};
|
|
18757
19055
|
|
|
18758
|
-
simple(parser.parse(moduleContents, {
|
|
19056
|
+
simple(parser.extend(importAttributes).parse(moduleContents, {
|
|
18759
19057
|
ecmaVersion: 'latest',
|
|
18760
19058
|
sourceType: 'module'
|
|
18761
19059
|
}), {
|
|
@@ -18795,13 +19093,13 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
|
|
|
18795
19093
|
async function getTagName(moduleURL) {
|
|
18796
19094
|
const moduleContents = await fs.promises.readFile(moduleURL, 'utf-8');
|
|
18797
19095
|
const customParser = getParser(moduleURL);
|
|
18798
|
-
const parser = customParser ? customParser.parser :
|
|
19096
|
+
const parser = customParser ? customParser.parser : Parser$2;
|
|
18799
19097
|
const config = customParser ? customParser.config : {
|
|
18800
19098
|
...base$1
|
|
18801
19099
|
};
|
|
18802
19100
|
let tagName;
|
|
18803
19101
|
|
|
18804
|
-
simple(parser.parse(moduleContents, {
|
|
19102
|
+
simple(parser.extend(importAttributes).parse(moduleContents, {
|
|
18805
19103
|
ecmaVersion: 'latest',
|
|
18806
19104
|
sourceType: 'module'
|
|
18807
19105
|
}), {
|
|
@@ -18822,9 +19120,10 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
18822
19120
|
}
|
|
18823
19121
|
|
|
18824
19122
|
// https://github.com/ProjectEvergreen/wcc/pull/67/files#r902061804
|
|
18825
|
-
|
|
18826
|
-
const
|
|
18827
|
-
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;
|
|
18828
19127
|
const data = props
|
|
18829
19128
|
? props
|
|
18830
19129
|
: dataLoader
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wc-compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Experimental native Web Components compiler.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"clean": "rimraf ./dist",
|
|
31
|
-
"lint": "
|
|
31
|
+
"lint": "eslint --ignore-pattern \"*.json\" \"*.*js\" \"./src/**/**/*.js*\" \"./sandbox/**/**/*.js*\" \"./docs/**/*.md\" \"./test/**/**/*.js*\"",
|
|
32
32
|
"docs:dev": "concurrently \"nodemon --watch src --watch docs -e js,md,css,html,jsx ./build.js\" \"http-server ./dist --open\"",
|
|
33
33
|
"docs:build": "node ./build.js",
|
|
34
34
|
"docs:serve": "npm run clean && npm run docs:build && http-server ./dist --open",
|
|
35
|
-
"sandbox": "npm run clean && concurrently \"nodemon --
|
|
35
|
+
"sandbox": "npm run clean && concurrently \"nodemon --loader ./test-exp-loader.js --watch src --watch sandbox -e js,md,css,html,jsx ./sandbox.js\" \"http-server ./dist --open\" \"livereload ./dist\"",
|
|
36
36
|
"start": "npm run docs:serve",
|
|
37
37
|
"test": "mocha --exclude \"./test/cases/jsx*/**\" --exclude \"./test/cases/custom-extension/**\" \"./test/**/**/*.spec.js\"",
|
|
38
|
-
"test:exp": "c8 node --
|
|
38
|
+
"test:exp": "c8 node --loader ./test-exp-loader.js ./node_modules/mocha/bin/mocha \"./test/**/**/*.spec.js\"",
|
|
39
39
|
"test:tdd": "npm run test -- --watch",
|
|
40
40
|
"test:tdd:exp": "npm run test:exp -- --watch",
|
|
41
41
|
"dist": "rollup -c rollup.config.js",
|
|
@@ -45,10 +45,15 @@
|
|
|
45
45
|
"@projectevergreen/acorn-jsx-esm": "~0.1.0",
|
|
46
46
|
"@projectevergreen/escodegen-esm": "~0.1.0",
|
|
47
47
|
"acorn": "^8.7.0",
|
|
48
|
+
"acorn-import-attributes": "^1.9.5",
|
|
48
49
|
"acorn-walk": "^8.2.0",
|
|
49
50
|
"parse5": "^6.0.1"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
53
|
+
"@babel/core": "^7.24.4",
|
|
54
|
+
"@babel/eslint-parser": "^7.24.1",
|
|
55
|
+
"@babel/plugin-syntax-import-assertions": "^7.24.1",
|
|
56
|
+
"@babel/preset-react": "^7.24.1",
|
|
52
57
|
"@ls-lint/ls-lint": "^1.10.0",
|
|
53
58
|
"@mapbox/rehype-prism": "^0.8.0",
|
|
54
59
|
"@rollup/plugin-commonjs": "^25.0.7",
|
package/src/dom-shim.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
function noop() { }
|
|
2
2
|
|
|
3
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet
|
|
4
|
+
class CSSStyleSheet {
|
|
5
|
+
insertRule() { }
|
|
6
|
+
deleteRule() { }
|
|
7
|
+
replace() { }
|
|
8
|
+
replaceSync() { }
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
|
|
4
12
|
class EventTarget {
|
|
5
13
|
constructor() {
|
|
@@ -93,6 +101,7 @@ class ShadowRoot extends DocumentFragment {
|
|
|
93
101
|
constructor(options) {
|
|
94
102
|
super();
|
|
95
103
|
this.mode = options.mode || 'closed';
|
|
104
|
+
this.adoptedStyleSheets = [];
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
107
|
|
|
@@ -146,4 +155,5 @@ class CustomElementsRegistry {
|
|
|
146
155
|
globalThis.addEventListener = globalThis.addEventListener ?? noop;
|
|
147
156
|
globalThis.document = globalThis.document ?? new Document();
|
|
148
157
|
globalThis.customElements = globalThis.customElements ?? new CustomElementsRegistry();
|
|
149
|
-
globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement;
|
|
158
|
+
globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement;
|
|
159
|
+
globalThis.CSSStyleSheet = globalThis.CSSStyleSheet ?? CSSStyleSheet;
|
package/src/jsx-loader.js
CHANGED
|
@@ -6,6 +6,8 @@ import { generate } from '@projectevergreen/escodegen-esm';
|
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import jsx from '@projectevergreen/acorn-jsx-esm';
|
|
8
8
|
import { parse, parseFragment, serialize } from 'parse5';
|
|
9
|
+
// Need an acorn plugin for now - https://github.com/ProjectEvergreen/greenwood/issues/1218
|
|
10
|
+
import { importAttributes } from 'acorn-import-attributes';
|
|
9
11
|
|
|
10
12
|
const jsxRegex = /\.(jsx)$/;
|
|
11
13
|
|
|
@@ -29,7 +31,7 @@ export function getParser(moduleURL) {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
return {
|
|
32
|
-
parser: acorn.Parser.extend(jsx()),
|
|
34
|
+
parser: acorn.Parser.extend(jsx(), importAttributes),
|
|
33
35
|
config: {
|
|
34
36
|
// https://github.com/acornjs/acorn/issues/829#issuecomment-1172586171
|
|
35
37
|
...walk.base,
|
|
@@ -236,7 +238,7 @@ export function parseJsx(moduleURL) {
|
|
|
236
238
|
const hasOwnObservedAttributes = undefined;
|
|
237
239
|
let inferredObservability = false;
|
|
238
240
|
let observedAttributes = [];
|
|
239
|
-
let tree = acorn.Parser.extend(jsx()).parse(moduleContents, {
|
|
241
|
+
let tree = acorn.Parser.extend(jsx(), importAttributes).parse(moduleContents, {
|
|
240
242
|
ecmaVersion: 'latest',
|
|
241
243
|
sourceType: 'module'
|
|
242
244
|
});
|
package/src/wcc.js
CHANGED
|
@@ -7,6 +7,8 @@ import * as walk from 'acorn-walk';
|
|
|
7
7
|
import { generate } from '@projectevergreen/escodegen-esm';
|
|
8
8
|
import { getParser, parseJsx } from './jsx-loader.js';
|
|
9
9
|
import { parse, parseFragment, serialize } from 'parse5';
|
|
10
|
+
// Need an acorn plugin for now - https://github.com/ProjectEvergreen/greenwood/issues/1218
|
|
11
|
+
import { importAttributes } from 'acorn-import-attributes';
|
|
10
12
|
import fs from 'fs';
|
|
11
13
|
|
|
12
14
|
function getParse(html) {
|
|
@@ -61,12 +63,12 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
|
|
|
61
63
|
const moduleContents = fs.readFileSync(moduleURL, 'utf-8');
|
|
62
64
|
const nextDepth = depth += 1;
|
|
63
65
|
const customParser = getParser(moduleURL);
|
|
64
|
-
const parser = customParser ? customParser.parser : acorn;
|
|
66
|
+
const parser = customParser ? customParser.parser : acorn.Parser;
|
|
65
67
|
const config = customParser ? customParser.config : {
|
|
66
68
|
...walk.base
|
|
67
69
|
};
|
|
68
70
|
|
|
69
|
-
walk.simple(parser.parse(moduleContents, {
|
|
71
|
+
walk.simple(parser.extend(importAttributes).parse(moduleContents, {
|
|
70
72
|
ecmaVersion: 'latest',
|
|
71
73
|
sourceType: 'module'
|
|
72
74
|
}), {
|
|
@@ -106,13 +108,13 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
|
|
|
106
108
|
async function getTagName(moduleURL) {
|
|
107
109
|
const moduleContents = await fs.promises.readFile(moduleURL, 'utf-8');
|
|
108
110
|
const customParser = getParser(moduleURL);
|
|
109
|
-
const parser = customParser ? customParser.parser : acorn;
|
|
111
|
+
const parser = customParser ? customParser.parser : acorn.Parser;
|
|
110
112
|
const config = customParser ? customParser.config : {
|
|
111
113
|
...walk.base
|
|
112
114
|
};
|
|
113
115
|
let tagName;
|
|
114
116
|
|
|
115
|
-
walk.simple(parser.parse(moduleContents, {
|
|
117
|
+
walk.simple(parser.extend(importAttributes).parse(moduleContents, {
|
|
116
118
|
ecmaVersion: 'latest',
|
|
117
119
|
sourceType: 'module'
|
|
118
120
|
}), {
|
|
@@ -133,9 +135,10 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
// https://github.com/ProjectEvergreen/wcc/pull/67/files#r902061804
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
const
|
|
138
|
+
// https://github.com/ProjectEvergreen/wcc/pull/159
|
|
139
|
+
const { href } = elementURL;
|
|
140
|
+
const element = customElements.get(tagName) ?? (await import(href)).default;
|
|
141
|
+
const dataLoader = (await import(href)).getData;
|
|
139
142
|
const data = props
|
|
140
143
|
? props
|
|
141
144
|
: dataLoader
|