From 3aa38bcf8cad7fac73d15195145ee526b90fdd12 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Fri, 24 Nov 2023 21:39:32 +0800 Subject: [PATCH] perf: more mustache tag check optimization --- packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts index 68e7cd168..ff29f73ad 100644 --- a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts +++ b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Attribute.ts @@ -171,10 +171,12 @@ export function handleAttribute( return; } + const lastCharIndex = attrVal.end - 1; const hasBrackets = - str.original.lastIndexOf('}', attrVal.end) === attrVal.end - 1 || - str.original.lastIndexOf('}"', attrVal.end) === attrVal.end - 1 || - str.original.lastIndexOf("}'", attrVal.end) === attrVal.end - 1; + str.original[lastCharIndex] === '}' || + ((str.original[lastCharIndex] === '"' || str.original[lastCharIndex] === "'") && + str.original[lastCharIndex - 1] === '}'); + const needsNumberConversion = !hasBrackets && parent.type === 'Element' &&