]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(build): avoid importing @babel/parser in esm-bundler build
authorEvan You <yyx990803@gmail.com>
Fri, 24 Sep 2021 03:20:53 +0000 (23:20 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 24 Sep 2021 03:20:53 +0000 (23:20 -0400)
fix #4665

packages/compiler-core/src/utils.ts

index ff903770229cd82aed38111d3ca90939d95da4dd..493c80934ffdddeadc76ae22c56092c37da41964 100644 (file)
@@ -47,7 +47,8 @@ import {
   isObject,
   hyphenate,
   extend,
-  babelParserDefaultPlugins
+  babelParserDefaultPlugins,
+  NOOP
 } from '@vue/shared'
 import { PropsExpression } from './transforms/transformElement'
 import { parseExpression } from '@babel/parser'
@@ -161,26 +162,25 @@ export const isMemberExpressionBrowser = (path: string): boolean => {
   return !currentOpenBracketCount && !currentOpenParensCount
 }
 
-export const isMemberExpressionNode = (
-  path: string,
-  context: TransformContext
-): boolean => {
-  try {
-    let ret: Expression = parseExpression(path, {
-      plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
-    })
-    if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
-      ret = ret.expression
+export const isMemberExpressionNode = __BROWSER__
+  ? NOOP
+  : (path: string, context: TransformContext): boolean => {
+      try {
+        let ret: Expression = parseExpression(path, {
+          plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
+        })
+        if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
+          ret = ret.expression
+        }
+        return (
+          ret.type === 'MemberExpression' ||
+          ret.type === 'OptionalMemberExpression' ||
+          ret.type === 'Identifier'
+        )
+      } catch (e) {
+        return false
+      }
     }
-    return (
-      ret.type === 'MemberExpression' ||
-      ret.type === 'OptionalMemberExpression' ||
-      ret.type === 'Identifier'
-    )
-  } catch (e) {
-    return false
-  }
-}
 
 export const isMemberExpression = __BROWSER__
   ? isMemberExpressionBrowser