-
Notifications
You must be signed in to change notification settings - Fork 682
Implement getJSSyntacticDiagnosticsForFile for TypeScript-only construct detection in JavaScript files #1387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
34
commits into
main
Choose a base branch
from
copilot/fix-1386
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
68c5302
Initial plan
Copilot e4b5e3c
Add getJSSyntacticDiagnosticsForFile implementation and additionalSyn…
Copilot 194f161
Fix AST node conversion issues and add comprehensive test case
Copilot 466a9f8
Add NodeFlagsReparsed check to bail out early for synthesized type an…
Copilot 3e0d26f
Update baselines after implementing NodeFlagsReparsed check
Copilot bd6a76d
Move diagnostic calculation to ast package with thread-safe lazy eval…
Copilot 1e6c41e
Refactor JS diagnostic functions: move field order and extract to sep…
Copilot 84ece9d
Address review feedback: format code, fix diagnostics initialization,…
Copilot 617d7ac
Add NodeFlagsReparsed checks to fix false positives on JSDoc type ann…
Copilot 2f7b583
Move JS diagnostics from ast to compiler package and use SyncMap for …
Copilot d55f804
Fix false positives on JSDoc type arguments in JavaScript files
Copilot 732f699
Refactor JS diagnostics: move to separate file and use visitor pattern
Copilot eaeddaf
Refactor JS diagnostics to use binder and scanner functions for bette…
Copilot 0eb0b7f
Merge branch 'main' into copilot/fix-1386
jakebailey 0305435
Fix JS diagnostic positioning and detection issues
Copilot 457a6d3
Fix JS diagnostic positioning for type parameters to match TypeScript…
Copilot 88f567f
Remove isTypeScriptOnlyModifier function and fix modifier checking logic
Copilot 47234a3
Add missing question mark modifier check for method and property decl…
Copilot 5d296fa
Remove duplicate JS diagnostic cases and fix token text detection
Copilot bd46d8a
Manual tweak
jakebailey 241e1c7
Merge branch 'main' into copilot/fix-1386
jakebailey 8389be3
Extract JS diagnostics calculation into helper function
Copilot 94d8aed
Fix JS diagnostics caching to avoid unnecessary AST walks
Copilot 4894614
Move GetErrorRangeForNode to scanner
jakebailey 563ca59
Remove old todo
jakebailey a460d7b
Merge branch 'main' into copilot/fix-1386
jakebailey 1719219
Move to parser
jakebailey 4873b39
Fix binding issue
jakebailey ec7ddc5
Remove cache
jakebailey e67cd95
No need for empty slice anymore
jakebailey 74416e1
Simplify JS diagnostics code per review feedback - reduce redundancy …
Copilot b48403d
Fix type argument panic and improve type node detection - partial fix…
Copilot a76f6f6
Fix JS syntactic diagnostics for null/undefined literals and type arg…
Copilot 60db541
Fix false positive error on ternary operators in JavaScript files
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
277 changes: 277 additions & 0 deletions
277
testdata/baselines/reference/compiler/jsSyntacticDiagnostics.errors.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,277 @@ | ||
test.js(2,17): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(2,26): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(4,2): error TS8006: 'interface' declarations can only be used in TypeScript files. | ||
test.js(10,2): error TS8008: Type aliases can only be used in TypeScript files. | ||
test.js(13,39): error TS8006: 'enum' declarations can only be used in TypeScript files. | ||
test.js(20,2): error TS8006: 'module' declarations can only be used in TypeScript files. | ||
test.js(25,2): error TS8006: 'module' declarations can only be used in TypeScript files. | ||
test.js(33,12): error TS8013: Non-null assertions can only be used in TypeScript files. | ||
test.js(36,23): error TS8016: Type assertion expressions can only be used in TypeScript files. | ||
test.js(39,17): error TS2741: Property 'name' is missing in type '{}' but required in type 'Config'. | ||
test.js(39,26): error TS8037: Type satisfaction expressions can only be used in TypeScript files. | ||
test.js(39,34): error TS8006: 'import type' declarations can only be used in TypeScript files. | ||
test.js(42,31): error TS2307: Cannot find module './other' or its corresponding type declarations. | ||
test.js(42,41): error TS8006: 'export type' declarations can only be used in TypeScript files. | ||
test.js(45,26): error TS8002: 'import ... =' can only be used in TypeScript files. | ||
test.js(48,22): error TS2307: Cannot find module './lib' or its corresponding type declarations. | ||
test.js(48,31): error TS8003: 'export =' can only be used in TypeScript files. | ||
test.js(51,1): error TS2309: An export assignment cannot be used in a module with other exported elements. | ||
test.js(54,16): error TS8009: The 'public' modifier can only be used in TypeScript files. | ||
test.js(55,17): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(55,25): error TS8009: The 'private' modifier can only be used in TypeScript files. | ||
test.js(56,17): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(56,25): error TS8009: The 'protected' modifier can only be used in TypeScript files. | ||
test.js(57,18): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(57,26): error TS8009: The 'readonly' modifier can only be used in TypeScript files. | ||
test.js(58,20): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(60,17): error TS8012: Parameter modifiers can only be used in TypeScript files. | ||
test.js(60,26): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(60,34): error TS8012: Parameter modifiers can only be used in TypeScript files. | ||
test.js(60,45): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(69,25): error TS8009: The '?' modifier can only be used in TypeScript files. | ||
test.js(69,27): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(71,2): error TS8017: Signature declarations can only be used in TypeScript files. | ||
test.js(74,43): error TS8004: Type parameter declarations can only be used in TypeScript files. | ||
test.js(77,23): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(77,27): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(82,19): error TS2693: 'string' only refers to a type, but is being used as a value here. | ||
test.js(82,27): error TS1109: Expression expected. | ||
test.js(85,28): error TS8005: 'implements' clauses can only be used in TypeScript files. | ||
test.js(90,21): error TS8010: Type annotations can only be used in TypeScript files. | ||
test.js(92,2): error TS8006: 'interface' declarations can only be used in TypeScript files. | ||
|
||
|
||
==== test.js (41 errors) ==== | ||
// Type annotations should be flagged as errors | ||
function func(x: number): string { | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
return x.toString(); | ||
} | ||
|
||
|
||
|
||
// Interface declarations should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
interface Person { | ||
~~~~~~~~~~~~~~~~~~ | ||
name: string; | ||
~~~~~~~~~~~~~~~~~ | ||
age: number; | ||
~~~~~~~~~~~~~~~~ | ||
} | ||
~ | ||
!!! error TS8006: 'interface' declarations can only be used in TypeScript files. | ||
|
||
|
||
|
||
// Type alias declarations should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
type StringOrNumber = string | number; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS8008: Type aliases can only be used in TypeScript files. | ||
|
||
|
||
|
||
// Enum declarations should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
enum Color { | ||
~~~~~~~~~~~~ | ||
Red, | ||
~~~~~~~~ | ||
Green, | ||
~~~~~~~~~~ | ||
Blue | ||
~~~~~~~~ | ||
} | ||
~ | ||
!!! error TS8006: 'enum' declarations can only be used in TypeScript files. | ||
|
||
|
||
|
||
// Module declarations should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
module MyModule { | ||
~~~~~~~~~~~~~~~~~ | ||
export var x = 1; | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
} | ||
~ | ||
!!! error TS8006: 'module' declarations can only be used in TypeScript files. | ||
|
||
|
||
|
||
// Namespace declarations should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
namespace MyNamespace { | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
export var y = 2; | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
} | ||
~ | ||
!!! error TS8006: 'module' declarations can only be used in TypeScript files. | ||
|
||
// Non-null assertions should be flagged as errors | ||
let value = getValue()!; | ||
~~~~~~~~~~~~ | ||
!!! error TS8013: Non-null assertions can only be used in TypeScript files. | ||
|
||
// Type assertions should be flagged as errors | ||
let result = (value as string).toUpperCase(); | ||
~~~~~~~ | ||
!!! error TS8016: Type assertion expressions can only be used in TypeScript files. | ||
|
||
// Satisfies expressions should be flagged as errors | ||
let config = {} satisfies Config; | ||
~~~~~~~~~ | ||
!!! error TS2741: Property 'name' is missing in type '{}' but required in type 'Config'. | ||
!!! related TS2728 test.js:95:5: 'name' is declared here. | ||
~~~~~~~ | ||
!!! error TS8037: Type satisfaction expressions can only be used in TypeScript files. | ||
|
||
|
||
|
||
// Import type should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
import type { SomeType } from './other'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS8006: 'import type' declarations can only be used in TypeScript files. | ||
~~~~~~~~~ | ||
!!! error TS2307: Cannot find module './other' or its corresponding type declarations. | ||
|
||
|
||
|
||
// Export type should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
export type { SomeType }; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS8006: 'export type' declarations can only be used in TypeScript files. | ||
|
||
|
||
|
||
// Import equals should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
import lib = require('./lib'); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS8002: 'import ... =' can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS2307: Cannot find module './lib' or its corresponding type declarations. | ||
|
||
|
||
|
||
// Export equals should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
export = MyModule; | ||
~~~~~~~~~~~~~~~~~~ | ||
!!! error TS8003: 'export =' can only be used in TypeScript files. | ||
~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2309: An export assignment cannot be used in a module with other exported elements. | ||
|
||
// TypeScript modifiers should be flagged as errors | ||
class MyClass { | ||
|
||
public name: string; | ||
~~~~~~~~~~ | ||
!!! error TS8009: The 'public' modifier can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
|
||
private age: number; | ||
~~~~~~~~~~~ | ||
!!! error TS8009: The 'private' modifier can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
|
||
protected id: number; | ||
~~~~~~~~~~~~~ | ||
!!! error TS8009: The 'protected' modifier can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
|
||
readonly value: number; | ||
~~~~~~~~~~~~ | ||
!!! error TS8009: The 'readonly' modifier can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
|
||
constructor(public x: number, private y: number) { | ||
~~~~~~ | ||
!!! error TS8012: Parameter modifiers can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
~~~~~~~~ | ||
!!! error TS8012: Parameter modifiers can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
this.name = ''; | ||
this.age = 0; | ||
this.id = 0; | ||
this.value = 0; | ||
} | ||
} | ||
|
||
// Optional parameters should be flagged as errors | ||
function optionalParam(x?: number) { | ||
~ | ||
!!! error TS8009: The '?' modifier can only be used in TypeScript files. | ||
~~~~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
return x || 0; | ||
} | ||
|
||
|
||
|
||
// Signature declarations should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
function signatureOnly(x: number): string; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS8017: Signature declarations can only be used in TypeScript files. | ||
|
||
|
||
|
||
// Type parameters should be flagged as errors | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
function generic<T>(x: T): T { | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
return x; | ||
~~~~~~~~~~~~~ | ||
} | ||
~ | ||
!!! error TS8004: Type parameter declarations can only be used in TypeScript files. | ||
|
||
// Type arguments should be flagged as errors | ||
let array = Array<string>(); | ||
~~~~~~ | ||
!!! error TS2693: 'string' only refers to a type, but is being used as a value here. | ||
~ | ||
!!! error TS1109: Expression expected. | ||
|
||
// Implements clause should be flagged as errors | ||
class MyClassWithImplements implements Person { | ||
~~~~~~~~~~~~~~~~~~ | ||
!!! error TS8005: 'implements' clauses can only be used in TypeScript files. | ||
name = ''; | ||
age = 0; | ||
} | ||
|
||
function getValue(): any { | ||
~~~~ | ||
!!! error TS8010: Type annotations can only be used in TypeScript files. | ||
return null; | ||
} | ||
|
||
|
||
|
||
interface Config { | ||
~~~~~~~~~~~~~~~~~~ | ||
name: string; | ||
~~~~~~~~~~~~~~~~~ | ||
} | ||
~ | ||
!!! error TS8006: 'interface' declarations can only be used in TypeScript files. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.