// The `beforeExpr` property is used to disambiguate between 1) binary // expression (<) and JSX Tag start (<name>); 2) object literal and JSX // texts. It is set on the `updateContext` function in the JSX plugin.
// The `startsExpr` property is used to determine whether an expression // may be the “argument” subexpression of a `yield` expression or // `yield` statement. It is set on all token types that may be at the // start of a subexpression.
// `isLoop` marks a keyword as starting a loop, which is important // to know when parsing a label, in order to allow or disallow // continue jumps to that label.
// we don't need to update context for tt.braceBarL because we do not pop context for tt.braceBarR // ideally only dollarBraceL "${" needs a non-template context // in order to indicate that the last "`" in `${`" starts a new string template // inside a template element within outer string template. // but when we popped such context in `}`, we lost track of whether this // `}` matches a `${` or other tokens matching `}`, so we have to push // such context in every token that `}` will match. tt.braceL.updateContext = tt.braceHashL.updateContext = tt.dollarBraceL.updateContext = context => { context.push(types.brace); };
clone(skipArrays?: boolean): State { const state = newState(); const keys = Object.keys(this); for (let i = 0, length = keys.length; i < length; i++) { const key = keys[i]; // $FlowIgnore let val = this[key];
if (!skipArrays && Array.isArray(val)) { val = val.slice(); }
// The current position of the tokenizer in the input. pos: number = 0; lineStart: number = 0;
// Properties of the current token: // Its type type: TokenType = tt.eof;
// For tokens that include more information than their type, the value value: any = null;
// Its start and end offset start: number = 0; end: number = 0;
// Position information for the previous token // $FlowIgnore this is initialized when generating the second token. lastTokEndLoc: Position = null; // $FlowIgnore this is initialized when generating the second token. lastTokStartLoc: Position = null; lastTokStart: number = 0; lastTokEnd: number = 0;
// The context stack is used to track whether the apostrophe "`" starts // or ends a string template context: Array<TokContext> = [ct.brace]; // Used to track whether a JSX element is allowed to form exprAllowed: boolean = true;
// Used to signal to callers of `readWord1` whether the word // contained any escape sequences. This is needed because words with // escape sequences must not be interpreted as keywords. containsEsc: boolean = false;
// This property is used to track the following errors // - StrictNumericEscape // - StrictOctalLiteral // // in a literal that occurs prior to/immediately after a "use strict" directive.
// todo(JLHwung): set strictErrors to null and avoid recording string errors // after a non-directive is parsed strictErrors: Map<number, ErrorTemplate> = newMap();
// Tokens length in token store tokensLength: number = 0;
pushToken(token: Token | N.Comment) { // Pop out invalid tokens trapped by try-catch parsing. // Those parsing branches are mainly created by typescript and flow plugins. this.tokens.length = this.state.tokensLength; this.tokens.push(token); ++this.state.tokensLength; }
// Move to the next token
next(): void { this.checkKeywordEscapes(); if (this.options.tokens) { this.pushToken(newToken(this.state)); }
// Anything else beginning with a digit is an integer, octal // number, or float. (fall through) case charCodes.digit1: case charCodes.digit2: case charCodes.digit3: case charCodes.digit4: case charCodes.digit5: case charCodes.digit6: case charCodes.digit7: case charCodes.digit8: case charCodes.digit9: this.readNumber(false); return;
// Quotes produce strings. case charCodes.quotationMark: case charCodes.apostrophe: this.readString(code); return;