Skip to content

Commit

Permalink
fix(lexer): improved identifier scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jun 22, 2019
1 parent 1e9d1b1 commit bb65cd7
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/lexer/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,24 @@ import { unicodeLookup } from '../unicode';
export function scanIdentifier(parser: ParserState, context: Context): Token {
let hasEscape: 0 | 1 = 0;
let canBeKeyword: number = CharTypes[parser.nextCP] & CharFlags.KeywordCandidate;
parser.tokenValue = '';
while ((CharTypes[nextCodePoint(parser)] & CharFlags.IdentifierPart) !== 0) {}
parser.tokenValue = parser.source.slice(parser.tokenIndex, parser.index);
if (parser.nextCP > 0x7e) return scanIdentifierSlowCase(parser, context, hasEscape, canBeKeyword);

if ((CharTypes[parser.nextCP] & CharFlags.BackSlash) === 0) {
if ((CharTypes[parser.nextCP] & CharFlags.BackSlash) === 0 && parser.nextCP < 0x7e) {
return descKeywordTable[parser.tokenValue] || Token.Identifier;
}

return scanIdentifierSlowCase(parser, context, hasEscape, canBeKeyword);
}

/**
* Scans unicode identifier
*
* @param parser Parser object
* @param context Context masks
*/
export function scanUnicodeIdentifier(parser: ParserState, context: Context): Token {
parser.tokenValue = '';
const cookedChar = scanIdentifierUnicodeEscape(parser) as number;
if (!isIdentifierPart(cookedChar)) report(parser, Errors.InvalidUnicodeEscapeSequence);
parser.tokenValue += fromCodePoint(cookedChar);
parser.tokenValue = fromCodePoint(cookedChar);
return scanIdentifierSlowCase(parser, context, 1, CharTypes[cookedChar] & CharFlags.KeywordCandidate);
}

Expand Down

0 comments on commit bb65cd7

Please sign in to comment.