Fix %== parsing in hack pipes (#13536)
* Fix `%==` parsing in hack pipes * Use custom token type * Update packages/babel-parser/src/parser/expression.js Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> * Apply suggestions from code review Co-authored-by: J. S. Choi <jschoi@jschoi.org> Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> Co-authored-by: J. S. Choi <jschoi@jschoi.org>
This commit is contained in:
@@ -615,7 +615,7 @@ export default class Tokenizer extends ParserErrors {
|
||||
|
||||
if (next === charCodes.equalsTo && !this.state.inType) {
|
||||
width++;
|
||||
type = tt.assign;
|
||||
type = code === charCodes.percentSign ? tt.moduloAssign : tt.assign;
|
||||
}
|
||||
|
||||
this.finishOp(type, width);
|
||||
|
||||
@@ -140,6 +140,9 @@ export const types: { [name: string]: TokenType } = {
|
||||
eq: new TokenType("=", { beforeExpr, isAssign }),
|
||||
assign: new TokenType("_=", { beforeExpr, isAssign }),
|
||||
slashAssign: new TokenType("_=", { beforeExpr, isAssign }),
|
||||
// This is only needed to support % as a Hack-pipe topic token. If the proposal
|
||||
// ends up choosing a different token, it can be merged with tt.assign.
|
||||
moduloAssign: new TokenType("_=", { beforeExpr, isAssign }),
|
||||
incDec: new TokenType("++/--", { prefix, postfix, startsExpr }),
|
||||
bang: new TokenType("!", { beforeExpr, prefix, startsExpr }),
|
||||
tilde: new TokenType("~", { beforeExpr, prefix, startsExpr }),
|
||||
|
||||
Reference in New Issue
Block a user