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