From 31f1c520f59526a6a64bd44d9c431b252aa29bc5 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 14 Oct 2022 11:23:54 +0200 Subject: [PATCH] switch from regex check to svelteCompiler.parse --- packages/svelte/rollup.npm.config.js | 2 +- packages/svelte/src/preprocessors.ts | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/svelte/rollup.npm.config.js b/packages/svelte/rollup.npm.config.js index ae3c7a9a5b8a..c2ab32e60374 100644 --- a/packages/svelte/rollup.npm.config.js +++ b/packages/svelte/rollup.npm.config.js @@ -3,6 +3,6 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js' export default makeNPMConfigVariants( makeBaseNPMConfig({ // Prevent 'svelte/internal' stuff from being included in the built JS - packageSpecificConfig: { external: ['svelte/internal'] }, + packageSpecificConfig: { external: ['svelte/internal', 'svelte/compiler'] }, }), ); diff --git a/packages/svelte/src/preprocessors.ts b/packages/svelte/src/preprocessors.ts index 2ee399f864f9..5ab80cf4c120 100644 --- a/packages/svelte/src/preprocessors.ts +++ b/packages/svelte/src/preprocessors.ts @@ -1,4 +1,5 @@ import MagicString from 'magic-string'; +import * as svelteCompiler from 'svelte/compiler'; import { PreprocessorGroup } from 'svelte/types/compiler/preprocess'; import { ComponentTrackingInitOptions, SentryPreprocessorGroup, TrackComponentOptions } from './types'; @@ -123,16 +124,8 @@ function getBaseName(filename: string): string { } function hasScriptTag(content: string): boolean { - // This regex is taken from the Svelte compiler code. - // They use this regex to find matching script tags that are passed to the `script` preprocessor hook: - // https://github.com/sveltejs/svelte/blob/bb83eddfc623437528f24e9fe210885b446e72fa/src/compiler/preprocess/index.ts#L144 - // However, we remove the first part of the regex to not match HTML comments - const scriptTagRegex = /([^]*?)<\/script>|\/>)/gi; - - // Regex testing is not a super safe way of checking for the presence of a