@lwc/template-compiler 7.0.3-alpha.0 → 7.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -12937,15 +12937,15 @@ function parseStyleText(cssText) {
12937
12937
  }
12938
12938
  return styleMap;
12939
12939
  }
12940
+ const IMPORTANT_FLAG = /\s*!\s*important\s*$/i;
12940
12941
  // Given a map of CSS property keys to values, return an array AST like:
12941
12942
  // ['color', 'blue', false] // { color: 'blue' }
12942
12943
  // ['background', 'red', true] // { background: 'red !important' }
12943
12944
  function styleMapToStyleDeclsAST(styleMap) {
12944
12945
  const styles = Object.entries(styleMap).map(([key, value]) => {
12945
- const important = value.endsWith('!important');
12946
+ const important = IMPORTANT_FLAG.test(value);
12946
12947
  if (important) {
12947
- // trim off the trailing "!important" (10 chars)
12948
- value = value.substring(0, value.length - 10).trim();
12948
+ value = value.replace(IMPORTANT_FLAG, '').trim();
12949
12949
  }
12950
12950
  return [key, value, important];
12951
12951
  });
@@ -12986,9 +12986,6 @@ function isStaticNode(node, apiVersion) {
12986
12986
  result &&= attributes.every(({ name, value }) => {
12987
12987
  const isStaticSafeLiteral = isLiteral(value) &&
12988
12988
  name !== 'slot' &&
12989
- // check for ScopedId
12990
- name !== 'id' &&
12991
- !isIdReferencingAttribute(name) &&
12992
12989
  // svg href needs sanitization.
12993
12990
  !isSvgUseHref(nodeName, name, namespace) &&
12994
12991
  // Check for ScopedFragId
@@ -13137,7 +13134,7 @@ function serializeAttrs(element, codeGen) {
13137
13134
  */
13138
13135
  const attrs = [];
13139
13136
  let hasClassAttr = false;
13140
- const collector = ({ name, value, hasExpression, }) => {
13137
+ const collector = ({ name, value, hasExpression, isIdOrIdRef, }) => {
13141
13138
  let v = typeof value === 'string' ? templateStringEscape(value) : value;
13142
13139
  if (name === 'class') {
13143
13140
  hasClassAttr = true;
@@ -13158,9 +13155,15 @@ function serializeAttrs(element, codeGen) {
13158
13155
  v = String(v.toLowerCase() !== 'false');
13159
13156
  }
13160
13157
  if (typeof v === 'string') {
13158
+ // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13159
+ // Skip serializing here and handle it as if it were a dynamic attribute instead.
13160
+ // Note that, to maintain backwards compatibility with the non-static output, we treat the valueless
13161
+ // "boolean" format (e.g. `<div id>`) as the empty string, which is semantically equivalent.
13162
+ // TODO [#3658]: `disableSyntheticShadowSupport` should also disable this dynamic behavior
13163
+ const needsPlaceholder = hasExpression || isIdOrIdRef;
13161
13164
  // Inject a placeholder where the staticPartId will go when an expression occurs.
13162
13165
  // This is only needed for SSR to inject the expression value during serialization.
13163
- attrs.push(hasExpression ? `\${"${v}"}` : ` ${name}="${htmlEscape(v, true)}"`);
13166
+ attrs.push(needsPlaceholder ? `\${"${v}"}` : ` ${name}="${htmlEscape(v, true)}"`);
13164
13167
  }
13165
13168
  else {
13166
13169
  attrs.push(` ${name}`);
@@ -13168,13 +13171,20 @@ function serializeAttrs(element, codeGen) {
13168
13171
  };
13169
13172
  element.attributes
13170
13173
  .map((attr) => {
13171
- const hasExpression = isExpression$1(attr.value);
13174
+ const { name, value } = attr;
13175
+ const hasExpression = isExpression$1(value);
13176
+ // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13177
+ // Note that for backwards compat we only consider non-booleans to be dynamic IDs/IDRefs
13178
+ // TODO [#3658]: `disableSyntheticShadowSupport` should also disable this dynamic behavior
13179
+ const isIdOrIdRef = (name === 'id' || isIdReferencingAttribute(name)) &&
13180
+ (isExpression$1(value) || isStringLiteral(value));
13172
13181
  return {
13173
13182
  hasExpression,
13174
- name: attr.name,
13175
- value: hasExpression
13183
+ isIdOrIdRef,
13184
+ name,
13185
+ value: hasExpression || isIdOrIdRef
13176
13186
  ? codeGen.getStaticExpressionToken(attr)
13177
- : attr.value.value,
13187
+ : value.value,
13178
13188
  };
13179
13189
  })
13180
13190
  .forEach(collector);
@@ -13587,7 +13597,7 @@ class CodeGen {
13587
13597
  }
13588
13598
  genClassExpression(value) {
13589
13599
  let classExpression = this.bindExpression(value);
13590
- const isClassNameObjectBindingEnabled = isAPIFeatureEnabled(11 /* APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING */, this.state.config.apiVersion);
13600
+ const isClassNameObjectBindingEnabled = isAPIFeatureEnabled(10 /* APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING */, this.state.config.apiVersion);
13591
13601
  if (isClassNameObjectBindingEnabled) {
13592
13602
  classExpression = this.genNormalizeClassName(classExpression);
13593
13603
  }
@@ -13877,7 +13887,12 @@ class CodeGen {
13877
13887
  const attributeExpressions = [];
13878
13888
  for (const attribute of elm.attributes) {
13879
13889
  const { name, value } = attribute;
13880
- if (isExpression$1(value)) {
13890
+ // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13891
+ // Note that for backwards compat we only consider non-booleans to be dynamic IDs/IDRefs
13892
+ // TODO [#3658]: `disableSyntheticShadowSupport` should also disable this dynamic behavior
13893
+ const isIdOrIdRef = (name === 'id' || isIdReferencingAttribute(name)) &&
13894
+ (isExpression$1(value) || isStringLiteral(value));
13895
+ if (isExpression$1(value) || isIdOrIdRef) {
13881
13896
  let partToken = '';
13882
13897
  if (name === 'style') {
13883
13898
  partToken = `${"s" /* STATIC_PART_TOKEN_ID.STYLE */}${partId}`;
@@ -13888,6 +13903,7 @@ class CodeGen {
13888
13903
  databag.push(property$1(identifier('className'), this.genClassExpression(value)));
13889
13904
  }
13890
13905
  else {
13906
+ // non-class, non-style (i.e. generic attribute or ID/IDRef)
13891
13907
  partToken = `${"a" /* STATIC_PART_TOKEN_ID.ATTRIBUTE */}${partId}:${name}`;
13892
13908
  attributeExpressions.push(property$1(literal$1(name), bindAttributeExpression(attribute, elm, this, false)));
13893
13909
  }
@@ -14652,5 +14668,5 @@ function compile(source, filename, config) {
14652
14668
  }
14653
14669
 
14654
14670
  export { ElementDirectiveName, LWCDirectiveDomMode, LWCDirectiveRenderMode, LwcTagName, RootDirectiveName, TemplateDirectiveName, compile, compile as default, kebabcaseToCamelcase, parse, toPropertyName };
14655
- /** version: 7.0.0 */
14671
+ /** version: 7.0.3 */
14656
14672
  //# sourceMappingURL=index.js.map