From 2fb5a847cab536cbfe20110353b5948fc43a5cfe Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Wed, 21 Jun 2023 10:25:18 +0900 Subject: [PATCH] refactor(compiler): fix single argument class and style interpolations (#50805) Single argument class and style interpolations (e.g. `style.color="{{color}"`) should be converted to standard class and property operations with no interpolation (e.g. `[style.color]="color") PR Close #50805 --- .../src/template/pipeline/src/instruction.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/compiler/src/template/pipeline/src/instruction.ts b/packages/compiler/src/template/pipeline/src/instruction.ts index 620c95a9c28..46109a4233d 100644 --- a/packages/compiler/src/template/pipeline/src/instruction.ts +++ b/packages/compiler/src/template/pipeline/src/instruction.ts @@ -358,7 +358,7 @@ const PROPERTY_INTERPOLATE_CONFIG: VariadicInstructionConfig = { */ const STYLE_PROP_INTERPOLATE_CONFIG: VariadicInstructionConfig = { constant: [ - null!, // Single argument stylePropInterpolate is converted to styleProp instruction. + Identifiers.styleProp, Identifiers.stylePropInterpolate1, Identifiers.stylePropInterpolate2, Identifiers.stylePropInterpolate3, @@ -373,9 +373,6 @@ const STYLE_PROP_INTERPOLATE_CONFIG: VariadicInstructionConfig = { if (n % 2 === 0) { throw new Error(`Expected odd number of arguments`); } - if (n < 3) { - throw new Error(`Expected at least 3 arguments`); - } return (n - 1) / 2; }, }; @@ -409,7 +406,7 @@ const ATTRIBUTE_INTERPOLATE_CONFIG: VariadicInstructionConfig = { */ const STYLE_MAP_INTERPOLATE_CONFIG: VariadicInstructionConfig = { constant: [ - null!, // Single argument styleMapInterpolate is converted to styleMap instruction. + Identifiers.styleMap, Identifiers.styleMapInterpolate1, Identifiers.styleMapInterpolate2, Identifiers.styleMapInterpolate3, @@ -424,9 +421,6 @@ const STYLE_MAP_INTERPOLATE_CONFIG: VariadicInstructionConfig = { if (n % 2 === 0) { throw new Error(`Expected odd number of arguments`); } - if (n < 3) { - throw new Error(`Expected at least 3 arguments`); - } return (n - 1) / 2; }, }; @@ -436,7 +430,7 @@ const STYLE_MAP_INTERPOLATE_CONFIG: VariadicInstructionConfig = { */ const CLASS_MAP_INTERPOLATE_CONFIG: VariadicInstructionConfig = { constant: [ - null!, // Single argument classMapInterpolate is converted to classMap instruction. + Identifiers.classMap, Identifiers.classMapInterpolate1, Identifiers.classMapInterpolate2, Identifiers.classMapInterpolate3, @@ -451,9 +445,6 @@ const CLASS_MAP_INTERPOLATE_CONFIG: VariadicInstructionConfig = { if (n % 2 === 0) { throw new Error(`Expected odd number of arguments`); } - if (n < 3) { - throw new Error(`Expected at least 3 arguments`); - } return (n - 1) / 2; }, };