diff --git a/internal/execute/tsctests/tsc_test.go b/internal/execute/tsctests/tsc_test.go index 29cba7ba4e2..00ed1838c9d 100644 --- a/internal/execute/tsctests/tsc_test.go +++ b/internal/execute/tsctests/tsc_test.go @@ -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"}, diff --git a/internal/parser/parser.go b/internal/parser/parser.go index a8cd3a6f3d2..8bbde76097b 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -227,7 +227,10 @@ func (p *Parser) parseJSONText() *ast.SourceFile { } func getErrorSpanForNode(sourceText string, node *ast.Node) core.TextRange { - pos := scanner.SkipTrivia(sourceText, node.Pos()) + pos := node.Pos() + if !ast.NodeIsMissing(node) { + pos = scanner.SkipTrivia(sourceText, pos) + } return core.NewTextRange(pos, node.End()) } diff --git a/testdata/baselines/reference/tsc/commandLine/malformed-tsconfig-property-without-value.js b/testdata/baselines/reference/tsc/commandLine/malformed-tsconfig-property-without-value.js new file mode 100644 index 00000000000..45425355086 --- /dev/null +++ b/testdata/baselines/reference/tsc/commandLine/malformed-tsconfig-property-without-value.js @@ -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* +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +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"; + +