MCPcopy
hub / github.com/jquery/esprima / lex

Method lex

src/scanner.ts:1245–1300  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1243 }
1244
1245 public lex(): RawToken {
1246 if (this.eof()) {
1247 return {
1248 type: Token.EOF,
1249 value: '',
1250 lineNumber: this.lineNumber,
1251 lineStart: this.lineStart,
1252 start: this.index,
1253 end: this.index
1254 };
1255 }
1256
1257 const cp = this.source.charCodeAt(this.index);
1258
1259 if (Character.isIdentifierStart(cp)) {
1260 return this.scanIdentifier();
1261 }
1262
1263 // Very common: ( and ) and ;
1264 if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
1265 return this.scanPunctuator();
1266 }
1267
1268 // String literal starts with single quote (U+0027) or double quote (U+0022).
1269 if (cp === 0x27 || cp === 0x22) {
1270 return this.scanStringLiteral();
1271 }
1272
1273 // Dot (.) U+002E can also start a floating-point number, hence the need
1274 // to check the next character.
1275 if (cp === 0x2E) {
1276 if (Character.isDecimalDigit(this.source.charCodeAt(this.index + 1))) {
1277 return this.scanNumericLiteral();
1278 }
1279 return this.scanPunctuator();
1280 }
1281
1282 if (Character.isDecimalDigit(cp)) {
1283 return this.scanNumericLiteral();
1284 }
1285
1286 // Template literals start with ` (U+0060) for template head
1287 // or } (U+007D) for template middle or template tail.
1288 if (cp === 0x60 || (cp === 0x7D && this.curlyStack[this.curlyStack.length - 1] === '${')) {
1289 return this.scanTemplate();
1290 }
1291
1292 // Possible identifier start in a surrogate pair.
1293 if (cp >= 0xD800 && cp < 0xDFFF) {
1294 if (Character.isIdentifierStart(this.codePointAt(this.index))) {
1295 return this.scanIdentifier();
1296 }
1297 }
1298
1299 return this.scanPunctuator();
1300 }
1301
1302}

Callers 6

angular-1.2.5.jsFile · 0.80
lexJSXMethod · 0.80
nextTokenMethod · 0.80
isLexicalDeclarationMethod · 0.80
matchAsyncFunctionMethod · 0.80
getNextTokenMethod · 0.80

Calls 7

eofMethod · 0.95
scanIdentifierMethod · 0.95
scanPunctuatorMethod · 0.95
scanStringLiteralMethod · 0.95
scanNumericLiteralMethod · 0.95
scanTemplateMethod · 0.95
codePointAtMethod · 0.95

Tested by

no test coverage detected