Caret topic (pipe operator) (#13749)
* parser: Add caret as topic reference (tests) * parser: Add caret as topic reference (implement) * generator: Avoid reconstructing validTopicTokenSet * babel-parser: Remove redundant throws in expression.js * Minimize diff * Update error message Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
@@ -605,20 +605,24 @@ export default class Tokenizer extends ParserErrors {
|
||||
}
|
||||
|
||||
readToken_mult_modulo(code: number): void {
|
||||
// '%*'
|
||||
// '%' or '*'
|
||||
let type = code === charCodes.asterisk ? tt.star : tt.modulo;
|
||||
let width = 1;
|
||||
let next = this.input.charCodeAt(this.state.pos + 1);
|
||||
|
||||
// Exponentiation operator **
|
||||
// Exponentiation operator '**'
|
||||
if (code === charCodes.asterisk && next === charCodes.asterisk) {
|
||||
width++;
|
||||
next = this.input.charCodeAt(this.state.pos + 2);
|
||||
type = tt.exponent;
|
||||
}
|
||||
|
||||
// '%=' or '*='
|
||||
if (next === charCodes.equalsTo && !this.state.inType) {
|
||||
width++;
|
||||
// `tt.moduloAssign` 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.
|
||||
type = code === charCodes.percentSign ? tt.moduloAssign : tt.assign;
|
||||
}
|
||||
|
||||
@@ -692,11 +696,17 @@ export default class Tokenizer extends ParserErrors {
|
||||
}
|
||||
|
||||
readToken_caret(): void {
|
||||
// '^'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next === charCodes.equalsTo) {
|
||||
this.finishOp(tt.assign, 2);
|
||||
} else {
|
||||
|
||||
// '^='
|
||||
if (next === charCodes.equalsTo && !this.state.inType) {
|
||||
// `tt.xorAssign` 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.
|
||||
this.finishOp(tt.xorAssign, 2);
|
||||
}
|
||||
// '^'
|
||||
else {
|
||||
this.finishOp(tt.bitwiseXOR, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,8 +182,9 @@ export const tt: { [name: string]: TokenType } = {
|
||||
eq: createToken("=", { beforeExpr, isAssign }),
|
||||
assign: createToken("_=", { beforeExpr, isAssign }),
|
||||
slashAssign: createToken("_=", { 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.
|
||||
// These are only needed to support % and ^ as a Hack-pipe topic token. When the
|
||||
// proposal settles on a token, the others can be merged with tt.assign.
|
||||
xorAssign: createToken("_=", { beforeExpr, isAssign }),
|
||||
moduloAssign: createToken("_=", { beforeExpr, isAssign }),
|
||||
// end: isAssign
|
||||
|
||||
|
||||
Reference in New Issue
Block a user