#415 JavaScript/TypeScript function detection issues #437
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.
Hello, @terryyin, I don't know Typescript or JavaScript, but I let Claude take a look at this one, so please give it a closer eye and let me know what you think.
Fixes missing method detection and false positives in JavaScript/TypeScript parser that were reported in issue #415.
Issues Fixed
Missing static async methods: static async simulateApiCall() was not being detected by the parser
False positive constructor calls: new Date() was incorrectly reported as a function definition
False positive method calls: Method calls like Date.toISOString() and this.generateRandomId() were incorrectly reported as function definitions
Changes Made
Parser Improvements (lizard_languages/typescript.py)
Added tracking for
staticandasynckeyword modifiers to properly handle static async method combinationsAdded
_prev_tokentracking to detectnewkeyword and.operator contextEnhanced method call detection to prevent false positives when
(is preceded by.ornewImproved token preservation logic to maintain context across multiple tokens
Test Coverage
Added tests to both testJavaScript.py and testTypeScript.py:
test_interactive_widget_from_github_issue_415()- Tests the full InteractiveWidget class example from the bug reporttest_no_false_positive_method_calls() - Verifies method calls and constructor calls are not detected as functions
Documented known limitation: methods appearing after complex async methods with nested callbacks may not be detected
Test Results
✅ 54 JavaScript/TypeScript tests passing (4 skipped - documented edge cases)
✅ 1012 total lizard tests passing (6 skipped)
✅ No regressions
✅ PEP8 compliant
Verification
All critical methods from the InteractiveWidget example in issue #415 are now correctly detected:
constructor,init,render,updateUI,handleClickstartTimer,stopTimer,formatDate,generateRandomIdsimulateApiCall(the main missing method from the bug report)No false positives detected for:
Constructor calls:
new Date()Method calls:
Date.toISOString(),this.generateRandomId()Known Limitations
Methods appearing after a
static asyncmethod containing complex nested callbacks (Promise + setTimeout) with method calls inside object literals may not be detected. This affects 2 methods (processItems,filterUnique) in the full InteractiveWidget example, but all methods specifically mentioned in the bug report are now working correctly. Fixes #415