@airtasker/form-schema-compiler
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -1,8 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
var _const = require('../const'); | ||
var _const = require("../const"); | ||
var _utils = require('./utils'); | ||
var _utils = require("./utils"); | ||
@@ -49,3 +49,3 @@ var utils = _interopRequireWildcard(_utils); | ||
if (!isPunctuation(ch)) { | ||
tokenStream.croak('Expecting punctuation: "' + ch + '"'); | ||
tokenStream.croak("Expecting punctuation: \"" + ch + "\""); | ||
} | ||
@@ -101,3 +101,3 @@ tokenStream.next(); | ||
/** | ||
* return an unary expressio if current token is -+! | ||
* return an unary expression if current token is -+! | ||
* @param expr | ||
@@ -133,5 +133,3 @@ * @returns {*} | ||
tokenStream.next(); | ||
var right = maybeUnary(function () { | ||
return maybeBinary(parseAtom(), rightOpPrec); | ||
}); | ||
var right = maybeBinary(parseAtom(), rightOpPrec); | ||
var binary = { | ||
@@ -168,5 +166,3 @@ type: _const.TYPES.BinaryExpression, | ||
return maybeCall(function () { | ||
return maybeUnary(function () { | ||
return maybeBinary(parseAtom(), 0); | ||
}); | ||
return maybeBinary(parseAtom(), 0); | ||
}); | ||
@@ -205,3 +201,3 @@ } | ||
tokenStream.croak('Unexpected token: ' + JSON.stringify(token || tokenStream.peek())); | ||
tokenStream.croak("Unexpected token: " + JSON.stringify(token || tokenStream.peek())); | ||
} | ||
@@ -208,0 +204,0 @@ |
@@ -110,6 +110,8 @@ "use strict"; | ||
var readString = function readString() { | ||
var readString = function readString(ch) { | ||
return { | ||
type: _const.TYPES.String, | ||
value: utils.readEscaped(inputStream, utils.isStringStart) | ||
value: utils.readEscaped(inputStream, function (c) { | ||
return c === ch; | ||
}) | ||
}; | ||
@@ -165,3 +167,3 @@ }; | ||
if (utils.isStringStart(ch)) { | ||
return readString(); | ||
return readString(ch); | ||
} | ||
@@ -168,0 +170,0 @@ if (utils.isDigit(ch)) { |
{ | ||
"name": "@airtasker/form-schema-compiler", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "a form schema compiler", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"build:commonjs": | ||
"cross-env BABEL_ENV=commonjs babel src --out-dir lib --ignore test.js", | ||
"build:umd": | ||
"cross-env BABEL_ENV=rollup NODE_ENV=development rollup -c -o dist/form-schema-compiler.js", | ||
"build:umd:min": | ||
"cross-env BABEL_ENV=rollup NODE_ENV=min rollup -c -o dist/form-schema-compiler.min.js", | ||
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --ignore test.js", | ||
"build:umd": "cross-env BABEL_ENV=rollup NODE_ENV=development rollup -c -o dist/form-schema-compiler.js", | ||
"build:umd:min": "cross-env BABEL_ENV=rollup NODE_ENV=min rollup -c -o dist/form-schema-compiler.min.js", | ||
"build": "npm run build:commonjs", | ||
@@ -22,4 +19,15 @@ "clean": "rimraf lib dist coverage", | ||
}, | ||
"files": ["dist", "lib", "src", "es"], | ||
"keywords": ["react", "reactjs", "backbone", "flux", "redux"], | ||
"files": [ | ||
"dist", | ||
"lib", | ||
"src", | ||
"es" | ||
], | ||
"keywords": [ | ||
"react", | ||
"reactjs", | ||
"backbone", | ||
"flux", | ||
"redux" | ||
], | ||
"author": "Zhenxi (Eric) Chen <eric.chen@airtasker.com>", | ||
@@ -26,0 +34,0 @@ "license": "MIT", |
/* eslint-disable no-use-before-define */ | ||
import { OPERATORS, PRECEDENCE, PUNCTUATIONS, TYPES } from '../const'; | ||
import * as utils from './utils'; | ||
import { OPERATORS, PRECEDENCE, PUNCTUATIONS, TYPES } from "../const"; | ||
import * as utils from "./utils"; | ||
@@ -19,8 +19,6 @@ /** | ||
*/ | ||
const parseExpressionTokenStream = (tokenStream) => { | ||
const isPunctuation = (paren) => | ||
utils.isPunctuation(tokenStream.peek(), paren); | ||
const parseExpressionTokenStream = tokenStream => { | ||
const isPunctuation = paren => utils.isPunctuation(tokenStream.peek(), paren); | ||
const isOperator = (operator) => | ||
utils.isOperator(tokenStream.peek(), operator); | ||
const isOperator = operator => utils.isOperator(tokenStream.peek(), operator); | ||
@@ -38,3 +36,3 @@ const isUnary = () => | ||
TYPES.RegExp, | ||
TYPES.Boolean, | ||
TYPES.Boolean | ||
]; | ||
@@ -46,3 +44,3 @@ | ||
*/ | ||
const skipPunctuation = (ch) => { | ||
const skipPunctuation = ch => { | ||
if (!isPunctuation(ch)) { | ||
@@ -100,3 +98,3 @@ tokenStream.croak(`Expecting punctuation: "${ch}"`); | ||
/** | ||
* return an unary expressio if current token is -+! | ||
* return an unary expression if current token is -+! | ||
* @param expr | ||
@@ -112,3 +110,3 @@ * @returns {*} | ||
operator: token.value, | ||
argument: expr(), | ||
argument: expr() | ||
}; | ||
@@ -131,3 +129,3 @@ } | ||
tokenStream.next(); | ||
const right = maybeUnary(() => maybeBinary(parseAtom(), rightOpPrec)); | ||
const right = maybeBinary(parseAtom(), rightOpPrec); | ||
const binary = { | ||
@@ -137,3 +135,3 @@ type: TYPES.BinaryExpression, | ||
left, | ||
right, | ||
right | ||
}; | ||
@@ -159,4 +157,4 @@ return maybeBinary(binary, leftOpPrec); | ||
PUNCTUATIONS.Separator, | ||
parseExpression, | ||
), | ||
parseExpression | ||
) | ||
}; | ||
@@ -170,3 +168,3 @@ } | ||
function parseExpression() { | ||
return maybeCall(() => maybeUnary(() => maybeBinary(parseAtom(), 0))); | ||
return maybeCall(() => maybeBinary(parseAtom(), 0)); | ||
} | ||
@@ -197,4 +195,4 @@ | ||
unexpected(token); | ||
}, | ||
), | ||
} | ||
) | ||
); | ||
@@ -205,3 +203,3 @@ } | ||
tokenStream.croak( | ||
`Unexpected token: ${JSON.stringify(token || tokenStream.peek())}`, | ||
`Unexpected token: ${JSON.stringify(token || tokenStream.peek())}` | ||
); | ||
@@ -208,0 +206,0 @@ } |
@@ -1,46 +0,57 @@ | ||
import createInputStream from '../tokenizers/createInputStream'; | ||
import createExpressionTokenStream from '../tokenizers/createExpressionTokenStream'; | ||
import parseExpressionTokenStream from './parseExpressionTokenStream'; | ||
import createInputStream from "../tokenizers/createInputStream"; | ||
import createExpressionTokenStream from "../tokenizers/createExpressionTokenStream"; | ||
import parseExpressionTokenStream from "./parseExpressionTokenStream"; | ||
import { | ||
OPERATORS, | ||
TYPES, | ||
} from '../const'; | ||
import { OPERATORS, TYPES } from "../const"; | ||
const parse = (str) => | ||
const parse = str => | ||
parseExpressionTokenStream( | ||
createExpressionTokenStream(createInputStream(str)), | ||
createExpressionTokenStream(createInputStream(str)) | ||
); | ||
describe('parseExpressionTokenStream', () => { | ||
it('should parse identifier', () => { | ||
const parsed = parse('foobar'); | ||
describe("parseExpressionTokenStream", () => { | ||
it("should parse identifier", () => { | ||
const parsed = parse("foobar"); | ||
expect(parsed).toEqual({ | ||
type: TYPES.Identifier, | ||
name: 'foobar', | ||
name: "foobar" | ||
}); | ||
}); | ||
it('should parse null', () => { | ||
const parsed = parse('null'); | ||
it("should parse null", () => { | ||
const parsed = parse("null"); | ||
expect(parsed).toEqual({ | ||
type: TYPES.Null, | ||
value: null, | ||
value: null | ||
}); | ||
}); | ||
describe('should parse boolean', () => { | ||
it('should parse true', () => { | ||
const parsed = parse('true'); | ||
it("should parse string", () => { | ||
const parsed = parse(`'asdfsad"f'`); | ||
expect(parsed).toEqual({ | ||
type: TYPES.String, | ||
value: 'asdfsad"f' | ||
}); | ||
const parsed2 = parse(`"asdfsad'f"`); | ||
expect(parsed2).toEqual({ | ||
type: TYPES.String, | ||
value: "asdfsad'f" | ||
}); | ||
}); | ||
describe("should parse boolean", () => { | ||
it("should parse true", () => { | ||
const parsed = parse("true"); | ||
expect(parsed).toEqual({ | ||
type: TYPES.Boolean, | ||
value: true, | ||
value: true | ||
}); | ||
}); | ||
it('should parse false', () => { | ||
const parsed = parse('false'); | ||
it("should parse false", () => { | ||
const parsed = parse("false"); | ||
expect(parsed).toEqual({ | ||
type: TYPES.Boolean, | ||
value: false, | ||
value: false | ||
}); | ||
@@ -50,5 +61,5 @@ }); | ||
describe('should parse expression', () => { | ||
it('should parse not unary expression', () => { | ||
const parsed = parse('not true'); | ||
describe("should parse expression", () => { | ||
it("should parse not unary expression", () => { | ||
const parsed = parse("not true"); | ||
expect(parsed).toEqual({ | ||
@@ -59,9 +70,45 @@ type: TYPES.UnaryExpression, | ||
type: TYPES.Boolean, | ||
value: true, | ||
value: true | ||
} | ||
}); | ||
}); | ||
it("should parse complicate not unary expression", () => { | ||
const parsed = parse("not true or not (true is not false)"); | ||
expect(parsed).toEqual({ | ||
type: TYPES.BinaryExpression, | ||
left: { | ||
type: TYPES.UnaryExpression, | ||
operator: OPERATORS.Not, | ||
argument: { | ||
type: TYPES.Boolean, | ||
value: true | ||
} | ||
}, | ||
operator: OPERATORS.Or, | ||
right: { | ||
type: TYPES.UnaryExpression, | ||
operator: OPERATORS.Not, | ||
argument: { | ||
type: TYPES.BinaryExpression, | ||
left: { | ||
type: TYPES.Boolean, | ||
value: true | ||
}, | ||
operator: OPERATORS.EqualTo, | ||
right: { | ||
type: TYPES.UnaryExpression, | ||
operator: OPERATORS.Not, | ||
argument: { | ||
type: TYPES.Boolean, | ||
value: false | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
it('should parse subtract unary expression', () => { | ||
const parsed = parse('-1'); | ||
it("should parse subtract unary expression", () => { | ||
const parsed = parse("-1"); | ||
expect(parsed).toEqual({ | ||
@@ -72,9 +119,9 @@ type: TYPES.UnaryExpression, | ||
type: TYPES.Numeric, | ||
value: 1, | ||
}, | ||
value: 1 | ||
} | ||
}); | ||
}); | ||
it('should parse add unary expression', () => { | ||
const parsed = parse('+foo'); | ||
it("should parse add unary expression", () => { | ||
const parsed = parse("+foo"); | ||
expect(parsed).toEqual({ | ||
@@ -85,9 +132,9 @@ type: TYPES.UnaryExpression, | ||
type: TYPES.Identifier, | ||
name: 'foo', | ||
}, | ||
name: "foo" | ||
} | ||
}); | ||
}); | ||
it('should parse binary expression', () => { | ||
const parsed = parse('a < 1'); | ||
it("should parse binary expression", () => { | ||
const parsed = parse("a < 1"); | ||
expect(parsed).toEqual({ | ||
@@ -98,12 +145,12 @@ type: TYPES.BinaryExpression, | ||
type: TYPES.Identifier, | ||
name: 'a', | ||
name: "a" | ||
}, | ||
right: { | ||
type: TYPES.Numeric, | ||
value: 1, | ||
}, | ||
value: 1 | ||
} | ||
}); | ||
}); | ||
it('should parse call expression', () => { | ||
it("should parse call expression", () => { | ||
const parsed = parse('hello(a, "c")'); | ||
@@ -114,3 +161,3 @@ expect(parsed).toEqual({ | ||
type: TYPES.Identifier, | ||
name: 'hello', | ||
name: "hello" | ||
}, | ||
@@ -120,14 +167,14 @@ arguments: [ | ||
type: TYPES.Identifier, | ||
name: 'a', | ||
name: "a" | ||
}, | ||
{ | ||
type: TYPES.String, | ||
value: 'c', | ||
}, | ||
], | ||
value: "c" | ||
} | ||
] | ||
}); | ||
}); | ||
it('should parse an equation expression', () => { | ||
const parsed = parse('1 + 2 * 3 - -4'); | ||
it("should parse an equation expression", () => { | ||
const parsed = parse("1 + 2 * 3 - -4"); | ||
expect(parsed).toEqual({ | ||
@@ -141,3 +188,3 @@ type: TYPES.BinaryExpression, | ||
type: TYPES.Numeric, | ||
value: 1, | ||
value: 1 | ||
}, | ||
@@ -149,9 +196,9 @@ right: { | ||
type: TYPES.Numeric, | ||
value: 2, | ||
value: 2 | ||
}, | ||
right: { | ||
type: TYPES.Numeric, | ||
value: 3, | ||
}, | ||
}, | ||
value: 3 | ||
} | ||
} | ||
}, | ||
@@ -163,10 +210,10 @@ right: { | ||
type: TYPES.Numeric, | ||
value: 4, | ||
}, | ||
}, | ||
value: 4 | ||
} | ||
} | ||
}); | ||
}); | ||
it('should parse a complex expression', () => { | ||
const parsed = parse('1 * +2 isnt not 3'); | ||
it("should parse a complex expression", () => { | ||
const parsed = parse("1 * +2 isnt not 3"); | ||
expect(parsed).toEqual({ | ||
@@ -180,3 +227,3 @@ type: TYPES.BinaryExpression, | ||
type: TYPES.Numeric, | ||
value: 1, | ||
value: 1 | ||
}, | ||
@@ -188,5 +235,5 @@ right: { | ||
type: TYPES.Numeric, | ||
value: 2, | ||
}, | ||
}, | ||
value: 2 | ||
} | ||
} | ||
}, | ||
@@ -198,10 +245,10 @@ right: { | ||
type: TYPES.Numeric, | ||
value: 3, | ||
}, | ||
}, | ||
value: 3 | ||
} | ||
} | ||
}); | ||
}); | ||
it('should work with parenthesis', () => { | ||
const parsed = parse('1 * (2 + 3)'); | ||
it("should work with parenthesis", () => { | ||
const parsed = parse("1 * (2 + 3)"); | ||
expect(parsed).toEqual({ | ||
@@ -212,3 +259,3 @@ type: TYPES.BinaryExpression, | ||
type: TYPES.Numeric, | ||
value: 1, | ||
value: 1 | ||
}, | ||
@@ -220,9 +267,9 @@ right: { | ||
type: TYPES.Numeric, | ||
value: 2, | ||
value: 2 | ||
}, | ||
right: { | ||
type: TYPES.Numeric, | ||
value: 3, | ||
}, | ||
}, | ||
value: 3 | ||
} | ||
} | ||
}); | ||
@@ -229,0 +276,0 @@ }); |
@@ -98,5 +98,5 @@ import * as utils from "./utils"; | ||
const readString = () => ({ | ||
const readString = ch => ({ | ||
type: TYPES.String, | ||
value: utils.readEscaped(inputStream, utils.isStringStart) | ||
value: utils.readEscaped(inputStream, c => c === ch) | ||
}); | ||
@@ -148,3 +148,3 @@ | ||
if (utils.isStringStart(ch)) { | ||
return readString(); | ||
return readString(ch); | ||
} | ||
@@ -151,0 +151,0 @@ if (utils.isDigit(ch)) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
114455
3213
0