Socket
Socket
Sign inDemoInstall

math-codegen

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

math-codegen - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

20

lib/misc/BinaryOperator.js

@@ -5,2 +5,3 @@ 'use strict';

module.exports = {
// arithmetic
'+': 'add',

@@ -12,6 +13,23 @@ '-': 'sub',

'%': 'mod',
// comparison
'<': 'lessThan',
'>': 'greaterThan',
'<=': 'lessEqualThan',
'>=': 'greaterEqualThan'
'>=': 'greaterEqualThan',
'===': 'strictlyEqual',
'==': 'equal',
'!==': 'strictlyNotEqual',
'!=': 'notEqual',
// shift
'>>': 'shiftRight',
'<<': 'shiftLeft',
'>>>': 'unsignedRightShift',
// logical
'|': 'or',
'&': 'and',
'in': 'in',
'instanceof': 'is'
};

4

lib/misc/UnaryOperator.js

@@ -8,3 +8,5 @@ 'use strict';

'!': 'logicalNegation',
'~': 'oneComplement'
'~': 'oneComplement',
'typeof': 'typeOf',
'delete': 'del'
};

@@ -6,15 +6,50 @@ /**

function equalOperator(node) {
return '(scope["' + node.left.name + '"] = ' + this.next(node.right) + ')';
return '(scope["' + node.left.name + '"] = ' + node.right + ')';
}
function equalPreProcessOperator(node) {
node.right = this.next(node.right);
return equalOperator(node);
}
function binaryProxy(node, operator) {
var right = {
type: 'BinaryExpression',
operator: operator,
left: node.left,
right: node.right
};
return equalOperator({
left: node.left,
right: this.next(right)
});
}
function binaryEqualOperator(operator) {
return function (node) {
// `this` is the Interpreter instance here
return binaryProxy.call(this, node, operator);
};
}
// https://github.com/estree/estree/blob/master/spec.md#binaryoperator
var operators = {
'=': equalOperator
'=': equalPreProcessOperator,
'+=': binaryEqualOperator('+'),
'-=': binaryEqualOperator('-'),
'*=': binaryEqualOperator('*'),
'/=': binaryEqualOperator('/'),
'%=': binaryEqualOperator('%'),
'<<=': binaryEqualOperator('<<'),
'>>=': binaryEqualOperator('>>'),
'>>>=': binaryEqualOperator('>>>'),
'|=': binaryEqualOperator('|'),
'^=': binaryEqualOperator('^'),
'&=': binaryEqualOperator('^')
};
module.exports = function (node) {
if (!(node.operator in operators)) {
throw new SyntaxError(node.operator + ' not implemented');
}
return operators[node.operator].call(this, node);
};

@@ -10,6 +10,2 @@ 'use strict';

if (!(node.operator in operators)) {
throw new SyntaxError(node.operator + ' not implemented');
}
// transform to CallExpression

@@ -16,0 +12,0 @@ var binaryNode = {

{
"name": "math-codegen",
"version": "0.1.0",
"version": "0.2.0",
"description": "Generates code from mathematical expressions",

@@ -5,0 +5,0 @@ "bugs": "https://github.com/maurizzzio/math-codegen/issues",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc