Skip to content

Commit 8fd98bb

Browse files
committed
fix: generate unique type assert vars
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent 85827ca commit 8fd98bb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

compiler/type-assert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func (c *GoToTSCompiler) writeTypeAssert(lhs []ast.Expr, typeAssertExpr *ast.Typ
9696
// For selector expressions as ok, we need to use temporary variables approach
9797
if okIsSelectorExpr {
9898
// Use temporary variables approach similar to SelectorExpr case
99-
tempValName := "_gs_ta_val_" // Fixed name for temporary value
100-
tempOkName := "_gs_ta_ok_" // Fixed name for temporary ok status
99+
tempValName := fmt.Sprintf("_gs_ta_val_%d_", typeAssertExpr.Pos()) // Unique name based on AST position
100+
tempOkName := fmt.Sprintf("_gs_ta_ok_%d_", typeAssertExpr.Pos()) // Unique name based on AST position
101101

102102
// Declare temporary variables:
103103
// let _gs_ta_val_: AssertedTypeTS;
@@ -217,8 +217,8 @@ func (c *GoToTSCompiler) writeTypeAssert(lhs []ast.Expr, typeAssertExpr *ast.Typ
217217

218218
case *ast.SelectorExpr:
219219
// Handle s.field, ok := expr.(Type)
220-
tempValName := "_gs_ta_val_" // Fixed name for temporary value
221-
tempOkName := "_gs_ta_ok_" // Fixed name for temporary ok status
220+
tempValName := fmt.Sprintf("_gs_ta_val_%d_", typeAssertExpr.Pos()) // Unique name based on AST position
221+
tempOkName := fmt.Sprintf("_gs_ta_ok_%d_", typeAssertExpr.Pos()) // Unique name based on AST position
222222

223223
// Declare temporary variables:
224224
// let _gs_ta_val_: AssertedTypeTS;

0 commit comments

Comments
 (0)