From 464b498f130df3e94abbdebf4e1c9157d7110078 Mon Sep 17 00:00:00 2001 From: Jevon <1787176370@qq.com> Date: Fri, 26 Apr 2024 23:25:00 +0800 Subject: [PATCH] fix(compiler-vapor): check global allowed for identifier (#189) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 三咲智子 Kevin Deng --- .../compiler-vapor/src/generators/expression.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/compiler-vapor/src/generators/expression.ts b/packages/compiler-vapor/src/generators/expression.ts index a5c25adb1..4b5701246 100644 --- a/packages/compiler-vapor/src/generators/expression.ts +++ b/packages/compiler-vapor/src/generators/expression.ts @@ -1,3 +1,4 @@ +import { isGloballyAllowed } from '@vue/shared' import { BindingTypes, NewlineType, @@ -167,7 +168,7 @@ function genIdentifier( raw = withAssignment(raw) } } else { - raw = withAssignment(`_ctx.${raw}`) + raw = withAssignment(canPrefix(raw) ? `_ctx.${raw}` : raw) } return [prefix, [raw, NewlineType.None, loc, name]] @@ -178,3 +179,15 @@ function genIdentifier( return `${vaporHelper('unref')}(${raw})` } } + +function canPrefix(name: string) { + // skip whitelisted globals + if (isGloballyAllowed(name)) { + return false + } + // special case for webpack compilation + if (name === 'require') { + return false + } + return true +}