Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzzen committed Jun 5, 2022
1 parent b699f0c commit fcbaa5d
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Expand Up @@ -301,23 +301,22 @@ export function preprocessBabylonAST(ast: File): any {
*/
TSTypeQuery(node: any) {
const { exprName } = node as TSTypeQuery;
const processIdentifier = (identifier: Identifier) => {
if (identifier.name === 'this') {
(identifier.type as string) = 'ThisExpression';
delete (identifier as { name?: string }).name;
}
};
if (exprName.type === 'Identifier') {
processIdentifier(exprName);
} else if (exprName.type === 'TSQualifiedName') {
let qualifiedName = exprName;
while (true) {
if (qualifiedName.left.type === 'Identifier') {
processIdentifier(qualifiedName.left);
return;
}
qualifiedName = qualifiedName.left;
let identifier: Identifier;
if (exprName.type === AST_NODE_TYPES.TSImportType) {
return;
} else if (exprName.type === AST_NODE_TYPES.TSQualifiedName) {
let iter = exprName;
while (iter.left.type === AST_NODE_TYPES.TSQualifiedName) {
iter = iter.left;
}
identifier = iter.left;
} else {
identifier = exprName;
}

if (identifier.name === 'this') {
(identifier.type as string) = AST_NODE_TYPES.ThisExpression;
delete (identifier as { name?: string }).name;
}
},
},
Expand Down

0 comments on commit fcbaa5d

Please sign in to comment.