Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

numenor

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

numenor - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

LICENSE

10

lib/ExpressionParser.js

@@ -86,7 +86,7 @@ "use strict";

this.setPrefix(_Lexer.TokenType.Plus, (0, _UnaryOperator.makePrefixOperatorParselet)(_Lexer.TokenType.Plus));
this.setPrefix(_Lexer.TokenType.Minus, (0, _UnaryOperator.makePrefixOperatorParselet)(_Lexer.TokenType.Minus)); // this.setPrefix(TokenType.PlusPlus, makePrefixOperatorParselet(TokenType.PlusPlus));
// this.setPrefix(TokenType.MinusMinus, makePrefixOperatorParselet(TokenType.MinusMinus));
// this.setInfix(TokenType.PlusPlus, makePostfixOperatorParselet(TokenType.PlusPlus));
// this.setInfix(TokenType.MinusMinus, makePostfixOperatorParselet(TokenType.MinusMinus));
this.setPrefix(_Lexer.TokenType.Minus, (0, _UnaryOperator.makePrefixOperatorParselet)(_Lexer.TokenType.Minus));
this.setPrefix(_Lexer.TokenType.PlusPlus, (0, _UnaryOperator.makePrefixAccessMutatorParselet)());
this.setPrefix(_Lexer.TokenType.MinusMinus, (0, _UnaryOperator.makePrefixAccessMutatorParselet)());
this.setInfix(_Lexer.TokenType.PlusPlus, (0, _UnaryOperator.makePostfixAccessMutatorParselet)(_Lexer.TokenType.PlusPlus));
this.setInfix(_Lexer.TokenType.MinusMinus, (0, _UnaryOperator.makePostfixAccessMutatorParselet)(_Lexer.TokenType.MinusMinus));
this.setInfix(_Lexer.TokenType.Dot, _MemberAccess.MemberAccess);

@@ -93,0 +93,0 @@ this.setInfix(_Lexer.TokenType.LBracket, _MemberAccess.ComputedMemberAccess);

@@ -238,3 +238,4 @@ "use strict";

line,
type: TokenType.PlusPlus
type: TokenType.PlusPlus,
operator: TokenType.Plus
};

@@ -260,3 +261,4 @@ } else if (match('=')) {

line,
type: TokenType.MinusMinus
type: TokenType.MinusMinus,
operator: TokenType.Minus
};

@@ -263,0 +265,0 @@ } else if (match('=')) {

@@ -8,7 +8,7 @@ "use strict";

exports.makePostfixOperatorParselet = makePostfixOperatorParselet;
exports.makePrefixAccessMutatorParselet = makePrefixAccessMutatorParselet;
exports.makePostfixAccessMutatorParselet = makePostfixAccessMutatorParselet;
var _ = require("./");
var _ExpressionType = require("../ExpressionType");
var _Error = require("../Error");

@@ -18,2 +18,6 @@

var ExpressionType = _interopRequireWildcard(require("../ExpressionType"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function makePrefixOperatorParselet(operator) {

@@ -26,3 +30,3 @@ return (parser, token) => {

return {
type: _ExpressionType.PrefixOperation,
type: ExpressionType.PrefixOperation,
rhs: parser.parse(),

@@ -41,3 +45,3 @@ operator

return {
type: _ExpressionType.PostfixOperation,
type: ExpressionType.PostfixOperation,
lhs,

@@ -49,2 +53,72 @@ operator

return (0, _.makeInfix)(parselet, precedence);
}
function makePrefixAccessMutatorParselet() {
return (parser, token) => {
if (!('operator' in token)) {
throw new SyntaxError((0, _Error.UnknownToken)(token));
} // ++a => (a += 1) => (a = a + 1)
const lhs = parser.parse(_Precedence.Prefix);
if (lhs.type !== ExpressionType.Identifier && lhs.type !== ExpressionType.Register && lhs.type !== ExpressionType.MemberAccess && lhs.type !== ExpressionType.ComputedMemberAccess) {
throw new SyntaxError(_Error.InvalidLeftHandSide);
}
const rhs = {
type: ExpressionType.BinaryOperation,
operator: token.operator,
rhs: {
type: ExpressionType.NumberLiteral,
value: 1
},
lhs
};
return {
type: ExpressionType.Assignment,
lhs,
rhs
};
};
}
function makePostfixAccessMutatorParselet(operator, precedence = _Precedence.Postfix) {
const parselet = (parser, lhs, token) => {
if (!('operator' in token)) {
throw new SyntaxError((0, _Error.UnknownToken)(token));
} // a++ => (#0 = a, a = a + 1, #0)
if (lhs.type !== ExpressionType.Identifier && lhs.type !== ExpressionType.Register && lhs.type !== ExpressionType.MemberAccess && lhs.type !== ExpressionType.ComputedMemberAccess) {
throw new SyntaxError(_Error.InvalidLeftHandSide);
}
const register = {
type: ExpressionType.Register,
index: 0
};
return {
type: ExpressionType.Sequence,
expressions: [{
type: ExpressionType.Assignment,
lhs: register,
rhs: lhs
}, {
type: ExpressionType.Assignment,
lhs,
rhs: {
type: ExpressionType.BinaryOperation,
lhs,
rhs: {
type: ExpressionType.NumberLiteral,
value: 1
},
operator: token.operator
}
}, register]
};
};
return (0, _.makeInfix)(parselet, precedence);
}
{
"name": "numenor",
"version": "0.0.3",
"version": "0.0.4",
"description": "Customizable, safe evaluator of JavaScript-like expressions.",

@@ -5,0 +5,0 @@ "keywords": [

# numenor
[![npm version](https://badge.fury.io/js/numenor.svg)](https://badge.fury.io/js/numenor)

@@ -22,3 +23,3 @@ Customizable, safe evaluator of JavaScript-like expressions.

evaluator.eval('2 + 2 / 2'); // -> 3
evaluator.evaluate('2 + 2 / 2'); // -> 3
```

@@ -40,2 +41,2 @@

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
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