From 8ec73a3aea7a52e9479f107ae5737761166ddae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Thu, 18 May 2023 11:09:40 +0800 Subject: [PATCH] fix(compiler-sfc): don't hoist regexp literial (#8300) --- .../__snapshots__/hoistStatic.spec.ts.snap | 3 ++- .../__tests__/compileScript/hoistStatic.spec.ts | 10 ++++++---- packages/compiler-sfc/src/compileScript.ts | 17 +++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/hoistStatic.spec.ts.snap b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/hoistStatic.spec.ts.snap index 3b94955f2db..307b3e212fe 100644 --- a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/hoistStatic.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/hoistStatic.spec.ts.snap @@ -37,7 +37,6 @@ exports[`sfc hoist static > should hoist literal value 1`] = ` const nil = null const bigint = 100n const template = \`str\` - const regex = /.*/g export default { setup(__props) { @@ -124,6 +123,8 @@ exports[`sfc hoist static > should not hoist a variable 1`] = ` let KEY1 = 'default value' var KEY2 = 123 + const regex = /.*/g + const undef = undefined return () => {} } diff --git a/packages/compiler-sfc/__tests__/compileScript/hoistStatic.spec.ts b/packages/compiler-sfc/__tests__/compileScript/hoistStatic.spec.ts index 7b3a8a813c5..d2c76c9a2cc 100644 --- a/packages/compiler-sfc/__tests__/compileScript/hoistStatic.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/hoistStatic.spec.ts @@ -19,7 +19,6 @@ describe('sfc hoist static', () => { const nil = null const bigint = 100n const template = \`str\` - const regex = /.*/g `.trim() const { content, bindings } = compile(`