From 272a4c8bfb02a54ce9f75a83168bc55ed0350397 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 3 Jun 2025 17:15:03 -0700 Subject: [PATCH 1/2] Fix more parent races --- internal/ast/utilities.go | 3 ++- internal/binder/binder.go | 5 ++++- internal/parser/references.go | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 8df59ec51d..7bab1f5f90 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -885,7 +885,8 @@ func newParentInChildrenSetter() func(node *Node) bool { } state.visit = func(node *Node) bool { - if state.parent != nil { + if state.parent != nil && node.Parent != state.parent { + // Avoid data races on no-ops node.Parent = state.parent } saveParent := state.parent diff --git a/internal/binder/binder.go b/internal/binder/binder.go index 5e3dcdbcda..433aa6c90e 100644 --- a/internal/binder/binder.go +++ b/internal/binder/binder.go @@ -762,7 +762,10 @@ func (b *Binder) bind(node *ast.Node) bool { func (b *Binder) setJSDocParents(node *ast.Node) { for _, jsdoc := range node.JSDoc(b.file) { setParent(jsdoc, node) - ast.SetParentInChildren(jsdoc) + if jsdoc.Kind != ast.KindJSDocImportTag { + // JSDocImportTag children have parents set during parsing for module resolution purposes. + ast.SetParentInChildren(jsdoc) + } } } diff --git a/internal/parser/references.go b/internal/parser/references.go index e3c130eb10..5d72f66db8 100644 --- a/internal/parser/references.go +++ b/internal/parser/references.go @@ -31,7 +31,9 @@ func collectModuleReferences(file *ast.SourceFile, node *ast.Statement, inAmbien if moduleNameExpr != nil && ast.IsStringLiteral(moduleNameExpr) { moduleName := moduleNameExpr.AsStringLiteral().Text if moduleName != "" && (!inAmbientModule || !tspath.IsExternalModuleNameRelative(moduleName)) { - ast.SetParentInChildren(node) // we need parent data on imports before the program is fully bound, so we ensure it's set here + if node.Kind != ast.KindJSImportDeclaration { + ast.SetParentInChildren(node) // we need parent data on imports before the program is fully bound, so we ensure it's set here + } ast.SetImportsOfSourceFile(file, append(file.Imports(), moduleNameExpr)) // !!! removed `&& p.currentNodeModulesDepth == 0` if file.UsesUriStyleNodeCoreModules != core.TSTrue && !file.IsDeclarationFile { From 097e4dad0923e94ef9536b8168ef0f210bf79e1f Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 4 Jun 2025 09:14:12 -0700 Subject: [PATCH 2/2] Update baselines --- .../submodule/conformance/importTag17.errors.txt | 6 +++--- .../conformance/importTag17.errors.txt.diff | 14 +++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/testdata/baselines/reference/submodule/conformance/importTag17.errors.txt b/testdata/baselines/reference/submodule/conformance/importTag17.errors.txt index 23d82435df..defcfc35bc 100644 --- a/testdata/baselines/reference/submodule/conformance/importTag17.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/importTag17.errors.txt @@ -1,4 +1,4 @@ -/a.js(1,29): error TS2307: Cannot find module 'foo' or its corresponding type declarations. +/a.js(5,15): error TS2749: 'Import' refers to a value, but is being used as a type here. Did you mean 'typeof Import'? /a.js(12,15): error TS2749: 'Require' refers to a value, but is being used as a type here. Did you mean 'typeof Require'? @@ -22,12 +22,12 @@ ==== /a.js (2 errors) ==== /** @import { Import } from 'foo' with { 'resolution-mode': 'import' } */ - ~~~~~ -!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. /** @import { Require } from 'foo' with { 'resolution-mode': 'require' } */ /** * @returns { Import } + ~~~~~~ +!!! error TS2749: 'Import' refers to a value, but is being used as a type here. Did you mean 'typeof Import'? */ export function f1() { return 1; diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/importTag17.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/importTag17.errors.txt.diff index 26073430f0..1c6f910b5b 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/importTag17.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/importTag17.errors.txt.diff @@ -3,21 +3,17 @@ @@= skipped -0, +0 lines =@@ -/a.js(8,5): error TS2322: Type '1' is not assignable to type '"module"'. -/a.js(15,5): error TS2322: Type '1' is not assignable to type '"script"'. -+/a.js(1,29): error TS2307: Cannot find module 'foo' or its corresponding type declarations. ++/a.js(5,15): error TS2749: 'Import' refers to a value, but is being used as a type here. Did you mean 'typeof Import'? +/a.js(12,15): error TS2749: 'Require' refers to a value, but is being used as a type here. Did you mean 'typeof Require'? ==== /node_modules/@types/foo/package.json (0 errors) ==== -@@= skipped -21, +21 lines =@@ - - ==== /a.js (2 errors) ==== - /** @import { Import } from 'foo' with { 'resolution-mode': 'import' } */ -+ ~~~~~ -+!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. - /** @import { Require } from 'foo' with { 'resolution-mode': 'require' } */ +@@= skipped -25, +25 lines =@@ /** -@@= skipped -7, +9 lines =@@ + * @returns { Import } ++ ~~~~~~ ++!!! error TS2749: 'Import' refers to a value, but is being used as a type here. Did you mean 'typeof Import'? */ export function f1() { return 1;