Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

Add lossless PSL syntax tree + typed AST under psl-parser/syntax - #776

Merged
SevInf merged 4 commits into
mainfrom
psl-parser-revamp
Jun 9, 2026
Merged

SevInf merged 4 commits into
mainfrom
psl-parser-revamp

Conversation

@SevInf

@SevInf SevInf commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

n/a — no Linear ticket. Exploratory work on the @prisma-next/psl-parser lossless syntax tree. The only red/green-tree tickets (PLT-6314, PLT-6316) were canceled as automation errors; happy to link a TML issue if one should track this.

At a glance

import { TypeAnnotationAst } from '@prisma-next/psl-parser/syntax';

// for the field type `supabase:auth.User[]?`
const ta = TypeAnnotationAst.cast(node)!;
ta.spaceName()?.token()?.text; // 'supabase'  (cross-space segment)
ta.namespaceName()?.token()?.text; // 'auth'   (namespace segment)
ta.name()?.token()?.text; // 'User'
ta.isList; // true
ta.isOptional; // true
ta.constructorCall(); // FunctionCallAst | undefined, e.g. for `Vector(1536)`

Before this branch the package exposed only the line-oriented parsePslDocument (producing a flat PslDocumentAst); there was no @prisma-next/psl-parser/syntax subpath and no navigable tree.

Decision

This PR introduces a lossless red/green syntax tree and a typed AST layer for PSL, shipped under the new @prisma-next/psl-parser/syntax subpath. Two substantive pieces:

  1. Tree infrastructure. An immutable green layer (GreenNode / GreenToken + GreenNodeBuilder), a red layer (SyntaxNode / SyntaxToken with lazily-computed offsets and full navigation — children, siblings, ancestors, descendants, tokens), and typed AST wrappers over the SyntaxKind alphabet.
  2. Vocabulary parity with the existing parser. The typed AST represents what parsePslDocument already accepts: models, enums (including @@map / per-value @map), composite types (type N {}), the document types {} block, namespace blocks, generic keyword Name { … } blocks, field/block attributes with namespaced names and positional/named argument lists, the expression grammar, and qualified / cross-space / inline-constructor type references.

This PR ships the tree vocabulary and structure, not a producer that consumes PSL source — see Notes for the reviewer.

How it fits together

  1. Green layer (src/syntax/green.ts, green-builder.ts) — immutable, position-independent nodes/tokens, assembled with a startNode / token / finishNode builder. Tokens carry kind + text only, so green subtrees are shareable.
  2. Red layer (src/syntax/red.ts) — SyntaxNode wraps a green node with a parent pointer and an absolute offset computed lazily on walk. SyntaxToken extends Token with that offset. This is the layer consumers navigate.
  3. Typed AST (src/syntax/ast/*.ts) — thin typed wrappers (DocumentAst, ModelDeclarationAst, EnumDeclarationAst, CompositeTypeDeclarationAst, NamespaceDeclarationAst, TypeAnnotationAst, the expression nodes, …) with intent-named accessors, each cast from a SyntaxNode by kind.
  4. Public surface (src/exports/syntax.ts) — the @prisma-next/psl-parser/syntax barrel, wired as a tsdown entry and package export.

Behavior changes & evidence

Notes for the reviewer

  • The tree has no source→tree producer yet — this is deliberate scope. Every green tree is assembled by hand via GreenNodeBuilder (the tests do exactly this). This PR delivers the lossless structure and the typed AST vocabulary; wiring the tokenizer to the builder so real .psl text round-trips is separate, larger follow-up work. Reviewing against "is the vocabulary right and faithful to parser.ts?" rather than "does it parse?" is the intended lens.
  • Namespace membership is intentionally narrower than document membership. castNamespaceMember is the authoritative set for a namespace body; DocumentAst.declarations() composes it as a superset. The dependency points one way (document → namespace members) so a document-only node like types {} can never leak into the namespace set — parser.ts:204 rejects types inside a namespace, and parser.ts:182 rejects nested namespaces.
  • Pre-existing footnote: running pnpm --filter @prisma-next/psl-parser test without building dependencies first surfaces implicit-any errors in parser.ts (it imports types from @prisma-next/framework-components). Those are an unbuilt-deps artifact, not introduced here; building the dep graph first clears them.
  • Largest file to spot-check: test/syntax/ast.test.ts — it builds representative trees for each construct and asserts the accessors.

Skill update

n/a — internal only. New public TypeScript surface (@prisma-next/psl-parser/syntax) but it is not yet consumed by any user-facing CLI/config/error surface; no skill governs it.

Testing performed

  • pnpm --filter @prisma-next/psl-parser... build — green (emits the new dist/syntax.mjs + d.mts).
  • pnpm --filter @prisma-next/psl-parser test — 227 passing (unit + type tests), no type errors.
  • pnpm --filter @prisma-next/psl-parser lint — clean.
  • pnpm lint:deps — no dependency-layering violations.

Alternatives considered

  • Extend the existing parser.ts instead of adding a tree. Rejected — the line/regex parser is lossy (it strips comments and whitespace) and can't back editor/tooling use cases that need a lossless, navigable tree with offsets.
  • A dedicated QualifiedTypeRef node vs. extending TypeAnnotation. Chose to extend TypeAnnotation: the namespace/space qualifiers and the inline constructor are optional decorations on the same annotation, alongside the existing isList / isOptional, so a single node with optional accessors matched the existing style with no new SyntaxKind.
  • Build the source→tree producer in this PR. Deferred — it is a larger, independently-reviewable effort, and the vocabulary needs to be settled (this PR) before it is worth wiring.

Checklist

  • All commits are signed off (git commit -s) per the DCO.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated.
  • The PR title is in TML-NNNN: <sentence-case title> form — no Linear ticket exists for this exploratory work; using a plain descriptive title. Will add the prefix if a ticket is assigned.
  • The Skill update section above is filled in.

Summary by CodeRabbit

Release Notes

  • New Features

    • Public syntax API added for constructing and inspecting parsed document structures, including syntax nodes, tokens, and utilities for building syntax trees.
  • Refactor

    • Enhanced AST layer with richer node wrappers and navigation helpers for safer, typed access to declarations, expressions, attributes, and type annotations.
  • Tests

    • Comprehensive test suites added to validate syntax tree construction, traversal, and AST accessor behavior.

@SevInf
SevInf requested a review from a team as a code owner June 9, 2026 12:56
@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@SevInf, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 16 minutes and 45 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 3bffaf1a-4918-45b3-b9d7-0d7519da6994

📥 Commits

Reviewing files that changed from the base of the PR and between 88b323b and e468feb.

📒 Files selected for processing (3)
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/expressions.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/type-annotation.ts
  • packages/1-framework/2-authoring/psl-parser/test/syntax/ast.test.ts
📝 Walkthrough

Walkthrough

This PR implements green/red syntax trees, typed AST wrappers for PSL declarations/attributes/expressions/identifiers/type-annotations, helper utilities, a GreenNodeBuilder, barrel exports, package subpath export, and comprehensive Vitest tests.

Changes

PSL Parser Syntax and AST Layer

Layer / File(s) Summary
Syntax kind type definitions
src/syntax/syntax-kind.ts
SyntaxKind type enumerates all node kinds used throughout the parser.
Green tree core and factories
src/syntax/green.ts
GreenToken/GreenNode types and greenToken/greenNode constructors with computed textLength.
GreenNodeBuilder and green tests
src/syntax/green-builder.ts, test/syntax/green-builder.test.ts, test/syntax/green.test.ts
Stack-based GreenNodeBuilder for constructing green trees and tests for construction, errors, and text round-trip.
Red tree layer and tests
src/syntax/red.ts, test/syntax/red.test.ts
SyntaxNode/SyntaxToken wrappers adding offsets and traversal (children/siblings/ancestors/descendants/tokens) with offset/navigation tests.
AST helper utilities
src/syntax/ast-helpers.ts
AstNode interface and helpers: findChildToken, findFirstChild, filterChildren.
Identifier & TypeAnnotation AST wrappers and tests
src/syntax/ast/identifier.ts, src/syntax/ast/type-annotation.ts, test/syntax/ast.test.ts
IdentifierAst and TypeAnnotationAst with namespace/space-name parsing, list/optional detection, and constructor-call extraction; tests included.
Expression AST wrappers and tests
src/syntax/ast/expressions.ts, test/syntax/ast.test.ts
FunctionCallAst, ArrayLiteralAst, literal wrappers (StringLiteralExprAst, NumberLiteralExprAst, BooleanLiteralExprAst), ExpressionAst union, castExpression, and AttributeArgAst with tests for literals, escapes, and args.
Attribute AST wrappers and tests
src/syntax/ast/attributes.ts, test/syntax/ast.test.ts
FieldAttributeAst, ModelAttributeAst, AttributeArgListAst with dot-qualified names and argument iteration; tests included.
Declaration AST wrappers and tests
src/syntax/ast/declarations.ts, test/syntax/ast.test.ts
AST classes for Document, Model, Enum, CompositeType, Namespace, TypesBlock, Block, Field, EnumValue, NamedType, KeyValuePair with typed accessors and iterables; comprehensive tests.
Public exports and configuration
src/exports/syntax.ts, package.json, tsdown.config.ts
New barrel export src/exports/syntax.ts; package.json adds exports["./syntax"] = "./dist/syntax.mjs"; tsdown.config.ts adds the new export to documentation entries.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • wmadden

Poem

🐰 In green and red I hop and write,
Tokens snug, offsets tight,
AST branches, wrappers spin—
Fields and types jump in!
Tests applaud with gentle bite.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Add lossless PSL syntax tree + typed AST under psl-parser/syntax' accurately and concisely summarizes the primary change: introducing both a lossless syntax tree infrastructure and a typed AST layer for the PSL parser under a new package export.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch psl-parser-revamp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@776

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@776

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@776

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@776

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@776

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@776

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@776

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@776

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@776

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@776

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@776

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@776

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@776

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@776

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@776

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@776

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@776

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@776

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@776

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@776

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@776

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@776

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@776

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@776

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@776

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@776

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@776

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@776

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@776

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@776

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@776

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@776

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@776

prisma-next

npm i https://pkg.pr.new/prisma-next@776

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@776

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@776

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@776

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@776

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@776

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@776

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@776

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@776

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@776

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@776

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@776

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@776

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@776

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@776

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@776

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@776

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@776

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@776

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@776

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@776

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@776

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@776

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@776

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@776

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@776

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@776

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@776

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@776

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@776

commit: e468feb

@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 150.65 KB (0%)
postgres / emit 119.44 KB (0%)
mongo / no-emit 76.67 KB (0%)
mongo / emit 70.96 KB (0%)
cf-worker / no-emit 179.98 KB (0%)
cf-worker / emit 145.5 KB (0%)

SevInf and others added 3 commits June 9, 2026 13:05
…appers

Implements a Roslyn/rust-analyzer style red/green tree infrastructure for PSL:
- Green layer: immutable GreenToken/GreenNode with GreenNodeBuilder
- Red layer: SyntaxNode with parent pointers, offsets, and navigation
- Typed AST wrappers for all PSL constructs (documents, models, enums, fields, attributes, expressions)
- Exported via new `@prisma-next/psl-parser/syntax` subpath

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
…rage gate

Cover all previously untested AST wrapper methods (EnumDeclarationAst,
TypesBlockAst, BlockDeclarationAst, NamedTypeDeclarationAst,
FieldDeclarationAst.attributes, FunctionCallAst, ModelAttributeAst.argList)
and SyntaxNode.textLength/prevSibling to bring functions coverage to 100%.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Serhii Tatarintsev <[email protected]>
…es, enum attributes, and qualified type refs

Adds the missing typed-AST vocabulary so the lossless syntax tree can represent the PSL surface the parser already accepts:

- enum @@Map and enum-value @Map via attributes() accessors
- composite-type `type N {}` declarations (CompositeTypeDeclaration)
- namespace blocks (Namespace) whose declarations() yields only namespace-valid members (NamespaceMemberAst)
- qualified (ns.T), cross-space (space:ns.T), and inline-constructor (Vector(1536)) type references on TypeAnnotation

Signed-off-by: Serhii Tatarintsev <[email protected]>
@SevInf
SevInf force-pushed the psl-parser-revamp branch from e1c6b0b to 88b323b Compare June 9, 2026 13:05

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/1-framework/2-authoring/psl-parser/src/syntax/ast/type-annotation.ts (1)

15-18: 💤 Low value

Consider deferring array collection to improve performance.

The REVIEW comment correctly notes that Array.from eagerly allocates and iterates all segments, while most callers (name(), spaceName(), namespaceName()) only need one element. A helper that iterates once and returns a specific index (e.g., findSegmentAt(index)) would avoid the allocation cost.

Since this is a new implementation and the current approach works correctly, this optimization can be deferred to a follow-up PR when profiling shows it's worthwhile.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/1-framework/2-authoring/psl-parser/src/syntax/ast/type-annotation.ts`
around lines 15 - 18, The current `#segments`() method eagerly builds an array via
Array.from(filterChildren(...)) causing unnecessary allocations; replace it with
a streaming helper (e.g., findSegmentAt(index)) that iterates
filterChildren(this.syntax, IdentifierAst.cast) once and returns the nth
IdentifierAst or undefined without collecting all items, and update callers
name(), spaceName(), and namespaceName() to call findSegmentAt(0/1/...) as
appropriate so they avoid the allocation; keep IdentifierAst.cast and
filterChildren usage unchanged, and leave the old `#segments`() behavior only if
you need backward compatibility (or remove it after switching callers).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/1-framework/2-authoring/psl-parser/src/syntax/ast/expressions.ts`:
- Around line 70-80: The value() method currently applies escape replacements in
an order that turns intended literal backslash sequences like "\\n" into actual
newlines; fix by handling escaped backslashes first or performing a single-pass
replacement mapping all escapes. Locate value() in expressions.ts (uses
this.token(), tok.text.slice(1, -1)) and either 1) run the .replace(/\\\\/g,
'\\') before the other .replace calls, or 2) replace all escape sequences in one
pass using a single regex with a callback that maps '\\\\' -> '\\', '\\n' ->
'\n', '\\r' -> '\r', '\\t' -> '\t', '\\"' -> '"' to ensure sequences like
"\\\\n" are preserved correctly as backslash + 'n'.

In `@packages/1-framework/2-authoring/psl-parser/src/syntax/red.ts`:
- Around line 101-110: The code uses bare "as" casts in descendants() and other
places (e.g., casting stack.pop() and child entries to SyntaxElement); replace
these casts with local runtime narrowing/guards: in descendants(), change "const
el = stack.pop() as SyntaxElement;" to let el = stack.pop(); if (!el) continue;
and keep the existing "if (el instanceof SyntaxNode)" check; when pushing
children remove "as SyntaxElement" and either filter/map children with a type
guard (e.g., children.filter((c): c is SyntaxElement => /* guard */)) or use an
instanceof/type-check before stack.push(children[i]); apply the same pattern
where bare casts appear at the other locations (lines around 141/143) — replace
"as" casts with explicit guards or predicate functions so SyntaxElement is
established by control flow rather than by assertion.

---

Nitpick comments:
In
`@packages/1-framework/2-authoring/psl-parser/src/syntax/ast/type-annotation.ts`:
- Around line 15-18: The current `#segments`() method eagerly builds an array via
Array.from(filterChildren(...)) causing unnecessary allocations; replace it with
a streaming helper (e.g., findSegmentAt(index)) that iterates
filterChildren(this.syntax, IdentifierAst.cast) once and returns the nth
IdentifierAst or undefined without collecting all items, and update callers
name(), spaceName(), and namespaceName() to call findSegmentAt(0/1/...) as
appropriate so they avoid the allocation; keep IdentifierAst.cast and
filterChildren usage unchanged, and leave the old `#segments`() behavior only if
you need backward compatibility (or remove it after switching callers).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 27a566f2-0e50-471b-89fb-8fc7e230e5e0

📥 Commits

Reviewing files that changed from the base of the PR and between ec5f7df and e1c6b0b.

📒 Files selected for processing (17)
  • packages/1-framework/2-authoring/psl-parser/package.json
  • packages/1-framework/2-authoring/psl-parser/src/exports/syntax.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast-helpers.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/attributes.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/declarations.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/expressions.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/identifier.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/type-annotation.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/green-builder.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/green.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/red.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/syntax-kind.ts
  • packages/1-framework/2-authoring/psl-parser/test/syntax/ast.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/syntax/green-builder.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/syntax/green.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/syntax/red.test.ts
  • packages/1-framework/2-authoring/psl-parser/tsdown.config.ts

…nnotation segments

Addresses CodeRabbit review on #776:
- StringLiteralExprAst.value() decoded escapes via sequential replace, so an escaped backslash before a letter (PSL "test\\n") was mis-decoded as the following escape (newline). Decode in a single left-to-right pass instead.
- TypeAnnotationAst no longer materialises an array of identifier segments per accessor; name()/namespaceName() iterate once, spaceName() takes the first child. Removes the leftover REVIEW note.

Signed-off-by: Serhii Tatarintsev <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant