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

@airtasker/form-schema-compiler

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@airtasker/form-schema-compiler - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

4

lib/const.js

@@ -49,3 +49,3 @@ "use strict";

var PRECEDENCE = exports.PRECEDENCE = (_PRECEDENCE = {}, _defineProperty(_PRECEDENCE, OPERATORS.Or, 2), _defineProperty(_PRECEDENCE, OPERATORS.And, 3), _defineProperty(_PRECEDENCE, OPERATORS.GreaterThan, 7), _defineProperty(_PRECEDENCE, OPERATORS.GreaterThanOrEqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.LessThan, 7), _defineProperty(_PRECEDENCE, OPERATORS.GreaterThanOrEqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.EqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.NotEqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.Match, 7), _defineProperty(_PRECEDENCE, OPERATORS.Add, 10), _defineProperty(_PRECEDENCE, OPERATORS.Subtract, 10), _defineProperty(_PRECEDENCE, OPERATORS.Multiply, 20), _defineProperty(_PRECEDENCE, OPERATORS.Divide, 20), _defineProperty(_PRECEDENCE, OPERATORS.Remainder, 20), _PRECEDENCE);
var PRECEDENCE = exports.PRECEDENCE = (_PRECEDENCE = {}, _defineProperty(_PRECEDENCE, OPERATORS.Or, 2), _defineProperty(_PRECEDENCE, OPERATORS.And, 3), _defineProperty(_PRECEDENCE, OPERATORS.GreaterThan, 7), _defineProperty(_PRECEDENCE, OPERATORS.GreaterThanOrEqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.LessThan, 7), _defineProperty(_PRECEDENCE, OPERATORS.LessThanOrEqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.EqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.NotEqualTo, 7), _defineProperty(_PRECEDENCE, OPERATORS.Match, 7), _defineProperty(_PRECEDENCE, OPERATORS.Add, 10), _defineProperty(_PRECEDENCE, OPERATORS.Subtract, 10), _defineProperty(_PRECEDENCE, OPERATORS.Multiply, 20), _defineProperty(_PRECEDENCE, OPERATORS.Divide, 20), _defineProperty(_PRECEDENCE, OPERATORS.Remainder, 20), _PRECEDENCE);

@@ -74,2 +74,2 @@ var BOOLEANS = exports.BOOLEANS = ["false", "true"];

// [minimum version, maximum version]
var COMPATIBLE_SCHEMA_VERSION = exports.COMPATIBLE_SCHEMA_VERSION = ["0.0.1", "0.0.13"];
var COMPATIBLE_SCHEMA_VERSION = exports.COMPATIBLE_SCHEMA_VERSION = ["0.0.1", "0.0.14"];

@@ -16,3 +16,3 @@ "use strict";

var regex = right instanceof RegExp ? right : new RegExp(right);
if (left === undefined) {
if (left == null) {
return regex.test("");

@@ -43,6 +43,2 @@ }

return handleRegex(left, operator, right);
case _const.OPERATORS.Or:
return left || right;
case _const.OPERATORS.And:
return left && right;
case _const.OPERATORS.Add:

@@ -67,9 +63,20 @@ return left + right;

right = _ref2.right;
return evalBinaryExpression({
operator: operator,
left: (0, _apply2.default)(left, options),
right: (0, _apply2.default)(right, options)
});
switch (operator) {
// specially handling for OR and AND
case _const.OPERATORS.Or:
// if left is true will ignore right
return (0, _apply2.default)(left, options) || (0, _apply2.default)(right, options);
case _const.OPERATORS.And:
// if left is false will ignore right
return (0, _apply2.default)(left, options) && (0, _apply2.default)(right, options);
default:
return evalBinaryExpression({
operator: operator,
left: (0, _apply2.default)(left, options),
right: (0, _apply2.default)(right, options)
});
}
};
exports.default = applyBinaryExpression;

@@ -94,3 +94,5 @@ "use strict";

if (isPunctuation(_const.PUNCTUATIONS.Parentheses[0])) {
return parseCall(callee);
return maybeCall(function () {
return parseCall(callee);
});
}

@@ -112,3 +114,3 @@ return callee;

operator: token.value,
argument: expr()
argument: maybeUnary(expr)
};

@@ -164,5 +166,3 @@ }

function parseExpression() {
return maybeCall(function () {
return maybeBinary(parseAtom(), 0);
});
return maybeBinary(parseAtom(), 0);
}

@@ -169,0 +169,0 @@

{
"name": "@airtasker/form-schema-compiler",
"version": "0.0.13",
"version": "0.0.14",
"description": "a form schema compiler",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -56,3 +56,3 @@ export const TYPES = {

[OPERATORS.LessThan]: 7,
[OPERATORS.GreaterThanOrEqualTo]: 7,
[OPERATORS.LessThanOrEqualTo]: 7,
[OPERATORS.EqualTo]: 7,

@@ -96,2 +96,2 @@ [OPERATORS.NotEqualTo]: 7,

// [minimum version, maximum version]
export const COMPATIBLE_SCHEMA_VERSION = ["0.0.1", "0.0.13"];
export const COMPATIBLE_SCHEMA_VERSION = ["0.0.1", "0.0.14"];

@@ -6,3 +6,3 @@ import { OPERATORS } from "../const";

const regex = right instanceof RegExp ? right : new RegExp(right);
if (left === undefined) {
if (left == null) {
return regex.test("");

@@ -29,6 +29,2 @@ }

return handleRegex(left, operator, right);
case OPERATORS.Or:
return left || right;
case OPERATORS.And:
return left && right;
case OPERATORS.Add:

@@ -51,9 +47,20 @@ return left + right;

const applyBinaryExpression = ({ operator, left, right }, options) =>
evalBinaryExpression({
operator,
left: apply(left, options),
right: apply(right, options)
});
const applyBinaryExpression = ({ operator, left, right }, options) => {
switch (operator) {
// specially handling for OR and AND
case OPERATORS.Or:
// if left is true will ignore right
return apply(left, options) || apply(right, options);
case OPERATORS.And:
// if left is false will ignore right
return apply(left, options) && apply(right, options);
default:
return evalBinaryExpression({
operator,
left: apply(left, options),
right: apply(right, options)
});
}
};
export default applyBinaryExpression;

@@ -89,3 +89,3 @@ /* eslint-disable no-use-before-define */

if (isPunctuation(PUNCTUATIONS.Parentheses[0])) {
return parseCall(callee);
return maybeCall(() => parseCall(callee));
}

@@ -107,3 +107,3 @@ return callee;

operator: token.value,
argument: expr()
argument: maybeUnary(expr)
};

@@ -162,3 +162,3 @@ }

function parseExpression() {
return maybeCall(() => maybeBinary(parseAtom(), 0));
return maybeBinary(parseAtom(), 0);
}

@@ -165,0 +165,0 @@

@@ -159,17 +159,139 @@ import createInputStream from "../tokenizers/createInputStream";

});
it("should parse chained unary expression", () => {
const parsed = parse("not - + foo");
expect(parsed).toEqual({
type: TYPES.UnaryExpression,
operator: OPERATORS.Not,
argument: {
type: TYPES.UnaryExpression,
operator: OPERATORS.Subtract,
argument: {
type: TYPES.UnaryExpression,
operator: OPERATORS.Add,
argument: {
type: TYPES.Identifier,
name: "foo"
}
}
}
});
});
});
it("should parse binary expression", () => {
const parsed = parse("a < 1");
describe("binary expression", () => {
it("should parse binary expression", () => {
const parsed = parse("a < 1");
expect(parsed).toEqual({
type: TYPES.BinaryExpression,
operator: OPERATORS.LessThan,
left: {
type: TYPES.Identifier,
name: "a"
},
right: {
type: TYPES.Numeric,
value: 1
}
});
});
it("should parse an complex binary expression", () => {
debugger;
const parsed = parse("a >= 5 and b <= 2000 or c > 5 or d < 5 ");
expect(parsed).toEqual({
type: TYPES.BinaryExpression,
operator: OPERATORS.Or,
left: {
type: TYPES.BinaryExpression,
operator: OPERATORS.Or,
left: {
type: TYPES.BinaryExpression,
operator: OPERATORS.And,
left: {
type: TYPES.BinaryExpression,
operator: OPERATORS.GreaterThanOrEqualTo,
left: {
type: TYPES.Identifier,
name: "a"
},
right: {
type: TYPES.Numeric,
value: 5
}
},
right: {
type: TYPES.BinaryExpression,
operator: OPERATORS.LessThanOrEqualTo,
left: {
type: TYPES.Identifier,
name: "b"
},
right: {
type: TYPES.Numeric,
value: 2000
}
}
},
right: {
type: TYPES.BinaryExpression,
operator: OPERATORS.GreaterThan,
left: {
type: TYPES.Identifier,
name: "c"
},
right: {
type: TYPES.Numeric,
value: 5
}
}
},
right: {
type: TYPES.BinaryExpression,
operator: OPERATORS.LessThan,
left: {
type: TYPES.Identifier,
name: "d"
},
right: {
type: TYPES.Numeric,
value: 5
}
}
});
});
});
it("should parse chained call expression", () => {
const parsed = parse("hello(1)(2)(3)");
expect(parsed).toEqual({
type: TYPES.BinaryExpression,
operator: OPERATORS.LessThan,
left: {
type: TYPES.Identifier,
name: "a"
type: TYPES.CallExpression,
callee: {
type: TYPES.CallExpression,
callee: {
type: TYPES.CallExpression,
callee: {
type: TYPES.Identifier,
name: "hello"
},
arguments: [
{
type: TYPES.Numeric,
value: 1
}
]
},
arguments: [
{
type: TYPES.Numeric,
value: 2
}
]
},
right: {
type: TYPES.Numeric,
value: 1
}
arguments: [
{
type: TYPES.Numeric,
value: 3
}
]
});

@@ -176,0 +298,0 @@ });

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