Skip to content

Expose parser AST statements and expression/codegen types in published TypeScript declarations - #2527

Draft
mathiasrw with Copilot wants to merge 7 commits into
developfrom
copilot/expose-parser-ast-tojs-docs
Draft

Expose parser AST statements and expression/codegen types in published TypeScript declarations#2527
mathiasrw with Copilot wants to merge 7 commits into
developfrom
copilot/expose-parser-ast-tojs-docs

Conversation

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

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 in types/alasql.d.ts and documents stable expression node shapes already used in practice.

  • Type surface: expose parsed statements

    • Adds statements: Statement[] to AlaSQLAST.
    • Introduces a typed Statement shape with where?: ExpressionWrapper to model common parser access patterns.
  • Type surface: document expression codegen contract

    • Adds base AlaSQLExpression with:
      • toJS(context: string, tableid: string | number, defcols: AlaSQLDefaultColumns | null): string
    • Captures default-column map as AlaSQLDefaultColumns.
  • Type surface: publish stable node shapes

    • Adds explicit node interfaces for:
      • Op (left, op, right/right1/right2)
      • Column (columnid, optional tableid, databaseid)
      • ParamValue (param)
      • NumValue (value)
      • StringValue (value)
      • LogicValue (value)
      • UniOp (op, right)
    • Adds ExpressionNode union over concrete node types.
  • Regression coverage for parser consumers

    • Adds test/test2498.js to lock in:
      • parse(...).statements[0].where
      • where.toJS(...) producing executable JS expression
      • expected node-field access for the documented shapes
const ast = alasql.parse('SELECT 1 FROM ? WHERE x < $y');
const where = ast.statements[0].where;
const js = where.toJS('p', '', null);
const fn = new Function('alasql', 'p', 'params', `return Boolean(${js});`);

Copilot AI changed the title [WIP] Expose and document the parser AST and toJS() in published types Expose parser AST statements and expression/codegen types in published TypeScript declarations Aug 20, 2026
Copilot AI requested a review from mathiasrw August 20, 2026 11:40
Comment thread test/test2498.js
assert.strictEqual(fn(alasql, {x: 3}, {y: 2}), false);
});

it('B) preserves stable expression node shapes used by parser consumers', function () {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be more specific by asserting towards the final complete object expected to be outputted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread types/alasql.d.ts
<T = unknown>(params?: any, cb?: AlaSQLCallback<T>, scope?: unknown): T;
}

type AlaSQLDefaultColumns = {[columnName: string]: string};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose and document the parser AST + toJS() in the published types

2 participants