diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 248db74ab3..d1c046a4d4 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -904,8 +904,7 @@ func newParentInChildrenSetter() func(node *Node) bool { } state.visit = func(node *Node) bool { - if state.parent != nil && node.Parent != state.parent { - // Avoid data races on no-ops + if state.parent != nil { node.Parent = state.parent } saveParent := state.parent diff --git a/internal/binder/binder.go b/internal/binder/binder.go index 3dc5ad31e8..f37f203fe3 100644 --- a/internal/binder/binder.go +++ b/internal/binder/binder.go @@ -46,7 +46,6 @@ type Binder struct { unreachableFlow *ast.FlowNode reportedUnreachableFlow *ast.FlowNode - parent *ast.Node container *ast.Node thisContainer *ast.Node blockScopeContainer *ast.Node @@ -211,9 +210,6 @@ func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol } else if !(includes&ast.SymbolFlagsVariable != 0 && symbol.Flags&ast.SymbolFlagsAssignment != 0 || includes&ast.SymbolFlagsAssignment != 0 && symbol.Flags&ast.SymbolFlagsVariable != 0) { // Assignment declarations are allowed to merge with variables, no matter what other flags they have. - if node.Name() != nil { - setParent(node.Name(), node) - } // Report errors every position with duplicate declaration // Report errors on previous encountered declarations var message *diagnostics.Message @@ -584,9 +580,6 @@ func (b *Binder) bind(node *ast.Node) bool { if node == nil { return false } - if node.Parent == nil || node.Parent.Flags&ast.NodeFlagsReparsed != 0 { - node.Parent = b.parent - } saveInStrictMode := b.inStrictMode // Even though in the AST the jsdoc @typedef node belongs to the current node, // its symbol might be in the same scope with the current node's symbol. Consider: @@ -731,9 +724,7 @@ func (b *Binder) bind(node *ast.Node) bool { // children, as an optimization we don't process those. thisNodeOrAnySubnodesHasError := node.Flags&ast.NodeFlagsThisNodeHasError != 0 if node.Kind > ast.KindLastToken { - saveParent := b.parent saveSeenParseError := b.seenParseError - b.parent = node b.seenParseError = false containerFlags := GetContainerFlags(node) if containerFlags == ContainerFlagsNone { @@ -744,15 +735,7 @@ func (b *Binder) bind(node *ast.Node) bool { if b.seenParseError { thisNodeOrAnySubnodesHasError = true } - b.parent = saveParent b.seenParseError = saveSeenParseError - } else { - saveParent := b.parent - if node.Kind == ast.KindEndOfFile { - b.parent = node - } - b.setJSDocParents(node) - b.parent = saveParent } if thisNodeOrAnySubnodesHasError { node.Flags |= ast.NodeFlagsThisNodeOrAnySubNodesHasError @@ -762,16 +745,6 @@ func (b *Binder) bind(node *ast.Node) bool { return false } -func (b *Binder) setJSDocParents(node *ast.Node) { - for _, jsdoc := range node.JSDoc(b.file) { - setParent(jsdoc, node) - if jsdoc.Kind != ast.KindJSDocImportTag { - // JSDocImportTag children have parents set during parsing for module resolution purposes. - ast.SetParentInChildren(jsdoc) - } - } -} - func (b *Binder) bindPropertyWorker(node *ast.Node) { isAutoAccessor := ast.IsAutoAccessorPropertyDeclaration(node) includes := core.IfElse(isAutoAccessor, ast.SymbolFlagsAccessor, ast.SymbolFlagsProperty) @@ -868,9 +841,6 @@ func (b *Binder) bindExportDeclaration(node *ast.Node) { // All export * declarations are collected in an __export symbol b.declareSymbol(ast.GetExports(b.container.Symbol()), b.container.Symbol(), node, ast.SymbolFlagsExportStar, ast.SymbolFlagsNone) } else if ast.IsNamespaceExport(decl.ExportClause) { - // declareSymbol walks up parents to find name text, parent _must_ be set - // but won't be set by the normal binder walk until `bindChildren` later on. - setParent(decl.ExportClause, node) b.declareSymbol(ast.GetExports(b.container.Symbol()), b.container.Symbol(), decl.ExportClause, ast.SymbolFlagsAlias, ast.SymbolFlagsAliasExcludes) } } @@ -981,7 +951,6 @@ func (b *Binder) bindClassLikeDeclaration(node *ast.Node) { prototypeSymbol := b.newSymbol(ast.SymbolFlagsProperty|ast.SymbolFlagsPrototype, "prototype") symbolExport := ast.GetExports(symbol)[prototypeSymbol.Name] if symbolExport != nil { - setParent(name, node) b.errorOnNode(symbolExport.Declarations[0], diagnostics.Duplicate_identifier_0, ast.SymbolName(prototypeSymbol)) } ast.GetExports(symbol)[prototypeSymbol.Name] = prototypeSymbol @@ -1026,9 +995,6 @@ func (b *Binder) bindExpandoPropertyAssignment(node *ast.Node) { symbol = b.lookupEntity(parent, b.container) } if symbol = getInitializerSymbol(symbol); symbol != nil { - // Fix up parent pointers since we're going to use these nodes before we bind into them - setParent(expr.Left, node) - setParent(expr.Right, node) if ast.HasDynamicName(node) { b.bindAnonymousDeclaration(node, ast.SymbolFlagsProperty|ast.SymbolFlagsAssignment, ast.InternalSymbolNameComputed) addLateBoundAssignmentDeclarationToSymbol(node, symbol) @@ -1599,7 +1565,6 @@ func (b *Binder) bindChildren(node *ast.Node) { // and set it before we descend into nodes that could actually be part of an assignment pattern. b.inAssignmentPattern = false if b.checkUnreachable(node) { - b.setJSDocParents(node) b.bindEachChild(node) b.inAssignmentPattern = saveInAssignmentPattern return @@ -1611,7 +1576,6 @@ func (b *Binder) bindChildren(node *ast.Node) { hasFlowNodeData.FlowNode = b.currentFlow } } - b.setJSDocParents(node) switch node.Kind { case ast.KindWhileStatement: b.bindWhileStatement(node) @@ -2800,12 +2764,6 @@ func (b *Binder) addDiagnostic(diagnostic *ast.Diagnostic) { b.file.SetBindDiagnostics(append(b.file.BindDiagnostics(), diagnostic)) } -func setParent(child *ast.Node, parent *ast.Node) { - if child != nil { - child.Parent = parent - } -} - func isSignedNumericLiteral(node *ast.Node) bool { if node.Kind == ast.KindPrefixUnaryExpression { node := node.AsPrefixUnaryExpression() diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index 5edfe9c4d8..f680ff880a 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -78,7 +78,6 @@ func fmtMain(sys System, input, output string) ExitStatus { Path: pathified, JSDocParsingMode: ast.JSDocParsingModeParseAll, }, text, core.GetScriptKindFromFileName(string(pathified))) - ast.SetParentInChildren(sourceFile.AsNode()) edits := format.FormatDocument(ctx, sourceFile) newText := applyBulkEdits(text, edits) diff --git a/internal/format/api_test.go b/internal/format/api_test.go index 62e87898a8..048d816f58 100644 --- a/internal/format/api_test.go +++ b/internal/format/api_test.go @@ -59,7 +59,6 @@ func TestFormat(t *testing.T) { FileName: "/checker.ts", Path: "/checker.ts", }, text, core.ScriptKindTS) - ast.SetParentInChildren(sourceFile.AsNode()) edits := format.FormatDocument(ctx, sourceFile) newText := applyBulkEdits(text, edits) assert.Assert(t, len(newText) > 0) @@ -89,7 +88,6 @@ func BenchmarkFormat(b *testing.B) { FileName: "/checker.ts", Path: "/checker.ts", }, text, core.ScriptKindTS) - ast.SetParentInChildren(sourceFile.AsNode()) b.Run("format checker.ts", func(b *testing.B) { for b.Loop() { diff --git a/internal/parser/jsdoc.go b/internal/parser/jsdoc.go index e9e9604d73..1da7b9511d 100644 --- a/internal/parser/jsdoc.go +++ b/internal/parser/jsdoc.go @@ -82,11 +82,6 @@ func (p *Parser) parseJSDocTypeExpression(mayOmitBraces bool) *ast.Node { } result := p.factory.NewJSDocTypeExpression(t) - // normally parent references are set during binding. However, for clients that only need - // a syntax tree, and no semantic features, then the binding process is an unnecessary - // overhead. This functions allows us to set all the parents, without all the expense of - // binding. - ast.SetParentInChildren(result) p.finishNode(result, pos) return result } @@ -107,7 +102,6 @@ func (p *Parser) parseJSDocNameReference() *ast.Node { } result := p.factory.NewJSDocNameReference(entityName) - ast.SetParentInChildren(result) p.finishNode(result, pos) return result } @@ -145,7 +139,6 @@ func (p *Parser) parseJSDocComment(parent *ast.Node, start int, end int, fullSta p.parsingContexts = p.parsingContexts | ParsingContexts(PCJSDocComment) comment := p.parseJSDocCommentWorker(start, end, fullStart, initialIndent) - comment.Parent = parent // move jsdoc diagnostics to jsdocDiagnostics -- for JS files only if p.contextFlags&ast.NodeFlagsJavaScriptFile != 0 { p.jsdocDiagnostics = append(p.jsdocDiagnostics, p.diagnostics[saveDiagnosticsLength:]...) @@ -457,7 +450,6 @@ func (p *Parser) parseTag(tags []*ast.Node, margin int) *ast.Node { tag = p.parseSeeTag(start, tagName, margin, indentText) case "import": tag = p.parseImportTag(start, tagName, margin, indentText) - ast.SetParentInChildren(tag) default: tag = p.parseUnknownTag(start, tagName, margin, indentText) } diff --git a/internal/parser/parser.go b/internal/parser/parser.go index fc1e70e19a..5ed34c4e42 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -352,6 +352,15 @@ func (p *Parser) finishSourceFile(result *ast.SourceFile, isDeclarationFile bool result.TextCount = p.factory.TextCount() result.IdentifierCount = p.identifierCount result.SetJSDocCache(p.jsdocCache) + + ast.SetParentInChildren(result.AsNode()) + for parent, children := range p.jsdocCache { + for _, child := range children { + child.Parent = parent + ast.SetParentInChildren(child) + } + } + ast.SetExternalModuleIndicator(result, p.opts.ExternalModuleIndicatorOptions) } diff --git a/internal/parser/references.go b/internal/parser/references.go index 5d72f66db8..c5fda691c6 100644 --- a/internal/parser/references.go +++ b/internal/parser/references.go @@ -15,7 +15,6 @@ func collectExternalModuleReferences(file *ast.SourceFile) { if file.Flags&ast.NodeFlagsPossiblyContainsDynamicImport != 0 || ast.IsInJSFile(file.AsNode()) { ast.ForEachDynamicImportOrRequireCall(file /*includeTypeSpaceImports*/, true /*requireStringLiteralLikeArgument*/, true, func(node *ast.Node, moduleSpecifier *ast.Expression) bool { - 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(), moduleSpecifier)) return false }) @@ -31,9 +30,6 @@ 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)) { - 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 { @@ -50,7 +46,6 @@ func collectModuleReferences(file *ast.SourceFile, node *ast.Statement, inAmbien return } if ast.IsModuleDeclaration(node) && ast.IsAmbientModule(node) && (inAmbientModule || ast.HasSyntacticModifier(node, ast.ModifierFlagsAmbient) || file.IsDeclarationFile) { - ast.SetParentInChildren(node) nameText := node.AsModuleDeclaration().Name().Text() // Ambient module declarations can be interpreted as augmentations for some existing external modules. // This will happen in two cases: diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 90fb6e2f56..754adb218c 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -614,7 +614,6 @@ func TestParenthesizeDecorator(t *testing.T) { }, )) - ast.SetParentInChildren(file) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "@(a + b)\nclass C {\n}") } @@ -651,7 +650,7 @@ func TestParenthesizeComputedPropertyName(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "class C {\n [(a, b)];\n}") } @@ -681,7 +680,7 @@ func TestParenthesizeArrayLiteral(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "[(a, b)];") } @@ -709,7 +708,7 @@ func TestParenthesizePropertyAccess1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b).c;") } @@ -736,7 +735,7 @@ func TestParenthesizePropertyAccess2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b).c;") } @@ -762,7 +761,7 @@ func TestParenthesizePropertyAccess3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(new a).b;") } @@ -790,7 +789,7 @@ func TestParenthesizeElementAccess1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b)[c];") } @@ -817,7 +816,7 @@ func TestParenthesizeElementAccess2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b)[c];") } @@ -843,7 +842,7 @@ func TestParenthesizeElementAccess3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(new a)[b];") } @@ -872,7 +871,7 @@ func TestParenthesizeCall1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b)();") } @@ -900,7 +899,7 @@ func TestParenthesizeCall2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b)();") } @@ -927,7 +926,7 @@ func TestParenthesizeCall3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(new C)();") } @@ -957,7 +956,7 @@ func TestParenthesizeCall4(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a((b, c));") } @@ -984,7 +983,7 @@ func TestParenthesizeNew1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new (a, b)();") } @@ -1011,7 +1010,7 @@ func TestParenthesizeNew2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new (C());") } @@ -1039,7 +1038,7 @@ func TestParenthesizeNew3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new C((a, b));") } @@ -1068,7 +1067,7 @@ func TestParenthesizeTaggedTemplate1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) ``;") } @@ -1096,7 +1095,7 @@ func TestParenthesizeTaggedTemplate2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b) ``;") } @@ -1125,7 +1124,7 @@ func TestParenthesizeTypeAssertion1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a + b);") } @@ -1152,7 +1151,7 @@ func TestParenthesizeArrowFunction1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "() => ({});") } @@ -1184,7 +1183,7 @@ func TestParenthesizeArrowFunction2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "() => ({}.a);") } @@ -1209,7 +1208,7 @@ func TestParenthesizeDelete(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "delete (a + b);") } @@ -1234,7 +1233,7 @@ func TestParenthesizeVoid(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "void (a + b);") } @@ -1259,7 +1258,7 @@ func TestParenthesizeTypeOf(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "typeof (a + b);") } @@ -1284,7 +1283,7 @@ func TestParenthesizeAwait(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "await (a + b);") } @@ -1407,7 +1406,7 @@ func TestParenthesizeBinary(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), rec.output+";") }) @@ -1438,7 +1437,7 @@ func TestParenthesizeConditional1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) ? c : d;") } @@ -1467,7 +1466,7 @@ func TestParenthesizeConditional2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a = b) ? c : d;") } @@ -1500,7 +1499,7 @@ func TestParenthesizeConditional3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(() => { }) ? a : b;") } @@ -1523,7 +1522,7 @@ func TestParenthesizeConditional4(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(yield) ? a : b;") } @@ -1552,7 +1551,7 @@ func TestParenthesizeConditional5(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a ? (b, c) : d;") } @@ -1581,7 +1580,7 @@ func TestParenthesizeConditional6(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a ? b : (c, d);") } @@ -1607,7 +1606,7 @@ func TestParenthesizeYield1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "yield (a, b);") } @@ -1643,7 +1642,7 @@ func TestParenthesizeSpreadElement1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "[...(a, b)];") } @@ -1678,7 +1677,7 @@ func TestParenthesizeSpreadElement2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a(...(b, c));") } @@ -1711,7 +1710,7 @@ func TestParenthesizeSpreadElement3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new a(...(b, c));") } @@ -1744,7 +1743,7 @@ func TestParenthesizeExpressionWithTypeArguments(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b);") } @@ -1773,7 +1772,7 @@ func TestParenthesizeAsExpression(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) as c;") } @@ -1802,7 +1801,7 @@ func TestParenthesizeSatisfiesExpression(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) satisfies c;") } @@ -1828,7 +1827,7 @@ func TestParenthesizeNonNullExpression(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b)!;") } @@ -1849,7 +1848,7 @@ func TestParenthesizeExpressionStatement1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "({});") } @@ -1878,7 +1877,7 @@ func TestParenthesizeExpressionStatement2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(function () { });") } @@ -1902,7 +1901,7 @@ func TestParenthesizeExpressionStatement3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(class {\n});") } @@ -1930,7 +1929,7 @@ func TestParenthesizeExpressionDefault1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "export default (class {\n});") } @@ -1965,7 +1964,7 @@ func TestParenthesizeExpressionDefault2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "export default (function () { });") } @@ -1991,7 +1990,7 @@ func TestParenthesizeExpressionDefault3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "export default (a, b);") } @@ -2020,7 +2019,7 @@ func TestParenthesizeArrayType(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (a | b)[];") } @@ -2055,7 +2054,7 @@ func TestParenthesizeOptionalType(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = [\n (a | b)?\n];") } @@ -2088,7 +2087,7 @@ func TestParenthesizeUnionType1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a | (() => b);") } @@ -2122,7 +2121,7 @@ func TestParenthesizeUnionType2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (infer a extends b) | c;") } @@ -2156,7 +2155,7 @@ func TestParenthesizeIntersectionType(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a & (b | c);") } @@ -2186,7 +2185,7 @@ func TestParenthesizeReadonlyTypeOperator1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = readonly (a | b);") } @@ -2212,7 +2211,7 @@ func TestParenthesizeReadonlyTypeOperator2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = readonly (keyof a);") } @@ -2242,7 +2241,7 @@ func TestParenthesizeKeyofTypeOperator(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = keyof (a | b);") } @@ -2272,7 +2271,7 @@ func TestParenthesizeIndexedAccessType(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (a | b)[c];") } @@ -2303,7 +2302,7 @@ func TestParenthesizeConditionalType1(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (() => a) extends b ? c : d;") } @@ -2333,7 +2332,7 @@ func TestParenthesizeConditionalType2(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a extends (b extends c ? d : e) ? f : g;") } @@ -2371,7 +2370,7 @@ func TestParenthesizeConditionalType3(t *testing.T) { ), }, )) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a extends () => (infer b extends c) ? d : e;") } @@ -2414,7 +2413,7 @@ func TestParenthesizeConditionalType4(t *testing.T) { ), ), })) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a extends () => (infer b extends c) | d ? e : f;") } @@ -2446,7 +2445,7 @@ func TestNameGeneration(t *testing.T) { }), true), ), })) - ast.SetParentInChildren(file) + parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, ec, file.AsSourceFile(), "var _a;\nfunction f() {\n var _a;\n}") } diff --git a/internal/testutil/parsetestutil/parsetestutil.go b/internal/testutil/parsetestutil/parsetestutil.go index 2901f6b2b1..589077b56c 100644 --- a/internal/testutil/parsetestutil/parsetestutil.go +++ b/internal/testutil/parsetestutil/parsetestutil.go @@ -19,7 +19,6 @@ func ParseTypeScript(text string, jsx bool) *ast.SourceFile { Path: tspath.Path(fileName), JSDocParsingMode: ast.JSDocParsingModeParseNone, }, text, core.GetScriptKindFromFileName(fileName)) - ast.SetParentInChildren(file.AsNode()) return file }