1 | import {IdentifierRole} from "../parser/tokenizer";
|
2 | import {TokenType, TokenType as tt} from "../parser/tokenizer/types";
|
3 |
|
4 | import {startsWithLowerCase} from "../transformers/JSXTransformer";
|
5 |
|
6 | export function getNonTypeIdentifiers(tokens) {
|
7 | const nonTypeIdentifiers = new Set();
|
8 | for (let i = 0; i < tokens.tokens.length; i++) {
|
9 | const token = tokens.tokens[i];
|
10 | if (
|
11 | token.type === tt.name &&
|
12 | !token.isType &&
|
13 | (token.identifierRole === IdentifierRole.Access ||
|
14 | token.identifierRole === IdentifierRole.ObjectShorthand ||
|
15 | token.identifierRole === IdentifierRole.ExportAccess) &&
|
16 | !token.shadowsGlobal
|
17 | ) {
|
18 | nonTypeIdentifiers.add(tokens.identifierNameForToken(token));
|
19 | }
|
20 | if (token.type === tt.jsxName && token.identifierRole === IdentifierRole.Access) {
|
21 | nonTypeIdentifiers.add("React");
|
22 | const identifierName = tokens.identifierNameForToken(token);
|
23 |
|
24 | if (!startsWithLowerCase(identifierName) || tokens.tokens[i + 1].type === TokenType.dot) {
|
25 | nonTypeIdentifiers.add(tokens.identifierNameForToken(token));
|
26 | }
|
27 | }
|
28 | }
|
29 | return nonTypeIdentifiers;
|
30 | }
|