From 7a8273cc3fe95a7d2d013f5b6f337edf00231d3e Mon Sep 17 00:00:00 2001 From: milahu Date: Wed, 30 Nov 2022 20:51:38 +0100 Subject: [PATCH] fix(isTypeScriptComponent): check all script tags (#933) --- packages/core/src/parsers/svelte/typescript/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/core/src/parsers/svelte/typescript/index.ts b/packages/core/src/parsers/svelte/typescript/index.ts index 12f6f0d24a..34294bd887 100644 --- a/packages/core/src/parsers/svelte/typescript/index.ts +++ b/packages/core/src/parsers/svelte/typescript/index.ts @@ -9,9 +9,14 @@ import type { SveltosisComponent } from '../types'; export function isTypeScriptComponent(string_: string) { const regex = createTagRegex('script', 'gi'); - const match = regex.exec(string_); - const { lang } = parseAttributes((match?.length && match[1]) || ''); - return lang === 'ts'; + let isTypeScript = false; + // match all + string_.replace(regex, (...match) => { + const { lang } = parseAttributes((match?.length && match[1]) || ''); + if (lang === 'ts') isTypeScript = true; + return ''; + }); + return isTypeScript; } /** Create a tag matching regexp. */