]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-core): reuse unwrapTS utility function (#9795)
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 11 Dec 2023 02:46:28 +0000 (10:46 +0800)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2023 02:46:28 +0000 (10:46 +0800)
packages/compiler-core/src/babelUtils.ts
packages/compiler-core/src/utils.ts
packages/compiler-sfc/src/compileScript.ts
packages/compiler-sfc/src/script/defineModel.ts
packages/compiler-sfc/src/script/defineOptions.ts
packages/compiler-sfc/src/script/defineProps.ts
packages/compiler-sfc/src/script/definePropsDestructure.ts
packages/compiler-sfc/src/script/utils.ts

index f3ef5df29db4fa7a6a367c1814c26a98964cbf02..a9c1ebe9c32a65878ad67305643e8b7fdc23bfd7 100644 (file)
@@ -441,3 +441,11 @@ export const TS_NODE_TYPES = [
   'TSInstantiationExpression', // foo<string>
   'TSSatisfiesExpression' // foo satisfies T
 ]
+
+export function unwrapTSNode(node: Node): Node {
+  if (TS_NODE_TYPES.includes(node.type)) {
+    return unwrapTSNode((node as any).expression)
+  } else {
+    return node
+  }
+}
index a159d2eedc729a75239c3691f36bf1048c708ecf..adc5c19476bff45541d80152ddae24e23926e3f0 100644 (file)
@@ -40,6 +40,7 @@ import { isString, isObject, NOOP } from '@vue/shared'
 import { PropsExpression } from './transforms/transformElement'
 import { parseExpression } from '@babel/parser'
 import { Expression } from '@babel/types'
+import { unwrapTSNode } from './babelUtils'
 
 export const isStaticExp = (p: JSChildNode): p is SimpleExpressionNode =>
   p.type === NodeTypes.SIMPLE_EXPRESSION && p.isStatic
@@ -158,9 +159,7 @@ export const isMemberExpressionNode = __BROWSER__
         let ret: Expression = parseExpression(path, {
           plugins: context.expressionPlugins
         })
-        if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
-          ret = ret.expression
-        }
+        ret = unwrapTSNode(ret) as Expression
         return (
           ret.type === 'MemberExpression' ||
           ret.type === 'OptionalMemberExpression' ||
index b3f5a1414860d2c5b15011145943713b23372792..1783c6db9ee855ddf1ce73fcd6ffe87c0574149b 100644 (file)
@@ -2,7 +2,8 @@ import {
   BindingTypes,
   UNREF,
   isFunctionType,
-  walkIdentifiers
+  walkIdentifiers,
+  unwrapTSNode
 } from '@vue/compiler-dom'
 import { DEFAULT_FILENAME, SFCDescriptor, SFCScriptBlock } from './parse'
 import { ParserPlugin } from '@babel/parser'
@@ -43,12 +44,7 @@ import { DEFINE_EXPOSE, processDefineExpose } from './script/defineExpose'
 import { DEFINE_OPTIONS, processDefineOptions } from './script/defineOptions'
 import { processDefineSlots } from './script/defineSlots'
 import { DEFINE_MODEL, processDefineModel } from './script/defineModel'
-import {
-  isLiteralNode,
-  unwrapTSNode,
-  isCallOf,
-  getImportedName
-} from './script/utils'
+import { isLiteralNode, isCallOf, getImportedName } from './script/utils'
 import { analyzeScriptBindings } from './script/analyzeScriptBindings'
 import { isImportUsed } from './script/importUsageCheck'
 import { processAwait } from './script/topLevelAwait'
index 432b8676fbd20c0a150dc02e009f00faeae3647c..c104eb306ae86cb540fe3404f20598af21f285f9 100644 (file)
@@ -5,10 +5,9 @@ import {
   UNKNOWN_TYPE,
   concatStrings,
   isCallOf,
-  toRuntimeTypeString,
-  unwrapTSNode
+  toRuntimeTypeString
 } from './utils'
-import { BindingTypes } from '@vue/compiler-dom'
+import { BindingTypes, unwrapTSNode } from '@vue/compiler-dom'
 import { warnOnce } from '../warn'
 
 export const DEFINE_MODEL = 'defineModel'
index 8da3dbc0b4d7935f23df825447ad0b0f384deb07..4a3551d7551c2427af942878372b28a2365fc8d4 100644 (file)
@@ -1,6 +1,7 @@
 import { Node } from '@babel/types'
+import { unwrapTSNode } from '@vue/compiler-dom'
 import { ScriptCompileContext } from './context'
-import { isCallOf, unwrapTSNode } from './utils'
+import { isCallOf } from './utils'
 import { DEFINE_PROPS } from './defineProps'
 import { DEFINE_EMITS } from './defineEmits'
 import { DEFINE_EXPOSE } from './defineExpose'
index ca631895f2bb91600c60b0647a87e94288841506..3df6daea7d6162800a77ef5ece54c5fcf41c6cd4 100644 (file)
@@ -6,7 +6,7 @@ import {
   ObjectExpression,
   Expression
 } from '@babel/types'
-import { BindingTypes, isFunctionType } from '@vue/compiler-dom'
+import { BindingTypes, isFunctionType, unwrapTSNode } from '@vue/compiler-dom'
 import { ScriptCompileContext } from './context'
 import {
   TypeResolveContext,
@@ -19,7 +19,6 @@ import {
   concatStrings,
   isLiteralNode,
   isCallOf,
-  unwrapTSNode,
   toRuntimeTypeString,
   getEscapedPropName
 } from './utils'
index 5f2a1ef0aa74e8eff33088ed804c3fef3916a39d..c9c4fb5f7b7e7e44da115bc4f7e5f955e5ac949c 100644 (file)
@@ -15,10 +15,11 @@ import {
   isInDestructureAssignment,
   isReferencedIdentifier,
   isStaticProperty,
-  walkFunctionParams
+  walkFunctionParams,
+  unwrapTSNode
 } from '@vue/compiler-dom'
 import { genPropsAccessExp } from '@vue/shared'
-import { isCallOf, resolveObjectKey, unwrapTSNode } from './utils'
+import { isCallOf, resolveObjectKey } from './utils'
 import { ScriptCompileContext } from './context'
 import { DEFINE_PROPS } from './defineProps'
 import { warnOnce } from '../warn'
index bc621d2584062da7aa39a036d3042b0e93316e3f..a1124ce81b1ad8a33e14c0f5317164996f9c6ffb 100644 (file)
@@ -9,7 +9,6 @@ import {
   StringLiteral
 } from '@babel/types'
 import path from 'path'
-import { TS_NODE_TYPES } from '@vue/compiler-dom'
 
 export const UNKNOWN_TYPE = 'Unknown'
 
@@ -32,14 +31,6 @@ export function isLiteralNode(node: Node) {
   return node.type.endsWith('Literal')
 }
 
-export function unwrapTSNode(node: Node): Node {
-  if (TS_NODE_TYPES.includes(node.type)) {
-    return unwrapTSNode((node as any).expression)
-  } else {
-    return node
-  }
-}
-
 export function isCallOf(
   node: Node | null | undefined,
   test: string | ((id: string) => boolean) | null | undefined