Expose parser AST statements and expression/codegen types in published TypeScript declarations#2527
Conversation
| assert.strictEqual(fn(alasql, {x: 3}, {y: 2}), false); | ||
| }); | ||
|
|
||
| it('B) preserves stable expression node shapes used by parser consumers', function () { |
There was a problem hiding this comment.
Please be more specific by asserting towards the final complete object expected to be outputted.
There was a problem hiding this comment.
Updated in 381ad22. Test B now uses a single assert.deepStrictEqual against a complete expected object for the documented AST-node shapes, instead of scattered field-by-field assertions.
| <T = unknown>(params?: any, cb?: AlaSQLCallback<T>, scope?: unknown): T; | ||
| } | ||
|
|
||
| type AlaSQLDefaultColumns = {[columnName: string]: string}; |
There was a problem hiding this comment.
Can you tell me a bit about why this is the right fix? It seems like a lot of code for this kind of fix.
There was a problem hiding this comment.
This is type-surface only (no runtime behavior changes), and most of the added lines are explicit interface declarations documenting parser shapes that already exist and are already used (statements, where, toJS, node fields like left/op/right, columnid, value, param). The reason for being explicit is to avoid unsafe casts for parser/codegen consumers and make those stable entry points discoverable in published typings. The added regression test is there to ensure we only expose shapes that actually parse today and to prevent accidental drift in future releases.
AlaSQL’s published types only exposed
AlaSQLAST.compile(...), leaving parser/codegen consumers to cast around undocumented internals (statements,where,toJS). This PR surfaces the existing parser API intypes/alasql.d.tsand documents stable expression node shapes already used in practice.Type surface: expose parsed statements
statements: Statement[]toAlaSQLAST.Statementshape withwhere?: ExpressionWrapperto model common parser access patterns.Type surface: document expression codegen contract
AlaSQLExpressionwith:toJS(context: string, tableid: string | number, defcols: AlaSQLDefaultColumns | null): stringAlaSQLDefaultColumns.Type surface: publish stable node shapes
Op(left,op,right/right1/right2)Column(columnid, optionaltableid,databaseid)ParamValue(param)NumValue(value)StringValue(value)LogicValue(value)UniOp(op,right)ExpressionNodeunion over concrete node types.Regression coverage for parser consumers
test/test2498.jsto lock in:parse(...).statements[0].wherewhere.toJS(...)producing executable JS expression