@lwc/template-compiler 7.0.0-alpha.0 → 7.0.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/codegen/static-element.d.ts +4 -2
- package/dist/index.cjs.js +47 -47
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +48 -48
- package/dist/index.js.map +1 -1
- package/dist/shared/types.d.ts +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ChildNode, Root, StaticElement, StaticChildNode, Text } from '../shared/types';
|
|
2
2
|
import State from '../state';
|
|
3
3
|
export declare function getStaticNodes(root: Root, state: State): Set<ChildNode>;
|
|
4
|
-
export declare function transformStaticChildren(elm: StaticElement): (StaticChildNode | Text[])[];
|
|
5
|
-
export declare const
|
|
4
|
+
export declare function transformStaticChildren(elm: StaticElement, preserveComments: boolean): (StaticChildNode | Text[])[];
|
|
5
|
+
export declare const isContiguousText: (staticChild: StaticChildNode | Text[]) => staticChild is Text[];
|
|
6
|
+
export declare const isTextExpression: (node: ChildNode) => boolean;
|
|
7
|
+
export declare const hasDynamicText: (nodes: Text[]) => boolean;
|
package/dist/index.cjs.js
CHANGED
|
@@ -13038,7 +13038,7 @@ function collectStaticNodes(node, staticNodes, state) {
|
|
|
13038
13038
|
childrenAreStaticSafe &&= staticNodes.has(childNode);
|
|
13039
13039
|
// Collect nodes that have dynamic text ahead of time.
|
|
13040
13040
|
// We only need to know if the direct child has dynamic text.
|
|
13041
|
-
hasDynamicText ||=
|
|
13041
|
+
hasDynamicText ||= isTextExpression(childNode);
|
|
13042
13042
|
});
|
|
13043
13043
|
// for IfBlock and ElseifBlock, traverse down the else branch
|
|
13044
13044
|
if (isConditionalParentBlock(node) && node.else) {
|
|
@@ -13066,62 +13066,57 @@ function getStaticNodes(root, state) {
|
|
|
13066
13066
|
});
|
|
13067
13067
|
return staticNodes;
|
|
13068
13068
|
}
|
|
13069
|
-
// The purpose of this function is to concatenate
|
|
13069
|
+
// The purpose of this function is to concatenate contiguous text nodes into a single array
|
|
13070
13070
|
// to simplify the traversing logic when generating static parts and serializing the element.
|
|
13071
|
-
|
|
13071
|
+
// Note, comments that are adjacent to text nodes are ignored when preserveComments is false,
|
|
13072
|
+
// ex: <span>{dynamic}<!-- comment -->text</span>
|
|
13073
|
+
// preserveComments = false => [[text, text]]
|
|
13074
|
+
// preserveComments = true => [[text], comment, [text]]
|
|
13075
|
+
function transformStaticChildren(elm, preserveComments) {
|
|
13072
13076
|
const children = elm.children;
|
|
13073
13077
|
if (!children.length || !STATIC_ELEMENT_WITH_DYNAMIC_TEXT_SET.has(elm)) {
|
|
13074
13078
|
// The element either has no children or its children does not contain dynamic text.
|
|
13075
13079
|
return children;
|
|
13076
13080
|
}
|
|
13077
13081
|
if (STATIC_ELEMENT_TO_DYNAMIC_TEXT_CHILDREN_CACHE.has(elm)) {
|
|
13082
|
+
// This will be hit by serializeStaticElement
|
|
13078
13083
|
return STATIC_ELEMENT_TO_DYNAMIC_TEXT_CHILDREN_CACHE.get(elm);
|
|
13079
13084
|
}
|
|
13080
13085
|
const result = [];
|
|
13081
13086
|
const len = children.length;
|
|
13082
13087
|
let current;
|
|
13083
|
-
let next;
|
|
13084
13088
|
let contiguousTextNodes = null;
|
|
13085
13089
|
for (let i = 0; i < len; i++) {
|
|
13086
13090
|
current = children[i];
|
|
13087
|
-
if (
|
|
13088
|
-
contiguousTextNodes = null;
|
|
13089
|
-
result.push(current);
|
|
13090
|
-
}
|
|
13091
|
-
else {
|
|
13091
|
+
if (isText(current)) {
|
|
13092
13092
|
if (!shared.isNull(contiguousTextNodes)) {
|
|
13093
13093
|
// Already in a contiguous text node chain
|
|
13094
13094
|
// All contiguous nodes represent an expression in the source, it's guaranteed by the parser.
|
|
13095
13095
|
contiguousTextNodes.push(current);
|
|
13096
13096
|
}
|
|
13097
13097
|
else {
|
|
13098
|
-
|
|
13099
|
-
|
|
13100
|
-
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
// This is to normalize the traversal behavior when creating static parts and when serializing
|
|
13110
|
-
// the elements.
|
|
13111
|
-
contiguousTextNodes = [current];
|
|
13112
|
-
}
|
|
13113
|
-
// When contiguousTextNodes is null it is a single string literal.
|
|
13114
|
-
result.push(contiguousTextNodes ?? current);
|
|
13098
|
+
// First time seeing a contiguous text chain
|
|
13099
|
+
contiguousTextNodes = [current];
|
|
13100
|
+
result.push(contiguousTextNodes);
|
|
13101
|
+
}
|
|
13102
|
+
}
|
|
13103
|
+
else {
|
|
13104
|
+
// Non-text nodes signal the end of contiguous text node chain
|
|
13105
|
+
if (!isComment(current) || preserveComments) {
|
|
13106
|
+
// Ignore comment nodes when preserveComments is false
|
|
13107
|
+
contiguousTextNodes = null;
|
|
13108
|
+
result.push(current);
|
|
13115
13109
|
}
|
|
13116
13110
|
}
|
|
13117
13111
|
}
|
|
13118
13112
|
STATIC_ELEMENT_TO_DYNAMIC_TEXT_CHILDREN_CACHE.set(elm, result);
|
|
13119
13113
|
return result;
|
|
13120
13114
|
}
|
|
13121
|
-
//
|
|
13122
|
-
//
|
|
13123
|
-
|
|
13124
|
-
const
|
|
13115
|
+
// Given a static child, determines wether the child is a contiguous text node.
|
|
13116
|
+
// Note this is intended to be used with children generated from transformStaticChildren
|
|
13117
|
+
const isContiguousText = (staticChild) => shared.isArray(staticChild) && shared.ArrayEvery.call(staticChild, isText);
|
|
13118
|
+
const isTextExpression = (node) => isText(node) && !isStringLiteral(node.value);
|
|
13119
|
+
const hasDynamicText = (nodes) => shared.ArraySome.call(nodes, isTextExpression);
|
|
13125
13120
|
|
|
13126
13121
|
/*
|
|
13127
13122
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -13206,12 +13201,14 @@ function serializeAttrs(element, codeGen) {
|
|
|
13206
13201
|
// See buildParseFragmentFn for details.
|
|
13207
13202
|
return attrs.join('') + (hasClassAttr ? '${2}' : '${3}');
|
|
13208
13203
|
}
|
|
13209
|
-
function serializeChildren(
|
|
13204
|
+
function serializeChildren(children, parentTagName, codeGen) {
|
|
13210
13205
|
let html = '';
|
|
13211
|
-
for (const child of
|
|
13212
|
-
/* istanbul ignore else
|
|
13213
|
-
if (
|
|
13214
|
-
html +=
|
|
13206
|
+
for (const child of children) {
|
|
13207
|
+
/* istanbul ignore else */
|
|
13208
|
+
if (isContiguousText(child)) {
|
|
13209
|
+
html += hasDynamicText(child)
|
|
13210
|
+
? serializeDynamicTextNode(child, codeGen)
|
|
13211
|
+
: serializeChildren(child, parentTagName, codeGen);
|
|
13215
13212
|
}
|
|
13216
13213
|
else if (isText(child)) {
|
|
13217
13214
|
html += serializeStaticTextNode(child, rawContentElements.has(parentTagName.toUpperCase()));
|
|
@@ -13257,7 +13254,8 @@ function serializeStaticElement(element, codeGen) {
|
|
|
13257
13254
|
return html;
|
|
13258
13255
|
}
|
|
13259
13256
|
html += '>';
|
|
13260
|
-
|
|
13257
|
+
const children = transformStaticChildren(element, codeGen.preserveComments);
|
|
13258
|
+
html += serializeChildren(children, tagName, codeGen);
|
|
13261
13259
|
if (!shared.isVoidElement(tagName, namespace) || hasChildren) {
|
|
13262
13260
|
html += `</${tagName}>`;
|
|
13263
13261
|
}
|
|
@@ -13595,7 +13593,7 @@ class CodeGen {
|
|
|
13595
13593
|
}
|
|
13596
13594
|
genClassExpression(value) {
|
|
13597
13595
|
let classExpression = this.bindExpression(value);
|
|
13598
|
-
const isClassNameObjectBindingEnabled = shared.isAPIFeatureEnabled(
|
|
13596
|
+
const isClassNameObjectBindingEnabled = shared.isAPIFeatureEnabled(11 /* APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING */, this.state.config.apiVersion);
|
|
13599
13597
|
if (isClassNameObjectBindingEnabled) {
|
|
13600
13598
|
classExpression = this.genNormalizeClassName(classExpression);
|
|
13601
13599
|
}
|
|
@@ -13847,17 +13845,19 @@ class CodeGen {
|
|
|
13847
13845
|
while (stack.length > 0) {
|
|
13848
13846
|
const current = stack.shift();
|
|
13849
13847
|
// Skip comment nodes in parts count, as they will be stripped in production, unless when `lwc:preserve-comments` is enabled
|
|
13850
|
-
if (
|
|
13848
|
+
if (isContiguousText(current) || !isComment(current) || this.preserveComments) {
|
|
13851
13849
|
partId++;
|
|
13852
13850
|
}
|
|
13853
|
-
if (
|
|
13851
|
+
if (isContiguousText(current)) {
|
|
13854
13852
|
const textNodes = current;
|
|
13855
|
-
|
|
13856
|
-
|
|
13857
|
-
|
|
13858
|
-
|
|
13859
|
-
|
|
13860
|
-
|
|
13853
|
+
if (hasDynamicText(textNodes)) {
|
|
13854
|
+
const partToken = `${"t" /* STATIC_PART_TOKEN_ID.TEXT */}${partId}`;
|
|
13855
|
+
// Use the first text node as the key.
|
|
13856
|
+
// Dynamic text is guaranteed to have at least 1 text node in the array by transformStaticChildren.
|
|
13857
|
+
this.staticExpressionMap.set(textNodes[0], partToken);
|
|
13858
|
+
const concatenatedText = this.genConcatenatedText(textNodes.map(({ value }) => isStringLiteral(value) ? value.value : this.bindExpression(value)));
|
|
13859
|
+
setPartIdText(concatenatedText);
|
|
13860
|
+
}
|
|
13861
13861
|
}
|
|
13862
13862
|
else if (isElement(current)) {
|
|
13863
13863
|
const elm = current;
|
|
@@ -13903,7 +13903,7 @@ class CodeGen {
|
|
|
13903
13903
|
// For depth-first traversal, children must be prepended in order, so that they are processed before
|
|
13904
13904
|
// siblings. Note that this is consistent with the order used in the diffing algo as well as
|
|
13905
13905
|
// `traverseAndSetElements` in @lwc/engine-core.
|
|
13906
|
-
stack.unshift(...transformStaticChildren(elm));
|
|
13906
|
+
stack.unshift(...transformStaticChildren(elm, this.preserveComments));
|
|
13907
13907
|
}
|
|
13908
13908
|
}
|
|
13909
13909
|
if (partIdsToArgs.size === 0) {
|
|
@@ -14655,5 +14655,5 @@ exports.default = compile;
|
|
|
14655
14655
|
exports.kebabcaseToCamelcase = kebabcaseToCamelcase;
|
|
14656
14656
|
exports.parse = parse;
|
|
14657
14657
|
exports.toPropertyName = toPropertyName;
|
|
14658
|
-
/** version: 7.0.0
|
|
14658
|
+
/** version: 7.0.0 */
|
|
14659
14659
|
//# sourceMappingURL=index.cjs.js.map
|