|
|
@ -11,57 +11,9 @@ import Block from '../../render_dom/Block';
|
|
|
|
import is_dynamic from '../../render_dom/wrappers/shared/is_dynamic';
|
|
|
|
import is_dynamic from '../../render_dom/wrappers/shared/is_dynamic';
|
|
|
|
import { x, b } from 'code-red';
|
|
|
|
import { x, b } from 'code-red';
|
|
|
|
import { invalidate } from '../../utils/invalidate';
|
|
|
|
import { invalidate } from '../../utils/invalidate';
|
|
|
|
import { Node, BinaryExpression, LogicalExpression, FunctionExpression } from 'estree';
|
|
|
|
import { Node, FunctionExpression } from 'estree';
|
|
|
|
import { TemplateNode } from '../../../interfaces';
|
|
|
|
import { TemplateNode } from '../../../interfaces';
|
|
|
|
|
|
|
|
|
|
|
|
const binary_operators: 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 logical_operators: Record<string, number> = {
|
|
|
|
|
|
|
|
'&&': 6,
|
|
|
|
|
|
|
|
'||': 5
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const precedence: Record<string, (node?: 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: (node: BinaryExpression) => binary_operators[node.operator],
|
|
|
|
|
|
|
|
LogicalExpression: (node: LogicalExpression) => logical_operators[node.operator],
|
|
|
|
|
|
|
|
ConditionalExpression: () => 4,
|
|
|
|
|
|
|
|
AssignmentExpression: () => 3,
|
|
|
|
|
|
|
|
YieldExpression: () => 2,
|
|
|
|
|
|
|
|
SpreadElement: () => 1,
|
|
|
|
|
|
|
|
SequenceExpression: () => 0
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Owner = Wrapper | TemplateNode;
|
|
|
|
type Owner = Wrapper | TemplateNode;
|
|
|
|
|
|
|
|
|
|
|
|
export default class Expression {
|
|
|
|
export default class Expression {
|
|
|
@ -220,10 +172,6 @@ export default class Expression {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get_precedence() {
|
|
|
|
|
|
|
|
return this.node.type in precedence ? precedence[this.node.type](this.node) : 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO move this into a render-dom wrapper?
|
|
|
|
// TODO move this into a render-dom wrapper?
|
|
|
|
manipulate(block?: Block) {
|
|
|
|
manipulate(block?: Block) {
|
|
|
|
// TODO ideally we wouldn't end up calling this method
|
|
|
|
// TODO ideally we wouldn't end up calling this method
|
|
|
|