-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Prevent panic and duplicate diagnostics for malformed tsconfig properties #4762
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,7 +261,13 @@ func parseOwnConfigOfJsonSourceFile( | |
| onPropertySet, | ||
| }, | ||
| ) | ||
| errors = append(errors, err...) | ||
| for _, diagnostic := range err { | ||
| if !slices.ContainsFunc(sourceFile.Diagnostics(), func(parseDiagnostic *ast.Diagnostic) bool { | ||
| return parseDiagnostic.Code() == diagnostic.Code() && parseDiagnostic.Pos() == diagnostic.Pos() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot Why are we doing this like this? Don't we already dedupe diags above this? This is quadratic
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Removed the local scan in 8483220 and rely on the existing final diagnostic sort/deduplication. |
||
| }) { | ||
| errors = append(errors, diagnostic) | ||
| } | ||
| } | ||
| // if len(rootCompilerOptions) != 0 && json != nil && json.CompilerOptions != nil { | ||
| // errors = append(errors, ast.NewDiagnostic(sourceFile, rootCompilerOptions[0], diagnostics.X_0_should_be_set_inside_the_compilerOptions_object_of_the_config_json_file)) | ||
| // } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| currentDirectory::/home/src/workspaces/project | ||
| useCaseSensitiveFileNames::true | ||
| Input:: | ||
| //// [/home/src/workspaces/project/index.ts] *new* | ||
|
|
||
| //// [/home/src/workspaces/project/tsconfig.json] *new* | ||
| {"" } | ||
|
|
||
| tsgo | ||
| ExitStatus:: DiagnosticsPresent_OutputsGenerated | ||
| Output:: | ||
| [96mtsconfig.json[0m:[93m1[0m:[93m4[0m - [91merror[0m[90m TS1328: [0mProperty value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal. | ||
|
|
||
| [7m1[0m {"" } | ||
| [7m [0m [91m ~[0m | ||
|
|
||
| [96mtsconfig.json[0m:[93m1[0m:[93m5[0m - [91merror[0m[90m TS1005: [0m':' expected. | ||
|
|
||
| [7m1[0m {"" } | ||
| [7m [0m [91m ~[0m | ||
|
|
||
|
|
||
| Found 2 errors in the same file, starting at: tsconfig.json[90m:1[0m | ||
|
|
||
| //// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib* | ||
| /// <reference no-default-lib="true"/> | ||
| interface Boolean {} | ||
| interface Function {} | ||
| interface CallableFunction {} | ||
| interface NewableFunction {} | ||
| interface IArguments {} | ||
| interface Number { toExponential: any; } | ||
| interface Object {} | ||
| interface RegExp {} | ||
| interface String { charAt: any; } | ||
| interface Array<T> { length: number; [n: number]: T; } | ||
| interface ReadonlyArray<T> {} | ||
| interface SymbolConstructor { | ||
| (desc?: string | number): symbol; | ||
| for(name: string): symbol; | ||
| readonly toStringTag: symbol; | ||
| } | ||
| declare var Symbol: SymbolConstructor; | ||
| interface Symbol { | ||
| readonly [Symbol.toStringTag]: string; | ||
| } | ||
| declare const console: { log(msg: any): void; }; | ||
| //// [/home/src/workspaces/project/index.js] *new* | ||
| "use strict"; | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot This is evil, why would this ever be out of range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node is a zero-width missing initializer; skipping its leading trivia moved the start past its end. Fixed in 8483220 by preserving missing-node spans, matching the shared/upstream error-span logic.