Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func TestTscCommandline(t *testing.T) {
subScenario: "when build not first argument",
commandLineArgs: []string{"--verbose", "--build"},
},
{
subScenario: "malformed tsconfig property without value",
files: FileMap{
"/home/src/workspaces/project/tsconfig.json": `{"" }`,
"/home/src/workspaces/project/index.ts": "",
},
commandLineArgs: nil,
},
{
subScenario: "Initialized TSConfig with files options",
commandLineArgs: []string{"--init", "file0.st", "file1.ts", "file2.ts"},
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (p *Parser) parseJSONText() *ast.SourceFile {

func getErrorSpanForNode(sourceText string, node *ast.Node) core.TextRange {
pos := scanner.SkipTrivia(sourceText, node.Pos())
return core.NewTextRange(pos, node.End())
return core.NewTextRange(min(pos, node.End()), max(pos, node.End()))

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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.

}

func (p *Parser) validateJsonValue(sourceFile *ast.SourceFile, valueExpression *ast.Expression) {
Expand Down
8 changes: 7 additions & 1 deletion internal/tsoptions/tsconfigparsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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))
// }
Expand Down
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::
tsconfig.json:1:4 - error TS1328: Property value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.

1 {"" }
   ~

tsconfig.json:1:5 - error TS1005: ':' expected.

1 {"" }
   ~


Found 2 errors in the same file, starting at: tsconfig.json:1

//// [/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";