]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: move @babel/types to dev deps, reduce install size
authorEvan You <yyx990803@gmail.com>
Tue, 21 Jul 2020 02:14:05 +0000 (22:14 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 21 Jul 2020 02:14:05 +0000 (22:14 -0400)
packages/compiler-core/package.json
packages/compiler-core/src/transforms/transformExpression.ts
packages/compiler-core/src/utils.ts
packages/compiler-sfc/package.json

index 12559873e73458b1fba74fe8e8e43c8f0e7f892f..67b6be87314bcc2476453673dc6d198402669e6c 100644 (file)
   "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"
   }
 }
index c77a8e8208be36b03df89aa1f8506bd912f458d9..a4dd94d06fcb6fd7779a06c13f22e16034dc603b 100644 (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
index fe0bc452a4027556446f2aba3fef33269e97c0c4..4bbd4300f13a09a96600cb63f09fbedc8e191c12 100644 (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)
index ba741877a1aeee2db14b5ad6377952b7e4c12463..a6f94f8e61d163ebb9970139830baa6c4c7bb4f3 100644 (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",