Skip to content

Commit 5af4ac0

Browse files
Fix panic in getTsConfigObjectLiteralExpression for malformed tsconfig (#3877)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
1 parent b463318 commit 5af4ac0

6 files changed

Lines changed: 41 additions & 1 deletion

File tree

internal/tsoptions/tsconfigparsing.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,9 @@ func ForEachPropertyAssignment[T any](objectLiteral *ast.ObjectLiteralExpression
15051505
func getTsConfigObjectLiteralExpression(tsConfigSourceFile *ast.SourceFile) *ast.ObjectLiteralExpression {
15061506
if tsConfigSourceFile != nil && tsConfigSourceFile.Statements != nil && len(tsConfigSourceFile.Statements.Nodes) > 0 {
15071507
expression := tsConfigSourceFile.Statements.Nodes[0].Expression()
1508-
return expression.AsObjectLiteralExpression()
1508+
if ast.IsObjectLiteralExpression(expression) {
1509+
return expression.AsObjectLiteralExpression()
1510+
}
15091511
}
15101512
return nil
15111513
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error TS2688: Cannot find type definition file for 'nonexistent'.
2+
The file is in the program because:
3+
Entry point of type library 'nonexistent' specified in compilerOptions
4+
5+
6+
!!! error TS2688: Cannot find type definition file for 'nonexistent'.
7+
!!! error TS2688: The file is in the program because:
8+
!!! error TS2688: Entry point of type library 'nonexistent' specified in compilerOptions
9+
==== tsconfig.json (0 errors) ====
10+
[{"compilerOptions": {"types": ["nonexistent"]}}]
11+
==== index.ts (0 errors) ====
12+
export const x = 1;
13+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/tsconfigMalformedNonObject.ts] ////
2+
3+
//// [index.ts]
4+
export const x = 1;
5+
6+
7+
//// [index.js]
8+
export const x = 1;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [tests/cases/compiler/tsconfigMalformedNonObject.ts] ////
2+
3+
=== index.ts ===
4+
export const x = 1;
5+
>x : Symbol(x, Decl(index.ts, 0, 12))
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/compiler/tsconfigMalformedNonObject.ts] ////
2+
3+
=== index.ts ===
4+
export const x = 1;
5+
>x : 1
6+
>1 : 1
7+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @filename: tsconfig.json
2+
[{"compilerOptions": {"types": ["nonexistent"]}}]
3+
// @filename: index.ts
4+
export const x = 1;

0 commit comments

Comments
 (0)