Skip to content

Commit

Permalink
fix(parser): precedence of <= and >= operators
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Feb 18, 2022
2 parents eee1cab + 4f7c86d commit 9277422
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export const enum Token {
StrictNotEqual = 61 | IsBinaryOp | 7 << PrecStart, // !==
LooseEqual = 62 | IsBinaryOp | 7 << PrecStart, // ==
LooseNotEqual = 63 | IsBinaryOp | 7 << PrecStart, // !=
LessThanOrEqual = 64 | IsBinaryOp | 7 << PrecStart, // <=
GreaterThanOrEqual = 65 | IsBinaryOp | 7 << PrecStart, // >=
LessThanOrEqual = 64 | IsBinaryOp | 8 << PrecStart, // <=
GreaterThanOrEqual = 65 | IsBinaryOp | 8 << PrecStart, // >=
LessThan = 66 | IsBinaryOp | IsExpressionStart | 8 << PrecStart, // <
GreaterThan = 67 | IsBinaryOp | 8 << PrecStart, // >
ShiftLeft = 68 | IsBinaryOp | 9 << PrecStart, // <<
Expand Down
107 changes: 107 additions & 0 deletions test/parser/expressions/logical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,113 @@ describe('Expressions - Logical', () => {
]
}
],
[
'a == b <= c',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'a'
},
right: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'b'
},
right: {
type: 'Identifier',
name: 'c'
},
operator: '<='
},
operator: '=='
}
}
]
}
],
[
'a == b >= c',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'a'
},
right: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'b'
},
right: {
type: 'Identifier',
name: 'c'
},
operator: '>='
},
operator: '=='
}
}
]
}
],
[
'a >= b !== c >= d',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'a'
},
right: {
type: 'Identifier',
name: 'b'
},
operator: '>='
},
right: {
type: 'BinaryExpression',
left: {
type: 'Identifier',
name: 'c'
},
right: {
type: 'Identifier',
name: 'd'
},
operator: '>='
},
operator: '!=='
}
}
]
}
],
[
'a << b < c',
Context.None,
Expand Down

0 comments on commit 9277422

Please sign in to comment.