Skip to content

Commit 464b498

Browse files
Jevon617sxzz
andauthored
fix(compiler-vapor): check global allowed for identifier (#189)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
1 parent 6b03b47 commit 464b498

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/compiler-vapor/src/generators/expression.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isGloballyAllowed } from '@vue/shared'
12
import {
23
BindingTypes,
34
NewlineType,
@@ -167,7 +168,7 @@ function genIdentifier(
167168
raw = withAssignment(raw)
168169
}
169170
} else {
170-
raw = withAssignment(`_ctx.${raw}`)
171+
raw = withAssignment(canPrefix(raw) ? `_ctx.${raw}` : raw)
171172
}
172173
return [prefix, [raw, NewlineType.None, loc, name]]
173174

@@ -178,3 +179,15 @@ function genIdentifier(
178179
return `${vaporHelper('unref')}(${raw})`
179180
}
180181
}
182+
183+
function canPrefix(name: string) {
184+
// skip whitelisted globals
185+
if (isGloballyAllowed(name)) {
186+
return false
187+
}
188+
// special case for webpack compilation
189+
if (name === 'require') {
190+
return false
191+
}
192+
return true
193+
}

0 commit comments

Comments
 (0)