agsamantha/node_modules/jintr/dist/nodes/AssignmentExpression.js

152 lines
8 KiB
JavaScript
Raw Normal View History

2024-10-02 15:15:21 -05:00
import BaseJSNode from './BaseJSNode.js';
export default class AssignmentExpression extends BaseJSNode {
run() {
const operator = this.node.operator;
const right_node = this.visitor.visitNode(this.node.right);
switch (operator) {
case '=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] = right_node;
}
else if (this.node.left.type === 'Identifier') {
this.visitor.scope.set(this.node.left.name, right_node);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '+=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] += right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) + right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '-=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] -= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) - right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '*=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] *= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) * right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '/=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] /= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) / right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '%=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] %= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) % right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '**=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] **= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) ** right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '<<=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] <<= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) << right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '>>=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] >>= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) >> right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '>>>=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] >>>= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) >>> right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
case '&=':
if (this.node.left.type === 'MemberExpression') {
const obj = this.visitor.visitNode(this.node.left.object);
const prop = this.visitor.visitNode(this.node.left.property);
return obj[prop] &= right_node;
}
else if (this.node.left.type === 'Identifier') {
const result = this.visitor.visitNode(this.node.left) & right_node;
this.visitor.scope.set(this.node.left.name, result);
return this.visitor.scope.get(this.node.left.name);
}
console.warn('Unhandled left node', this.node.left);
break;
}
}
}