Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 11, 2023
1 parent ae8bcdc commit 81783b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
29 changes: 25 additions & 4 deletions lib/utils/ts-utils/ts-ast.js
Expand Up @@ -14,6 +14,8 @@ const { inferRuntimeTypeFromTypeNode } = require('./ts-types')
* @typedef {import('../index').ComponentTypeEmit} ComponentTypeEmit
*/

const noop = Function.prototype

module.exports = {
isTypeNode,
flattenTypeNodes,
Expand All @@ -25,17 +27,21 @@ module.exports = {
}

/**
* @param {TSESTreeNode | ASTNode} node
* @returns {node is TSESTreeTypeNode}
* @param {ASTNode} node
* @returns {node is TypeNode}
*/
function isTypeNode(node) {
return (
if (
node.type === 'TSAbstractKeyword' ||
node.type === 'TSAnyKeyword' ||
node.type === 'TSAsyncKeyword' ||
node.type === 'TSArrayType' ||
node.type === 'TSBigIntKeyword' ||
node.type === 'TSBooleanKeyword' ||
node.type === 'TSConditionalType' ||
node.type === 'TSConstructorType' ||
node.type === 'TSDeclareKeyword' ||
node.type === 'TSExportKeyword' ||
node.type === 'TSFunctionType' ||
node.type === 'TSImportType' ||
node.type === 'TSIndexedAccessType' ||
Expand All @@ -50,7 +56,13 @@ function isTypeNode(node) {
node.type === 'TSNumberKeyword' ||
node.type === 'TSObjectKeyword' ||
node.type === 'TSOptionalType' ||
node.type === 'TSQualifiedName' ||
node.type === 'TSPrivateKeyword' ||
node.type === 'TSProtectedKeyword' ||
node.type === 'TSPublicKeyword' ||
node.type === 'TSReadonlyKeyword' ||
node.type === 'TSRestType' ||
node.type === 'TSStaticKeyword' ||
node.type === 'TSStringKeyword' ||
node.type === 'TSSymbolKeyword' ||
node.type === 'TSTemplateLiteralType' ||
Expand All @@ -65,7 +77,16 @@ function isTypeNode(node) {
node.type === 'TSUnionType' ||
node.type === 'TSUnknownKeyword' ||
node.type === 'TSVoidKeyword'
)
) {
/** @type {TypeNode['type']} for type check */
const type = node.type
noop(type)
return true
}
/** @type {Exclude<ASTNode['type'], TypeNode['type']>} for type check */
const type = node.type
noop(type)
return false
}

/**
Expand Down
7 changes: 3 additions & 4 deletions typings/eslint-plugin-vue/util-types/ast/ts-ast.ts
Expand Up @@ -92,12 +92,11 @@ export interface TSFunctionType extends TSFunctionSignatureBase {
type: 'TSFunctionType'
}

type TypeNodeTypes = `${TSESTree.TypeNode['type']}`

export type TypeNode =
| (HasParentNode & {
type: Exclude<
TSESTree.TypeNode['type'],
'TSFunctionType' | 'TSLiteralType'
>
type: Exclude<TypeNodeTypes, 'TSFunctionType' | 'TSLiteralType'>
})
| TSFunctionType
| TSLiteralType

0 comments on commit 81783b7

Please sign in to comment.