UNPKG

1.21 kBJavaScriptView Raw
1import {IdentifierRole} from "../parser/tokenizer";
2import {TokenType, TokenType as tt} from "../parser/tokenizer/types";
3
4import {startsWithLowerCase} from "../transformers/JSXTransformer";
5
6export 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 // Lower-case single-component tag names like "div" don't count.
24 if (!startsWithLowerCase(identifierName) || tokens.tokens[i + 1].type === TokenType.dot) {
25 nonTypeIdentifiers.add(tokens.identifierNameForToken(token));
26 }
27 }
28 }
29 return nonTypeIdentifiers;
30}