Skip to content

Commit 272a4c8

Browse files
committed
Fix more parent races
1 parent ae5c275 commit 272a4c8

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

internal/ast/utilities.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ func newParentInChildrenSetter() func(node *Node) bool {
885885
}
886886

887887
state.visit = func(node *Node) bool {
888-
if state.parent != nil {
888+
if state.parent != nil && node.Parent != state.parent {
889+
// Avoid data races on no-ops
889890
node.Parent = state.parent
890891
}
891892
saveParent := state.parent

internal/binder/binder.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@ func (b *Binder) bind(node *ast.Node) bool {
762762
func (b *Binder) setJSDocParents(node *ast.Node) {
763763
for _, jsdoc := range node.JSDoc(b.file) {
764764
setParent(jsdoc, node)
765-
ast.SetParentInChildren(jsdoc)
765+
if jsdoc.Kind != ast.KindJSDocImportTag {
766+
// JSDocImportTag children have parents set during parsing for module resolution purposes.
767+
ast.SetParentInChildren(jsdoc)
768+
}
766769
}
767770
}
768771

internal/parser/references.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ func collectModuleReferences(file *ast.SourceFile, node *ast.Statement, inAmbien
3131
if moduleNameExpr != nil && ast.IsStringLiteral(moduleNameExpr) {
3232
moduleName := moduleNameExpr.AsStringLiteral().Text
3333
if moduleName != "" && (!inAmbientModule || !tspath.IsExternalModuleNameRelative(moduleName)) {
34-
ast.SetParentInChildren(node) // we need parent data on imports before the program is fully bound, so we ensure it's set here
34+
if node.Kind != ast.KindJSImportDeclaration {
35+
ast.SetParentInChildren(node) // we need parent data on imports before the program is fully bound, so we ensure it's set here
36+
}
3537
ast.SetImportsOfSourceFile(file, append(file.Imports(), moduleNameExpr))
3638
// !!! removed `&& p.currentNodeModulesDepth == 0`
3739
if file.UsesUriStyleNodeCoreModules != core.TSTrue && !file.IsDeclarationFile {

0 commit comments

Comments
 (0)