@lwc/template-compiler 2.5.10 → 2.6.3
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/commonjs/codegen/optimize.js +115 -0
- package/dist/commonjs/codegen/optimize.js.map +1 -0
- package/dist/commonjs/parser/expression.js +7 -2
- package/dist/commonjs/parser/expression.js.map +1 -1
- package/dist/commonjs/parser/utils/javascript.js +25 -0
- package/dist/commonjs/parser/utils/javascript.js.map +1 -0
- package/dist/commonjs/shared/ast.js +303 -0
- package/dist/commonjs/shared/ast.js.map +1 -0
- package/dist/types/codegen/optimize.d.ts +33 -0
- package/dist/types/parser/utils/javascript.d.ts +1 -0
- package/dist/types/shared/ast.d.ts +45 -0
- package/package.json +6 -7
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.optimizeStaticExpressions = void 0;
|
|
23
|
+
/*
|
|
24
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
25
|
+
* All rights reserved.
|
|
26
|
+
* SPDX-License-Identifier: MIT
|
|
27
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
28
|
+
*/
|
|
29
|
+
const astring = __importStar(require("astring"));
|
|
30
|
+
const estree_walker_1 = require("estree-walker");
|
|
31
|
+
const t = __importStar(require("../shared/estree"));
|
|
32
|
+
/**
|
|
33
|
+
* Given a template function, extract all static objects/arrays (e.g. `{ key : 1 }`)
|
|
34
|
+
* and return them as a list of `const` declarations. Also return the modified function
|
|
35
|
+
* that is now referencing those declarations.
|
|
36
|
+
*
|
|
37
|
+
* Example input:
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
* function tmpl() {
|
|
41
|
+
* return {
|
|
42
|
+
* foo: dynamic(),
|
|
43
|
+
* bar: { static: true },
|
|
44
|
+
* baz: { really: { static: ['yep', 'totally', 'static' ] } }
|
|
45
|
+
* };
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Example output:
|
|
50
|
+
*
|
|
51
|
+
* ```
|
|
52
|
+
* const stc0 = { static: true };
|
|
53
|
+
* const stc1 = { really: { static: ['yep', 'totally', 'static' ] } };
|
|
54
|
+
* function tmpl() {
|
|
55
|
+
* return {
|
|
56
|
+
* foo: dynamic(),
|
|
57
|
+
* bar: stc0,
|
|
58
|
+
* baz: stc1
|
|
59
|
+
* };
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function optimizeStaticExpressions(templateFn) {
|
|
64
|
+
const result = [];
|
|
65
|
+
const keysToVariableNames = new Map();
|
|
66
|
+
// Return true if this node is an object/array that is fully static
|
|
67
|
+
function isStaticObjectOrArray(node) {
|
|
68
|
+
if (t.isObjectExpression(node)) {
|
|
69
|
+
return node.properties.every((prop) => {
|
|
70
|
+
return (t.isProperty(prop) &&
|
|
71
|
+
!prop.computed &&
|
|
72
|
+
!prop.method &&
|
|
73
|
+
!prop.shorthand &&
|
|
74
|
+
(t.isLiteral(prop.value) || isStaticObjectOrArray(prop.value)));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (t.isArrayExpression(node)) {
|
|
78
|
+
return node.elements.every((element) => {
|
|
79
|
+
return element !== null && (t.isLiteral(element) || isStaticObjectOrArray(element));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
function extractStaticVariable(node) {
|
|
85
|
+
// This key generation can probably be improved using a hash code, but stringification is
|
|
86
|
+
// simplest for finding a unique identifier for an object/array expression
|
|
87
|
+
const key = astring.generate(node);
|
|
88
|
+
// Check for duplicates to avoid re-declaring the same object/array multiple times
|
|
89
|
+
// Especially for the empty array (`[]`), which is very common in templates
|
|
90
|
+
if (!keysToVariableNames.has(key)) {
|
|
91
|
+
const variableName = `stc${keysToVariableNames.size}`;
|
|
92
|
+
// e.g. `const stc0 = { /* original object */ };
|
|
93
|
+
const declaration = t.variableDeclaration('const', [
|
|
94
|
+
t.variableDeclarator(t.identifier(variableName), node),
|
|
95
|
+
]);
|
|
96
|
+
result.push(declaration);
|
|
97
|
+
keysToVariableNames.set(key, variableName);
|
|
98
|
+
}
|
|
99
|
+
return t.identifier(keysToVariableNames.get(key));
|
|
100
|
+
}
|
|
101
|
+
(0, estree_walker_1.walk)(templateFn, {
|
|
102
|
+
enter(node) {
|
|
103
|
+
// For deeply-nested static object, we only want to extract the top-level node
|
|
104
|
+
if (isStaticObjectOrArray(node)) {
|
|
105
|
+
const newNode = extractStaticVariable(node);
|
|
106
|
+
this.replace(newNode);
|
|
107
|
+
this.skip();
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
result.push(templateFn);
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
exports.optimizeStaticExpressions = optimizeStaticExpressions;
|
|
115
|
+
//# sourceMappingURL=optimize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimize.js","sourceRoot":"","sources":["../../../src/codegen/optimize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,iDAAmC;AACnC,iDAAqC;AACrC,oDAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,yBAAyB,CACrC,UAAiC;IAEjC,MAAM,MAAM,GAAyD,EAAE,CAAC;IACxE,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAE,CAAC;IAEtC,mEAAmE;IACnE,SAAS,qBAAqB,CAC1B,IAAgB;QAEhB,IAAI,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE;YAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;gBAClC,OAAO,CACH,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;oBAClB,CAAC,IAAI,CAAC,QAAQ;oBACd,CAAC,IAAI,CAAC,MAAM;oBACZ,CAAC,IAAI,CAAC,SAAS;oBACf,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CACjE,CAAC;YACN,CAAC,CAAC,CAAC;SACN;aAAM,IAAI,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;YAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE;gBACnC,OAAO,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;YACxF,CAAC,CAAC,CAAC;SACN;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,SAAS,qBAAqB,CAAC,IAAkB;QAC7C,yFAAyF;QACzF,0EAA0E;QAC1E,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEnC,kFAAkF;QAClF,2EAA2E;QAC3E,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAC/B,MAAM,YAAY,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,CAAC;YACtD,gDAAgD;YAChD,MAAM,WAAW,GAAG,CAAC,CAAC,mBAAmB,CAAC,OAAO,EAAE;gBAC/C,CAAC,CAAC,kBAAkB,CAChB,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,EAC1B,IAA8C,CACjD;aACJ,CAAC,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACzB,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;SAC9C;QAED,OAAO,CAAC,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,IAAA,oBAAI,EAAC,UAAU,EAAE;QACb,KAAK,CAAC,IAAI;YACN,8EAA8E;YAC9E,IAAI,qBAAqB,CAAC,IAAI,CAAC,EAAE;gBAC7B,MAAM,OAAO,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;gBAC5C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBACtB,IAAI,CAAC,IAAI,EAAE,CAAC;aACf;QACL,CAAC;KACJ,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAExB,OAAO,MAAM,CAAC;AAClB,CAAC;AAjED,8DAiEC"}
|
|
@@ -26,10 +26,10 @@ exports.parseIdentifier = exports.parseExpression = exports.isPotentialExpressio
|
|
|
26
26
|
* SPDX-License-Identifier: MIT
|
|
27
27
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
28
28
|
*/
|
|
29
|
-
const esutils = __importStar(require("esutils"));
|
|
30
29
|
const acorn_1 = require("acorn");
|
|
31
30
|
const errors_1 = require("@lwc/errors");
|
|
32
31
|
const t = __importStar(require("../shared/estree"));
|
|
32
|
+
const javascript_1 = require("./utils/javascript");
|
|
33
33
|
exports.EXPRESSION_SYMBOL_START = '{';
|
|
34
34
|
exports.EXPRESSION_SYMBOL_END = '}';
|
|
35
35
|
const VALID_EXPRESSION_RE = /^{.+}$/;
|
|
@@ -97,7 +97,12 @@ function parseExpression(ctx, source, location) {
|
|
|
97
97
|
}
|
|
98
98
|
exports.parseExpression = parseExpression;
|
|
99
99
|
function parseIdentifier(ctx, source, location) {
|
|
100
|
-
|
|
100
|
+
let isValid = true;
|
|
101
|
+
isValid = (0, acorn_1.isIdentifierStart)(source.charCodeAt(0));
|
|
102
|
+
for (let i = 1; i < source.length && isValid; i++) {
|
|
103
|
+
isValid = (0, acorn_1.isIdentifierChar)(source.charCodeAt(i));
|
|
104
|
+
}
|
|
105
|
+
if (isValid && !(0, javascript_1.isReservedES6Keyword)(source)) {
|
|
101
106
|
return t.identifier(source);
|
|
102
107
|
}
|
|
103
108
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../src/parser/expression.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../src/parser/expression.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,iCAAqF;AAErF,wCAA2D;AAE3D,oDAAsC;AAItC,mDAA0D;AAI7C,QAAA,uBAAuB,GAAG,GAAG,CAAC;AAC9B,QAAA,qBAAqB,GAAG,GAAG,CAAC;AAEzC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AACrC,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAC7C,MAAM,cAAc,GAAG,IA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AAO,MAAM,CAAC;IAClB,CAAC,EACD,0BAAiB,CAAC,iCAAiC,EACnD,QAAQ,EACR,CAAC,GAAG,EAAE,EAAE,CAAC,sBAAsB,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,CAC3D,CAAC;AACN,CAAC;AAlBD,0CAkBC;AAED,SAAgB,eAAe,CAC3B,GAAc,EACd,MAAc,EACd,QAAkB;IAElB,IAAI,OAAO,GAAG,IAAI,CAAC;IAEnB,OAAO,GAAG,IAAA,yBAAiB,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,EAAE,CAAC,EAAE,EAAE;QAC/C,OAAO,GAAG,IAAA,wBAAgB,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;KACpD;IAED,IAAI,OAAO,IAAI,CAAC,IAAA,iCAAoB,EAAC,MAAM,CAAC,EAAE;QAC1C,OAAO,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KAC/B;SAAM;QACH,GAAG,CAAC,eAAe,CAAC,0BAAiB,CAAC,kBAAkB,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;KACjF;AACL,CAAC;AAjBD,0CAiBC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isReservedES6Keyword = void 0;
|
|
10
|
+
// https://262.ecma-international.org/12.0/#sec-keywords-and-reserved-words
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
const REVERSED_KEYWORDS = new Set([
|
|
13
|
+
// Reserved keywords
|
|
14
|
+
'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete',
|
|
15
|
+
'do', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'import',
|
|
16
|
+
'in', 'instanceof', 'new', 'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try',
|
|
17
|
+
'typeof', 'var', 'void', 'while', 'with', 'yield',
|
|
18
|
+
// Strict mode only reserved keywords
|
|
19
|
+
'let', 'static', 'implements', 'interface', 'package', 'private', 'protected', 'public'
|
|
20
|
+
]);
|
|
21
|
+
function isReservedES6Keyword(str) {
|
|
22
|
+
return REVERSED_KEYWORDS.has(str);
|
|
23
|
+
}
|
|
24
|
+
exports.isReservedES6Keyword = isReservedES6Keyword;
|
|
25
|
+
//# sourceMappingURL=javascript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../../../src/parser/utils/javascript.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2EAA2E;AAC3E,kBAAkB;AAClB,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAC9B,oBAAoB;IACpB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ;IAChG,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ;IAChG,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK;IAC9F,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO;IAEjD,qCAAqC;IACrC,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ;CAC1F,CAAC,CAAC;AAEH,SAAgB,oBAAoB,CAAC,GAAW;IAC5C,OAAO,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAFD,oDAEC"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isProperty = exports.isPreserveCommentsDirective = exports.isRenderModeDirective = exports.isKeyDirective = exports.isInnerHTMLDirective = exports.isDomDirective = exports.isDynamicDirective = exports.isParentNode = exports.isIf = exports.isForBlock = exports.isForEach = exports.isForOf = exports.isBooleanLiteral = exports.isStringLiteral = exports.isExpression = exports.isComment = exports.isText = exports.isBaseElement = exports.isSlot = exports.isComponent = exports.isRoot = exports.isElement = exports.property = exports.attribute = exports.renderModeDirective = exports.preserveCommentsDirective = exports.innerHTMLDirective = exports.domDirective = exports.dynamicDirective = exports.keyDirective = exports.eventListener = exports.ifNode = exports.forOf = exports.forEach = exports.literal = exports.sourceLocation = exports.elementSourceLocation = exports.comment = exports.text = exports.slot = exports.component = exports.element = exports.root = void 0;
|
|
4
|
+
function root(parse5ElmLocation) {
|
|
5
|
+
return {
|
|
6
|
+
type: 'Root',
|
|
7
|
+
location: elementSourceLocation(parse5ElmLocation),
|
|
8
|
+
directives: [],
|
|
9
|
+
children: [],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.root = root;
|
|
13
|
+
function element(parse5Elm, parse5ElmLocation) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'Element',
|
|
16
|
+
name: parse5Elm.nodeName,
|
|
17
|
+
namespace: parse5Elm.namespaceURI,
|
|
18
|
+
location: elementSourceLocation(parse5ElmLocation),
|
|
19
|
+
attributes: [],
|
|
20
|
+
properties: [],
|
|
21
|
+
directives: [],
|
|
22
|
+
listeners: [],
|
|
23
|
+
children: [],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.element = element;
|
|
27
|
+
function component(parse5Elm, parse5ElmLocation) {
|
|
28
|
+
return {
|
|
29
|
+
type: 'Component',
|
|
30
|
+
name: parse5Elm.nodeName,
|
|
31
|
+
location: elementSourceLocation(parse5ElmLocation),
|
|
32
|
+
attributes: [],
|
|
33
|
+
properties: [],
|
|
34
|
+
directives: [],
|
|
35
|
+
listeners: [],
|
|
36
|
+
children: [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.component = component;
|
|
40
|
+
function slot(slotName, parse5ElmLocation) {
|
|
41
|
+
return {
|
|
42
|
+
type: 'Slot',
|
|
43
|
+
name: 'slot',
|
|
44
|
+
slotName,
|
|
45
|
+
location: elementSourceLocation(parse5ElmLocation),
|
|
46
|
+
attributes: [],
|
|
47
|
+
properties: [],
|
|
48
|
+
directives: [],
|
|
49
|
+
listeners: [],
|
|
50
|
+
children: [],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.slot = slot;
|
|
54
|
+
function text(value, parse5Location) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'Text',
|
|
57
|
+
value,
|
|
58
|
+
location: sourceLocation(parse5Location),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.text = text;
|
|
62
|
+
function comment(value, parse5Location) {
|
|
63
|
+
return {
|
|
64
|
+
type: 'Comment',
|
|
65
|
+
value,
|
|
66
|
+
location: sourceLocation(parse5Location),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.comment = comment;
|
|
70
|
+
function elementSourceLocation(parse5ElmLocation) {
|
|
71
|
+
const elementLocation = sourceLocation(parse5ElmLocation);
|
|
72
|
+
const startTag = sourceLocation(parse5ElmLocation.startTag);
|
|
73
|
+
// endTag must be optional because Parse5 currently fails to collect end tag location for element with a tag name
|
|
74
|
+
// containing an upper case character (inikulin/parse5#352).
|
|
75
|
+
const endTag = parse5ElmLocation.endTag
|
|
76
|
+
? sourceLocation(parse5ElmLocation.endTag)
|
|
77
|
+
: parse5ElmLocation.endTag;
|
|
78
|
+
return { ...elementLocation, startTag, endTag };
|
|
79
|
+
}
|
|
80
|
+
exports.elementSourceLocation = elementSourceLocation;
|
|
81
|
+
function sourceLocation(location) {
|
|
82
|
+
return {
|
|
83
|
+
startLine: location.startLine,
|
|
84
|
+
startColumn: location.startCol,
|
|
85
|
+
endLine: location.endLine,
|
|
86
|
+
endColumn: location.endCol,
|
|
87
|
+
start: location.startOffset,
|
|
88
|
+
end: location.endOffset,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.sourceLocation = sourceLocation;
|
|
92
|
+
function literal(value) {
|
|
93
|
+
return {
|
|
94
|
+
type: 'Literal',
|
|
95
|
+
value,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
exports.literal = literal;
|
|
99
|
+
function forEach(expression, elementLocation, directiveLocation, item, index) {
|
|
100
|
+
return {
|
|
101
|
+
type: 'ForEach',
|
|
102
|
+
expression,
|
|
103
|
+
item,
|
|
104
|
+
index,
|
|
105
|
+
location: elementLocation,
|
|
106
|
+
directiveLocation,
|
|
107
|
+
children: [],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.forEach = forEach;
|
|
111
|
+
function forOf(expression, iterator, elementLocation, directiveLocation) {
|
|
112
|
+
return {
|
|
113
|
+
type: 'ForOf',
|
|
114
|
+
expression,
|
|
115
|
+
iterator,
|
|
116
|
+
location: elementLocation,
|
|
117
|
+
directiveLocation,
|
|
118
|
+
children: [],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.forOf = forOf;
|
|
122
|
+
function ifNode(modifier, condition, elementLocation, directiveLocation) {
|
|
123
|
+
return {
|
|
124
|
+
type: 'If',
|
|
125
|
+
modifier,
|
|
126
|
+
condition,
|
|
127
|
+
location: elementLocation,
|
|
128
|
+
directiveLocation,
|
|
129
|
+
children: [],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.ifNode = ifNode;
|
|
133
|
+
function eventListener(name, handler, location) {
|
|
134
|
+
return {
|
|
135
|
+
type: 'EventListener',
|
|
136
|
+
name,
|
|
137
|
+
handler,
|
|
138
|
+
location,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
exports.eventListener = eventListener;
|
|
142
|
+
function keyDirective(value, location) {
|
|
143
|
+
return {
|
|
144
|
+
type: 'Directive',
|
|
145
|
+
name: 'Key',
|
|
146
|
+
value,
|
|
147
|
+
location,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
exports.keyDirective = keyDirective;
|
|
151
|
+
function dynamicDirective(value, location) {
|
|
152
|
+
return {
|
|
153
|
+
type: 'Directive',
|
|
154
|
+
name: 'Dynamic',
|
|
155
|
+
value,
|
|
156
|
+
location,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
exports.dynamicDirective = dynamicDirective;
|
|
160
|
+
function domDirective(lwcDomAttr, location) {
|
|
161
|
+
return {
|
|
162
|
+
type: 'Directive',
|
|
163
|
+
name: 'Dom',
|
|
164
|
+
value: literal(lwcDomAttr),
|
|
165
|
+
location,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
exports.domDirective = domDirective;
|
|
169
|
+
function innerHTMLDirective(value, location) {
|
|
170
|
+
return {
|
|
171
|
+
type: 'Directive',
|
|
172
|
+
name: 'InnerHTML',
|
|
173
|
+
value,
|
|
174
|
+
location,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
exports.innerHTMLDirective = innerHTMLDirective;
|
|
178
|
+
function preserveCommentsDirective(preserveComments, location) {
|
|
179
|
+
return {
|
|
180
|
+
type: 'Directive',
|
|
181
|
+
name: 'PreserveComments',
|
|
182
|
+
value: literal(preserveComments),
|
|
183
|
+
location,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
exports.preserveCommentsDirective = preserveCommentsDirective;
|
|
187
|
+
function renderModeDirective(renderMode, location) {
|
|
188
|
+
return {
|
|
189
|
+
type: 'Directive',
|
|
190
|
+
name: 'RenderMode',
|
|
191
|
+
value: literal(renderMode),
|
|
192
|
+
location,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
exports.renderModeDirective = renderModeDirective;
|
|
196
|
+
function attribute(name, value, location) {
|
|
197
|
+
return {
|
|
198
|
+
type: 'Attribute',
|
|
199
|
+
name,
|
|
200
|
+
value,
|
|
201
|
+
location,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
exports.attribute = attribute;
|
|
205
|
+
function property(name, attributeName, value, location) {
|
|
206
|
+
return {
|
|
207
|
+
type: 'Property',
|
|
208
|
+
name,
|
|
209
|
+
attributeName,
|
|
210
|
+
value,
|
|
211
|
+
location,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
exports.property = property;
|
|
215
|
+
function isElement(node) {
|
|
216
|
+
return node.type === 'Element';
|
|
217
|
+
}
|
|
218
|
+
exports.isElement = isElement;
|
|
219
|
+
function isRoot(node) {
|
|
220
|
+
return node.type === 'Root';
|
|
221
|
+
}
|
|
222
|
+
exports.isRoot = isRoot;
|
|
223
|
+
function isComponent(node) {
|
|
224
|
+
return node.type === 'Component';
|
|
225
|
+
}
|
|
226
|
+
exports.isComponent = isComponent;
|
|
227
|
+
function isSlot(node) {
|
|
228
|
+
return node.type === 'Slot';
|
|
229
|
+
}
|
|
230
|
+
exports.isSlot = isSlot;
|
|
231
|
+
function isBaseElement(node) {
|
|
232
|
+
return isElement(node) || isComponent(node) || isSlot(node);
|
|
233
|
+
}
|
|
234
|
+
exports.isBaseElement = isBaseElement;
|
|
235
|
+
function isText(node) {
|
|
236
|
+
return node.type === 'Text';
|
|
237
|
+
}
|
|
238
|
+
exports.isText = isText;
|
|
239
|
+
function isComment(node) {
|
|
240
|
+
return node.type === 'Comment';
|
|
241
|
+
}
|
|
242
|
+
exports.isComment = isComment;
|
|
243
|
+
function isExpression(node) {
|
|
244
|
+
return node.type === 'Identifier' || node.type === 'MemberExpression';
|
|
245
|
+
}
|
|
246
|
+
exports.isExpression = isExpression;
|
|
247
|
+
function isStringLiteral(node) {
|
|
248
|
+
return node.type === 'Literal' && typeof node.value === 'string';
|
|
249
|
+
}
|
|
250
|
+
exports.isStringLiteral = isStringLiteral;
|
|
251
|
+
function isBooleanLiteral(node) {
|
|
252
|
+
return node.type === 'Literal' && typeof node.value === 'boolean';
|
|
253
|
+
}
|
|
254
|
+
exports.isBooleanLiteral = isBooleanLiteral;
|
|
255
|
+
function isForOf(node) {
|
|
256
|
+
return node.type === 'ForOf';
|
|
257
|
+
}
|
|
258
|
+
exports.isForOf = isForOf;
|
|
259
|
+
function isForEach(node) {
|
|
260
|
+
return node.type === 'ForEach';
|
|
261
|
+
}
|
|
262
|
+
exports.isForEach = isForEach;
|
|
263
|
+
function isForBlock(node) {
|
|
264
|
+
return isForOf(node) || isForEach(node);
|
|
265
|
+
}
|
|
266
|
+
exports.isForBlock = isForBlock;
|
|
267
|
+
function isIf(node) {
|
|
268
|
+
return node.type === 'If';
|
|
269
|
+
}
|
|
270
|
+
exports.isIf = isIf;
|
|
271
|
+
function isParentNode(node) {
|
|
272
|
+
return isBaseElement(node) || isRoot(node) || isForBlock(node) || isIf(node);
|
|
273
|
+
}
|
|
274
|
+
exports.isParentNode = isParentNode;
|
|
275
|
+
function isDynamicDirective(directive) {
|
|
276
|
+
return directive.name === 'Dynamic';
|
|
277
|
+
}
|
|
278
|
+
exports.isDynamicDirective = isDynamicDirective;
|
|
279
|
+
function isDomDirective(directive) {
|
|
280
|
+
return directive.name === 'Dom';
|
|
281
|
+
}
|
|
282
|
+
exports.isDomDirective = isDomDirective;
|
|
283
|
+
function isInnerHTMLDirective(directive) {
|
|
284
|
+
return directive.name === 'InnerHTML';
|
|
285
|
+
}
|
|
286
|
+
exports.isInnerHTMLDirective = isInnerHTMLDirective;
|
|
287
|
+
function isKeyDirective(directive) {
|
|
288
|
+
return directive.name === 'Key';
|
|
289
|
+
}
|
|
290
|
+
exports.isKeyDirective = isKeyDirective;
|
|
291
|
+
function isRenderModeDirective(directive) {
|
|
292
|
+
return directive.name === 'RenderMode';
|
|
293
|
+
}
|
|
294
|
+
exports.isRenderModeDirective = isRenderModeDirective;
|
|
295
|
+
function isPreserveCommentsDirective(directive) {
|
|
296
|
+
return directive.name === 'PreserveComments';
|
|
297
|
+
}
|
|
298
|
+
exports.isPreserveCommentsDirective = isPreserveCommentsDirective;
|
|
299
|
+
function isProperty(node) {
|
|
300
|
+
return node.type === 'Property';
|
|
301
|
+
}
|
|
302
|
+
exports.isProperty = isProperty;
|
|
303
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/shared/ast.ts"],"names":[],"mappings":";;;AAyCA,SAAgB,IAAI,CAAC,iBAAyC;IAC1D,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,qBAAqB,CAAC,iBAAiB,CAAC;QAClD,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,EAAE;KACf,CAAC;AACN,CAAC;AAPD,oBAOC;AAED,SAAgB,OAAO,CACnB,SAAyB,EACzB,iBAAyC;IAEzC,OAAO;QACH,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,SAAS,CAAC,QAAQ;QACxB,SAAS,EAAE,SAAS,CAAC,YAAY;QACjC,QAAQ,EAAE,qBAAqB,CAAC,iBAAiB,CAAC;QAClD,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,EAAE;QACd,SAAS,EAAE,EAAE;QACb,QAAQ,EAAE,EAAE;KACf,CAAC;AACN,CAAC;AAfD,0BAeC;AAED,SAAgB,SAAS,CACrB,SAAyB,EACzB,iBAAyC;IAEzC,OAAO;QACH,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,SAAS,CAAC,QAAQ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AAK,WAAW,CAAC;AAC1C,CAAC;AAFD,oDAEC;AAED,SAAgB,cAAc,CAAC,SAAoB;IAC/C,OAAO,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC;AACpC,CAAC;AAFD,wCAEC;AAED,SAAgB,qBAAqB,CAAC,SAAoB;IACtD,OAAO,SAAS,CAAC,IAAI,KAAK,YAAY,CAAC;AAC3C,CAAC;AAFD,sDAEC;AAED,SAAgB,2BAA2B,CACvC,SAAoB;IAEpB,OAAO,SAAS,CAAC,IAAI,KAAK,kBAAkB,CAAC;AACjD,CAAC;AAJD,kEAIC;AAED,SAAgB,UAAU,CAAC,IAAc;IACrC,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC;AACpC,CAAC;AAFD,gCAEC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as t from '../shared/estree';
|
|
2
|
+
/**
|
|
3
|
+
* Given a template function, extract all static objects/arrays (e.g. `{ key : 1 }`)
|
|
4
|
+
* and return them as a list of `const` declarations. Also return the modified function
|
|
5
|
+
* that is now referencing those declarations.
|
|
6
|
+
*
|
|
7
|
+
* Example input:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* function tmpl() {
|
|
11
|
+
* return {
|
|
12
|
+
* foo: dynamic(),
|
|
13
|
+
* bar: { static: true },
|
|
14
|
+
* baz: { really: { static: ['yep', 'totally', 'static' ] } }
|
|
15
|
+
* };
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Example output:
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
* const stc0 = { static: true };
|
|
23
|
+
* const stc1 = { really: { static: ['yep', 'totally', 'static' ] } };
|
|
24
|
+
* function tmpl() {
|
|
25
|
+
* return {
|
|
26
|
+
* foo: dynamic(),
|
|
27
|
+
* bar: stc0,
|
|
28
|
+
* baz: stc1
|
|
29
|
+
* };
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function optimizeStaticExpressions(templateFn: t.FunctionDeclaration): Array<t.FunctionDeclaration | t.VariableDeclaration>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isReservedES6Keyword(str: string): boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as parse5 from 'parse5';
|
|
2
|
+
import { Literal, SourceLocation, Element, Component, Expression, Comment, Text, ForEach, ForBlock, Slot, Identifier, Root, EventListener, KeyDirective, DynamicDirective, DomDirective, PreserveCommentsDirective, RenderModeDirective, Attribute, Property, ParentNode, BaseNode, ForOf, LWCDirectiveRenderMode, If, ElementSourceLocation, InnerHTMLDirective, Directive, BaseElement, LWCDirectiveDomMode } from './types';
|
|
3
|
+
export declare function root(parse5ElmLocation: parse5.ElementLocation): Root;
|
|
4
|
+
export declare function element(parse5Elm: parse5.Element, parse5ElmLocation: parse5.ElementLocation): Element;
|
|
5
|
+
export declare function component(parse5Elm: parse5.Element, parse5ElmLocation: parse5.ElementLocation): Component;
|
|
6
|
+
export declare function slot(slotName: string, parse5ElmLocation: parse5.ElementLocation): Slot;
|
|
7
|
+
export declare function text(value: Literal | Expression, parse5Location: parse5.Location): Text;
|
|
8
|
+
export declare function comment(value: string, parse5Location: parse5.Location): Comment;
|
|
9
|
+
export declare function elementSourceLocation(parse5ElmLocation: parse5.ElementLocation): ElementSourceLocation;
|
|
10
|
+
export declare function sourceLocation(location: parse5.Location): SourceLocation;
|
|
11
|
+
export declare function literal<T extends string | boolean>(value: T): Literal<T>;
|
|
12
|
+
export declare function forEach(expression: Expression, elementLocation: SourceLocation, directiveLocation: SourceLocation, item: Identifier, index?: Identifier): ForEach;
|
|
13
|
+
export declare function forOf(expression: Expression, iterator: Identifier, elementLocation: SourceLocation, directiveLocation: SourceLocation): ForOf;
|
|
14
|
+
export declare function ifNode(modifier: string, condition: Expression, elementLocation: SourceLocation, directiveLocation: SourceLocation): If;
|
|
15
|
+
export declare function eventListener(name: string, handler: Expression, location: SourceLocation): EventListener;
|
|
16
|
+
export declare function keyDirective(value: Expression, location: SourceLocation): KeyDirective;
|
|
17
|
+
export declare function dynamicDirective(value: Expression, location: SourceLocation): DynamicDirective;
|
|
18
|
+
export declare function domDirective(lwcDomAttr: LWCDirectiveDomMode, location: SourceLocation): DomDirective;
|
|
19
|
+
export declare function innerHTMLDirective(value: Expression | Literal<string>, location: SourceLocation): InnerHTMLDirective;
|
|
20
|
+
export declare function preserveCommentsDirective(preserveComments: boolean, location: SourceLocation): PreserveCommentsDirective;
|
|
21
|
+
export declare function renderModeDirective(renderMode: LWCDirectiveRenderMode, location: SourceLocation): RenderModeDirective;
|
|
22
|
+
export declare function attribute(name: string, value: Expression | Literal, location: SourceLocation): Attribute;
|
|
23
|
+
export declare function property(name: string, attributeName: string, value: Expression | Literal, location: SourceLocation): Property;
|
|
24
|
+
export declare function isElement(node: BaseNode): node is Element;
|
|
25
|
+
export declare function isRoot(node: BaseNode): node is Root;
|
|
26
|
+
export declare function isComponent(node: BaseNode): node is Component;
|
|
27
|
+
export declare function isSlot(node: BaseNode): node is Slot;
|
|
28
|
+
export declare function isBaseElement(node: BaseNode): node is BaseElement;
|
|
29
|
+
export declare function isText(node: BaseNode): node is Text;
|
|
30
|
+
export declare function isComment(node: BaseNode): node is Comment;
|
|
31
|
+
export declare function isExpression(node: Expression | Literal): node is Expression;
|
|
32
|
+
export declare function isStringLiteral(node: Expression | Literal): node is Literal<string>;
|
|
33
|
+
export declare function isBooleanLiteral(node: Expression | Literal): node is Literal<boolean>;
|
|
34
|
+
export declare function isForOf(node: BaseNode): node is ForOf;
|
|
35
|
+
export declare function isForEach(node: BaseNode): node is ForEach;
|
|
36
|
+
export declare function isForBlock(node: BaseNode): node is ForBlock;
|
|
37
|
+
export declare function isIf(node: BaseNode): node is If;
|
|
38
|
+
export declare function isParentNode(node: BaseNode): node is ParentNode;
|
|
39
|
+
export declare function isDynamicDirective(directive: Directive): directive is DynamicDirective;
|
|
40
|
+
export declare function isDomDirective(directive: Directive): directive is DomDirective;
|
|
41
|
+
export declare function isInnerHTMLDirective(directive: Directive): directive is InnerHTMLDirective;
|
|
42
|
+
export declare function isKeyDirective(directive: Directive): directive is KeyDirective;
|
|
43
|
+
export declare function isRenderModeDirective(directive: Directive): directive is RenderModeDirective;
|
|
44
|
+
export declare function isPreserveCommentsDirective(directive: Directive): directive is PreserveCommentsDirective;
|
|
45
|
+
export declare function isProperty(node: BaseNode): node is Property;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lwc/template-compiler",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.3",
|
|
4
4
|
"description": "Template compiler package",
|
|
5
5
|
"homepage": "https://lwc.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -25,12 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"//": "Currently can't upgrade estree-walker to v3.0.0 because it dropped CommonJS support: https://git.io/JXguS",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lwc/errors": "2.
|
|
29
|
-
"@lwc/shared": "2.
|
|
30
|
-
"acorn": "~8.
|
|
31
|
-
"astring": "~1.
|
|
28
|
+
"@lwc/errors": "2.6.3",
|
|
29
|
+
"@lwc/shared": "2.6.3",
|
|
30
|
+
"acorn": "~8.7.0",
|
|
31
|
+
"astring": "~1.8.1",
|
|
32
32
|
"estree-walker": "~2.0.2",
|
|
33
|
-
"esutils": "~2.0.3",
|
|
34
33
|
"he": "~1.2.0",
|
|
35
34
|
"parse5": "~6.0.1"
|
|
36
35
|
},
|
|
@@ -40,5 +39,5 @@
|
|
|
40
39
|
"publishConfig": {
|
|
41
40
|
"access": "public"
|
|
42
41
|
},
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1fdd835243eed190b8ab9ca61ae7eae9f9a4073d"
|
|
44
43
|
}
|