diff --git a/lib/rules/define-emits-declaration.js b/lib/rules/define-emits-declaration.js index 4daf4115c..478e1d840 100644 --- a/lib/rules/define-emits-declaration.js +++ b/lib/rules/define-emits-declaration.js @@ -47,7 +47,8 @@ module.exports = { } case 'runtime': { - if (node.typeParameters && node.typeParameters.params.length > 0) { + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments && typeArguments.params.length > 0) { context.report({ node, messageId: 'hasTypeArg' diff --git a/lib/rules/define-props-declaration.js b/lib/rules/define-props-declaration.js index c6fe4ffdc..d355bb2fc 100644 --- a/lib/rules/define-props-declaration.js +++ b/lib/rules/define-props-declaration.js @@ -47,7 +47,8 @@ module.exports = { } case 'runtime': { - if (node.typeParameters && node.typeParameters.params.length > 0) { + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments && typeArguments.params.length > 0) { context.report({ node, messageId: 'hasTypeArg' diff --git a/lib/rules/require-typed-ref.js b/lib/rules/require-typed-ref.js index 4ae12b040..2f691fec1 100644 --- a/lib/rules/require-typed-ref.js +++ b/lib/rules/require-typed-ref.js @@ -83,7 +83,9 @@ module.exports = { continue } - if (ref.node.typeParameters == null) { + const typeArguments = + ref.node.typeArguments || ref.node.typeParameters + if (typeArguments == null) { if ( ref.node.parent.type === 'VariableDeclarator' && ref.node.parent.id.type === 'Identifier' diff --git a/lib/rules/valid-define-emits.js b/lib/rules/valid-define-emits.js index 64d3fd15a..994302c60 100644 --- a/lib/rules/valid-define-emits.js +++ b/lib/rules/valid-define-emits.js @@ -47,8 +47,9 @@ module.exports = { onDefineEmitsEnter(node) { defineEmitsNodes.push(node) + const typeArguments = node.typeArguments || node.typeParameters if (node.arguments.length > 0) { - if (node.typeParameters && node.typeParameters.params.length > 0) { + if (typeArguments && typeArguments.params.length > 0) { // `defineEmits` has both a literal type and an argument. context.report({ node, @@ -59,10 +60,7 @@ module.exports = { emitsDefExpressions.add(node.arguments[0]) } else { - if ( - !node.typeParameters || - node.typeParameters.params.length === 0 - ) { + if (!typeArguments || typeArguments.params.length === 0) { emptyDefineEmits = node } } diff --git a/lib/rules/valid-define-options.js b/lib/rules/valid-define-options.js index 784ac3fbd..c1cd5b993 100644 --- a/lib/rules/valid-define-options.js +++ b/lib/rules/valid-define-options.js @@ -74,9 +74,10 @@ module.exports = { }) } - if (node.typeParameters) { + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments) { context.report({ - node: node.typeParameters, + node: typeArguments, messageId: 'typeArgs' }) } diff --git a/lib/rules/valid-define-props.js b/lib/rules/valid-define-props.js index 43cce1d3c..ecde56f15 100644 --- a/lib/rules/valid-define-props.js +++ b/lib/rules/valid-define-props.js @@ -48,8 +48,9 @@ module.exports = { onDefinePropsEnter(node) { definePropsNodes.push(node) + const typeArguments = node.typeArguments || node.typeParameters if (node.arguments.length > 0) { - if (node.typeParameters && node.typeParameters.params.length > 0) { + if (typeArguments && typeArguments.params.length > 0) { // `defineProps` has both a literal type and an argument. context.report({ node, @@ -60,10 +61,7 @@ module.exports = { propsDefExpressions.add(node.arguments[0]) } else { - if ( - !node.typeParameters || - node.typeParameters.params.length === 0 - ) { + if (!typeArguments || typeArguments.params.length === 0) { emptyDefineProps = node } } diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index 5b97f37b5..6119406e7 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -1168,21 +1168,22 @@ module.exports.defineVisitor = function create( }, /** @param {CallExpression} node */ CallExpression(node) { + const typeArguments = node.typeArguments || node.typeParameters const firstToken = tokenStore.getFirstToken(node) const rightToken = tokenStore.getLastToken(node) const leftToken = /** @type {Token} */ ( tokenStore.getTokenAfter( - node.typeParameters || node.callee, + typeArguments || node.callee, isOpeningParenToken ) ) - if (node.typeParameters) { - setOffset(tokenStore.getFirstToken(node.typeParameters), 1, firstToken) + if (typeArguments) { + setOffset(tokenStore.getFirstToken(typeArguments), 1, firstToken) } for (const optionalToken of tokenStore.getTokensBetween( - tokenStore.getLastToken(node.typeParameters || node.callee), + tokenStore.getLastToken(typeArguments || node.callee), leftToken, isOptionalToken )) { @@ -1694,19 +1695,20 @@ module.exports.defineVisitor = function create( }, /** @param {NewExpression} node */ NewExpression(node) { + const typeArguments = node.typeArguments || node.typeParameters const newToken = tokenStore.getFirstToken(node) const calleeToken = tokenStore.getTokenAfter(newToken) const rightToken = tokenStore.getLastToken(node) const leftToken = isClosingParenToken(rightToken) ? tokenStore.getFirstTokenBetween( - node.typeParameters || node.callee, + typeArguments || node.callee, rightToken, isOpeningParenToken ) : null - if (node.typeParameters) { - setOffset(tokenStore.getFirstToken(node.typeParameters), 1, calleeToken) + if (typeArguments) { + setOffset(tokenStore.getFirstToken(typeArguments), 1, calleeToken) } setOffset(calleeToken, 1, newToken) diff --git a/lib/utils/indent-ts.js b/lib/utils/indent-ts.js index c6f146f66..a4323b38f 100644 --- a/lib/utils/indent-ts.js +++ b/lib/utils/indent-ts.js @@ -332,9 +332,10 @@ function defineVisitor({ * @param {TSTypeReference | TSInstantiationExpression} node */ 'TSTypeReference, TSInstantiationExpression'(node) { - if (node.typeParameters) { + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments) { const firstToken = tokenStore.getFirstToken(node) - setOffset(tokenStore.getFirstToken(node.typeParameters), 1, firstToken) + setOffset(tokenStore.getFirstToken(typeArguments), 1, firstToken) } }, /** diff --git a/lib/utils/index.js b/lib/utils/index.js index 0c9a4ac99..8702c6260 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -2990,11 +2990,9 @@ function getComponentPropsFromDefineProps(context, node) { } ] } - if (node.typeParameters && node.typeParameters.params.length > 0) { - return getComponentPropsFromTypeDefine( - context, - node.typeParameters.params[0] - ) + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments && typeArguments.params.length > 0) { + return getComponentPropsFromTypeDefine(context, typeArguments.params[0]) } return [ { @@ -3025,11 +3023,9 @@ function getComponentEmitsFromDefineEmits(context, node) { } ] } - if (node.typeParameters && node.typeParameters.params.length > 0) { - return getComponentEmitsFromTypeDefine( - context, - node.typeParameters.params[0] - ) + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments && typeArguments.params.length > 0) { + return getComponentEmitsFromTypeDefine(context, typeArguments.params[0]) } return [ { diff --git a/lib/utils/ts-utils/ts-ast.js b/lib/utils/ts-utils/ts-ast.js index d019b77cd..8a95dd9b1 100644 --- a/lib/utils/ts-utils/ts-ast.js +++ b/lib/utils/ts-utils/ts-ast.js @@ -430,33 +430,28 @@ function inferRuntimeType(context, node, checked = new Set()) { return ['Array'] } case 'NonNullable': { - if (node.typeParameters && node.typeParameters.params[0]) { + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments && typeArguments.params[0]) { return inferRuntimeType( context, - node.typeParameters.params[0], + typeArguments.params[0], checked ).filter((t) => t !== 'null') } break } case 'Extract': { - if (node.typeParameters && node.typeParameters.params[1]) { - return inferRuntimeType( - context, - node.typeParameters.params[1], - checked - ) + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments && typeArguments.params[1]) { + return inferRuntimeType(context, typeArguments.params[1], checked) } break } case 'Exclude': case 'OmitThisParameter': { - if (node.typeParameters && node.typeParameters.params[0]) { - return inferRuntimeType( - context, - node.typeParameters.params[0], - checked - ) + const typeArguments = node.typeArguments || node.typeParameters + if (typeArguments && typeArguments.params[0]) { + return inferRuntimeType(context, typeArguments.params[0], checked) } break } diff --git a/tests/integrations/eslint-plugin-import.js b/tests/integrations/eslint-plugin-import.js index a408fdcdd..4e26508ce 100644 --- a/tests/integrations/eslint-plugin-import.js +++ b/tests/integrations/eslint-plugin-import.js @@ -30,10 +30,12 @@ describe('Integration with eslint-plugin-import', () => { if ( !semver.satisfies( process.version, - require(path.join( - __dirname, - 'eslint-plugin-import/node_modules/eslint/package.json' - )).engines.node + require( + path.join( + __dirname, + 'eslint-plugin-import/node_modules/eslint/package.json' + ) + ).engines.node ) ) { return diff --git a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts index 944246411..db3a7f39c 100644 --- a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts +++ b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts @@ -519,7 +519,10 @@ export interface CallExpression extends HasParentNode { callee: Expression | Super arguments: (Expression | SpreadElement)[] optional: boolean - typeParameters?: TS.TSTypeParameterInstantiation + typeArguments?: TS.TSTypeParameterInstantiation + + /* @deprecated */ + typeParameters: never } export interface Super extends HasParentNode { type: 'Super' @@ -528,7 +531,10 @@ export interface NewExpression extends HasParentNode { type: 'NewExpression' callee: Expression arguments: (Expression | SpreadElement)[] - typeParameters?: TSTypeParameterInstantiation + typeArguments?: TSTypeParameterInstantiation + + /* @deprecated */ + typeParameters: never } interface BaseMemberExpression extends HasParentNode { type: 'MemberExpression'