Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace typeParameters with typeArguments #2292

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rules/define-emits-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/define-props-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/require-typed-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 3 additions & 5 deletions lib/rules/valid-define-emits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/valid-define-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
}
Expand Down
8 changes: 3 additions & 5 deletions lib/rules/valid-define-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
}
Expand Down
16 changes: 9 additions & 7 deletions lib/utils/indent-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)) {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/utils/indent-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
/**
Expand Down
16 changes: 6 additions & 10 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
{
Expand Down Expand Up @@ -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 [
{
Expand Down
23 changes: 9 additions & 14 deletions lib/utils/ts-utils/ts-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 6 additions & 4 deletions tests/integrations/eslint-plugin-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions typings/eslint-plugin-vue/util-types/ast/es-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down