MCPcopy Create free account
hub / github.com/browserify/static-module / Parser

Function Parser

bench/input.js:444–525  ·  view source on GitHub ↗
(options, input, startPos)

Source from the content-addressed store, hash-verified

442}
443
444var Parser = function Parser(options, input, startPos) {
445 this.options = options = getOptions(options);
446 this.sourceFile = options.sourceFile;
447 this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
448 var reserved = "";
449 if (!options.allowReserved) {
450 for (var v = options.ecmaVersion;; v--)
451 { if (reserved = reservedWords[v]) { break } }
452 if (options.sourceType == "module") { reserved += " await"; }
453 }
454 this.reservedWords = keywordRegexp(reserved);
455 var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
456 this.reservedWordsStrict = keywordRegexp(reservedStrict);
457 this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
458 this.input = String(input);
459
460 // Used to signal to callers of `readWord1` whether the word
461 // contained any escape sequences. This is needed because words with
462 // escape sequences must not be interpreted as keywords.
463 this.containsEsc = false;
464
465 // Load plugins
466 this.loadPlugins(options.plugins);
467
468 // Set up token state
469
470 // The current position of the tokenizer in the input.
471 if (startPos) {
472 this.pos = startPos;
473 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
474 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
475 } else {
476 this.pos = this.lineStart = 0;
477 this.curLine = 1;
478 }
479
480 // Properties of the current token:
481 // Its type
482 this.type = types.eof;
483 // For tokens that include more information than their type, the value
484 this.value = null;
485 // Its start and end offset
486 this.start = this.end = this.pos;
487 // And, if locations are used, the {line, column} object
488 // corresponding to those offsets
489 this.startLoc = this.endLoc = this.curPosition();
490
491 // Position information for the previous token
492 this.lastTokEndLoc = this.lastTokStartLoc = null;
493 this.lastTokStart = this.lastTokEnd = this.pos;
494
495 // The context stack is used to superficially track syntactic
496 // context to predict whether a regular expression is allowed in a
497 // given position.
498 this.context = this.initialContext();
499 this.exprAllowed = true;
500
501 // Figure out if it's a module code.

Callers

nothing calls this directly

Calls 2

getOptionsFunction · 0.85
keywordRegexpFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…