fix(compiler-vapor): check global allowed for identifier (#189)

Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
This commit is contained in:
Jevon 2024-04-26 23:25:00 +08:00 committed by GitHub
parent 6b03b47462
commit 464b498f13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -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
}