@lwc/template-compiler 6.4.1 → 6.4.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/codegen/static-element.d.ts +4 -2
- package/dist/index.cjs.js +46 -46
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +47 -47
- package/dist/index.js.map +1 -1
- package/dist/shared/types.d.ts +1 -1
- package/package.json +3 -3
|
@@ -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
|
@@ -12675,7 +12675,7 @@ function collectStaticNodes(node, staticNodes, state) {
|
|
|
12675
12675
|
childrenAreStaticSafe &&= staticNodes.has(childNode);
|
|
12676
12676
|
// Collect nodes that have dynamic text ahead of time.
|
|
12677
12677
|
// We only need to know if the direct child has dynamic text.
|
|
12678
|
-
hasDynamicText ||=
|
|
12678
|
+
hasDynamicText ||= isTextExpression(childNode);
|
|
12679
12679
|
});
|
|
12680
12680
|
// for IfBlock and ElseifBlock, traverse down the else branch
|
|
12681
12681
|
if (isConditionalParentBlock(node) && node.else) {
|
|
@@ -12703,62 +12703,57 @@ function getStaticNodes(root, state) {
|
|
|
12703
12703
|
});
|
|
12704
12704
|
return staticNodes;
|
|
12705
12705
|
}
|
|
12706
|
-
// The purpose of this function is to concatenate
|
|
12706
|
+
// The purpose of this function is to concatenate contiguous text nodes into a single array
|
|
12707
12707
|
// to simplify the traversing logic when generating static parts and serializing the element.
|
|
12708
|
-
|
|
12708
|
+
// Note, comments that are adjacent to text nodes are ignored when preserveComments is false,
|
|
12709
|
+
// ex: <span>{dynamic}<!-- comment -->text</span>
|
|
12710
|
+
// preserveComments = false => [[text, text]]
|
|
12711
|
+
// preserveComments = true => [[text], comment, [text]]
|
|
12712
|
+
function transformStaticChildren(elm, preserveComments) {
|
|
12709
12713
|
const children = elm.children;
|
|
12710
12714
|
if (!children.length || !STATIC_ELEMENT_WITH_DYNAMIC_TEXT_SET.has(elm)) {
|
|
12711
12715
|
// The element either has no children or its children does not contain dynamic text.
|
|
12712
12716
|
return children;
|
|
12713
12717
|
}
|
|
12714
12718
|
if (STATIC_ELEMENT_TO_DYNAMIC_TEXT_CHILDREN_CACHE.has(elm)) {
|
|
12719
|
+
// This will be hit by serializeStaticElement
|
|
12715
12720
|
return STATIC_ELEMENT_TO_DYNAMIC_TEXT_CHILDREN_CACHE.get(elm);
|
|
12716
12721
|
}
|
|
12717
12722
|
const result = [];
|
|
12718
12723
|
const len = children.length;
|
|
12719
12724
|
let current;
|
|
12720
|
-
let next;
|
|
12721
12725
|
let contiguousTextNodes = null;
|
|
12722
12726
|
for (let i = 0; i < len; i++) {
|
|
12723
12727
|
current = children[i];
|
|
12724
|
-
if (
|
|
12725
|
-
contiguousTextNodes = null;
|
|
12726
|
-
result.push(current);
|
|
12727
|
-
}
|
|
12728
|
-
else {
|
|
12728
|
+
if (isText(current)) {
|
|
12729
12729
|
if (!shared.isNull(contiguousTextNodes)) {
|
|
12730
12730
|
// Already in a contiguous text node chain
|
|
12731
12731
|
// All contiguous nodes represent an expression in the source, it's guaranteed by the parser.
|
|
12732
12732
|
contiguousTextNodes.push(current);
|
|
12733
12733
|
}
|
|
12734
12734
|
else {
|
|
12735
|
-
|
|
12736
|
-
|
|
12737
|
-
|
|
12738
|
-
|
|
12739
|
-
|
|
12740
|
-
|
|
12741
|
-
|
|
12742
|
-
|
|
12743
|
-
|
|
12744
|
-
|
|
12745
|
-
|
|
12746
|
-
// This is to normalize the traversal behavior when creating static parts and when serializing
|
|
12747
|
-
// the elements.
|
|
12748
|
-
contiguousTextNodes = [current];
|
|
12749
|
-
}
|
|
12750
|
-
// When contiguousTextNodes is null it is a single string literal.
|
|
12751
|
-
result.push(contiguousTextNodes ?? current);
|
|
12735
|
+
// First time seeing a contiguous text chain
|
|
12736
|
+
contiguousTextNodes = [current];
|
|
12737
|
+
result.push(contiguousTextNodes);
|
|
12738
|
+
}
|
|
12739
|
+
}
|
|
12740
|
+
else {
|
|
12741
|
+
// Non-text nodes signal the end of contiguous text node chain
|
|
12742
|
+
if (!isComment(current) || preserveComments) {
|
|
12743
|
+
// Ignore comment nodes when preserveComments is false
|
|
12744
|
+
contiguousTextNodes = null;
|
|
12745
|
+
result.push(current);
|
|
12752
12746
|
}
|
|
12753
12747
|
}
|
|
12754
12748
|
}
|
|
12755
12749
|
STATIC_ELEMENT_TO_DYNAMIC_TEXT_CHILDREN_CACHE.set(elm, result);
|
|
12756
12750
|
return result;
|
|
12757
12751
|
}
|
|
12758
|
-
//
|
|
12759
|
-
//
|
|
12760
|
-
|
|
12761
|
-
const
|
|
12752
|
+
// Given a static child, determines wether the child is a contiguous text node.
|
|
12753
|
+
// Note this is intended to be used with children generated from transformStaticChildren
|
|
12754
|
+
const isContiguousText = (staticChild) => shared.isArray(staticChild) && shared.ArrayEvery.call(staticChild, isText);
|
|
12755
|
+
const isTextExpression = (node) => isText(node) && !isStringLiteral(node.value);
|
|
12756
|
+
const hasDynamicText = (nodes) => shared.ArraySome.call(nodes, isTextExpression);
|
|
12762
12757
|
|
|
12763
12758
|
/*
|
|
12764
12759
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -12843,12 +12838,14 @@ function serializeAttrs(element, codeGen) {
|
|
|
12843
12838
|
// See buildParseFragmentFn for details.
|
|
12844
12839
|
return attrs.join('') + (hasClassAttr ? '${2}' : '${3}');
|
|
12845
12840
|
}
|
|
12846
|
-
function serializeChildren(
|
|
12841
|
+
function serializeChildren(children, parentTagName, codeGen) {
|
|
12847
12842
|
let html = '';
|
|
12848
|
-
for (const child of
|
|
12849
|
-
/* istanbul ignore else
|
|
12850
|
-
if (
|
|
12851
|
-
html +=
|
|
12843
|
+
for (const child of children) {
|
|
12844
|
+
/* istanbul ignore else */
|
|
12845
|
+
if (isContiguousText(child)) {
|
|
12846
|
+
html += hasDynamicText(child)
|
|
12847
|
+
? serializeDynamicTextNode(child, codeGen)
|
|
12848
|
+
: serializeChildren(child, parentTagName, codeGen);
|
|
12852
12849
|
}
|
|
12853
12850
|
else if (isText(child)) {
|
|
12854
12851
|
html += serializeStaticTextNode(child, rawContentElements.has(parentTagName.toUpperCase()));
|
|
@@ -12894,7 +12891,8 @@ function serializeStaticElement(element, codeGen) {
|
|
|
12894
12891
|
return html;
|
|
12895
12892
|
}
|
|
12896
12893
|
html += '>';
|
|
12897
|
-
|
|
12894
|
+
const children = transformStaticChildren(element, codeGen.preserveComments);
|
|
12895
|
+
html += serializeChildren(children, tagName, codeGen);
|
|
12898
12896
|
if (!shared.isVoidElement(tagName, namespace) || hasChildren) {
|
|
12899
12897
|
html += `</${tagName}>`;
|
|
12900
12898
|
}
|
|
@@ -13464,17 +13462,19 @@ class CodeGen {
|
|
|
13464
13462
|
while (stack.length > 0) {
|
|
13465
13463
|
const current = stack.shift();
|
|
13466
13464
|
// Skip comment nodes in parts count, as they will be stripped in production, unless when `lwc:preserve-comments` is enabled
|
|
13467
|
-
if (
|
|
13465
|
+
if (isContiguousText(current) || !isComment(current) || this.preserveComments) {
|
|
13468
13466
|
partId++;
|
|
13469
13467
|
}
|
|
13470
|
-
if (
|
|
13468
|
+
if (isContiguousText(current)) {
|
|
13471
13469
|
const textNodes = current;
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
|
|
13475
|
-
|
|
13476
|
-
|
|
13477
|
-
|
|
13470
|
+
if (hasDynamicText(textNodes)) {
|
|
13471
|
+
const partToken = `${"t" /* STATIC_PART_TOKEN_ID.TEXT */}${partId}`;
|
|
13472
|
+
// Use the first text node as the key.
|
|
13473
|
+
// Dynamic text is guaranteed to have at least 1 text node in the array by transformStaticChildren.
|
|
13474
|
+
this.staticExpressionMap.set(textNodes[0], partToken);
|
|
13475
|
+
const concatenatedText = this.genConcatenatedText(textNodes.map(({ value }) => isStringLiteral(value) ? value.value : this.bindExpression(value)));
|
|
13476
|
+
setPartIdText(concatenatedText);
|
|
13477
|
+
}
|
|
13478
13478
|
}
|
|
13479
13479
|
else if (isElement(current)) {
|
|
13480
13480
|
const elm = current;
|
|
@@ -13520,7 +13520,7 @@ class CodeGen {
|
|
|
13520
13520
|
// For depth-first traversal, children must be prepended in order, so that they are processed before
|
|
13521
13521
|
// siblings. Note that this is consistent with the order used in the diffing algo as well as
|
|
13522
13522
|
// `traverseAndSetElements` in @lwc/engine-core.
|
|
13523
|
-
stack.unshift(...transformStaticChildren(elm));
|
|
13523
|
+
stack.unshift(...transformStaticChildren(elm, this.preserveComments));
|
|
13524
13524
|
}
|
|
13525
13525
|
}
|
|
13526
13526
|
if (partIdsToArgs.size === 0) {
|
|
@@ -14245,5 +14245,5 @@ function compile(source, config) {
|
|
|
14245
14245
|
exports.compile = compile;
|
|
14246
14246
|
exports.default = compile;
|
|
14247
14247
|
exports.parse = parse;
|
|
14248
|
-
/** version: 6.4.
|
|
14248
|
+
/** version: 6.4.3 */
|
|
14249
14249
|
//# sourceMappingURL=index.cjs.js.map
|