From 72ab3907569432770d41b5627ef901deb8a11b04 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 13 Sep 2024 09:18:57 +0800 Subject: [PATCH] Refactor(files-util): Optimize the regular expression to match "import react" --- src/components/Playground/files.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Playground/files.ts b/src/components/Playground/files.ts index 7b91bb5..4769b99 100644 --- a/src/components/Playground/files.ts +++ b/src/components/Playground/files.ts @@ -106,7 +106,7 @@ export const cssToJs = (file: IFile) => { } export const addReactImport = (code: string) => { - if (!/import\s+React/g.test(code)) { + if (!/^\s*import\s+React\s+/g.test(code)) { return `import React from 'react';\n${code}` } return code