• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2
3module.exports = function(token, tt, source) {
4  var type = token.type;
5  token.range = [token.start, token.end];
6
7  if (type === tt.name) {
8    token.type = "Identifier";
9  } else if (
10    type === tt.semi ||
11    type === tt.comma ||
12    type === tt.parenL ||
13    type === tt.parenR ||
14    type === tt.braceL ||
15    type === tt.braceR ||
16    type === tt.slash ||
17    type === tt.dot ||
18    type === tt.bracketL ||
19    type === tt.bracketR ||
20    type === tt.ellipsis ||
21    type === tt.arrow ||
22    type === tt.pipeline ||
23    type === tt.star ||
24    type === tt.incDec ||
25    type === tt.colon ||
26    type === tt.question ||
27    type === tt.questionDot ||
28    type === tt.template ||
29    type === tt.backQuote ||
30    type === tt.dollarBraceL ||
31    type === tt.at ||
32    type === tt.logicalOR ||
33    type === tt.logicalAND ||
34    type === tt.nullishCoalescing ||
35    type === tt.bitwiseOR ||
36    type === tt.bitwiseXOR ||
37    type === tt.bitwiseAND ||
38    type === tt.equality ||
39    type === tt.relational ||
40    type === tt.bitShift ||
41    type === tt.plusMin ||
42    type === tt.modulo ||
43    type === tt.exponent ||
44    type === tt.bang ||
45    type === tt.tilde ||
46    type === tt.doubleColon ||
47    type.isAssign
48  ) {
49    token.type = "Punctuator";
50    if (!token.value) token.value = type.label;
51  } else if (type === tt.jsxTagStart) {
52    token.type = "Punctuator";
53    token.value = "<";
54  } else if (type === tt.jsxTagEnd) {
55    token.type = "Punctuator";
56    token.value = ">";
57  } else if (type === tt.jsxName) {
58    token.type = "JSXIdentifier";
59  } else if (type === tt.jsxText) {
60    token.type = "JSXText";
61  } else if (type.keyword === "null") {
62    token.type = "Null";
63  } else if (type.keyword === "false" || type.keyword === "true") {
64    token.type = "Boolean";
65  } else if (type.keyword) {
66    token.type = "Keyword";
67  } else if (type === tt.num) {
68    token.type = "Numeric";
69    token.value = source.slice(token.start, token.end);
70  } else if (type === tt.string) {
71    token.type = "String";
72    token.value = source.slice(token.start, token.end);
73  } else if (type === tt.regexp) {
74    token.type = "RegularExpression";
75    var value = token.value;
76    token.regex = {
77      pattern: value.pattern,
78      flags: value.flags,
79    };
80    token.value = `/${value.pattern}/${value.flags}`;
81  }
82
83  return token;
84};
85