@lwc/template-compiler 8.1.0-alpha.4 → 8.1.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.
@@ -22,6 +22,7 @@ export declare function generateTemplateMetadata(codeGen: CodeGen): t.Statement[
22
22
  export declare function parseStyleText(cssText: string): {
23
23
  [name: string]: string;
24
24
  };
25
+ export declare function normalizeStyleAttribute(style: string): string;
25
26
  export declare function styleMapToStyleDeclsAST(styleMap: {
26
27
  [name: string]: string;
27
28
  }): t.ArrayExpression;
package/dist/index.cjs.js CHANGED
@@ -11279,6 +11279,17 @@ function parseFragment(source, config) {
11279
11279
  return parser.getFragment();
11280
11280
  }
11281
11281
 
11282
+ /*
11283
+ * Copyright (c) 2023, salesforce.com, inc.
11284
+ * All rights reserved.
11285
+ * SPDX-License-Identifier: MIT
11286
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
11287
+ */
11288
+ function isComplexTemplateExpressionEnabled(ctx) {
11289
+ return (ctx.config.experimentalComplexExpressions &&
11290
+ shared.isAPIFeatureEnabled(11 /* APIFeature.ENABLE_COMPLEX_TEMPLATE_EXPRESSIONS */, ctx.apiVersion));
11291
+ }
11292
+
11282
11293
  /*
11283
11294
  * Copyright (c) 2018, salesforce.com, inc.
11284
11295
  * All rights reserved.
@@ -11417,7 +11428,7 @@ function normalizeAttributeValue(ctx, raw, tag, attr, location) {
11417
11428
  const isQuoted = isQuotedAttribute(rawAttrVal);
11418
11429
  const isEscaped = isEscapedAttribute(rawAttrVal);
11419
11430
  if (!isEscaped && isExpression(value)) {
11420
- if (isQuoted) {
11431
+ if (isQuoted && !isComplexTemplateExpressionEnabled(ctx)) {
11421
11432
  // <input value="{myValue}" />
11422
11433
  // -> ambiguity if the attribute value is a template identifier or a string literal.
11423
11434
  const unquoted = raw.replace(/"/g, '');
@@ -12950,6 +12961,14 @@ function parseStyleText(cssText) {
12950
12961
  }
12951
12962
  return styleMap;
12952
12963
  }
12964
+ function normalizeStyleAttribute(style) {
12965
+ const styleMap = parseStyleText(style);
12966
+ const styles = Object.entries(styleMap).map(([key, value]) => {
12967
+ value = value.replace(IMPORTANT_FLAG, ' !important').trim();
12968
+ return `${key}: ${value};`;
12969
+ });
12970
+ return styles.join(' ');
12971
+ }
12953
12972
  const IMPORTANT_FLAG = /\s*!\s*important\s*$/i;
12954
12973
  // Given a map of CSS property keys to values, return an array AST like:
12955
12974
  // ['color', 'blue', false] // { color: 'blue' }
@@ -13129,6 +13148,9 @@ const rawContentElements = new Set([
13129
13148
  function templateStringEscape(str) {
13130
13149
  return str.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
13131
13150
  }
13151
+ function normalizeWhitespace(str) {
13152
+ return str.trim().replace(/\s+/g, ' ');
13153
+ }
13132
13154
  function serializeAttrs(element, codeGen) {
13133
13155
  /**
13134
13156
  * 0: styleToken in existing class attr
@@ -13146,9 +13168,15 @@ function serializeAttrs(element, codeGen) {
13146
13168
  // The token is only needed when the class attribute is static.
13147
13169
  // The token will be injected at runtime for expressions in parseFragmentFn.
13148
13170
  if (!hasExpression) {
13171
+ if (typeof v === 'string') {
13172
+ v = normalizeWhitespace(v);
13173
+ }
13149
13174
  v += '${0}';
13150
13175
  }
13151
13176
  }
13177
+ if (name === 'style' && !hasExpression && typeof v === 'string') {
13178
+ v = normalizeStyleAttribute(v);
13179
+ }
13152
13180
  // `spellcheck` string values are specially handled to massage them into booleans.
13153
13181
  // For backwards compat with non-static-optimized templates, we also treat any non-`"false"`
13154
13182
  // value other than the valueless format (e.g. `<div spellcheck>`) as `"true"`,
@@ -14745,5 +14773,5 @@ exports.default = compile;
14745
14773
  exports.kebabcaseToCamelcase = kebabcaseToCamelcase;
14746
14774
  exports.parse = parse;
14747
14775
  exports.toPropertyName = toPropertyName;
14748
- /** version: 8.1.0-alpha.4 */
14776
+ /** version: 8.1.0 */
14749
14777
  //# sourceMappingURL=index.cjs.js.map