@lwc/template-compiler 6.2.0 → 6.3.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/codegen.d.ts +8 -2
- package/dist/codegen/expression.d.ts +10 -8
- package/dist/codegen/formatters/module.d.ts +2 -1
- package/dist/codegen/helpers.d.ts +3 -0
- package/dist/codegen/optimize.d.ts +1 -0
- package/dist/config.d.ts +14 -13
- package/dist/index.cjs.js +110 -41
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.js +110 -41
- package/dist/index.js.map +1 -1
- package/dist/parser/attribute.d.ts +1 -0
- package/dist/parser/expression-complex/html.d.ts +3 -5
- package/dist/parser/parser.d.ts +26 -8
- package/dist/shared/utils.d.ts +2 -0
- package/package.json +3 -3
|
@@ -69,10 +69,15 @@ export default class CodeGen {
|
|
|
69
69
|
genScopedFragId(id: string | t.Expression): t.CallExpression;
|
|
70
70
|
/**
|
|
71
71
|
* Generates childs vnodes when slot content is static.
|
|
72
|
+
* @param slotName
|
|
73
|
+
* @param data
|
|
74
|
+
* @param children
|
|
72
75
|
*/
|
|
73
76
|
getSlot(slotName: string, data: t.ObjectExpression, children: t.Expression): import("estree").CallExpression;
|
|
74
77
|
/**
|
|
75
78
|
* Generates a factory function that inturn generates child vnodes for scoped slot content.
|
|
79
|
+
* @param callback
|
|
80
|
+
* @param slotName
|
|
76
81
|
*/
|
|
77
82
|
getScopedSlotFactory(callback: t.FunctionExpression, slotName: t.Expression | t.SimpleLiteral): import("estree").CallExpression;
|
|
78
83
|
genTabIndex(children: [t.Expression]): import("estree").CallExpression;
|
|
@@ -84,9 +89,8 @@ export default class CodeGen {
|
|
|
84
89
|
* This routine generates an expression that avoids
|
|
85
90
|
* computing the sanitized html of a raw html if it does not change
|
|
86
91
|
* between renders.
|
|
87
|
-
*
|
|
88
92
|
* @param expr
|
|
89
|
-
* @returns
|
|
93
|
+
* @returns The generated expression
|
|
90
94
|
*/
|
|
91
95
|
genSanitizedHtmlExpr(expr: t.Expression): import("estree").ConditionalExpression | import("estree").LogicalExpression;
|
|
92
96
|
private _renderApiCall;
|
|
@@ -96,12 +100,14 @@ export default class CodeGen {
|
|
|
96
100
|
declareIdentifier(identifier: t.Identifier): void;
|
|
97
101
|
/**
|
|
98
102
|
* Searches the scopes to find an identifier with a matching name.
|
|
103
|
+
* @param identifier
|
|
99
104
|
*/
|
|
100
105
|
isLocalIdentifier(identifier: t.Identifier): boolean;
|
|
101
106
|
/**
|
|
102
107
|
* Bind the passed expression to the component instance. It applies the following transformation to the expression:
|
|
103
108
|
* - {value} --> {$cmp.value}
|
|
104
109
|
* - {value[index]} --> {$cmp.value[$cmp.index]}
|
|
110
|
+
* @param expression
|
|
105
111
|
*/
|
|
106
112
|
bindExpression(expression: Expression | Literal | ComplexExpression): t.Expression;
|
|
107
113
|
genStaticElement(element: StaticElement, slotParentName?: string): t.Expression;
|
|
@@ -4,20 +4,22 @@ import type CodeGen from './codegen';
|
|
|
4
4
|
/**
|
|
5
5
|
* Bind the passed expression to the component instance. It applies the following
|
|
6
6
|
* transformation to the expression:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* - `{value}` --> `{$cmp.value}`
|
|
8
|
+
* - `{value[index]}` --> `{$cmp.value[$cmp.index]}`
|
|
9
|
+
* - `{foo ?? bar}` --> `{$cmp.foo ?? $cmp.bar}`
|
|
10
|
+
* - `{foo?.bar}` --> `{$cmp.foo?.bar}`
|
|
11
11
|
*
|
|
12
12
|
* However, parameter variables are not be transformed in this way. For example,
|
|
13
13
|
* the following transformations do not happen:
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* - `{(foo) => foo && bar}` --> `{(foo) => $cmp.foo && $cmp.bar}`
|
|
15
|
+
* - `{(foo) => foo && bar}` --> `{($cmp.foo) => foo && $cmp.bar}`
|
|
16
|
+
* - `{(foo) => foo && bar}` --> `{($cmp.foo) => $cmp.foo && $cmp.bar}`
|
|
17
17
|
*
|
|
18
18
|
* Instead, the scopes are respected:
|
|
19
|
-
*
|
|
19
|
+
* - `{(foo) => foo && $cmp.bar}`
|
|
20
20
|
*
|
|
21
21
|
* Similar checks occur for local identifiers introduced via for:each or similar.
|
|
22
|
+
* @param expression
|
|
23
|
+
* @param codeGen
|
|
22
24
|
*/
|
|
23
25
|
export declare function bindComplexExpression(expression: ComplexExpression, codeGen: CodeGen): t.Expression;
|
|
@@ -4,7 +4,8 @@ import CodeGen from '../codegen';
|
|
|
4
4
|
* Generate an ES module AST from a template ESTree AST. The generated module imports the dependent
|
|
5
5
|
* LWC components via import statements and expose the template function via a default export
|
|
6
6
|
* statement.
|
|
7
|
-
*
|
|
7
|
+
* @param templateFn
|
|
8
|
+
* @param codeGen
|
|
8
9
|
* @example
|
|
9
10
|
* ```js
|
|
10
11
|
* import { registerTemplate } from 'lwc';
|
|
@@ -10,10 +10,13 @@ export declare function objectToAST(obj: object, valueMapper: (key: string) => t
|
|
|
10
10
|
*
|
|
11
11
|
* This function searches through the children to determine if flattening needs to occur in the runtime.
|
|
12
12
|
* Children should be flattened if they contain an iterator, a dynamic directive or a slot inside a light dom element.
|
|
13
|
+
* @param codeGen
|
|
14
|
+
* @param children
|
|
13
15
|
*/
|
|
14
16
|
export declare function shouldFlatten(codeGen: CodeGen, children: ChildNode[]): boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Returns true if the AST element or any of its descendants use an id attribute.
|
|
19
|
+
* @param node
|
|
17
20
|
*/
|
|
18
21
|
export declare function hasIdAttribute(node: Node): boolean;
|
|
19
22
|
export declare function memorizeHandler(codeGen: CodeGen, componentHandler: t.Expression, handler: t.Expression): t.Expression;
|
package/dist/config.d.ts
CHANGED
|
@@ -6,23 +6,24 @@ export interface Config {
|
|
|
6
6
|
*/
|
|
7
7
|
customRendererConfig?: CustomRendererConfig;
|
|
8
8
|
/**
|
|
9
|
-
* Enable computed member expression in the template.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Enable computed member expression in the template.
|
|
10
|
+
* @example
|
|
11
|
+
* <template>
|
|
12
|
+
* {list[0].name}
|
|
13
|
+
* </template>
|
|
13
14
|
*/
|
|
14
15
|
experimentalComputedMemberExpression?: boolean;
|
|
15
16
|
/**
|
|
16
17
|
* Enable use of (a subset of) JavaScript expressions in place of template bindings.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
18
|
+
* @example
|
|
19
|
+
* <template>
|
|
20
|
+
* <input
|
|
21
|
+
* attr={complex ?? expressions()}
|
|
22
|
+
* onchange={({ target }) => componentMethod(target.value)}
|
|
23
|
+
* >
|
|
24
|
+
* Hey there {inAustralia ? 'mate' : 'friend'}
|
|
25
|
+
* </input>
|
|
26
|
+
* </template>
|
|
26
27
|
*/
|
|
27
28
|
experimentalComplexExpressions?: boolean;
|
|
28
29
|
/**
|
package/dist/index.cjs.js
CHANGED
|
@@ -78,7 +78,7 @@ const DASHED_TAGNAME_ELEMENT_SET = new Set([
|
|
|
78
78
|
const STATIC_SAFE_DIRECTIVES = new Set(['Ref']);
|
|
79
79
|
|
|
80
80
|
/*
|
|
81
|
-
* Copyright (c)
|
|
81
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
|
82
82
|
* All rights reserved.
|
|
83
83
|
* SPDX-License-Identifier: MIT
|
|
84
84
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
@@ -102,6 +102,7 @@ function toPropertyName(attr) {
|
|
|
102
102
|
* Test if given tag name is a custom element.
|
|
103
103
|
* @param tagName element tag name to test
|
|
104
104
|
* @returns true if given tag name represents a custom element, false otherwise.
|
|
105
|
+
* @example isCustomElementTag("my-component") // true
|
|
105
106
|
*/
|
|
106
107
|
function isCustomElementTag(tagName) {
|
|
107
108
|
return tagName.includes('-') && !DASHED_TAGNAME_ELEMENT_SET.has(tagName);
|
|
@@ -110,6 +111,7 @@ function isCustomElementTag(tagName) {
|
|
|
110
111
|
* Test if given tag name is a custom LWC tag denoted lwc:*.
|
|
111
112
|
* @param tagName element tag name to test
|
|
112
113
|
* @returns true if given tag name represents a custom LWC tag, false otherwise.
|
|
114
|
+
* @example isLwcElementTag("my-component") // false
|
|
113
115
|
*/
|
|
114
116
|
function isLwcElementTag(tagName) {
|
|
115
117
|
return tagName.startsWith('lwc:');
|
|
@@ -10156,6 +10158,8 @@ class ParserCtx {
|
|
|
10156
10158
|
}
|
|
10157
10159
|
/**
|
|
10158
10160
|
* This method flattens the scopes into a single array for traversal.
|
|
10161
|
+
* @param element
|
|
10162
|
+
* @yields Each node in the scope and its parent.
|
|
10159
10163
|
*/
|
|
10160
10164
|
*ancestors(element) {
|
|
10161
10165
|
const ancestors = this.elementScopes.flat();
|
|
@@ -10168,11 +10172,10 @@ class ParserCtx {
|
|
|
10168
10172
|
* This method returns an iterator over ancestor nodes, starting at the parent and ending at the root node.
|
|
10169
10173
|
*
|
|
10170
10174
|
* Note: There are instances when we want to terminate the traversal early, such as searching for a ForBlock parent.
|
|
10171
|
-
*
|
|
10172
|
-
* @param
|
|
10173
|
-
* @param {function} predicate - This callback is called once for each ancestor until it finds one where predicate returns true.
|
|
10174
|
-
* @param {function} traversalCond - This callback is called after predicate and will terminate the traversal if it returns false.
|
|
10175
|
+
* @param predicate This callback is called once for each ancestor until it finds one where predicate returns true.
|
|
10176
|
+
* @param traversalCond This callback is called after predicate and will terminate the traversal if it returns false.
|
|
10175
10177
|
* traversalCond is ignored if no value is provided.
|
|
10178
|
+
* @param startNode Starting node to begin search, defaults to the tail of the current scope.
|
|
10176
10179
|
*/
|
|
10177
10180
|
findAncestor(predicate, traversalCond = () => true, startNode) {
|
|
10178
10181
|
for (const { current, parent } of this.ancestors(startNode)) {
|
|
@@ -10187,8 +10190,7 @@ class ParserCtx {
|
|
|
10187
10190
|
}
|
|
10188
10191
|
/**
|
|
10189
10192
|
* This method searchs the current scope and returns the value that satisfies the predicate.
|
|
10190
|
-
*
|
|
10191
|
-
* @param {function} predicate - This callback is called once for each sibling in the current scope
|
|
10193
|
+
* @param predicate This callback is called once for each sibling in the current scope
|
|
10192
10194
|
* until it finds one where predicate returns true.
|
|
10193
10195
|
*/
|
|
10194
10196
|
findInCurrentElementScope(predicate) {
|
|
@@ -10299,8 +10301,7 @@ class ParserCtx {
|
|
|
10299
10301
|
/**
|
|
10300
10302
|
* This method recovers from diagnostic errors that are encountered when fn is invoked.
|
|
10301
10303
|
* All other errors are considered compiler errors and can not be recovered from.
|
|
10302
|
-
*
|
|
10303
|
-
* @param fn - method to be invoked.
|
|
10304
|
+
* @param fn method to be invoked.
|
|
10304
10305
|
*/
|
|
10305
10306
|
withErrorRecovery(fn) {
|
|
10306
10307
|
try {
|
|
@@ -10337,18 +10338,28 @@ class ParserCtx {
|
|
|
10337
10338
|
}
|
|
10338
10339
|
/**
|
|
10339
10340
|
* This method throws a diagnostic error with the node's location.
|
|
10341
|
+
* @param errorInfo
|
|
10342
|
+
* @param node
|
|
10343
|
+
* @param messageArgs
|
|
10340
10344
|
*/
|
|
10341
10345
|
throwOnNode(errorInfo, node, messageArgs) {
|
|
10342
10346
|
this.throw(errorInfo, messageArgs, node.location);
|
|
10343
10347
|
}
|
|
10344
10348
|
/**
|
|
10345
10349
|
* This method throws a diagnostic error with location information.
|
|
10350
|
+
* @param errorInfo
|
|
10351
|
+
* @param location
|
|
10352
|
+
* @param messageArgs
|
|
10346
10353
|
*/
|
|
10347
10354
|
throwAtLocation(errorInfo, location, messageArgs) {
|
|
10348
10355
|
this.throw(errorInfo, messageArgs, location);
|
|
10349
10356
|
}
|
|
10350
10357
|
/**
|
|
10351
10358
|
* This method throws a diagnostic error and will immediately exit the current routine.
|
|
10359
|
+
* @param errorInfo
|
|
10360
|
+
* @param messageArgs
|
|
10361
|
+
* @param location
|
|
10362
|
+
* @throws
|
|
10352
10363
|
*/
|
|
10353
10364
|
throw(errorInfo, messageArgs, location) {
|
|
10354
10365
|
throw errors.generateCompilerError(errorInfo, {
|
|
@@ -10360,18 +10371,27 @@ class ParserCtx {
|
|
|
10360
10371
|
}
|
|
10361
10372
|
/**
|
|
10362
10373
|
* This method logs a diagnostic warning with the node's location.
|
|
10374
|
+
* @param errorInfo
|
|
10375
|
+
* @param node
|
|
10376
|
+
* @param messageArgs
|
|
10363
10377
|
*/
|
|
10364
10378
|
warnOnNode(errorInfo, node, messageArgs) {
|
|
10365
10379
|
this.warn(errorInfo, messageArgs, node.location);
|
|
10366
10380
|
}
|
|
10367
10381
|
/**
|
|
10368
10382
|
* This method logs a diagnostic warning with location information.
|
|
10383
|
+
* @param errorInfo
|
|
10384
|
+
* @param location
|
|
10385
|
+
* @param messageArgs
|
|
10369
10386
|
*/
|
|
10370
10387
|
warnAtLocation(errorInfo, location, messageArgs) {
|
|
10371
10388
|
this.warn(errorInfo, messageArgs, location);
|
|
10372
10389
|
}
|
|
10373
10390
|
/**
|
|
10374
10391
|
* This method logs a diagnostic warning and will continue execution of the current routine.
|
|
10392
|
+
* @param errorInfo
|
|
10393
|
+
* @param messageArgs
|
|
10394
|
+
* @param location
|
|
10375
10395
|
*/
|
|
10376
10396
|
warn(errorInfo, messageArgs, location) {
|
|
10377
10397
|
this.addDiagnostic(errors.generateCompilerDiagnostic(errorInfo, {
|
|
@@ -10592,22 +10612,24 @@ function getTrailingChars(str) {
|
|
|
10592
10612
|
* This function checks for "unbalanced" extraneous parentheses surrounding the expression.
|
|
10593
10613
|
*
|
|
10594
10614
|
* Examples of balanced extraneous parentheses (validation passes):
|
|
10595
|
-
*
|
|
10596
|
-
*
|
|
10597
|
-
*
|
|
10615
|
+
* - `{(foo.bar)}` <-- the MemberExpressions does not account for the surrounding parens
|
|
10616
|
+
* - `{(foo())}` <-- the CallExpression does not account for the surrounding parens
|
|
10617
|
+
* - `{((foo ?? bar)())}` <-- the CallExpression does not account for the surrounding parens
|
|
10598
10618
|
*
|
|
10599
10619
|
* Examples of unbalanced extraneous parentheses (validation fails):
|
|
10600
|
-
*
|
|
10601
|
-
*
|
|
10620
|
+
* - `{(foo.bar))}` <-- there is an extraneous trailing paren
|
|
10621
|
+
* - `{foo())}` <-- there is an extraneous trailing paren
|
|
10602
10622
|
*
|
|
10603
10623
|
* Examples of no extraneous parentheses (validation passes):
|
|
10604
|
-
*
|
|
10605
|
-
*
|
|
10606
|
-
*
|
|
10624
|
+
* - `{foo()}` <-- the CallExpression accounts for the trailing paren
|
|
10625
|
+
* - `{(foo ?? bar).baz}` <-- the outer MemberExpression accounts for the leading paren
|
|
10626
|
+
* - `{(foo).bar}` <-- the outer MemberExpression accounts for the leading paren
|
|
10607
10627
|
*
|
|
10608
10628
|
* Notably, no examples of extraneous leading parens could be found - these result in a
|
|
10609
10629
|
* parsing error in Acorn. However, this function still checks, in case there is an
|
|
10610
10630
|
* unknown expression that would parse with an extraneous leading paren.
|
|
10631
|
+
* @param leadingChars
|
|
10632
|
+
* @param trailingChars
|
|
10611
10633
|
*/
|
|
10612
10634
|
function validateMatchingExtraParens(leadingChars, trailingChars) {
|
|
10613
10635
|
const numLeadingParens = leadingChars.split('(').length - 1;
|
|
@@ -10619,8 +10641,8 @@ function validateMatchingExtraParens(leadingChars, trailingChars) {
|
|
|
10619
10641
|
*
|
|
10620
10642
|
* Its behavior diverges from that specified in the WHATWG HTML spec
|
|
10621
10643
|
* in two places:
|
|
10622
|
-
*
|
|
10623
|
-
*
|
|
10644
|
+
* - 13.2.5.38 - unquoted attribute values
|
|
10645
|
+
* - 13.2.5.1 - the "data" state, which corresponds to parsing outside of tags
|
|
10624
10646
|
*
|
|
10625
10647
|
* Specifically, this tokenizer defers to Acorn's JavaScript parser when
|
|
10626
10648
|
* encountering a `{` character for an attribute value or within a text
|
|
@@ -10684,7 +10706,7 @@ class TemplateHtmlTokenizer extends Tokenizer {
|
|
|
10684
10706
|
// coming later in an unquoted attr value should not be considered
|
|
10685
10707
|
// the beginning of a template expression.
|
|
10686
10708
|
this.checkedAttrs.add(this.currentAttr);
|
|
10687
|
-
// @ts-
|
|
10709
|
+
// @ts-expect-error private method
|
|
10688
10710
|
super._stateAttributeValueUnquoted(codePoint);
|
|
10689
10711
|
}
|
|
10690
10712
|
}
|
|
@@ -10717,7 +10739,7 @@ class TemplateHtmlTokenizer extends Tokenizer {
|
|
|
10717
10739
|
this.currentCharacterToken = null;
|
|
10718
10740
|
}
|
|
10719
10741
|
else {
|
|
10720
|
-
// @ts-
|
|
10742
|
+
// @ts-expect-error private method
|
|
10721
10743
|
super._stateData(codePoint);
|
|
10722
10744
|
}
|
|
10723
10745
|
}
|
|
@@ -10771,11 +10793,9 @@ class TemplateHtmlParser extends Parser {
|
|
|
10771
10793
|
/**
|
|
10772
10794
|
* Parse the LWC template using a customized parser & lexer that allow
|
|
10773
10795
|
* for template expressions to be parsed correctly.
|
|
10774
|
-
*
|
|
10775
|
-
* @param
|
|
10776
|
-
* @
|
|
10777
|
-
*
|
|
10778
|
-
* @return {DocumentFragment} the parsed document
|
|
10796
|
+
* @param source raw template markup
|
|
10797
|
+
* @param config
|
|
10798
|
+
* @returns the parsed document
|
|
10779
10799
|
*/
|
|
10780
10800
|
function parseFragment(source, config) {
|
|
10781
10801
|
const { ctx, sourceCodeLocationInfo = true, onParseError } = config;
|
|
@@ -11155,6 +11175,7 @@ function isTemplateDirective(attrName) {
|
|
|
11155
11175
|
}
|
|
11156
11176
|
/**
|
|
11157
11177
|
* Convert attribute name from kebab case to camel case property name
|
|
11178
|
+
* @param attrName
|
|
11158
11179
|
*/
|
|
11159
11180
|
function attributeToPropertyName(attrName) {
|
|
11160
11181
|
return ATTRS_PROPS_TRANFORMS[attrName] || toPropertyName(attrName);
|
|
@@ -11283,6 +11304,10 @@ function parseRoot(ctx, parse5Elm) {
|
|
|
11283
11304
|
*
|
|
11284
11305
|
* Note: Not every node in the hierarchy is guaranteed to be created, for example,
|
|
11285
11306
|
* <div></div> will only create an Element node.
|
|
11307
|
+
* @param ctx
|
|
11308
|
+
* @param parse5Elm
|
|
11309
|
+
* @param parentNode
|
|
11310
|
+
* @param parse5ParentLocation
|
|
11286
11311
|
*/
|
|
11287
11312
|
function parseElement(ctx, parse5Elm, parentNode, parse5ParentLocation) {
|
|
11288
11313
|
const parse5ElmLocation = parseElementLocation(ctx, parse5Elm, parse5ParentLocation);
|
|
@@ -11478,7 +11503,23 @@ function parseText(ctx, parse5Text) {
|
|
|
11478
11503
|
}
|
|
11479
11504
|
// Extract the raw source to avoid HTML entity decoding done by parse5
|
|
11480
11505
|
const rawText = cleanTextNode(ctx.getSource(location.startOffset, location.endOffset));
|
|
11481
|
-
|
|
11506
|
+
/*
|
|
11507
|
+
The original job of this if-block was to discard the whitespace between HTML tags, HTML
|
|
11508
|
+
comments, and HTML tags and HTML comments. The whitespace inside the text content of HTML tags
|
|
11509
|
+
would never be considered here because they would not be parsed into individual text nodes until
|
|
11510
|
+
later (several lines below).
|
|
11511
|
+
|
|
11512
|
+
["Hello {first} {last}!"] => ["Hello ", "{first}", " ", "{last}", "!"]
|
|
11513
|
+
|
|
11514
|
+
With the implementation of complex template expressions, whitespace that shouldn't be discarded
|
|
11515
|
+
has already been parsed into individual text nodes at this point so we only discard when
|
|
11516
|
+
experimentalComplexExpressions is disabled.
|
|
11517
|
+
|
|
11518
|
+
When removing the experimentalComplexExpressions flag, we need to figure out how to best discard
|
|
11519
|
+
the HTML whitespace while preserving text content whitespace, while also taking into account how
|
|
11520
|
+
comments are sometimes preserved (in which case we need to keep the HTML whitespace).
|
|
11521
|
+
*/
|
|
11522
|
+
if (!rawText.trim().length && !ctx.config.experimentalComplexExpressions) {
|
|
11482
11523
|
return parsedTextNodes;
|
|
11483
11524
|
}
|
|
11484
11525
|
// TODO [#3370]: remove experimental template expression flag
|
|
@@ -12434,6 +12475,8 @@ function objectToAST(obj, valueMapper) {
|
|
|
12434
12475
|
*
|
|
12435
12476
|
* This function searches through the children to determine if flattening needs to occur in the runtime.
|
|
12436
12477
|
* Children should be flattened if they contain an iterator, a dynamic directive or a slot inside a light dom element.
|
|
12478
|
+
* @param codeGen
|
|
12479
|
+
* @param children
|
|
12437
12480
|
*/
|
|
12438
12481
|
function shouldFlatten(codeGen, children) {
|
|
12439
12482
|
return children.some((child) => {
|
|
@@ -12451,6 +12494,7 @@ function shouldFlatten(codeGen, children) {
|
|
|
12451
12494
|
}
|
|
12452
12495
|
/**
|
|
12453
12496
|
* Returns true if the AST element or any of its descendants use an id attribute.
|
|
12497
|
+
* @param node
|
|
12454
12498
|
*/
|
|
12455
12499
|
function hasIdAttribute(node) {
|
|
12456
12500
|
if (isBaseElement(node)) {
|
|
@@ -12625,6 +12669,7 @@ const rawContentElements = new Set([
|
|
|
12625
12669
|
/**
|
|
12626
12670
|
* Escape all the characters that could break a JavaScript template string literal: "`" (backtick),
|
|
12627
12671
|
* "${" (dollar + open curly) and "\" (backslash).
|
|
12672
|
+
* @param str
|
|
12628
12673
|
*/
|
|
12629
12674
|
function templateStringEscape(str) {
|
|
12630
12675
|
return str.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
|
|
@@ -12730,21 +12775,23 @@ function serializeStaticElement(element, preserveComments) {
|
|
|
12730
12775
|
/**
|
|
12731
12776
|
* Bind the passed expression to the component instance. It applies the following
|
|
12732
12777
|
* transformation to the expression:
|
|
12733
|
-
*
|
|
12734
|
-
*
|
|
12735
|
-
*
|
|
12736
|
-
*
|
|
12778
|
+
* - `{value}` --> `{$cmp.value}`
|
|
12779
|
+
* - `{value[index]}` --> `{$cmp.value[$cmp.index]}`
|
|
12780
|
+
* - `{foo ?? bar}` --> `{$cmp.foo ?? $cmp.bar}`
|
|
12781
|
+
* - `{foo?.bar}` --> `{$cmp.foo?.bar}`
|
|
12737
12782
|
*
|
|
12738
12783
|
* However, parameter variables are not be transformed in this way. For example,
|
|
12739
12784
|
* the following transformations do not happen:
|
|
12740
|
-
*
|
|
12741
|
-
*
|
|
12742
|
-
*
|
|
12785
|
+
* - `{(foo) => foo && bar}` --> `{(foo) => $cmp.foo && $cmp.bar}`
|
|
12786
|
+
* - `{(foo) => foo && bar}` --> `{($cmp.foo) => foo && $cmp.bar}`
|
|
12787
|
+
* - `{(foo) => foo && bar}` --> `{($cmp.foo) => $cmp.foo && $cmp.bar}`
|
|
12743
12788
|
*
|
|
12744
12789
|
* Instead, the scopes are respected:
|
|
12745
|
-
*
|
|
12790
|
+
* - `{(foo) => foo && $cmp.bar}`
|
|
12746
12791
|
*
|
|
12747
12792
|
* Similar checks occur for local identifiers introduced via for:each or similar.
|
|
12793
|
+
* @param expression
|
|
12794
|
+
* @param codeGen
|
|
12748
12795
|
*/
|
|
12749
12796
|
function bindComplexExpression(expression, codeGen) {
|
|
12750
12797
|
const expressionScopes = new ExpressionScopes();
|
|
@@ -13008,6 +13055,9 @@ class CodeGen {
|
|
|
13008
13055
|
}
|
|
13009
13056
|
/**
|
|
13010
13057
|
* Generates childs vnodes when slot content is static.
|
|
13058
|
+
* @param slotName
|
|
13059
|
+
* @param data
|
|
13060
|
+
* @param children
|
|
13011
13061
|
*/
|
|
13012
13062
|
getSlot(slotName, data, children) {
|
|
13013
13063
|
this.slotNames.add(slotName);
|
|
@@ -13020,6 +13070,8 @@ class CodeGen {
|
|
|
13020
13070
|
}
|
|
13021
13071
|
/**
|
|
13022
13072
|
* Generates a factory function that inturn generates child vnodes for scoped slot content.
|
|
13073
|
+
* @param callback
|
|
13074
|
+
* @param slotName
|
|
13023
13075
|
*/
|
|
13024
13076
|
getScopedSlotFactory(callback, slotName) {
|
|
13025
13077
|
return this._renderApiCall(RENDER_APIS.scopedSlotFactory, [slotName, callback]);
|
|
@@ -13053,9 +13105,8 @@ class CodeGen {
|
|
|
13053
13105
|
* This routine generates an expression that avoids
|
|
13054
13106
|
* computing the sanitized html of a raw html if it does not change
|
|
13055
13107
|
* between renders.
|
|
13056
|
-
*
|
|
13057
13108
|
* @param expr
|
|
13058
|
-
* @returns
|
|
13109
|
+
* @returns The generated expression
|
|
13059
13110
|
*/
|
|
13060
13111
|
genSanitizedHtmlExpr(expr) {
|
|
13061
13112
|
const instance = this.innerHtmlInstances++;
|
|
@@ -13105,6 +13156,7 @@ class CodeGen {
|
|
|
13105
13156
|
}
|
|
13106
13157
|
/**
|
|
13107
13158
|
* Searches the scopes to find an identifier with a matching name.
|
|
13159
|
+
* @param identifier
|
|
13108
13160
|
*/
|
|
13109
13161
|
isLocalIdentifier(identifier) {
|
|
13110
13162
|
let scope = this.scope;
|
|
@@ -13120,6 +13172,7 @@ class CodeGen {
|
|
|
13120
13172
|
* Bind the passed expression to the component instance. It applies the following transformation to the expression:
|
|
13121
13173
|
* - {value} --> {$cmp.value}
|
|
13122
13174
|
* - {value[index]} --> {$cmp.value[$cmp.index]}
|
|
13175
|
+
* @param expression
|
|
13123
13176
|
*/
|
|
13124
13177
|
bindExpression(expression) {
|
|
13125
13178
|
if (isIdentifier(expression)) {
|
|
@@ -13132,6 +13185,9 @@ class CodeGen {
|
|
|
13132
13185
|
}
|
|
13133
13186
|
// TODO [#3370]: remove experimental template expression flag
|
|
13134
13187
|
if (this.state.config.experimentalComplexExpressions) {
|
|
13188
|
+
// Cloning here is necessary because `this.replace()` is destructive, and we might use the
|
|
13189
|
+
// node later during static content optimization
|
|
13190
|
+
expression = doStructuredClone(expression);
|
|
13135
13191
|
return bindComplexExpression(expression, this);
|
|
13136
13192
|
}
|
|
13137
13193
|
// We need access to both this `this` and the walker's `this` in the walker
|
|
@@ -13301,6 +13357,7 @@ function kebabcaseToCamelcase(name) {
|
|
|
13301
13357
|
* };
|
|
13302
13358
|
* }
|
|
13303
13359
|
* ```
|
|
13360
|
+
* @param templateFn
|
|
13304
13361
|
*/
|
|
13305
13362
|
function optimizeStaticExpressions(templateFn) {
|
|
13306
13363
|
const result = [];
|
|
@@ -13383,7 +13440,8 @@ function generateHoistedNodes(codegen) {
|
|
|
13383
13440
|
* Generate an ES module AST from a template ESTree AST. The generated module imports the dependent
|
|
13384
13441
|
* LWC components via import statements and expose the template function via a default export
|
|
13385
13442
|
* statement.
|
|
13386
|
-
*
|
|
13443
|
+
* @param templateFn
|
|
13444
|
+
* @param codeGen
|
|
13387
13445
|
* @example
|
|
13388
13446
|
* ```js
|
|
13389
13447
|
* import { registerTemplate } from 'lwc';
|
|
@@ -13562,7 +13620,6 @@ function transform(codeGen) {
|
|
|
13562
13620
|
}
|
|
13563
13621
|
/**
|
|
13564
13622
|
* Transforms an IfBlock or ElseifBlock along with both its direct descendants and its 'else' descendants.
|
|
13565
|
-
*
|
|
13566
13623
|
* @param conditionalParentBlock The IfBlock or ElseifBlock to transform into a conditional expression
|
|
13567
13624
|
* @param key The key to use for this chain of IfBlock/ElseifBlock branches, if applicable
|
|
13568
13625
|
* @returns A conditional expression representing the full conditional tree with conditionalParentBlock as the root node
|
|
@@ -13930,16 +13987,28 @@ function generate (root, state) {
|
|
|
13930
13987
|
}
|
|
13931
13988
|
|
|
13932
13989
|
/*
|
|
13933
|
-
* Copyright (c)
|
|
13990
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
|
13934
13991
|
* All rights reserved.
|
|
13935
13992
|
* SPDX-License-Identifier: MIT
|
|
13936
13993
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
13937
13994
|
*/
|
|
13995
|
+
/**
|
|
13996
|
+
* Parses HTML markup into an AST
|
|
13997
|
+
* @param source HTML markup to parse
|
|
13998
|
+
* @param config HTML template compilation config
|
|
13999
|
+
* @returns Object containing the AST
|
|
14000
|
+
*/
|
|
13938
14001
|
function parse(source, config = {}) {
|
|
13939
14002
|
const options = normalizeConfig(config);
|
|
13940
14003
|
const state = new State$1(options);
|
|
13941
14004
|
return parse$1(source, state);
|
|
13942
14005
|
}
|
|
14006
|
+
/**
|
|
14007
|
+
* Compiles a LWC template to JavaScript source code consumable by the engine.
|
|
14008
|
+
* @param source HTML markup to compile
|
|
14009
|
+
* @param config HTML template compilation config
|
|
14010
|
+
* @returns Object containing the compiled code and any warnings that occurred.
|
|
14011
|
+
*/
|
|
13943
14012
|
function compile(source, config) {
|
|
13944
14013
|
const options = normalizeConfig(config);
|
|
13945
14014
|
const state = new State$1(options);
|
|
@@ -13970,5 +14039,5 @@ function compile(source, config) {
|
|
|
13970
14039
|
exports.compile = compile;
|
|
13971
14040
|
exports.default = compile;
|
|
13972
14041
|
exports.parse = parse;
|
|
13973
|
-
/** version: 6.
|
|
14042
|
+
/** version: 6.3.0 */
|
|
13974
14043
|
//# sourceMappingURL=index.cjs.js.map
|