@lwc/template-compiler 7.0.2 → 7.0.3-alpha.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.cjs.js CHANGED
@@ -12961,15 +12961,15 @@ function parseStyleText(cssText) {
12961
12961
  }
12962
12962
  return styleMap;
12963
12963
  }
12964
- const IMPORTANT_FLAG = /\s*!\s*important\s*$/i;
12965
12964
  // Given a map of CSS property keys to values, return an array AST like:
12966
12965
  // ['color', 'blue', false] // { color: 'blue' }
12967
12966
  // ['background', 'red', true] // { background: 'red !important' }
12968
12967
  function styleMapToStyleDeclsAST(styleMap) {
12969
12968
  const styles = Object.entries(styleMap).map(([key, value]) => {
12970
- const important = IMPORTANT_FLAG.test(value);
12969
+ const important = value.endsWith('!important');
12971
12970
  if (important) {
12972
- value = value.replace(IMPORTANT_FLAG, '').trim();
12971
+ // trim off the trailing "!important" (10 chars)
12972
+ value = value.substring(0, value.length - 10).trim();
12973
12973
  }
12974
12974
  return [key, value, important];
12975
12975
  });
@@ -13010,6 +13010,9 @@ function isStaticNode(node, apiVersion) {
13010
13010
  result &&= attributes.every(({ name, value }) => {
13011
13011
  const isStaticSafeLiteral = isLiteral(value) &&
13012
13012
  name !== 'slot' &&
13013
+ // check for ScopedId
13014
+ name !== 'id' &&
13015
+ !isIdReferencingAttribute(name) &&
13013
13016
  // svg href needs sanitization.
13014
13017
  !isSvgUseHref(nodeName, name, namespace) &&
13015
13018
  // Check for ScopedFragId
@@ -13158,7 +13161,7 @@ function serializeAttrs(element, codeGen) {
13158
13161
  */
13159
13162
  const attrs = [];
13160
13163
  let hasClassAttr = false;
13161
- const collector = ({ name, value, hasExpression, isIdOrIdRef, }) => {
13164
+ const collector = ({ name, value, hasExpression, }) => {
13162
13165
  let v = typeof value === 'string' ? templateStringEscape(value) : value;
13163
13166
  if (name === 'class') {
13164
13167
  hasClassAttr = true;
@@ -13179,15 +13182,9 @@ function serializeAttrs(element, codeGen) {
13179
13182
  v = String(v.toLowerCase() !== 'false');
13180
13183
  }
13181
13184
  if (typeof v === 'string') {
13182
- // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13183
- // Skip serializing here and handle it as if it were a dynamic attribute instead.
13184
- // Note that, to maintain backwards compatibility with the non-static output, we treat the valueless
13185
- // "boolean" format (e.g. `<div id>`) as the empty string, which is semantically equivalent.
13186
- // TODO [#3658]: `disableSyntheticShadowSupport` should also disable this dynamic behavior
13187
- const needsPlaceholder = hasExpression || isIdOrIdRef;
13188
13185
  // Inject a placeholder where the staticPartId will go when an expression occurs.
13189
13186
  // This is only needed for SSR to inject the expression value during serialization.
13190
- attrs.push(needsPlaceholder ? `\${"${v}"}` : ` ${name}="${shared.htmlEscape(v, true)}"`);
13187
+ attrs.push(hasExpression ? `\${"${v}"}` : ` ${name}="${shared.htmlEscape(v, true)}"`);
13191
13188
  }
13192
13189
  else {
13193
13190
  attrs.push(` ${name}`);
@@ -13195,20 +13192,13 @@ function serializeAttrs(element, codeGen) {
13195
13192
  };
13196
13193
  element.attributes
13197
13194
  .map((attr) => {
13198
- const { name, value } = attr;
13199
- const hasExpression = isExpression$1(value);
13200
- // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13201
- // Note that for backwards compat we only consider non-booleans to be dynamic IDs/IDRefs
13202
- // TODO [#3658]: `disableSyntheticShadowSupport` should also disable this dynamic behavior
13203
- const isIdOrIdRef = (name === 'id' || isIdReferencingAttribute(name)) &&
13204
- (isExpression$1(value) || isStringLiteral(value));
13195
+ const hasExpression = isExpression$1(attr.value);
13205
13196
  return {
13206
13197
  hasExpression,
13207
- isIdOrIdRef,
13208
- name,
13209
- value: hasExpression || isIdOrIdRef
13198
+ name: attr.name,
13199
+ value: hasExpression
13210
13200
  ? codeGen.getStaticExpressionToken(attr)
13211
- : value.value,
13201
+ : attr.value.value,
13212
13202
  };
13213
13203
  })
13214
13204
  .forEach(collector);
@@ -13621,7 +13611,7 @@ class CodeGen {
13621
13611
  }
13622
13612
  genClassExpression(value) {
13623
13613
  let classExpression = this.bindExpression(value);
13624
- const isClassNameObjectBindingEnabled = shared.isAPIFeatureEnabled(10 /* APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING */, this.state.config.apiVersion);
13614
+ const isClassNameObjectBindingEnabled = shared.isAPIFeatureEnabled(11 /* APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING */, this.state.config.apiVersion);
13625
13615
  if (isClassNameObjectBindingEnabled) {
13626
13616
  classExpression = this.genNormalizeClassName(classExpression);
13627
13617
  }
@@ -13911,12 +13901,7 @@ class CodeGen {
13911
13901
  const attributeExpressions = [];
13912
13902
  for (const attribute of elm.attributes) {
13913
13903
  const { name, value } = attribute;
13914
- // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13915
- // Note that for backwards compat we only consider non-booleans to be dynamic IDs/IDRefs
13916
- // TODO [#3658]: `disableSyntheticShadowSupport` should also disable this dynamic behavior
13917
- const isIdOrIdRef = (name === 'id' || isIdReferencingAttribute(name)) &&
13918
- (isExpression$1(value) || isStringLiteral(value));
13919
- if (isExpression$1(value) || isIdOrIdRef) {
13904
+ if (isExpression$1(value)) {
13920
13905
  let partToken = '';
13921
13906
  if (name === 'style') {
13922
13907
  partToken = `${"s" /* STATIC_PART_TOKEN_ID.STYLE */}${partId}`;
@@ -13927,7 +13912,6 @@ class CodeGen {
13927
13912
  databag.push(property$1(identifier('className'), this.genClassExpression(value)));
13928
13913
  }
13929
13914
  else {
13930
- // non-class, non-style (i.e. generic attribute or ID/IDRef)
13931
13915
  partToken = `${"a" /* STATIC_PART_TOKEN_ID.ATTRIBUTE */}${partId}:${name}`;
13932
13916
  attributeExpressions.push(property$1(literal$1(name), bindAttributeExpression(attribute, elm, this, false)));
13933
13917
  }
@@ -14696,5 +14680,5 @@ exports.default = compile;
14696
14680
  exports.kebabcaseToCamelcase = kebabcaseToCamelcase;
14697
14681
  exports.parse = parse;
14698
14682
  exports.toPropertyName = toPropertyName;
14699
- /** version: 7.0.2 */
14683
+ /** version: 7.0.0 */
14700
14684
  //# sourceMappingURL=index.cjs.js.map