mirror of https://github.com/sveltejs/svelte
parent
7224ef4eff
commit
4c8a5c598d
@ -1,54 +0,0 @@
|
||||
import { Node } from '../interfaces';
|
||||
|
||||
const binaryOperators: Record<string, number> = {
|
||||
'**': 15,
|
||||
'*': 14,
|
||||
'/': 14,
|
||||
'%': 14,
|
||||
'+': 13,
|
||||
'-': 13,
|
||||
'<<': 12,
|
||||
'>>': 12,
|
||||
'>>>': 12,
|
||||
'<': 11,
|
||||
'<=': 11,
|
||||
'>': 11,
|
||||
'>=': 11,
|
||||
'in': 11,
|
||||
'instanceof': 11,
|
||||
'==': 10,
|
||||
'!=': 10,
|
||||
'===': 10,
|
||||
'!==': 10,
|
||||
'&': 9,
|
||||
'^': 8,
|
||||
'|': 7
|
||||
};
|
||||
|
||||
const logicalOperators: Record<string, number> = {
|
||||
'&&': 6,
|
||||
'||': 5
|
||||
};
|
||||
|
||||
const precedence: Record<string, (expression?: Node) => number> = {
|
||||
Literal: () => 21,
|
||||
Identifier: () => 21,
|
||||
ParenthesizedExpression: () => 20,
|
||||
MemberExpression: () => 19,
|
||||
NewExpression: () => 19, // can be 18 (if no args) but makes no practical difference
|
||||
CallExpression: () => 19,
|
||||
UpdateExpression: () => 17,
|
||||
UnaryExpression: () => 16,
|
||||
BinaryExpression: (expression: Node) => binaryOperators[expression.operator],
|
||||
LogicalExpression: (expression: Node) => logicalOperators[expression.operator],
|
||||
ConditionalExpression: () => 4,
|
||||
AssignmentExpression: () => 3,
|
||||
YieldExpression: () => 2,
|
||||
SpreadElement: () => 1,
|
||||
SequenceExpression: () => 0
|
||||
};
|
||||
|
||||
// TODO make this a method of Expression
|
||||
export default function getExpressionPrecedence(expression: Node) {
|
||||
return expression.type in precedence ? precedence[expression.type](expression) : 0;
|
||||
}
|
Loading…
Reference in new issue