Skip to content

Commit

Permalink
fix(compiler-vapor): check global allowed for identifier (#189)
Browse files Browse the repository at this point in the history
Co-authored-by: 三咲智子 Kevin Deng <[email protected]>
  • Loading branch information
Jevon617 and sxzz authored Apr 26, 2024
1 parent 6b03b47 commit 464b498
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/compiler-vapor/src/generators/expression.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isGloballyAllowed } from '@vue/shared'
import {
BindingTypes,
NewlineType,
Expand Down Expand Up @@ -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]]

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

0 comments on commit 464b498

Please sign in to comment.