@lwc/ssr-compiler 8.2.0 → 8.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/index.js CHANGED
@@ -7,22 +7,11 @@ import { parseModule } from 'meriyah';
7
7
  import { AriaPropNameToAttrNameMap, reservedKeywords, normalizeStyleAttribute, isVoidElement, HTML_NAMESPACE, StringReplace, StringTrim } from '@lwc/shared';
8
8
  import { parse } from 'acorn';
9
9
  import { produce } from 'immer';
10
+ import { basename } from 'node:path';
10
11
  import { generateScopeTokens, toPropertyName, kebabcaseToCamelcase, parse as parse$1 } from '@lwc/template-compiler';
11
12
  import { builders as builders$1 } from 'estree-toolkit/dist/builders';
12
13
  import { inspect } from 'util';
13
14
 
14
- /*
15
- * Copyright (c) 2024, Salesforce, Inc.
16
- * All rights reserved.
17
- * SPDX-License-Identifier: MIT
18
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
19
- */
20
- /**
21
- * Imports from `lwc` that are allowed in the SSR runtime context.
22
- * Every listed item should be a top-level export from `@lwc/ssr-runtime`.
23
- */
24
- const allowedLwcImports = new Set(['LightningElement']);
25
-
26
15
  /*
27
16
  * Copyright (c) 2024, salesforce.com, inc.
28
17
  * All rights reserved.
@@ -46,14 +35,6 @@ function replaceLwcImport(path, state) {
46
35
  state.lightningElementIdentifier = specifier.local.name;
47
36
  break;
48
37
  }
49
- if (specifier.type === 'ImportSpecifier' && specifier.imported.type === 'Identifier') {
50
- if (!allowedLwcImports.has(specifier.imported.name)) {
51
- throw new Error(`Cannot import "${specifier.imported.name}" in SSR context.`);
52
- }
53
- if (specifier.imported.name === 'LightningElement') {
54
- state.lightningElementIdentifier = specifier.local.name;
55
- }
56
- }
57
38
  }
58
39
  path.replaceWith(builders.importDeclaration(path.node.specifiers, builders.literal('@lwc/ssr-runtime')));
59
40
  }
@@ -90,19 +71,29 @@ function catalogTmplImport(path, state) {
90
71
  * SPDX-License-Identifier: MIT
91
72
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
92
73
  */
74
+ /** Placeholder value to use to opt out of validation. */
75
+ const NO_VALIDATION = false;
93
76
  const PLACEHOLDER_PREFIX = `__ESTEMPLATE_${Math.random().toString().slice(2)}_PLACEHOLDER__`;
77
+ const getReplacementNode = (state, placeholderId, nodeType) => {
78
+ const key = Number(placeholderId.slice(PLACEHOLDER_PREFIX.length));
79
+ const nodeCount = state.replacementNodes.length;
80
+ if (key >= nodeCount) {
81
+ throw new Error(`Cannot use index ${key} when only ${nodeCount} values have been provided.`);
82
+ }
83
+ const validateReplacement = state.placeholderToValidator.get(key);
84
+ const replacementNode = state.replacementNodes[key];
85
+ if (validateReplacement &&
86
+ !(Array.isArray(replacementNode)
87
+ ? replacementNode.every(validateReplacement)
88
+ : validateReplacement(replacementNode))) {
89
+ throw new Error(`Validation failed for templated node of type ${nodeType}`);
90
+ }
91
+ return replacementNode;
92
+ };
94
93
  const visitors$1 = {
95
94
  Identifier(path, state) {
96
95
  if (path.node?.name.startsWith(PLACEHOLDER_PREFIX)) {
97
- const key = path.node.name.slice(PLACEHOLDER_PREFIX.length);
98
- const validateReplacement = state.placeholderToValidator.get(key);
99
- const replacementNode = state.replacementNodes[key];
100
- if (validateReplacement &&
101
- !(Array.isArray(replacementNode)
102
- ? replacementNode.every(validateReplacement)
103
- : validateReplacement(replacementNode))) {
104
- throw new Error(`Validation failed for templated node of type ${path.node.type}`);
105
- }
96
+ const replacementNode = getReplacementNode(state, path.node.name, path.node.type);
106
97
  if (replacementNode === null) {
107
98
  path.remove();
108
99
  }
@@ -111,7 +102,7 @@ const visitors$1 = {
111
102
  path.remove();
112
103
  }
113
104
  else {
114
- if (path.parentPath.node.type === 'ExpressionStatement') {
105
+ if (path.parentPath?.node?.type === 'ExpressionStatement') {
115
106
  path.parentPath.replaceWithMultiple(replacementNode);
116
107
  }
117
108
  else {
@@ -127,27 +118,34 @@ const visitors$1 = {
127
118
  Literal(path, state) {
128
119
  if (typeof path.node?.value === 'string' &&
129
120
  path.node.value.startsWith(PLACEHOLDER_PREFIX)) {
130
- const key = path.node.value.slice(PLACEHOLDER_PREFIX.length);
131
- const validateReplacement = state.placeholderToValidator.get(key);
132
- const replacementNode = state.replacementNodes[key];
133
- if (validateReplacement && !validateReplacement(replacementNode)) {
134
- throw new Error(`Validation failed for templated node of type ${path.node.type}`);
135
- }
121
+ // A literal can only be replaced with a single node
122
+ const replacementNode = getReplacementNode(state, path.node.value, path.node.type);
136
123
  path.replaceWith(replacementNode);
137
124
  }
138
125
  },
139
126
  };
140
- function esTemplateImpl(javascriptSegments, validatorFns, wrap, unwrap) {
127
+ function esTemplateImpl(javascriptSegments, validators, wrap, unwrap) {
141
128
  let placeholderCount = 0;
142
129
  let parsableCode = javascriptSegments[0];
143
- validatorFns.reverse();
144
130
  const placeholderToValidator = new Map();
145
- for (const segment of javascriptSegments.slice(1)) {
146
- const validatorFn = validatorFns.pop();
147
- if (validatorFn) {
148
- placeholderToValidator.set(placeholderCount.toString(), validatorFn);
131
+ for (let i = 1; i < javascriptSegments.length; i += 1) {
132
+ const segment = javascriptSegments[i];
133
+ const validator = validators[i - 1]; // always one less value than strings in template literals
134
+ if (typeof validator === 'function' || validator === NO_VALIDATION) {
135
+ // Template slot will be filled by a *new* argument passed to the generated function
136
+ if (validator !== NO_VALIDATION) {
137
+ placeholderToValidator.set(placeholderCount, validator);
138
+ }
139
+ parsableCode += `${PLACEHOLDER_PREFIX}${placeholderCount}`;
140
+ placeholderCount += 1;
141
+ }
142
+ else {
143
+ // Template slot uses a *previously defined* argument passed to the generated function
144
+ if (validator >= placeholderCount) {
145
+ throw new Error(`Reference to argument ${validator} at index ${i} cannot be used. Only ${placeholderCount - 1} arguments have been defined.`);
146
+ }
147
+ parsableCode += `${PLACEHOLDER_PREFIX}${validator}`;
149
148
  }
150
- parsableCode += `${PLACEHOLDER_PREFIX}${placeholderCount++}`;
151
149
  parsableCode += segment;
152
150
  }
153
151
  if (wrap) {
@@ -179,16 +177,30 @@ function esTemplateImpl(javascriptSegments, validatorFns, wrap, unwrap) {
179
177
  placeholderToValidator,
180
178
  replacementNodes,
181
179
  }));
182
- return unwrap ? unwrap(result) : result;
180
+ return (unwrap ? unwrap(result) : result);
183
181
  };
184
182
  }
185
- function esTemplate(javascriptSegments, ...validatorFns) {
186
- return esTemplateImpl(javascriptSegments, validatorFns);
183
+ /**
184
+ * Template literal tag that generates a builder function. Like estree's `builders`, but for more
185
+ * complex structures. The template values should be estree `is` validators or a back reference to
186
+ * a previous slot (to re-use the referenced value).
187
+ *
188
+ * To have the generated function return a particular node type, the generic comes _after_ the
189
+ * template literal. Kinda weird, but it's necessary to infer the types of the template values.
190
+ * (If it were at the start, we'd need to explicitly provide _all_ type params. Tedious!)
191
+ * @example
192
+ * const bSum = esTemplate`(${is.identifier}, ${is.identifier}) => ${0} + ${1}`<EsArrowFunctionExpression>
193
+ * const sumFuncNode = bSum(b.identifier('a'), b.identifier('b'))
194
+ * // `sumFuncNode` is an AST node representing `(a, b) => a + b`
195
+ */
196
+ function esTemplate(javascriptSegments, ...Validators) {
197
+ return esTemplateImpl(javascriptSegments, Validators);
187
198
  }
188
- function esTemplateWithYield(javascriptSegments, ...validatorFns) {
199
+ /** Similar to {@linkcode esTemplate}, but supports `yield` expressions. */
200
+ function esTemplateWithYield(javascriptSegments, ...validators) {
189
201
  const wrap = (code) => `function* placeholder() {${code}}`;
190
202
  const unwrap = (node) => node.body.body.length === 1 ? node.body.body[0] : node.body.body;
191
- return esTemplateImpl(javascriptSegments, validatorFns, wrap, unwrap);
203
+ return esTemplateImpl(javascriptSegments, validators, wrap, unwrap);
192
204
  }
193
205
 
194
206
  /*
@@ -197,12 +209,12 @@ function esTemplateWithYield(javascriptSegments, ...validatorFns) {
197
209
  * SPDX-License-Identifier: MIT
198
210
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
199
211
  */
200
- const bDefaultStyleImport = esTemplate `
212
+ const bDefaultStyleImport = (esTemplate `
201
213
  import defaultStylesheets from '${is.literal}';
202
- `;
203
- const bDefaultScopedStyleImport = esTemplate `
214
+ `);
215
+ const bDefaultScopedStyleImport = (esTemplate `
204
216
  import defaultScopedStylesheets from '${is.literal}';
205
- `;
217
+ `);
206
218
  function catalogStyleImport(path, state) {
207
219
  const specifier = path.node.specifiers[0];
208
220
  if (typeof path.node.source.value !== 'string' ||
@@ -240,14 +252,20 @@ function catalogStaticStylesheets(ids, state) {
240
252
  * SPDX-License-Identifier: MIT
241
253
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
242
254
  */
243
- const isStringLiteral = (node) => is.literal(node) && typeof node.value === 'string';
244
- const isIdentOrRenderCall = (node) => is.identifier(node) ||
245
- (is.callExpression(node) &&
246
- is.memberExpression(node.callee) &&
247
- is.identifier(node.callee.property) &&
248
- node.callee.property.name === 'render');
255
+ const isStringLiteral = (node) => {
256
+ return is.literal(node) && typeof node.value === 'string';
257
+ };
258
+ /** Returns `true` if the node is an identifier or `<something>.render()`. */
259
+ const isIdentOrRenderCall = (node) => {
260
+ return (is.identifier(node) ||
261
+ (is.callExpression(node) &&
262
+ is.memberExpression(node.callee) &&
263
+ is.identifier(node.callee.property) &&
264
+ node.callee.property.name === 'render'));
265
+ };
266
+ /** Extends a validator to return `true` if the node is `null`. */
249
267
  function isNullableOf(validator) {
250
- return (node) => node === null || (validator && validator(node));
268
+ return (node) => node === null || validator(node);
251
269
  }
252
270
 
253
271
  /*
@@ -256,9 +274,9 @@ function isNullableOf(validator) {
256
274
  * SPDX-License-Identifier: MIT
257
275
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
258
276
  */
259
- const bImportDeclaration = esTemplate `
277
+ const bImportDeclaration = (esTemplate `
260
278
  import ${is.identifier} from "${isStringLiteral}";
261
- `;
279
+ `);
262
280
 
263
281
  /*
264
282
  * Copyright (c) 2024, salesforce.com, inc.
@@ -266,31 +284,40 @@ const bImportDeclaration = esTemplate `
266
284
  * SPDX-License-Identifier: MIT
267
285
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
268
286
  */
269
- const bGenerateMarkup = esTemplate `
287
+ const bGenerateMarkup = (esTemplate `
270
288
  export async function* generateMarkup(tagName, props, attrs, slotted) {
271
289
  attrs = attrs ?? {};
272
290
  ${isNullableOf(is.expressionStatement)};
273
291
  const instance = new ${is.identifier}({
274
292
  tagName: tagName.toUpperCase(),
275
293
  });
276
- instance.__internal__setState(props, __REFLECTED_PROPS__, attrs);
294
+ instance[__SYMBOL__SET_INTERNALS](props, __REFLECTED_PROPS__, attrs);
277
295
  instance.isConnected = true;
278
- instance.connectedCallback?.();
296
+ if (instance.connectedCallback) {
297
+ __mutationTracker.enable(instance);
298
+ instance.connectedCallback();
299
+ __mutationTracker.disable(instance);
300
+ }
279
301
  const tmplFn = ${isIdentOrRenderCall} ?? __fallbackTmpl;
280
302
  yield \`<\${tagName}\`;
281
303
  yield tmplFn.stylesheetScopeTokenHostClass ?? '';
282
- yield *__renderAttrs(instance, attrs)
304
+ yield* __renderAttrs(instance, attrs)
283
305
  yield '>';
284
- yield* tmplFn(props, attrs, slotted, ${is.identifier}, instance);
306
+ yield* tmplFn(props, attrs, slotted, ${1}, instance);
285
307
  yield \`</\${tagName}>\`;
286
308
  }
287
- `;
288
- const bInsertFallbackTmplImport = esTemplate `
289
- import { fallbackTmpl as __fallbackTmpl, renderAttrs as __renderAttrs } from '@lwc/ssr-runtime';
290
- `;
291
- const bCreateReflectedPropArr = esTemplate `
309
+ `);
310
+ const bInsertFallbackTmplImport = (esTemplate `
311
+ import {
312
+ fallbackTmpl as __fallbackTmpl,
313
+ mutationTracker as __mutationTracker,
314
+ renderAttrs as __renderAttrs,
315
+ SYMBOL__SET_INTERNALS as __SYMBOL__SET_INTERNALS,
316
+ } from '@lwc/ssr-runtime';
317
+ `);
318
+ const bCreateReflectedPropArr = (esTemplate `
292
319
  const __REFLECTED_PROPS__ = ${is.arrayExpression};
293
- `;
320
+ `);
294
321
  function bReflectedAttrsObj(reflectedPropNames) {
295
322
  // This will build getter properties for each reflected property. It'll look
296
323
  // something like this:
@@ -341,7 +368,7 @@ function addGenerateMarkupExport(program, state, filename) {
341
368
  ? builders.callExpression(builders.memberExpression(builders.identifier('instance'), builders.identifier('render')), [])
342
369
  : builders.identifier('tmpl');
343
370
  if (!tmplExplicitImports) {
344
- const defaultTmplPath = filename.replace(/\.js$/, '.html');
371
+ const defaultTmplPath = `./${basename(filename, 'js')}html`;
345
372
  program.body.unshift(bImportDeclaration(builders.identifier('tmpl'), builders.literal(defaultTmplPath)));
346
373
  }
347
374
  let attrsAugmentation = null;
@@ -351,7 +378,7 @@ function addGenerateMarkupExport(program, state, filename) {
351
378
  const reflectedPropArr = builders.arrayExpression([...state.reflectedPropsInPlay].map((propName) => builders.literal(propName)));
352
379
  program.body.unshift(bInsertFallbackTmplImport());
353
380
  program.body.push(bCreateReflectedPropArr(reflectedPropArr));
354
- program.body.push(bGenerateMarkup(attrsAugmentation, classIdentifier, renderCall, classIdentifier));
381
+ program.body.push(bGenerateMarkup(attrsAugmentation, classIdentifier, renderCall));
355
382
  }
356
383
 
357
384
  /*
@@ -481,33 +508,1199 @@ function compileJS(src, filename) {
481
508
  };
482
509
  }
483
510
 
511
+ /**
512
+ * Copyright (c) 2024 Salesforce, Inc.
513
+ */
514
+ /*
515
+ * Copyright (c) 2024, Salesforce, Inc.
516
+ * All rights reserved.
517
+ * SPDX-License-Identifier: MIT
518
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
519
+ */
520
+
521
+ /*
522
+ * Copyright (c) 2018, salesforce.com, inc.
523
+ * All rights reserved.
524
+ * SPDX-License-Identifier: MIT
525
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
526
+ */
527
+ var DiagnosticLevel;
528
+ (function (DiagnosticLevel) {
529
+ /** Unexpected error, parsing error, bundling error */
530
+ DiagnosticLevel[DiagnosticLevel["Fatal"] = 0] = "Fatal";
531
+ /** Linting error with error level, invalid external reference, invalid import, invalid transform */
532
+ DiagnosticLevel[DiagnosticLevel["Error"] = 1] = "Error";
533
+ /** Linting error with warning level, usage of an API to be deprecated */
534
+ DiagnosticLevel[DiagnosticLevel["Warning"] = 2] = "Warning";
535
+ /** Logging messages */
536
+ DiagnosticLevel[DiagnosticLevel["Log"] = 3] = "Log";
537
+ })(DiagnosticLevel || (DiagnosticLevel = {}));
538
+
484
539
  /*
485
540
  * Copyright (c) 2024, Salesforce, Inc.
486
541
  * All rights reserved.
487
542
  * SPDX-License-Identifier: MIT
488
543
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
489
544
  */
490
- const bStylesheetTokenDeclaration = esTemplate `
545
+ /*
546
+ * For the next available error code, reference (and update!) the value in ./index.ts
547
+ */
548
+ ({
549
+ code: 1001,
550
+ message: 'Unexpected compilation error: {0}',
551
+ level: DiagnosticLevel.Error,
552
+ url: '',
553
+ });
554
+ ({
555
+ INVALID_COMPAT_PROPERTY: {
556
+ code: 1013,
557
+ message: 'Expected a boolean for outputConfig.compat, received "{0}".',
558
+ level: DiagnosticLevel.Error,
559
+ url: '',
560
+ },
561
+ INVALID_ENV_ENTRY_VALUE: {
562
+ code: 1014,
563
+ message: 'Expected a string for outputConfig.env["{0}"], received "{1}".',
564
+ level: DiagnosticLevel.Error,
565
+ url: '',
566
+ },
567
+ INVALID_ENV_PROPERTY: {
568
+ code: 1015,
569
+ message: 'Expected an object for outputConfig.env, received "{0}".',
570
+ level: DiagnosticLevel.Error,
571
+ url: '',
572
+ },
573
+ INVALID_FILES_PROPERTY: {
574
+ code: 1016,
575
+ message: 'Expected an object with files to be compiled.',
576
+ level: DiagnosticLevel.Error,
577
+ url: '',
578
+ },
579
+ INVALID_NAME_PROPERTY: {
580
+ code: 1018,
581
+ message: 'Expected a string for name, received "{0}".',
582
+ level: DiagnosticLevel.Error,
583
+ url: '',
584
+ },
585
+ INVALID_NAMESPACE_PROPERTY: {
586
+ code: 1019,
587
+ message: 'Expected a string for namespace, received "{0}".',
588
+ level: DiagnosticLevel.Error,
589
+ url: '',
590
+ },
591
+ INVALID_SOURCEMAP_PROPERTY: {
592
+ code: 1021,
593
+ message: 'Expected a boolean value or \'inline\' for outputConfig.sourcemap, received "{0}".',
594
+ level: DiagnosticLevel.Error,
595
+ url: '',
596
+ },
597
+ MISSING_OPTIONS_OBJECT: {
598
+ code: 1023,
599
+ message: 'Expected options object, received "{0}".',
600
+ level: DiagnosticLevel.Error,
601
+ url: '',
602
+ },
603
+ UNEXPECTED_FILE_CONTENT: {
604
+ code: 1024,
605
+ message: 'Unexpected file content for "{0}". Expected a string, received "{1}".',
606
+ level: DiagnosticLevel.Error,
607
+ url: '',
608
+ },
609
+ UNKNOWN_ENV_ENTRY_KEY: {
610
+ code: 1025,
611
+ message: 'Unknown entry "{0}" in outputConfig.env.',
612
+ level: DiagnosticLevel.Error,
613
+ url: '',
614
+ },
615
+ });
616
+ ({
617
+ MODULE_RESOLUTION_ERROR: {
618
+ code: 1002,
619
+ message: 'Error in module resolution: {0}',
620
+ level: DiagnosticLevel.Warning,
621
+ url: '',
622
+ },
623
+ IMPORTEE_RESOLUTION_FAILED: {
624
+ code: 1010,
625
+ message: 'Failed to resolve entry for module "{0}".',
626
+ level: DiagnosticLevel.Error,
627
+ url: '',
628
+ },
629
+ IMPORTEE_RESOLUTION_FROM_IMPORTER_FAILED: {
630
+ code: 1011,
631
+ message: 'Failed to resolve import "{0}" from "{1}". Please add "{2}" file to the component folder.',
632
+ level: DiagnosticLevel.Error,
633
+ url: '',
634
+ },
635
+ NONEXISTENT_FILE: {
636
+ code: 1004,
637
+ message: 'No such file {0}',
638
+ level: DiagnosticLevel.Error,
639
+ url: '',
640
+ },
641
+ FOLDER_NAME_STARTS_WITH_CAPITAL_LETTER: {
642
+ code: 1116,
643
+ message: 'Illegal folder name "{0}". The folder name must start with a lowercase character: "{1}".',
644
+ level: DiagnosticLevel.Error,
645
+ url: '',
646
+ },
647
+ FOLDER_AND_FILE_NAME_CASE_MISMATCH: {
648
+ code: 1117,
649
+ message: 'Failed to resolve "{0}". The file name must case match the component folder name "{1}".',
650
+ level: DiagnosticLevel.Error,
651
+ url: '',
652
+ },
653
+ IMPORT_AND_FILE_NAME_CASE_MISMATCH: {
654
+ code: 1118,
655
+ message: 'Failed to resolve "{0}" from "{1}". Did you mean "{2}"?',
656
+ level: DiagnosticLevel.Error,
657
+ url: '',
658
+ },
659
+ RELATIVE_DYNAMIC_IMPORT: {
660
+ code: 1120,
661
+ message: 'Illegal usage of the dynamic import syntax with a relative path.',
662
+ level: DiagnosticLevel.Error,
663
+ url: '',
664
+ },
665
+ });
666
+ ({
667
+ CSS_TRANSFORMER_ERROR: {
668
+ code: 1009,
669
+ message: '{0}',
670
+ level: DiagnosticLevel.Error,
671
+ url: '',
672
+ },
673
+ CSS_IN_HTML_ERROR: {
674
+ code: 1026,
675
+ message: 'An error occurred parsing inline CSS. {0}',
676
+ level: DiagnosticLevel.Error,
677
+ url: '',
678
+ },
679
+ HTML_TRANSFORMER_ERROR: {
680
+ code: 1008,
681
+ message: '{0}',
682
+ level: DiagnosticLevel.Error,
683
+ url: '',
684
+ },
685
+ INVALID_ID: {
686
+ code: 1027,
687
+ message: 'Expect a string for id. Received {0}',
688
+ level: DiagnosticLevel.Error,
689
+ url: '',
690
+ },
691
+ INVALID_SOURCE: {
692
+ code: 1006,
693
+ message: 'Expect a string for source. Received {0}',
694
+ level: DiagnosticLevel.Error,
695
+ url: '',
696
+ },
697
+ JS_TRANSFORMER_ERROR: {
698
+ code: 1007,
699
+ message: '{0}',
700
+ level: DiagnosticLevel.Error,
701
+ url: '',
702
+ },
703
+ NO_AVAILABLE_TRANSFORMER: {
704
+ code: 1005,
705
+ message: 'No available transformer for "{0}"',
706
+ level: DiagnosticLevel.Error,
707
+ url: '',
708
+ },
709
+ JS_TRANSFORMER_DECORATOR_ERROR: {
710
+ code: 1198,
711
+ message: 'Decorators like @api, @track, and @wire are only supported in LightningElement classes. {0}',
712
+ level: DiagnosticLevel.Error,
713
+ url: '',
714
+ },
715
+ });
716
+
717
+ /*
718
+ * Copyright (c) 2024, Salesforce, Inc.
719
+ * All rights reserved.
720
+ * SPDX-License-Identifier: MIT
721
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
722
+ */
723
+ /*
724
+ * For the next available error code, reference (and update!) the value in ./index.ts
725
+ */
726
+ ({
727
+ INVALID_DYNAMIC_IMPORT_SOURCE_STRICT: {
728
+ code: 1121,
729
+ message: 'Invalid import. The argument "{0}" must be a stringLiteral for dynamic imports when strict mode is enabled.',
730
+ url: '',
731
+ level: DiagnosticLevel.Error,
732
+ },
733
+ });
734
+ ({
735
+ ADAPTER_SHOULD_BE_FIRST_PARAMETER: {
736
+ code: 1092,
737
+ message: '@wire expects an adapter as first parameter. @wire(adapter: WireAdapter, config?: any).',
738
+ level: DiagnosticLevel.Error,
739
+ url: '',
740
+ },
741
+ API_AND_TRACK_DECORATOR_CONFLICT: {
742
+ code: 1093,
743
+ message: '@api method or property cannot be used with @track',
744
+ level: DiagnosticLevel.Error,
745
+ url: '',
746
+ },
747
+ CONFIG_OBJECT_SHOULD_BE_SECOND_PARAMETER: {
748
+ code: 1094,
749
+ message: '@wire expects a configuration object expression as second parameter.',
750
+ level: DiagnosticLevel.Error,
751
+ url: '',
752
+ },
753
+ CONFLICT_WITH_ANOTHER_DECORATOR: {
754
+ code: 1095,
755
+ message: '@wire method or property cannot be used with @{0}',
756
+ level: DiagnosticLevel.Error,
757
+ url: '',
758
+ },
759
+ DUPLICATE_API_PROPERTY: {
760
+ code: 1096,
761
+ message: 'Duplicate @api property "{0}".',
762
+ level: DiagnosticLevel.Error,
763
+ url: '',
764
+ },
765
+ FUNCTION_IDENTIFIER_SHOULD_BE_FIRST_PARAMETER: {
766
+ code: 1097,
767
+ message: '@wire expects a function identifier as first parameter.',
768
+ level: DiagnosticLevel.Error,
769
+ url: '',
770
+ },
771
+ IMPORTED_FUNCTION_IDENTIFIER_SHOULD_BE_FIRST_PARAMETER: {
772
+ code: 1098,
773
+ message: '@wire expects a function identifier to be imported as first parameter.',
774
+ level: DiagnosticLevel.Error,
775
+ url: '',
776
+ },
777
+ INVALID_BOOLEAN_PUBLIC_PROPERTY: {
778
+ code: 1099,
779
+ message: 'Boolean public property must default to false.',
780
+ level: DiagnosticLevel.Error,
781
+ url: '',
782
+ },
783
+ INVALID_DECORATOR: {
784
+ code: 1100,
785
+ message: 'Invalid decorator usage. Supported decorators ({0}) should be imported from "{1}"',
786
+ level: DiagnosticLevel.Error,
787
+ url: '',
788
+ },
789
+ INVALID_DECORATOR_TYPE: {
790
+ code: 1101,
791
+ message: 'Invalid property of field type',
792
+ level: DiagnosticLevel.Error,
793
+ url: '',
794
+ },
795
+ INVALID_DECORATOR_WITH_NAME: {
796
+ code: 1102,
797
+ message: 'Invalid \'{0}\' decorator usage. Supported decorators ({1}) should be imported from "{2}"',
798
+ level: DiagnosticLevel.Error,
799
+ url: '',
800
+ },
801
+ IS_NOT_CLASS_PROPERTY_OR_CLASS_METHOD: {
802
+ code: 1103,
803
+ message: '"@{0}" can only be applied on class properties',
804
+ level: DiagnosticLevel.Error,
805
+ url: '',
806
+ },
807
+ IS_NOT_DECORATOR: {
808
+ code: 1104,
809
+ message: '"{0}" can only be used as a class decorator',
810
+ level: DiagnosticLevel.Error,
811
+ url: '',
812
+ },
813
+ ONE_WIRE_DECORATOR_ALLOWED: {
814
+ code: 1105,
815
+ message: 'Method or property can only have 1 @wire decorator',
816
+ level: DiagnosticLevel.Error,
817
+ url: '',
818
+ },
819
+ PROPERTY_CANNOT_BE_COMPUTED: {
820
+ code: 1106,
821
+ message: '@api cannot be applied to a computed property, getter, setter or method.',
822
+ level: DiagnosticLevel.Error,
823
+ url: '',
824
+ },
825
+ PROPERTY_NAME_CANNOT_START_WITH_DATA: {
826
+ code: 1107,
827
+ message: 'Invalid property name "{0}". Properties starting with "data" are reserved attributes.',
828
+ level: DiagnosticLevel.Error,
829
+ url: '',
830
+ },
831
+ PROPERTY_NAME_CANNOT_START_WITH_ON: {
832
+ code: 1108,
833
+ message: 'Invalid property name "{0}". Properties starting with "on" are reserved for event handlers.',
834
+ level: DiagnosticLevel.Error,
835
+ url: '',
836
+ },
837
+ PROPERTY_NAME_IS_AMBIGUOUS: {
838
+ code: 1109,
839
+ message: 'Ambiguous attribute name "{0}". "{0}" will never be called from template because its corresponding property is camel cased. Consider renaming to "{1}".',
840
+ level: DiagnosticLevel.Error,
841
+ url: '',
842
+ },
843
+ PROPERTY_NAME_IS_RESERVED: {
844
+ code: 1110,
845
+ message: 'Invalid property name "{0}". "{0}" is a reserved attribute.',
846
+ level: DiagnosticLevel.Error,
847
+ url: '',
848
+ },
849
+ PROPERTY_NAME_PART_IS_RESERVED: {
850
+ code: 1111,
851
+ message: 'Invalid property name "{0}". "part" is a future reserved attribute for web components.',
852
+ level: DiagnosticLevel.Error,
853
+ url: '',
854
+ },
855
+ SINGLE_DECORATOR_ON_SETTER_GETTER_PAIR: {
856
+ code: 1112,
857
+ message: '@api get {0} and @api set {0} detected in class declaration. Only one of the two needs to be decorated with @api.',
858
+ level: DiagnosticLevel.Error,
859
+ url: '',
860
+ },
861
+ TRACK_ONLY_ALLOWED_ON_CLASS_PROPERTIES: {
862
+ code: 1113,
863
+ message: '@track decorator can only be applied to class properties.',
864
+ level: DiagnosticLevel.Error,
865
+ url: '',
866
+ },
867
+ WIRE_ADAPTER_SHOULD_BE_IMPORTED: {
868
+ code: 1119,
869
+ message: 'Failed to resolve @wire adapter "{0}". Ensure it is imported.',
870
+ level: DiagnosticLevel.Error,
871
+ url: '',
872
+ },
873
+ FUNCTION_IDENTIFIER_CANNOT_HAVE_COMPUTED_PROPS: {
874
+ code: 1131,
875
+ message: '@wire identifier cannot contain computed properties',
876
+ level: DiagnosticLevel.Error,
877
+ url: '',
878
+ },
879
+ FUNCTION_IDENTIFIER_CANNOT_HAVE_NESTED_MEMBER_EXRESSIONS: {
880
+ code: 1132,
881
+ message: '@wire identifier cannot contain nested member expressions',
882
+ level: DiagnosticLevel.Error,
883
+ url: '',
884
+ },
885
+ COMPUTED_PROPERTY_CANNOT_BE_TEMPLATE_LITERAL: {
886
+ code: 1199,
887
+ message: 'Cannot use a template literal as a computed property key. Instead, use a string or extract the value to a constant.',
888
+ level: DiagnosticLevel.Error,
889
+ url: '',
890
+ },
891
+ COMPUTED_PROPERTY_MUST_BE_CONSTANT_OR_LITERAL: {
892
+ code: 1200,
893
+ message: 'Computed property in @wire config must be a constant or primitive literal.',
894
+ level: DiagnosticLevel.Error,
895
+ url: '',
896
+ },
897
+ });
898
+
899
+ /*
900
+ * Copyright (c) 2024, Salesforce, Inc.
901
+ * All rights reserved.
902
+ * SPDX-License-Identifier: MIT
903
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
904
+ */
905
+ /*
906
+ * For the next available error code, reference (and update!) the value in ./index.ts
907
+ */
908
+ ({
909
+ INVALID_TEMPLATE: {
910
+ code: 1003,
911
+ message: 'Invalid template',
912
+ level: DiagnosticLevel.Error,
913
+ url: '',
914
+ },
915
+ OPTIONS_MUST_BE_OBJECT: {
916
+ code: 1028,
917
+ message: 'Compiler options must be an object',
918
+ level: DiagnosticLevel.Error,
919
+ url: '',
920
+ },
921
+ UNKNOWN_IF_MODIFIER: {
922
+ code: 1029,
923
+ message: 'Unknown if modifier {0}',
924
+ level: DiagnosticLevel.Error,
925
+ url: '',
926
+ },
927
+ UNKNOWN_OPTION_PROPERTY: {
928
+ code: 1030,
929
+ message: 'Unknown option property {0}',
930
+ level: DiagnosticLevel.Error,
931
+ url: '',
932
+ },
933
+ DUPLICATE_ELEMENT_ENTRY: {
934
+ code: 1150,
935
+ message: 'customRendererConfig contains duplicate entry for {0} element tag',
936
+ level: DiagnosticLevel.Error,
937
+ url: '',
938
+ },
939
+ CUSTOM_ELEMENT_TAG_DISALLOWED: {
940
+ code: 1151,
941
+ message: 'customRendererConfig should not contain a custom element tag, but found {0}',
942
+ level: DiagnosticLevel.Error,
943
+ url: '',
944
+ },
945
+ });
946
+ ({
947
+ AMBIGUOUS_ATTRIBUTE_VALUE: {
948
+ code: 1034,
949
+ message: 'Ambiguous attribute value {0}. ' +
950
+ 'If you want to make it a valid identifier you should remove the surrounding quotes {1}. ' +
951
+ 'If you want to make it a string you should escape it {2}.',
952
+ level: DiagnosticLevel.Error,
953
+ url: '',
954
+ },
955
+ AMBIGUOUS_ATTRIBUTE_VALUE_STRING: {
956
+ code: 1035,
957
+ message: 'Ambiguous attribute value {0}. If you want to make it a string you should escape it {1}',
958
+ level: DiagnosticLevel.Error,
959
+ url: '',
960
+ },
961
+ BOOLEAN_ATTRIBUTE_FALSE: {
962
+ code: 1036,
963
+ message: 'To not set a boolean attribute, try <{0}> instead of <{0} {1}="{2}">. ' +
964
+ 'To represent a false value, the attribute has to be omitted altogether.',
965
+ level: DiagnosticLevel.Error,
966
+ url: '',
967
+ },
968
+ BOOLEAN_ATTRIBUTE_TRUE: {
969
+ code: 1037,
970
+ message: 'To set a boolean attributes, try <{0} {1}> instead of <{0} {1}="{2}">. ' +
971
+ 'If the attribute is present, its value must either be the empty string ' +
972
+ "or a value that is an ASCII case -insensitive match for the attribute's canonical name " +
973
+ 'with no leading or trailing whitespace.',
974
+ level: DiagnosticLevel.Error,
975
+ url: '',
976
+ },
977
+ COMPUTED_PROPERTY_ACCESS_NOT_ALLOWED: {
978
+ code: 1038,
979
+ message: "Template expression doesn't allow computed property access",
980
+ level: DiagnosticLevel.Error,
981
+ url: '',
982
+ },
983
+ DIRECTIVE_SHOULD_BE_EXPRESSION: {
984
+ code: 1039,
985
+ message: '{0} directive is expected to be an expression',
986
+ level: DiagnosticLevel.Error,
987
+ url: '',
988
+ },
989
+ INVALID_ID_ATTRIBUTE: {
990
+ code: 1040,
991
+ message: 'Invalid id value "{0}". Id values must not contain any whitespace.',
992
+ level: DiagnosticLevel.Error,
993
+ url: '',
994
+ },
995
+ INVALID_STATIC_ID_IN_ITERATION: {
996
+ code: 1041,
997
+ message: 'Static id values are not allowed in iterators. Id values must be unique within a template and must therefore be computed with an expression.',
998
+ level: DiagnosticLevel.Warning,
999
+ url: '',
1000
+ },
1001
+ DUPLICATE_ID_FOUND: {
1002
+ code: 1042,
1003
+ message: 'Duplicate id value "{0}" detected. Id values must be unique within a template.',
1004
+ level: DiagnosticLevel.Error,
1005
+ url: '',
1006
+ },
1007
+ EVENT_HANDLER_SHOULD_BE_EXPRESSION: {
1008
+ code: 1043,
1009
+ message: 'Event handler should be an expression',
1010
+ level: DiagnosticLevel.Error,
1011
+ url: '',
1012
+ },
1013
+ FOR_EACH_AND_FOR_ITEM_DIRECTIVES_SHOULD_BE_TOGETHER: {
1014
+ code: 1044,
1015
+ message: 'for:each and for:item directives should be associated together.',
1016
+ level: DiagnosticLevel.Error,
1017
+ url: '',
1018
+ },
1019
+ FOR_EACH_DIRECTIVE_SHOULD_BE_EXPRESSION: {
1020
+ code: 1045,
1021
+ message: 'for:each directive is expected to be a expression.',
1022
+ level: DiagnosticLevel.Error,
1023
+ url: '',
1024
+ },
1025
+ FOR_INDEX_DIRECTIVE_SHOULD_BE_STRING: {
1026
+ code: 1046,
1027
+ message: 'for:index directive is expected to be a string.',
1028
+ level: DiagnosticLevel.Error,
1029
+ url: '',
1030
+ },
1031
+ FOR_ITEM_DIRECTIVE_SHOULD_BE_STRING: {
1032
+ code: 1047,
1033
+ message: 'for:item directive is expected to be a string.',
1034
+ level: DiagnosticLevel.Error,
1035
+ url: '',
1036
+ },
1037
+ FORBIDDEN_IFRAME_SRCDOC_ATTRIBUTE: {
1038
+ code: 1048,
1039
+ message: 'srcdoc attribute is disallowed on <iframe> for security reasons',
1040
+ level: DiagnosticLevel.Error,
1041
+ url: '',
1042
+ },
1043
+ FORBIDDEN_SVG_NAMESPACE_IN_TEMPLATE: {
1044
+ code: 1049,
1045
+ message: "Forbidden svg namespace tag found in template: '<{0}>' tag is not allowed within <svg>",
1046
+ level: DiagnosticLevel.Error,
1047
+ url: '',
1048
+ },
1049
+ FORBIDDEN_MATHML_NAMESPACE_IN_TEMPLATE: {
1050
+ code: 1050,
1051
+ message: "Forbidden MathML namespace tag found in template: '<{0}>' tag is not allowed within <math>",
1052
+ level: DiagnosticLevel.Error,
1053
+ url: '',
1054
+ },
1055
+ FORBIDDEN_TAG_ON_TEMPLATE: {
1056
+ code: 1051,
1057
+ message: "Forbidden tag found in template: '<{0}>' tag is not allowed.",
1058
+ level: DiagnosticLevel.Error,
1059
+ url: '',
1060
+ },
1061
+ GENERIC_PARSING_ERROR: {
1062
+ code: 1052,
1063
+ message: 'Error parsing attribute: {0}',
1064
+ level: DiagnosticLevel.Error,
1065
+ url: '',
1066
+ },
1067
+ IDENTIFIER_PARSING_ERROR: {
1068
+ code: 1053,
1069
+ message: 'Error parsing identifier: {0}',
1070
+ level: DiagnosticLevel.Error,
1071
+ url: '',
1072
+ },
1073
+ IF_DIRECTIVE_SHOULD_BE_EXPRESSION: {
1074
+ code: 1054,
1075
+ message: 'If directive should be an expression',
1076
+ level: DiagnosticLevel.Error,
1077
+ url: '',
1078
+ },
1079
+ INVALID_ATTRIBUTE_CASE: {
1080
+ code: 1055,
1081
+ message: '{0} is not valid attribute for {1}. All attributes name should be all lowercase.',
1082
+ level: DiagnosticLevel.Error,
1083
+ url: '',
1084
+ },
1085
+ INVALID_EVENT_NAME: {
1086
+ code: 1056,
1087
+ message: 'Invalid event type "{0}". Event type must begin with a lower-case alphabetic character and contain only lower-case alphabetic characters, underscores, and numeric characters',
1088
+ level: DiagnosticLevel.Error,
1089
+ url: '',
1090
+ },
1091
+ INVALID_HTML_ATTRIBUTE: {
1092
+ code: 1057,
1093
+ message: '{0} is not valid attribute for {1}. For more information refer to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/{1}',
1094
+ level: DiagnosticLevel.Warning,
1095
+ url: '',
1096
+ },
1097
+ INVALID_HTML_SYNTAX: {
1098
+ code: 1058,
1099
+ message: 'Invalid HTML syntax: {0}. For more information, ' +
1100
+ 'please visit https://html.spec.whatwg.org/multipage/parsing.html#parse-error-{0}',
1101
+ level: DiagnosticLevel.Error,
1102
+ url: '',
1103
+ },
1104
+ INVALID_IDENTIFIER: {
1105
+ code: 1059,
1106
+ message: '{0} is not a valid identifier',
1107
+ level: DiagnosticLevel.Error,
1108
+ url: '',
1109
+ },
1110
+ INVALID_NODE: {
1111
+ code: 1060,
1112
+ message: "Template expression doesn't allow {0}",
1113
+ level: DiagnosticLevel.Error,
1114
+ url: '',
1115
+ },
1116
+ INVALID_TABINDEX_ATTRIBUTE: {
1117
+ code: 1061,
1118
+ message: 'The attribute "tabindex" can only be set to "0" or "-1".',
1119
+ level: DiagnosticLevel.Error,
1120
+ url: '',
1121
+ },
1122
+ DEPRECATED_IS_ATTRIBUTE_CANNOT_BE_EXPRESSION: {
1123
+ code: 1062,
1124
+ message: '"is" attribute value can\'t be an expression',
1125
+ level: DiagnosticLevel.Error,
1126
+ url: '',
1127
+ },
1128
+ IS_ATTRIBUTE_NOT_SUPPORTED: {
1129
+ code: 1063,
1130
+ message: '"is" attribute is disallowed',
1131
+ level: DiagnosticLevel.Error,
1132
+ url: '',
1133
+ },
1134
+ KEY_ATTRIBUTE_SHOULD_BE_EXPRESSION: {
1135
+ code: 1064,
1136
+ message: 'Key attribute value should be an expression',
1137
+ level: DiagnosticLevel.Error,
1138
+ url: '',
1139
+ },
1140
+ KEY_SHOULDNT_REFERENCE_FOR_EACH_INDEX: {
1141
+ code: 1065,
1142
+ message: 'Invalid key value for element <{0}>. Key cannot reference for:each index {1}',
1143
+ level: DiagnosticLevel.Error,
1144
+ url: '',
1145
+ },
1146
+ KEY_SHOULDNT_REFERENCE_ITERATOR_INDEX: {
1147
+ code: 1066,
1148
+ message: 'Invalid key value for element <{0}>. Key cannot reference iterator index',
1149
+ level: DiagnosticLevel.Error,
1150
+ url: '',
1151
+ },
1152
+ MISSING_KEY_IN_ITERATOR: {
1153
+ code: 1071,
1154
+ message: 'Missing key for element <{0}> inside of iterator. Elements within iterators must have a unique, computed key value.',
1155
+ level: DiagnosticLevel.Error,
1156
+ url: '',
1157
+ },
1158
+ MISSING_ROOT_TEMPLATE_TAG: {
1159
+ code: 1072,
1160
+ message: 'Missing root template tag',
1161
+ level: DiagnosticLevel.Error,
1162
+ url: '',
1163
+ },
1164
+ MODIFYING_ITERATORS_NOT_ALLOWED: {
1165
+ code: 1073,
1166
+ message: "Template expression doesn't allow to modify iterators",
1167
+ level: DiagnosticLevel.Error,
1168
+ url: '',
1169
+ },
1170
+ MULTIPLE_EXPRESSIONS: {
1171
+ code: 1074,
1172
+ message: 'Multiple expressions found',
1173
+ level: DiagnosticLevel.Error,
1174
+ url: '',
1175
+ },
1176
+ MULTIPLE_ROOTS_FOUND: {
1177
+ code: 1075,
1178
+ message: 'Multiple roots found',
1179
+ level: DiagnosticLevel.Error,
1180
+ url: '',
1181
+ },
1182
+ NAME_ON_SLOT_CANNOT_BE_EXPRESSION: {
1183
+ code: 1076,
1184
+ message: "Name attribute on slot tag can't be an expression.",
1185
+ level: DiagnosticLevel.Error,
1186
+ url: '',
1187
+ },
1188
+ NO_DIRECTIVE_FOUND_ON_TEMPLATE: {
1189
+ code: 1077,
1190
+ message: 'Invalid template tag. A directive is expected to be associated with the template tag.',
1191
+ level: DiagnosticLevel.Error,
1192
+ url: '',
1193
+ },
1194
+ NO_MATCHING_CLOSING_TAGS: {
1195
+ code: 1078,
1196
+ message: '<{0}> has no matching closing tag.',
1197
+ level: DiagnosticLevel.Error,
1198
+ url: '',
1199
+ },
1200
+ ROOT_TAG_SHOULD_BE_TEMPLATE: {
1201
+ code: 1079,
1202
+ message: 'Expected root tag to be template, found {0}',
1203
+ level: DiagnosticLevel.Error,
1204
+ url: '',
1205
+ },
1206
+ ROOT_TEMPLATE_HAS_UNKNOWN_ATTRIBUTES: {
1207
+ code: 1080,
1208
+ message: 'Root template has unknown or disallowed attributes: {0}',
1209
+ level: DiagnosticLevel.Error,
1210
+ url: '',
1211
+ },
1212
+ // TODO [#3100]: Update message to point to external documentation once available.
1213
+ SLOT_TAG_CANNOT_HAVE_DIRECTIVES: {
1214
+ code: 1082,
1215
+ message: "<slot> tag can't be associated with {0} template directives.",
1216
+ level: DiagnosticLevel.Error,
1217
+ url: '',
1218
+ },
1219
+ TEMPLATE_EXPRESSION_PARSING_ERROR: {
1220
+ code: 1083,
1221
+ message: 'Error parsing template expression: {0}',
1222
+ level: DiagnosticLevel.Error,
1223
+ url: '',
1224
+ },
1225
+ UNEXPECTED_IF_MODIFIER: {
1226
+ code: 1084,
1227
+ message: 'Unexpected if modifier {0}',
1228
+ level: DiagnosticLevel.Error,
1229
+ url: '',
1230
+ },
1231
+ LWC_DOM_INVALID_VALUE: {
1232
+ code: 1085,
1233
+ message: 'Invalid value for "lwc:dom". \'lwc:dom\' can only be set to {0}',
1234
+ level: DiagnosticLevel.Error,
1235
+ url: '',
1236
+ },
1237
+ LWC_DOM_INVALID_CONTENTS: {
1238
+ code: 1086,
1239
+ message: 'Invalid contents for element with "lwc:dom". Element must be empty',
1240
+ level: DiagnosticLevel.Error,
1241
+ url: '',
1242
+ },
1243
+ LWC_DOM_INVALID_CUSTOM_ELEMENT: {
1244
+ code: 1087,
1245
+ message: 'Invalid directive "lwc:dom" on element {0}. "lwc:dom" cannot be added to a custom element',
1246
+ level: DiagnosticLevel.Error,
1247
+ url: '',
1248
+ },
1249
+ LWC_DOM_INVALID_SLOT_ELEMENT: {
1250
+ code: 1088,
1251
+ message: 'Invalid directive "lwc:dom" on <slot>.. "lwc:dom" cannot be added to a <slot>',
1252
+ level: DiagnosticLevel.Error,
1253
+ url: '',
1254
+ },
1255
+ STYLE_TAG_NOT_ALLOWED_IN_TEMPLATE: {
1256
+ code: 1122,
1257
+ message: "The <style> element is disallowed inside the template. Please add css rules into '.css' file of your component bundle.",
1258
+ level: DiagnosticLevel.Error,
1259
+ url: '',
1260
+ },
1261
+ UNKNOWN_HTML_TAG_IN_TEMPLATE: {
1262
+ code: 1123,
1263
+ message: "Unknown html tag '<{0}>'. For more information refer to https://developer.mozilla.org/en-US/docs/Web/HTML/Element and https://developer.mozilla.org/en-US/docs/Web/SVG/Element",
1264
+ level: DiagnosticLevel.Warning,
1265
+ url: '',
1266
+ },
1267
+ ATTRIBUTE_NAME_STARTS_WITH_INVALID_CHARACTER: {
1268
+ code: 1124,
1269
+ message: '{0} is not valid attribute for {1}. Attribute name must start with an underscore, dollar sign, or an optional hyphen character followed by an alphabetic character.',
1270
+ level: DiagnosticLevel.Error,
1271
+ url: '',
1272
+ },
1273
+ ATTRIBUTE_NAME_MUST_END_WITH_ALPHA_NUMERIC_CHARACTER: {
1274
+ code: 1125,
1275
+ message: '{0} is not valid attribute for {1}. Attribute name must end with alpha-numeric character.',
1276
+ level: DiagnosticLevel.Error,
1277
+ url: '',
1278
+ },
1279
+ UNKNOWN_LWC_DIRECTIVE: {
1280
+ code: 1127,
1281
+ message: 'Invalid directive "{0}" on element {1}.',
1282
+ level: DiagnosticLevel.Error,
1283
+ url: '',
1284
+ },
1285
+ INVALID_OPTS_LWC_DYNAMIC: {
1286
+ code: 1128,
1287
+ message: 'Invalid lwc:dynamic usage. The LWC dynamic directive must be enabled in order to use this feature.',
1288
+ level: DiagnosticLevel.Error,
1289
+ url: '',
1290
+ },
1291
+ INVALID_LWC_DYNAMIC_ON_NATIVE_ELEMENT: {
1292
+ code: 1129,
1293
+ message: 'Invalid lwc:dynamic usage on element "{0}". This directive can only be used in a custom element.',
1294
+ level: DiagnosticLevel.Error,
1295
+ url: '',
1296
+ },
1297
+ INVALID_LWC_DYNAMIC_LITERAL_PROP: {
1298
+ code: 1130,
1299
+ message: 'Invalid lwc:dynamic usage on element "{0}". The directive binding must be an expression.',
1300
+ level: DiagnosticLevel.Error,
1301
+ url: '',
1302
+ },
1303
+ LWC_RENDER_MODE_INVALID_VALUE: {
1304
+ code: 1133,
1305
+ message: 'Invalid value for "lwc:render-mode". \'lwc:render-mode\' can only be set to "shadow", or "light"',
1306
+ level: DiagnosticLevel.Error,
1307
+ url: '',
1308
+ },
1309
+ LWC_LIGHT_SLOT_INVALID_ATTRIBUTES: {
1310
+ code: 1134,
1311
+ message: "Invalid attribute(s) '{0}' on slot. Slots in Light DOM templates (which have 'lwc:render-mode' directive) can only have [{1}] attributes",
1312
+ level: DiagnosticLevel.Error,
1313
+ url: '',
1314
+ },
1315
+ LWC_DOM_INVALID_IN_LIGHT_DOM: {
1316
+ code: 1135,
1317
+ message: "Invalid directive 'lwc:dom' on element {0}. 'lwc:dom' is not necessary in Light DOM components.",
1318
+ level: DiagnosticLevel.Error,
1319
+ url: '',
1320
+ },
1321
+ INVALID_FOR_EACH_WITH_ITERATOR: {
1322
+ code: 1136,
1323
+ message: "Invalid usage for 'for:each' and '{0}' directives on the same element.",
1324
+ level: DiagnosticLevel.Error,
1325
+ url: '',
1326
+ },
1327
+ NO_DUPLICATE_SLOTS: {
1328
+ code: 1137,
1329
+ message: 'Invalid duplicate slot ({0}).',
1330
+ level: DiagnosticLevel.Warning,
1331
+ url: '',
1332
+ },
1333
+ NO_SLOTS_IN_ITERATOR: {
1334
+ code: 1138,
1335
+ message: 'Invalid slot ({0}). A slot cannot appear inside of an iterator.',
1336
+ level: DiagnosticLevel.Warning,
1337
+ url: '',
1338
+ },
1339
+ LWC_LIGHT_SLOT_INVALID_EVENT_LISTENER: {
1340
+ code: 1139,
1341
+ message: "Invalid event listener '{0}' on slot. Slots in Light DOM templates cannot have event listeners.",
1342
+ level: DiagnosticLevel.Error,
1343
+ url: '',
1344
+ },
1345
+ LWC_INNER_HTML_INVALID_CUSTOM_ELEMENT: {
1346
+ code: 1140,
1347
+ message: 'Invalid lwc:inner-html usage on element "{0}". The directive can\'t be used on a custom element or special LWC managed elements denoted with lwc:*.',
1348
+ level: DiagnosticLevel.Error,
1349
+ url: '',
1350
+ },
1351
+ LWC_INNER_HTML_INVALID_ELEMENT: {
1352
+ code: 1141,
1353
+ message: 'Invalid lwc:inner-html usage on element "{0}". The directive can\'t be used on a slot or a template element.',
1354
+ level: DiagnosticLevel.Error,
1355
+ url: '',
1356
+ },
1357
+ LWC_INNER_HTML_INVALID_CONTENTS: {
1358
+ code: 1142,
1359
+ message: 'Invalid lwc:inner-html usage on element "{0}". The directive can\'t be used on an element with content.',
1360
+ level: DiagnosticLevel.Error,
1361
+ url: '',
1362
+ },
1363
+ LWC_INNER_HTML_INVALID_VALUE: {
1364
+ code: 1143,
1365
+ message: 'Invalid lwc:inner-html usage on element "{0}". The directive binding can only be an expression or a string.',
1366
+ level: DiagnosticLevel.Error,
1367
+ url: '',
1368
+ },
1369
+ INVALID_HTML_RECOVERY: {
1370
+ code: 1144,
1371
+ message: 'Invalid HTML detected, "<{0}>" was automatically inserted within "<{1}>"; the compiled template may not match the template source.',
1372
+ level: DiagnosticLevel.Warning,
1373
+ url: '',
1374
+ },
1375
+ INVALID_TEMPLATE_ATTRIBUTE: {
1376
+ code: 1145,
1377
+ message: 'Invalid attributes detected on template. The following attributes are not supported on template tags in LWC: {0}. For more information, ' +
1378
+ 'please visit https://sfdc.co/template-directives',
1379
+ level: DiagnosticLevel.Warning,
1380
+ url: '',
1381
+ },
1382
+ PRESERVE_COMMENTS_MUST_BE_BOOLEAN: {
1383
+ code: 1146,
1384
+ message: 'lwc:preserve-comments must be a boolean attribute.',
1385
+ level: DiagnosticLevel.Error,
1386
+ url: '',
1387
+ },
1388
+ DUPLICATE_ATTR_PROP_TRANSFORM: {
1389
+ code: 1147,
1390
+ message: 'Found multiple HTML attributes mapping to the same JavaScript property. "{0}" and "{1}" both map to "{2}".',
1391
+ level: DiagnosticLevel.Warning,
1392
+ url: '',
1393
+ },
1394
+ INVALID_HTML_SYNTAX_WARNING: {
1395
+ code: 1148,
1396
+ message: 'Invalid HTML syntax: {0}. This will not be supported in future versions of LWC. For more information, ' +
1397
+ 'please visit https://html.spec.whatwg.org/multipage/parsing.html#parse-error-{0}',
1398
+ level: DiagnosticLevel.Warning,
1399
+ url: '',
1400
+ },
1401
+ KEY_SHOULD_BE_IN_ITERATION: {
1402
+ code: 1149,
1403
+ message: 'Invalid key attribute on element <{0}>. The key attribute should be applied to an element with for:each or iterator:*, or to a direct child of a <template> element with for:each or iterator:*. This key will be ignored, and may throw an error in future versions of LWC.',
1404
+ level: DiagnosticLevel.Warning,
1405
+ url: '',
1406
+ },
1407
+ INVALID_TEMPLATE_WARNING: {
1408
+ code: 1153,
1409
+ message: 'Non-root template elements must contain valid LWC template directive attributes. Otherwise, the template and its children will be ignored. ' +
1410
+ 'For more information please visit https://sfdc.co/template-directives',
1411
+ level: DiagnosticLevel.Warning,
1412
+ url: '',
1413
+ },
1414
+ INVALID_LWC_SPREAD_LITERAL_PROP: {
1415
+ code: 1155,
1416
+ message: 'Invalid lwc:spread usage on element "{0}". The directive binding must be an expression.',
1417
+ level: DiagnosticLevel.Error,
1418
+ url: '',
1419
+ },
1420
+ LWC_REF_INVALID_ELEMENT: {
1421
+ code: 1156,
1422
+ message: 'Invalid lwc:ref usage on element "{0}". The directive can\'t be used on a slot or a template element.',
1423
+ level: DiagnosticLevel.Error,
1424
+ url: '',
1425
+ },
1426
+ LWC_REF_INVALID_VALUE: {
1427
+ code: 1157,
1428
+ message: 'Invalid lwc:ref usage on element "{0}". The directive binding must be a non-empty string.',
1429
+ level: DiagnosticLevel.Error,
1430
+ url: '',
1431
+ },
1432
+ LWC_REF_INVALID_LOCATION_INSIDE_ITERATION: {
1433
+ code: 1158,
1434
+ message: 'Invalid lwc:ref usage on element "{0}". lwc:ref cannot be used inside for:each or an iterator.',
1435
+ level: DiagnosticLevel.Error,
1436
+ url: '',
1437
+ },
1438
+ IF_BLOCK_DIRECTIVE_SHOULD_BE_EXPRESSION: {
1439
+ code: 1159,
1440
+ message: 'lwc:if directive value should be an expression',
1441
+ level: DiagnosticLevel.Error,
1442
+ url: '',
1443
+ },
1444
+ ELSEIF_BLOCK_DIRECTIVE_SHOULD_BE_EXPRESSION: {
1445
+ code: 1160,
1446
+ message: 'lwc:elseif directive value should be an expression',
1447
+ level: DiagnosticLevel.Error,
1448
+ url: '',
1449
+ },
1450
+ ELSE_BLOCK_DIRECTIVE_CANNOT_HAVE_VALUE: {
1451
+ code: 1161,
1452
+ message: 'lwc:else directive cannot have a value',
1453
+ level: DiagnosticLevel.Error,
1454
+ url: '',
1455
+ },
1456
+ INVALID_IF_BLOCK_DIRECTIVE_WITH_CONDITIONAL: {
1457
+ code: 1162,
1458
+ message: "Invalid usage of 'lwc:if' and '{0}' directives on the same element.",
1459
+ level: DiagnosticLevel.Error,
1460
+ url: '',
1461
+ },
1462
+ INVALID_ELSEIF_BLOCK_DIRECTIVE_WITH_CONDITIONAL: {
1463
+ code: 1163,
1464
+ message: "Invalid usage of 'lwc:elseif' and '{0}' directives on the same element.",
1465
+ level: DiagnosticLevel.Error,
1466
+ url: '',
1467
+ },
1468
+ INVALID_ELSE_BLOCK_DIRECTIVE_WITH_CONDITIONAL: {
1469
+ code: 1164,
1470
+ message: "Invalid usage of 'lwc:else' and '{0}' directives on the same element.",
1471
+ level: DiagnosticLevel.Error,
1472
+ url: '',
1473
+ },
1474
+ LWC_IF_SCOPE_NOT_FOUND: {
1475
+ code: 1165,
1476
+ message: "'{0}' directive must be used immediately after an element with 'lwc:if' or 'lwc:elseif'. No such element found.",
1477
+ level: DiagnosticLevel.Error,
1478
+ url: '',
1479
+ },
1480
+ LWC_IF_CANNOT_BE_USED_WITH_IF_DIRECTIVE: {
1481
+ code: 1166,
1482
+ message: "'{0}' directive cannot be used with 'lwc:if', 'lwc:elseif', or 'lwc:else directives on the same element.",
1483
+ level: DiagnosticLevel.Error,
1484
+ url: '',
1485
+ },
1486
+ SCOPED_SLOT_BIND_IN_LIGHT_DOM_ONLY: {
1487
+ code: 1169,
1488
+ message: 'Invalid lwc:slot-bind usage on <slot> element. Scoped slots usage is allowed in Light DOM templates only.',
1489
+ level: DiagnosticLevel.Error,
1490
+ url: '',
1491
+ },
1492
+ INVALID_LWC_SLOT_BIND_LITERAL_PROP: {
1493
+ code: 1170,
1494
+ message: 'Invalid lwc:slot-bind usage on element {0}. The directive binding must be an expression.',
1495
+ level: DiagnosticLevel.Error,
1496
+ url: '',
1497
+ },
1498
+ INVALID_LWC_SLOT_BIND_NON_SLOT_ELEMENT: {
1499
+ code: 1171,
1500
+ message: 'Invalid lwc:slot-bind usage on element {0}. The directive can be used on a <slot> element only.',
1501
+ level: DiagnosticLevel.Error,
1502
+ url: '',
1503
+ },
1504
+ NO_DUPLICATE_SCOPED_SLOT: {
1505
+ code: 1172,
1506
+ message: 'Invalid duplicate scoped slots ({0})',
1507
+ level: DiagnosticLevel.Error,
1508
+ url: '',
1509
+ },
1510
+ NO_MIXED_SLOT_TYPES: {
1511
+ code: 1173,
1512
+ message: 'Mixing slot types disallowed for same ({0}) slot.',
1513
+ level: DiagnosticLevel.Error,
1514
+ url: '',
1515
+ },
1516
+ SLOT_DATA_VALUE_SHOULD_BE_STRING: {
1517
+ code: 1174,
1518
+ message: 'lwc:slot-data attribute value is expected to be a string.',
1519
+ level: DiagnosticLevel.Error,
1520
+ url: '',
1521
+ },
1522
+ SCOPED_SLOT_DATA_ON_TEMPLATE_ONLY: {
1523
+ code: 1176,
1524
+ message: 'lwc:slot-data directive can be used on <template> elements only.',
1525
+ level: DiagnosticLevel.Error,
1526
+ url: '',
1527
+ },
1528
+ NON_ELEMENT_SCOPED_SLOT_CONTENT: {
1529
+ code: 1177,
1530
+ message: '<template> tag with lwc:slot-data directive cannot contain a comment or text node as a direct child.',
1531
+ level: DiagnosticLevel.Error,
1532
+ url: '',
1533
+ },
1534
+ INVALID_PARENT_OF_LWC_SLOT_DATA: {
1535
+ code: 1178,
1536
+ message: '<template> tag with lwc:slot-data directive must be the direct child of a custom element.',
1537
+ level: DiagnosticLevel.Error,
1538
+ url: '',
1539
+ },
1540
+ SCOPED_SLOTDATA_CANNOT_BE_COMBINED_WITH_OTHER_DIRECTIVE: {
1541
+ code: 1179,
1542
+ message: 'lwc:slot-data directive cannot be combined with other directives on the same <template> tag.',
1543
+ level: DiagnosticLevel.Error,
1544
+ url: '',
1545
+ },
1546
+ INVALID_LWC_EXTERNAL_ON_NON_CUSTOM_ELEMENT: {
1547
+ code: 1180,
1548
+ message: 'Invalid lwc:external directive usage: {0}. This directive can only be used on custom elements.',
1549
+ level: DiagnosticLevel.Error,
1550
+ url: '',
1551
+ },
1552
+ INVALID_LWC_EXTERNAL_VALUE: {
1553
+ code: 1181,
1554
+ message: 'Invalid lwc:external directive usage: {0}. This directive is a boolean attribute and should not have a value.',
1555
+ level: DiagnosticLevel.Error,
1556
+ url: '',
1557
+ },
1558
+ SINGLE_IF_DIRECTIVE_ALLOWED: {
1559
+ code: 1182,
1560
+ message: `Multiple if: directives found on '{0}'. Only one if: directive is allowed; the rest are ignored.`,
1561
+ level: DiagnosticLevel.Warning,
1562
+ url: '',
1563
+ },
1564
+ LWC_COMPONENT_TAG_WITHOUT_IS_DIRECTIVE: {
1565
+ code: 1183,
1566
+ message: `<lwc:component> must have an 'lwc:is' attribute.`,
1567
+ level: DiagnosticLevel.Error,
1568
+ url: '',
1569
+ },
1570
+ UNSUPPORTED_LWC_TAG_NAME: {
1571
+ code: 1184,
1572
+ message: '{0} is not a special LWC tag name and will be treated as an HTML element.',
1573
+ level: DiagnosticLevel.Warning,
1574
+ url: '',
1575
+ },
1576
+ INVALID_LWC_IS_DIRECTIVE_VALUE: {
1577
+ code: 1185,
1578
+ message: 'Invalid lwc:is usage for value {0}. The value assigned to lwc:is must be an expression.',
1579
+ level: DiagnosticLevel.Error,
1580
+ url: '',
1581
+ },
1582
+ LWC_IS_INVALID_ELEMENT: {
1583
+ code: 1186,
1584
+ message: 'Invalid lwc:is usage for element {0}. The directive can only be used with <lwc:component>',
1585
+ level: DiagnosticLevel.Error,
1586
+ url: '',
1587
+ },
1588
+ DEPRECATED_LWC_DYNAMIC_ATTRIBUTE: {
1589
+ code: 1187,
1590
+ message: `The lwc:dynamic directive is deprecated and will be removed in a future release. Please use lwc:is instead.`,
1591
+ level: DiagnosticLevel.Warning,
1592
+ url: '',
1593
+ },
1594
+ INVALID_OPTS_LWC_ENABLE_DYNAMIC_COMPONENTS: {
1595
+ code: 1188,
1596
+ message: 'Invalid dynamic components usage, lwc:component and lwc:is can only be used when dynamic components have been enabled.',
1597
+ level: DiagnosticLevel.Error,
1598
+ url: '',
1599
+ },
1600
+ // TODO [#3370]: remove this error if template expressions is removed
1601
+ INVALID_EXPR_ARROW_FN_PARAM: {
1602
+ code: 1189,
1603
+ message: "Template expression doesn't allow {0} in arrow function params.",
1604
+ level: DiagnosticLevel.Error,
1605
+ url: '',
1606
+ },
1607
+ // TODO [#3370]: remove this error if template expressions is removed
1608
+ INVALID_EXPR_STATEMENTS_PROHIBITED: {
1609
+ code: 1190,
1610
+ message: 'Statements are disallowed in template expressions.',
1611
+ level: DiagnosticLevel.Error,
1612
+ url: '',
1613
+ },
1614
+ // TODO [#3370]: remove this error if template expressions is removed
1615
+ INVALID_EXPR_MUTATION_OUTSIDE_ARROW: {
1616
+ code: 1191,
1617
+ message: 'Field mutations are only permitted within arrow functions.',
1618
+ level: DiagnosticLevel.Error,
1619
+ url: '',
1620
+ },
1621
+ // TODO [#3370]: remove this error if template expressions is removed
1622
+ INVALID_EXPR_DELETE_OP: {
1623
+ code: 1192,
1624
+ message: 'Use of the delete operator is prohibited within template expressions.',
1625
+ level: DiagnosticLevel.Error,
1626
+ url: '',
1627
+ },
1628
+ // TODO [#3370]: remove this error if template expressions is removed
1629
+ INVALID_EXPR_ARROW_FN_BODY: {
1630
+ code: 1193,
1631
+ message: 'The body of arrow functions in template expressions must be an expression.',
1632
+ level: DiagnosticLevel.Error,
1633
+ url: '',
1634
+ },
1635
+ // TODO [#3370]: remove this error if template expressions is removed
1636
+ INVALID_EXPR_ARROW_FN_KIND: {
1637
+ code: 1194,
1638
+ message: 'Arrow functions in template expressions cannot be {0}.',
1639
+ level: DiagnosticLevel.Error,
1640
+ url: '',
1641
+ },
1642
+ // TODO [#3370]: remove this error if template expressions is removed
1643
+ INVALID_EXPR_EARLY_STAGE_FEATURE: {
1644
+ code: 1195,
1645
+ message: 'Early-stage JS features are disallowed in template expressions.',
1646
+ level: DiagnosticLevel.Error,
1647
+ url: '',
1648
+ },
1649
+ // TODO [#3370]: remove this error if template expressions is removed
1650
+ INVALID_EXPR_PROHIBITED_NODE_TYPE: {
1651
+ code: 1196,
1652
+ message: 'Use of {0} is disallowed within template expressions.',
1653
+ level: DiagnosticLevel.Error,
1654
+ url: '',
1655
+ },
1656
+ // TODO [#3370]: remove this error if template expressions is removed
1657
+ INVALID_EXPR_COMMENTS_DISALLOWED: {
1658
+ code: 1197,
1659
+ message: 'Use of comments is disallowed within template expressions.',
1660
+ level: DiagnosticLevel.Error,
1661
+ url: '',
1662
+ },
1663
+ });
1664
+
1665
+ /**
1666
+ * Pattern modeled after @lwc/engine-core's reporting.ts system
1667
+ */
1668
+ var CompilerMetrics;
1669
+ (function (CompilerMetrics) {
1670
+ CompilerMetrics["LWCDynamicDirective"] = "lwc-dynamic-directive";
1671
+ CompilerMetrics["LWCRenderModeDirective"] = "lwc-render-mode-directive";
1672
+ CompilerMetrics["LWCSpreadDirective"] = "lwc-spread-directive";
1673
+ CompilerMetrics["DynamicImportTransform"] = "dynamic-import-transform";
1674
+ })(CompilerMetrics || (CompilerMetrics = {}));
1675
+ /** version: 8.3.0 */
1676
+
1677
+ /*
1678
+ * Copyright (c) 2024, Salesforce, Inc.
1679
+ * All rights reserved.
1680
+ * SPDX-License-Identifier: MIT
1681
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1682
+ */
1683
+ const bStylesheetTokenDeclaration = (esTemplate `
491
1684
  const stylesheetScopeToken = '${is.literal}';
492
- `;
1685
+ `);
493
1686
  const bAdditionalDeclarations = [
494
- esTemplate `
1687
+ (esTemplate `
495
1688
  const hasScopedStylesheets = defaultScopedStylesheets && defaultScopedStylesheets.length > 0;
496
- `,
497
- esTemplate `
1689
+ `),
1690
+ (esTemplate `
498
1691
  const stylesheetScopeTokenClass = hasScopedStylesheets ? \` class="\${stylesheetScopeToken}"\` : '';
499
- `,
500
- esTemplate `
1692
+ `),
1693
+ (esTemplate `
501
1694
  const stylesheetScopeTokenHostClass = hasScopedStylesheets ? \` class="\${stylesheetScopeToken}-host"\` : '';
502
- `,
503
- esTemplate `
1695
+ `),
1696
+ (esTemplate `
504
1697
  const stylesheetScopeTokenClassPrefix = hasScopedStylesheets ? (stylesheetScopeToken + ' ') : '';
505
- `,
1698
+ `),
506
1699
  ];
507
1700
  // Scope tokens are associated with a given template. This is assigned here so that it can be used in `generateMarkup`.
508
- const tmplAssignmentBlock = esTemplate `
1701
+ const tmplAssignmentBlock = (esTemplate `
509
1702
  ${is.identifier}.stylesheetScopeTokenHostClass = stylesheetScopeTokenHostClass;
510
- `;
1703
+ `);
511
1704
  function addScopeTokenDeclarations(program, filename, namespace, componentName) {
512
1705
  const { scopeToken } = generateScopeTokens(filename, namespace, componentName);
513
1706
  program.body.unshift(bStylesheetTokenDeclaration(builders$1.literal(scopeToken)), ...bAdditionalDeclarations.map((declaration) => declaration()));
@@ -520,9 +1713,9 @@ function addScopeTokenDeclarations(program, filename, namespace, componentName)
520
1713
  * SPDX-License-Identifier: MIT
521
1714
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
522
1715
  */
523
- const bImportHtmlEscape = esTemplate `
1716
+ const bImportHtmlEscape = (esTemplate `
524
1717
  import { htmlEscape } from '@lwc/shared';
525
- `;
1718
+ `);
526
1719
  const importHtmlEscapeKey = 'import:htmlEscape';
527
1720
  // This is a mostly-correct regular expression will only match if the entire string
528
1721
  // provided is a valid ECMAScript identifier. Its imperfections lie in the fact that
@@ -608,14 +1801,16 @@ function expressionIrToEs(node, cxt) {
608
1801
  * SPDX-License-Identifier: MIT
609
1802
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
610
1803
  */
611
- const bYieldFromChildGenerator = esTemplateWithYield `
1804
+ const bYieldFromChildGenerator = (esTemplateWithYield `
612
1805
  {
613
1806
  const childProps = ${is.objectExpression};
614
1807
  const childAttrs = ${is.objectExpression};
615
- const childSlottedContentGenerators = {};
616
- yield* ${is.identifier}(${is.literal}, childProps, childAttrs, childSlottedContentGenerators);
1808
+ async function* childSlottedContentGenerator() {
1809
+ ${is.statement}
1810
+ };
1811
+ yield* ${is.identifier}(${is.literal}, childProps, childAttrs, childSlottedContentGenerator);
617
1812
  }
618
- `;
1813
+ `);
619
1814
  const bImportGenerateMarkup = (localName, importPath) => builders.importDeclaration([builders.importSpecifier(builders.identifier('generateMarkup'), builders.identifier(localName))], builders.literal(importPath));
620
1815
  function getChildAttrsOrProps(attrs, cxt) {
621
1816
  const objectAttrsOrProps = attrs.map((attr) => {
@@ -660,7 +1855,7 @@ const Component = function Component(node, cxt) {
660
1855
  const childTagName = node.name;
661
1856
  const attributes = [...node.attributes, ...reflectAriaPropsAsAttrs(node.properties)];
662
1857
  return [
663
- bYieldFromChildGenerator(getChildAttrsOrProps(node.properties, cxt), getChildAttrsOrProps(attributes, cxt), builders.identifier(childGeneratorLocalName), builders.literal(childTagName)),
1858
+ bYieldFromChildGenerator(getChildAttrsOrProps(node.properties, cxt), getChildAttrsOrProps(attributes, cxt), optimizeAdjacentYieldStmts(irChildrenToEs(node.children, cxt)), builders.identifier(childGeneratorLocalName), builders.literal(childTagName)),
664
1859
  ];
665
1860
  };
666
1861
 
@@ -671,7 +1866,7 @@ const Component = function Component(node, cxt) {
671
1866
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
672
1867
  */
673
1868
  const bYield$1 = (expr) => builders.expressionStatement(builders.yieldExpression(expr));
674
- const bConditionalLiveYield = esTemplateWithYield `
1869
+ const bConditionalLiveYield = (esTemplateWithYield `
675
1870
  {
676
1871
  const prefix = (${ /* isClass */is.literal} && stylesheetScopeTokenClassPrefix) || '';
677
1872
  const attrOrPropValue = ${is.expression};
@@ -683,13 +1878,13 @@ const bConditionalLiveYield = esTemplateWithYield `
683
1878
  }
684
1879
  }
685
1880
  }
686
- `;
687
- const bStringLiteralYield = esTemplateWithYield `
1881
+ `);
1882
+ const bStringLiteralYield = (esTemplateWithYield `
688
1883
  {
689
1884
  const prefix = (${ /* isClass */is.literal} && stylesheetScopeTokenClassPrefix) || '';
690
1885
  yield ' ' + ${is.literal} + '="' + prefix + "${is.literal}" + '"'
691
1886
  }
692
- `;
1887
+ `);
693
1888
  function yieldAttrOrPropLiteralValue(name, valueNode, isClass) {
694
1889
  const { value, type } = valueNode;
695
1890
  if (typeof value === 'string') {
@@ -737,6 +1932,7 @@ function reorderAttributes(attrs, props) {
737
1932
  return [classAttr, styleAttr, ...boringAttrs, ...props, slotAttr].filter((el) => el !== null);
738
1933
  }
739
1934
  const Element = function Element(node, cxt) {
1935
+ const innerHtmlDirective = node.type === 'Element' && node.directives.find((dir) => dir.name === 'InnerHTML');
740
1936
  const attrsAndProps = reorderAttributes(node.attributes, node.properties);
741
1937
  let hasClassAttribute = false;
742
1938
  const yieldAttrsAndProps = attrsAndProps.flatMap((attr) => {
@@ -757,13 +1953,27 @@ const Element = function Element(node, cxt) {
757
1953
  if (isVoidElement(node.name, HTML_NAMESPACE)) {
758
1954
  return [bYield$1(builders.literal(`<${node.name}`)), ...yieldAttrsAndProps, bYield$1(builders.literal(`>`))];
759
1955
  }
1956
+ let childContent;
1957
+ // An element can have children or lwc:inner-html, but not both
1958
+ // If it has both, the template compiler will throw an error before reaching here
1959
+ if (node.children.length) {
1960
+ childContent = irChildrenToEs(node.children, cxt);
1961
+ }
1962
+ else if (innerHtmlDirective) {
1963
+ const value = innerHtmlDirective.value;
1964
+ const unsanitizedHtmlExpression = value.type === 'Literal' ? builders.literal(value.value) : expressionIrToEs(value, cxt);
1965
+ childContent = [bYield$1(unsanitizedHtmlExpression)];
1966
+ }
1967
+ else {
1968
+ childContent = [];
1969
+ }
760
1970
  return [
761
1971
  bYield$1(builders.literal(`<${node.name}`)),
762
1972
  // If we haven't already prefixed the scope token to an existing class, add an explicit class here
763
1973
  ...(hasClassAttribute ? [] : [bYield$1(builders.identifier('stylesheetScopeTokenClass'))]),
764
1974
  ...yieldAttrsAndProps,
765
1975
  bYield$1(builders.literal(`>`)),
766
- ...irChildrenToEs(node.children, cxt),
1976
+ ...childContent,
767
1977
  bYield$1(builders.literal(`</${node.name}>`)),
768
1978
  ].filter(Boolean);
769
1979
  };
@@ -781,11 +1991,11 @@ function getRootIdentifier$1(node) {
781
1991
  const rootMemberExpression = getRootMemberExpression$1(node);
782
1992
  return is.identifier(rootMemberExpression?.object) ? rootMemberExpression.object : null;
783
1993
  }
784
- const bForOfYieldFrom$1 = esTemplate `
1994
+ const bForOfYieldFrom$1 = (esTemplate `
785
1995
  for (let [${is.identifier}, ${is.identifier}] of Object.entries(${is.expression} ?? {})) {
786
1996
  ${is.statement};
787
1997
  }
788
- `;
1998
+ `);
789
1999
  const ForEach = function ForEach(node, cxt) {
790
2000
  const forItemId = node.item.name;
791
2001
  const forIndexId = node.index?.name ?? '__unused__';
@@ -819,14 +2029,14 @@ function getRootIdentifier(node) {
819
2029
  const rootMemberExpression = getRootMemberExpression(node);
820
2030
  return is.identifier(rootMemberExpression?.object) ? rootMemberExpression.object : null;
821
2031
  }
822
- const bForOfYieldFrom = esTemplate `
2032
+ const bForOfYieldFrom = (esTemplate `
823
2033
  for (let ${is.identifier} of toIteratorDirective(${is.expression} ?? [])) {
824
2034
  ${is.statement};
825
2035
  }
826
- `;
827
- const bToIteratorDirectiveImport = esTemplate `
2036
+ `);
2037
+ const bToIteratorDirectiveImport = (esTemplate `
828
2038
  import { toIteratorDirective } from '@lwc/ssr-runtime';
829
- `;
2039
+ `);
830
2040
  const ForOf = function ForEach(node, cxt) {
831
2041
  const id = node.iterator.name;
832
2042
  cxt.pushLocalVars([id]);
@@ -885,6 +2095,54 @@ const IfBlock = function IfBlock(node, cxt) {
885
2095
  return [bIfStatement(node, cxt)];
886
2096
  };
887
2097
 
2098
+ /*
2099
+ * Copyright (c) 2024, salesforce.com, inc.
2100
+ * All rights reserved.
2101
+ * SPDX-License-Identifier: MIT
2102
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2103
+ */
2104
+ const bConditionalSlot = (esTemplateWithYield `
2105
+ if (isLightDom) {
2106
+ // start bookend HTML comment
2107
+ yield '<!---->';
2108
+
2109
+ const generator = slottedContent[${ /* slotName */is.expression} ?? ""];
2110
+ if (generator) {
2111
+ yield* generator();
2112
+ } else {
2113
+ // If we're in this else block, then the generator _must_ have yielded
2114
+ // something. It's impossible for a slottedContent["foo"] to exist
2115
+ // without the generator yielding at least a text node / element.
2116
+ // FIXME: how does this work with comments and lwc:preserve-comments?
2117
+ // TODO: default/fallback slot content
2118
+ ${ /* slot fallback content */is.statement}
2119
+ }
2120
+
2121
+ // end bookend HTML comment
2122
+ yield '<!---->';
2123
+ } else {
2124
+ ${ /* slot element AST */is.statement}
2125
+ }
2126
+ `);
2127
+ const Slot = function Slot(node, ctx) {
2128
+ const nameAttrValue = node.attributes.find((attr) => attr.name === 'name')?.value;
2129
+ let slotName;
2130
+ if (!nameAttrValue) {
2131
+ slotName = builders.literal('');
2132
+ }
2133
+ else if (nameAttrValue.type === 'Literal') {
2134
+ const name = typeof nameAttrValue.value === 'string' ? nameAttrValue.value : '';
2135
+ slotName = builders.literal(name);
2136
+ }
2137
+ else {
2138
+ slotName = builders.memberExpression(builders.literal('instance'), nameAttrValue);
2139
+ }
2140
+ // FIXME: avoid serializing the slot's children twice
2141
+ const slotAst = Element(node, ctx);
2142
+ const slotChildren = irChildrenToEs(node.children, ctx);
2143
+ return [bConditionalSlot(slotName, slotChildren, slotAst)];
2144
+ };
2145
+
888
2146
  /*
889
2147
  * Copyright (c) 2024, salesforce.com, inc.
890
2148
  * All rights reserved.
@@ -892,16 +2150,16 @@ const IfBlock = function IfBlock(node, cxt) {
892
2150
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
893
2151
  */
894
2152
  const bYield = (expr) => builders.expressionStatement(builders.yieldExpression(expr));
895
- const bYieldEscapedString = esTemplateWithYield `
2153
+ const bYieldEscapedString = (esTemplateWithYield `
896
2154
  const ${is.identifier} = ${is.expression};
897
- if (typeof ${is.identifier} === 'string') {
898
- yield (${is.literal} && ${is.identifier} === '') ? '\\u200D' : htmlEscape(${is.identifier});
899
- } else if (typeof ${is.identifier} === 'number') {
900
- yield ${is.identifier}.toString();
2155
+ if (typeof ${0} === 'string') {
2156
+ yield (${is.literal} && ${0} === '') ? '\\u200D' : htmlEscape(${0});
2157
+ } else if (typeof ${0} === 'number') {
2158
+ yield ${0}.toString();
901
2159
  } else {
902
- yield htmlEscape((${is.identifier} ?? '').toString());
2160
+ yield ${0} ? htmlEscape(${0}.toString()) : '\\u200D';
903
2161
  }
904
- `;
2162
+ `);
905
2163
  function isLiteral(node) {
906
2164
  return node.type === 'Literal';
907
2165
  }
@@ -914,7 +2172,7 @@ const Text = function Text(node, cxt) {
914
2172
  const valueToYield = expressionIrToEs(node.value, cxt);
915
2173
  cxt.hoist(bImportHtmlEscape(), importHtmlEscapeKey);
916
2174
  const tempVariable = builders.identifier(cxt.getUniqueVar());
917
- return bYieldEscapedString(tempVariable, valueToYield, tempVariable, isIsolatedTextNode, tempVariable, tempVariable, tempVariable, tempVariable, tempVariable);
2175
+ return bYieldEscapedString(tempVariable, valueToYield, isIsolatedTextNode);
918
2176
  };
919
2177
 
920
2178
  /*
@@ -999,7 +2257,7 @@ const transformers = {
999
2257
  // lwc:elseif cannot exist without an lwc:elseif (IfBlock); this gets handled by that transformer
1000
2258
  ElseBlock: defaultTransformer,
1001
2259
  ScopedSlotFragment: defaultTransformer,
1002
- Slot: defaultTransformer,
2260
+ Slot,
1003
2261
  Lwc: defaultTransformer,
1004
2262
  };
1005
2263
  function irChildrenToEs(children, cxt) {
@@ -1013,6 +2271,9 @@ function irChildrenToEs(children, cxt) {
1013
2271
  return result;
1014
2272
  }
1015
2273
  function irToEs(node, cxt) {
2274
+ if ('directives' in node && node.directives.some((d) => d.name === 'Dynamic')) {
2275
+ throw new Error('The lwc:dynamic directive is not supported for SSR. Use <lwc:component> instead.');
2276
+ }
1016
2277
  const transformer = transformers[node.type];
1017
2278
  return transformer(node, cxt);
1018
2279
  }
@@ -1031,13 +2292,14 @@ function templateIrToEsTree(node, contextOpts) {
1031
2292
  * SPDX-License-Identifier: MIT
1032
2293
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1033
2294
  */
1034
- const isBool = (node) => is.literal(node) && typeof node.value === 'boolean';
1035
- const bStyleValidationImport = esTemplate `
2295
+ const bStyleValidationImport = (esTemplate `
1036
2296
  import { validateStyleTextContents } from '@lwc/ssr-runtime';
1037
- `;
1038
- const bExportTemplate = esTemplate `
1039
- export default async function* tmpl(props, attrs, slotted, Cmp, instance) {
1040
- if (!${isBool} && Cmp.renderMode !== 'light') {
2297
+ `);
2298
+ // TODO [#4663]: Render mode mismatch between template and compiler should throw.
2299
+ const bExportTemplate = (esTemplate `
2300
+ export default async function* tmpl(props, attrs, slottedContent, Cmp, instance) {
2301
+ const isLightDom = Cmp.renderMode === 'light';
2302
+ if (!isLightDom) {
1041
2303
  yield \`<template shadowrootmode="open"\${Cmp.delegatesFocus ? ' shadowrootdelegatesfocus' : ''}>\`
1042
2304
  }
1043
2305
 
@@ -1059,29 +2321,54 @@ const bExportTemplate = esTemplate `
1059
2321
 
1060
2322
  ${is.statement};
1061
2323
 
1062
- if (!${isBool} && Cmp.renderMode !== 'light') {
2324
+ if (!isLightDom) {
1063
2325
  yield '</template>';
1064
2326
  }
2327
+
2328
+ if (slottedContent) {
2329
+ yield* slottedContent();
2330
+ }
1065
2331
  }
1066
- `;
2332
+ `);
1067
2333
  function compileTemplate(src, filename, options) {
1068
- const { root, warnings } = parse$1(src);
2334
+ const { root, warnings } = parse$1(src, {
2335
+ // `options` is from @lwc/compiler, and may have flags that @lwc/template-compiler doesn't
2336
+ // know about, so we must explicitly extract the relevant props.
2337
+ name: options.name,
2338
+ namespace: options.namespace,
2339
+ customRendererConfig: options.customRendererConfig,
2340
+ experimentalComputedMemberExpression: options.experimentalComputedMemberExpression,
2341
+ experimentalComplexExpressions: options.experimentalComplexExpressions,
2342
+ enableDynamicComponents: options.enableDynamicComponents,
2343
+ preserveHtmlComments: options.preserveHtmlComments,
2344
+ enableStaticContentOptimization: options.enableStaticContentOptimization,
2345
+ instrumentation: options.instrumentation,
2346
+ apiVersion: options.apiVersion,
2347
+ disableSyntheticShadowSupport: options.disableSyntheticShadowSupport,
2348
+ // TODO [#3331]: remove usage of lwc:dynamic in 246
2349
+ experimentalDynamicDirective: options.experimentalDynamicDirective,
2350
+ });
1069
2351
  if (!root || warnings.length) {
2352
+ let fatal = !root;
1070
2353
  for (const warning of warnings) {
1071
2354
  // eslint-disable-next-line no-console
1072
2355
  console.error('Cannot compile:', warning.message);
2356
+ if (warning.level === DiagnosticLevel.Fatal ||
2357
+ warning.level === DiagnosticLevel.Error) {
2358
+ fatal = true;
2359
+ }
2360
+ }
2361
+ // || !root is just used here to make TypeScript happy
2362
+ if (fatal || !root) {
2363
+ throw new Error('Template compilation failure; see warnings in the console.');
1073
2364
  }
1074
- throw new Error('Template compilation failure; see warnings in the console.');
1075
2365
  }
1076
- const tmplRenderMode = root.directives.find((directive) => directive.name === 'RenderMode')?.value?.value ??
1077
- 'shadow';
1078
- const astShadowModeBool = tmplRenderMode === 'light' ? builders.literal(true) : builders.literal(false);
1079
2366
  const preserveComments = !!root.directives.find((directive) => directive.name === 'PreserveComments')?.value?.value;
1080
2367
  const { hoisted, statements } = templateIrToEsTree(root, { preserveComments });
1081
2368
  const moduleBody = [
1082
2369
  ...hoisted,
1083
2370
  bStyleValidationImport(),
1084
- bExportTemplate(astShadowModeBool, optimizeAdjacentYieldStmts(statements), astShadowModeBool),
2371
+ bExportTemplate(optimizeAdjacentYieldStmts(statements)),
1085
2372
  ];
1086
2373
  const program = builders.program(moduleBody, 'module');
1087
2374
  addScopeTokenDeclarations(program, filename, options.namespace, options.name);
@@ -1108,5 +2395,5 @@ function compileTemplateForSSR(src, filename, options) {
1108
2395
  }
1109
2396
 
1110
2397
  export { compileComponentForSSR, compileTemplateForSSR };
1111
- /** version: 8.2.0 */
2398
+ /** version: 8.3.0 */
1112
2399
  //# sourceMappingURL=index.js.map