@lwc/template-compiler 2.50.0 → 3.0.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/README.md +2 -0
- package/dist/config.d.ts +4 -0
- package/dist/index.cjs.js +24 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +25 -13
- package/dist/index.js.map +1 -1
- package/dist/parser/parse5Errors.d.ts +1 -1
- package/dist/parser/parser.d.ts +2 -0
- package/package.json +3 -3
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);
|
|
@@ -1923,7 +1925,7 @@ const errorCodesToErrorOn = new Set([
|
|
|
1923
1925
|
'duplicate-attribute',
|
|
1924
1926
|
]);
|
|
1925
1927
|
// These were added between parse5-with-errors v4.0.4 and parse5 v6.0.1
|
|
1926
|
-
const
|
|
1928
|
+
const errorCodesToWarnOnInOlderAPIVersions = new Set([
|
|
1927
1929
|
'non-conforming-doctype',
|
|
1928
1930
|
'missing-doctype',
|
|
1929
1931
|
'misplaced-doctype',
|
|
@@ -2258,13 +2260,19 @@ function parseFragment(source, config) {
|
|
|
2258
2260
|
return parser.parseFragment(source);
|
|
2259
2261
|
}
|
|
2260
2262
|
|
|
2261
|
-
function getLwcErrorFromParse5Error(code) {
|
|
2263
|
+
function getLwcErrorFromParse5Error(ctx, code) {
|
|
2262
2264
|
/* istanbul ignore else */
|
|
2263
2265
|
if (errorCodesToErrorOn.has(code)) {
|
|
2264
2266
|
return errors.ParserDiagnostics.INVALID_HTML_SYNTAX;
|
|
2265
2267
|
}
|
|
2266
|
-
else if (
|
|
2267
|
-
|
|
2268
|
+
else if (errorCodesToWarnOnInOlderAPIVersions.has(code)) {
|
|
2269
|
+
// In newer API versions, all parse 5 errors are errors, not warnings
|
|
2270
|
+
if (shared.isAPIFeatureEnabled(1 /* APIFeature.TREAT_ALL_PARSE5_ERRORS_AS_ERRORS */, ctx.apiVersion)) {
|
|
2271
|
+
return errors.ParserDiagnostics.INVALID_HTML_SYNTAX;
|
|
2272
|
+
}
|
|
2273
|
+
else {
|
|
2274
|
+
return errors.ParserDiagnostics.INVALID_HTML_SYNTAX_WARNING;
|
|
2275
|
+
}
|
|
2268
2276
|
}
|
|
2269
2277
|
else {
|
|
2270
2278
|
// It should be impossible to reach here; we have a test in parser.spec.ts to ensure
|
|
@@ -2278,7 +2286,7 @@ function getLwcErrorFromParse5Error(code) {
|
|
|
2278
2286
|
function parseHTML(ctx, source) {
|
|
2279
2287
|
const onParseError = (err) => {
|
|
2280
2288
|
const { code } = err, location = __rest(err, ["code"]);
|
|
2281
|
-
const lwcError = getLwcErrorFromParse5Error(code);
|
|
2289
|
+
const lwcError = getLwcErrorFromParse5Error(ctx, code);
|
|
2282
2290
|
ctx.warnAtLocation(lwcError, sourceLocation(location), [code]);
|
|
2283
2291
|
};
|
|
2284
2292
|
// TODO [#3370]: remove experimental template expression flag
|
|
@@ -3972,11 +3980,13 @@ function parseClassNames(classNames) {
|
|
|
3972
3980
|
.map((className) => className.trim())
|
|
3973
3981
|
.filter((className) => className.length);
|
|
3974
3982
|
}
|
|
3975
|
-
function isStaticNode(node) {
|
|
3983
|
+
function isStaticNode(node, apiVersion) {
|
|
3976
3984
|
let result = true;
|
|
3977
3985
|
const { name: nodeName, namespace = '', attributes, directives, properties } = node;
|
|
3978
|
-
|
|
3979
|
-
|
|
3986
|
+
// SVG is excluded from static content optimization in older API versions due to issues with case sensitivity
|
|
3987
|
+
// in CSS scope tokens. See https://github.com/salesforce/lwc/issues/3313
|
|
3988
|
+
if (!shared.isAPIFeatureEnabled(0 /* APIFeature.LOWERCASE_SCOPE_TOKENS */, apiVersion) &&
|
|
3989
|
+
namespace !== shared.HTML_NAMESPACE) {
|
|
3980
3990
|
return false;
|
|
3981
3991
|
}
|
|
3982
3992
|
// it is an element
|
|
@@ -4031,7 +4041,9 @@ function collectStaticNodes(node, staticNodes, state) {
|
|
|
4031
4041
|
collectStaticNodes(node.else, staticNodes, state);
|
|
4032
4042
|
}
|
|
4033
4043
|
nodeIsStatic =
|
|
4034
|
-
isBaseElement(node) &&
|
|
4044
|
+
isBaseElement(node) &&
|
|
4045
|
+
!isCustomRendererHookRequired(node, state) &&
|
|
4046
|
+
isStaticNode(node, state.config.apiVersion);
|
|
4035
4047
|
}
|
|
4036
4048
|
if (nodeIsStatic && childrenAreStatic) {
|
|
4037
4049
|
staticNodes.add(node);
|
|
@@ -5348,5 +5360,5 @@ function compile(source, config) {
|
|
|
5348
5360
|
exports.compile = compile;
|
|
5349
5361
|
exports.default = compile;
|
|
5350
5362
|
exports.parse = parse;
|
|
5351
|
-
/** version:
|
|
5363
|
+
/** version: 3.0.0 */
|
|
5352
5364
|
//# sourceMappingURL=index.cjs.js.map
|