@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.d.ts CHANGED
@@ -5,6 +5,7 @@ export { CustomRendererConfig, CustomRendererElementConfig } from './shared/rend
5
5
  export { Config } from './config';
6
6
  export { toPropertyName } from './shared/utils';
7
7
  export { kebabcaseToCamelcase } from './shared/naming';
8
+ export { generateScopeTokens } from './scopeTokens';
8
9
  /**
9
10
  * Parses HTML markup into an AST
10
11
  * @param source HTML markup to parse
package/dist/index.js CHANGED
@@ -44,8 +44,15 @@ function escapeScopeToken(input) {
44
44
  // in certain cases in attribute names
45
45
  return input.replace(/@/g, '___at___').replace(/#/g, '___hash___');
46
46
  }
47
- function generateScopeTokens(filename, namespace, name) {
48
- const uniqueToken = `${namespace}-${name}_${path.basename(filename, path.extname(filename))}`;
47
+ /**
48
+ * Generate the scope tokens for a given component. Note that this API is NOT stable and should be
49
+ * considered internal to the LWC framework.
50
+ * @param filename - full filename, e.g. `path/to/x/foo/foo.js`
51
+ * @param namespace - namespace, e.g. 'x' for `x/foo/foo.js`
52
+ * @param componentName - component name, e.g. 'foo' for `x/foo/foo.js`
53
+ */
54
+ function generateScopeTokens(filename, namespace, componentName) {
55
+ const uniqueToken = `${namespace}-${componentName}_${path.basename(filename, path.extname(filename))}`;
49
56
  // This scope token is all lowercase so that it works correctly in case-sensitive namespaces (e.g. SVG).
50
57
  // It is deliberately designed to discourage people from relying on it by appearing somewhat random.
51
58
  // (But not totally random, because it's nice to have stable scope tokens for our own tests.)
@@ -12921,7 +12928,7 @@ function generateStylesheetTokens(codeGen) {
12921
12928
  return styleTokens;
12922
12929
  }
12923
12930
  const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
12924
- const PROPERTY_DELIMITER = /:(.+)/;
12931
+ const PROPERTY_DELIMITER = /:(.+)/s; // `/s` (dotAll) required to match styles across newlines, e.g. `color: \n red;`
12925
12932
  // Borrowed from Vue template compiler.
12926
12933
  // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
12927
12934
  function parseStyleText(cssText) {
@@ -12989,6 +12996,8 @@ function isStaticNode(node, apiVersion) {
12989
12996
  }
12990
12997
  // it is an element
12991
12998
  result &&= isElement(node);
12999
+ // See W-16784305
13000
+ result &&= node.name !== 'noframes';
12992
13001
  // all attrs are static-safe
12993
13002
  // the criteria to determine safety can be found in computeAttrValue
12994
13003
  result &&= attributes.every(({ name }) => {
@@ -13136,34 +13145,44 @@ function serializeAttrs(element, codeGen) {
13136
13145
  const attrs = [];
13137
13146
  let hasClassAttr = false;
13138
13147
  const collector = ({ name, value, hasExpression, hasSvgUseHref, needsScoping, }) => {
13139
- let v = typeof value === 'string' ? templateStringEscape(value) : value;
13140
- if (name === 'class') {
13141
- hasClassAttr = true;
13142
- // ${0} maps to class token that will be appended to the string.
13143
- // See buildParseFragmentFn for details.
13144
- // The token is only needed when the class attribute is static.
13145
- // The token will be injected at runtime for expressions in parseFragmentFn.
13146
- if (!hasExpression) {
13147
- if (typeof v === 'string') {
13148
- v = normalizeWhitespace(v);
13149
- }
13150
- v += '${0}';
13151
- }
13152
- }
13153
- if (name === 'style' && !hasExpression && typeof v === 'string') {
13154
- v = normalizeStyleAttribute(v);
13155
- }
13156
- // `spellcheck` string values are specially handled to massage them into booleans.
13157
- // For backwards compat with non-static-optimized templates, we also treat any non-`"false"`
13158
- // value other than the valueless format (e.g. `<div spellcheck>`) as `"true"`,
13159
- // even though per MDN, the empty string and `"true"` are equivalent:
13160
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck
13161
- if (name === 'spellcheck' && typeof v === 'string' && !hasExpression) {
13162
- v = String(v.toLowerCase() !== 'false');
13148
+ // Do not serialize boolean class/style attribute (consistent with non-static optimized)
13149
+ if (typeof value === 'boolean' && (name === 'class' || name === 'style')) {
13150
+ return;
13163
13151
  }
13164
13152
  // See W-16614169
13165
13153
  const escapedAttributeName = templateStringEscape(name);
13166
- if (typeof v === 'string') {
13154
+ if (typeof value === 'string') {
13155
+ let v = templateStringEscape(value);
13156
+ if (name === 'class') {
13157
+ // ${0} maps to class token that will be appended to the string.
13158
+ // See buildParseFragmentFn for details.
13159
+ // The token is only needed when the class attribute is static.
13160
+ // The token will be injected at runtime for expressions in parseFragmentFn.
13161
+ if (!hasExpression) {
13162
+ v = normalizeWhitespace(v);
13163
+ if (v === '') {
13164
+ // Do not serialize empty class attribute (consistent with non-static optimized)
13165
+ return;
13166
+ }
13167
+ v += '${0}';
13168
+ }
13169
+ hasClassAttr = true;
13170
+ }
13171
+ // `spellcheck` string values are specially handled to massage them into booleans.
13172
+ // For backwards compat with non-static-optimized templates, we also treat any non-`"false"`
13173
+ // value other than the valueless format (e.g. `<div spellcheck>`) as `"true"`,
13174
+ // even though per MDN, the empty string and `"true"` are equivalent:
13175
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck
13176
+ if (name === 'spellcheck' && !hasExpression) {
13177
+ v = String(v.toLowerCase() !== 'false');
13178
+ }
13179
+ if (name === 'style' && !hasExpression) {
13180
+ v = normalizeStyleAttribute(v);
13181
+ if (v === '') {
13182
+ // Do not serialize empty style attribute (consistent with non-static optimized)
13183
+ return;
13184
+ }
13185
+ }
13167
13186
  // IDs/IDRefs must be handled dynamically at runtime due to synthetic shadow scoping.
13168
13187
  // Skip serializing here and handle it as if it were a dynamic attribute instead.
13169
13188
  // Note that, to maintain backwards compatibility with the non-static output, we treat the valueless
@@ -14744,6 +14763,6 @@ function compile(source, filename, config) {
14744
14763
  };
14745
14764
  }
14746
14765
 
14747
- export { ElementDirectiveName, LWCDirectiveDomMode, LWCDirectiveRenderMode, LwcTagName, RootDirectiveName, TemplateDirectiveName, compile, compile as default, kebabcaseToCamelcase, parse, toPropertyName };
14748
- /** version: 8.1.0 */
14766
+ export { ElementDirectiveName, LWCDirectiveDomMode, LWCDirectiveRenderMode, LwcTagName, RootDirectiveName, TemplateDirectiveName, compile, compile as default, generateScopeTokens, kebabcaseToCamelcase, parse, toPropertyName };
14767
+ /** version: 8.1.2 */
14749
14768
  //# sourceMappingURL=index.js.map