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

feat: treat this in typeof this as a ThisExpression #4382

Merged
merged 19 commits into from Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/typescript-estree/tests/ast-alignment/utils.ts
@@ -1,6 +1,6 @@
// babel types are something we don't really care about
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-plus-operands */
import type { File, Program } from '@babel/types';
import type { File, Identifier, Program, TSTypeQuery } from '@babel/types';
import { AST_NODE_TYPES, TSESTree } from '../../src/ts-estree';
import { deeplyCopy, omitDeep } from '../../tools/test-utils';

Expand Down Expand Up @@ -295,6 +295,27 @@ export function preprocessBabylonAST(ast: File): any {
delete node.loc.start.index;
}
},
TSTypeQuery(node: TSTypeQuery) {
Copy link
Member

@armano2 armano2 May 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an comment with explanation why we need this and if there is babel ticket please link it here,
(this is necessary to ease maintenance of this file)

const { exprName } = node;
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;
}
}
},
},
);
}
Expand Down
Expand Up @@ -72,6 +72,7 @@ Object {
21,
],
"type": "TSTypeQuery",
"typeParameters": undefined,
},
},
},
Expand Down Expand Up @@ -214,6 +215,7 @@ Object {
47,
],
"type": "TSTypeQuery",
"typeParameters": undefined,
},
},
},
Expand Down