UNPKG

2.07 kBJavaScriptView Raw
1"use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }Object.defineProperty(exports, "__esModule", {value: true});
2var _tokenizer = require('../parser/tokenizer');
3var _types = require('../parser/tokenizer/types');
4
5var _JSXTransformer = require('../transformers/JSXTransformer');
6var _getJSXPragmaInfo = require('./getJSXPragmaInfo'); var _getJSXPragmaInfo2 = _interopRequireDefault(_getJSXPragmaInfo);
7
8 function getNonTypeIdentifiers(tokens, options) {
9 const jsxPragmaInfo = _getJSXPragmaInfo2.default.call(void 0, 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 === _types.TokenType.name &&
15 !token.isType &&
16 (token.identifierRole === _tokenizer.IdentifierRole.Access ||
17 token.identifierRole === _tokenizer.IdentifierRole.ObjectShorthand ||
18 token.identifierRole === _tokenizer.IdentifierRole.ExportAccess) &&
19 !token.shadowsGlobal
20 ) {
21 nonTypeIdentifiers.add(tokens.identifierNameForToken(token));
22 }
23 if (token.type === _types.TokenType.jsxTagStart) {
24 nonTypeIdentifiers.add(jsxPragmaInfo.base);
25 }
26 if (
27 token.type === _types.TokenType.jsxTagStart &&
28 i + 1 < tokens.tokens.length &&
29 tokens.tokens[i + 1].type === _types.TokenType.jsxTagEnd
30 ) {
31 nonTypeIdentifiers.add(jsxPragmaInfo.base);
32 nonTypeIdentifiers.add(jsxPragmaInfo.fragmentBase);
33 }
34 if (token.type === _types.TokenType.jsxName && token.identifierRole === _tokenizer.IdentifierRole.Access) {
35 const identifierName = tokens.identifierNameForToken(token);
36 // Lower-case single-component tag names like "div" don't count.
37 if (!_JSXTransformer.startsWithLowerCase.call(void 0, identifierName) || tokens.tokens[i + 1].type === _types.TokenType.dot) {
38 nonTypeIdentifiers.add(tokens.identifierNameForToken(token));
39 }
40 }
41 }
42 return nonTypeIdentifiers;
43} exports.getNonTypeIdentifiers = getNonTypeIdentifiers;