Skip to content

TypeScript: skip ! when parsing variable statements#4389

Merged
masatake merged 2 commits intouniversal-ctags:masterfrom
masatake:typescript--ban-in-expr
Mar 1, 2026
Merged

TypeScript: skip ! when parsing variable statements#4389
masatake merged 2 commits intouniversal-ctags:masterfrom
masatake:typescript--ban-in-expr

Conversation

@masatake
Copy link
Member

Fixes #4384

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.02%. Comparing base (b4fdb90) to head (f03070c).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4389   +/-   ##
=======================================
  Coverage   86.02%   86.02%           
=======================================
  Files         253      253           
  Lines       63506    63506           
=======================================
  Hits        54634    54634           
  Misses       8872     8872           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@masatake masatake force-pushed the typescript--ban-in-expr branch 2 times, most recently from 416d9c3 to feb392b Compare February 26, 2026 18:06
@masatake masatake requested a review from Copilot February 26, 2026 18:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for TypeScript's non-null assertion operator (!) in the parser, ensuring it is properly skipped and doesn't interfere with parsing variable statements and class properties.

Changes:

  • Added TOKEN_BANG to handle the ! operator in TypeScript
  • Updated parser logic to skip ! tokens in variable and class body parsing contexts
  • Added comprehensive test cases for both definite assignment assertions and non-null assertions

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
parsers/typescript.c Added TOKEN_BANG token type and updated parsers to handle ! in variable statements and class properties
Units/parser-typescript.r/skip-bang.d/validator Added validator file specifying TypeScript compiler for test validation
Units/parser-typescript.r/skip-bang.d/input.ts Added test case for non-null assertion in ternary expression
Units/parser-typescript.r/skip-bang.d/input-0.ts Added test case for definite assignment assertions on class properties
Units/parser-typescript.r/skip-bang.d/expected.tags Added expected parser output for the test cases
Units/parser-typescript.r/skip-bang.d/args.ctags Added test configuration to disable sorting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Fixes universal-ctags#4384

Suggested-by: Rimvydas Naktinis (@naktinis)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

TOKEN_QUESTION_MARK, TOKEN_COLON, TOKEN_SEMICOLON, TOKEN_EQUAL_SIGN,
TOKEN_QUESTION_MARK, TOKEN_BANG, TOKEN_COLON, TOKEN_SEMICOLON, TOKEN_EQUAL_SIGN,
TOKEN_MINUS, TOKEN_PLUS, TOKEN_DIV, TOKEN_POWER,
TOKEN_GREATER, TOKEN_LOWER, TOKEN_PERIOD, TOKEN_COMMA,
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

In ClassBodyAfterCurlyChars, the character list contains <> (i.e., < then >), but the corresponding token list maps them as TOKEN_GREATER, TOKEN_LOWER. Because parseChar() indexes by the character position, this will classify < as TOKEN_GREATER and > as TOKEN_LOWER. Swap the token order (or the character order) so < maps to TOKEN_LOWER and > maps to TOKEN_GREATER consistently (as in VariableChars).

Suggested change
TOKEN_GREATER, TOKEN_LOWER, TOKEN_PERIOD, TOKEN_COMMA,
TOKEN_LOWER, TOKEN_GREATER, TOKEN_PERIOD, TOKEN_COMMA,

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Seems to make sense, but unrelated to this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

I will reconsider this comment from the copilot in another pull request that may fix #4000.

Copy link
Member Author

Choose a reason for hiding this comment

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

The token types neither TOKEN_LOWER nor TOKEN_GENERATOR are not considered in the code executed after calling ClassBodyAfterCurlyChars(). So this mismatch has not been a trouble. Anyway, I will make a pull request.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@masatake masatake merged commit 8c3f63b into universal-ctags:master Mar 1, 2026
89 checks passed
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.

TypeScript: exclamation point breaks assignment parsing

3 participants