@lwc/template-compiler 3.7.0 → 3.7.2

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/index.js CHANGED
@@ -158,167 +158,6 @@ function normalizeConfig(config) {
158
158
  experimentalComplexExpressions: false, experimentalDynamicDirective: false, enableDynamicComponents: false, enableStaticContentOptimization: true, enableLwcSpread: true }, config), { apiVersion }), { customRendererConfig }), { instrumentation });
159
159
  }
160
160
 
161
- function isIdentifier(node) {
162
- return node.type === 'Identifier';
163
- }
164
- function isMemberExpression(node) {
165
- return node.type === 'MemberExpression';
166
- }
167
- function isArrayExpression(node) {
168
- return node.type === 'ArrayExpression';
169
- }
170
- function isObjectExpression(node) {
171
- return node.type === 'ObjectExpression';
172
- }
173
- function isProperty$1(node) {
174
- return node.type === 'Property';
175
- }
176
- function isArrowFunctionExpression(node) {
177
- return node.type === 'ArrowFunctionExpression';
178
- }
179
- function isObjectPattern(node) {
180
- return node.type === 'ObjectPattern';
181
- }
182
- function isArrayPattern(node) {
183
- return node.type === 'ArrayPattern';
184
- }
185
- function isRestElement(node) {
186
- return node.type === 'RestElement';
187
- }
188
- function isAssignmentPattern(node) {
189
- return node.type === 'AssigmentPattern';
190
- }
191
- function isUnaryExpression(node) {
192
- return node.type === 'UnaryExpression';
193
- }
194
- function identifier(name, config) {
195
- return Object.assign({ type: 'Identifier', name }, config);
196
- }
197
- function isLiteral(node) {
198
- return node.type === 'Literal';
199
- }
200
- function memberExpression(object, property, config) {
201
- return Object.assign({ type: 'MemberExpression', object,
202
- property, computed: false, optional: false }, config);
203
- }
204
- function callExpression(callee, args, config) {
205
- return Object.assign({ type: 'CallExpression', callee, arguments: args, optional: false }, config);
206
- }
207
- function literal$1(value, config) {
208
- return Object.assign({ type: 'Literal', value }, config);
209
- }
210
- function conditionalExpression(test, consequent, alternate, config) {
211
- return Object.assign({ type: 'ConditionalExpression', test,
212
- consequent,
213
- alternate }, config);
214
- }
215
- function unaryExpression(operator, argument, config) {
216
- return Object.assign({ type: 'UnaryExpression', argument,
217
- operator, prefix: true }, config);
218
- }
219
- function binaryExpression(operator, left, right, config) {
220
- return Object.assign({ type: 'BinaryExpression', left,
221
- operator,
222
- right }, config);
223
- }
224
- function logicalExpression(operator, left, right, config) {
225
- return Object.assign({ type: 'LogicalExpression', operator,
226
- left,
227
- right }, config);
228
- }
229
- function assignmentExpression(operator, left, right, config) {
230
- return Object.assign({ type: 'AssignmentExpression', operator,
231
- left,
232
- right }, config);
233
- }
234
- function property$1(key, value, config) {
235
- return Object.assign({ type: 'Property', key,
236
- value, kind: 'init', computed: false, method: false, shorthand: false }, config);
237
- }
238
- function spreadElement(argument) {
239
- return {
240
- type: 'SpreadElement',
241
- argument,
242
- };
243
- }
244
- function assignmentProperty(key, value, config) {
245
- return Object.assign({ type: 'Property', key,
246
- value, kind: 'init', computed: false, method: false, shorthand: false }, config);
247
- }
248
- function objectExpression(properties, config) {
249
- return Object.assign({ type: 'ObjectExpression', properties }, config);
250
- }
251
- function objectPattern(properties, config) {
252
- return Object.assign({ type: 'ObjectPattern', properties }, config);
253
- }
254
- function arrayExpression(elements, config) {
255
- return Object.assign({ type: 'ArrayExpression', elements }, config);
256
- }
257
- function expressionStatement(expression, config) {
258
- return Object.assign({ type: 'ExpressionStatement', expression }, config);
259
- }
260
- function taggedTemplateExpression(tag, quasi) {
261
- return {
262
- type: 'TaggedTemplateExpression',
263
- tag,
264
- quasi,
265
- };
266
- }
267
- function templateLiteral(quasis, expressions) {
268
- return {
269
- type: 'TemplateLiteral',
270
- quasis,
271
- expressions,
272
- };
273
- }
274
- function functionExpression(id, params, body, config) {
275
- return Object.assign({ type: 'FunctionExpression', id,
276
- params,
277
- body }, config);
278
- }
279
- function functionDeclaration(id, params, body, config) {
280
- return Object.assign({ type: 'FunctionDeclaration', id,
281
- params,
282
- body }, config);
283
- }
284
- function blockStatement(body, config) {
285
- return Object.assign({ type: 'BlockStatement', body }, config);
286
- }
287
- function returnStatement(argument, config) {
288
- return Object.assign({ type: 'ReturnStatement', argument }, config);
289
- }
290
- function variableDeclarator(id, init, config) {
291
- return Object.assign({ type: 'VariableDeclarator', id,
292
- init }, config);
293
- }
294
- function variableDeclaration(kind, declarations, config) {
295
- return Object.assign({ type: 'VariableDeclaration', kind,
296
- declarations }, config);
297
- }
298
- function importDeclaration(specifiers, source, config) {
299
- return Object.assign({ type: 'ImportDeclaration', specifiers,
300
- source }, config);
301
- }
302
- function importDefaultSpecifier(local, config) {
303
- return Object.assign({ type: 'ImportDefaultSpecifier', local }, config);
304
- }
305
- function importSpecifier(imported, local, config) {
306
- return Object.assign({ type: 'ImportSpecifier', imported,
307
- local }, config);
308
- }
309
- function exportDefaultDeclaration(declaration, config) {
310
- return Object.assign({ type: 'ExportDefaultDeclaration', declaration }, config);
311
- }
312
- function program(body, config) {
313
- return Object.assign({ type: 'Program', sourceType: 'module', body }, config);
314
- }
315
- function comment$1(content) {
316
- return {
317
- type: 'Block',
318
- value: content,
319
- };
320
- }
321
-
322
161
  const UNDEFINED_CODE_POINTS = new Set([
323
162
  65534, 65535, 131070, 131071, 196606, 196607, 262142, 262143, 327678, 327679, 393214,
324
163
  393215, 458750, 458751, 524286, 524287, 589822, 589823, 655358, 655359, 720894,
@@ -8722,26 +8561,189 @@ function parseFragment$1(fragmentContext, html, options) {
8722
8561
  return parser.getFragment();
8723
8562
  }
8724
8563
 
8725
- /*
8726
- * Copyright (c) 2023, salesforce.com, inc.
8727
- * All rights reserved.
8728
- * SPDX-License-Identifier: MIT
8729
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8564
+ ({
8565
+ HTML: NS.HTML,
8566
+ XML: NS.XML,
8567
+ MATHML: NS.MATHML,
8568
+ SVG: NS.SVG,
8569
+ XLINK: NS.XLINK,
8570
+ XMLNS: NS.XMLNS
8571
+ });
8572
+
8573
+ /**
8574
+ * Determines if a given node is a template node or not
8575
+ * @param {Node} node Node to test
8576
+ * @return {boolean}
8730
8577
  */
8731
- function isElementNode(node) {
8732
- return node !== null && 'tagName' in node;
8578
+ function isTemplateNode(node) {
8579
+ return node.nodeName === 'template';
8733
8580
  }
8734
- function isCommentNode(node) {
8735
- return node.nodeName === '#comment';
8581
+ const isElementNode = defaultTreeAdapter.isElementNode;
8582
+ const isCommentNode = defaultTreeAdapter.isCommentNode;
8583
+ defaultTreeAdapter.isDocumentTypeNode;
8584
+ const isTextNode$1 = defaultTreeAdapter.isTextNode;
8585
+
8586
+ defaultTreeAdapter.appendChild;
8587
+
8588
+ function isIdentifier(node) {
8589
+ return node.type === 'Identifier';
8736
8590
  }
8737
- function isTextNode$1(node) {
8738
- return node.nodeName === '#text';
8591
+ function isMemberExpression(node) {
8592
+ return node.type === 'MemberExpression';
8739
8593
  }
8740
- function isTemplateNode(node) {
8741
- return isElementNode(node) && node.tagName === 'template';
8594
+ function isArrayExpression(node) {
8595
+ return node.type === 'ArrayExpression';
8596
+ }
8597
+ function isObjectExpression(node) {
8598
+ return node.type === 'ObjectExpression';
8599
+ }
8600
+ function isProperty$1(node) {
8601
+ return node.type === 'Property';
8602
+ }
8603
+ function isArrowFunctionExpression(node) {
8604
+ return node.type === 'ArrowFunctionExpression';
8605
+ }
8606
+ function isObjectPattern(node) {
8607
+ return node.type === 'ObjectPattern';
8608
+ }
8609
+ function isArrayPattern(node) {
8610
+ return node.type === 'ArrayPattern';
8611
+ }
8612
+ function isRestElement(node) {
8613
+ return node.type === 'RestElement';
8614
+ }
8615
+ function isAssignmentPattern(node) {
8616
+ return node.type === 'AssigmentPattern';
8617
+ }
8618
+ function isUnaryExpression(node) {
8619
+ return node.type === 'UnaryExpression';
8620
+ }
8621
+ function identifier(name, config) {
8622
+ return Object.assign({ type: 'Identifier', name }, config);
8623
+ }
8624
+ function isLiteral(node) {
8625
+ return node.type === 'Literal';
8626
+ }
8627
+ function memberExpression(object, property, config) {
8628
+ return Object.assign({ type: 'MemberExpression', object,
8629
+ property, computed: false, optional: false }, config);
8630
+ }
8631
+ function callExpression(callee, args, config) {
8632
+ return Object.assign({ type: 'CallExpression', callee, arguments: args, optional: false }, config);
8633
+ }
8634
+ function literal$1(value, config) {
8635
+ return Object.assign({ type: 'Literal', value }, config);
8636
+ }
8637
+ function conditionalExpression(test, consequent, alternate, config) {
8638
+ return Object.assign({ type: 'ConditionalExpression', test,
8639
+ consequent,
8640
+ alternate }, config);
8641
+ }
8642
+ function unaryExpression(operator, argument, config) {
8643
+ return Object.assign({ type: 'UnaryExpression', argument,
8644
+ operator, prefix: true }, config);
8645
+ }
8646
+ function binaryExpression(operator, left, right, config) {
8647
+ return Object.assign({ type: 'BinaryExpression', left,
8648
+ operator,
8649
+ right }, config);
8650
+ }
8651
+ function logicalExpression(operator, left, right, config) {
8652
+ return Object.assign({ type: 'LogicalExpression', operator,
8653
+ left,
8654
+ right }, config);
8655
+ }
8656
+ function assignmentExpression(operator, left, right, config) {
8657
+ return Object.assign({ type: 'AssignmentExpression', operator,
8658
+ left,
8659
+ right }, config);
8660
+ }
8661
+ function property$1(key, value, config) {
8662
+ return Object.assign({ type: 'Property', key,
8663
+ value, kind: 'init', computed: false, method: false, shorthand: false }, config);
8664
+ }
8665
+ function spreadElement(argument) {
8666
+ return {
8667
+ type: 'SpreadElement',
8668
+ argument,
8669
+ };
8670
+ }
8671
+ function assignmentProperty(key, value, config) {
8672
+ return Object.assign({ type: 'Property', key,
8673
+ value, kind: 'init', computed: false, method: false, shorthand: false }, config);
8674
+ }
8675
+ function objectExpression(properties, config) {
8676
+ return Object.assign({ type: 'ObjectExpression', properties }, config);
8677
+ }
8678
+ function objectPattern(properties, config) {
8679
+ return Object.assign({ type: 'ObjectPattern', properties }, config);
8680
+ }
8681
+ function arrayExpression(elements, config) {
8682
+ return Object.assign({ type: 'ArrayExpression', elements }, config);
8683
+ }
8684
+ function expressionStatement(expression, config) {
8685
+ return Object.assign({ type: 'ExpressionStatement', expression }, config);
8686
+ }
8687
+ function taggedTemplateExpression(tag, quasi) {
8688
+ return {
8689
+ type: 'TaggedTemplateExpression',
8690
+ tag,
8691
+ quasi,
8692
+ };
8693
+ }
8694
+ function templateLiteral(quasis, expressions) {
8695
+ return {
8696
+ type: 'TemplateLiteral',
8697
+ quasis,
8698
+ expressions,
8699
+ };
8700
+ }
8701
+ function functionExpression(id, params, body, config) {
8702
+ return Object.assign({ type: 'FunctionExpression', id,
8703
+ params,
8704
+ body }, config);
8705
+ }
8706
+ function functionDeclaration(id, params, body, config) {
8707
+ return Object.assign({ type: 'FunctionDeclaration', id,
8708
+ params,
8709
+ body }, config);
8742
8710
  }
8743
- function getTemplateContent(templateElement) {
8744
- return isTemplateNode(templateElement) ? templateElement.content : undefined;
8711
+ function blockStatement(body, config) {
8712
+ return Object.assign({ type: 'BlockStatement', body }, config);
8713
+ }
8714
+ function returnStatement(argument, config) {
8715
+ return Object.assign({ type: 'ReturnStatement', argument }, config);
8716
+ }
8717
+ function variableDeclarator(id, init, config) {
8718
+ return Object.assign({ type: 'VariableDeclarator', id,
8719
+ init }, config);
8720
+ }
8721
+ function variableDeclaration(kind, declarations, config) {
8722
+ return Object.assign({ type: 'VariableDeclaration', kind,
8723
+ declarations }, config);
8724
+ }
8725
+ function importDeclaration(specifiers, source, config) {
8726
+ return Object.assign({ type: 'ImportDeclaration', specifiers,
8727
+ source }, config);
8728
+ }
8729
+ function importDefaultSpecifier(local, config) {
8730
+ return Object.assign({ type: 'ImportDefaultSpecifier', local }, config);
8731
+ }
8732
+ function importSpecifier(imported, local, config) {
8733
+ return Object.assign({ type: 'ImportSpecifier', imported,
8734
+ local }, config);
8735
+ }
8736
+ function exportDefaultDeclaration(declaration, config) {
8737
+ return Object.assign({ type: 'ExportDefaultDeclaration', declaration }, config);
8738
+ }
8739
+ function program(body, config) {
8740
+ return Object.assign({ type: 'Program', sourceType: 'module', body }, config);
8741
+ }
8742
+ function comment$1(content) {
8743
+ return {
8744
+ type: 'Block',
8745
+ value: content,
8746
+ };
8745
8747
  }
8746
8748
 
8747
8749
  /*
@@ -10630,7 +10632,7 @@ class TemplateHtmlParser extends Parser {
10630
10632
  const textNode = {
10631
10633
  nodeName: '#text',
10632
10634
  value: token.chars,
10633
- sourceCodeLocation: Object.assign({}, token.location),
10635
+ sourceCodeLocation: token.location ? Object.assign({}, token.location) : null,
10634
10636
  parentNode,
10635
10637
  };
10636
10638
  parentNode.childNodes.push(textNode);
@@ -11192,7 +11194,7 @@ function parseElementLocation(ctx, parse5Elm, parse5ParentLocation) {
11192
11194
  // creates a <tbody> element in the middle without location information. In this case, we
11193
11195
  // can safely skip the closing tag validation.
11194
11196
  let current = parse5Elm;
11195
- while (!location && isElementNode(current.parentNode)) {
11197
+ while (!location && current.parentNode && isElementNode(current.parentNode)) {
11196
11198
  current = current.parentNode;
11197
11199
  location = current.sourceCodeLocation;
11198
11200
  }
@@ -11282,7 +11284,14 @@ function parseLwcElementAsBuiltIn(ctx, parse5Elm, _parsedAttr, parse5ElmLocation
11282
11284
  }
11283
11285
  function parseChildren(ctx, parse5Parent, parent, parse5ParentLocation) {
11284
11286
  var _a;
11285
- const children = ((_a = getTemplateContent(parse5Parent)) !== null && _a !== void 0 ? _a : parse5Parent).childNodes;
11287
+ let container = parse5Parent;
11288
+ // `content` isn't nullable but we need to keep the optional chaining
11289
+ // until parse5/tools also asserts that `content` is set. It should be
11290
+ // impossible to have nullish `content`, but templates in SVG can cause it
11291
+ if (isTemplateNode(parse5Parent) && ((_a = parse5Parent.content) === null || _a === void 0 ? void 0 : _a.childNodes.length) > 0) {
11292
+ container = parse5Parent.content;
11293
+ }
11294
+ const children = container.childNodes;
11286
11295
  ctx.beginSiblingScope();
11287
11296
  for (const child of children) {
11288
11297
  ctx.withErrorRecovery(() => {
@@ -11377,11 +11386,12 @@ function parseComment(parse5Comment) {
11377
11386
  return comment(parse5Comment.data, decodeTextContent(parse5Comment.data), location);
11378
11387
  }
11379
11388
  function getTemplateRoot(ctx, documentFragment) {
11389
+ var _a;
11380
11390
  // Filter all the empty text nodes
11381
11391
  const validRoots = documentFragment.childNodes.filter((child) => isElementNode(child) ||
11382
11392
  (isTextNode$1(child) && child.value.trim().length));
11383
11393
  if (validRoots.length > 1) {
11384
- const duplicateRoot = validRoots[1].sourceCodeLocation;
11394
+ const duplicateRoot = (_a = validRoots[1].sourceCodeLocation) !== null && _a !== void 0 ? _a : undefined;
11385
11395
  ctx.throw(ParserDiagnostics.MULTIPLE_ROOTS_FOUND, [], duplicateRoot ? sourceLocation(duplicateRoot) : duplicateRoot !== null && duplicateRoot !== void 0 ? duplicateRoot : undefined);
11386
11396
  }
11387
11397
  const [root] = validRoots;
@@ -13795,5 +13805,5 @@ function compile(source, config) {
13795
13805
  }
13796
13806
 
13797
13807
  export { ElementDirectiveName, LWCDirectiveDomMode, LWCDirectiveRenderMode, LwcTagName, RootDirectiveName, TemplateDirectiveName, compile, compile as default, parse };
13798
- /** version: 3.7.0 */
13808
+ /** version: 3.7.2 */
13799
13809
  //# sourceMappingURL=index.js.map