* Transforms Babylon-style token to Esprima-style token. * * @param {Object} token * @param {String} source
(token: Object, source: string)
| 192 | * @param {String} source |
| 193 | */ |
| 194 | function processToken(token: Object, source: string): BabylonToken { |
| 195 | let type = token.type; |
| 196 | |
| 197 | if (type === tt.name) { |
| 198 | token.type = 'Identifier'; |
| 199 | } else if (type === tt.semi || type === tt.comma || |
| 200 | type === tt.parenL || type === tt.parenR || |
| 201 | type === tt.braceL || type === tt.braceR || |
| 202 | type === tt.slash || type === tt.dot || |
| 203 | type === tt.bracketL || type === tt.bracketR || |
| 204 | type === tt.ellipsis || type === tt.arrow || |
| 205 | type === tt.star || type === tt.incDec || |
| 206 | type === tt.colon || type === tt.question || |
| 207 | type === tt.backQuote || |
| 208 | type === tt.dollarBraceL || type === tt.at || |
| 209 | type === tt.logicalOR || type === tt.logicalAND || |
| 210 | type === tt.bitwiseOR || type === tt.bitwiseXOR || |
| 211 | type === tt.bitwiseAND || type === tt.equality || |
| 212 | type === tt.relational || type === tt.bitShift || |
| 213 | type === tt.plusMin || type === tt.modulo || |
| 214 | type === tt.exponent || type === tt.prefix || |
| 215 | type === tt.doubleColon || |
| 216 | type.isAssign) { |
| 217 | token.type = 'Punctuator'; |
| 218 | if (!token.value) { |
| 219 | token.sourceCode = token.value = type.label; |
| 220 | } |
| 221 | } else if (type === tt.template) { |
| 222 | token.type = 'Template'; |
| 223 | token.sourceCode = token.value; |
| 224 | } else if (type === tt.jsxTagStart) { |
| 225 | token.type = 'Punctuator'; |
| 226 | token.sourceCode = token.value = '<'; |
| 227 | } else if (type === tt.jsxTagEnd) { |
| 228 | token.type = 'Punctuator'; |
| 229 | token.sourceCode = token.value = '>'; |
| 230 | } else if (type === tt.jsxName) { |
| 231 | token.type = 'JSXIdentifier'; |
| 232 | } else if (type === tt.jsxText) { |
| 233 | token.type = 'JSXText'; |
| 234 | } else if (type.keyword === 'null') { |
| 235 | token.type = 'Null'; |
| 236 | token.value = null; |
| 237 | } else if (type.keyword === 'false' || type.keyword === 'true') { |
| 238 | token.type = 'Boolean'; |
| 239 | token.value = type.keyword === 'true'; |
| 240 | } else if (type.keyword) { |
| 241 | token.type = 'Keyword'; |
| 242 | } else if (type === tt.num) { |
| 243 | token.type = 'Numeric'; |
| 244 | } else if (type === tt.string) { |
| 245 | token.type = 'String'; |
| 246 | } else if (type === tt.regexp) { |
| 247 | token.type = 'RegularExpression'; |
| 248 | } else if (type === 'CommentLine') { |
| 249 | token.sourceCode = '//' + token.value; |
| 250 | } else if (type === 'CommentBlock') { |
| 251 | token.sourceCode = '/*' + token.value + '*/'; |
no outgoing calls
no test coverage detected
searching dependent graphs…