@lwc/template-compiler 2.50.0 → 3.0.1

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/README.md CHANGED
@@ -89,6 +89,8 @@ const { code, warnings } = compile(`<template><h1>Hello World!</h1></template>`,
89
89
  }
90
90
  ```
91
91
 
92
+ - `apiVersion` (type: `number`, optional) - API version to associate with the compiled template.
93
+
92
94
  **Return:**
93
95
  The method returns an object with the following fields:
94
96
 
package/dist/config.d.ts CHANGED
@@ -55,6 +55,10 @@ export interface Config {
55
55
  * Config to use to collect metrics and logs
56
56
  */
57
57
  instrumentation?: InstrumentationObject;
58
+ /**
59
+ * The API version to associate with the compiled template
60
+ */
61
+ apiVersion?: number;
58
62
  }
59
63
  export type NormalizedConfig = Required<Omit<Config, 'customRendererConfig' | 'instrumentation'>> & Partial<Pick<Config, 'customRendererConfig' | 'instrumentation'>>;
60
64
  export declare function normalizeConfig(config: Config): NormalizedConfig;
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,3 @@
1
- /* proxy-compat-disable */
2
1
  /**
3
2
  * Copyright (C) 2023 salesforce.com, inc.
4
3
  */
@@ -128,6 +127,7 @@ function isLwcElementTag(tagName) {
128
127
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
129
128
  */
130
129
  const AVAILABLE_OPTION_NAMES = new Set([
130
+ 'apiVersion',
131
131
  'customRendererConfig',
132
132
  'enableLwcSpread',
133
133
  'enableStaticContentOptimization',
@@ -180,9 +180,10 @@ function normalizeConfig(config) {
180
180
  });
181
181
  }
182
182
  }
183
+ const apiVersion = shared.getAPIVersionFromNumber(config.apiVersion);
183
184
  return Object.assign(Object.assign(Object.assign({ preserveHtmlComments: false, experimentalComputedMemberExpression: false,
184
185
  // TODO [#3370]: remove experimental template expression flag
185
- experimentalComplexExpressions: false, experimentalDynamicDirective: false, enableDynamicComponents: false, enableStaticContentOptimization: true, enableLwcSpread: true }, config), { customRendererConfig }), { instrumentation });
186
+ experimentalComplexExpressions: false, experimentalDynamicDirective: false, enableDynamicComponents: false, enableStaticContentOptimization: true, enableLwcSpread: true, apiVersion }, config), { customRendererConfig }), { instrumentation });
186
187
  }
187
188
 
188
189
  function isIdentifier(node) {
@@ -1588,6 +1589,7 @@ class ParserCtx {
1588
1589
  ? TMPL_EXPR_ECMASCRIPT_EDITION
1589
1590
  : 2020;
1590
1591
  this.instrumentation = config.instrumentation;
1592
+ this.apiVersion = config.apiVersion;
1591
1593
  }
1592
1594
  getSource(start, end) {
1593
1595
  return this.source.slice(start, end);
@@ -1848,7 +1850,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1848
1850
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1849
1851
  PERFORMANCE OF THIS SOFTWARE.
1850
1852
  ***************************************************************************** */
1851
- /* global Reflect, Promise */
1853
+ /* global Reflect, Promise, SuppressedError, Symbol */
1852
1854
 
1853
1855
 
1854
1856
  function __rest(s, e) {
@@ -1861,7 +1863,12 @@ function __rest(s, e) {
1861
1863
  t[p[i]] = s[p[i]];
1862
1864
  }
1863
1865
  return t;
1864
- }
1866
+ }
1867
+
1868
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1869
+ var e = new Error(message);
1870
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1871
+ };
1865
1872
 
1866
1873
  /*
1867
1874
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1923,7 +1930,7 @@ const errorCodesToErrorOn = new Set([
1923
1930
  'duplicate-attribute',
1924
1931
  ]);
1925
1932
  // These were added between parse5-with-errors v4.0.4 and parse5 v6.0.1
1926
- const errorCodesToWarnOn = new Set([
1933
+ const errorCodesToWarnOnInOlderAPIVersions = new Set([
1927
1934
  'non-conforming-doctype',
1928
1935
  'missing-doctype',
1929
1936
  'misplaced-doctype',
@@ -2258,13 +2265,19 @@ function parseFragment(source, config) {
2258
2265
  return parser.parseFragment(source);
2259
2266
  }
2260
2267
 
2261
- function getLwcErrorFromParse5Error(code) {
2268
+ function getLwcErrorFromParse5Error(ctx, code) {
2262
2269
  /* istanbul ignore else */
2263
2270
  if (errorCodesToErrorOn.has(code)) {
2264
2271
  return errors.ParserDiagnostics.INVALID_HTML_SYNTAX;
2265
2272
  }
2266
- else if (errorCodesToWarnOn.has(code)) {
2267
- return errors.ParserDiagnostics.INVALID_HTML_SYNTAX_WARNING;
2273
+ else if (errorCodesToWarnOnInOlderAPIVersions.has(code)) {
2274
+ // In newer API versions, all parse 5 errors are errors, not warnings
2275
+ if (shared.isAPIFeatureEnabled(1 /* APIFeature.TREAT_ALL_PARSE5_ERRORS_AS_ERRORS */, ctx.apiVersion)) {
2276
+ return errors.ParserDiagnostics.INVALID_HTML_SYNTAX;
2277
+ }
2278
+ else {
2279
+ return errors.ParserDiagnostics.INVALID_HTML_SYNTAX_WARNING;
2280
+ }
2268
2281
  }
2269
2282
  else {
2270
2283
  // It should be impossible to reach here; we have a test in parser.spec.ts to ensure
@@ -2278,7 +2291,7 @@ function getLwcErrorFromParse5Error(code) {
2278
2291
  function parseHTML(ctx, source) {
2279
2292
  const onParseError = (err) => {
2280
2293
  const { code } = err, location = __rest(err, ["code"]);
2281
- const lwcError = getLwcErrorFromParse5Error(code);
2294
+ const lwcError = getLwcErrorFromParse5Error(ctx, code);
2282
2295
  ctx.warnAtLocation(lwcError, sourceLocation(location), [code]);
2283
2296
  };
2284
2297
  // TODO [#3370]: remove experimental template expression flag
@@ -3972,11 +3985,13 @@ function parseClassNames(classNames) {
3972
3985
  .map((className) => className.trim())
3973
3986
  .filter((className) => className.length);
3974
3987
  }
3975
- function isStaticNode(node) {
3988
+ function isStaticNode(node, apiVersion) {
3976
3989
  let result = true;
3977
3990
  const { name: nodeName, namespace = '', attributes, directives, properties } = node;
3978
- if (namespace !== shared.HTML_NAMESPACE) {
3979
- // TODO [#3313]: re-enable static optimization for SVGs once scope token is always lowercase
3991
+ // SVG is excluded from static content optimization in older API versions due to issues with case sensitivity
3992
+ // in CSS scope tokens. See https://github.com/salesforce/lwc/issues/3313
3993
+ if (!shared.isAPIFeatureEnabled(0 /* APIFeature.LOWERCASE_SCOPE_TOKENS */, apiVersion) &&
3994
+ namespace !== shared.HTML_NAMESPACE) {
3980
3995
  return false;
3981
3996
  }
3982
3997
  // it is an element
@@ -4031,7 +4046,9 @@ function collectStaticNodes(node, staticNodes, state) {
4031
4046
  collectStaticNodes(node.else, staticNodes, state);
4032
4047
  }
4033
4048
  nodeIsStatic =
4034
- isBaseElement(node) && !isCustomRendererHookRequired(node, state) && isStaticNode(node);
4049
+ isBaseElement(node) &&
4050
+ !isCustomRendererHookRequired(node, state) &&
4051
+ isStaticNode(node, state.config.apiVersion);
4035
4052
  }
4036
4053
  if (nodeIsStatic && childrenAreStatic) {
4037
4054
  staticNodes.add(node);
@@ -5348,5 +5365,5 @@ function compile(source, config) {
5348
5365
  exports.compile = compile;
5349
5366
  exports.default = compile;
5350
5367
  exports.parse = parse;
5351
- /** version: 2.50.0 */
5368
+ /** version: 3.0.1 */
5352
5369
  //# sourceMappingURL=index.cjs.js.map