@lwc/template-compiler 8.1.0 → 8.1.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.
package/dist/index.cjs.js CHANGED
@@ -68,8 +68,15 @@ function escapeScopeToken(input) {
68
68
  // in certain cases in attribute names
69
69
  return input.replace(/@/g, '___at___').replace(/#/g, '___hash___');
70
70
  }
71
- function generateScopeTokens(filename, namespace, name) {
72
- const uniqueToken = `${namespace}-${name}_${path.basename(filename, path.extname(filename))}`;
71
+ /**
72
+ * Generate the scope tokens for a given component. Note that this API is NOT stable and should be
73
+ * considered internal to the LWC framework.
74
+ * @param filename - full filename, e.g. `path/to/x/foo/foo.js`
75
+ * @param namespace - namespace, e.g. 'x' for `x/foo/foo.js`
76
+ * @param componentName - component name, e.g. 'foo' for `x/foo/foo.js`
77
+ */
78
+ function generateScopeTokens(filename, namespace, componentName) {
79
+ const uniqueToken = `${namespace}-${componentName}_${path.basename(filename, path.extname(filename))}`;
73
80
  // This scope token is all lowercase so that it works correctly in case-sensitive namespaces (e.g. SVG).
74
81
  // It is deliberately designed to discourage people from relying on it by appearing somewhat random.
75
82
  // (But not totally random, because it's nice to have stable scope tokens for our own tests.)
@@ -12945,7 +12952,7 @@ function generateStylesheetTokens(codeGen) {
12945
12952
  return styleTokens;
12946
12953
  }
12947
12954
  const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
12948
- const PROPERTY_DELIMITER = /:(.+)/;
12955
+ const PROPERTY_DELIMITER = /:(.+)/s; // `/s` (dotAll) required to match styles across newlines, e.g. `color: \n red;`
12949
12956
  // Borrowed from Vue template compiler.
12950
12957
  // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
12951
12958
  function parseStyleText(cssText) {
@@ -13013,6 +13020,8 @@ function isStaticNode(node, apiVersion) {
13013
13020
  }
13014
13021
  // it is an element
13015
13022
  result &&= isElement(node);
13023
+ // See W-16784305
13024
+ result &&= node.name !== 'noframes';
13016
13025
  // all attrs are static-safe
13017
13026
  // the criteria to determine safety can be found in computeAttrValue
13018
13027
  result &&= attributes.every(({ name }) => {
@@ -13160,34 +13169,44 @@ function serializeAttrs(element, codeGen) {
13160
13169
  const attrs = [];
13161
13170
  let hasClassAttr = false;
13162
13171
  const collector = ({ name, value, hasExpression, hasSvgUseHref, needsScoping, }) => {
13163
- let v = typeof value === 'string' ? templateStringEscape(value) : value;
13164
- if (name === 'class') {
13165
- hasClassAttr = true;
13166
- // ${0} maps to class token that will be appended to the string.
13167
- // See buildParseFragmentFn for details.
13168
- // The token is only needed when the class attribute is static.
13169
- // The token will be injected at runtime for expressions in parseFragmentFn.
13170
- if (!hasExpression) {
13171
- if (typeof v === 'string') {
13172
- v = normalizeWhitespace(v);
13173
- }
13174
- v += '${0}';
13175
- }
13176
- }
13177
- if (name === 'style' && !hasExpression && typeof v === 'string') {
13178
- v = normalizeStyleAttribute(v);
13179
- }
13180
- // `spellcheck` string values are specially handled to massage them into booleans.
13181
- // For backwards compat with non-static-optimized templates, we also treat any non-`"false"`
13182
- // value other than the valueless format (e.g. `<div spellcheck>`) as `"true"`,
13183
- // even though per MDN, the empty string and `"true"` are equivalent:
13184
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck
13185
- if (name === 'spellcheck' && typeof v === 'string' && !hasExpression) {
13186
- v = String(v.toLowerCase() !== 'false');
13172
+ // Do not serialize boolean class/style attribute (consistent with non-static optimized)
13173
+ if (typeof value === 'boolean' && (name === 'class' || name === 'style')) {
13174
+ return;
13187
13175
  }
13188
13176
  // See W-16614169
13189
13177
  const escapedAttributeName = templateStringEscape(name);
13190
- if (typeof v === 'string') {
13178
+ if (typeof value === 'string') {
13179
+ let v = templateStringEscape(value);
13180
+ if (name === 'class') {
13181
+ // ${0} maps to class token that will be appended to the string.
13182
+ // See buildParseFragmentFn for details.
13183
+ // The token is only needed when the class attribute is static.
13184
+ // The token will be injected at runtime for expressions in parseFragmentFn.
13185
+ if (!hasExpression) {
13186
+ v = normalizeWhitespace(v);
13187
+ if (v === '') {
13188
+ // Do not serialize empty class attribute (consistent with non-static optimized)
13189
+ return;
13190
+ }
13191
+ v += '${0}';
13192
+ }
13193
+ hasClassAttr = true;
13194
+ }
13195
+ // `spellcheck` string values are specially handled to massage them into booleans.
13196
+ // For backwards compat with non-static-optimized templates, we also treat any non-`"false"`
13197
+ // value other than the valueless format (e.g. `<div spellcheck>`) as `"true"`,
13198
+ // even though per MDN, the empty string and `"true"` are equivalent:
13199
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck
13200
+ if (name === 'spellcheck' && !hasExpression) {
13201
+ v = String(v.toLowerCase() !== 'false');
13202
+ }
13203
+ if (name === 'style' && !hasExpression) {
13204
+ v = normalizeStyleAttribute(v);
13205
+ if (v === '') {
13206
+ // Do not serialize empty style attribute (consistent with non-static optimized)
13207
+ return;
13208
+ }
13209
+ }
13191
13210
  // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13192
13211
  // Skip serializing here and handle it as if it were a dynamic attribute instead.
13193
13212
  // Note that, to maintain backwards compatibility with the non-static output, we treat the valueless
@@ -14770,8 +14789,9 @@ function compile(source, filename, config) {
14770
14789
 
14771
14790
  exports.compile = compile;
14772
14791
  exports.default = compile;
14792
+ exports.generateScopeTokens = generateScopeTokens;
14773
14793
  exports.kebabcaseToCamelcase = kebabcaseToCamelcase;
14774
14794
  exports.parse = parse;
14775
14795
  exports.toPropertyName = toPropertyName;
14776
- /** version: 8.1.0 */
14796
+ /** version: 8.1.2 */
14777
14797
  //# sourceMappingURL=index.cjs.js.map