parseJS,
walkJS
} from '../utils'
+import { globalsWhitelist } from '@vue/shared'
export const transformExpression: NodeTransform = (node, context) => {
if (node.type === NodeTypes.INTERPOLATION) {
const isStaticPropertyKey = (node: Node, parent: Node) =>
isPropertyKey(node, parent) && (parent as Property).value !== node
-const globals = new Set(
- (
- 'Infinity,undefined,NaN,isFinite,isNaN,' +
- 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
- 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
- 'require,' + // for webpack
- 'arguments,'
- ) // parsed as identifier but is a special keyword...
- .split(',')
-)
-
function shouldPrefix(identifier: Identifier, parent: Node) {
if (
!(
) &&
// not in an Array destructure pattern
!(parent.type === 'ArrayPattern') &&
- // skip globals + commonly used shorthands
- !globals.has(identifier.name)
+ // skip whitelisted globals
+ !globalsWhitelist.has(identifier.name) &&
+ // special case for webpack compilation
+ identifier.name !== `require` &&
+ // is a special keyword but parsed as identifier
+ identifier.name !== `arguments`
) {
return true
}
import { ComponentInternalInstance, Data } from './component'
import { nextTick } from './scheduler'
import { instanceWatch } from './apiWatch'
-import { EMPTY_OBJ, hasOwn } from '@vue/shared'
+import { EMPTY_OBJ, hasOwn, globalsWhitelist } from '@vue/shared'
import { ExtracComputedReturns } from './apiOptions'
import { UnwrapRef } from '@vue/reactivity'
}
}
},
- has(target: ComponentInternalInstance, key: string): boolean {
- const { renderContext, data, props } = target
- // TODO handle $xxx properties
- return (
- key[0] !== '_' &&
- ((data !== EMPTY_OBJ && hasOwn(data, key)) ||
- hasOwn(renderContext, key) ||
- hasOwn(props, key))
- )
+ // this trap is only called in browser-compiled render functions that use
+ // `with (this) {}`
+ has(_: any, key: string): boolean {
+ return key[0] !== '_' && !globalsWhitelist.has(key)
},
set(target: ComponentInternalInstance, key: string, value: any): boolean {
const { data, renderContext } = target
--- /dev/null
+export const globalsWhitelist = new Set(
+ (
+ 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
+ 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
+ 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl'
+ ).split(',')
+)
export * from './patchFlags'
+export { globalsWhitelist } from './globalsWhitelist'
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
? Object.freeze({})