refactor(core): use makeMap for faster string match checks (#282)

This commit is contained in:
Ayush Goyal
2019-10-15 21:41:08 +05:30
committed by Evan You
parent eb28d45933
commit 58fffcb987
6 changed files with 53 additions and 202 deletions

View File

@@ -23,9 +23,9 @@ import {
parseJS,
walkJS
} from '../utils'
import { globalsWhitelist } from '@vue/shared'
import { isGloballyWhitelisted, makeMap } from '@vue/shared'
const literalsWhitelist = new Set([`true`, `false`, `null`, `this`])
const isLiteralWhitelisted = makeMap('true,false,null,this')
export const transformExpression: NodeTransform = (node, context) => {
if (node.type === NodeTypes.INTERPOLATION) {
@@ -87,8 +87,8 @@ export function processExpression(
if (
!asParams &&
!context.identifiers[rawExp] &&
!globalsWhitelist.has(rawExp) &&
!literalsWhitelist.has(rawExp)
!isGloballyWhitelisted(rawExp) &&
!isLiteralWhitelisted(rawExp)
) {
node.content = `_ctx.${rawExp}`
} else if (!context.identifiers[rawExp]) {
@@ -261,7 +261,7 @@ function shouldPrefix(identifier: Identifier, parent: Node) {
// not in an Array destructure pattern
!(parent.type === 'ArrayPattern') &&
// skip whitelisted globals
!globalsWhitelist.has(identifier.name) &&
!isGloballyWhitelisted(identifier.name) &&
// special case for webpack compilation
identifier.name !== `require` &&
// is a special keyword but parsed as identifier