@lwc/template-compiler 9.0.4-alpha.1 → 9.0.4-alpha.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.
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, '__esModule', { value: true });
7
7
 
8
8
  var errors = require('@lwc/errors');
9
- var path = require('node:path');
9
+ var path = require('path');
10
10
  var shared = require('@lwc/shared');
11
11
  var he = require('he');
12
12
  var acorn = require('acorn');
@@ -29,6 +29,7 @@ function _interopNamespaceDefault(e) {
29
29
  return Object.freeze(n);
30
30
  }
31
31
 
32
+ var he__namespace = /*#__PURE__*/_interopNamespaceDefault(he);
32
33
  var astring__namespace = /*#__PURE__*/_interopNamespaceDefault(astring);
33
34
 
34
35
  /*
@@ -9266,46 +9267,52 @@ function isAttribute$1(node) {
9266
9267
  return node.type === 'Attribute';
9267
9268
  }
9268
9269
 
9269
- const LWCDirectiveDomMode = {
9270
- manual: 'manual',
9271
- };
9272
- const LWCDirectiveRenderMode = {
9273
- shadow: 'shadow',
9274
- light: 'light',
9275
- };
9270
+ exports.LWCDirectiveDomMode = void 0;
9271
+ (function (LWCDirectiveDomMode) {
9272
+ LWCDirectiveDomMode["manual"] = "manual";
9273
+ })(exports.LWCDirectiveDomMode || (exports.LWCDirectiveDomMode = {}));
9274
+ exports.LWCDirectiveRenderMode = void 0;
9275
+ (function (LWCDirectiveRenderMode) {
9276
+ LWCDirectiveRenderMode["shadow"] = "shadow";
9277
+ LWCDirectiveRenderMode["light"] = "light";
9278
+ })(exports.LWCDirectiveRenderMode || (exports.LWCDirectiveRenderMode = {}));
9276
9279
  /**
9277
9280
  * All supported special LWC tags, they should all begin with lwc:*
9278
9281
  */
9279
- const LwcTagName = {
9280
- Component: 'lwc:component',
9281
- };
9282
- const TemplateDirectiveName = {
9283
- If: 'if:true',
9284
- IfBlock: 'lwc:if',
9285
- ElseifBlock: 'lwc:elseif',
9286
- ElseBlock: 'lwc:else',
9287
- ForEach: 'for:each',
9288
- ForOf: 'for:of',
9289
- ScopedSlotFragment: 'lwc:slot-data',
9290
- };
9291
- const ElementDirectiveName = {
9292
- Dom: 'lwc:dom',
9282
+ exports.LwcTagName = void 0;
9283
+ (function (LwcTagName) {
9284
+ LwcTagName["Component"] = "lwc:component";
9285
+ })(exports.LwcTagName || (exports.LwcTagName = {}));
9286
+ exports.TemplateDirectiveName = void 0;
9287
+ (function (TemplateDirectiveName) {
9288
+ TemplateDirectiveName["If"] = "if:true";
9289
+ TemplateDirectiveName["IfBlock"] = "lwc:if";
9290
+ TemplateDirectiveName["ElseifBlock"] = "lwc:elseif";
9291
+ TemplateDirectiveName["ElseBlock"] = "lwc:else";
9292
+ TemplateDirectiveName["ForEach"] = "for:each";
9293
+ TemplateDirectiveName["ForOf"] = "for:of";
9294
+ TemplateDirectiveName["ScopedSlotFragment"] = "lwc:slot-data";
9295
+ })(exports.TemplateDirectiveName || (exports.TemplateDirectiveName = {}));
9296
+ exports.ElementDirectiveName = void 0;
9297
+ (function (ElementDirectiveName) {
9298
+ ElementDirectiveName["Dom"] = "lwc:dom";
9293
9299
  // TODO [#3331]: remove usage of lwc:dynamic in 246
9294
- Dynamic: 'lwc:dynamic',
9295
- Is: 'lwc:is',
9296
- External: 'lwc:external',
9297
- InnerHTML: 'lwc:inner-html',
9298
- Ref: 'lwc:ref',
9299
- SlotBind: 'lwc:slot-bind',
9300
- SlotData: 'lwc:slot-data',
9301
- Spread: 'lwc:spread',
9302
- On: 'lwc:on',
9303
- Key: 'key',
9304
- };
9305
- const RootDirectiveName = {
9306
- PreserveComments: 'lwc:preserve-comments',
9307
- RenderMode: 'lwc:render-mode',
9308
- };
9300
+ ElementDirectiveName["Dynamic"] = "lwc:dynamic";
9301
+ ElementDirectiveName["Is"] = "lwc:is";
9302
+ ElementDirectiveName["External"] = "lwc:external";
9303
+ ElementDirectiveName["InnerHTML"] = "lwc:inner-html";
9304
+ ElementDirectiveName["Ref"] = "lwc:ref";
9305
+ ElementDirectiveName["SlotBind"] = "lwc:slot-bind";
9306
+ ElementDirectiveName["SlotData"] = "lwc:slot-data";
9307
+ ElementDirectiveName["Spread"] = "lwc:spread";
9308
+ ElementDirectiveName["On"] = "lwc:on";
9309
+ ElementDirectiveName["Key"] = "key";
9310
+ })(exports.ElementDirectiveName || (exports.ElementDirectiveName = {}));
9311
+ exports.RootDirectiveName = void 0;
9312
+ (function (RootDirectiveName) {
9313
+ RootDirectiveName["PreserveComments"] = "lwc:preserve-comments";
9314
+ RootDirectiveName["RenderMode"] = "lwc:render-mode";
9315
+ })(exports.RootDirectiveName || (exports.RootDirectiveName = {}));
9309
9316
 
9310
9317
  /*
9311
9318
  * Copyright (c) 2018, salesforce.com, inc.
@@ -9497,7 +9504,7 @@ const VALID_IF_MODIFIER = new Set(['true', 'false', 'strict-true']);
9497
9504
  const ITERATOR_RE = /^iterator:.*$/;
9498
9505
  const EVENT_HANDLER_RE = /^on/;
9499
9506
  const EVENT_HANDLER_NAME_RE = /^on[a-z][a-z0-9_]*$/;
9500
- const LWC_DIRECTIVE_SET = new Set(Object.values(ElementDirectiveName));
9507
+ const LWC_DIRECTIVE_SET = new Set(Object.values(exports.ElementDirectiveName));
9501
9508
  const ATTRIBUTE_NAME_CHAR = [
9502
9509
  ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-',
9503
9510
  '\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD',
@@ -9643,7 +9650,7 @@ class ParserCtx {
9643
9650
  this.siblingScopes = [];
9644
9651
  this.source = source;
9645
9652
  this.config = config;
9646
- this.renderMode = LWCDirectiveRenderMode.shadow;
9653
+ this.renderMode = exports.LWCDirectiveRenderMode.shadow;
9647
9654
  this.preserveComments = config.preserveHtmlComments;
9648
9655
  this.ecmaVersion = config.experimentalComplexExpressions
9649
9656
  ? TMPL_EXPR_ECMASCRIPT_EDITION
@@ -10056,7 +10063,7 @@ function cleanTextNode(value) {
10056
10063
  return str;
10057
10064
  }
10058
10065
  function decodeTextContent(source) {
10059
- return he.decode(source);
10066
+ return he__namespace.decode(source);
10060
10067
  }
10061
10068
 
10062
10069
  /*
@@ -10609,7 +10616,8 @@ function parseExpression(ctx, source, location, unquotedAttributeExpression) {
10609
10616
  }, errors.ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR, location, (err) => `Invalid expression ${source} - ${err.message}`);
10610
10617
  }
10611
10618
  function parseIdentifier(ctx, source, location) {
10612
- let isValid = acorn.isIdentifierStart(source.charCodeAt(0));
10619
+ let isValid = true;
10620
+ isValid = acorn.isIdentifierStart(source.charCodeAt(0));
10613
10621
  for (let i = 1; i < source.length && isValid; i++) {
10614
10622
  isValid = acorn.isIdentifierChar(source.charCodeAt(i));
10615
10623
  }
@@ -11434,7 +11442,7 @@ function parseBaseElement(ctx, parsedAttr, parse5Elm, parent, parse5ElmLocation)
11434
11442
  // Check if the element tag is a valid custom element name and is not part of known standard
11435
11443
  // element name containing a dash.
11436
11444
  if (isCustomElementTag(tag)) {
11437
- if (parsedAttr.get(ElementDirectiveName.External)) {
11445
+ if (parsedAttr.get(exports.ElementDirectiveName.External)) {
11438
11446
  element$1 = externalComponent(tag, parse5ElmLocation);
11439
11447
  }
11440
11448
  else {
@@ -11459,7 +11467,7 @@ function parseBaseElement(ctx, parsedAttr, parse5Elm, parent, parse5ElmLocation)
11459
11467
  function parseLwcElement(ctx, parse5Elm, parsedAttr, parse5ElmLocation) {
11460
11468
  let lwcElementParser;
11461
11469
  switch (parse5Elm.tagName) {
11462
- case LwcTagName.Component:
11470
+ case exports.LwcTagName.Component:
11463
11471
  lwcElementParser = parseLwcComponent;
11464
11472
  break;
11465
11473
  default:
@@ -11472,7 +11480,7 @@ function parseLwcComponent(ctx, parse5Elm, parsedAttr, parse5ElmLocation) {
11472
11480
  ctx.throwAtLocation(errors.ParserDiagnostics.INVALID_OPTS_LWC_ENABLE_DYNAMIC_COMPONENTS, sourceLocation(parse5ElmLocation));
11473
11481
  }
11474
11482
  // <lwc:component> must be used with lwc:is directive
11475
- if (!parsedAttr.get(ElementDirectiveName.Is)) {
11483
+ if (!parsedAttr.get(exports.ElementDirectiveName.Is)) {
11476
11484
  ctx.throwAtLocation(errors.ParserDiagnostics.LWC_COMPONENT_TAG_WITHOUT_IS_DIRECTIVE, sourceLocation(parse5ElmLocation));
11477
11485
  }
11478
11486
  return lwcComponent(parse5Elm.tagName, parse5ElmLocation);
@@ -11747,21 +11755,21 @@ function applyRootLwcDirectives(ctx, parsedAttr, root) {
11747
11755
  applyLwcPreserveCommentsDirective(ctx, parsedAttr, root);
11748
11756
  }
11749
11757
  function applyLwcRenderModeDirective(ctx, parsedAttr, root) {
11750
- const lwcRenderModeAttribute = parsedAttr.pick(RootDirectiveName.RenderMode);
11758
+ const lwcRenderModeAttribute = parsedAttr.pick(exports.RootDirectiveName.RenderMode);
11751
11759
  if (!lwcRenderModeAttribute) {
11752
11760
  return;
11753
11761
  }
11754
11762
  const { value: renderDomAttr } = lwcRenderModeAttribute;
11755
11763
  if (!isStringLiteral(renderDomAttr) ||
11756
- (renderDomAttr.value !== LWCDirectiveRenderMode.shadow &&
11757
- renderDomAttr.value !== LWCDirectiveRenderMode.light)) {
11764
+ (renderDomAttr.value !== exports.LWCDirectiveRenderMode.shadow &&
11765
+ renderDomAttr.value !== exports.LWCDirectiveRenderMode.light)) {
11758
11766
  ctx.throwOnNode(errors.ParserDiagnostics.LWC_RENDER_MODE_INVALID_VALUE, root);
11759
11767
  }
11760
11768
  root.directives.push(renderModeDirective(renderDomAttr.value, lwcRenderModeAttribute.location));
11761
11769
  ctx.instrumentation?.incrementCounter(errors.CompilerMetrics.LWCRenderModeDirective);
11762
11770
  }
11763
11771
  function applyLwcPreserveCommentsDirective(ctx, parsedAttr, root) {
11764
- const lwcPreserveCommentAttribute = parsedAttr.pick(RootDirectiveName.PreserveComments);
11772
+ const lwcPreserveCommentAttribute = parsedAttr.pick(exports.RootDirectiveName.PreserveComments);
11765
11773
  if (!lwcPreserveCommentAttribute) {
11766
11774
  return;
11767
11775
  }
@@ -11794,15 +11802,15 @@ function applyLwcDirectives(ctx, parsedAttr, element) {
11794
11802
  ]);
11795
11803
  }
11796
11804
  // Should not allow render mode or preserve comments on non root nodes
11797
- if (parsedAttr.get(RootDirectiveName.RenderMode)) {
11805
+ if (parsedAttr.get(exports.RootDirectiveName.RenderMode)) {
11798
11806
  ctx.throwOnNode(errors.ParserDiagnostics.UNKNOWN_LWC_DIRECTIVE, element, [
11799
- RootDirectiveName.RenderMode,
11807
+ exports.RootDirectiveName.RenderMode,
11800
11808
  `<${element.name}>`,
11801
11809
  ]);
11802
11810
  }
11803
- if (parsedAttr.get(RootDirectiveName.PreserveComments)) {
11811
+ if (parsedAttr.get(exports.RootDirectiveName.PreserveComments)) {
11804
11812
  ctx.throwOnNode(errors.ParserDiagnostics.UNKNOWN_LWC_DIRECTIVE, element, [
11805
- RootDirectiveName.PreserveComments,
11813
+ exports.RootDirectiveName.PreserveComments,
11806
11814
  `<${element.name}>`,
11807
11815
  ]);
11808
11816
  }
@@ -11813,7 +11821,7 @@ function applyLwcDirectives(ctx, parsedAttr, element) {
11813
11821
  }
11814
11822
  function applyLwcSlotBindDirective(ctx, parsedAttr, element) {
11815
11823
  const { name: tag } = element;
11816
- const slotBindAttribute = parsedAttr.pick(ElementDirectiveName.SlotBind);
11824
+ const slotBindAttribute = parsedAttr.pick(exports.ElementDirectiveName.SlotBind);
11817
11825
  if (!slotBindAttribute) {
11818
11826
  return;
11819
11827
  }
@@ -11832,7 +11840,7 @@ function applyLwcSlotBindDirective(ctx, parsedAttr, element) {
11832
11840
  }
11833
11841
  function applyLwcSpreadDirective(ctx, parsedAttr, element) {
11834
11842
  const { name: tag } = element;
11835
- const lwcSpread = parsedAttr.pick(ElementDirectiveName.Spread);
11843
+ const lwcSpread = parsedAttr.pick(exports.ElementDirectiveName.Spread);
11836
11844
  if (!lwcSpread) {
11837
11845
  return;
11838
11846
  }
@@ -11844,7 +11852,7 @@ function applyLwcSpreadDirective(ctx, parsedAttr, element) {
11844
11852
  }
11845
11853
  function applyLwcOnDirective(ctx, parsedAttr, element) {
11846
11854
  const { name: tag } = element;
11847
- const lwcOn = parsedAttr.pick(ElementDirectiveName.On);
11855
+ const lwcOn = parsedAttr.pick(exports.ElementDirectiveName.On);
11848
11856
  if (!lwcOn) {
11849
11857
  return;
11850
11858
  }
@@ -11865,7 +11873,7 @@ function applyLwcOnDirective(ctx, parsedAttr, element) {
11865
11873
  element.directives.push(OnDirective(lwcOnValue, lwcOn.location));
11866
11874
  }
11867
11875
  function applyLwcExternalDirective(ctx, parsedAttr, element) {
11868
- const lwcExternalAttribute = parsedAttr.pick(ElementDirectiveName.External);
11876
+ const lwcExternalAttribute = parsedAttr.pick(exports.ElementDirectiveName.External);
11869
11877
  if (!lwcExternalAttribute) {
11870
11878
  return;
11871
11879
  }
@@ -11882,7 +11890,7 @@ function applyLwcExternalDirective(ctx, parsedAttr, element) {
11882
11890
  }
11883
11891
  function applyLwcDynamicDirective(ctx, parsedAttr, element) {
11884
11892
  const { name: tag } = element;
11885
- const lwcDynamicAttribute = parsedAttr.pick(ElementDirectiveName.Dynamic);
11893
+ const lwcDynamicAttribute = parsedAttr.pick(exports.ElementDirectiveName.Dynamic);
11886
11894
  if (!lwcDynamicAttribute) {
11887
11895
  return;
11888
11896
  }
@@ -11905,7 +11913,7 @@ function applyLwcDynamicDirective(ctx, parsedAttr, element) {
11905
11913
  }
11906
11914
  function applyLwcIsDirective(ctx, parsedAttr, element) {
11907
11915
  const { name: tag } = element;
11908
- const lwcIsAttribute = parsedAttr.pick(ElementDirectiveName.Is);
11916
+ const lwcIsAttribute = parsedAttr.pick(exports.ElementDirectiveName.Is);
11909
11917
  if (!lwcIsAttribute) {
11910
11918
  return;
11911
11919
  }
@@ -11926,7 +11934,7 @@ function applyLwcDomDirective(ctx, parsedAttr, element) {
11926
11934
  if (!lwcDomAttribute) {
11927
11935
  return;
11928
11936
  }
11929
- if (ctx.renderMode === LWCDirectiveRenderMode.light) {
11937
+ if (ctx.renderMode === exports.LWCDirectiveRenderMode.light) {
11930
11938
  ctx.throwOnNode(errors.ParserDiagnostics.LWC_DOM_INVALID_IN_LIGHT_DOM, element, [`<${tag}>`]);
11931
11939
  }
11932
11940
  if (isComponent(element)) {
@@ -11936,8 +11944,8 @@ function applyLwcDomDirective(ctx, parsedAttr, element) {
11936
11944
  ctx.throwOnNode(errors.ParserDiagnostics.LWC_DOM_INVALID_SLOT_ELEMENT, element);
11937
11945
  }
11938
11946
  const { value: lwcDomAttr } = lwcDomAttribute;
11939
- if (!isStringLiteral(lwcDomAttr) || lwcDomAttr.value !== LWCDirectiveDomMode.manual) {
11940
- const possibleValues = Object.keys(LWCDirectiveDomMode)
11947
+ if (!isStringLiteral(lwcDomAttr) || lwcDomAttr.value !== exports.LWCDirectiveDomMode.manual) {
11948
+ const possibleValues = Object.keys(exports.LWCDirectiveDomMode)
11941
11949
  .map((value) => `"${value}"`)
11942
11950
  .join(', or ');
11943
11951
  ctx.throwOnNode(errors.ParserDiagnostics.LWC_DOM_INVALID_VALUE, element, [possibleValues]);
@@ -11945,7 +11953,7 @@ function applyLwcDomDirective(ctx, parsedAttr, element) {
11945
11953
  element.directives.push(domDirective(lwcDomAttr.value, lwcDomAttribute.location));
11946
11954
  }
11947
11955
  function applyLwcInnerHtmlDirective(ctx, parsedAttr, element) {
11948
- const lwcInnerHtmlDirective = parsedAttr.pick(ElementDirectiveName.InnerHTML);
11956
+ const lwcInnerHtmlDirective = parsedAttr.pick(exports.ElementDirectiveName.InnerHTML);
11949
11957
  if (!lwcInnerHtmlDirective) {
11950
11958
  return;
11951
11959
  }
@@ -11968,7 +11976,7 @@ function applyLwcInnerHtmlDirective(ctx, parsedAttr, element) {
11968
11976
  element.directives.push(innerHTMLDirective(innerHTMLVal, lwcInnerHtmlDirective.location));
11969
11977
  }
11970
11978
  function applyRefDirective(ctx, parsedAttr, element) {
11971
- const lwcRefDirective = parsedAttr.pick(ElementDirectiveName.Ref);
11979
+ const lwcRefDirective = parsedAttr.pick(exports.ElementDirectiveName.Ref);
11972
11980
  if (!lwcRefDirective) {
11973
11981
  return;
11974
11982
  }
@@ -12039,7 +12047,7 @@ function parseForOf(ctx, _parse5Elm, parse5ElmLocation, parent, parsedAttr) {
12039
12047
  return node;
12040
12048
  }
12041
12049
  function parseScopedSlotFragment(ctx, parse5Elm, parse5ElmLocation, parent, parsedAttr) {
12042
- const slotDataAttr = parsedAttr.pick(ElementDirectiveName.SlotData);
12050
+ const slotDataAttr = parsedAttr.pick(exports.ElementDirectiveName.SlotData);
12043
12051
  if (!slotDataAttr) {
12044
12052
  return;
12045
12053
  }
@@ -12077,7 +12085,7 @@ function parseScopedSlotFragment(ctx, parse5Elm, parse5ElmLocation, parent, pars
12077
12085
  }
12078
12086
  function applyKey(ctx, parsedAttr, element) {
12079
12087
  const { name: tag } = element;
12080
- const keyAttribute = parsedAttr.pick(ElementDirectiveName.Key);
12088
+ const keyAttribute = parsedAttr.pick(exports.ElementDirectiveName.Key);
12081
12089
  if (keyAttribute) {
12082
12090
  if (!isExpression$1(keyAttribute.value)) {
12083
12091
  ctx.throwOnNode(errors.ParserDiagnostics.KEY_ATTRIBUTE_SHOULD_BE_EXPRESSION, keyAttribute);
@@ -12106,18 +12114,18 @@ function applyKey(ctx, parsedAttr, element) {
12106
12114
  ctx.throwOnNode(errors.ParserDiagnostics.MISSING_KEY_IN_ITERATOR, element, [tag]);
12107
12115
  }
12108
12116
  }
12109
- const RESTRICTED_DIRECTIVES_ON_SLOT = Object.values(TemplateDirectiveName).join(', ');
12117
+ const RESTRICTED_DIRECTIVES_ON_SLOT = Object.values(exports.TemplateDirectiveName).join(', ');
12110
12118
  const ALLOWED_SLOT_ATTRIBUTES = [
12111
- ElementDirectiveName.Key,
12112
- ElementDirectiveName.SlotBind,
12119
+ exports.ElementDirectiveName.Key,
12120
+ exports.ElementDirectiveName.SlotBind,
12113
12121
  'name',
12114
12122
  'slot',
12115
12123
  ];
12116
12124
  const ALLOWED_SLOT_ATTRIBUTES_SET = new Set(ALLOWED_SLOT_ATTRIBUTES);
12117
12125
  function parseSlot(ctx, parsedAttr, parse5ElmLocation) {
12118
12126
  const location = sourceLocation(parse5ElmLocation);
12119
- const isScopedSlot = !shared.isUndefined(parsedAttr.get(ElementDirectiveName.SlotBind));
12120
- if (isScopedSlot && ctx.renderMode !== LWCDirectiveRenderMode.light) {
12127
+ const isScopedSlot = !shared.isUndefined(parsedAttr.get(exports.ElementDirectiveName.SlotBind));
12128
+ if (isScopedSlot && ctx.renderMode !== exports.LWCDirectiveRenderMode.light) {
12121
12129
  ctx.throwAtLocation(errors.ParserDiagnostics.SCOPED_SLOT_BIND_IN_LIGHT_DOM_ONLY, location);
12122
12130
  }
12123
12131
  // Restrict specific template directives on <slot> element
@@ -12128,7 +12136,7 @@ function parseSlot(ctx, parsedAttr, parse5ElmLocation) {
12128
12136
  ]);
12129
12137
  }
12130
12138
  // Can't handle slots in applySlot because it would be too late for class and style attrs
12131
- if (ctx.renderMode === LWCDirectiveRenderMode.light) {
12139
+ if (ctx.renderMode === exports.LWCDirectiveRenderMode.light) {
12132
12140
  const invalidAttrs = parsedAttr
12133
12141
  .getAttributes()
12134
12142
  .filter(({ name }) => !ALLOWED_SLOT_ATTRIBUTES_SET.has(name))
@@ -12310,21 +12318,21 @@ function validateTemplate(ctx, parsedAttr, template, parse5ElmLocation) {
12310
12318
  if (!template.attrs.length) {
12311
12319
  ctx.throwAtLocation(errors.ParserDiagnostics.NO_DIRECTIVE_FOUND_ON_TEMPLATE, location);
12312
12320
  }
12313
- if (parsedAttr.get(ElementDirectiveName.External)) {
12321
+ if (parsedAttr.get(exports.ElementDirectiveName.External)) {
12314
12322
  ctx.throwAtLocation(errors.ParserDiagnostics.INVALID_LWC_EXTERNAL_ON_NON_CUSTOM_ELEMENT, location, ['<template>']);
12315
12323
  }
12316
- if (parsedAttr.get(ElementDirectiveName.InnerHTML)) {
12324
+ if (parsedAttr.get(exports.ElementDirectiveName.InnerHTML)) {
12317
12325
  ctx.throwAtLocation(errors.ParserDiagnostics.LWC_INNER_HTML_INVALID_ELEMENT, location, [
12318
12326
  '<template>',
12319
12327
  ]);
12320
12328
  }
12321
- if (parsedAttr.get(ElementDirectiveName.Ref)) {
12329
+ if (parsedAttr.get(exports.ElementDirectiveName.Ref)) {
12322
12330
  ctx.throwAtLocation(errors.ParserDiagnostics.LWC_REF_INVALID_ELEMENT, location, ['<template>']);
12323
12331
  }
12324
- if (parsedAttr.get(ElementDirectiveName.Is)) {
12332
+ if (parsedAttr.get(exports.ElementDirectiveName.Is)) {
12325
12333
  ctx.throwAtLocation(errors.ParserDiagnostics.LWC_IS_INVALID_ELEMENT, location, ['<template>']);
12326
12334
  }
12327
- if (parsedAttr.get(ElementDirectiveName.On)) {
12335
+ if (parsedAttr.get(exports.ElementDirectiveName.On)) {
12328
12336
  if (!ctx.config.enableLwcOn) {
12329
12337
  ctx.throwAtLocation(errors.ParserDiagnostics.INVALID_LWC_ON_OPTS, location, ['<template>']);
12330
12338
  }
@@ -12526,9 +12534,10 @@ function shouldAddCustomRenderer(element, state) {
12526
12534
  }
12527
12535
  const { attributes, directives } = element;
12528
12536
  if (directives.length) {
12537
+ let directiveMatched = false;
12529
12538
  // If any directives require custom renderer
12530
- const directiveMatched = directives.some((dir) => {
12531
- return state.crDirectives.has(ElementDirectiveName[dir.name]);
12539
+ directiveMatched = directives.some((dir) => {
12540
+ return state.crDirectives.has(exports.ElementDirectiveName[dir.name]);
12532
12541
  });
12533
12542
  if (directiveMatched) {
12534
12543
  return true;
@@ -12600,7 +12609,7 @@ function shouldFlatten(codeGen, children) {
12600
12609
  // light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
12601
12610
  (!shared.isAPIFeatureEnabled(2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */, codeGen.apiVersion) &&
12602
12611
  isSlot(child) &&
12603
- codeGen.renderMode === LWCDirectiveRenderMode.light) ||
12612
+ codeGen.renderMode === exports.LWCDirectiveRenderMode.light) ||
12604
12613
  // If node is only a control flow node and does not map to a stand alone element.
12605
12614
  // Search children to determine if it should be flattened.
12606
12615
  (isIf(child) && shouldFlatten(codeGen, child.children)));
@@ -12633,7 +12642,7 @@ function generateTemplateMetadata(codeGen) {
12633
12642
  metadataExpressions.push(expressionStatement(slotsMetadata));
12634
12643
  }
12635
12644
  // ignore when shadow because we don't want to modify template unnecessarily
12636
- if (codeGen.renderMode === LWCDirectiveRenderMode.light) {
12645
+ if (codeGen.renderMode === exports.LWCDirectiveRenderMode.light) {
12637
12646
  const renderModeMetadata = assignmentExpression('=', memberExpression(identifier(TEMPLATE_FUNCTION_NAME), identifier('renderMode')), literal$1('light'));
12638
12647
  metadataExpressions.push(expressionStatement(renderModeMetadata));
12639
12648
  }
@@ -13359,7 +13368,7 @@ class CodeGen {
13359
13368
  }
13360
13369
  this.renderMode =
13361
13370
  root.directives.find(isRenderModeDirective)?.value.value ??
13362
- LWCDirectiveRenderMode.shadow;
13371
+ exports.LWCDirectiveRenderMode.shadow;
13363
13372
  this.preserveComments =
13364
13373
  root.directives.find(isPreserveCommentsDirective)?.value.value ??
13365
13374
  state.config.preserveHtmlComments;
@@ -13368,7 +13377,7 @@ class CodeGen {
13368
13377
  this.state = state;
13369
13378
  this.apiVersion = shared.getAPIVersionFromNumber(state.config.apiVersion);
13370
13379
  this.isSyntheticShadow =
13371
- this.renderMode !== LWCDirectiveRenderMode.light &&
13380
+ this.renderMode !== exports.LWCDirectiveRenderMode.light &&
13372
13381
  !this.state.config.disableSyntheticShadowSupport;
13373
13382
  }
13374
13383
  generateKey() {
@@ -13762,7 +13771,7 @@ class CodeGen {
13762
13771
  // then static IDs/IDrefs/fragment refs will be rendered directly into HTML strings.
13763
13772
  const needsScoping = this.isSyntheticShadow && (isIdOrIdRef || isScopedFragmentRef);
13764
13773
  if (isExpression$1(value) || isSvgHref || needsScoping) {
13765
- let partToken;
13774
+ let partToken = '';
13766
13775
  if (name === 'style') {
13767
13776
  partToken = `${"s" /* STATIC_PART_TOKEN_ID.STYLE */}${partId}`;
13768
13777
  databag.push(property$1(identifier('style'), this.bindExpression(value)));
@@ -14563,12 +14572,6 @@ function compile(source, filename, config) {
14563
14572
  };
14564
14573
  }
14565
14574
 
14566
- exports.ElementDirectiveName = ElementDirectiveName;
14567
- exports.LWCDirectiveDomMode = LWCDirectiveDomMode;
14568
- exports.LWCDirectiveRenderMode = LWCDirectiveRenderMode;
14569
- exports.LwcTagName = LwcTagName;
14570
- exports.RootDirectiveName = RootDirectiveName;
14571
- exports.TemplateDirectiveName = TemplateDirectiveName;
14572
14575
  exports.bindExpression = bindExpression;
14573
14576
  exports.compile = compile;
14574
14577
  exports.default = compile;
@@ -14576,5 +14579,5 @@ exports.generateScopeTokens = generateScopeTokens;
14576
14579
  exports.kebabcaseToCamelcase = kebabcaseToCamelcase;
14577
14580
  exports.parse = parse;
14578
14581
  exports.toPropertyName = toPropertyName;
14579
- /** version: 9.0.4-alpha.1 */
14580
- //# sourceMappingURL=index.cjs.map
14582
+ /** version: 9.0.4-alpha.2 */
14583
+ //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { Config } from './config';
2
2
  import type { TemplateCompileResult, TemplateParseResult } from './shared/types';
3
3
  export * from './shared/types';
4
- export type { CustomRendererConfig, CustomRendererElementConfig } from './shared/renderer-hooks';
5
- export type { Config } from './config';
4
+ export { CustomRendererConfig, CustomRendererElementConfig } from './shared/renderer-hooks';
5
+ export { Config } from './config';
6
6
  export { toPropertyName } from './shared/utils';
7
7
  export { kebabcaseToCamelcase } from './shared/naming';
8
8
  export { generateScopeTokens } from './scopeTokens';
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) 2026 Salesforce, Inc.
3
3
  */
4
4
  import { invariant, TemplateErrors, generateCompilerError, CompilerError, normalizeToDiagnostic, generateCompilerDiagnostic, ParserDiagnostics, DiagnosticLevel, CompilerMetrics } from '@lwc/errors';
5
- import path from 'node:path';
5
+ import path from 'path';
6
6
  import { StringCharAt, hasOwnProperty, getAPIVersionFromNumber, HTML_NAMESPACE, AriaAttrNameToPropNameMap, fromEntries, ArrayFrom, SPECIAL_PROPERTY_ATTRIBUTE_MAPPING, isAPIFeatureEnabled, minApiVersion, ID_REFERENCING_ATTRIBUTES_SET, SVG_NAMESPACE, isBooleanAttribute, isGlobalHtmlAttribute, isAriaAttribute, isVoidElement, MATHML_NAMESPACE, isNull, isUndefined, IMPORTANT_FLAG, isArray, ArrayEvery, ArraySome, normalizeStyleAttributeValue, htmlEscape, parseStyleText, LWC_VERSION_COMMENT } from '@lwc/shared';
7
- import he from 'he';
7
+ import * as he from 'he';
8
8
  import { parseExpressionAt, isIdentifierStart, isIdentifierChar } from 'acorn';
9
9
  import * as astring from 'astring';
10
10
 
@@ -9243,46 +9243,52 @@ function isAttribute$1(node) {
9243
9243
  return node.type === 'Attribute';
9244
9244
  }
9245
9245
 
9246
- const LWCDirectiveDomMode = {
9247
- manual: 'manual',
9248
- };
9249
- const LWCDirectiveRenderMode = {
9250
- shadow: 'shadow',
9251
- light: 'light',
9252
- };
9246
+ var LWCDirectiveDomMode;
9247
+ (function (LWCDirectiveDomMode) {
9248
+ LWCDirectiveDomMode["manual"] = "manual";
9249
+ })(LWCDirectiveDomMode || (LWCDirectiveDomMode = {}));
9250
+ var LWCDirectiveRenderMode;
9251
+ (function (LWCDirectiveRenderMode) {
9252
+ LWCDirectiveRenderMode["shadow"] = "shadow";
9253
+ LWCDirectiveRenderMode["light"] = "light";
9254
+ })(LWCDirectiveRenderMode || (LWCDirectiveRenderMode = {}));
9253
9255
  /**
9254
9256
  * All supported special LWC tags, they should all begin with lwc:*
9255
9257
  */
9256
- const LwcTagName = {
9257
- Component: 'lwc:component',
9258
- };
9259
- const TemplateDirectiveName = {
9260
- If: 'if:true',
9261
- IfBlock: 'lwc:if',
9262
- ElseifBlock: 'lwc:elseif',
9263
- ElseBlock: 'lwc:else',
9264
- ForEach: 'for:each',
9265
- ForOf: 'for:of',
9266
- ScopedSlotFragment: 'lwc:slot-data',
9267
- };
9268
- const ElementDirectiveName = {
9269
- Dom: 'lwc:dom',
9258
+ var LwcTagName;
9259
+ (function (LwcTagName) {
9260
+ LwcTagName["Component"] = "lwc:component";
9261
+ })(LwcTagName || (LwcTagName = {}));
9262
+ var TemplateDirectiveName;
9263
+ (function (TemplateDirectiveName) {
9264
+ TemplateDirectiveName["If"] = "if:true";
9265
+ TemplateDirectiveName["IfBlock"] = "lwc:if";
9266
+ TemplateDirectiveName["ElseifBlock"] = "lwc:elseif";
9267
+ TemplateDirectiveName["ElseBlock"] = "lwc:else";
9268
+ TemplateDirectiveName["ForEach"] = "for:each";
9269
+ TemplateDirectiveName["ForOf"] = "for:of";
9270
+ TemplateDirectiveName["ScopedSlotFragment"] = "lwc:slot-data";
9271
+ })(TemplateDirectiveName || (TemplateDirectiveName = {}));
9272
+ var ElementDirectiveName;
9273
+ (function (ElementDirectiveName) {
9274
+ ElementDirectiveName["Dom"] = "lwc:dom";
9270
9275
  // TODO [#3331]: remove usage of lwc:dynamic in 246
9271
- Dynamic: 'lwc:dynamic',
9272
- Is: 'lwc:is',
9273
- External: 'lwc:external',
9274
- InnerHTML: 'lwc:inner-html',
9275
- Ref: 'lwc:ref',
9276
- SlotBind: 'lwc:slot-bind',
9277
- SlotData: 'lwc:slot-data',
9278
- Spread: 'lwc:spread',
9279
- On: 'lwc:on',
9280
- Key: 'key',
9281
- };
9282
- const RootDirectiveName = {
9283
- PreserveComments: 'lwc:preserve-comments',
9284
- RenderMode: 'lwc:render-mode',
9285
- };
9276
+ ElementDirectiveName["Dynamic"] = "lwc:dynamic";
9277
+ ElementDirectiveName["Is"] = "lwc:is";
9278
+ ElementDirectiveName["External"] = "lwc:external";
9279
+ ElementDirectiveName["InnerHTML"] = "lwc:inner-html";
9280
+ ElementDirectiveName["Ref"] = "lwc:ref";
9281
+ ElementDirectiveName["SlotBind"] = "lwc:slot-bind";
9282
+ ElementDirectiveName["SlotData"] = "lwc:slot-data";
9283
+ ElementDirectiveName["Spread"] = "lwc:spread";
9284
+ ElementDirectiveName["On"] = "lwc:on";
9285
+ ElementDirectiveName["Key"] = "key";
9286
+ })(ElementDirectiveName || (ElementDirectiveName = {}));
9287
+ var RootDirectiveName;
9288
+ (function (RootDirectiveName) {
9289
+ RootDirectiveName["PreserveComments"] = "lwc:preserve-comments";
9290
+ RootDirectiveName["RenderMode"] = "lwc:render-mode";
9291
+ })(RootDirectiveName || (RootDirectiveName = {}));
9286
9292
 
9287
9293
  /*
9288
9294
  * Copyright (c) 2018, salesforce.com, inc.
@@ -10586,7 +10592,8 @@ function parseExpression(ctx, source, location, unquotedAttributeExpression) {
10586
10592
  }, ParserDiagnostics.TEMPLATE_EXPRESSION_PARSING_ERROR, location, (err) => `Invalid expression ${source} - ${err.message}`);
10587
10593
  }
10588
10594
  function parseIdentifier(ctx, source, location) {
10589
- let isValid = isIdentifierStart(source.charCodeAt(0));
10595
+ let isValid = true;
10596
+ isValid = isIdentifierStart(source.charCodeAt(0));
10590
10597
  for (let i = 1; i < source.length && isValid; i++) {
10591
10598
  isValid = isIdentifierChar(source.charCodeAt(i));
10592
10599
  }
@@ -12503,8 +12510,9 @@ function shouldAddCustomRenderer(element, state) {
12503
12510
  }
12504
12511
  const { attributes, directives } = element;
12505
12512
  if (directives.length) {
12513
+ let directiveMatched = false;
12506
12514
  // If any directives require custom renderer
12507
- const directiveMatched = directives.some((dir) => {
12515
+ directiveMatched = directives.some((dir) => {
12508
12516
  return state.crDirectives.has(ElementDirectiveName[dir.name]);
12509
12517
  });
12510
12518
  if (directiveMatched) {
@@ -13739,7 +13747,7 @@ class CodeGen {
13739
13747
  // then static IDs/IDrefs/fragment refs will be rendered directly into HTML strings.
13740
13748
  const needsScoping = this.isSyntheticShadow && (isIdOrIdRef || isScopedFragmentRef);
13741
13749
  if (isExpression$1(value) || isSvgHref || needsScoping) {
13742
- let partToken;
13750
+ let partToken = '';
13743
13751
  if (name === 'style') {
13744
13752
  partToken = `${"s" /* STATIC_PART_TOKEN_ID.STYLE */}${partId}`;
13745
13753
  databag.push(property$1(identifier('style'), this.bindExpression(value)));
@@ -14541,5 +14549,5 @@ function compile(source, filename, config) {
14541
14549
  }
14542
14550
 
14543
14551
  export { ElementDirectiveName, LWCDirectiveDomMode, LWCDirectiveRenderMode, LwcTagName, RootDirectiveName, TemplateDirectiveName, bindExpression, compile, compile as default, generateScopeTokens, kebabcaseToCamelcase, parse, toPropertyName };
14544
- /** version: 9.0.4-alpha.1 */
14552
+ /** version: 9.0.4-alpha.2 */
14545
14553
  //# sourceMappingURL=index.js.map
@@ -8,15 +8,13 @@ export interface TemplateCompileResult extends TemplateParseResult {
8
8
  code: string;
9
9
  cssScopeTokens: string[];
10
10
  }
11
- export declare const LWCDirectiveDomMode: {
12
- readonly manual: "manual";
13
- };
14
- export type LWCDirectiveDomMode = (typeof LWCDirectiveDomMode)[keyof typeof LWCDirectiveDomMode];
15
- export declare const LWCDirectiveRenderMode: {
16
- readonly shadow: "shadow";
17
- readonly light: "light";
18
- };
19
- export type LWCDirectiveRenderMode = (typeof LWCDirectiveRenderMode)[keyof typeof LWCDirectiveRenderMode];
11
+ export declare enum LWCDirectiveDomMode {
12
+ manual = "manual"
13
+ }
14
+ export declare enum LWCDirectiveRenderMode {
15
+ shadow = "shadow",
16
+ light = "light"
17
+ }
20
18
  export interface BaseNode {
21
19
  type: string;
22
20
  location: SourceLocation;
@@ -161,25 +159,24 @@ export interface LwcComponent extends BaseLwcElement<'lwc:component'> {
161
159
  /**
162
160
  * All supported special LWC tags, they should all begin with lwc:*
163
161
  */
164
- export declare const LwcTagName: {
165
- readonly Component: "lwc:component";
166
- };
167
- export type LwcTagName = (typeof LwcTagName)[keyof typeof LwcTagName];
162
+ export declare enum LwcTagName {
163
+ Component = "lwc:component"
164
+ }
168
165
  export type BaseElement = Element | ExternalComponent | Component | Slot | LwcComponent;
169
166
  export interface Root extends BaseParentNode {
170
167
  type: 'Root';
171
168
  location: ElementSourceLocation;
172
169
  directives: RootDirective[];
173
170
  }
174
- export declare const TemplateDirectiveName: {
175
- readonly If: "if:true";
176
- readonly IfBlock: "lwc:if";
177
- readonly ElseifBlock: "lwc:elseif";
178
- readonly ElseBlock: "lwc:else";
179
- readonly ForEach: "for:each";
180
- readonly ForOf: "for:of";
181
- readonly ScopedSlotFragment: "lwc:slot-data";
182
- };
171
+ export declare enum TemplateDirectiveName {
172
+ If = "if:true",
173
+ IfBlock = "lwc:if",
174
+ ElseifBlock = "lwc:elseif",
175
+ ElseBlock = "lwc:else",
176
+ ForEach = "for:each",
177
+ ForOf = "for:of",
178
+ ScopedSlotFragment = "lwc:slot-data"
179
+ }
183
180
  interface DirectiveParentNode<T extends keyof typeof TemplateDirectiveName> extends BaseParentNode {
184
181
  directiveLocation: SourceLocation;
185
182
  type: T;
@@ -230,22 +227,22 @@ export type ForBlock = ForEach | ForOf;
230
227
  export type ParentNode = Root | ForBlock | If | IfBlock | ElseifBlock | ElseBlock | BaseElement | ScopedSlotFragment;
231
228
  export type ChildNode = ForBlock | If | IfBlock | ElseifBlock | ElseBlock | BaseElement | Comment | Text | ScopedSlotFragment;
232
229
  export type Node = Root | ForBlock | If | IfBlock | ElseifBlock | ElseBlock | BaseElement | Comment | Text | ScopedSlotFragment;
233
- export declare const ElementDirectiveName: {
234
- readonly Dom: "lwc:dom";
235
- readonly Dynamic: "lwc:dynamic";
236
- readonly Is: "lwc:is";
237
- readonly External: "lwc:external";
238
- readonly InnerHTML: "lwc:inner-html";
239
- readonly Ref: "lwc:ref";
240
- readonly SlotBind: "lwc:slot-bind";
241
- readonly SlotData: "lwc:slot-data";
242
- readonly Spread: "lwc:spread";
243
- readonly On: "lwc:on";
244
- readonly Key: "key";
245
- };
246
- export declare const RootDirectiveName: {
247
- readonly PreserveComments: "lwc:preserve-comments";
248
- readonly RenderMode: "lwc:render-mode";
249
- };
230
+ export declare enum ElementDirectiveName {
231
+ Dom = "lwc:dom",
232
+ Dynamic = "lwc:dynamic",
233
+ Is = "lwc:is",
234
+ External = "lwc:external",
235
+ InnerHTML = "lwc:inner-html",
236
+ Ref = "lwc:ref",
237
+ SlotBind = "lwc:slot-bind",
238
+ SlotData = "lwc:slot-data",
239
+ Spread = "lwc:spread",
240
+ On = "lwc:on",
241
+ Key = "key"
242
+ }
243
+ export declare enum RootDirectiveName {
244
+ PreserveComments = "lwc:preserve-comments",
245
+ RenderMode = "lwc:render-mode"
246
+ }
250
247
  export {};
251
248
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
5
5
  ],
6
6
  "name": "@lwc/template-compiler",
7
- "version": "9.0.4-alpha.1",
7
+ "version": "9.0.4-alpha.2",
8
8
  "description": "Template compiler package",
9
9
  "keywords": [
10
10
  "lwc"
@@ -19,22 +19,17 @@
19
19
  "url": "https://github.com/salesforce/lwc/issues"
20
20
  },
21
21
  "license": "MIT",
22
- "type": "module",
23
22
  "publishConfig": {
24
23
  "access": "public"
25
24
  },
26
- "engines": {
27
- "node": ">=16.6.0"
28
- },
29
25
  "volta": {
30
26
  "extends": "../../../package.json"
31
27
  },
32
- "main": "dist/index.js",
28
+ "main": "dist/index.cjs.js",
33
29
  "module": "dist/index.js",
34
30
  "types": "dist/index.d.ts",
35
31
  "files": [
36
32
  "dist/**/*.js",
37
- "dist/**/*.cjs",
38
33
  "dist/**/*.d.ts"
39
34
  ],
40
35
  "scripts": {
@@ -51,8 +46,8 @@
51
46
  }
52
47
  },
53
48
  "dependencies": {
54
- "@lwc/errors": "9.0.4-alpha.1",
55
- "@lwc/shared": "9.0.4-alpha.1",
49
+ "@lwc/errors": "9.0.4-alpha.2",
50
+ "@lwc/shared": "9.0.4-alpha.2",
56
51
  "acorn": "~8.16.0",
57
52
  "astring": "~1.9.0",
58
53
  "he": "~1.2.0"