Skip to content

Commit

Permalink
support for AccessorProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Nov 24, 2022
1 parent a3fb7b9 commit 55c14db
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions lib/utils/indent-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const { isTypeNode } = require('./ts-ast-utils')
* @typedef {import('@typescript-eslint/types').TSESTree.TSImportEqualsDeclaration} TSImportEqualsDeclaration
* @typedef {import('@typescript-eslint/types').TSESTree.TSAbstractMethodDefinition} TSAbstractMethodDefinition
* @typedef {import('@typescript-eslint/types').TSESTree.TSAbstractPropertyDefinition} TSAbstractPropertyDefinition
* @typedef {import('@typescript-eslint/types').TSESTree.TSAbstractAccessorProperty} TSAbstractAccessorProperty
* @typedef {import('@typescript-eslint/types').TSESTree.TSEnumMember} TSEnumMember
* @typedef {import('@typescript-eslint/types').TSESTree.TSPropertySignature} TSPropertySignature
* @typedef {import('@typescript-eslint/types').TSESTree.TSIndexSignature} TSIndexSignature
Expand Down Expand Up @@ -206,15 +207,16 @@ function defineVisitor({
* | TSImportEqualsDeclaration
* | TSAbstractMethodDefinition
* | TSAbstractPropertyDefinition
* | TSAbstractClassProperty
* | TSAbstractAccessorProperty
* | TSEnumMember
* | ClassProperty
* | TSPropertySignature
* | TSIndexSignature
* | TSMethodSignature} node
* | TSMethodSignature
* | ClassProperty
* | TSAbstractClassProperty} node
*/
['TSTypeAliasDeclaration, TSCallSignatureDeclaration, TSConstructSignatureDeclaration, TSImportEqualsDeclaration,' +
'TSAbstractMethodDefinition, TSAbstractPropertyDefinition, TSEnumMember,' +
'TSAbstractMethodDefinition, TSAbstractPropertyDefinition, TSAbstractAccessorProperty, TSEnumMember,' +
'TSPropertySignature, TSIndexSignature, TSMethodSignature,' +
// Deprecated in @typescript-eslint/parser v5
'ClassProperty, TSAbstractClassProperty'](node) {
Expand Down Expand Up @@ -1073,10 +1075,10 @@ function defineVisitor({
* // ^^^^^^^
* ```
*
* @param {TSAbstractMethodDefinition | TSAbstractPropertyDefinition | TSEnumMember | TSAbstractClassProperty | ClassProperty} node
* @param {TSAbstractMethodDefinition | TSAbstractPropertyDefinition | TSAbstractAccessorProperty | TSEnumMember | TSAbstractClassProperty | ClassProperty} node
*
*/
['TSAbstractMethodDefinition, TSAbstractPropertyDefinition, TSEnumMember,' +
['TSAbstractMethodDefinition, TSAbstractPropertyDefinition, TSAbstractAccessorProperty, TSEnumMember,' +
// Deprecated in @typescript-eslint/parser v5
'ClassProperty, TSAbstractClassProperty'](node) {
const { keyNode, valueNode } =
Expand Down Expand Up @@ -1335,6 +1337,42 @@ function defineVisitor({
setOffset(atToken, 0, tokenStore.getFirstToken(decorators[0]))
}
},
AccessorProperty(node) {
const keyNode = node.key
const valueNode = node.value
const firstToken = tokenStore.getFirstToken(node)
const keyTokens = getFirstAndLastTokens(keyNode)
const prefixTokens = tokenStore.getTokensBetween(
firstToken,
keyTokens.firstToken
)
if (node.computed) {
prefixTokens.pop() // pop [
}
setOffset(prefixTokens, 0, firstToken)
let lastKeyToken
if (node.computed) {
const leftBracketToken = tokenStore.getTokenBefore(keyTokens.firstToken)
const rightBracketToken = (lastKeyToken = tokenStore.getTokenAfter(
keyTokens.lastToken
))
setOffset(leftBracketToken, 0, firstToken)
processNodeList([keyNode], leftBracketToken, rightBracketToken, 1)
} else {
setOffset(keyTokens.firstToken, 0, firstToken)
lastKeyToken = keyTokens.lastToken
}

if (valueNode != null) {
const initToken = tokenStore.getFirstToken(valueNode)
setOffset(
[...tokenStore.getTokensBetween(lastKeyToken, initToken), initToken],
1,
lastKeyToken
)
}
processSemicolons(node)
},
ImportAttribute(node) {
const firstToken = tokenStore.getFirstToken(node)
const keyTokens = getFirstAndLastTokens(node.key)
Expand Down

0 comments on commit 55c14db

Please sign in to comment.