refactor: move @babel/types to dev deps, reduce install size

This commit is contained in:
Evan You 2020-07-20 22:14:05 -04:00
parent 54727f9874
commit be4df124e6
4 changed files with 12 additions and 45 deletions

View File

@ -32,8 +32,10 @@
"dependencies": {
"@vue/shared": "3.0.0-rc.2",
"@babel/parser": "^7.10.4",
"@babel/types": "^7.10.4",
"estree-walker": "^2.0.1",
"source-map": "^0.6.1"
},
"devDependencies": {
"@babel/types": "^7.10.4"
}
}

View File

@ -16,12 +16,7 @@ import {
CompoundExpressionNode,
createCompoundExpression
} from '../ast'
import {
advancePositionWithClone,
isSimpleIdentifier,
parseJS,
walkJS
} from '../utils'
import { advancePositionWithClone, isSimpleIdentifier } from '../utils'
import {
isGloballyWhitelisted,
makeMap,
@ -31,6 +26,8 @@ import {
import { createCompilerError, ErrorCodes } from '../errors'
import { Node, Function, Identifier, ObjectProperty } from '@babel/types'
import { validateBrowserExpression } from '../validateExpression'
import { parse } from '@babel/parser'
import { walk } from 'estree-walker'
const isLiteralWhitelisted = /*#__PURE__*/ makeMap('true,false,null,this')
@ -137,7 +134,7 @@ export function processExpression(
? ` ${rawExp} `
: `(${rawExp})${asParams ? `=>{}` : ``}`
try {
ast = parseJS(source, {
ast = parse(source, {
plugins: [...context.expressionPlugins, ...babelParserDefautPlugins]
}).program
} catch (e) {
@ -158,8 +155,8 @@ export function processExpression(
ids.some(id => id.start === node.start)
// walk the AST and look for identifiers that need to be prefixed.
walkJS(ast, {
enter(node: Node & PrefixMeta, parent) {
;(walk as any)(ast, {
enter(node: Node & PrefixMeta, parent: Node) {
if (node.type === 'Identifier') {
if (!isDuplicate(node)) {
const needPrefix = shouldPrefix(node, parent)
@ -186,8 +183,8 @@ export function processExpression(
// walk function expressions and add its arguments to known identifiers
// so that we don't prefix them
node.params.forEach(p =>
walkJS(p, {
enter(child, parent) {
(walk as any)(p, {
enter(child: Node, parent: Node) {
if (
child.type === 'Identifier' &&
// do not record as scope variable if is a destructured key

View File

@ -32,9 +32,6 @@ import {
BASE_TRANSITION
} from './runtimeHelpers'
import { isString, isObject, hyphenate, extend } from '@vue/shared'
import { parse } from '@babel/parser'
import { walk } from 'estree-walker'
import { Node } from '@babel/types'
export const isStaticExp = (p: JSChildNode): p is SimpleExpressionNode =>
p.type === NodeTypes.SIMPLE_EXPRESSION && p.isStatic
@ -54,35 +51,6 @@ export function isCoreComponent(tag: string): symbol | void {
}
}
export const parseJS: typeof parse = (code, options) => {
if (__BROWSER__) {
assert(
!__BROWSER__,
`Expression AST analysis can only be performed in non-browser builds.`
)
return null as any
} else {
return parse(code, options)
}
}
interface Walker {
enter?(node: Node, parent: Node): void
leave?(node: Node): void
}
export const walkJS = (ast: Node, walker: Walker) => {
if (__BROWSER__) {
assert(
!__BROWSER__,
`Expression AST analysis can only be performed in non-browser builds.`
)
return null as any
} else {
return (walk as any)(ast, walker)
}
}
const nonIdentifierRE = /^\d|[^\$\w]/
export const isSimpleIdentifier = (name: string): boolean =>
!nonIdentifierRE.test(name)

View File

@ -35,7 +35,6 @@
},
"dependencies": {
"@babel/parser": "^7.10.4",
"@babel/types": "^7.10.4",
"@vue/compiler-core": "3.0.0-rc.2",
"@vue/compiler-dom": "3.0.0-rc.2",
"@vue/compiler-ssr": "3.0.0-rc.2",
@ -52,6 +51,7 @@
"source-map": "^0.6.1"
},
"devDependencies": {
"@babel/types": "^7.10.4",
"@types/consolidate": "^0.14.0",
"@types/lru-cache": "^5.1.0",
"pug": "^2.0.4",