[typescript] fix Semgrep pattern parsing for TS-specific positions (decorators, types, interfaces, enums) - #588
Draft
brandonspark wants to merge 1 commit into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
lang/semgrep-grammars/src/semgrep-typescript/common/semgrep-ext.jsso Semgrep patterns parse cleanly in positions that are unique to TypeScript:@$DEC,@$DEC(),@$DEC(...))....and metavariables in any_type-typed slot (type alias RHS, type annotation, conditional-type sides, mapped-type value, tuple types, generic type arguments)....as a member ofobject_type(which propagates tointerface_bodyviaalias($.object_type, $.interface_body))....as a member ofenum_body.<...>and<$T, ...>intype_parameters; the mapped-type RHS case is subsumed by the LANG-489primary_typeextension.semgrep_patternalso now admits$.statementso declaration-position patterns likeinterface I { ... },enum E { ... },type T = ..., andlet X: ...parse as Semgrep patterns under the__SEMGREP_EXPRESSIONentry point.Companion regeneration PRs:
Test plan
make buildfromlang/semgrep-grammars/src/semgrep-typescript/regenerates bothtypescript/andtsx/parsers without unresolved conflicts.tree-sitter parseon every reproducer from the LANG-477/489/500/502/504 tickets produces anERROR-free tree (verified for both__SEMGREP_EXPRESSION-wrapped and bare forms).corpus/semgrep-ext.txtcases (expression ellipsis, class-body ellipsis, function-parameter ellipsis, decorator-prefixed method patterns) still parse to the same trees.Tickets
.........🤖 Generated with Claude Code