From 7608502d65c5559e454f5d932958ce27305c8e77 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 26 Oct 2024 15:47:40 +0800 Subject: [PATCH] Refactor(files-util): Optimize the regular expression to match "import react" --- src/renderer/src/components/Playground/files.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/components/Playground/files.ts b/src/renderer/src/components/Playground/files.ts index 7b91bb5..4769b99 100644 --- a/src/renderer/src/components/Playground/files.ts +++ b/src/renderer/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