Skip to content

[typescript] fix Semgrep pattern parsing for TS-specific positions (decorators, types, interfaces, enums) - #588

Draft
brandonspark wants to merge 1 commit into
mainfrom
fix/typescript-pattern-augmentation
Draft

[typescript] fix Semgrep pattern parsing for TS-specific positions (decorators, types, interfaces, enums)#588
brandonspark wants to merge 1 commit into
mainfrom
fix/typescript-pattern-augmentation

Conversation

@brandonspark

@brandonspark brandonspark commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends lang/semgrep-grammars/src/semgrep-typescript/common/semgrep-ext.js so Semgrep patterns parse cleanly in positions that are unique to TypeScript:

  • LANG-477 — standalone decorator patterns (@$DEC, @$DEC(), @$DEC(...)).
  • LANG-489 — bare types and type predicates as patterns; ... and metavariables in any _type-typed slot (type alias RHS, type annotation, conditional-type sides, mapped-type value, tuple types, generic type arguments).
  • LANG-500... as a member of object_type (which propagates to interface_body via alias($.object_type, $.interface_body)).
  • LANG-502... as a member of enum_body.
  • LANG-504<...> and <$T, ...> in type_parameters; the mapped-type RHS case is subsumed by the LANG-489 primary_type extension.

semgrep_pattern also now admits $.statement so declaration-position patterns like interface I { ... }, enum E { ... }, type T = ..., and let X: ... parse as Semgrep patterns under the __SEMGREP_EXPRESSION entry point.

Companion regeneration PRs:

Test plan

  • make build from lang/semgrep-grammars/src/semgrep-typescript/ regenerates both typescript/ and tsx/ parsers without unresolved conflicts.
  • tree-sitter parse on every reproducer from the LANG-477/489/500/502/504 tickets produces an ERROR-free tree (verified for both __SEMGREP_EXPRESSION-wrapped and bare forms).
  • Existing corpus/semgrep-ext.txt cases (expression ellipsis, class-body ellipsis, function-parameter ellipsis, decorator-prefixed method patterns) still parse to the same trees.

Tickets

  • LANG-477 — Standalone decorator patterns rejected
  • LANG-489 — Type-position patterns rejected
  • LANG-500 — Interface bodies / object type literals reject ...
  • LANG-502 — Enum bodies reject ...
  • LANG-504 — Mapped-type value / generic type-parameter lists reject ...

🤖 Generated with Claude Code

Extends `semgrep_pattern` and the relevant member/type rules so Semgrep
patterns parse cleanly in positions that are unique to TypeScript:
decorator-only patterns (LANG-477), bare types/type predicates and
`...` in any type-position slot (LANG-489), `...` inside interface
bodies and object-type literals (LANG-500), `...` inside enum bodies
(LANG-502), and `<...>` in generic-parameter lists plus `...` as a
mapped-type value (LANG-504).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant