Skip to content

TS/PHP func_start swallows the preceding newline: function span and start_line begin on the previous line #3543

Closed

Description

@squid-protocol

Problem

In TypeScript and PHP, a unit's start_idx and start_line land on the line before its declaration: the class or interface {, the previous member's },, or a docblock's closing */. The span body is otherwise right. The reported location is wrong, so SARIF, the DB and anything that anchors on start_line point one or more lines too early.

Found while closing #3339: these units made up the 75 TypeScript "span does not name the unit in its first 3 lines" cases left after that fix.

Mechanism

Both func_start patterns consume the newline before the declaration, and _slice_by_braces uses match.start() as the unit's start:

  • typescript: the declaration branch opens with [ \t\n]* (after the (?<=[^<>(,\s])|^... anchor), so the match starts at the end of the previous line.
  • php: the pattern opens with (?:^|(?<!->)(?<!::)[^a-zA-Z0-9_$]). The consumed boundary character is usually the previous line's \n.

Measured (language-crucible v1.5.0, direct splice)

A unit counts as affected when its span begins with non-identifier characters ending in a newline.

language affected / units 1 line early 2-4 lines 5+ lines
typescript 724 / 8398 (8.6%) 638 19 67
php 248 / 1703 (14.6%) 241 2 5
javascript 4 / 823 1 3 0

Every other brace-mode language checked has 0: java, csharp, go, c, cpp, rust, dart, kotlin, swift, scala. Their "start line lacks the name" cases are declaration-start conventions (annotations, #[attr], return type or template <> on the line above) and are correct.

The 5+ cases are units whose preceding doc comment PRISM stripped, so the span starts on the { above the comment.

Examples:

  • typescript/assemblyscript/ast.ts::constructor: start_line 1940 (export class ExportStatement extends Statement {); the declaration is on 1941.
  • typescript/vscode/vscode.d.ts::provideHover: start_line 3144 (export interface HoverProvider {); the declaration is on 3157, below a stripped JSDoc.
  • php/wordpress/formatting.php::sanitize_option: start_line 4841, the docblock's closing */.

Impact

  • start_line in the DB and SARIF is early for about 9% of TS units and about 15% of PHP units.
  • The wrapper channel's aligned check (wrapper_extractor.py, name in the span's first 3 lines) rejects the 5+ cases, dropping them as candidates.

Fix direction

Anchor the unit at the declaration, not at the consumed boundary: skip leading whitespace (and, for PHP, the one boundary char) from match.start() before it becomes start_idx, or make the leading class a lookbehind. Re-bless the golden masters with crucible_check.py --update --yes. Expect start_line and coordinate moves in typescript, php and html-embedded TS/JS only.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions