expre-parser
Advanced tools
Comparing version 0.1.21 to 0.1.22
@@ -30,2 +30,3 @@ import * as sqliteParser from "sqlite-parser"; | ||
readonly associative: boolean; | ||
readonly mayNeedParentheses: boolean; | ||
abstract readonly precedence: number; | ||
@@ -39,2 +40,3 @@ abstract getFunciones(): string[]; | ||
getFunciones(): string[]; | ||
readonly mayNeedParentheses: boolean; | ||
} | ||
@@ -80,2 +82,3 @@ export declare class IdentifierNode extends leafNode { | ||
toCodeWoP(c: Compiler): string; | ||
readonly mayNeedParentheses: boolean; | ||
getFunciones(): string[]; | ||
@@ -87,2 +90,3 @@ } | ||
toCodeWoP(c: Compiler): string; | ||
readonly mayNeedParentheses: boolean; | ||
} | ||
@@ -93,2 +97,3 @@ export declare class WhenThenCaseNode extends ExpressionNode { | ||
toCodeWoP(c: Compiler): string; | ||
readonly mayNeedParentheses: boolean; | ||
} | ||
@@ -99,2 +104,3 @@ export declare class ElseCaseNode extends ExpressionNode { | ||
toCodeWoP(c: Compiler): string; | ||
readonly mayNeedParentheses: boolean; | ||
} |
@@ -56,3 +56,3 @@ "use strict"; | ||
var result = this.toCodeWoP(c); | ||
if (invokerNode instanceof compiler_1.Compiler) { | ||
if (invokerNode instanceof compiler_1.Compiler || !this.mayNeedParentheses) { | ||
return result; | ||
@@ -67,2 +67,3 @@ } | ||
get associative() { return false; } | ||
get mayNeedParentheses() { return true; } | ||
getInsumos() { | ||
@@ -82,2 +83,3 @@ // Using Set to remove duplicates | ||
} | ||
get mayNeedParentheses() { return false; } | ||
} | ||
@@ -201,2 +203,3 @@ exports.leafNode = leafNode; | ||
} | ||
get mayNeedParentheses() { return false; } | ||
getFunciones() { | ||
@@ -217,2 +220,3 @@ return [this.mainContent].concat(...super.getFunciones()); | ||
} | ||
get mayNeedParentheses() { return false; } | ||
} | ||
@@ -230,2 +234,3 @@ exports.CaseExpressionNode = CaseExpressionNode; | ||
} | ||
get mayNeedParentheses() { return false; } | ||
} | ||
@@ -243,4 +248,5 @@ exports.WhenThenCaseNode = WhenThenCaseNode; | ||
} | ||
get mayNeedParentheses() { return false; } | ||
} | ||
exports.ElseCaseNode = ElseCaseNode; | ||
//# sourceMappingURL=ast-model.js.map |
@@ -154,2 +154,38 @@ "use strict"; | ||
}); | ||
describe("parse() then toCode() respect precedence order", function () { | ||
var compilerOptions = { | ||
varWrapper: null, | ||
divWrapper: null, | ||
language: 'sql' | ||
}; | ||
var compiler; | ||
before(function () { | ||
compiler = new compiler_1.Compiler(compilerOptions); | ||
}); | ||
it('dont add unuseful parenthesis', function () { | ||
let obtained = compiler.toCode(ExpresionParser.parse("a and not b or c or d and e"), 'pk1,t2'); | ||
let expected = "a and not b or c or d and e"; | ||
compare(obtained, expected); | ||
}); | ||
it('dont lose parenthesis 2', function () { | ||
let obtained = compiler.toCode(ExpresionParser.parse("a and not (b or c) or d and e"), 'pk1,t2'); | ||
let expected = "a and not (b or c) or d and e"; | ||
compare(obtained, expected); | ||
}); | ||
it('dont lose parenthesis 3', function () { | ||
let obtained = compiler.toCode(ExpresionParser.parse("a and not ((b or c) or d) and e"), 'pk1,t2'); | ||
let expected = "a and not (b or c or d) and e"; | ||
compare(obtained, expected); | ||
}); | ||
it('dont lose parenthesis 4', function () { | ||
let obtained = compiler.toCode(ExpresionParser.parse("a and (not (b or c) or d) and e"), 'pk1,t2'); | ||
let expected = "a and (not (b or c) or d) and e"; | ||
compare(obtained, expected); | ||
}); | ||
it('dont lose parenthesis 5', function () { | ||
let obtained = compiler.toCode(ExpresionParser.parse("a and (not (b or c) or d and e)"), 'pk1,t2'); | ||
let expected = "a and (not (b or c) or d and e)"; | ||
compare(obtained, expected); | ||
}); | ||
}); | ||
describe("non wrapped", function () { | ||
@@ -202,2 +238,10 @@ var compilerOptions = { | ||
}); | ||
it("inside functions", async function () { | ||
var expr = "f(g(x))+abs(a-1) = f(y) or tiene_permiso('pepe')"; | ||
compilerOptions.language = 'sql'; | ||
compiler = new compiler_1.Compiler(compilerOptions); | ||
let obtained = compiler.toCode(ExpresionParser.parse(expr), 'pk2'); | ||
let expected = "f(g(x)) + abs(a - 1) = f(y) or tiene_permiso('pepe')"; | ||
compare(obtained, expected); | ||
}); | ||
}); | ||
@@ -204,0 +248,0 @@ describe("case", function () { |
{ | ||
"name": "expre-parser", | ||
"description": "expression parser", | ||
"version": "0.1.21", | ||
"version": "0.1.22", | ||
"author": "Codenautas <codenautas@googlegroups.com>", | ||
@@ -19,3 +19,3 @@ "license": "MIT", | ||
"mocha": "~5.2.0", | ||
"discrepances": "~0.2.3" | ||
"discrepances": "~0.2.4" | ||
}, | ||
@@ -22,0 +22,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
68319
920
0