Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@lwc/errors/src/compiler/error-info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
/**
* Next error code: 1209
* Next error code: 1211
*/

export * from './compiler';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,19 +980,35 @@ export const ParserDiagnostics = {
url: '',
},

COMPUTED_PROPERTY_ACCESS_NOT_ALLOWED_COMPLEX: {
COMPUTED_PROPERTY_ACCESS_NOT_ALLOWED_CTE_UNQUOTED: {
code: 1207,
message:
'Template expression doesn\'t allow computed property access unless the expression is surrounded by quotes: "{0}"',
level: DiagnosticLevel.Error,
url: '',
},

INVALID_NODE_COMPLEX: {
INVALID_NODE_CTE_UNQUOTED: {
code: 1208,
message:
'Template expression doesn\'t allow {0} unless the expression is surrounded by quotes: "{1}"',
level: DiagnosticLevel.Error,
url: '',
},

COMPUTED_PROPERTY_ACCESS_NOT_ALLOWED_CTE_API_VERSION: {
code: 1209,
message:
"Template expression doesn't allow computed property access. The current component API version ({1}) is insufficient and must be increased to at least {2} for this type of expression.",
level: DiagnosticLevel.Error,
url: '',
},

INVALID_NODE_CTE_API_VERSION: {
code: 1210,
message:
"Template expression doesn't allow {0}. The current component API version ({1}) is insufficient and must be increased to at least {2} for this type of expression.",
level: DiagnosticLevel.Error,
url: '',
},
};
48 changes: 29 additions & 19 deletions packages/@lwc/shared/src/api-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const enum APIVersion {
V61_250_SUMMER_24 = 61,
V62_252_WINTER_25 = 62,
V63_254_SPRING_25 = 63,
V64_256_SUMMER_25 = 64,
V65_258_WINTER_26 = 65,
V66_260_SPRING_26 = 66,
}

// These must be updated when the enum is updated.
Expand All @@ -27,6 +30,9 @@ const allVersions = [
APIVersion.V61_250_SUMMER_24,
APIVersion.V62_252_WINTER_25,
APIVersion.V63_254_SPRING_25,
APIVersion.V64_256_SUMMER_25,
APIVersion.V65_258_WINTER_26,
APIVersion.V66_260_SPRING_26,
];
const allVersionsSet = /*@__PURE__@*/ new Set(allVersions);
export const LOWEST_API_VERSION = allVersions[0];
Expand Down Expand Up @@ -117,6 +123,28 @@ export const enum APIFeature {
ENABLE_COMPLEX_TEMPLATE_EXPRESSIONS,
}

const minFeatureApiVersions = new Map([
[APIFeature.LOWERCASE_SCOPE_TOKENS, APIVersion.V59_246_WINTER_24],
[APIFeature.TREAT_ALL_PARSE5_ERRORS_AS_ERRORS, APIVersion.V59_246_WINTER_24],
[APIFeature.DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION, APIVersion.V60_248_SPRING_24],
[APIFeature.SKIP_UNNECESSARY_REGISTER_DECORATORS, APIVersion.V60_248_SPRING_24],
[APIFeature.USE_COMMENTS_FOR_FRAGMENT_BOOKENDS, APIVersion.V60_248_SPRING_24],
[APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS, APIVersion.V60_248_SPRING_24],
[APIFeature.ENABLE_ELEMENT_INTERNALS_AND_FACE, APIVersion.V61_250_SUMMER_24],
[APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING, APIVersion.V61_250_SUMMER_24],
[APIFeature.ENABLE_THIS_DOT_HOST_ELEMENT, APIVersion.V62_252_WINTER_25],
[APIFeature.ENABLE_THIS_DOT_STYLE, APIVersion.V62_252_WINTER_25],
[APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING, APIVersion.V62_252_WINTER_25],
[APIFeature.ENABLE_COMPLEX_TEMPLATE_EXPRESSIONS, APIVersion.V66_260_SPRING_26],
]);

/**
* @param apiVersionFeature
*/
export function minApiVersion(apiVersionFeature: APIFeature): APIVersion {
return minFeatureApiVersions.get(apiVersionFeature) || HIGHEST_API_VERSION;
}

/**
*
* @param apiVersionFeature
Expand All @@ -126,23 +154,5 @@ export function isAPIFeatureEnabled(
apiVersionFeature: APIFeature,
apiVersion: APIVersion
): boolean {
switch (apiVersionFeature) {
case APIFeature.LOWERCASE_SCOPE_TOKENS:
case APIFeature.TREAT_ALL_PARSE5_ERRORS_AS_ERRORS:
return apiVersion >= APIVersion.V59_246_WINTER_24;
case APIFeature.DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION:
case APIFeature.SKIP_UNNECESSARY_REGISTER_DECORATORS:
case APIFeature.USE_COMMENTS_FOR_FRAGMENT_BOOKENDS:
case APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS:
return apiVersion >= APIVersion.V60_248_SPRING_24;
case APIFeature.ENABLE_ELEMENT_INTERNALS_AND_FACE:
case APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING:
return apiVersion >= APIVersion.V61_250_SUMMER_24;
case APIFeature.ENABLE_THIS_DOT_HOST_ELEMENT:
case APIFeature.ENABLE_THIS_DOT_STYLE:
case APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING:
return apiVersion >= APIVersion.V62_252_WINTER_25;
case APIFeature.ENABLE_COMPLEX_TEMPLATE_EXPRESSIONS:
return apiVersion >= APIVersion.V63_254_SPRING_25;
}
return apiVersion >= minApiVersion(apiVersionFeature);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function compileFixture({
}: {
entry: string;
dirname: string;
experimentalComplexExpressions: boolean;
experimentalComplexExpressions: boolean | undefined;
Comment on lines 60 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
experimentalComplexExpressions: boolean | undefined;
experimentalComplexExpressions = false,
}: {
entry: string;
dirname: string;
experimentalComplexExpressions: boolean;

just cuz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A default value isn't enough, still considered boolean | undefined and results in a type error. Gonna keep it as-is

}) {
const modulesDir = path.resolve(dirname, './modules');
const outputFile = path.resolve(dirname, './dist/compiled-experimental-ssr.js');
Expand Down
11 changes: 9 additions & 2 deletions packages/@lwc/ssr-compiler/src/compile-template/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { bindExpression } from '@lwc/template-compiler';
import { APIFeature, isAPIFeatureEnabled } from '@lwc/shared';
import type {
ComplexExpression as IrComplexExpression,
Expression as IrExpression,
Expand All @@ -18,11 +19,17 @@ export function expressionIrToEs(
node: IrExpression | IrComplexExpression,
cxt: TransformerContext
): EsExpression {
const isComplexTemplateExpressionEnabled =
cxt.templateOptions.experimentalComplexExpressions &&
isAPIFeatureEnabled(
APIFeature.ENABLE_COMPLEX_TEMPLATE_EXPRESSIONS,
cxt.templateOptions.apiVersion
);
return bindExpression(
node as IrComplexExpression,
(n: EsIdentifier) => cxt.isLocalVar((n as EsIdentifier).name),
(n: EsIdentifier) => cxt.isLocalVar(n.name),
'instance',
cxt.templateOptions.experimentalComplexExpressions
isComplexTemplateExpressionEnabled
);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@lwc/ssr-compiler/src/compile-template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ export default function compileTemplate(
(directive) => directive.name === 'PreserveComments'
)?.value?.value;
const experimentalComplexExpressions = Boolean(options.experimentalComplexExpressions);
const apiVersion = Number(options.apiVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not already a number? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be undefined (goes to NaN)


const { addImport, getImports, statements, cxt } = templateIrToEsTree(root, {
preserveComments,
experimentalComplexExpressions,
apiVersion,
});
addImport(['renderStylesheets', 'hasScopedStaticStylesheets']);
for (const [imports, source] of getStylesheetImports(filename)) {
Expand Down
1 change: 1 addition & 0 deletions packages/@lwc/ssr-compiler/src/compile-template/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ export interface TransformerContext {
export interface TemplateOpts {
preserveComments: boolean;
experimentalComplexExpressions: boolean;
apiVersion: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<section>
<x-child foo="{foo()}"></x-child>
</section>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"experimentalComplexExpressions": true,
"apiVersion": 59
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"warnings": [
{
"code": 1210,
"message": "Invalid expression {foo()} - LWC1210: Template expression doesn't allow CallExpression. The current component API version (59) is insufficient and must be increased to at least 66 for this type of expression.",
"level": 1,
"location": {
"line": 3,
"column": 18,
"start": 42,
"length": 13
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<section>
<x-child>{foo()}</x-child>
</section>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"experimentalComplexExpressions": true,
"apiVersion": 59
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"warnings": [
{
"code": 1210,
"message": "Invalid expression {foo()} - LWC1210: Template expression doesn't allow CallExpression. The current component API version (59) is insufficient and must be increased to at least 66 for this type of expression.",
"level": 1,
"location": {
"line": 3,
"column": 18,
"start": 42,
"length": 7
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<section>
<p class="{classNames[0]}"></p>
</section>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"experimentalComplexExpressions": true,
"apiVersion": 59
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"warnings": [
{
"code": 1209,
"message": "Invalid expression {classNames[0]} - LWC1209: Template expression doesn't allow computed property access. The current component API version (59) is insufficient and must be increased to at least 66 for this type of expression.",
"level": 1,
"location": {
"line": 3,
"column": 12,
"start": 36,
"length": 23
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
{val[state.foo]}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"experimentalComplexExpressions": true,
"apiVersion": 59
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"warnings": [
{
"code": 1209,
"message": "Invalid expression {val[state.foo]} - LWC1209: Template expression doesn't allow computed property access. The current component API version (59) is insufficient and must be increased to at least 66 for this type of expression.",
"level": 1,
"location": {
"line": 1,
"column": 11,
"start": 10,
"length": 22
}
}
]
}
6 changes: 4 additions & 2 deletions packages/@lwc/template-compiler/src/parser/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
isExpression,
isPotentialExpression,
} from './expression';
import { isComplexTemplateExpressionEnabled } from './expression-complex';

import {
ATTR_NAME,
DATA_RE,
Expand Down Expand Up @@ -111,7 +111,9 @@ export function normalizeAttributeValue(
const isQuoted = isQuotedAttribute(rawAttrVal);
const isEscaped = isEscapedAttribute(rawAttrVal);
if (!isEscaped && isExpression(value)) {
if (isQuoted && !isComplexTemplateExpressionEnabled(ctx)) {
// Don't test for the API version here, just check if CTE is enabled.
// We can provide more specific errors WRT API versions after the expression has been parsed and we know what it is.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We can provide more specific errors WRT API versions after the expression has been parsed and we know what it is.
// We can provide more specific errors w.r.t API versions after the expression has been parsed and we know what it is.

Otherwise I might think that MRT fell over.

if (isQuoted && !ctx.config.experimentalComplexExpressions) {
// <input value="{myValue}" />
// -> ambiguity if the attribute value is a template identifier or a string literal.

Expand Down
Loading
Loading