-
Notifications
You must be signed in to change notification settings - Fork 692
Expose parser AST statements and expression/codegen types in published TypeScript declarations #2527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+114
−0
Merged
Expose parser AST statements and expression/codegen types in published TypeScript declarations #2527
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
36bc989
Initial plan
Copilot 80b0a03
Expose parser AST statements and expression node typings
Copilot c9af0c3
Refine AST declaration union and wrapper naming
Copilot 381ad22
Strengthen test2498 with full AST shape assertions
Copilot 166c928
Refactor test2498 to explicit normalized-vs-expected object assertions
Copilot 85fe594
Assert complete AST objects with explicit undefined tableid checks
Copilot 9806e81
Add explicit undefined tableid checks for all unqualified nodes
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| if (typeof exports === 'object') { | ||
| var assert = require('assert'); | ||
| var alasql = require('..'); | ||
| } | ||
|
|
||
| let testId = '2498'; | ||
|
|
||
| describe(`Test ${testId} - parser AST surface`, function () { | ||
| it('A) exposes statements[] and where.toJS() for parsed statements', function () { | ||
| const ast = alasql.parse('SELECT 1 FROM ? WHERE x < $y'); | ||
| assert.ok(Array.isArray(ast.statements)); | ||
| assert.strictEqual(ast.statements.length, 1); | ||
|
|
||
| const where = ast.statements[0].where; | ||
| assert.strictEqual(typeof where.toJS, 'function'); | ||
|
|
||
| const js = where.toJS('p', '', null); | ||
| assert.strictEqual(typeof js, 'string'); | ||
|
|
||
| const fn = new Function('alasql', 'p', 'params', `return Boolean(${js});`); | ||
| assert.strictEqual(fn(alasql, {x: 1}, {y: 2}), true); | ||
| assert.strictEqual(fn(alasql, {x: 3}, {y: 2}), false); | ||
| }); | ||
|
|
||
| it('B) preserves stable expression node shapes used by parser consumers', function () { | ||
| const parsed = { | ||
| paramWhere: alasql.parse('SELECT 1 FROM ? WHERE x < $y').statements[0].where.expression, | ||
| numWhere: alasql.parse('SELECT 1 FROM ? WHERE x < 10').statements[0].where.expression, | ||
| strWhere: alasql.parse("SELECT 1 FROM ? WHERE x = 'abc'").statements[0].where.expression, | ||
| boolWhere: alasql.parse('SELECT 1 FROM ? WHERE x = TRUE').statements[0].where.expression, | ||
| uniWhere: alasql.parse('SELECT 1 FROM ? WHERE -x < 0').statements[0].where.expression, | ||
| }; | ||
|
|
||
| assert.strictEqual(parsed.paramWhere.left.tableid, undefined); | ||
| assert.strictEqual(parsed.numWhere.left.tableid, undefined); | ||
| assert.strictEqual(parsed.strWhere.left.tableid, undefined); | ||
| assert.strictEqual(parsed.boolWhere.left.tableid, undefined); | ||
| assert.strictEqual(parsed.uniWhere.left.right.tableid, undefined); | ||
|
|
||
| const actual = JSON.parse(JSON.stringify(parsed)); | ||
| const expected = { | ||
| paramWhere: {left: {columnid: 'x'}, op: '<', right: {param: 'y'}}, | ||
| numWhere: {left: {columnid: 'x'}, op: '<', right: {value: 10}}, | ||
| strWhere: {left: {columnid: 'x'}, op: '=', right: {value: 'abc'}}, | ||
| boolWhere: {left: {columnid: 'x'}, op: '=', right: {value: true}}, | ||
| uniWhere: { | ||
| left: {op: '-', right: {columnid: 'x'}}, | ||
| op: '<', | ||
| right: {value: 0}, | ||
| }, | ||
| }; | ||
|
|
||
| assert.deepStrictEqual(actual, expected); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.