diff --git a/tsc/internal/api/session.go b/tsc/internal/api/session.go index e44b35895353b..d7b086ecf6d69 100644 --- a/tsc/internal/api/session.go +++ b/tsc/internal/api/session.go @@ -57,7 +57,7 @@ func getSourceFileSymbolIndex(sourceFile *ast.SourceFile) map[SymbolID]*ast.Symb index := make(map[SymbolID]*ast.Symbol, file.SymbolCount) var addSymbol func(*ast.Symbol) addSymbol = func(symbol *ast.Symbol) { - if symbol == nil || symbol.Flags&ast.SymbolFlagsTransient != 0 { + if symbol == nil || symbol.Flags()&ast.SymbolFlagsTransient != 0 { return } compilerdebug.Assert(ast.GetSourceFileOfSymbol(symbol) == file) @@ -67,9 +67,9 @@ func getSourceFileSymbolIndex(sourceFile *ast.SourceFile) map[SymbolID]*ast.Symb return } index[id] = symbol - addSymbol(symbol.Parent) - addSymbol(symbol.ExportSymbol) - for _, table := range []ast.SymbolTable{symbol.Members, symbol.Exports} { + addSymbol(symbol.Parent()) + addSymbol(symbol.ExportSymbol()) + for _, table := range []ast.SymbolTable{symbol.Members(), symbol.Exports()} { for _, child := range table { addSymbol(child) } @@ -203,7 +203,7 @@ func (sd *snapshotData) getOrCreateProjectRegistry(projectID project.ID) *projec // symbol is owned by its snapshot. Content-mapped outputs live in a cache that cannot yet be // addressed by file key, so their binder symbols remain snapshot-owned. func symbolOwnerFile(symbol *ast.Symbol) *ast.SourceFile { - if symbol.Flags&ast.SymbolFlagsTransient != 0 { + if symbol.Flags()&ast.SymbolFlagsTransient != 0 { return nil } file := ast.GetSourceFileOfSymbol(symbol) @@ -248,25 +248,25 @@ func newFileSymbolResponse(symbol *ast.Symbol) *SymbolResponse { func buildSymbolResponse(symbol *ast.Symbol, reference SymbolReference, owner *ast.SourceFile) *SymbolResponse { resp := &SymbolResponse{ Reference: reference, - Name: ast.EscapeSymbolName(symbol.Name), - Flags: uint32(symbol.Flags), - CheckFlags: uint32(symbol.CheckFlags), - Parent: newSymbolReference(symbol.Parent), - ExportSymbol: newSymbolReference(symbol.ExportSymbol), + Name: ast.EscapeSymbolName(symbol.Name()), + Flags: uint32(symbol.Flags()), + CheckFlags: uint32(symbol.CheckFlags()), + Parent: newSymbolReference(symbol.Parent()), + ExportSymbol: newSymbolReference(symbol.ExportSymbol()), } if owner != nil { // A client resolves a file-owned symbol's relationships through its own source file. - compilerdebug.Assert(symbol.Parent == nil || symbolOwnerFile(symbol.Parent) == owner, "File-owned symbol parent belongs to another owner") - compilerdebug.Assert(symbol.ExportSymbol == nil || symbolOwnerFile(symbol.ExportSymbol) == owner, "File-owned export symbol belongs to another owner") + compilerdebug.Assert(symbol.Parent() == nil || symbolOwnerFile(symbol.Parent()) == owner, "File-owned symbol parent belongs to another owner") + compilerdebug.Assert(symbol.ExportSymbol() == nil || symbolOwnerFile(symbol.ExportSymbol()) == owner, "File-owned export symbol belongs to another owner") } - if len(symbol.Declarations) > 0 { - resp.Declarations = make([]NodeHandle, len(symbol.Declarations)) - for i, decl := range symbol.Declarations { + if len(symbol.Declarations()) > 0 { + resp.Declarations = make([]NodeHandle, len(symbol.Declarations())) + for i, decl := range symbol.Declarations() { resp.Declarations[i] = symbolNodeHandleFrom(decl, owner) } } - if symbol.ValueDeclaration != nil { - resp.ValueDeclaration = symbolNodeHandleFrom(symbol.ValueDeclaration, owner) + if symbol.ValueDeclaration() != nil { + resp.ValueDeclaration = symbolNodeHandleFrom(symbol.ValueDeclaration(), owner) } return resp } @@ -3071,26 +3071,26 @@ func (s *Session) handleGetTypesAtPositions(ctx context.Context, params *GetType // @gen-proto-nullable func (s *Session) handleGetParentOfSymbol(_ context.Context, params *GetSymbolPropertyParams) (*SymbolResponse, error) { - return s.resolveSymbolPropertyOfSymbol(params, func(sym *ast.Symbol) *ast.Symbol { return sym.Parent }) + return s.resolveSymbolPropertyOfSymbol(params, func(sym *ast.Symbol) *ast.Symbol { return sym.Parent() }) } // @gen-proto-nullable func (s *Session) handleGetMembersOfSymbol(ctx context.Context, params *GetSymbolPropertyParams) ([]*SymbolResponse, error) { return s.resolveSymbolTablePropertyOfSymbol(ctx, params, func(symbol *ast.Symbol) ast.SymbolTable { - return symbol.Members + return symbol.Members() }) } // @gen-proto-nullable func (s *Session) handleGetExportsOfSymbol(ctx context.Context, params *GetSymbolPropertyParams) ([]*SymbolResponse, error) { return s.resolveSymbolTablePropertyOfSymbol(ctx, params, func(symbol *ast.Symbol) ast.SymbolTable { - return symbol.Exports + return symbol.Exports() }) } // @gen-proto-nullable func (s *Session) handleGetExportSymbolOfSymbol(_ context.Context, params *GetSymbolPropertyParams) (*SymbolResponse, error) { - return s.resolveSymbolPropertyOfSymbol(params, func(sym *ast.Symbol) *ast.Symbol { return sym.ExportSymbol }) + return s.resolveSymbolPropertyOfSymbol(params, func(sym *ast.Symbol) *ast.Symbol { return sym.ExportSymbol() }) } // @gen-proto-nullable @@ -3469,8 +3469,8 @@ func (s *Session) resolveSymbolTablePropertyOfSymbol(ctx context.Context, params slices.SortFunc(symbols, func(left *ast.Symbol, right *ast.Symbol) int { compilerdebug.Assert(ast.GetSourceFileOfSymbol(left) == file) compilerdebug.Assert(ast.GetSourceFileOfSymbol(right) == file) - leftHasDeclaration := len(left.Declarations) != 0 - rightHasDeclaration := len(right.Declarations) != 0 + leftHasDeclaration := len(left.Declarations()) != 0 + rightHasDeclaration := len(right.Declarations()) != 0 if leftHasDeclaration != rightHasDeclaration { if leftHasDeclaration { return -1 @@ -3478,11 +3478,11 @@ func (s *Session) resolveSymbolTablePropertyOfSymbol(ctx context.Context, params return 1 } if leftHasDeclaration { - if order := cmp.Compare(left.Declarations[0].Pos(), right.Declarations[0].Pos()); order != 0 { + if order := cmp.Compare(left.Declarations()[0].Pos(), right.Declarations()[0].Pos()); order != 0 { return order } } - if order := cmp.Compare(left.Name, right.Name); order != 0 { + if order := cmp.Compare(left.Name(), right.Name()); order != 0 { return order } return cmp.Compare(ast.GetSymbolId(left), ast.GetSymbolId(right)) @@ -4214,9 +4214,9 @@ func (s *Session) handleGetWellKnownSymbols(ctx context.Context, params *GetIntr unknownSymbol := setup.checker.GetUnknownSymbol() undefinedSymbol := setup.checker.GetUndefinedSymbol() argumentsSymbol := setup.checker.GetArgumentsSymbol() - compilerdebug.Assert(unknownSymbol.Flags&ast.SymbolFlagsTransient != 0) - compilerdebug.Assert(undefinedSymbol.Flags&ast.SymbolFlagsTransient != 0) - compilerdebug.Assert(argumentsSymbol.Flags&ast.SymbolFlagsTransient != 0) + compilerdebug.Assert(unknownSymbol.Flags()&ast.SymbolFlagsTransient != 0) + compilerdebug.Assert(undefinedSymbol.Flags()&ast.SymbolFlagsTransient != 0) + compilerdebug.Assert(argumentsSymbol.Flags()&ast.SymbolFlagsTransient != 0) unknown, _ := setup.sd.registerSymbol(unknownSymbol, setup.projectID) undefined, _ := setup.sd.registerSymbol(undefinedSymbol, setup.projectID) arguments, _ := setup.sd.registerSymbol(argumentsSymbol, setup.projectID) diff --git a/tsc/internal/api/session_symbolresponse_test.go b/tsc/internal/api/session_symbolresponse_test.go index d6a564919b9f6..021f5e848055a 100644 --- a/tsc/internal/api/session_symbolresponse_test.go +++ b/tsc/internal/api/session_symbolresponse_test.go @@ -59,11 +59,10 @@ func TestTransientSymbolWithFileDeclarationIsSnapshotOwned(t *testing.T) { t.Parallel() sourceFile := parseAndBind(t, "/file.ts", `export class C { property = 1 }`) class := sourceFile.Statements.Nodes[0] - symbol := &ast.Symbol{ - Flags: ast.SymbolFlagsClass | ast.SymbolFlagsTransient, - Name: "C", - Declarations: []*ast.Node{class}, - } + symbol := &ast.Symbol{} + symbol.SetFlags(ast.SymbolFlagsClass | ast.SymbolFlagsTransient) + symbol.SetName("C") + symbol.SetDeclarations([]*ast.Node{class}) sd := newTestSnapshotData() response := sd.newSymbolResponse(symbol, "/tsconfig.json") @@ -86,7 +85,7 @@ func TestSymbolReferencesIdentifyOwnerWithoutDescriptor(t *testing.T) { assert.Assert(t, !strings.Contains(string(encoded), "contentHash")) // A file-owned symbol's relationships are references into the same file. - member := class.Members["property"] + member := class.Members()["property"] response := newFileSymbolResponse(member) assert.DeepEqual(t, response.Parent, reference) } @@ -110,6 +109,6 @@ func TestContentMappedSymbolsAreSnapshotOwned(t *testing.T) { assert.NilError(t, err) assert.Equal(t, resolved, class) - reference := newSymbolReference(class.Members["property"]) + reference := newSymbolReference(class.Members()["property"]) assert.Equal(t, reference.File, "") } diff --git a/tsc/internal/ast/symbol.go b/tsc/internal/ast/symbol.go index 56de5dd69af78..47505fa6476a9 100644 --- a/tsc/internal/ast/symbol.go +++ b/tsc/internal/ast/symbol.go @@ -7,60 +7,80 @@ import ( "github.com/microsoft/TypeScript/tsc/internal/debug" ) -// Symbol - +// Symbol stores binding information. Its accessors expose the stored values +// without copying declaration slices or symbol tables. type Symbol struct { - Flags SymbolFlags - CheckFlags CheckFlags // Non-zero only in transient symbols created by Checker - Name string - Declarations []*Node - ValueDeclaration *Node - Members SymbolTable - Exports SymbolTable + flags SymbolFlags + checkFlags CheckFlags // Non-zero only in transient symbols created by Checker + name string + declarations []*Node + valueDeclaration *Node + members SymbolTable + exports SymbolTable id atomic.Uint64 - Parent *Symbol - ExportSymbol *Symbol + parent *Symbol + exportSymbol *Symbol } +func (s *Symbol) Flags() SymbolFlags { return s.flags } +func (s *Symbol) CheckFlags() CheckFlags { return s.checkFlags } +func (s *Symbol) Name() string { return s.name } +func (s *Symbol) Declarations() []*Node { return s.declarations } +func (s *Symbol) ValueDeclaration() *Node { return s.valueDeclaration } +func (s *Symbol) Members() SymbolTable { return s.members } +func (s *Symbol) Exports() SymbolTable { return s.exports } +func (s *Symbol) Parent() *Symbol { return s.parent } +func (s *Symbol) ExportSymbol() *Symbol { return s.exportSymbol } + +func (s *Symbol) SetFlags(value SymbolFlags) { s.flags = value } +func (s *Symbol) SetCheckFlags(value CheckFlags) { s.checkFlags = value } +func (s *Symbol) SetName(value string) { s.name = value } +func (s *Symbol) SetDeclarations(value []*Node) { s.declarations = value } +func (s *Symbol) SetValueDeclaration(value *Node) { s.valueDeclaration = value } +func (s *Symbol) SetMembers(value SymbolTable) { s.members = value } +func (s *Symbol) SetExports(value SymbolTable) { s.exports = value } +func (s *Symbol) SetParent(value *Symbol) { s.parent = value } +func (s *Symbol) SetExportSymbol(value *Symbol) { s.exportSymbol = value } + // GetSourceFileOfSymbol returns the owning file of a published binder symbol, or // nil for a non-file-owned symbol, even if it borrows declarations from a file. // Ownership recovery walks only the first declaration's AST parents. func GetSourceFileOfSymbol(symbol *Symbol) *SourceFile { debug.Assert(symbol != nil, "Expected a symbol") - if symbol.Flags&SymbolFlagsTransient != 0 { + if symbol.Flags()&SymbolFlagsTransient != 0 { return nil } - if len(symbol.Declarations) == 0 { + if len(symbol.Declarations()) == 0 { // A class's implicit prototype has no declaration of its own. - debug.Assert(symbol.Flags&SymbolFlagsPrototype != 0, "File-bound symbol has no declarations") - debug.Assert(symbol.Parent != nil && symbol.Parent.Flags&SymbolFlagsClass != 0, "Prototype has no declaring class") - symbol = symbol.Parent - debug.Assert(symbol.Flags&SymbolFlagsTransient == 0, "Prototype parent is not file-bound") - debug.Assert(len(symbol.Declarations) != 0, "Prototype parent has no declarations") + debug.Assert(symbol.Flags()&SymbolFlagsPrototype != 0, "File-bound symbol has no declarations") + debug.Assert(symbol.Parent() != nil && symbol.Parent().Flags()&SymbolFlagsClass != 0, "Prototype has no declaring class") + symbol = symbol.Parent() + debug.Assert(symbol.Flags()&SymbolFlagsTransient == 0, "Prototype parent is not file-bound") + debug.Assert(len(symbol.Declarations()) != 0, "Prototype parent has no declarations") } - file := GetSourceFileOfNode(symbol.Declarations[0]) + file := GetSourceFileOfNode(symbol.Declarations()[0]) debug.Assert(file != nil, "File-bound declaration has no source file") return file } func (s *Symbol) IsExternalModule() bool { - return s.Flags&SymbolFlagsModule != 0 && IsAmbientModuleSymbolName(s.Name) + return s.Flags()&SymbolFlagsModule != 0 && IsAmbientModuleSymbolName(s.Name()) } func (s *Symbol) IsStatic() bool { - if s.ValueDeclaration == nil { + if s.ValueDeclaration() == nil { return false } - modifierFlags := s.ValueDeclaration.ModifierFlags() + modifierFlags := s.ValueDeclaration().ModifierFlags() return modifierFlags&ModifierFlagsStatic != 0 } // See comment on `declareModuleMember` in `binder.go`. func (s *Symbol) CombinedLocalAndExportSymbolFlags() SymbolFlags { - if s.ExportSymbol != nil { - return s.Flags | s.ExportSymbol.Flags + if s.ExportSymbol() != nil { + return s.Flags() | s.ExportSymbol().Flags() } - return s.Flags + return s.Flags() } // SymbolTable @@ -93,10 +113,10 @@ const ( ) func SymbolName(symbol *Symbol) string { - if symbol.ValueDeclaration != nil && IsPrivateIdentifierClassElementDeclaration(symbol.ValueDeclaration) { - return symbol.ValueDeclaration.Name().Text() + if symbol.ValueDeclaration() != nil && IsPrivateIdentifierClassElementDeclaration(symbol.ValueDeclaration()) { + return symbol.ValueDeclaration().Name().Text() } - return symbol.Name + return symbol.Name() } // EscapeAllInternalSymbolNames replaces internal symbol name markers ("\xFE") with "__". diff --git a/tsc/internal/ast/symbol_test.go b/tsc/internal/ast/symbol_test.go new file mode 100644 index 0000000000000..23a97c61cc0d0 --- /dev/null +++ b/tsc/internal/ast/symbol_test.go @@ -0,0 +1,113 @@ +package ast_test + +import ( + "reflect" + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/ast" + "gotest.tools/v3/assert" +) + +func TestSymbolFieldsArePrivate(t *testing.T) { + t.Parallel() + for field := range reflect.TypeFor[ast.Symbol]().Fields() { + assert.Assert(t, !field.IsExported(), "Symbol field %s must be private", field.Name) + } +} + +func TestSymbolAccessors(t *testing.T) { + t.Parallel() + symbol := &ast.Symbol{} + assert.Equal(t, symbol.Flags(), ast.SymbolFlagsNone) + assert.Equal(t, symbol.CheckFlags(), ast.CheckFlags(0)) + assert.Equal(t, symbol.Name(), "") + assert.Assert(t, symbol.Declarations() == nil) + assert.Assert(t, symbol.ValueDeclaration() == nil) + assert.Assert(t, symbol.Members() == nil) + assert.Assert(t, symbol.Exports() == nil) + assert.Assert(t, symbol.Parent() == nil) + assert.Assert(t, symbol.ExportSymbol() == nil) + + declaration := &ast.Node{} + otherDeclaration := &ast.Node{} + member := &ast.Symbol{} + export := &ast.Symbol{} + parent := &ast.Symbol{} + exportSymbol := &ast.Symbol{} + declarations := []*ast.Node{declaration} + members := ast.SymbolTable{"member": member} + exports := ast.SymbolTable{"export": export} + + symbol.SetFlags(ast.SymbolFlagsClass | ast.SymbolFlagsTransient) + symbol.SetCheckFlags(ast.CheckFlagsReadonly) + symbol.SetName("C") + symbol.SetDeclarations(declarations) + symbol.SetValueDeclaration(declaration) + symbol.SetMembers(members) + symbol.SetExports(exports) + symbol.SetParent(parent) + symbol.SetExportSymbol(exportSymbol) + + assert.Equal(t, symbol.Flags(), ast.SymbolFlagsClass|ast.SymbolFlagsTransient) + assert.Equal(t, symbol.CheckFlags(), ast.CheckFlagsReadonly) + assert.Equal(t, symbol.Name(), "C") + assert.Equal(t, symbol.Declarations()[0], declaration) + assert.Equal(t, symbol.ValueDeclaration(), declaration) + assert.Equal(t, symbol.Members()["member"], member) + assert.Equal(t, symbol.Exports()["export"], export) + assert.Equal(t, symbol.Parent(), parent) + assert.Equal(t, symbol.ExportSymbol(), exportSymbol) + + declarations[0] = otherDeclaration + assert.Equal(t, symbol.Declarations()[0], otherDeclaration) + symbol.Declarations()[0] = declaration + assert.Equal(t, declarations[0], declaration) + symbol.Members()["added"] = export + assert.Equal(t, members["added"], export) + symbol.Exports()["added"] = member + assert.Equal(t, exports["added"], member) + + symbol.SetFlags(ast.SymbolFlagsNone) + symbol.SetCheckFlags(0) + symbol.SetName("") + symbol.SetDeclarations(nil) + symbol.SetValueDeclaration(nil) + symbol.SetMembers(nil) + symbol.SetExports(nil) + symbol.SetParent(nil) + symbol.SetExportSymbol(nil) + + assert.Equal(t, symbol.Flags(), ast.SymbolFlagsNone) + assert.Equal(t, symbol.CheckFlags(), ast.CheckFlags(0)) + assert.Equal(t, symbol.Name(), "") + assert.Assert(t, symbol.Declarations() == nil) + assert.Assert(t, symbol.ValueDeclaration() == nil) + assert.Assert(t, symbol.Members() == nil) + assert.Assert(t, symbol.Exports() == nil) + assert.Assert(t, symbol.Parent() == nil) + assert.Assert(t, symbol.ExportSymbol() == nil) +} + +func TestSymbolTableInitialization(t *testing.T) { + t.Parallel() + symbol := &ast.Symbol{} + member := &ast.Symbol{} + export := &ast.Symbol{} + + members := ast.GetMembers(symbol) + members["member"] = member + assert.Equal(t, symbol.Members()["member"], member) + assert.Equal(t, ast.GetMembers(symbol)["member"], member) + + exports := ast.GetExports(symbol) + exports["export"] = export + assert.Equal(t, symbol.Exports()["export"], export) + assert.Equal(t, ast.GetExports(symbol)["export"], export) + + symbol.SetMembers(nil) + symbol.SetExports(nil) + assert.Assert(t, ast.GetMembers(symbol) != nil) + assert.Assert(t, ast.GetExports(symbol) != nil) + assert.Equal(t, len(symbol.Members()), 0) + assert.Equal(t, len(symbol.Exports()), 0) +} diff --git a/tsc/internal/ast/utilities.go b/tsc/internal/ast/utilities.go index 2644758d7372b..5f282bc1b2cc7 100644 --- a/tsc/internal/ast/utilities.go +++ b/tsc/internal/ast/utilities.go @@ -51,11 +51,11 @@ func GetSymbolTable(data *SymbolTable) SymbolTable { } func GetMembers(symbol *Symbol) SymbolTable { - return GetSymbolTable(&symbol.Members) + return GetSymbolTable(&symbol.members) } func GetExports(symbol *Symbol) SymbolTable { - return GetSymbolTable(&symbol.Exports) + return GetSymbolTable(&symbol.exports) } func GetLocals(container *Node) SymbolTable { @@ -2567,7 +2567,7 @@ func IsParameterLike(node *Node) bool { } func GetDeclarationOfKind(symbol *Symbol, kind Kind) *Node { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if declaration.Kind == kind { return declaration } @@ -2689,8 +2689,8 @@ func IsNonLocalAlias(symbol *Symbol, excludes SymbolFlags) bool { if symbol == nil { return false } - return symbol.Flags&(SymbolFlagsAlias|excludes) == SymbolFlagsAlias || - symbol.Flags&SymbolFlagsAlias != 0 && symbol.Flags&SymbolFlagsAssignment != 0 + return symbol.Flags()&(SymbolFlagsAlias|excludes) == SymbolFlagsAlias || + symbol.Flags()&SymbolFlagsAlias != 0 && symbol.Flags()&SymbolFlagsAssignment != 0 } // An alias symbol is created by one of the following declarations: @@ -3023,7 +3023,7 @@ func IsExclusivelyTypeOnlyImportOrExport(node *Node) bool { } func GetClassLikeDeclarationOfSymbol(symbol *Symbol) *Node { - return core.Find(symbol.Declarations, IsClassLike) + return core.Find(symbol.Declarations(), IsClassLike) } func IsCallLikeExpression(node *Node) bool { @@ -3642,7 +3642,7 @@ func IsExternalModuleAugmentation(node *Node) bool { } func GetSourceFileOfModule(module *Symbol) *SourceFile { - declaration := module.ValueDeclaration + declaration := module.ValueDeclaration() if declaration == nil { declaration = GetNonAugmentationDeclaration(module) } @@ -3650,7 +3650,7 @@ func GetSourceFileOfModule(module *Symbol) *SourceFile { } func GetNonAugmentationDeclaration(symbol *Symbol) *Node { - return core.Find(symbol.Declarations, func(d *Node) bool { + return core.Find(symbol.Declarations(), func(d *Node) bool { return !IsExternalModuleAugmentation(d) && !IsGlobalScopeAugmentation(d) }) } diff --git a/tsc/internal/binder/binder.go b/tsc/internal/binder/binder.go index adf0b17af211f..9f446e653a680 100644 --- a/tsc/internal/binder/binder.go +++ b/tsc/internal/binder/binder.go @@ -131,8 +131,8 @@ func bindSourceFile(file *ast.SourceFile) { func (b *Binder) newSymbol(flags ast.SymbolFlags, name string) *ast.Symbol { b.symbolCount++ result := b.symbolArena.New() - result.Flags = flags - result.Name = name + result.SetFlags(flags) + result.SetName(name) return result } @@ -193,35 +193,35 @@ func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol symbol = b.newSymbol(ast.SymbolFlagsNone, name) symbolTable[name] = symbol if isReplaceableByMethod { - symbol.Flags |= ast.SymbolFlagsReplaceableByMethod + symbol.SetFlags(symbol.Flags() | ast.SymbolFlagsReplaceableByMethod) } - } else if isReplaceableByMethod && symbol.Flags&ast.SymbolFlagsReplaceableByMethod == 0 { + } else if isReplaceableByMethod && symbol.Flags()&ast.SymbolFlagsReplaceableByMethod == 0 { // A symbol already exists, so don't add this as a declaration. return symbol - } else if symbol.Flags&excludes != 0 { - if symbol.Flags&ast.SymbolFlagsReplaceableByMethod != 0 { + } else if symbol.Flags()&excludes != 0 { + if symbol.Flags()&ast.SymbolFlagsReplaceableByMethod != 0 { // Javascript constructor-declared symbols can be discarded in favor of // prototype symbols like methods. symbol = b.newSymbol(ast.SymbolFlagsNone, name) symbolTable[name] = symbol - } else if !(includes&ast.SymbolFlagsVariable != 0 && symbol.Flags&ast.SymbolFlagsAssignment != 0 || - includes&ast.SymbolFlagsAssignment != 0 && symbol.Flags&ast.SymbolFlagsVariable != 0) { + } 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. // Report errors every position with duplicate declaration // Report errors on previous encountered declarations var message *diagnostics.Message - if symbol.Flags&ast.SymbolFlagsBlockScopedVariable != 0 { + if symbol.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 { message = diagnostics.Cannot_redeclare_block_scoped_variable_0 } else { message = diagnostics.Duplicate_identifier_0 } messageNeedsName := true - if symbol.Flags&ast.SymbolFlagsEnum != 0 || includes&ast.SymbolFlagsEnum != 0 { + if symbol.Flags()&ast.SymbolFlagsEnum != 0 || includes&ast.SymbolFlagsEnum != 0 { message = diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations messageNeedsName = false } multipleDefaultExports := false - if len(symbol.Declarations) != 0 { + if len(symbol.Declarations()) != 0 { // If the current node is a default export of some sort, then check if // there are any other default exports that we need to error on. // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. @@ -234,7 +234,7 @@ func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol // Error on multiple export default in the following case: // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) - if len(symbol.Declarations) != 0 && ast.IsExportAssignment(node) && !node.AsExportAssignment().IsExportEquals { + if len(symbol.Declarations()) != 0 && ast.IsExportAssignment(node) && !node.AsExportAssignment().IsExportEquals { message = diagnostics.A_module_cannot_have_multiple_default_exports messageNeedsName = false multipleDefaultExports = true @@ -251,11 +251,11 @@ func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol } else { diag = b.createDiagnosticForNode(declarationName, message) } - if ast.IsTypeAliasDeclaration(node) && ast.NodeIsMissing(node.Type()) && ast.HasSyntacticModifier(node, ast.ModifierFlagsExport) && symbol.Flags&(ast.SymbolFlagsAlias|ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 { + if ast.IsTypeAliasDeclaration(node) && ast.NodeIsMissing(node.Type()) && ast.HasSyntacticModifier(node, ast.ModifierFlagsExport) && symbol.Flags()&(ast.SymbolFlagsAlias|ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 { // export type T; - may have meant export type { T }? diag.AddRelatedInfo(b.createDiagnosticForNode(node, diagnostics.Did_you_mean_0, "export type { "+node.AsTypeAliasDeclaration().Name().Text()+" }")) } - for index, declaration := range symbol.Declarations { + for index, declaration := range symbol.Declarations() { var decl *ast.Node = ast.GetNameOfDeclaration(declaration) if decl == nil { decl = declaration @@ -279,17 +279,17 @@ func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol // the symbol as a full accessor such that all subsequent declarations are considered conflicting. This // for example ensures that a get accessor followed by a non-accessor followed by a set accessor with the // same name are all marked as duplicates. - if symbol.Flags&ast.SymbolFlagsAccessor != 0 && symbol.Flags&ast.SymbolFlagsAccessor != includes&ast.SymbolFlagsAccessor { - symbol.Flags |= ast.SymbolFlagsAccessor + if symbol.Flags()&ast.SymbolFlagsAccessor != 0 && symbol.Flags()&ast.SymbolFlagsAccessor != includes&ast.SymbolFlagsAccessor { + symbol.SetFlags(symbol.Flags() | ast.SymbolFlagsAccessor) } symbol = b.newSymbol(ast.SymbolFlagsNone, name) } } } b.addDeclarationToSymbol(symbol, node, includes) - if symbol.Parent == nil { - symbol.Parent = parent - } else if symbol.Parent != parent { + if symbol.Parent() == nil { + symbol.SetParent(parent) + } else if symbol.Parent() != parent { panic("Existing symbol parent should match new one") } return symbol @@ -408,7 +408,7 @@ func (b *Binder) declareModuleMember(node *ast.Node, symbolFlags ast.SymbolFlags exportKind = ast.SymbolFlagsExportValue } local := b.declareSymbol(ast.GetLocals(container), nil /*parent*/, node, exportKind, symbolExcludes) - local.ExportSymbol = b.declareSymbol(ast.GetExports(container.Symbol()), container.Symbol(), node, symbolFlags, symbolExcludes) + local.SetExportSymbol(b.declareSymbol(ast.GetExports(container.Symbol()), container.Symbol(), node, symbolFlags, symbolExcludes)) node.ExportableData().LocalSymbol = local return local } @@ -763,7 +763,7 @@ func (b *Binder) bindSourceFileIfExternalModule() { b.bindSourceFileAsExternalModule() // Create symbol equivalent for the module.exports = {} originalSymbol := b.file.Symbol - b.declareSymbol(ast.GetSymbolTable(&b.file.Symbol.Exports), b.file.Symbol, b.file.AsNode(), ast.SymbolFlagsProperty, ast.SymbolFlagsAll) + b.declareSymbol(ast.GetExports(b.file.Symbol), b.file.Symbol, b.file.AsNode(), ast.SymbolFlagsProperty, ast.SymbolFlagsAll) b.file.Symbol = originalSymbol } } @@ -802,15 +802,15 @@ func (b *Binder) bindModuleDeclaration(node *ast.Node) { if state != ast.ModuleInstanceStateNonInstantiated { symbol := node.Symbol() // if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only - constEnumOnlyModule := (symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) == 0) && + constEnumOnlyModule := (symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) == 0) && // Current must be `const enum` only state == ast.ModuleInstanceStateConstEnumOnly && // Can't have been set to 'false' in a previous merged symbol. ('undefined' OK) !b.notConstEnumOnlyModules.Has(symbol) if constEnumOnlyModule { - symbol.Flags |= ast.SymbolFlagsConstEnumOnlyModule + symbol.SetFlags(symbol.Flags() | ast.SymbolFlagsConstEnumOnlyModule) } else { - symbol.Flags &^= ast.SymbolFlagsConstEnumOnlyModule + symbol.SetFlags(symbol.Flags() &^ ast.SymbolFlagsConstEnumOnlyModule) b.notConstEnumOnlyModules.Add(symbol) } } @@ -967,12 +967,12 @@ func (b *Binder) bindClassLikeDeclaration(node *ast.Node) { // module might have an exported variable called 'prototype'. We can't allow that as // that would clash with the built-in 'prototype' for the class. prototypeSymbol := b.newSymbol(ast.SymbolFlagsProperty|ast.SymbolFlagsPrototype, "prototype") - symbolExport := ast.GetExports(symbol)[prototypeSymbol.Name] + symbolExport := ast.GetExports(symbol)[prototypeSymbol.Name()] if symbolExport != nil { - b.errorOnNode(symbolExport.Declarations[0], diagnostics.Duplicate_identifier_0, ast.SymbolName(prototypeSymbol)) + b.errorOnNode(symbolExport.Declarations()[0], diagnostics.Duplicate_identifier_0, ast.SymbolName(prototypeSymbol)) } - ast.GetExports(symbol)[prototypeSymbol.Name] = prototypeSymbol - prototypeSymbol.Parent = symbol + ast.GetExports(symbol)[prototypeSymbol.Name()] = prototypeSymbol + prototypeSymbol.SetParent(symbol) } func (b *Binder) bindPropertyOrMethodOrAccessor(node *ast.Node, symbolFlags ast.SymbolFlags, symbolExcludes ast.SymbolFlags) { @@ -1000,8 +1000,8 @@ func (b *Binder) bindFunctionOrConstructorType(node *ast.Node) { b.addDeclarationToSymbol(symbol, node, ast.SymbolFlagsSignature) typeLiteralSymbol := b.newSymbol(ast.SymbolFlagsTypeLiteral, ast.InternalSymbolNameType) b.addDeclarationToSymbol(typeLiteralSymbol, node, ast.SymbolFlagsTypeLiteral) - typeLiteralSymbol.Members = make(ast.SymbolTable) - typeLiteralSymbol.Members[symbol.Name] = symbol + typeLiteralSymbol.SetMembers(make(ast.SymbolTable)) + typeLiteralSymbol.Members()[symbol.Name()] = symbol } func (b *Binder) addLateBoundAssignmentDeclarationToSymbol(node *ast.Node, symbol *ast.Symbol) { @@ -1011,7 +1011,7 @@ func (b *Binder) addLateBoundAssignmentDeclarationToSymbol(node *ast.Node, symbo assignmentSymbol = b.newSymbol(ast.SymbolFlagsNone, ast.InternalSymbolNameAssignmentDeclaration) exports[ast.InternalSymbolNameAssignmentDeclaration] = assignmentSymbol } - assignmentSymbol.Declarations = append(assignmentSymbol.Declarations, node) + assignmentSymbol.SetDeclarations(append(assignmentSymbol.Declarations(), node)) } func (b *Binder) bindModuleExportsAssignment(node *ast.Node) { @@ -1043,12 +1043,12 @@ func (b *Binder) bindDeferredExpandoAssignments() { // from the module symbol onto the export= symbol and, if any such exports exist, mark the export= // symbol as a namespace module. func (b *Binder) bindCommonJSTypeExports(moduleSymbol *ast.Symbol) { - moduleExports := moduleSymbol.Exports + moduleExports := moduleSymbol.Exports() if exportEquals := moduleExports[ast.InternalSymbolNameExportEquals]; exportEquals != nil { for _, symbol := range moduleExports { - if symbol.Name != ast.InternalSymbolNameExportEquals && symbol.Flags&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 { - ast.GetExports(exportEquals)[symbol.Name] = symbol - exportEquals.Flags |= ast.SymbolFlagsNamespaceModule + if symbol.Name() != ast.InternalSymbolNameExportEquals && symbol.Flags()&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 { + ast.GetExports(exportEquals)[symbol.Name()] = symbol + exportEquals.SetFlags(exportEquals.Flags() | ast.SymbolFlagsNamespaceModule) } } } @@ -1067,7 +1067,7 @@ func (b *Binder) bindDeferredExpandoAssignment(node *ast.Node) { } else { // We declare expandos only when there are no non-expando declarations for that name. exports := ast.GetExports(symbol) - if existing := exports[b.getDeclarationName(node)]; existing == nil || existing.Flags&ast.SymbolFlagsAssignment != 0 { + if existing := exports[b.getDeclarationName(node)]; existing == nil || existing.Flags()&ast.SymbolFlagsAssignment != 0 { b.declareSymbol(exports, symbol, node, ast.SymbolFlagsProperty|ast.SymbolFlagsAssignment, ast.SymbolFlagsPropertyExcludes) } } @@ -1093,10 +1093,10 @@ func (b *Binder) bindExportsOrObjectDefineProperty(node *ast.Node) { } func getInitializerSymbol(symbol *ast.Symbol) *ast.Symbol { - if symbol == nil || symbol.ValueDeclaration == nil { + if symbol == nil || symbol.ValueDeclaration() == nil { return nil } - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() // For an assignment 'fn.xxx = ...', where 'fn' is a previously declared function or a previously // declared const variable initialized with a function expression or arrow function, we add expando // property declarations to the function's symbol. This also applies to class expressions in JS files, @@ -1237,7 +1237,7 @@ func (b *Binder) getInferTypeContainer(node *ast.Node) *ast.Node { func (b *Binder) bindAnonymousDeclaration(node *ast.Node, symbolFlags ast.SymbolFlags, name string) { symbol := b.newSymbol(symbolFlags, name) if symbolFlags&(ast.SymbolFlagsEnumMember|ast.SymbolFlagsClassMember) != 0 { - symbol.Parent = b.container.Symbol() + symbol.SetParent(b.container.Symbol()) } b.addDeclarationToSymbol(symbol, node, symbolFlags) } @@ -1282,9 +1282,9 @@ func (b *Binder) lookupEntity(node *ast.Node, container *ast.Node) *ast.Symbol { } return nil } - if symbol := getInitializerSymbol(b.lookupEntity(node.Expression(), container)); symbol != nil && symbol.Exports != nil { + if symbol := getInitializerSymbol(b.lookupEntity(node.Expression(), container)); symbol != nil && symbol.Exports() != nil { if name := ast.GetElementOrPropertyAccessName(node); name != nil { - return symbol.Exports[name.Text()] + return symbol.Exports()[name.Text()] } } return nil @@ -1293,11 +1293,11 @@ func (b *Binder) lookupEntity(node *ast.Node, container *ast.Node) *ast.Symbol { func (b *Binder) lookupName(name string, container *ast.Node) *ast.Symbol { if localsContainer := container.LocalsContainerData(); localsContainer != nil { if local := localsContainer.Locals[name]; local != nil { - return core.OrElse(local.ExportSymbol, local) + return core.OrElse(local.ExportSymbol(), local) } } if declaration := container.DeclarationData(); declaration != nil && declaration.Symbol != nil { - return declaration.Symbol.Exports[name] + return declaration.Symbol.Exports()[name] } return nil } @@ -1628,15 +1628,15 @@ func (b *Binder) declareCommonJSVariable(name string) { locals := ast.GetLocals(b.file.AsNode()) if locals[name] == nil { symbol := b.newSymbol(ast.SymbolFlagsFunctionScopedVariable|ast.SymbolFlagsModuleExports, name) - symbol.Declarations = b.newSingleDeclaration(b.file.AsNode()) - symbol.ValueDeclaration = symbol.Declarations[0] + symbol.SetDeclarations(b.newSingleDeclaration(b.file.AsNode())) + symbol.SetValueDeclaration(symbol.Declarations()[0]) if name == "module" { exportsProperty := b.newSymbol(ast.SymbolFlagsModuleExports|ast.SymbolFlagsProperty, "exports") - exportsProperty.Declarations = symbol.Declarations - exportsProperty.ValueDeclaration = symbol.ValueDeclaration - exportsProperty.Parent = symbol - symbol.Members = make(ast.SymbolTable, 1) - symbol.Members["exports"] = exportsProperty + exportsProperty.SetDeclarations(symbol.Declarations()) + exportsProperty.SetValueDeclaration(symbol.ValueDeclaration()) + exportsProperty.SetParent(symbol) + symbol.SetMembers(make(ast.SymbolTable, 1)) + symbol.Members()["exports"] = exportsProperty } locals[name] = symbol } @@ -2539,16 +2539,16 @@ func (b *Binder) addToContainerChain(next *ast.Node) { } func (b *Binder) addDeclarationToSymbol(symbol *ast.Symbol, node *ast.Node, symbolFlags ast.SymbolFlags) { - symbol.Flags |= symbolFlags + symbol.SetFlags(symbol.Flags() | symbolFlags) node.DeclarationData().Symbol = symbol - if symbol.Declarations == nil { - symbol.Declarations = b.newSingleDeclaration(node) + if symbol.Declarations() == nil { + symbol.SetDeclarations(b.newSingleDeclaration(node)) } else { - symbol.Declarations = core.AppendIfUnique(symbol.Declarations, node) + symbol.SetDeclarations(core.AppendIfUnique(symbol.Declarations(), node)) } // On merge of const enum module with class or function, reset const enum only flag (namespaces will already recalculate) - if symbol.Flags&ast.SymbolFlagsConstEnumOnlyModule != 0 && symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) != 0 { - symbol.Flags &^= ast.SymbolFlagsConstEnumOnlyModule + if symbol.Flags()&ast.SymbolFlagsConstEnumOnlyModule != 0 && symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsClass|ast.SymbolFlagsRegularEnum) != 0 { + symbol.SetFlags(symbol.Flags() &^ ast.SymbolFlagsConstEnumOnlyModule) b.notConstEnumOnlyModules.Add(symbol) } if symbolFlags&ast.SymbolFlagsValue != 0 { @@ -2557,13 +2557,13 @@ func (b *Binder) addDeclarationToSymbol(symbol *ast.Symbol, node *ast.Node, symb } func SetValueDeclaration(symbol *ast.Symbol, node *ast.Node) { - valueDeclaration := symbol.ValueDeclaration + valueDeclaration := symbol.ValueDeclaration() if valueDeclaration == nil || isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node) || valueDeclaration.Kind != node.Kind && isEffectiveModuleDeclaration(valueDeclaration) { // Non-assignment declarations take precedence over assignment declarations and // non-namespace declarations take precedence over namespace declarations. - symbol.ValueDeclaration = node + symbol.SetValueDeclaration(node) } } @@ -2758,7 +2758,7 @@ func getOptionalSymbolFlagForNode(node *ast.Node) ast.SymbolFlags { } func isFunctionSymbol(symbol *ast.Symbol) bool { - d := symbol.ValueDeclaration + d := symbol.ValueDeclaration() if d != nil { if ast.IsFunctionDeclaration(d) { return true diff --git a/tsc/internal/binder/nameresolver.go b/tsc/internal/binder/nameresolver.go index 5c1928ec4b6fd..f525a4414b867 100644 --- a/tsc/internal/binder/nameresolver.go +++ b/tsc/internal/binder/nameresolver.go @@ -63,10 +63,10 @@ loop: // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be - if meaning&result.Flags&ast.SymbolFlagsType != 0 && lastLocation.Kind != ast.KindJSDoc { + if meaning&result.Flags()&ast.SymbolFlagsType != 0 && lastLocation.Kind != ast.KindJSDoc { // type parameters are visible in parameter list, return type and type parameter list. // Synthetic fake scopes are added for signatures so type parameters are accessible from them. - useResult = result.Flags&ast.SymbolFlagsTypeParameter != 0 && + useResult = result.Flags()&ast.SymbolFlagsTypeParameter != 0 && (lastLocation.Flags&ast.NodeFlagsSynthesized != 0 || lastLocation == location.Type() || lastLocation.Kind == ast.KindParameter || @@ -74,18 +74,18 @@ loop: lastLocation.Kind == ast.KindJSDocReturnTag || lastLocation.Kind == ast.KindTypeParameter) } - if meaning&result.Flags&ast.SymbolFlagsVariable != 0 { + if meaning&result.Flags()&ast.SymbolFlagsVariable != 0 { // expression inside parameter will lookup as normal variable scope when targeting es2015+ if r.useOuterVariableScopeInParameter(result, location, lastLocation) { useResult = false - } else if result.Flags&ast.SymbolFlagsFunctionScopedVariable != 0 { + } else if result.Flags()&ast.SymbolFlagsFunctionScopedVariable != 0 { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.Kind == ast.KindParameter || lastLocation.Flags&ast.NodeFlagsSynthesized != 0 || - lastLocation == location.Type() && ast.FindAncestor(result.ValueDeclaration, ast.IsParameterDeclaration) != nil + lastLocation == location.Type() && ast.FindAncestor(result.ValueDeclaration(), ast.IsParameterDeclaration) != nil } } } else if location.Kind == ast.KindConditionalType { @@ -114,14 +114,14 @@ loop: if moduleSymbol == nil { break } - moduleExports := moduleSymbol.Exports + moduleExports := moduleSymbol.Exports() if ast.IsSourceFile(location) || (ast.IsModuleDeclaration(location) && location.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsGlobalScopeAugmentation(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. result = moduleExports[ast.InternalSymbolNameDefault] if result != nil { localSymbol := GetLocalSymbolForExportDefault(result) - if localSymbol != nil && result.Flags&meaning != 0 && localSymbol.Name == name { + if localSymbol != nil && result.Flags()&meaning != 0 && localSymbol.Name() == name { break loop } result = nil @@ -138,13 +138,13 @@ loop: // an alias. If we used &, we'd be throwing out symbols that have non alias aspects, // which is not the desired behavior. moduleExport := moduleExports[name] - if moduleExport != nil && moduleExport.Flags == ast.SymbolFlagsAlias && (ast.GetDeclarationOfKind(moduleExport, ast.KindExportSpecifier) != nil || ast.GetDeclarationOfKind(moduleExport, ast.KindNamespaceExport) != nil) { + if moduleExport != nil && moduleExport.Flags() == ast.SymbolFlagsAlias && (ast.GetDeclarationOfKind(moduleExport, ast.KindExportSpecifier) != nil || ast.GetDeclarationOfKind(moduleExport, ast.KindNamespaceExport) != nil) { break } } if name != ast.InternalSymbolNameDefault { if result = r.lookup(moduleExports, name, meaning&ast.SymbolFlagsModuleMember); result != nil { - if ast.IsSourceFile(location) && location.AsSourceFile().CommonJSModuleIndicator != nil && result.Flags&ast.SymbolFlagsType == 0 { + if ast.IsSourceFile(location) && location.AsSourceFile().CommonJSModuleIndicator != nil && result.Flags()&ast.SymbolFlagsType == 0 { result = nil } else { break loop @@ -156,12 +156,12 @@ loop: if enumSymbol == nil { break } - result = r.lookup(enumSymbol.Exports, name, meaning&ast.SymbolFlagsEnumMember) + result = r.lookup(enumSymbol.Exports(), name, meaning&ast.SymbolFlagsEnumMember) if result != nil { - if nameNotFoundMessage != nil && r.CompilerOptions.GetIsolatedModules() && location.Flags&ast.NodeFlagsAmbient == 0 && ast.GetSourceFileOfNode(location) != ast.GetSourceFileOfNode(result.ValueDeclaration) { + if nameNotFoundMessage != nil && r.CompilerOptions.GetIsolatedModules() && location.Flags&ast.NodeFlagsAmbient == 0 && ast.GetSourceFileOfNode(location) != ast.GetSourceFileOfNode(result.ValueDeclaration()) { isolatedModulesLikeFlagName := core.IfElse(r.CompilerOptions.VerbatimModuleSyntax == core.TSTrue, "verbatimModuleSyntax", "isolatedModules") r.error(originalLocation, diagnostics.Cannot_access_0_from_another_file_without_qualification_when_1_is_enabled_Use_2_instead, - name, isolatedModulesLikeFlagName, enumSymbol.Name+"."+name) + name, isolatedModulesLikeFlagName, enumSymbol.Name()+"."+name) } break loop } @@ -176,7 +176,7 @@ loop: } } case ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration: - result = r.lookup(r.getSymbolOfDeclaration(location).Members, name, meaning&ast.SymbolFlagsType) + result = r.lookup(r.getSymbolOfDeclaration(location).Members(), name, meaning&ast.SymbolFlagsType) if result != nil { if !isTypeParameterSymbolDeclaredInContainer(result, location) { // ignore type parameters not declared in this container @@ -205,7 +205,7 @@ loop: if lastLocation == location.Expression() && ast.IsHeritageClause(location.Parent) && location.Parent.AsHeritageClause().Token == ast.KindExtendsKeyword { container := location.Parent.Parent if ast.IsClassLike(container) { - result = r.lookup(r.getSymbolOfDeclaration(container).Members, name, meaning&ast.SymbolFlagsType) + result = r.lookup(r.getSymbolOfDeclaration(container).Members(), name, meaning&ast.SymbolFlagsType) if result != nil { if nameNotFoundMessage != nil { r.error(originalLocation, diagnostics.Base_class_expressions_cannot_reference_class_type_parameters) @@ -225,7 +225,7 @@ loop: grandparent = location.Parent.Parent if ast.IsClassLike(grandparent) || ast.IsInterfaceDeclaration(grandparent) { // A reference to this grandparent's type parameters would be an error - result = r.lookup(r.getSymbolOfDeclaration(grandparent).Members, name, meaning&ast.SymbolFlagsType) + result = r.lookup(r.getSymbolOfDeclaration(grandparent).Members(), name, meaning&ast.SymbolFlagsType) if result != nil { if nameNotFoundMessage != nil { r.error(originalLocation, diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type) @@ -354,7 +354,7 @@ loop: func (r *NameResolver) useOuterVariableScopeInParameter(result *ast.Symbol, location *ast.Node, lastLocation *ast.Node) bool { if ast.IsParameterDeclaration(lastLocation) { body := location.Body() - if body != nil && result.ValueDeclaration != nil && result.ValueDeclaration.Pos() >= body.Pos() && result.ValueDeclaration.End() <= body.End() { + if body != nil && result.ValueDeclaration() != nil && result.ValueDeclaration().Pos() >= body.Pos() && result.ValueDeclaration().End() <= body.End() { // check for several cases where we introduce temporaries that require moving the name/initializer of the parameter to the body // - static field in a class expression // - optional chaining pre-es2020 @@ -431,7 +431,7 @@ func (r *NameResolver) lookup(symbols ast.SymbolTable, name string, meaning ast. if meaning != 0 { symbol := symbols[name] if symbol != nil { - if symbol.Flags&meaning != 0 { + if symbol.Flags()&meaning != 0 { return symbol } } @@ -442,16 +442,18 @@ func (r *NameResolver) lookup(symbols ast.SymbolTable, name string, meaning ast. func (r *NameResolver) argumentsSymbol() *ast.Symbol { if r.ArgumentsSymbol == nil { // Default implementation synthesizes a transient symbol for `arguments` - r.ArgumentsSymbol = &ast.Symbol{Name: "arguments", Flags: ast.SymbolFlagsProperty | ast.SymbolFlagsTransient} + r.ArgumentsSymbol = &ast.Symbol{} + r.ArgumentsSymbol.SetName("arguments") + r.ArgumentsSymbol.SetFlags(ast.SymbolFlagsProperty | ast.SymbolFlagsTransient) } return r.ArgumentsSymbol } func GetLocalSymbolForExportDefault(symbol *ast.Symbol) *ast.Symbol { - if !isExportDefaultSymbol(symbol) || len(symbol.Declarations) == 0 { + if !isExportDefaultSymbol(symbol) || len(symbol.Declarations()) == 0 { return nil } - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { localSymbol := decl.LocalSymbol() if localSymbol != nil { return localSymbol @@ -461,7 +463,7 @@ func GetLocalSymbolForExportDefault(symbol *ast.Symbol) *ast.Symbol { } func isExportDefaultSymbol(symbol *ast.Symbol) bool { - return symbol != nil && len(symbol.Declarations) > 0 && ast.HasSyntacticModifier(symbol.Declarations[0], ast.ModifierFlagsDefault) + return symbol != nil && len(symbol.Declarations()) > 0 && ast.HasSyntacticModifier(symbol.Declarations()[0], ast.ModifierFlagsDefault) } func getIsDeferredContext(location *ast.Node, lastLocation *ast.Node) bool { @@ -483,7 +485,7 @@ func getIsDeferredContext(location *ast.Node, lastLocation *ast.Node) bool { } func isTypeParameterSymbolDeclaredInContainer(symbol *ast.Symbol, container *ast.Node) bool { - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { if decl.Kind == ast.KindTypeParameter { parent := decl.Parent if parent == container { diff --git a/tsc/internal/binder/referenceresolver.go b/tsc/internal/binder/referenceresolver.go index fbc6e5a24d7ff..c7e606328f505 100644 --- a/tsc/internal/binder/referenceresolver.go +++ b/tsc/internal/binder/referenceresolver.go @@ -65,7 +65,7 @@ func (r *referenceResolver) getParentOfSymbol(symbol *ast.Symbol) *ast.Symbol { if r.hooks.GetParentOfSymbol != nil { return r.hooks.GetParentOfSymbol(symbol) } - return symbol.Parent + return symbol.Parent() } return nil } @@ -132,7 +132,7 @@ func (r *referenceResolver) isTypeOnlyAliasDeclaration(symbol *ast.Symbol) bool } func (r *referenceResolver) getDeclarationOfAliasSymbol(symbol *ast.Symbol) *ast.Declaration { - return core.FindLast(symbol.Declarations, ast.IsAliasSymbolDeclaration) + return core.FindLast(symbol.Declarations(), ast.IsAliasSymbolDeclaration) } func (r *referenceResolver) getExportSymbolOfValueSymbolIfExported(symbol *ast.Symbol) *ast.Symbol { @@ -140,8 +140,8 @@ func (r *referenceResolver) getExportSymbolOfValueSymbolIfExported(symbol *ast.S if r.hooks.GetExportSymbolOfValueSymbolIfExported != nil { return r.hooks.GetExportSymbolOfValueSymbolIfExported(symbol) } - if symbol.Flags&ast.SymbolFlagsExportValue != 0 && symbol.ExportSymbol != nil { - symbol = symbol.ExportSymbol + if symbol.Flags()&ast.SymbolFlagsExportValue != 0 && symbol.ExportSymbol() != nil { + symbol = symbol.ExportSymbol() } return r.getMergedSymbol(symbol) } @@ -155,20 +155,20 @@ func (r *referenceResolver) GetReferencedExportContainer(node *ast.IdentifierNod // declaration if it contains an exported member with the same name. startInDeclarationContainer := node.Parent != nil && (node.Parent.Kind == ast.KindModuleDeclaration || node.Parent.Kind == ast.KindEnumDeclaration) && node == node.Parent.Name() if symbol := r.getReferencedValueSymbol(node, startInDeclarationContainer); symbol != nil { - if symbol.Flags&ast.SymbolFlagsExportValue != 0 { + if symbol.Flags()&ast.SymbolFlagsExportValue != 0 { // If we reference an exported entity within the same module declaration, then whether // we prefix depends on the kind of entity. SymbolFlags.ExportHasLocal encompasses all the // kinds that we do NOT prefix. - exportSymbol := r.getMergedSymbol(symbol.ExportSymbol) - if !prefixLocals && exportSymbol.Flags&ast.SymbolFlagsExportHasLocal != 0 && exportSymbol.Flags&ast.SymbolFlagsVariable == 0 { + exportSymbol := r.getMergedSymbol(symbol.ExportSymbol()) + if !prefixLocals && exportSymbol.Flags()&ast.SymbolFlagsExportHasLocal != 0 && exportSymbol.Flags()&ast.SymbolFlagsVariable == 0 { return nil } symbol = exportSymbol } parentSymbol := r.getParentOfSymbol(symbol) if parentSymbol != nil { - if parentSymbol.Flags&ast.SymbolFlagsValueModule != 0 && parentSymbol.ValueDeclaration != nil && parentSymbol.ValueDeclaration.Kind == ast.KindSourceFile { - symbolFile := parentSymbol.ValueDeclaration.AsSourceFile() + if parentSymbol.Flags()&ast.SymbolFlagsValueModule != 0 && parentSymbol.ValueDeclaration() != nil && parentSymbol.ValueDeclaration().Kind == ast.KindSourceFile { + symbolFile := parentSymbol.ValueDeclaration().AsSourceFile() referenceFile := ast.GetSourceFileOfNode(node) // If `node` accesses an export and that export isn't in the same file, then symbol is a namespace export, so return nil. symbolIsUmdExport := symbolFile != referenceFile @@ -201,7 +201,7 @@ func (r *referenceResolver) GetReferencedImportDeclaration(node *ast.IdentifierN func (r *referenceResolver) GetReferencedValueDeclaration(node *ast.IdentifierNode) *ast.Declaration { if symbol := r.getReferencedValueSymbol(node, false /*startInDeclarationContainer*/); symbol != nil { - return r.getExportSymbolOfValueSymbolIfExported(symbol).ValueDeclaration + return r.getExportSymbolOfValueSymbolIfExported(symbol).ValueDeclaration() } return nil } @@ -210,7 +210,7 @@ func (r *referenceResolver) GetReferencedValueDeclarations(node *ast.IdentifierN var declarations []*ast.Declaration if symbol := r.getReferencedValueSymbol(node, false /*startInDeclarationContainer*/); symbol != nil { symbol = r.getExportSymbolOfValueSymbolIfExported(symbol) - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { switch declaration.Kind { case ast.KindVariableDeclaration, ast.KindParameter, @@ -258,5 +258,5 @@ func (r *referenceResolver) GetReferencedMemberValueDeclaration(node *ast.Node) if s == nil { return nil } - return r.getExportSymbolOfValueSymbolIfExported(s).ValueDeclaration + return r.getExportSymbolOfValueSymbolIfExported(s).ValueDeclaration() } diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 7bcc8d6cf2ced..2cb6f0e4ff686 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -970,8 +970,8 @@ func NewChecker(program Program, tracer *Tracer) (*Checker, *sync.Mutex) { c.errorTypes = make(map[CacheHashKey]*Type) c.moduleSymbols = make(map[*ast.Node]*ast.Symbol) c.globalThisSymbol = c.newSymbolEx(ast.SymbolFlagsModule, "globalThis", ast.CheckFlagsReadonly) - c.globalThisSymbol.Exports = c.globals - c.globals[c.globalThisSymbol.Name] = c.globalThisSymbol + c.globalThisSymbol.SetExports(c.globals) + c.globals[c.globalThisSymbol.Name()] = c.globalThisSymbol c.resolveName = c.createNameResolver().Resolve c.resolveNameForSymbolSuggestion = c.createNameResolverForSuggestion().Resolve c.tupleTypes = make(map[CacheHashKey]*Type) @@ -1203,7 +1203,7 @@ func (c *Checker) getGlobalTypeAliasSymbol(name string, arity int, reportErrors c.getDeclaredTypeOfSymbol(symbol) if len(c.typeAliasLinks.Get(symbol).typeParameters) != arity { if reportErrors { - decl := core.Find(symbol.Declarations, ast.IsTypeAliasDeclaration) + decl := core.Find(symbol.Declarations(), ast.IsTypeAliasDeclaration) c.error(decl, diagnostics.Global_type_0_must_have_1_type_parameter_s, ast.SymbolName(symbol), arity) } return nil @@ -1212,7 +1212,7 @@ func (c *Checker) getGlobalTypeAliasSymbol(name string, arity int, reportErrors } func (c *Checker) GetTypeAliasTypeParameters(symbol *ast.Symbol) []*Type { - if symbol.Flags&ast.SymbolFlagsTypeAlias == 0 { + if symbol.Flags()&ast.SymbolFlagsTypeAlias == 0 { panic("Attempted to fetch type alias parameters for non-type-alias symbol") } c.getDeclaredTypeOfSymbol(symbol) @@ -1222,7 +1222,7 @@ func (c *Checker) GetTypeAliasTypeParameters(symbol *ast.Symbol) []*Type { func (c *Checker) getGlobalType(name string, arity int, reportErrors bool) *Type { symbol := c.getGlobalSymbol(name, ast.SymbolFlagsType, core.IfElse(reportErrors, diagnostics.Cannot_find_global_type_0, nil)) if symbol != nil { - if symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { + if symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { t := c.getDeclaredTypeOfSymbol(symbol) if len(t.AsInterfaceType().TypeParameters()) == arity { return t @@ -1241,7 +1241,7 @@ func (c *Checker) getGlobalType(name string, arity int, reportErrors bool) *Type } func getGlobalTypeDeclaration(symbol *ast.Symbol) *ast.Declaration { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { switch declaration.Kind { case ast.KindClassDeclaration, ast.KindInterfaceDeclaration, ast.KindEnumDeclaration, ast.KindTypeAliasDeclaration: return declaration @@ -1313,14 +1313,14 @@ func (c *Checker) initializeChecker() { if !ast.IsExternalOrCommonJSModule(file) { // It is an error for a non-external-module (i.e. script) to declare its own `globalThis`. if fileGlobalThisSymbol := file.Locals["globalThis"]; fileGlobalThisSymbol != nil { - for _, d := range fileGlobalThisSymbol.Declarations { + for _, d := range fileGlobalThisSymbol.Declarations() { c.addDiagnostic(NewDiagnosticForNode(d, diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, "globalThis")) } } for _, symbol := range file.Locals { // We defer merging of global ambient module declarations since they may require other global symbols // and types to be resolved. See https://github.com/microsoft/TypeScript/tsc/issues/2953. - if symbol.Flags&ast.SymbolFlagsModule != 0 && ast.IsAmbientModuleSymbolName(symbol.Name) { + if symbol.Flags()&ast.SymbolFlagsModule != 0 && ast.IsAmbientModuleSymbolName(symbol.Name()) { ambientModuleSymbols = append(ambientModuleSymbols, symbol) } else { c.mergeGlobalSymbol(symbol) @@ -1397,14 +1397,14 @@ func (c *Checker) initializeChecker() { } func (c *Checker) mergeGlobalSymbol(symbol *ast.Symbol) { - globalSymbol := c.globals[symbol.Name] + globalSymbol := c.globals[symbol.Name()] var merged *ast.Symbol if globalSymbol != nil { merged = c.mergeSymbol(globalSymbol, symbol, false /*unidirectional*/) } else { merged = c.getMergedSymbol(symbol) } - c.globals[symbol.Name] = merged + c.globals[symbol.Name()] = merged } // Pattern ambient modules are merged together if they have the same pattern and identical import attributes type. @@ -1428,8 +1428,8 @@ func (c *Checker) mergePatternAmbientModules() { } } for _, module := range c.patternAmbientModules { - if _, ok := c.globals[module.Symbol.Name]; ok { - c.globals[module.Symbol.Name] = c.getMergedSymbol(module.Symbol) + if _, ok := c.globals[module.Symbol.Name()]; ok { + c.globals[module.Symbol.Name()] = c.getMergedSymbol(module.Symbol) } } c.patternAmbientModules = grouped @@ -1438,14 +1438,14 @@ func (c *Checker) mergePatternAmbientModules() { func (c *Checker) mergeModuleAugmentation(moduleName *ast.Node) { moduleNode := moduleName.Parent moduleAugmentation := moduleNode.AsModuleDeclaration() - if moduleAugmentation.Symbol.Declarations[0] != moduleNode { + if moduleAugmentation.Symbol.Declarations()[0] != moduleNode { // this is a combined symbol for multiple augmentations within the same file. // its symbol already has accumulated information for all declarations // so we need to add it just once - do the work only for first declaration return } if ast.IsGlobalScopeAugmentation(moduleNode) { - c.mergeSymbolTable(c.globals, moduleAugmentation.Symbol.Exports, false /*unidirectional*/, nil /*parent*/) + c.mergeSymbolTable(c.globals, moduleAugmentation.Symbol.Exports(), false /*unidirectional*/, nil /*parent*/) } else { // find a module that about to be augmented // do not validate names of augmentations that are defined in ambient context @@ -1460,7 +1460,7 @@ func (c *Checker) mergeModuleAugmentation(moduleName *ast.Node) { } // obtain item referenced by 'export=' mainModule = c.resolveExternalModuleSymbol(mainModule, false /*dontResolveAlias*/) - if mainModule.Flags&ast.SymbolFlagsNamespace != 0 { + if mainModule.Flags()&ast.SymbolFlagsNamespace != 0 { // If we're merging an augmentation to a pattern ambient module, we want to // perform the merge unidirectionally from the augmentation ('a.foo') to // the pattern ('*.foo'), so that 'getMergedSymbol()' on a.foo gives you @@ -1474,11 +1474,11 @@ func (c *Checker) mergeModuleAugmentation(moduleName *ast.Node) { ast.GetSymbolTable(&c.patternAmbientModuleAugmentations)[moduleName.Text()] = merged ast.GetSymbolTable(&c.patternAmbientModuleAugmentationTargets)[moduleName.Text()] = mainModule } else { - if mainModule.Exports[ast.InternalSymbolNameExportStar] != nil && len(moduleAugmentation.Symbol.Exports) != 0 { + if mainModule.Exports()[ast.InternalSymbolNameExportStar] != nil && len(moduleAugmentation.Symbol.Exports()) != 0 { // We may need to merge the module augmentation's exports into the target symbols of the resolved exports resolvedExports := c.getResolvedMembersOrExportsOfSymbol(mainModule, MembersOrExportsResolutionKindResolvedExports) - for key, value := range moduleAugmentation.Symbol.Exports { - if resolvedExports[key] != nil && mainModule.Exports[key] == nil { + for key, value := range moduleAugmentation.Symbol.Exports() { + if resolvedExports[key] != nil && mainModule.Exports()[key] == nil { c.mergeSymbol(resolvedExports[key], value, false /*unidirectional*/) } } @@ -1493,10 +1493,10 @@ func (c *Checker) mergeModuleAugmentation(moduleName *ast.Node) { } func (c *Checker) addUndefinedToGlobalsOrErrorOnRedeclaration() { - name := c.undefinedSymbol.Name + name := c.undefinedSymbol.Name() targetSymbol := c.globals[name] if targetSymbol != nil { - for _, declaration := range targetSymbol.Declarations { + for _, declaration := range targetSymbol.Declarations() { if !ast.IsTypeDeclaration(declaration) { c.addDiagnostic(createDiagnosticForNode(declaration, diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, name)) } @@ -1632,14 +1632,14 @@ func (c *Checker) onFailedToResolveSymbol(errorLocation *ast.Node, name string, } // Then spelling suggestions suggestion := c.getSuggestedSymbolForNonexistentSymbol(errorLocation, name, meaning) - if suggestion != nil && !(suggestion.ValueDeclaration != nil && ast.IsAmbientModule(suggestion.ValueDeclaration) && ast.IsGlobalScopeAugmentation(suggestion.ValueDeclaration)) { + if suggestion != nil && !(suggestion.ValueDeclaration() != nil && ast.IsAmbientModule(suggestion.ValueDeclaration()) && ast.IsGlobalScopeAugmentation(suggestion.ValueDeclaration())) { suggestionName := c.symbolToString(suggestion) isUncheckedJS := c.isUncheckedJSSuggestion(errorLocation, suggestion, false /*excludeClasses*/) message := core.IfElse(meaning == ast.SymbolFlagsNamespace, diagnostics.Cannot_find_namespace_0_Did_you_mean_1, core.IfElse(isUncheckedJS, diagnostics.Could_not_find_name_0_Did_you_mean_1, diagnostics.Cannot_find_name_0_Did_you_mean_1)) diagnostic := NewDiagnosticForNode(errorLocation, message, declarationName, suggestionName) - if suggestion.ValueDeclaration != nil { - diagnostic.AddRelatedInfo(NewDiagnosticForNode(suggestion.ValueDeclaration, diagnostics.X_0_is_declared_here, suggestionName)) + if suggestion.ValueDeclaration() != nil { + diagnostic.AddRelatedInfo(NewDiagnosticForNode(suggestion.ValueDeclaration(), diagnostics.X_0_is_declared_here, suggestionName)) } c.addErrorOrSuggestion(!isUncheckedJS, diagnostic) return @@ -1765,7 +1765,7 @@ func (c *Checker) maybeMappedType(node *ast.Node, symbol *ast.Symbol) bool { func (c *Checker) checkAndReportErrorForUsingValueAsType(errorLocation *ast.Node, name string, meaning ast.SymbolFlags) bool { if meaning&(ast.SymbolFlagsType & ^ast.SymbolFlagsNamespace) != 0 { symbol := c.resolveSymbol(c.resolveName(errorLocation, name, ^ast.SymbolFlagsType&ast.SymbolFlagsValue, nil /*nameNotFoundMessage*/, false /*isUse*/, false /*excludeGlobals*/)) - if symbol != nil && symbol.Flags&ast.SymbolFlagsNamespace == 0 { + if symbol != nil && symbol.Flags()&ast.SymbolFlagsNamespace == 0 { c.error(errorLocation, diagnostics.X_0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0, name) return true } @@ -1796,8 +1796,8 @@ var primitiveTypeAliasSuggestions = sync.OnceValue(func() map[string]*ast.Symbol {"symbol", "Symbol"}, } { sym := &ast.Symbol{} - sym.Flags = ast.SymbolFlagsTypeAlias | ast.SymbolFlagsTransient - sym.Name = e.primitive + sym.SetFlags(ast.SymbolFlagsTypeAlias | ast.SymbolFlagsTransient) + sym.SetName(e.primitive) result[e.builtin] = sym } return result @@ -1846,12 +1846,12 @@ func (c *Checker) getSpellingSuggestionForName(name string, symbols iter.Seq[*as if len(candidateName) == 0 || candidateName[0] == '"' || candidateName[0] == '\xFE' { return "" } - if candidate.Flags&meaning != 0 { + if candidate.Flags()&meaning != 0 { return candidateName } - if candidate.Flags&ast.SymbolFlagsAlias != 0 { + if candidate.Flags()&ast.SymbolFlagsAlias != 0 { alias := c.tryResolveAlias(candidate) - if alias != nil && alias.Flags&meaning != 0 { + if alias != nil && alias.Flags()&meaning != 0 { return candidateName } } @@ -1861,7 +1861,7 @@ func (c *Checker) getSpellingSuggestionForName(name string, symbols iter.Seq[*as } func (c *Checker) onSuccessfullyResolvedSymbol(errorLocation *ast.Node, result *ast.Symbol, meaning ast.SymbolFlags, lastLocation *ast.Node, associatedDeclarationForContainingInitializerOrBindingName *ast.Node, withinDeferredContext bool) { - name := result.Name + name := result.Name() isInExternalModule := lastLocation != nil && ast.IsSourceFile(lastLocation) && ast.IsExternalOrCommonJSModule(lastLocation.AsSourceFile()) // Only check for block-scoped variable if we have an error location and are looking for the // name with variable meaning @@ -1876,14 +1876,14 @@ func (c *Checker) onSuccessfullyResolvedSymbol(errorLocation *ast.Node, result * // we want to check for block-scoped if errorLocation != nil && (meaning&ast.SymbolFlagsBlockScopedVariable != 0 || meaning&(ast.SymbolFlagsClass|ast.SymbolFlagsEnum) != 0 && meaning&ast.SymbolFlagsValue == ast.SymbolFlagsValue) { exportOrLocalSymbol := c.getExportSymbolOfValueSymbolIfExported(result) - if exportOrLocalSymbol.Flags&(ast.SymbolFlagsBlockScopedVariable|ast.SymbolFlagsClass|ast.SymbolFlagsEnum) != 0 { + if exportOrLocalSymbol.Flags()&(ast.SymbolFlagsBlockScopedVariable|ast.SymbolFlagsClass|ast.SymbolFlagsEnum) != 0 { c.checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation) } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if isInExternalModule && (meaning&ast.SymbolFlagsValue) == ast.SymbolFlagsValue && errorLocation.Flags&ast.NodeFlagsJSDoc == 0 { merged := c.getMergedSymbol(result) - if len(merged.Declarations) != 0 && core.Every(merged.Declarations, func(d *ast.Node) bool { + if len(merged.Declarations()) != 0 && core.Every(merged.Declarations(), func(d *ast.Node) bool { return ast.IsNamespaceExportDeclaration(d) || ast.IsSourceFile(d) && d.AsSourceFile().GlobalExports != nil }) { c.errorOrSuggestion(c.compilerOptions.AllowUmdGlobalAccess != core.TSTrue, errorLocation, diagnostics.X_0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name) @@ -1896,11 +1896,11 @@ func (c *Checker) onSuccessfullyResolvedSymbol(errorLocation *ast.Node, result * // A parameter initializer or binding pattern initializer within a parameter cannot refer to itself if candidate == c.getSymbolOfDeclaration(associatedDeclarationForContainingInitializerOrBindingName) { c.error(errorLocation, diagnostics.Parameter_0_cannot_reference_itself, scanner.DeclarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.Name())) - } else if candidate.ValueDeclaration != nil && candidate.ValueDeclaration.Pos() > associatedDeclarationForContainingInitializerOrBindingName.Pos() && root.Parent.Locals() != nil && c.getSymbol(root.Parent.Locals(), candidate.Name, meaning) == candidate { + } else if candidate.ValueDeclaration() != nil && candidate.ValueDeclaration().Pos() > associatedDeclarationForContainingInitializerOrBindingName.Pos() && root.Parent.Locals() != nil && c.getSymbol(root.Parent.Locals(), candidate.Name(), meaning) == candidate { c.error(errorLocation, diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, scanner.DeclarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.Name()), scanner.DeclarationNameToString(errorLocation)) } } - if errorLocation != nil && meaning&ast.SymbolFlagsValue != 0 && result.Flags&ast.SymbolFlagsAlias != 0 && result.Flags&ast.SymbolFlagsValue == 0 && !ast.IsValidTypeOnlyAliasUseSite(errorLocation) { + if errorLocation != nil && meaning&ast.SymbolFlagsValue != 0 && result.Flags()&ast.SymbolFlagsAlias != 0 && result.Flags()&ast.SymbolFlagsValue == 0 && !ast.IsValidTypeOnlyAliasUseSite(errorLocation) { typeOnlyDeclaration := c.getTypeOnlyAliasDeclarationEx(result, ast.SymbolFlagsValue) if typeOnlyDeclaration != nil { message := core.IfElse(ast.NodeKindIs(typeOnlyDeclaration, ast.KindExportSpecifier, ast.KindExportDeclaration, ast.KindNamespaceExport), @@ -1918,7 +1918,7 @@ func (c *Checker) onSuccessfullyResolvedSymbol(errorLocation *ast.Node, result * nonValueSymbol = c.getSymbol(lastLocation.Locals(), name, ^ast.SymbolFlagsValue) } if nonValueSymbol != nil { - importDecl := core.Find(nonValueSymbol.Declarations, func(d *ast.Node) bool { + importDecl := core.Find(nonValueSymbol.Declarations(), func(d *ast.Node) bool { return ast.NodeKindIs(d, ast.KindImportSpecifier, ast.KindImportClause, ast.KindNamespaceImport, ast.KindImportEqualsDeclaration) }) if importDecl != nil && !ast.IsTypeOnlyImportDeclaration(importDecl) { @@ -1929,13 +1929,13 @@ func (c *Checker) onSuccessfullyResolvedSymbol(errorLocation *ast.Node, result * } func (c *Checker) checkResolvedBlockScopedVariable(result *ast.Symbol, errorLocation *ast.Node) { - debug.Assert(result.Flags&ast.SymbolFlagsBlockScopedVariable != 0 || result.Flags&ast.SymbolFlagsClass != 0 || result.Flags&ast.SymbolFlagsEnum != 0) - if result.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsFunctionScopedVariable|ast.SymbolFlagsAssignment) != 0 && result.Flags&ast.SymbolFlagsClass != 0 { + debug.Assert(result.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 || result.Flags()&ast.SymbolFlagsClass != 0 || result.Flags()&ast.SymbolFlagsEnum != 0) + if result.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsFunctionScopedVariable|ast.SymbolFlagsAssignment) != 0 && result.Flags()&ast.SymbolFlagsClass != 0 { // constructor functions aren't block scoped return } // Block-scoped variables cannot be used before their definition - declaration := core.Find(result.Declarations, func(d *ast.Node) bool { + declaration := core.Find(result.Declarations(), func(d *ast.Node) bool { return ast.IsBlockOrCatchScoped(d) || ast.IsClassLike(d) || ast.IsEnumDeclaration(d) }) if declaration == nil { @@ -1944,14 +1944,14 @@ func (c *Checker) checkResolvedBlockScopedVariable(result *ast.Symbol, errorLoca if declaration.Flags&ast.NodeFlagsAmbient == 0 && !c.isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation) { var diagnostic *ast.Diagnostic declarationName := scanner.DeclarationNameToString(ast.GetNameOfDeclaration(declaration)) - if result.Flags&ast.SymbolFlagsBlockScopedVariable != 0 { + if result.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 { diagnostic = c.error(errorLocation, diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName) - } else if result.Flags&ast.SymbolFlagsClass != 0 { + } else if result.Flags()&ast.SymbolFlagsClass != 0 { diagnostic = c.error(errorLocation, diagnostics.Class_0_used_before_its_declaration, declarationName) - } else if result.Flags&ast.SymbolFlagsRegularEnum != 0 { + } else if result.Flags()&ast.SymbolFlagsRegularEnum != 0 { diagnostic = c.error(errorLocation, diagnostics.Enum_0_used_before_its_declaration, declarationName) } else { - debug.Assert(result.Flags&ast.SymbolFlagsConstEnum != 0) + debug.Assert(result.Flags()&ast.SymbolFlagsConstEnum != 0) if c.compilerOptions.GetIsolatedModules() { diagnostic = c.error(errorLocation, diagnostics.Enum_0_used_before_its_declaration, declarationName) } @@ -2174,7 +2174,7 @@ func isPropertyImmediatelyReferencedWithinDeclaration(declaration *ast.Node, usa // Return the type-only declaration node (if any) for the given alias symbol (non-transitively) func (c *Checker) getTypeOnlyAliasDeclaration(symbol *ast.Symbol) *ast.Node { - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { c.resolveAlias(symbol) return c.aliasSymbolLinks.Get(symbol).typeOnlyDeclaration } @@ -2184,7 +2184,7 @@ func (c *Checker) getTypeOnlyAliasDeclaration(symbol *ast.Symbol) *ast.Node { // Return the first type-only alias declaration node (if any) in the resolution chain that affects // the symbol for the given meaning func (c *Checker) getTypeOnlyAliasDeclarationEx(symbol *ast.Symbol, meaning ast.SymbolFlags) *ast.Node { - for symbol.Flags&ast.SymbolFlagsAlias != 0 && symbol.Flags&meaning == 0 { + for symbol.Flags()&ast.SymbolFlagsAlias != 0 && symbol.Flags()&meaning == 0 { resolved := c.resolveAlias(symbol) links := c.aliasSymbolLinks.Get(symbol) if links.typeOnlyDeclaration != nil { @@ -2196,7 +2196,7 @@ func (c *Checker) getTypeOnlyAliasDeclarationEx(symbol *ast.Symbol, meaning ast. } func (c *Checker) getImmediateAliasedSymbol(symbol *ast.Symbol) *ast.Symbol { - debug.Assert(symbol.Flags&ast.SymbolFlagsAlias != 0, "Should only get Alias here.") + debug.Assert(symbol.Flags()&ast.SymbolFlagsAlias != 0, "Should only get Alias here.") links := c.aliasSymbolLinks.Get(symbol) if links.immediateTarget == nil { node := c.getDeclarationOfAliasSymbol(symbol) @@ -2220,10 +2220,10 @@ func (c *Checker) getSymbol(symbols ast.SymbolTable, name string, meaning ast.Sy if meaning&ast.SymbolFlagsAll != 0 { symbol := c.getMergedSymbol(symbols[name]) if symbol != nil { - if symbol.Flags&meaning != 0 { + if symbol.Flags()&meaning != 0 { return symbol } - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { targetFlags := c.getSymbolFlags(symbol) // `targetFlags` will be `SymbolFlags.All` if an error occurred in alias resolution; this avoids cascading errors if targetFlags&meaning != 0 { @@ -2605,7 +2605,7 @@ func (c *Checker) resolveJSDocMemberName(name *ast.Node) *ast.Symbol { if ast.IsQualifiedName(name) { if symbol := c.resolveJSDocMemberName(name.AsQualifiedName().Left); symbol != nil { var t *Type - if symbol.Flags&ast.SymbolFlagsValue != 0 { + if symbol.Flags()&ast.SymbolFlagsValue != 0 { proto := c.getPropertyOfType(c.getTypeOfSymbol(symbol), "prototype") if proto != nil { t = c.getTypeOfSymbol(proto) @@ -3056,8 +3056,8 @@ func (c *Checker) checkTypeReferenceOrImport(node *ast.Node) { } symbol := c.getResolvedSymbolOrNil(node) if symbol != nil { - if core.Some(symbol.Declarations, func(d *ast.Node) bool { return ast.IsTypeDeclaration(d) && c.IsDeprecatedDeclaration(d) }) { - c.addDeprecatedSuggestion(c.getDeprecatedSuggestionNode(node), symbol.Declarations, symbol.Name) + if core.Some(symbol.Declarations(), func(d *ast.Node) bool { return ast.IsTypeDeclaration(d) && c.IsDeprecatedDeclaration(d) }) { + c.addDeprecatedSuggestion(c.getDeprecatedSuggestionNode(node), symbol.Declarations(), symbol.Name()) } } } @@ -3195,7 +3195,7 @@ func (c *Checker) checkObjectTypeForDuplicateDeclarations(node *ast.Node, checkP var privateNames map[string]int nodeInAmbientContext := node.Flags&ast.NodeFlagsAmbient != 0 checkPropertyOrAccessor := func(symbol *ast.Symbol, kind int, isStatic bool) { - if len(symbol.Declarations) > 1 { + if len(symbol.Declarations()) > 1 { var names map[string]int if isStatic { if staticNames == nil { @@ -3208,16 +3208,16 @@ func (c *Checker) checkObjectTypeForDuplicateDeclarations(node *ast.Node, checkP } names = instanceNames } - state := names[symbol.Name] + state := names[symbol.Name()] switch { case state == 0: // On first occurrence just record the kind - names[symbol.Name] = kind + names[symbol.Name()] = kind case state == 1 || state == 2 && kind != 2: // Error on second property or combination of property and accessor - c.reportDuplicateMemberErrors(node, symbol.Name, true, isStatic, diagnostics.Duplicate_identifier_0) + c.reportDuplicateMemberErrors(node, symbol.Name(), true, isStatic, diagnostics.Duplicate_identifier_0) // Record that errors have been reported - names[symbol.Name] = 3 + names[symbol.Name()] = 3 } } } @@ -3232,8 +3232,8 @@ func (c *Checker) checkObjectTypeForDuplicateDeclarations(node *ast.Node, checkP symbol := c.getSymbolOfDeclaration(member) isStatic := ast.HasStaticModifier(member) // In non-ambient contexts, check that static members are not named 'prototype'. - if !nodeInAmbientContext && isStatic && symbol != nil && symbol.Name == "prototype" { - c.error(member.Name(), diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1, symbol.Name, c.symbolToString(c.getSymbolOfDeclaration(node))) + if !nodeInAmbientContext && isStatic && symbol != nil && symbol.Name() == "prototype" { + c.error(member.Name(), diagnostics.Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1, symbol.Name(), c.symbolToString(c.getSymbolOfDeclaration(node))) } // Check that this object type declaration doesn't contain multiple declarations of the same property, // or accessor and property declarations with the same name. @@ -3245,14 +3245,14 @@ func (c *Checker) checkObjectTypeForDuplicateDeclarations(node *ast.Node, checkP // Check that each private identifier is used only for instance members or only for static members. It is an // error for an instance and a static member to have the same private identifier. if checkPrivateNames && member.Name() != nil && ast.IsPrivateIdentifier(member.Name()) { - if flags := privateNames[symbol.Name]; flags != 3 { + if flags := privateNames[symbol.Name()]; flags != 3 { flags |= core.IfElse(ast.IsStatic(member), 2, 1) if privateNames == nil { privateNames = make(map[string]int) } - privateNames[symbol.Name] = flags + privateNames[symbol.Name()] = flags if flags == 3 { - c.reportDuplicateMemberErrors(node, symbol.Name, false, false, diagnostics.Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name) + c.reportDuplicateMemberErrors(node, symbol.Name(), false, false, diagnostics.Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name) } } } @@ -3265,12 +3265,12 @@ func (c *Checker) reportDuplicateMemberErrors(node *ast.Node, name string, check if ast.IsConstructorDeclaration(member) { for _, param := range member.Parameters() { if ast.IsParameterPropertyDeclaration(param, member) && !ast.IsBindingPattern(param.Name()) { - if symbol := c.getSymbolOfDeclaration(param); symbol.Name == name { + if symbol := c.getSymbolOfDeclaration(param); symbol.Name() == name { c.error(param.Name(), message, c.symbolToString(symbol)) } } } - } else if symbol := c.getSymbolOfDeclaration(member); symbol != nil && symbol.Name == name && (!checkStatic || isStatic == ast.IsStatic(member)) { + } else if symbol := c.getSymbolOfDeclaration(member); symbol != nil && symbol.Name() == name && (!checkStatic || isStatic == ast.IsStatic(member)) { c.error(member.Name(), message, c.symbolToString(symbol)) } } @@ -3344,7 +3344,7 @@ func (c *Checker) checkInferType(node *ast.Node) { typeParameterDeclarationNode := node.AsInferTypeNode().TypeParameter c.checkSourceElement(typeParameterDeclarationNode) symbol := c.getSymbolOfDeclaration(typeParameterDeclarationNode) - if len(symbol.Declarations) > 1 { + if len(symbol.Declarations()) > 1 { links := c.declaredTypeLinks.Get(symbol) if !links.typeParametersChecked { links.typeParametersChecked = true @@ -3459,7 +3459,7 @@ func (c *Checker) checkFunctionOrMethodDeclaration(node *ast.Node) { if node.Flags&ast.NodeFlagsJavaScriptFile == 0 { c.checkFunctionOrConstructorSymbol(localSymbol) } - if symbol.Parent != nil { + if symbol.Parent() != nil { // run check on export symbol to check that modifiers agree across all exported declarations c.checkFunctionOrConstructorSymbol(symbol) } @@ -3506,8 +3506,8 @@ func (c *Checker) checkFunctionOrConstructorSymbolWorker(symbol *ast.Symbol) { var bodyDeclaration *ast.Node var lastSeenNonAmbientDeclaration *ast.Node var previousDeclaration *ast.Node - declarations := symbol.Declarations - isConstructor := symbol.Flags&ast.SymbolFlagsConstructor != 0 + declarations := symbol.Declarations() + isConstructor := symbol.Flags()&ast.SymbolFlagsConstructor != 0 duplicateFunctionDeclaration := false multipleConstructorImplementation := false hasNonAmbientClass := false @@ -3687,7 +3687,7 @@ func (c *Checker) checkFunctionOrConstructorSymbolWorker(symbol *ast.Symbol) { c.error(core.OrElse(ast.GetNameOfDeclaration(declaration), declaration), diagnostics.Duplicate_function_implementation) } } - if hasNonAmbientClass && !isConstructor && symbol.Flags&ast.SymbolFlagsFunction != 0 && len(declarations) != 0 { + if hasNonAmbientClass && !isConstructor && symbol.Flags()&ast.SymbolFlagsFunction != 0 && len(declarations) != 0 { var relatedDiagnostics []*ast.Diagnostic for _, declaration := range declarations { if ast.IsClassDeclaration(declaration) { @@ -3703,7 +3703,7 @@ func (c *Checker) checkFunctionOrConstructorSymbolWorker(symbol *ast.Symbol) { diagnostic = diagnostics.Function_with_bodies_can_only_merge_with_classes_that_are_ambient } if diagnostic != nil { - c.error(core.OrElse(ast.GetNameOfDeclaration(declaration), declaration), diagnostic, symbol.Name).SetRelatedInfo(relatedDiagnostics) + c.error(core.OrElse(ast.GetNameOfDeclaration(declaration), declaration), diagnostic, symbol.Name()).SetRelatedInfo(relatedDiagnostics) } } } @@ -3873,7 +3873,7 @@ func (c *Checker) checkTestingKnownTruthyType(condExpr *ast.Node, condType *Type if location != condExpr { t = c.checkExpression(location) } - if t.flags&TypeFlagsEnumLiteral != 0 && ast.IsPropertyAccessExpression(location) && core.OrElse(c.getResolvedSymbolOrNil(location.Expression()), c.unknownSymbol).Flags&ast.SymbolFlagsEnum != 0 { + if t.flags&TypeFlagsEnumLiteral != 0 && ast.IsPropertyAccessExpression(location) && core.OrElse(c.getResolvedSymbolOrNil(location.Expression()), c.unknownSymbol).Flags()&ast.SymbolFlagsEnum != 0 { // EnumLiteral type at condition with known value is always truthy or always falsy, likely an error c.error(location, diagnostics.This_condition_will_always_return_0, core.IfElse(evaluator.IsTruthy(t.AsLiteralType().value), "true", "false")) return @@ -4290,8 +4290,8 @@ func (c *Checker) checkCatchClause(node *ast.Node) { blockLocals := node.AsCatchClause().Block.Locals() if blockLocals != nil { for caughtName := range node.Locals() { - if blockLocal := blockLocals[caughtName]; blockLocal != nil && blockLocal.ValueDeclaration != nil && blockLocal.Flags&ast.SymbolFlagsBlockScopedVariable != 0 { - c.grammarErrorOnNode(blockLocal.ValueDeclaration, diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, caughtName) + if blockLocal := blockLocals[caughtName]; blockLocal != nil && blockLocal.ValueDeclaration() != nil && blockLocal.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 { + c.grammarErrorOnNode(blockLocal.ValueDeclaration(), diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, caughtName) } } } @@ -4392,7 +4392,7 @@ func (c *Checker) checkClassLikeDeclaration(node *ast.Node) { } } } - if !(staticBaseType.symbol != nil && staticBaseType.symbol.Flags&ast.SymbolFlagsClass != 0) && baseConstructorType.flags&TypeFlagsTypeVariable == 0 { + if !(staticBaseType.symbol != nil && staticBaseType.symbol.Flags()&ast.SymbolFlagsClass != 0) && baseConstructorType.flags&TypeFlagsTypeVariable == 0 { // When the static base type is a "class-like" constructor function (but not actually a class), we verify // that all instantiated base constructor signatures return the same type. constructors := c.getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.TypeArguments(), baseTypeNode) @@ -4418,7 +4418,7 @@ func (c *Checker) checkClassLikeDeclaration(node *ast.Node) { t := c.getReducedType(c.getTypeFromTypeNode(typeRefNode)) if !c.isErrorType(t) { if c.isValidBaseType(t) { - genericDiag := core.IfElse(t.symbol != nil && t.symbol.Flags&ast.SymbolFlagsClass != 0, + genericDiag := core.IfElse(t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsClass != 0, diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass, diagnostics.Class_0_incorrectly_implements_interface_1) baseWithThis := c.getTypeWithThisArgument(t, classType.AsInterfaceType().thisType, false) @@ -4486,7 +4486,7 @@ func (c *Checker) checkClassForStaticPropertyNameConflicts(node *ast.Node) { // Check that type parameter lists are identical across multiple declarations func (c *Checker) checkTypeParameterListsIdentical(symbol *ast.Symbol) { - if len(symbol.Declarations) == 1 { + if len(symbol.Declarations()) == 1 { return } links := c.declaredTypeLinks.Get(symbol) @@ -4508,7 +4508,7 @@ func (c *Checker) checkTypeParameterListsIdentical(symbol *ast.Symbol) { } func (c *Checker) getClassOrInterfaceDeclarationsOfSymbol(symbol *ast.Symbol) []*ast.Node { - return core.Filter(symbol.Declarations, func(d *ast.Node) bool { + return core.Filter(symbol.Declarations(), func(d *ast.Node) bool { return ast.IsClassDeclaration(d) || ast.IsInterfaceDeclaration(d) }) } @@ -4526,7 +4526,7 @@ func (c *Checker) areTypeParametersIdentical(declarations []*ast.Node, targetPar target := targetParameters[i] // If the type parameter node does not have the same name as the resolved type // parameter at this position, we report an error. - if source.Name().Text() != target.symbol.Name { + if source.Name().Text() != target.symbol.Name() { return false } // If the type parameter node does not have an identical constraintNode as the resolved @@ -4565,9 +4565,9 @@ func (c *Checker) issueMemberSpecificError(node *ast.Node, typeWithThis *Type, b if ast.IsStatic(member) { continue } - if declaredProp := c.getSymbolOfDeclaration(member); declaredProp != nil && declaredProp.Name != ast.InternalSymbolNameComputed { - prop := c.getPropertyOfType(typeWithThis, declaredProp.Name) - baseProp := c.getPropertyOfType(baseWithThis, declaredProp.Name) + if declaredProp := c.getSymbolOfDeclaration(member); declaredProp != nil && declaredProp.Name() != ast.InternalSymbolNameComputed { + prop := c.getPropertyOfType(typeWithThis, declaredProp.Name()) + baseProp := c.getPropertyOfType(baseWithThis, declaredProp.Name()) if prop != nil && baseProp != nil { var diags []*ast.Diagnostic if !c.checkTypeAssignableToEx(c.getTypeOfSymbol(prop), c.getTypeOfSymbol(baseProp), core.OrElse(member.Name(), member), nil /*headMessage*/, &diags) { @@ -4624,10 +4624,10 @@ func (c *Checker) checkKindsOfPropertyMemberOverrides(t *Type, baseType *Type) { basePropertyCheck: for _, baseProperty := range c.getPropertiesOfType(baseType) { base := c.getTargetSymbol(baseProperty) - if base.Flags&ast.SymbolFlagsPrototype != 0 { + if base.Flags()&ast.SymbolFlagsPrototype != 0 { continue } - baseSymbol := c.getPropertyOfObjectType(t, base.Name) + baseSymbol := c.getPropertyOfObjectType(t, base.Name()) if baseSymbol == nil { continue } @@ -4651,7 +4651,7 @@ basePropertyCheck: if otherBaseType == baseType { continue } - if baseSymbol := c.getPropertyOfObjectType(otherBaseType, base.Name); baseSymbol != nil && base != c.getTargetSymbol(baseSymbol) { + if baseSymbol := c.getPropertyOfObjectType(otherBaseType, base.Name()); baseSymbol != nil && base != c.getTargetSymbol(baseSymbol) { // Derived property exists elsewhere. continue basePropertyCheck } @@ -4677,12 +4677,12 @@ basePropertyCheck: continue } var errorMessage *diagnostics.Message - basePropertyFlags := base.Flags & ast.SymbolFlagsPropertyOrAccessor - derivedPropertyFlags := derived.Flags & ast.SymbolFlagsPropertyOrAccessor + basePropertyFlags := base.Flags() & ast.SymbolFlagsPropertyOrAccessor + derivedPropertyFlags := derived.Flags() & ast.SymbolFlagsPropertyOrAccessor if basePropertyFlags != 0 && derivedPropertyFlags != 0 { // property/accessor is overridden with property/accessor - if base.CheckFlags&ast.CheckFlagsMapped != 0 || - derived.ValueDeclaration != nil && ast.IsBinaryExpression(derived.ValueDeclaration) || + if base.CheckFlags()&ast.CheckFlagsMapped != 0 || + derived.ValueDeclaration() != nil && ast.IsBinaryExpression(derived.ValueDeclaration()) || c.arePropertiesAbstractOrInterface(base, baseDeclarationFlags) { // when the base property is abstract or from an interface, base/derived flags don't need to match // for intersection properties, this must be true of *any* of the declarations, for others it must be true of *all* @@ -4695,37 +4695,37 @@ basePropertyCheck: errorMessage := core.IfElse(overriddenInstanceProperty, diagnostics.X_0_is_defined_as_an_accessor_in_class_1_but_is_overridden_here_in_2_as_an_instance_property, diagnostics.X_0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor) - c.error(core.OrElse(ast.GetNameOfDeclaration(derived.ValueDeclaration), derived.ValueDeclaration), errorMessage, c.symbolToString(base), c.TypeToString(baseType), c.TypeToString(t)) + c.error(core.OrElse(ast.GetNameOfDeclaration(derived.ValueDeclaration()), derived.ValueDeclaration()), errorMessage, c.symbolToString(base), c.TypeToString(baseType), c.TypeToString(t)) } else if c.compilerOptions.GetUseDefineForClassFields() { - uninitialized := core.Find(derived.Declarations, func(d *ast.Node) bool { + uninitialized := core.Find(derived.Declarations(), func(d *ast.Node) bool { return ast.IsPropertyDeclaration(d) && d.Initializer() == nil }) - if uninitialized != nil && derived.Flags&ast.SymbolFlagsTransient == 0 && baseDeclarationFlags&ast.ModifierFlagsAbstract == 0 && derivedDeclarationFlags&ast.ModifierFlagsAbstract == 0 && !core.Some(derived.Declarations, func(d *ast.Node) bool { + if uninitialized != nil && derived.Flags()&ast.SymbolFlagsTransient == 0 && baseDeclarationFlags&ast.ModifierFlagsAbstract == 0 && derivedDeclarationFlags&ast.ModifierFlagsAbstract == 0 && !core.Some(derived.Declarations(), func(d *ast.Node) bool { return d.Flags&ast.NodeFlagsAmbient != 0 }) { constructor := ast.FindConstructorDeclaration(ast.GetClassLikeDeclarationOfSymbol(t.symbol)) propName := uninitialized.Name() if isExclamationToken(uninitialized.PostfixToken()) || constructor == nil || !ast.IsIdentifier(propName) || !c.strictNullChecks || !c.isPropertyInitializedInConstructor(propName, t, constructor) { errorMessage := diagnostics.Property_0_will_overwrite_the_base_property_in_1_If_this_is_intentional_add_an_initializer_Otherwise_add_a_declare_modifier_or_remove_the_redundant_declaration - c.error(core.OrElse(ast.GetNameOfDeclaration(derived.ValueDeclaration), derived.ValueDeclaration), errorMessage, c.symbolToString(base), c.TypeToString(baseType)) + c.error(core.OrElse(ast.GetNameOfDeclaration(derived.ValueDeclaration()), derived.ValueDeclaration()), errorMessage, c.symbolToString(base), c.TypeToString(baseType)) } } } // correct case continue } else if isPrototypeProperty(base) { - if isPrototypeProperty(derived) || derived.Flags&ast.SymbolFlagsProperty != 0 { + if isPrototypeProperty(derived) || derived.Flags()&ast.SymbolFlagsProperty != 0 { // method is overridden with method or property -- correct case continue } else { errorMessage = diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor } - } else if base.Flags&ast.SymbolFlagsAccessor != 0 { + } else if base.Flags()&ast.SymbolFlagsAccessor != 0 { errorMessage = diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function } else { errorMessage = diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function } - c.error(core.OrElse(ast.GetNameOfDeclaration(derived.ValueDeclaration), derived.ValueDeclaration), errorMessage, c.TypeToString(baseType), c.symbolToString(base), c.TypeToString(t)) + c.error(core.OrElse(ast.GetNameOfDeclaration(derived.ValueDeclaration()), derived.ValueDeclaration()), errorMessage, c.TypeToString(baseType), c.symbolToString(base), c.TypeToString(t)) } } for errorNode, memberInfo := range notImplementedInfo { @@ -4757,10 +4757,10 @@ basePropertyCheck: } func (c *Checker) arePropertiesAbstractOrInterface(base *ast.Symbol, baseDeclarationFlags ast.ModifierFlags) bool { - if base.CheckFlags&ast.CheckFlagsSynthetic != 0 { - return core.Some(base.Declarations, func(d *ast.Node) bool { return c.isPropertyAbstractOrInterface(d, baseDeclarationFlags) }) + if base.CheckFlags()&ast.CheckFlagsSynthetic != 0 { + return core.Some(base.Declarations(), func(d *ast.Node) bool { return c.isPropertyAbstractOrInterface(d, baseDeclarationFlags) }) } - return core.Every(base.Declarations, func(d *ast.Node) bool { return c.isPropertyAbstractOrInterface(d, baseDeclarationFlags) }) + return core.Every(base.Declarations(), func(d *ast.Node) bool { return c.isPropertyAbstractOrInterface(d, baseDeclarationFlags) }) } func (c *Checker) isPropertyAbstractOrInterface(declaration *ast.Node, baseDeclarationFlags ast.ModifierFlags) bool { @@ -4829,7 +4829,7 @@ func (c *Checker) getMemberOverrideModifierStatus(node *ast.Node, member *ast.No func (c *Checker) checkMemberForOverrideModifierWorker(node *ast.Node, staticType *Type, baseStaticType *Type, baseWithThis *Type, t *Type, typeWithThis *Type, memberHasOverrideModifier bool, memberHasAbstractModifier bool, memberIsStatic bool, memberIsParameterProperty bool, member *ast.Symbol, errorNode *ast.Node) MemberOverrideStatus { isJs := ast.IsInJSFile(node) - if memberHasOverrideModifier && member.ValueDeclaration != nil && ast.IsClassElement(member.ValueDeclaration) && member.ValueDeclaration.Name() != nil && c.isNonBindableDynamicName(member.ValueDeclaration.Name()) { + if memberHasOverrideModifier && member.ValueDeclaration() != nil && ast.IsClassElement(member.ValueDeclaration()) && member.ValueDeclaration().Name() != nil && c.isNonBindableDynamicName(member.ValueDeclaration().Name()) { if errorNode != nil { c.error(errorNode, core.IfElse(isJs, diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_its_name_is_dynamic, diagnostics.This_member_cannot_have_an_override_modifier_because_its_name_is_dynamic)) } @@ -4839,8 +4839,8 @@ func (c *Checker) checkMemberForOverrideModifierWorker(node *ast.Node, staticTyp if baseWithThis != nil && (memberHasOverrideModifier || c.compilerOptions.NoImplicitOverride.IsTrue()) { thisType := core.IfElse(memberIsStatic, staticType, typeWithThis) baseType := core.IfElse(memberIsStatic, baseStaticType, baseWithThis) - prop := c.getPropertyOfType(thisType, member.Name) - baseProp := c.getPropertyOfType(baseType, member.Name) + prop := c.getPropertyOfType(thisType, member.Name()) + baseProp := c.getPropertyOfType(baseType, member.Name()) if prop != nil && baseProp == nil && memberHasOverrideModifier { if errorNode != nil { @@ -4854,8 +4854,8 @@ func (c *Checker) checkMemberForOverrideModifierWorker(node *ast.Node, staticTyp return MemberOverrideStatusHasInvalidOverride } - if prop != nil && baseProp != nil && len(baseProp.Declarations) > 0 && c.compilerOptions.NoImplicitOverride.IsTrue() && node.Flags&ast.NodeFlagsAmbient == 0 { - baseHasAbstract := core.Some(baseProp.Declarations, ast.HasAbstractModifier) + if prop != nil && baseProp != nil && len(baseProp.Declarations()) > 0 && c.compilerOptions.NoImplicitOverride.IsTrue() && node.Flags&ast.NodeFlagsAmbient == 0 { + baseHasAbstract := core.Some(baseProp.Declarations(), ast.HasAbstractModifier) if memberHasOverrideModifier { return MemberOverrideStatusNone } @@ -4895,11 +4895,11 @@ func (c *Checker) checkIndexConstraints(t *Type, symbol *ast.Symbol, isStaticInd return } for _, prop := range c.getPropertiesOfObjectType(t) { - if !(isStaticIndex && prop.Flags&ast.SymbolFlagsPrototype != 0) { + if !(isStaticIndex && prop.Flags()&ast.SymbolFlagsPrototype != 0) { c.checkIndexConstraintForProperty(t, prop, c.getLiteralTypeFromProperty(prop, TypeFlagsStringOrNumberLiteralOrUnique, true /*includeNonPublic*/), c.getNonMissingTypeOfSymbol(prop)) } } - typeDeclaration := symbol.ValueDeclaration + typeDeclaration := symbol.ValueDeclaration() if typeDeclaration != nil && ast.IsClassLike(typeDeclaration) { for _, member := range typeDeclaration.Members() { // Only process instance properties against instance index signatures and static properties against static index signatures @@ -4917,7 +4917,7 @@ func (c *Checker) checkIndexConstraints(t *Type, symbol *ast.Symbol, isStaticInd } func (c *Checker) checkIndexConstraintForProperty(t *Type, prop *ast.Symbol, propNameType *Type, propType *Type) { - declaration := prop.ValueDeclaration + declaration := prop.ValueDeclaration() name := ast.GetNameOfDeclaration(declaration) if name != nil && ast.IsPrivateIdentifier(name) { return @@ -4948,7 +4948,7 @@ func (c *Checker) checkIndexConstraintForProperty(t *Type, prop *ast.Symbol, pro // the index signature (i.e. property and index signature are declared in separate inherited interfaces). errorNode := core.OrElse(localPropDeclaration, localIndexDeclaration) if errorNode == nil && interfaceDeclaration != nil && !core.Some(c.getBaseTypes(t), func(base *Type) bool { - return c.getPropertyOfObjectType(base, prop.Name) != nil && c.getIndexTypeOfType(base, info.keyType) != nil + return c.getPropertyOfObjectType(base, prop.Name()) != nil && c.getIndexTypeOfType(base, info.keyType) != nil }) { errorNode = interfaceDeclaration } @@ -5012,11 +5012,11 @@ func (c *Checker) checkTypeForDuplicateIndexSignatures(node *ast.Node) { // 3.7.4: An object type can contain at most one string index signature and one numeric index signature. // 8.5: A class declaration can have at most one string index member declaration and one numeric index member declaration indexSymbol := c.getIndexSymbol(c.getSymbolOfDeclaration(node)) - if indexSymbol == nil || len(indexSymbol.Declarations) <= 1 { + if indexSymbol == nil || len(indexSymbol.Declarations()) <= 1 { return } indexSignatureMap := make(map[*Type][]*ast.Node) - for _, declaration := range indexSymbol.Declarations { + for _, declaration := range indexSymbol.Declarations() { if ast.IsIndexSignatureDeclaration(declaration) { parameters := declaration.Parameters() if len(parameters) == 1 && parameters[0].Type() != nil { @@ -5149,15 +5149,15 @@ func (c *Checker) checkInheritedPropertiesAreIdentical(t *Type, typeNode *ast.No seen := make(map[string]InheritanceInfo) for id, p := range c.resolveDeclaredMembers(t).declaredMembers { if c.isNamedMember(p, id) { - seen[p.Name] = InheritanceInfo{prop: p, containingType: t} + seen[p.Name()] = InheritanceInfo{prop: p, containingType: t} } } identical := true for _, base := range baseTypes { properties := c.getPropertiesOfType(c.getTypeWithThisArgument(base, t.AsInterfaceType().thisType, false)) for _, prop := range properties { - if existing, ok := seen[prop.Name]; !ok { - seen[prop.Name] = InheritanceInfo{prop: prop, containingType: base} + if existing, ok := seen[prop.Name()]; !ok { + seen[prop.Name()] = InheritanceInfo{prop: prop, containingType: base} } else { isInheritedProperty := existing.containingType != t if isInheritedProperty && !c.isPropertyIdenticalTo(existing.prop, prop) { @@ -5197,18 +5197,18 @@ func (c *Checker) checkEnumDeclaration(node *ast.Node) { enumSymbol := c.getSymbolOfDeclaration(node) if links := c.declaredTypeLinks.Get(enumSymbol); !links.enumChecked { links.enumChecked = true - if len(enumSymbol.Declarations) > 1 { + if len(enumSymbol.Declarations()) > 1 { firstEnumDeclaration := ast.GetDeclarationOfKind(enumSymbol, ast.KindEnumDeclaration) enumIsConst := ast.IsEnumConst(firstEnumDeclaration) // check that const is placed\omitted on all enum declarations - for _, decl := range enumSymbol.Declarations { + for _, decl := range enumSymbol.Declarations() { if ast.IsEnumDeclaration(decl) && ast.IsEnumConst(decl) != enumIsConst { c.error(ast.GetNameOfDeclaration(decl), diagnostics.Enum_declarations_must_all_be_const_or_non_const) } } } seenEnumMissingInitialInitializer := false - for _, declaration := range enumSymbol.Declarations { + for _, declaration := range enumSymbol.Declarations() { // return true if we hit a violation of the rule, false otherwise if declaration.Kind != ast.KindEnumDeclaration { continue @@ -5276,7 +5276,7 @@ func (c *Checker) checkModuleDeclaration(node *ast.Node) { c.checkExportsOnMergedDeclarations(node) symbol := c.getSymbolOfDeclaration(node) // The following checks only apply on a non-ambient instantiated module declaration. - if symbol.Flags&ast.SymbolFlagsValueModule != 0 && !inAmbientContext && isInstantiatedModule(node, c.compilerOptions.ShouldPreserveConstEnums()) { + if symbol.Flags()&ast.SymbolFlagsValueModule != 0 && !inAmbientContext && isInstantiatedModule(node, c.compilerOptions.ShouldPreserveConstEnums()) { if c.shouldCheckErasableSyntax(node) { c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled) } @@ -5286,7 +5286,7 @@ func (c *Checker) checkModuleDeclaration(node *ast.Node) { // so for now we will just not allow them in scripts, which is the only place they can merge cross-file. c.error(node.Name(), diagnostics.Namespaces_are_not_allowed_in_global_script_files_when_0_is_enabled_If_this_file_is_not_intended_to_be_a_global_script_set_moduleDetection_to_force_or_add_an_empty_export_statement, c.getIsolatedModulesLikeFlagName()) } - if len(symbol.Declarations) > 1 { + if len(symbol.Declarations()) > 1 { firstNonAmbientClassOrFunc := getFirstNonAmbientClassOrFunctionDeclaration(symbol) if firstNonAmbientClassOrFunc != nil { if ast.GetSourceFileOfNode(node) != ast.GetSourceFileOfNode(firstNonAmbientClassOrFunc) { @@ -5311,7 +5311,7 @@ func (c *Checker) checkModuleDeclaration(node *ast.Node) { // We can detect if augmentation was applied using following rules: // - augmentation for a global scope is always applied // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). - checkBody := isGlobalAugmentation || c.getSymbolOfDeclaration(node).Flags&ast.SymbolFlagsTransient != 0 + checkBody := isGlobalAugmentation || c.getSymbolOfDeclaration(node).Flags()&ast.SymbolFlagsTransient != 0 if checkBody && node.Body() != nil { for _, statement := range node.Body().Statements() { c.checkModuleAugmentationElement(statement) @@ -5357,7 +5357,7 @@ func (c *Checker) getTypeOfModuleImportAttributes(symbol *ast.Symbol) *Type { return t } var result *Type - moduleDecl := core.Find(symbol.Declarations, ast.IsModuleWithStringLiteralName) + moduleDecl := core.Find(symbol.Declarations(), ast.IsModuleWithStringLiteralName) if moduleDecl == nil { result = c.emptyObjectType } else { @@ -5373,7 +5373,7 @@ func isInstantiatedModule(node *ast.Node, preserveConstEnums bool) bool { } func getFirstNonAmbientClassOrFunctionDeclaration(symbol *ast.Symbol) *ast.Node { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if (ast.IsClassDeclaration(declaration) || ast.IsFunctionDeclaration(declaration) && ast.NodeIsPresent(declaration.Body())) && declaration.Flags&ast.NodeFlagsAmbient == 0 { return declaration } @@ -5602,7 +5602,7 @@ func (c *Checker) checkImportAttributesExpression(node *ast.Node) *Type { for _, attribute := range node.AsImportAttributes().Attributes.Nodes { member := c.newSymbol(ast.SymbolFlagsProperty, attribute.Name().Text()) c.valueSymbolLinks.Get(member).resolvedType = c.getRegularTypeOfLiteralType(c.checkExpressionCached(attribute.AsImportAttribute().Value)) - members[member.Name] = member + members[member.Name()] = member } t := c.newAnonymousType(symbol, members, nil, nil, nil) t.objectFlags |= ObjectFlagsObjectLiteral | ObjectFlagsNonInferrableType @@ -5648,7 +5648,7 @@ func (c *Checker) checkImportEqualsDeclaration(node *ast.Node) { if targetFlags&ast.SymbolFlagsValue != 0 { // Target is a value symbol, check that it is not hidden by a local declaration with the same name moduleName := ast.GetFirstIdentifier(moduleReference) - if c.resolveEntityName(moduleName, ast.SymbolFlagsValue|ast.SymbolFlagsNamespace, false, false, nil).Flags&ast.SymbolFlagsNamespace == 0 { + if c.resolveEntityName(moduleName, ast.SymbolFlagsValue|ast.SymbolFlagsNamespace, false, false, nil).Flags()&ast.SymbolFlagsNamespace == 0 { c.error(moduleName, diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, scanner.DeclarationNameToString(moduleName)) } } @@ -5744,7 +5744,7 @@ func (c *Checker) checkExportSpecifier(node *ast.ExportSpecifierNode) { } // find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases) symbol := c.resolveName(exportedName, exportedName.Text(), ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace|ast.SymbolFlagsAlias, nil /*nameNotFoundMessage*/, true /*isUse*/, false) - if symbol != nil && (symbol == c.undefinedSymbol || symbol == c.globalThisSymbol || symbol.Declarations != nil && ast.IsGlobalSourceFile(ast.GetDeclarationContainer(symbol.Declarations[0]))) { + if symbol != nil && (symbol == c.undefinedSymbol || symbol == c.globalThisSymbol || symbol.Declarations() != nil && ast.IsGlobalSourceFile(ast.GetDeclarationContainer(symbol.Declarations()[0]))) { c.error(exportedName, diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module, exportedName.Text()) } else { c.markLinkedReferences(node, ReferenceHintExportSpecifier, nil /*propSymbol*/, nil /*parentType*/) @@ -5812,9 +5812,9 @@ func (c *Checker) checkExportAssignment(node *ast.Node) { diagnostics.An_export_default_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type) c.error(id, message, id.Text()) } - if !isIllegalExportDefaultInCJS && node.Flags&ast.NodeFlagsAmbient == 0 && c.compilerOptions.GetIsolatedModules() && sym.Flags&ast.SymbolFlagsValue == 0 { + if !isIllegalExportDefaultInCJS && node.Flags&ast.NodeFlagsAmbient == 0 && c.compilerOptions.GetIsolatedModules() && sym.Flags()&ast.SymbolFlagsValue == 0 { nonLocalMeanings := c.getSymbolFlagsEx(sym, false /*excludeTypeOnlyMeanings*/, true /*excludeLocalMeanings*/) - if sym.Flags&ast.SymbolFlagsAlias != 0 && nonLocalMeanings&ast.SymbolFlagsType != 0 && nonLocalMeanings&ast.SymbolFlagsValue == 0 && (typeOnlyDeclaration == nil || ast.GetSourceFileOfNode(typeOnlyDeclaration) != ast.GetSourceFileOfNode(node)) { + if sym.Flags()&ast.SymbolFlagsAlias != 0 && nonLocalMeanings&ast.SymbolFlagsType != 0 && nonLocalMeanings&ast.SymbolFlagsValue == 0 && (typeOnlyDeclaration == nil || ast.GetSourceFileOfNode(typeOnlyDeclaration) != ast.GetSourceFileOfNode(node)) { // import { SomeType } from "./someModule"; // export default SomeType; OR // export = SomeType; @@ -5877,11 +5877,11 @@ func (c *Checker) checkExternalModuleExports(node *ast.Node) { moduleSymbol := c.getSymbolOfDeclaration(node) links := c.moduleSymbolLinks.Get(moduleSymbol) if !links.exportsChecked { - exportEqualsSymbol := moduleSymbol.Exports[ast.InternalSymbolNameExportEquals] + exportEqualsSymbol := moduleSymbol.Exports()[ast.InternalSymbolNameExportEquals] // An export assignment is in error if (a) the module exports value members or (b) if the module exports type or // namespace members and the exported entity also exports type or namespace members. if exportEqualsSymbol != nil && (c.hasExportedMembersOfKind(moduleSymbol, ast.SymbolFlagsValue) || c.hasShadowedNamespace(exportEqualsSymbol)) { - declaration := core.OrElse(c.getDeclarationOfAliasSymbol(exportEqualsSymbol), exportEqualsSymbol.ValueDeclaration) + declaration := core.OrElse(c.getDeclarationOfAliasSymbol(exportEqualsSymbol), exportEqualsSymbol.ValueDeclaration()) if declaration != nil && !isTopLevelInExternalModuleAugmentation(declaration) { c.error(declaration, diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements) } @@ -5893,21 +5893,21 @@ func (c *Checker) checkExternalModuleExports(node *ast.Node) { } // ECMA262: 15.2.1.1 It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries. // (TS Exceptions: namespaces, function overloads, enums, and interfaces) - if symbol.Flags&(ast.SymbolFlagsNamespace|ast.SymbolFlagsEnum) != 0 { + if symbol.Flags()&(ast.SymbolFlagsNamespace|ast.SymbolFlagsEnum) != 0 { continue } - exportedDeclarationsCount := core.CountWhere(symbol.Declarations, func(d *ast.Node) bool { + exportedDeclarationsCount := core.CountWhere(symbol.Declarations(), func(d *ast.Node) bool { return isNotOverload(d) && !ast.IsAccessor(d) && !ast.IsInterfaceDeclaration(d) }) - if symbol.Flags&ast.SymbolFlagsTypeAlias != 0 && exportedDeclarationsCount <= 2 { + if symbol.Flags()&ast.SymbolFlagsTypeAlias != 0 && exportedDeclarationsCount <= 2 { // it is legal to merge type alias with other values // so count should be either 1 (just type alias) or 2 (type alias + merged value) continue } - if exportedDeclarationsCount > 1 && !core.Every(symbol.Declarations, func(node *ast.Node) bool { + if exportedDeclarationsCount > 1 && !core.Every(symbol.Declarations(), func(node *ast.Node) bool { return ast.GetAssignmentDeclarationKind(node) == ast.JSDeclarationKindExportsProperty }) { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if isNotOverload(declaration) { c.error(declaration, diagnostics.Cannot_redeclare_exported_variable_0, id) } @@ -5919,8 +5919,8 @@ func (c *Checker) checkExternalModuleExports(node *ast.Node) { } func (c *Checker) hasExportedMembersOfKind(moduleSymbol *ast.Symbol, kind ast.SymbolFlags) bool { - for _, symbol := range moduleSymbol.Exports { - if symbol.Name != ast.InternalSymbolNameExportEquals && c.getSymbolFlags(symbol)&kind != 0 { + for _, symbol := range moduleSymbol.Exports() { + if symbol.Name() != ast.InternalSymbolNameExportEquals && c.getSymbolFlags(symbol)&kind != 0 { return true } } @@ -5928,8 +5928,8 @@ func (c *Checker) hasExportedMembersOfKind(moduleSymbol *ast.Symbol, kind ast.Sy } func (c *Checker) hasShadowedNamespace(symbol *ast.Symbol) bool { - if symbol.Flags&ast.SymbolFlagsNamespaceModule != 0 && symbol.Flags&ast.SymbolFlagsAlias != 0 { - if target := c.resolveAlias(symbol); target.Flags&ast.SymbolFlagsNamespace != 0 && c.hasExportedMembersOfKind(target, ast.SymbolFlagsType|ast.SymbolFlagsNamespace) { + if symbol.Flags()&ast.SymbolFlagsNamespaceModule != 0 && symbol.Flags()&ast.SymbolFlagsAlias != 0 { + if target := c.resolveAlias(symbol); target.Flags()&ast.SymbolFlagsNamespace != 0 && c.hasExportedMembersOfKind(target, ast.SymbolFlagsType|ast.SymbolFlagsNamespace) { return true } } @@ -6071,7 +6071,7 @@ func (c *Checker) checkVariableLikeDeclaration(node *ast.Node) { } // For a commonjs `const x = require`, validate the alias and exit symbol := c.getSymbolOfDeclaration(node) - if symbol.Flags&ast.SymbolFlagsAlias != 0 && ast.IsVariableDeclarationInitializedToRequire(node) { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 && ast.IsVariableDeclarationInitializedToRequire(node) { c.checkAliasSymbol(node) return } @@ -6079,7 +6079,7 @@ func (c *Checker) checkVariableLikeDeclaration(node *ast.Node) { c.error(name, diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name) } t := c.convertAutoToAny(c.getTypeOfSymbol(symbol)) - if node == symbol.ValueDeclaration { + if node == symbol.ValueDeclaration() { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error if initializer != nil && !ast.IsForInStatement(node.Parent.Parent) { @@ -6112,8 +6112,8 @@ func (c *Checker) checkVariableLikeDeclaration(node *ast.Node) { } } } - if len(symbol.Declarations) > 1 { - if core.Some(symbol.Declarations, func(d *ast.Declaration) bool { + if len(symbol.Declarations()) > 1 { + if core.Some(symbol.Declarations(), func(d *ast.Declaration) bool { return d != node && ast.IsVariableLike(d) && !c.areDeclarationFlagsIdentical(d, node) }) { c.error(name, diagnostics.All_declarations_of_0_must_have_identical_modifiers, scanner.DeclarationNameToString(name)) @@ -6123,13 +6123,13 @@ func (c *Checker) checkVariableLikeDeclaration(node *ast.Node) { // Node is a secondary declaration, check that type is identical to primary declaration and check that // initializer is consistent with type associated with the node declarationType := c.convertAutoToAny(c.getWidenedTypeForVariableLikeDeclaration(node, false)) - if !c.isErrorType(t) && !c.isErrorType(declarationType) && !c.isTypeIdenticalTo(t, declarationType) && symbol.Flags&ast.SymbolFlagsAssignment == 0 { - c.errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.ValueDeclaration, t, node, declarationType) + if !c.isErrorType(t) && !c.isErrorType(declarationType) && !c.isTypeIdenticalTo(t, declarationType) && symbol.Flags()&ast.SymbolFlagsAssignment == 0 { + c.errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.ValueDeclaration(), t, node, declarationType) } if initializer != nil { c.checkTypeAssignableToAndOptionallyElaborate(c.checkExpressionCached(initializer), declarationType, node, initializer, nil /*headMessage*/, nil) } - if symbol.ValueDeclaration != nil && !c.areDeclarationFlagsIdentical(node, symbol.ValueDeclaration) { + if symbol.ValueDeclaration() != nil && !c.areDeclarationFlagsIdentical(node, symbol.ValueDeclaration()) { c.error(name, diagnostics.All_declarations_of_0_must_have_identical_modifiers, scanner.DeclarationNameToString(name)) } } @@ -6189,14 +6189,14 @@ func (c *Checker) checkVarDeclaredNamesNotShadowed(node *ast.Node) { // so we'll always treat binding elements as initialized symbol := c.getSymbolOfDeclaration(node) name := node.Name() - if symbol.Flags&ast.SymbolFlagsFunctionScopedVariable != 0 { + if symbol.Flags()&ast.SymbolFlagsFunctionScopedVariable != 0 { if !ast.IsIdentifier(name) { panic("Identifier expected") } localDeclarationSymbol := c.resolveName(node, name.Text(), ast.SymbolFlagsVariable, nil /*nameNotFoundMessage*/, false /*isUse*/, false) - if localDeclarationSymbol != nil && localDeclarationSymbol != symbol && localDeclarationSymbol.Flags&ast.SymbolFlagsBlockScopedVariable != 0 { + if localDeclarationSymbol != nil && localDeclarationSymbol != symbol && localDeclarationSymbol.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 { if c.getDeclarationNodeFlagsFromSymbol(localDeclarationSymbol)&ast.NodeFlagsBlockScoped != 0 { - varDeclList := ast.FindAncestorKind(localDeclarationSymbol.ValueDeclaration, ast.KindVariableDeclarationList) + varDeclList := ast.FindAncestorKind(localDeclarationSymbol.ValueDeclaration(), ast.KindVariableDeclarationList) var container *ast.Node if ast.IsVariableStatement(varDeclList.Parent) && varDeclList.Parent.Parent != nil { container = varDeclList.Parent.Parent @@ -6655,7 +6655,7 @@ func (c *Checker) getAsyncFromSyncIterationTypes(iterationTypes IterationTypes, // NOTE: You probably don't want to call this directly and should be calling // `getIterationTypesOfIterable` instead. func (c *Checker) getIterationTypesOfIterableSlow(t *Type, r *IterationTypesResolver, errorNode *ast.Node, diagnosticOutput *[]*ast.Diagnostic) IterationTypes { - if method := c.getPropertyOfType(t, c.getPropertyNameForKnownSymbolName(r.iteratorSymbolName)); method != nil && method.Flags&ast.SymbolFlagsOptional == 0 { + if method := c.getPropertyOfType(t, c.getPropertyNameForKnownSymbolName(r.iteratorSymbolName)); method != nil && method.Flags()&ast.SymbolFlagsOptional == 0 { methodType := c.getTypeOfSymbol(method) if IsTypeAny(methodType) { return IterationTypes{c.anyType, c.anyType, c.anyType} @@ -6742,7 +6742,7 @@ func (c *Checker) getIterationTypesOfMethod(t *Type, resolver *IterationTypesRes return IterationTypes{} } var methodType *Type - if method != nil && !(methodName == "next" && method.Flags&ast.SymbolFlagsOptional != 0) { + if method != nil && !(methodName == "next" && method.Flags()&ast.SymbolFlagsOptional != 0) { if methodName == "next" { methodType = c.getTypeOfSymbol(method) } else { @@ -6774,8 +6774,8 @@ func (c *Checker) getIterationTypesOfMethod(t *Type, resolver *IterationTypesRes if len(methodSignatures) == 1 && methodType.symbol != nil { globalGeneratorType := resolver.getGlobalGeneratorType() globalIteratorType := resolver.getGlobalIteratorType() - isGeneratorMethod := globalGeneratorType.symbol != nil && globalGeneratorType.symbol.Members[methodName] == methodType.symbol - isIteratorMethod := !isGeneratorMethod && globalIteratorType.symbol != nil && globalIteratorType.symbol.Members[methodName] == methodType.symbol + isGeneratorMethod := globalGeneratorType.symbol != nil && globalGeneratorType.symbol.Members()[methodName] == methodType.symbol + isIteratorMethod := !isGeneratorMethod && globalIteratorType.symbol != nil && globalIteratorType.symbol.Members()[methodName] == methodType.symbol if isGeneratorMethod || isIteratorMethod { typeParameters := core.IfElse(isGeneratorMethod, globalGeneratorType, globalIteratorType).AsInterfaceType().TypeParameters() mapper := methodType.Mapper() @@ -6913,7 +6913,7 @@ func (c *Checker) getIterationDiagnosticDetails(use IterationUse, inputType *Typ if yieldType != nil { return diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher, false } - if inputType.symbol != nil && isES2015OrLaterIterable(inputType.symbol.Name) { + if inputType.symbol != nil && isES2015OrLaterIterable(inputType.symbol.Name()) { return diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher, true } if allowsStrings { @@ -6942,7 +6942,7 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) { // Based on symbol.flags we can compute a set of excluded meanings (meaning that resolved alias should not have, // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export* // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names). - symbol = c.getMergedSymbol(core.OrElse(symbol.ExportSymbol, symbol)) + symbol = c.getMergedSymbol(core.OrElse(symbol.ExportSymbol(), symbol)) targetFlags := c.getSymbolFlags(target) // A type-only import/export will already have a grammar error in a JS file, so no need to issue more errors within if ast.IsInJSFile(node) && targetFlags&ast.SymbolFlagsValue == 0 && !ast.IsTypeOnlyImportOrExportDeclaration(node) { @@ -6951,14 +6951,14 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) { if ast.IsExportSpecifier(node) { diag := c.error(errorNode, diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files) if sourceSymbol := ast.GetSourceFileOfNode(node).AsNode().Symbol(); sourceSymbol != nil { - if alreadyExportedSymbol := sourceSymbol.Exports[node.PropertyNameOrName().Text()]; alreadyExportedSymbol == target { - if exportingDeclaration := core.Find(alreadyExportedSymbol.Declarations, ast.IsJSTypeAliasDeclaration); exportingDeclaration != nil { - diag.AddRelatedInfo(NewDiagnosticForNode(exportingDeclaration, diagnostics.X_0_is_automatically_exported_here, alreadyExportedSymbol.Name)) + if alreadyExportedSymbol := sourceSymbol.Exports()[node.PropertyNameOrName().Text()]; alreadyExportedSymbol == target { + if exportingDeclaration := core.Find(alreadyExportedSymbol.Declarations(), ast.IsJSTypeAliasDeclaration); exportingDeclaration != nil { + diag.AddRelatedInfo(NewDiagnosticForNode(exportingDeclaration, diagnostics.X_0_is_automatically_exported_here, alreadyExportedSymbol.Name())) } } } } else { - identifierText := symbol.Name + identifierText := symbol.Name() if ast.IsIdentifier(errorNode) { identifierText = errorNode.Text() } @@ -6978,9 +6978,9 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) { } return } - excludedMeanings := core.IfElse(symbol.Flags&(ast.SymbolFlagsValue|ast.SymbolFlagsExportValue) != 0, ast.SymbolFlagsValue, 0) | - core.IfElse(symbol.Flags&ast.SymbolFlagsType != 0, ast.SymbolFlagsType, 0) | - core.IfElse(symbol.Flags&ast.SymbolFlagsNamespace != 0, ast.SymbolFlagsNamespace, 0) + excludedMeanings := core.IfElse(symbol.Flags()&(ast.SymbolFlagsValue|ast.SymbolFlagsExportValue) != 0, ast.SymbolFlagsValue, 0) | + core.IfElse(symbol.Flags()&ast.SymbolFlagsType != 0, ast.SymbolFlagsType, 0) | + core.IfElse(symbol.Flags()&ast.SymbolFlagsNamespace != 0, ast.SymbolFlagsNamespace, 0) if targetFlags&excludedMeanings != 0 { message := core.IfElse(ast.IsExportSpecifier(node), diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0, @@ -6990,7 +6990,7 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) { // Look at 'compilerOptions.isolatedModules' and not 'getIsolatedModules(...)' (which considers 'verbatimModuleSyntax') // here because 'verbatimModuleSyntax' will already have an error for importing a type without 'import type'. appearsValueyToTranspiler := c.compilerOptions.IsolatedModules.IsTrue() && ast.FindAncestor(node, ast.IsTypeOnlyImportOrExportDeclaration) == nil - if appearsValueyToTranspiler && symbol.Flags&(ast.SymbolFlagsValue|ast.SymbolFlagsExportValue) != 0 { + if appearsValueyToTranspiler && symbol.Flags()&(ast.SymbolFlagsValue|ast.SymbolFlagsExportValue) != 0 { c.error(node, diagnostics.Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled, c.symbolToString(symbol), c.getIsolatedModulesLikeFlagName()) } } @@ -7043,7 +7043,7 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) { c.error(node, diagnostics.ECMAScript_module_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve) } if c.compilerOptions.VerbatimModuleSyntax.IsTrue() && !ast.IsTypeOnlyImportOrExportDeclaration(node) && node.Flags&ast.NodeFlagsAmbient == 0 && targetFlags&ast.SymbolFlagsConstEnum != 0 { - constEnumDeclaration := target.ValueDeclaration + constEnumDeclaration := target.ValueDeclaration() if constEnumDeclaration != nil && constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 { redirect := c.program.GetProjectReferenceFromOutputDts(ast.GetSourceFileOfNode(constEnumDeclaration).PathKey()) if redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums() { @@ -7054,8 +7054,8 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) { } if ast.IsImportSpecifier(node) { targetSymbol := c.resolveAliasWithDeprecationCheck(symbol, node) - if c.isDeprecatedSymbol(targetSymbol) && targetSymbol.Declarations != nil { - c.addDeprecatedSuggestion(node, targetSymbol.Declarations, targetSymbol.Name) + if c.isDeprecatedSymbol(targetSymbol) && targetSymbol.Declarations() != nil { + c.addDeprecatedSuggestion(node, targetSymbol.Declarations(), targetSymbol.Name()) } } } @@ -7113,18 +7113,18 @@ func (c *Checker) checkExportsOnMergedDeclarations(node *ast.Node) { // Local symbol is undefined => this declaration is non-exported. // However, symbol might contain other declarations that are exported. symbol = c.getSymbolOfDeclaration(node) - if symbol.ExportSymbol == nil { + if symbol.ExportSymbol() == nil { // This is a pure local symbol (all declarations are non-exported) - no need to check anything. return } } - if len(symbol.Declarations) < 2 || !c.mergedExportsChecked.AddIfAbsent(symbol) { + if len(symbol.Declarations()) < 2 || !c.mergedExportsChecked.AddIfAbsent(symbol) { return } exportedDeclarationSpaces := DeclarationSpacesNone nonExportedDeclarationSpaces := DeclarationSpacesNone defaultExportedDeclarationSpaces := DeclarationSpacesNone - for _, d := range symbol.Declarations { + for _, d := range symbol.Declarations() { declarationSpaces := c.getDeclarationSpaces(d) effectiveDeclarationFlags := c.getEffectiveDeclarationFlags(d, ast.ModifierFlagsExport|ast.ModifierFlagsDefault) if effectiveDeclarationFlags&ast.ModifierFlagsExport != 0 { @@ -7143,7 +7143,7 @@ func (c *Checker) checkExportsOnMergedDeclarations(node *ast.Node) { commonDeclarationSpacesForDefaultAndNonDefault := defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces if commonDeclarationSpacesForExportsAndLocals != 0 || commonDeclarationSpacesForDefaultAndNonDefault != 0 { // declaration spaces for exported and non-exported declarations intersect - for _, d := range symbol.Declarations { + for _, d := range symbol.Declarations() { declarationSpaces := c.getDeclarationSpaces(d) name := ast.GetNameOfDeclaration(d) // Only error on the declarations that contributed to the intersecting spaces. @@ -7177,7 +7177,7 @@ func (c *Checker) getDeclarationSpaces(node *ast.Declaration) DeclarationSpaces expression = node.AsBinaryExpression().Right } // Export assigned entity name expressions act as aliases and should fall through, otherwise they export values. - if !ast.IsEntityNameExpression(expression) || c.getSymbolOfDeclaration(node).Flags&ast.SymbolFlagsAlias == 0 { + if !ast.IsEntityNameExpression(expression) || c.getSymbolOfDeclaration(node).Flags()&ast.SymbolFlagsAlias == 0 { return DeclarationSpacesExportValue } // The below options all declare an Alias, which is allowed to merge with other values within the importing module. @@ -7185,7 +7185,7 @@ func (c *Checker) getDeclarationSpaces(node *ast.Declaration) DeclarationSpaces case ast.KindImportEqualsDeclaration, ast.KindNamespaceImport, ast.KindImportClause: result := DeclarationSpacesNone target := c.resolveAlias(c.getSymbolOfDeclaration(node)) - for _, d := range target.Declarations { + for _, d := range target.Declarations() { result |= c.getDeclarationSpaces(d) } return result @@ -7314,7 +7314,7 @@ func (c *Checker) checkUnusedClassMembers(node *ast.Node) { for _, member := range node.Members() { switch member.Kind { case ast.KindMethodDeclaration, ast.KindPropertyDeclaration, ast.KindGetAccessor, ast.KindSetAccessor: - if ast.IsSetAccessorDeclaration(member) && member.Symbol().Flags&ast.SymbolFlagsGetAccessor != 0 { + if ast.IsSetAccessorDeclaration(member) && member.Symbol().Flags()&ast.SymbolFlagsGetAccessor != 0 { break // Already would have reported an error on the getter. } symbol := c.getSymbolOfDeclaration(member) @@ -7340,12 +7340,12 @@ func (c *Checker) checkUnusedLocalsAndParameters(node *ast.Node) { var importClauses map[*ast.Node][]*ast.Node for _, local := range node.Locals() { referenceKinds := c.symbolReferenceLinks.Get(local).referenceKinds - if local.Flags&ast.SymbolFlagsTypeParameter != 0 && (local.Flags&ast.SymbolFlagsVariable == 0 || referenceKinds&ast.SymbolFlagsVariable != 0) || - local.Flags&ast.SymbolFlagsTypeParameter == 0 && (referenceKinds != 0 || local.ExportSymbol != nil || - local.Flags&ast.SymbolFlagsModuleExports != 0) { + if local.Flags()&ast.SymbolFlagsTypeParameter != 0 && (local.Flags()&ast.SymbolFlagsVariable == 0 || referenceKinds&ast.SymbolFlagsVariable != 0) || + local.Flags()&ast.SymbolFlagsTypeParameter == 0 && (referenceKinds != 0 || local.ExportSymbol() != nil || + local.Flags()&ast.SymbolFlagsModuleExports != 0) { continue } - for _, declaration := range local.Declarations { + for _, declaration := range local.Declarations() { switch { case ast.IsVariableDeclaration(declaration) || ast.IsParameterDeclaration(declaration) || ast.IsBindingElement(declaration): variableParents.Add(ast.GetRootDeclaration(declaration).Parent) @@ -7785,8 +7785,8 @@ func (c *Checker) checkConstEnumAccess(node *ast.Node, t *Type) { // resolve to an import, because imports of ambient const enums get checked // separately in `checkAliasSymbol`. if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, ast.GetFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil { - debug.Assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0) - constEnumDeclaration := t.symbol.ValueDeclaration + debug.Assert(t.symbol.Flags()&ast.SymbolFlagsConstEnum != 0) + constEnumDeclaration := t.symbol.ValueDeclaration() redirect := c.program.GetProjectReferenceFromOutputDts(ast.GetSourceFileOfNode(constEnumDeclaration).PathKey()) if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsValidTypeOnlyAliasUseSite(node) && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) { c.error(node, diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, c.getIsolatedModulesLikeFlagName()) @@ -7884,7 +7884,7 @@ func (c *Checker) getUniqueTypeParameters(context *InferenceContext, typeParamet var newTypeParameters []*Type result := make([]*Type, 0, len(typeParameters)) for _, tp := range typeParameters { - name := tp.symbol.Name + name := tp.symbol.Name() if hasTypeParameterByName(context.inferredTypeParameters, name) || hasTypeParameterByName(result, name) { newName := getUniqueTypeParameterName(core.Concatenate(context.inferredTypeParameters, result), name) symbol := c.newSymbol(ast.SymbolFlagsTypeParameter, newName) @@ -7908,7 +7908,7 @@ func (c *Checker) getUniqueTypeParameters(context *InferenceContext, typeParamet func hasTypeParameterByName(typeParameters []*Type, name string) bool { return core.Some(typeParameters, func(tp *Type) bool { - return tp.symbol.Name == name + return tp.symbol.Name() == name }) } @@ -8378,7 +8378,7 @@ func (c *Checker) isForInVariableForNumericPropertyNames(expr *ast.Node) bool { e := ast.SkipParentheses(expr) if ast.IsIdentifier(e) { symbol := c.getResolvedSymbol(e) - if symbol.Flags&ast.SymbolFlagsVariable != 0 { + if symbol.Flags()&ast.SymbolFlagsVariable != 0 { child := expr node := expr.Parent for node != nil { @@ -9905,7 +9905,7 @@ func (c *Checker) reportCallResolutionErrors(node *ast.Node, s *CallState, signa func (c *Checker) addImplementationSuccessElaboration(s *CallState, failed *Signature, diagnostic *ast.Diagnostic) { if failed.declaration != nil && failed.declaration.Symbol() != nil { - declarations := failed.declaration.Symbol().Declarations + declarations := failed.declaration.Symbol().Declarations() if len(declarations) > 1 { implementation := core.Find(declarations, func(d *ast.Declaration) bool { return ast.IsFunctionLikeDeclaration(d) && ast.NodeIsPresent(d.Body()) @@ -10049,7 +10049,7 @@ func (c *Checker) isPromiseResolveArityError(node *ast.Node) bool { if symbol == nil { return false } - decl := symbol.ValueDeclaration + decl := symbol.ValueDeclaration() if decl == nil || !ast.IsParameterDeclaration(decl) || !ast.IsFunctionExpressionOrArrowFunction(decl.Parent) || !ast.IsNewExpression(decl.Parent.Parent) || !ast.IsIdentifier(decl.Parent.Parent.Expression()) { return false } @@ -10203,7 +10203,7 @@ func (c *Checker) invocationErrorDetails(errorTarget *ast.Node, apparentType *Ty // Diagnose get accessors incorrectly called as functions if ast.IsCallExpression(errorTarget.Parent) && len(errorTarget.Parent.Arguments()) == 0 { resolvedSymbol := c.getResolvedSymbolOrNil(errorTarget) - if resolvedSymbol != nil && resolvedSymbol.Flags&ast.SymbolFlagsGetAccessor != 0 { + if resolvedSymbol != nil && resolvedSymbol.Flags()&ast.SymbolFlagsGetAccessor != 0 { headMessage = diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without } } @@ -10466,7 +10466,7 @@ func (c *Checker) checkFunctionExpressionOrObjectLiteralMethodDeferred(node *ast func (c *Checker) inferFromAnnotatedParametersAndReturn(sig *Signature, context *Signature, inferenceContext *InferenceContext) { length := len(sig.parameters) - core.IfElse(signatureHasRestParameter(sig), 1, 0) for i := range length { - declaration := sig.parameters[i].ValueDeclaration + declaration := sig.parameters[i].ValueDeclaration() typeNode := declaration.Type() if typeNode != nil { source := c.addOptionalityEx(c.getTypeFromTypeNode(typeNode), false /*isProperty*/, isOptionalDeclaration(declaration)) @@ -10583,7 +10583,7 @@ func (c *Checker) assignContextualParameterTypes(sig *Signature, context *Signat } if context.thisParameter != nil { parameter := sig.thisParameter - if parameter == nil || parameter.ValueDeclaration != nil && parameter.ValueDeclaration.Type() == nil { + if parameter == nil || parameter.ValueDeclaration() != nil && parameter.ValueDeclaration().Type() == nil { if parameter == nil { sig.thisParameter = c.createSymbolWithType(context.thisParameter, nil /*type*/) } @@ -10593,7 +10593,7 @@ func (c *Checker) assignContextualParameterTypes(sig *Signature, context *Signat length := len(sig.parameters) - core.IfElse(signatureHasRestParameter(sig), 1, 0) for i := range length { parameter := sig.parameters[i] - declaration := parameter.ValueDeclaration + declaration := parameter.ValueDeclaration() if declaration.Type() == nil { t := c.tryGetTypeAtPosition(context, i) if t != nil && declaration.Initializer() != nil { @@ -10611,8 +10611,8 @@ func (c *Checker) assignContextualParameterTypes(sig *Signature, context *Signat if signatureHasRestParameter(sig) { // parameter might be a transient symbol generated by use of `arguments` in the function body. parameter := core.LastOrNil(sig.parameters) - if parameter.ValueDeclaration != nil && parameter.ValueDeclaration.Type() == nil || - parameter.ValueDeclaration == nil && parameter.CheckFlags&ast.CheckFlagsDeferredType != 0 { + if parameter.ValueDeclaration() != nil && parameter.ValueDeclaration().Type() == nil || + parameter.ValueDeclaration() == nil && parameter.CheckFlags()&ast.CheckFlagsDeferredType != 0 { contextualParameterType := c.getRestTypeAtPosition(context, length, false) c.assignParameterType(parameter, contextualParameterType) } @@ -10633,7 +10633,7 @@ func (c *Checker) assignParameterType(parameter *ast.Symbol, contextualType *Typ if links.resolvedType != nil { return } - declaration := parameter.ValueDeclaration + declaration := parameter.ValueDeclaration() t := contextualType if t == nil { if declaration != nil { @@ -10922,7 +10922,7 @@ func (c *Checker) getInstantiationExpressionType(exprType *Type, node *ast.Node) if !core.Same(callSignatures, resolved.CallSignatures()) || !core.Same(constructSignatures, resolved.ConstructSignatures()) { symbol := c.newSymbol(ast.SymbolFlagsNone, ast.InternalSymbolNameInstantiationExpression) debug.Assert(t.symbol != nil, "Instantiation expression source type must have a symbol") - symbol.Declarations = t.symbol.Declarations + symbol.SetDeclarations(t.symbol.Declarations()) result := c.newObjectType(ObjectFlagsAnonymous|ObjectFlagsInstantiationExpressionType, symbol) c.setStructuredTypeMembers(result, resolved.members, callSignatures, constructSignatures, resolved.indexInfos) result.AsInstantiationExpressionType().node = node @@ -11059,7 +11059,7 @@ func (c *Checker) checkDeleteExpressionMustBeOptional(expr *ast.Node, symbol *as if c.strictNullChecks && t.flags&(TypeFlagsAnyOrUnknown|TypeFlagsNever) == 0 { var isOptional bool if c.exactOptionalPropertyTypes { - isOptional = symbol.Flags&ast.SymbolFlagsOptional != 0 + isOptional = symbol.Flags()&ast.SymbolFlagsOptional != 0 } else { isOptional = c.hasTypeFacts(t, TypeFactsIsUndefined) } @@ -11291,10 +11291,10 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { } localOrExportSymbol := c.getExportSymbolOfValueSymbolIfExported(symbol) targetSymbol := c.resolveAliasWithDeprecationCheck(localOrExportSymbol, node) - if len(targetSymbol.Declarations) != 0 && c.isDeprecatedSymbol(targetSymbol) && c.isUncalledFunctionReference(node, targetSymbol) { - c.addDeprecatedSuggestion(node, targetSymbol.Declarations, node.Text()) + if len(targetSymbol.Declarations()) != 0 && c.isDeprecatedSymbol(targetSymbol) && c.isUncalledFunctionReference(node, targetSymbol) { + c.addDeprecatedSuggestion(node, targetSymbol.Declarations(), node.Text()) } - declaration := localOrExportSymbol.ValueDeclaration + declaration := localOrExportSymbol.ValueDeclaration() immediateDeclaration := declaration // If the identifier is declared in a binding pattern for which we're currently computing the implied type and the // reference occurs with the same binding pattern, return the non-inferrable any type. This for example occurs in @@ -11306,18 +11306,18 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { t := c.getNarrowedTypeOfSymbol(localOrExportSymbol, node) assignmentKind := getAssignmentTargetKind(node) if assignmentKind != AssignmentKindNone { - if localOrExportSymbol.Flags&ast.SymbolFlagsVariable == 0 && !(ast.IsInJSFile(node) && localOrExportSymbol.Flags&ast.SymbolFlagsValueModule != 0) { + if localOrExportSymbol.Flags()&ast.SymbolFlagsVariable == 0 && !(ast.IsInJSFile(node) && localOrExportSymbol.Flags()&ast.SymbolFlagsValueModule != 0) { var assignmentError *diagnostics.Message switch { - case localOrExportSymbol.Flags&ast.SymbolFlagsEnum != 0: + case localOrExportSymbol.Flags()&ast.SymbolFlagsEnum != 0: assignmentError = diagnostics.Cannot_assign_to_0_because_it_is_an_enum - case localOrExportSymbol.Flags&ast.SymbolFlagsClass != 0: + case localOrExportSymbol.Flags()&ast.SymbolFlagsClass != 0: assignmentError = diagnostics.Cannot_assign_to_0_because_it_is_a_class - case localOrExportSymbol.Flags&ast.SymbolFlagsModule != 0: + case localOrExportSymbol.Flags()&ast.SymbolFlagsModule != 0: assignmentError = diagnostics.Cannot_assign_to_0_because_it_is_a_namespace - case localOrExportSymbol.Flags&ast.SymbolFlagsFunction != 0: + case localOrExportSymbol.Flags()&ast.SymbolFlagsFunction != 0: assignmentError = diagnostics.Cannot_assign_to_0_because_it_is_a_function - case localOrExportSymbol.Flags&ast.SymbolFlagsAlias != 0: + case localOrExportSymbol.Flags()&ast.SymbolFlagsAlias != 0: assignmentError = diagnostics.Cannot_assign_to_0_because_it_is_an_import default: assignmentError = diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable @@ -11326,7 +11326,7 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { return c.errorType } if c.isReadonlySymbol(localOrExportSymbol) { - if localOrExportSymbol.Flags&ast.SymbolFlagsVariable != 0 { + if localOrExportSymbol.Flags()&ast.SymbolFlagsVariable != 0 { c.error(node, diagnostics.Cannot_assign_to_0_because_it_is_a_constant, c.symbolToString(symbol)) } else { c.error(node, diagnostics.Cannot_assign_to_0_because_it_is_a_read_only_property, c.symbolToString(symbol)) @@ -11334,10 +11334,10 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { return c.errorType } } - isAlias := localOrExportSymbol.Flags&ast.SymbolFlagsAlias != 0 + isAlias := localOrExportSymbol.Flags()&ast.SymbolFlagsAlias != 0 // We only narrow variables and parameters occurring in a non-assignment position. For all other // entities we simply return the declared type. - if localOrExportSymbol.Flags&ast.SymbolFlagsVariable != 0 { + if localOrExportSymbol.Flags()&ast.SymbolFlagsVariable != 0 { if assignmentKind == AssignmentKindDefinite { if isInCompoundLikeAssignment(node) { return c.getBaseTypeOfLiteralType(t) @@ -11361,7 +11361,7 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { flowContainer := c.getControlFlowContainer(node) isOuterVariable := flowContainer != declarationContainer isSpreadDestructuringAssignmentTarget := node.Parent != nil && node.Parent.Parent != nil && ast.IsSpreadAssignment(node.Parent) && c.isDestructuringAssignmentTarget(node.Parent.Parent) - isModuleExports := symbol.Flags&ast.SymbolFlagsModuleExports != 0 + isModuleExports := symbol.Flags()&ast.SymbolFlagsModuleExports != 0 typeIsAutomatic := t == c.autoType || t == c.autoArrayType isAutomaticTypeInNonNull := typeIsAutomatic && node.Parent.Kind == ast.KindNonNullExpression // When the control flow originates in a function expression, arrow function, method, or accessor, and @@ -11509,7 +11509,7 @@ func (c *Checker) checkPropertyAccessExpressionOrQualifiedName(node *ast.Node, l } } lexicallyScopedSymbol := c.lookupSymbolForPrivateIdentifierDeclaration(right.Text(), right) - if assignmentKind != AssignmentKindNone && lexicallyScopedSymbol != nil && lexicallyScopedSymbol.ValueDeclaration != nil && ast.IsMethodDeclaration(lexicallyScopedSymbol.ValueDeclaration) { + if assignmentKind != AssignmentKindNone && lexicallyScopedSymbol != nil && lexicallyScopedSymbol.ValueDeclaration() != nil && ast.IsMethodDeclaration(lexicallyScopedSymbol.ValueDeclaration()) { c.grammarErrorOnNode(right, diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable, right.Text()) } if isAnyLike { @@ -11537,7 +11537,7 @@ func (c *Checker) checkPropertyAccessExpressionOrQualifiedName(node *ast.Node, l c.grammarErrorOnNode(right, diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class, right.Text()) } } else { - isSetonlyAccessor := prop.Flags&ast.SymbolFlagsSetAccessor != 0 && prop.Flags&ast.SymbolFlagsGetAccessor == 0 + isSetonlyAccessor := prop.Flags()&ast.SymbolFlagsSetAccessor != 0 && prop.Flags()&ast.SymbolFlagsGetAccessor == 0 if isSetonlyAccessor && assignmentKind != AssignmentKindDefinite { c.error(node, diagnostics.Private_accessor_was_defined_without_a_getter) } @@ -11567,8 +11567,8 @@ func (c *Checker) checkPropertyAccessExpressionOrQualifiedName(node *ast.Node, l return c.anyType } if leftType.symbol == c.globalThisSymbol { - globalSymbol := c.globalThisSymbol.Exports[right.Text()] - if globalSymbol != nil && globalSymbol.Flags&ast.SymbolFlagsBlockScoped != 0 { + globalSymbol := c.globalThisSymbol.Exports()[right.Text()] + if globalSymbol != nil && globalSymbol.Flags()&ast.SymbolFlagsBlockScoped != 0 { c.error(right, diagnostics.Property_0_does_not_exist_on_type_1, right.Text(), c.TypeToString(leftType)) } else if c.noImplicitAny { c.error(right, diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, c.TypeToString(leftType)) @@ -11598,8 +11598,8 @@ func (c *Checker) checkPropertyAccessExpressionOrQualifiedName(node *ast.Node, l } } else { targetPropSymbol := c.resolveAliasWithDeprecationCheck(prop, right) - if c.isDeprecatedSymbol(targetPropSymbol) && c.isUncalledFunctionReference(node, targetPropSymbol) && targetPropSymbol.Declarations != nil { - c.addDeprecatedSuggestion(right, targetPropSymbol.Declarations, right.Text()) + if c.isDeprecatedSymbol(targetPropSymbol) && c.isUncalledFunctionReference(node, targetPropSymbol) && targetPropSymbol.Declarations() != nil { + c.addDeprecatedSuggestion(right, targetPropSymbol.Declarations(), right.Text()) } c.checkPropertyNotUsedBeforeDeclaration(prop, node, right) c.markPropertyAsReferenced(prop, node, c.isSelfTypeAccess(left, parentSymbol)) @@ -11627,9 +11627,9 @@ func (c *Checker) getFlowTypeOfAccessExpression(node *ast.Node, prop *ast.Symbol // accessor, or optional method. assignmentKind := getAssignmentTargetKind(node) if assignmentKind == AssignmentKindDefinite { - return c.removeMissingType(propType, prop != nil && prop.Flags&ast.SymbolFlagsOptional != 0) + return c.removeMissingType(propType, prop != nil && prop.Flags()&ast.SymbolFlagsOptional != 0) } - if prop != nil && prop.Flags&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty|ast.SymbolFlagsAccessor) == 0 && !(prop.Flags&ast.SymbolFlagsMethod != 0 && propType.flags&TypeFlagsUnion != 0) { + if prop != nil && prop.Flags()&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty|ast.SymbolFlagsAccessor) == 0 && !(prop.Flags()&ast.SymbolFlagsMethod != 0 && propType.flags&TypeFlagsUnion != 0) { return propType } if propType == c.autoType { @@ -11642,7 +11642,7 @@ func (c *Checker) getFlowTypeOfAccessExpression(node *ast.Node, prop *ast.Symbol // the property is uninitialized at the top of the control flow. assumeUninitialized := false if c.strictNullChecks && prop != nil { - if declaration := prop.ValueDeclaration; declaration != nil { + if declaration := prop.ValueDeclaration(); declaration != nil { if c.strictPropertyInitialization && ast.IsAccessExpression(node) && node.Expression().Kind == ast.KindThisKeyword { if c.isPropertyWithoutInitializer(declaration) && !ast.IsStatic(declaration) { flowContainer := c.getControlFlowContainer(node) @@ -11676,7 +11676,7 @@ func (c *Checker) getControlFlowContainer(node *ast.Node) *ast.Node { func (c *Checker) getFlowTypeOfProperty(reference *ast.Node, prop *ast.Symbol) *Type { initialType := c.undefinedType - if prop != nil && prop.ValueDeclaration != nil && (!c.isAutoTypedProperty(prop) || prop.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsAmbient != 0) { + if prop != nil && prop.ValueDeclaration() != nil && (!c.isAutoTypedProperty(prop) || prop.ValueDeclaration().ModifierFlags()&ast.ModifierFlagsAmbient != 0) { if baseType := c.getTypeOfPropertyInBaseClass(prop); baseType != nil { initialType = baseType } @@ -11690,7 +11690,7 @@ func (c *Checker) getTypeOfPropertyInBaseClass(property *ast.Symbol) *Type { if classType != nil { baseClassTypes := c.getBaseTypes(classType) if len(baseClassTypes) > 0 { - return c.getTypeOfPropertyOfType(baseClassTypes[0], property.Name) + return c.getTypeOfPropertyOfType(baseClassTypes[0], property.Name()) } } return nil @@ -11708,11 +11708,11 @@ func (c *Checker) lookupSymbolForPrivateIdentifierDeclaration(propName string, l for containingClass := getContainingClassExcludingClassDecorators(location); containingClass != nil; containingClass = ast.GetContainingClass(containingClass) { symbol := containingClass.Symbol() name := binder.GetSymbolNameForPrivateIdentifier(symbol, propName) - prop := symbol.Members[name] + prop := symbol.Members()[name] if prop != nil { return prop } - prop = symbol.Exports[name] + prop = symbol.Exports()[name] if prop != nil { return prop } @@ -11721,7 +11721,7 @@ func (c *Checker) lookupSymbolForPrivateIdentifierDeclaration(propName string, l } func (c *Checker) getPrivateIdentifierPropertyOfType(leftType *Type, lexicallyScopedIdentifier *ast.Symbol) *ast.Symbol { - return c.getPropertyOfType(leftType, lexicallyScopedIdentifier.Name) + return c.getPropertyOfType(leftType, lexicallyScopedIdentifier.Name()) } func (c *Checker) checkPrivateIdentifierPropertyAccess(leftType *Type, right *ast.Node, lexicallyScopedIdentifier *ast.Symbol) bool { @@ -11730,7 +11730,7 @@ func (c *Checker) checkPrivateIdentifierPropertyAccess(leftType *Type, right *as properties := c.getPropertiesOfType(leftType) var propertyOnType *ast.Symbol for _, symbol := range properties { - decl := symbol.ValueDeclaration + decl := symbol.ValueDeclaration() if decl != nil && decl.Name() != nil && ast.IsPrivateIdentifier(decl.Name()) && decl.Name().Text() == right.Text() { propertyOnType = symbol break @@ -11738,14 +11738,14 @@ func (c *Checker) checkPrivateIdentifierPropertyAccess(leftType *Type, right *as } diagName := scanner.DeclarationNameToString(right) if propertyOnType != nil { - typeValueDecl := propertyOnType.ValueDeclaration + typeValueDecl := propertyOnType.ValueDeclaration() typeClass := ast.GetContainingClass(typeValueDecl) // We found a private identifier property with the same description. // Either: // - There is a lexically scoped private identifier AND it shadows the one we found on the type. // - It is an attempt to access the private identifier outside of the class. - if lexicallyScopedIdentifier != nil && lexicallyScopedIdentifier.ValueDeclaration != nil { - lexicalValueDecl := lexicallyScopedIdentifier.ValueDeclaration + if lexicallyScopedIdentifier != nil && lexicallyScopedIdentifier.ValueDeclaration() != nil { + lexicalValueDecl := lexicallyScopedIdentifier.ValueDeclaration() lexicalClass := ast.GetContainingClass(lexicalValueDecl) if ast.FindAncestor(lexicalClass, func(n *ast.Node) bool { return typeClass == n }) != nil { diagnostic := c.error(right, diagnostics.The_property_0_cannot_be_accessed_on_type_1_within_this_class_because_it_is_shadowed_by_another_private_identifier_with_the_same_spelling, diagName, c.TypeToString(leftType)) @@ -11804,8 +11804,8 @@ func (c *Checker) reportNonexistentProperty(propNode *ast.Node, containingType * suggestedName := ast.SymbolName(suggestion) message := core.IfElse(isUncheckedJS, diagnostics.Property_0_may_not_exist_on_type_1_Did_you_mean_2, diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2) diagnostic = NewDiagnosticChainForNode(diagnostic, propNode, message, missingProperty, container, suggestedName) - if suggestion.ValueDeclaration != nil { - diagnostic.AddRelatedInfo(NewDiagnosticForNode(suggestion.ValueDeclaration, diagnostics.X_0_is_declared_here, suggestedName)) + if suggestion.ValueDeclaration() != nil { + diagnostic.AddRelatedInfo(NewDiagnosticForNode(suggestion.ValueDeclaration(), diagnostics.X_0_is_declared_here, suggestedName)) } } else { diagnostic = c.elaborateNeverIntersection(diagnostic, propNode, containingType) @@ -11827,7 +11827,7 @@ func (c *Checker) getSuggestedLibForNonExistentProperty(missingProperty string, container := c.getApparentType(containingType).symbol if container != nil { featureMap := getFeatureMap() - if typeFeatures, ok := featureMap[container.Name]; ok { + if typeFeatures, ok := featureMap[container.Name()]; ok { for _, entry := range typeFeatures { if slices.Contains(entry.props, missingProperty) { return entry.lib @@ -11877,8 +11877,8 @@ func (c *Checker) isPropertyAccessible(node *ast.Node, isSuper bool, isWrite boo } // A #private property access in an optional chain is an error dealt with by the parser. // The checker does not check for it, so we need to do our own check here. - if property.ValueDeclaration != nil && ast.IsPrivateIdentifierClassElementDeclaration(property.ValueDeclaration) { - declClass := ast.GetContainingClass(property.ValueDeclaration) + if property.ValueDeclaration() != nil && ast.IsPrivateIdentifierClassElementDeclaration(property.ValueDeclaration()) { + declClass := ast.GetContainingClass(property.ValueDeclaration()) return !ast.IsOptionalChain(node) && ast.IsNodeDescendantOf(node, declClass) } return c.checkPropertyAccessibilityAtLocation(node, isSuper, isWrite, containingType, property, nil) @@ -11892,7 +11892,7 @@ func hasCommonDomTypeName(t *Type) bool { if t.symbol == nil { return false } - name := t.symbol.Name + name := t.symbol.Name() return name == "EventTarget" || name == "Node" || name == "Element" || strings.HasPrefix(name, "HTML") && strings.HasSuffix(name, "Element") } @@ -11925,7 +11925,7 @@ func (c *Checker) getEntityNameForExtendingInterface(node *ast.Node) *ast.Node { } func (c *Checker) isUncalledFunctionReference(node *ast.Node, symbol *ast.Symbol) bool { - if symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { + if symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { parent := ast.FindAncestor(node.Parent, func(n *ast.Node) bool { return !ast.IsAccessExpression(n) }) if parent == nil { parent = node.Parent @@ -11933,7 +11933,7 @@ func (c *Checker) isUncalledFunctionReference(node *ast.Node, symbol *ast.Symbol if ast.IsCallLikeExpression(parent) { return ast.IsCallOrNewExpression(parent) && ast.IsIdentifier(node) && c.hasMatchingArgument(parent, node) } - return core.Every(symbol.Declarations, func(d *ast.Node) bool { + return core.Every(symbol.Declarations(), func(d *ast.Node) bool { return !ast.IsFunctionLike(d) || c.IsDeprecatedDeclaration(d) }) } @@ -11941,7 +11941,7 @@ func (c *Checker) isUncalledFunctionReference(node *ast.Node, symbol *ast.Symbol } func (c *Checker) checkPropertyNotUsedBeforeDeclaration(prop *ast.Symbol, node *ast.Node, right *ast.Node) { - valueDeclaration := prop.ValueDeclaration + valueDeclaration := prop.ValueDeclaration() if valueDeclaration == nil || ast.GetSourceFileOfNode(node).IsDeclarationFile { return } @@ -11967,10 +11967,10 @@ func (c *Checker) isOptionalPropertyDeclaration(node *ast.Node) bool { } func (c *Checker) isPropertyDeclaredInAncestorClass(prop *ast.Symbol) bool { - if prop.Parent.Flags&ast.SymbolFlagsClass != 0 { - if baseTypes := c.getBaseTypes(c.getDeclaredTypeOfSymbol(prop.Parent)); len(baseTypes) != 0 { - superProperty := c.getPropertyOfType(baseTypes[0], prop.Name) - return superProperty != nil && superProperty.ValueDeclaration != nil + if prop.Parent().Flags()&ast.SymbolFlagsClass != 0 { + if baseTypes := c.getBaseTypes(c.getDeclaredTypeOfSymbol(prop.Parent())); len(baseTypes) != 0 { + superProperty := c.getPropertyOfType(baseTypes[0], prop.Name()) + return superProperty != nil && superProperty.ValueDeclaration() != nil } } return false @@ -12039,7 +12039,7 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup } // A class field cannot be accessed via super.* from a derived class. // This is true for both [[Set]] (old) and [[Define]] (ES spec) semantics. - if flags&ast.ModifierFlagsStatic == 0 && core.Some(prop.Declarations, isClassInstanceProperty) { + if flags&ast.ModifierFlagsStatic == 0 && core.Some(prop.Declarations(), isClassInstanceProperty) { if errorNode != nil { c.error(errorNode, diagnostics.Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super, c.symbolToString(prop)) } @@ -12051,7 +12051,7 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup isThisInitializedObjectBindingExpression(location) || ast.IsObjectBindingPattern(location.Parent) && isThisInitializedDeclaration(location.Parent.Parent)) { parentSymbol := c.getParentOfSymbol(prop) - if parentSymbol != nil && parentSymbol.Flags&ast.SymbolFlagsClass != 0 && c.isNodeUsedDuringClassInitialization(location) { + if parentSymbol != nil && parentSymbol.Flags()&ast.SymbolFlagsClass != 0 && c.isNodeUsedDuringClassInitialization(location) { if errorNode != nil { c.error(errorNode, diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, c.symbolToString(prop), c.symbolToString(parentSymbol)) } @@ -12133,17 +12133,17 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup } func (c *Checker) symbolHasNonMethodDeclaration(symbol *ast.Symbol) bool { - return c.forEachProperty(symbol, func(prop *ast.Symbol) bool { return prop.Flags&ast.SymbolFlagsMethod == 0 }) + return c.forEachProperty(symbol, func(prop *ast.Symbol) bool { return prop.Flags()&ast.SymbolFlagsMethod == 0 }) } // Invoke the callback for each underlying property symbol of the given symbol and return the first // value that isn't undefined. func (c *Checker) forEachProperty(prop *ast.Symbol, callback func(p *ast.Symbol) bool) bool { - if prop.CheckFlags&ast.CheckFlagsSynthetic == 0 { + if prop.CheckFlags()&ast.CheckFlagsSynthetic == 0 { return callback(prop) } for _, t := range c.valueSymbolLinks.Get(prop).containingType.Types() { - p := c.getPropertyOfType(t, prop.Name) + p := c.getPropertyOfType(t, prop.Name()) if p != nil && c.forEachProperty(p, callback) { return true } @@ -12153,7 +12153,7 @@ func (c *Checker) forEachProperty(prop *ast.Symbol, callback func(p *ast.Symbol) // Return the declaring class type of a property or undefined if property not declared in class func (c *Checker) getDeclaringClass(prop *ast.Symbol) *Type { - if prop.Parent != nil && prop.Parent.Flags&ast.SymbolFlagsClass != 0 { + if prop.Parent() != nil && prop.Parent().Flags()&ast.SymbolFlagsClass != 0 { return c.getDeclaredTypeOfSymbol(c.getParentOfSymbol(prop)) } return nil @@ -12298,7 +12298,7 @@ func (c *Checker) getContextualThisParameterType(fn *ast.Node) *Type { // Don't contextually type `this` as `exports` in `exports.Point = function(x, y) { this.x = x; this.y = y; }` if inJs && ast.IsIdentifier(expression) { sourceFile := ast.GetSourceFileOfNode(parent) - if sourceFile.CommonJSModuleIndicator != nil && c.getResolvedSymbol(expression).Flags&ast.SymbolFlagsModuleExports != 0 { + if sourceFile.CommonJSModuleIndicator != nil && c.getResolvedSymbol(expression).Flags()&ast.SymbolFlagsModuleExports != 0 { return nil } } @@ -12998,7 +12998,7 @@ func (c *Checker) checkAssignmentOperator(left *ast.Node, operator ast.Kind, rig if ast.IsAssignmentOperator(operator) { // We ignore assignments of undefined to CommonJS exports when there are multiple assignment declarations if ast.IsDeclarationNode(left.Parent) && ast.GetAssignmentDeclarationKind(left.Parent) == ast.JSDeclarationKindExportsProperty { - if symbol := c.symbolNodeLinks.Get(left).resolvedSymbol; symbol != nil && len(symbol.Declarations) > 1 && rightType.flags&TypeFlagsUndefined != 0 { + if symbol := c.symbolNodeLinks.Get(left).resolvedSymbol; symbol != nil && len(symbol.Declarations()) > 1 && rightType.flags&TypeFlagsUndefined != 0 { return } } @@ -13359,7 +13359,7 @@ func (c *Checker) getExactOptionalUnassignableProperties(source *Type, target *T return nil } return core.Filter(c.getPropertiesOfType(target), func(targetProp *ast.Symbol) bool { - return c.isExactOptionalPropertyMismatch(c.getTypeOfPropertyOfType(source, targetProp.Name), c.getTypeOfSymbol(targetProp)) + return c.isExactOptionalPropertyMismatch(c.getTypeOfPropertyOfType(source, targetProp.Name()), c.getTypeOfSymbol(targetProp)) }) } @@ -13383,8 +13383,8 @@ func (c *Checker) checkReferenceExpression(expr *ast.Node, invalidReferenceMessa func (c *Checker) checkObjectLiteral(node *ast.Node, checkMode CheckMode) *Type { // Expando object literals have empty properties but filled exports - if len(node.Properties()) == 0 && node.Symbol() != nil && len(node.Symbol().Exports) != 0 { - result := c.newAnonymousType(node.Symbol(), node.Symbol().Exports, nil, nil, nil) + if len(node.Properties()) == 0 && node.Symbol() != nil && len(node.Symbol().Exports()) != 0 { + result := c.newAnonymousType(node.Symbol(), node.Symbol().Exports(), nil, nil, nil) if ast.IsInJSFile(node) && !ast.IsInJsonFile(node) { result.objectFlags |= ObjectFlagsJSLiteral } @@ -13478,9 +13478,9 @@ func (c *Checker) checkObjectLiteral(node *ast.Node, checkMode CheckMode) *Type } var prop *ast.Symbol if nameType != nil { - prop = c.newSymbolEx(ast.SymbolFlagsProperty|member.Flags, getPropertyNameFromType(nameType), checkFlags|ast.CheckFlagsLate) + prop = c.newSymbolEx(ast.SymbolFlagsProperty|member.Flags(), getPropertyNameFromType(nameType), checkFlags|ast.CheckFlagsLate) } else { - prop = c.newSymbolEx(ast.SymbolFlagsProperty|member.Flags, member.Name, checkFlags) + prop = c.newSymbolEx(ast.SymbolFlagsProperty|member.Flags(), member.Name(), checkFlags) } links := c.valueSymbolLinks.Get(prop) if nameType != nil { @@ -13489,25 +13489,25 @@ func (c *Checker) checkObjectLiteral(node *ast.Node, checkMode CheckMode) *Type if inDestructuringPattern && c.hasDefaultValue(memberDecl) { // If object literal is an assignment pattern and if the assignment pattern specifies a default value // for the property, make the property optional. - prop.Flags |= ast.SymbolFlagsOptional + prop.SetFlags(prop.Flags() | ast.SymbolFlagsOptional) } else if contextualTypeHasPattern && contextualType.objectFlags&ObjectFlagsObjectLiteralPatternWithComputedProperties == 0 { // If object literal is contextually typed by the implied type of a binding pattern, and if the // binding pattern specifies a default value for the property, make the property optional. - impliedProp := c.getPropertyOfType(contextualType, member.Name) + impliedProp := c.getPropertyOfType(contextualType, member.Name()) if impliedProp != nil { - prop.Flags |= impliedProp.Flags & ast.SymbolFlagsOptional + prop.SetFlags(prop.Flags() | impliedProp.Flags()&ast.SymbolFlagsOptional) } else if c.getIndexInfoOfType(contextualType, c.stringType) == nil { c.error(memberDecl.Name(), diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, c.symbolToString(member), c.TypeToString(contextualType)) } } - prop.Declarations = member.Declarations - prop.Parent = member.Parent - prop.ValueDeclaration = member.ValueDeclaration + prop.SetDeclarations(member.Declarations()) + prop.SetParent(member.Parent()) + prop.SetValueDeclaration(member.ValueDeclaration()) links.resolvedType = t links.target = member member = prop if allPropertiesTable != nil { - allPropertiesTable[prop.Name] = prop + allPropertiesTable[prop.Name()] = prop } if contextualType != nil && checkMode&CheckModeInferential != 0 && checkMode&CheckModeSkipContextSensitive == 0 && (ast.IsPropertyAssignment(memberDecl) || ast.IsMethodDeclaration(memberDecl)) && c.isContextSensitive(memberDecl) { inferenceContext := c.getInferenceContext(node) @@ -13566,7 +13566,7 @@ func (c *Checker) checkObjectLiteral(node *ast.Node, checkMode CheckMode) *Type } } } else { - propertiesTable[member.Name] = member + propertiesTable[member.Name()] = member } propertiesArray = append(propertiesArray, member) } @@ -13610,19 +13610,19 @@ func (c *Checker) checkDeprecatedProperty(name *ast.Node, contextualType *Type) return } prop := c.getPropertyOfType(contextualType, name.Text()) - if prop == nil || len(prop.Declarations) == 0 { + if prop == nil || len(prop.Declarations()) == 0 { return } if c.isDeprecatedSymbol(prop) { - c.addDeprecatedSuggestion(name, prop.Declarations, name.Text()) + c.addDeprecatedSuggestion(name, prop.Declarations(), name.Text()) } } func (c *Checker) checkSpreadPropOverrides(t *Type, props ast.SymbolTable, spread *ast.Node) { for _, right := range c.getPropertiesOfType(t) { - if right.Flags&ast.SymbolFlagsOptional == 0 && right.CheckFlags&ast.CheckFlagsPartial == 0 { - if left := props[right.Name]; left != nil { - diagnostic := c.error(left.ValueDeclaration, diagnostics.X_0_is_specified_more_than_once_so_this_usage_will_be_overwritten, left.Name) + if right.Flags()&ast.SymbolFlagsOptional == 0 && right.CheckFlags()&ast.CheckFlagsPartial == 0 { + if left := props[right.Name()]; left != nil { + diagnostic := c.error(left.ValueDeclaration(), diagnostics.X_0_is_specified_more_than_once_so_this_usage_will_be_overwritten, left.Name()) diagnostic.AddRelatedInfo(NewDiagnosticForNode(spread, diagnostics.This_spread_always_overwrites_this_property)) } } @@ -13696,23 +13696,23 @@ func (c *Checker) getSpreadType(left *Type, right *Type, symbol *ast.Symbol, obj } for _, rightProp := range c.getPropertiesOfType(right) { if getDeclarationModifierFlagsFromSymbol(rightProp)&(ast.ModifierFlagsPrivate|ast.ModifierFlagsProtected) != 0 { - skippedPrivateMembers.Add(rightProp.Name) + skippedPrivateMembers.Add(rightProp.Name()) } else if c.isSpreadableProperty(rightProp) { - members[rightProp.Name] = c.getSpreadSymbol(rightProp, readonly) + members[rightProp.Name()] = c.getSpreadSymbol(rightProp, readonly) } } for _, leftProp := range c.getPropertiesOfType(left) { - if skippedPrivateMembers.Has(leftProp.Name) || !c.isSpreadableProperty(leftProp) { + if skippedPrivateMembers.Has(leftProp.Name()) || !c.isSpreadableProperty(leftProp) { continue } - if members[leftProp.Name] != nil { - rightProp := members[leftProp.Name] + if members[leftProp.Name()] != nil { + rightProp := members[leftProp.Name()] rightType := c.getTypeOfSymbol(rightProp) - if rightProp.Flags&ast.SymbolFlagsOptional != 0 { - declarations := core.Concatenate(leftProp.Declarations, rightProp.Declarations) - flags := ast.SymbolFlagsProperty | (leftProp.Flags & ast.SymbolFlagsOptional) - result := c.newSymbol(flags, leftProp.Name) + if rightProp.Flags()&ast.SymbolFlagsOptional != 0 { + declarations := core.Concatenate(leftProp.Declarations(), rightProp.Declarations()) + flags := ast.SymbolFlagsProperty | (leftProp.Flags() & ast.SymbolFlagsOptional) + result := c.newSymbol(flags, leftProp.Name()) links := c.valueSymbolLinks.Get(result) // Optimization: avoid calculating the union type if spreading into the exact same type. // This is common, e.g. spreading one options bag into another where the bags have the @@ -13728,12 +13728,12 @@ func (c *Checker) getSpreadType(left *Type, right *Type, symbol *ast.Symbol, obj } c.spreadLinks.Get(result).leftSpread = leftProp c.spreadLinks.Get(result).rightSpread = rightProp - result.Declarations = declarations + result.SetDeclarations(declarations) links.nameType = c.valueSymbolLinks.Get(leftProp).nameType - members[leftProp.Name] = result + members[leftProp.Name()] = result } } else { - members[leftProp.Name] = c.getSpreadSymbol(leftProp, readonly) + members[leftProp.Name()] = c.getSpreadSymbol(leftProp, readonly) } } spreadIndexInfos := core.SameMap(indexInfos, func(info *IndexInfo) *IndexInfo { @@ -13806,19 +13806,19 @@ func (c *Checker) tryMergeUnionOfObjectTypeAndEmptyObject(t *Type, readonly bool if getDeclarationModifierFlagsFromSymbol(prop)&(ast.ModifierFlagsPrivate|ast.ModifierFlagsProtected) != 0 { // do nothing, skip privates } else if c.isSpreadableProperty(prop) { - isSetonlyAccessor := prop.Flags&ast.SymbolFlagsSetAccessor != 0 && prop.Flags&ast.SymbolFlagsGetAccessor == 0 + isSetonlyAccessor := prop.Flags()&ast.SymbolFlagsSetAccessor != 0 && prop.Flags()&ast.SymbolFlagsGetAccessor == 0 flags := ast.SymbolFlagsProperty | ast.SymbolFlagsOptional - result := c.newSymbolEx(flags, prop.Name, prop.CheckFlags&ast.CheckFlagsLate|core.IfElse(readonly, ast.CheckFlagsReadonly, 0)) + result := c.newSymbolEx(flags, prop.Name(), prop.CheckFlags()&ast.CheckFlagsLate|core.IfElse(readonly, ast.CheckFlagsReadonly, 0)) links := c.valueSymbolLinks.Get(result) if isSetonlyAccessor { links.resolvedType = c.undefinedType } else { links.resolvedType = c.addOptionalityEx(c.getTypeOfSymbol(prop), true /*isProperty*/, true /*isOptional*/) } - result.Declarations = prop.Declarations + result.SetDeclarations(prop.Declarations()) links.nameType = c.valueSymbolLinks.Get(prop).nameType c.mappedSymbolLinks.Get(result).syntheticOrigin = prop - members[prop.Name] = result + members[prop.Name()] = result } } spread := c.newAnonymousType(firstType.symbol, members, nil, nil, c.getIndexInfosOfType(firstType)) @@ -13828,24 +13828,24 @@ func (c *Checker) tryMergeUnionOfObjectTypeAndEmptyObject(t *Type, readonly bool // We approximate own properties as non-methods plus methods that are inside the object literal func (c *Checker) isSpreadableProperty(prop *ast.Symbol) bool { - return !core.Some(prop.Declarations, ast.IsPrivateIdentifierClassElementDeclaration) && prop.Flags&(ast.SymbolFlagsMethod|ast.SymbolFlagsGetAccessor|ast.SymbolFlagsSetAccessor) == 0 || - !core.Some(prop.Declarations, func(d *ast.Node) bool { return d.Parent != nil && ast.IsClassLike(d.Parent) }) + return !core.Some(prop.Declarations(), ast.IsPrivateIdentifierClassElementDeclaration) && prop.Flags()&(ast.SymbolFlagsMethod|ast.SymbolFlagsGetAccessor|ast.SymbolFlagsSetAccessor) == 0 || + !core.Some(prop.Declarations(), func(d *ast.Node) bool { return d.Parent != nil && ast.IsClassLike(d.Parent) }) } func (c *Checker) getSpreadSymbol(prop *ast.Symbol, readonly bool) *ast.Symbol { - isSetonlyAccessor := prop.Flags&ast.SymbolFlagsSetAccessor != 0 && prop.Flags&ast.SymbolFlagsGetAccessor == 0 + isSetonlyAccessor := prop.Flags()&ast.SymbolFlagsSetAccessor != 0 && prop.Flags()&ast.SymbolFlagsGetAccessor == 0 if !isSetonlyAccessor && readonly == c.isReadonlySymbol(prop) { return prop } - flags := ast.SymbolFlagsProperty | (prop.Flags & ast.SymbolFlagsOptional) - result := c.newSymbolEx(flags, prop.Name, prop.CheckFlags&ast.CheckFlagsLate|core.IfElse(readonly, ast.CheckFlagsReadonly, 0)) + flags := ast.SymbolFlagsProperty | (prop.Flags() & ast.SymbolFlagsOptional) + result := c.newSymbolEx(flags, prop.Name(), prop.CheckFlags()&ast.CheckFlagsLate|core.IfElse(readonly, ast.CheckFlagsReadonly, 0)) links := c.valueSymbolLinks.Get(result) if isSetonlyAccessor { links.resolvedType = c.undefinedType } else { links.resolvedType = c.getTypeOfSymbol(prop) } - result.Declarations = prop.Declarations + result.SetDeclarations(prop.Declarations()) links.nameType = c.valueSymbolLinks.Get(prop).nameType c.mappedSymbolLinks.Get(result).syntheticOrigin = prop return result @@ -13904,7 +13904,7 @@ func (c *Checker) isValidConstAssertionArgument(node *ast.Node) bool { if ast.IsEntityNameExpression(expr) { symbol = c.resolveEntityName(expr, ast.SymbolFlagsValue, true /*ignoreErrors*/, false, nil) } - return symbol != nil && symbol.Flags&ast.SymbolFlagsEnum != 0 + return symbol != nil && symbol.Flags()&ast.SymbolFlagsEnum != 0 } return false } @@ -13915,7 +13915,7 @@ func (c *Checker) isConstTypeVariable(t *Type, depth int) bool { } switch { case t.flags&TypeFlagsTypeParameter != 0: - return t.symbol != nil && core.Some(t.symbol.Declarations, func(d *ast.Node) bool { return ast.HasSyntacticModifier(d, ast.ModifierFlagsConst) }) + return t.symbol != nil && core.Some(t.symbol.Declarations(), func(d *ast.Node) bool { return ast.HasSyntacticModifier(d, ast.ModifierFlagsConst) }) case t.flags&TypeFlagsUnionOrIntersection != 0: return core.Some(t.Types(), func(s *Type) bool { return c.isConstTypeVariable(s, depth) }) case t.flags&TypeFlagsIndexedAccess != 0: @@ -13989,7 +13989,7 @@ func (c *Checker) isInPropertyInitializerOrClassStaticBlock(node *ast.Node, igno func (c *Checker) getNarrowedTypeOfSymbol(symbol *ast.Symbol, location *ast.Node) *Type { t := c.getTypeOfSymbol(symbol) - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() if declaration != nil { switch { // If we have a non-rest binding element with no initializer declared as a const variable or a const-like @@ -14101,8 +14101,8 @@ func (c *Checker) isReadonlyAssignmentDeclaration(node *ast.Node) bool { if valueType := c.getTypeOfPropertyOfType(propertyDescriptorType, "value"); valueType != nil { if writableProp := c.getPropertyOfType(propertyDescriptorType, "writable"); writableProp != nil { var writableType *Type - if writableProp.ValueDeclaration != nil && ast.IsPropertyAssignment(writableProp.ValueDeclaration) { - writableType = c.checkExpression(writableProp.ValueDeclaration.Initializer()) + if writableProp.ValueDeclaration() != nil && ast.IsPropertyAssignment(writableProp.ValueDeclaration()) { + writableType = c.checkExpression(writableProp.ValueDeclaration().Initializer()) } else { writableType = c.getTypeOfSymbol(writableProp) } @@ -14121,12 +14121,12 @@ func (c *Checker) isReadonlySymbol(symbol *ast.Symbol) bool { // Enum members // Object.defineProperty assignments with writable false or no setter // Unions and intersections of the above (unions and intersections eagerly set isReadonly on creation) - return symbol.CheckFlags&ast.CheckFlagsReadonly != 0 || - symbol.Flags&ast.SymbolFlagsProperty != 0 && getDeclarationModifierFlagsFromSymbol(symbol)&ast.ModifierFlagsReadonly != 0 || - symbol.Flags&ast.SymbolFlagsVariable != 0 && c.getDeclarationNodeFlagsFromSymbol(symbol)&ast.NodeFlagsConstant != 0 || - symbol.Flags&ast.SymbolFlagsAccessor != 0 && symbol.Flags&ast.SymbolFlagsSetAccessor == 0 || - symbol.Flags&ast.SymbolFlagsEnumMember != 0 || - core.Some(symbol.Declarations, c.isReadonlyAssignmentDeclaration) + return symbol.CheckFlags()&ast.CheckFlagsReadonly != 0 || + symbol.Flags()&ast.SymbolFlagsProperty != 0 && getDeclarationModifierFlagsFromSymbol(symbol)&ast.ModifierFlagsReadonly != 0 || + symbol.Flags()&ast.SymbolFlagsVariable != 0 && c.getDeclarationNodeFlagsFromSymbol(symbol)&ast.NodeFlagsConstant != 0 || + symbol.Flags()&ast.SymbolFlagsAccessor != 0 && symbol.Flags()&ast.SymbolFlagsSetAccessor == 0 || + symbol.Flags()&ast.SymbolFlagsEnumMember != 0 || + core.Some(symbol.Declarations(), c.isReadonlyAssignmentDeclaration) } func (c *Checker) checkObjectLiteralMethod(node *ast.Node, checkMode CheckMode) *Type { @@ -14320,14 +14320,14 @@ func (c *Checker) addDeprecatedSuggestionWorker(declarations []*ast.Node, diagno func (c *Checker) isDeprecatedSymbol(symbol *ast.Symbol) bool { parentSymbol := c.getParentOfSymbol(symbol) - if parentSymbol != nil && len(symbol.Declarations) > 1 { - if parentSymbol.Flags&ast.SymbolFlagsInterface != 0 { - return core.Some(symbol.Declarations, c.IsDeprecatedDeclaration) + if parentSymbol != nil && len(symbol.Declarations()) > 1 { + if parentSymbol.Flags()&ast.SymbolFlagsInterface != 0 { + return core.Some(symbol.Declarations(), c.IsDeprecatedDeclaration) } else { - return core.Every(symbol.Declarations, c.IsDeprecatedDeclaration) + return core.Every(symbol.Declarations(), c.IsDeprecatedDeclaration) } } - return symbol.ValueDeclaration != nil && c.IsDeprecatedDeclaration(symbol.ValueDeclaration) || len(symbol.Declarations) != 0 && core.Every(symbol.Declarations, c.IsDeprecatedDeclaration) + return symbol.ValueDeclaration() != nil && c.IsDeprecatedDeclaration(symbol.ValueDeclaration()) || len(symbol.Declarations()) != 0 && core.Every(symbol.Declarations(), c.IsDeprecatedDeclaration) } func (c *Checker) hasParseDiagnostics(sourceFile *ast.SourceFile) bool { @@ -14337,14 +14337,14 @@ func (c *Checker) hasParseDiagnostics(sourceFile *ast.SourceFile) bool { func (c *Checker) newSymbol(flags ast.SymbolFlags, name string) *ast.Symbol { c.SymbolCount++ result := c.symbolArena.New() - result.Flags = flags | ast.SymbolFlagsTransient - result.Name = name + result.SetFlags(flags | ast.SymbolFlagsTransient) + result.SetName(name) return result } func (c *Checker) newSymbolEx(flags ast.SymbolFlags, name string, checkFlags ast.CheckFlags) *ast.Symbol { result := c.newSymbol(flags, name) - result.CheckFlags = checkFlags + result.SetCheckFlags(checkFlags) return result } @@ -14398,8 +14398,8 @@ func (c *Checker) mergeSymbolTable(target ast.SymbolTable, source ast.SymbolTabl // When merging the module augmentation into a.ts, the symbol for `A` will itself be merged, so its parent // should be the merged module symbol. But the symbol for `B` has only one declaration, so its parent should // be the module augmentation symbol, which contains its only declaration. - if merged.Flags&ast.SymbolFlagsTransient != 0 { - merged.Parent = mergedParent + if merged.Flags()&ast.SymbolFlagsTransient != 0 { + merged.SetParent(mergedParent) } } target[id] = merged @@ -14411,18 +14411,18 @@ func (c *Checker) mergeSymbolTable(target ast.SymbolTable, source ast.SymbolTabl * If target is not transient, mergeSymbol will produce a transient clone, mutate that and return it. */ func (c *Checker) mergeSymbol(target *ast.Symbol, source *ast.Symbol, unidirectional bool) *ast.Symbol { - if target.Flags&getExcludedSymbolFlags(source.Flags) == 0 || (source.Flags|target.Flags)&ast.SymbolFlagsAssignment != 0 { + if target.Flags()&getExcludedSymbolFlags(source.Flags()) == 0 || (source.Flags()|target.Flags())&ast.SymbolFlagsAssignment != 0 { if source == target { // This can happen when an export assigned namespace exports something also erroneously exported at the top level // See `declarationFileNoCrashOnExtraExportModifier` for an example return target } - if target.Flags&ast.SymbolFlagsTransient == 0 { + if target.Flags()&ast.SymbolFlagsTransient == 0 { resolvedTarget := c.resolveSymbol(target) if resolvedTarget == c.unknownSymbol { return source } - if resolvedTarget.Flags&getExcludedSymbolFlags(source.Flags) == 0 || (source.Flags|resolvedTarget.Flags)&ast.SymbolFlagsAssignment != 0 { + if resolvedTarget.Flags()&getExcludedSymbolFlags(source.Flags()) == 0 || (source.Flags()|resolvedTarget.Flags())&ast.SymbolFlagsAssignment != 0 { target = c.cloneSymbol(resolvedTarget) } else { c.reportMergeSymbolError(target, source) @@ -14430,29 +14430,29 @@ func (c *Checker) mergeSymbol(target *ast.Symbol, source *ast.Symbol, unidirecti } } // Javascript static-property-assignment declarations always merge, even though they are also values - if source.Flags&ast.SymbolFlagsValueModule != 0 && target.Flags&ast.SymbolFlagsValueModule != 0 && target.Flags&ast.SymbolFlagsConstEnumOnlyModule != 0 && source.Flags&ast.SymbolFlagsConstEnumOnlyModule == 0 { + if source.Flags()&ast.SymbolFlagsValueModule != 0 && target.Flags()&ast.SymbolFlagsValueModule != 0 && target.Flags()&ast.SymbolFlagsConstEnumOnlyModule != 0 && source.Flags()&ast.SymbolFlagsConstEnumOnlyModule == 0 { // reset flag when merging instantiated module into value module that has only const enums - target.Flags &^= ast.SymbolFlagsConstEnumOnlyModule + target.SetFlags(target.Flags() &^ ast.SymbolFlagsConstEnumOnlyModule) } - sourceFlags := source.Flags - if target.Flags&ast.SymbolFlagsConstEnumOnlyModule == 0 { + sourceFlags := source.Flags() + if target.Flags()&ast.SymbolFlagsConstEnumOnlyModule == 0 { sourceFlags &^= ast.SymbolFlagsConstEnumOnlyModule } - target.Flags |= sourceFlags - if source.ValueDeclaration != nil { - binder.SetValueDeclaration(target, source.ValueDeclaration) + target.SetFlags(target.Flags() | sourceFlags) + if source.ValueDeclaration() != nil { + binder.SetValueDeclaration(target, source.ValueDeclaration()) } - target.Declarations = append(target.Declarations, source.Declarations...) - if source.Members != nil { - c.mergeSymbolTable(ast.GetSymbolTable(&target.Members), source.Members, unidirectional, nil) + target.SetDeclarations(append(target.Declarations(), source.Declarations()...)) + if source.Members() != nil { + c.mergeSymbolTable(ast.GetMembers(target), source.Members(), unidirectional, nil) } - if source.Exports != nil { - c.mergeSymbolTable(ast.GetSymbolTable(&target.Exports), source.Exports, unidirectional, target) + if source.Exports() != nil { + c.mergeSymbolTable(ast.GetExports(target), source.Exports(), unidirectional, target) } if !unidirectional { c.recordMergedSymbol(target, source) } - } else if target.Flags&ast.SymbolFlagsNamespaceModule != 0 { + } else if target.Flags()&ast.SymbolFlagsNamespaceModule != 0 { // Do not report an error when merging `var globalThis` with the built-in `globalThis`, // as we will already report a "Declaration name conflicts..." error, and this error // won't make much sense. @@ -14466,8 +14466,8 @@ func (c *Checker) mergeSymbol(target *ast.Symbol, source *ast.Symbol, unidirecti } func (c *Checker) reportMergeSymbolError(target *ast.Symbol, source *ast.Symbol) { - isEitherEnum := target.Flags&ast.SymbolFlagsEnum != 0 || source.Flags&ast.SymbolFlagsEnum != 0 - isEitherBlockScoped := target.Flags&ast.SymbolFlagsBlockScopedVariable != 0 || source.Flags&ast.SymbolFlagsBlockScopedVariable != 0 + isEitherEnum := target.Flags()&ast.SymbolFlagsEnum != 0 || source.Flags()&ast.SymbolFlagsEnum != 0 + isEitherBlockScoped := target.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 || source.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 var message *diagnostics.Message switch { case isEitherEnum: @@ -14491,8 +14491,8 @@ func (c *Checker) reportMergeSymbolError(target *ast.Symbol, source *ast.Symbol) } func (c *Checker) addDuplicateDeclarationErrorsForSymbols(target *ast.Symbol, message *diagnostics.Message, symbolName string, source *ast.Symbol) { - for _, node := range target.Declarations { - c.addDuplicateDeclarationError(node, message, symbolName, source.Declarations) + for _, node := range target.Declarations() { + c.addDuplicateDeclarationError(node, message, symbolName, source.Declarations()) } } @@ -14539,8 +14539,8 @@ func (c *Checker) lookupOrIssueError(location *ast.Node, message *diagnostics.Me } func getFirstDeclaration(symbol *ast.Symbol) *ast.Node { - if len(symbol.Declarations) > 0 { - return symbol.Declarations[0] + if len(symbol.Declarations()) > 0 { + return symbol.Declarations()[0] } return nil } @@ -14602,13 +14602,13 @@ func getExcludedSymbolFlags(flags ast.SymbolFlags) ast.SymbolFlags { } func (c *Checker) cloneSymbol(symbol *ast.Symbol) *ast.Symbol { - result := c.newSymbol(symbol.Flags, symbol.Name) + result := c.newSymbol(symbol.Flags(), symbol.Name()) // Force reallocation if anything is ever appended to declarations - result.Declarations = symbol.Declarations[0:len(symbol.Declarations):len(symbol.Declarations)] - result.Parent = symbol.Parent - result.ValueDeclaration = symbol.ValueDeclaration - result.Members = maps.Clone(symbol.Members) - result.Exports = maps.Clone(symbol.Exports) + result.SetDeclarations(symbol.Declarations()[0:len(symbol.Declarations()):len(symbol.Declarations())]) + result.SetParent(symbol.Parent()) + result.SetValueDeclaration(symbol.ValueDeclaration()) + result.SetMembers(maps.Clone(symbol.Members())) + result.SetExports(maps.Clone(symbol.Exports())) c.recordMergedSymbol(result, symbol) return result } @@ -14624,8 +14624,8 @@ func (c *Checker) getMergedSymbol(symbol *ast.Symbol) *ast.Symbol { } func (c *Checker) getParentOfSymbol(symbol *ast.Symbol) *ast.Symbol { - if symbol.Parent != nil { - return c.getMergedSymbol(c.getLateBoundSymbol(symbol.Parent)) + if symbol.Parent() != nil { + return c.getMergedSymbol(c.getLateBoundSymbol(symbol.Parent())) } return nil } @@ -14642,8 +14642,8 @@ func (c *Checker) getSymbolIfSameReference(s1 *ast.Symbol, s2 *ast.Symbol) *ast. } func (c *Checker) getExportSymbolOfValueSymbolIfExported(symbol *ast.Symbol) *ast.Symbol { - if symbol != nil && symbol.Flags&ast.SymbolFlagsExportValue != 0 && symbol.ExportSymbol != nil { - symbol = symbol.ExportSymbol + if symbol != nil && symbol.Flags()&ast.SymbolFlagsExportValue != 0 && symbol.ExportSymbol() != nil { + symbol = symbol.ExportSymbol() } return c.getMergedSymbol(symbol) } @@ -14667,14 +14667,14 @@ func (c *Checker) getSymbolOfNode(node *ast.Node) *ast.Symbol { } func (c *Checker) getLateBoundSymbol(symbol *ast.Symbol) *ast.Symbol { - if symbol.Flags&ast.SymbolFlagsClassMember == 0 || symbol.Name != ast.InternalSymbolNameComputed { + if symbol.Flags()&ast.SymbolFlagsClassMember == 0 || symbol.Name() != ast.InternalSymbolNameComputed { return symbol } links := c.lateBoundLinks.Get(symbol) - if links.lateSymbol == nil && core.Some(symbol.Declarations, c.hasLateBindableName) { + if links.lateSymbol == nil && core.Some(symbol.Declarations(), c.hasLateBindableName) { // force late binding of members/exports. This will set the late-bound symbol - parent := c.getMergedSymbol(symbol.Parent) - if core.Some(symbol.Declarations, ast.HasStaticModifier) { + parent := c.getMergedSymbol(symbol.Parent()) + if core.Some(symbol.Declarations(), ast.HasStaticModifier) { c.getExportsOfSymbol(parent) } else { c.getMembersOfSymbol(parent) @@ -14792,7 +14792,7 @@ func (c *Checker) getTargetOfImportClause(node *ast.Node) *ast.Symbol { links := c.aliasSymbolLinks.Get(alias) if links.immediateTarget == nil { symbol := c.newSymbol(ast.SymbolFlagsFunctionScopedVariable, node.Name().Text()) - symbol.Declarations = alias.Declarations + symbol.SetDeclarations(alias.Declarations()) c.valueSymbolLinks.Get(symbol).resolvedType = c.getGlobalAbstractModuleSourceType() links.immediateTarget = symbol } @@ -14806,7 +14806,7 @@ func (c *Checker) getTargetOfImportClause(node *ast.Node) *ast.Symbol { } func (c *Checker) getTargetOfModuleDefault(moduleSymbol *ast.Symbol, node *ast.Node, dontResolveAlias bool) *ast.Symbol { - file := core.Find(moduleSymbol.Declarations, ast.IsSourceFile) + file := core.Find(moduleSymbol.Declarations(), ast.IsSourceFile) specifier := c.getModuleSpecifierForImportOrExport(node) var exportDefaultSymbol *ast.Symbol var exportModuleDotExportsSymbol *ast.Symbol @@ -14870,21 +14870,21 @@ func (c *Checker) getTargetOfModuleDefault(moduleSymbol *ast.Symbol, node *ast.N } func (c *Checker) reportNonDefaultExport(moduleSymbol *ast.Symbol, node *ast.Node) { - if moduleSymbol.Exports != nil && moduleSymbol.Exports[node.Symbol().Name] != nil { + if moduleSymbol.Exports() != nil && moduleSymbol.Exports()[node.Symbol().Name()] != nil { c.error(node, diagnostics.Module_0_has_no_default_export_Did_you_mean_to_use_import_1_from_0_instead, c.symbolToString(moduleSymbol), c.symbolToString(node.Symbol())) } else { diagnostic := c.error(node.Name(), diagnostics.Module_0_has_no_default_export, c.symbolToString(moduleSymbol)) var exportStar *ast.Symbol - if moduleSymbol.Exports != nil { - exportStar = moduleSymbol.Exports[ast.InternalSymbolNameExportStar] + if moduleSymbol.Exports() != nil { + exportStar = moduleSymbol.Exports()[ast.InternalSymbolNameExportStar] } if exportStar != nil { - defaultExport := core.Find(exportStar.Declarations, func(decl *ast.Declaration) bool { + defaultExport := core.Find(exportStar.Declarations(), func(decl *ast.Declaration) bool { if !(ast.IsExportDeclaration(decl) && decl.ModuleSpecifier() != nil) { return false } resolvedExternalModuleName := c.resolveExternalModuleName(decl, decl.ModuleSpecifier(), false /*ignoreErrors*/, c.getTypeFromImportAttributes(ast.GetImportAttributes(decl))) - return resolvedExternalModuleName != nil && resolvedExternalModuleName.Exports[ast.InternalSymbolNameDefault] != nil + return resolvedExternalModuleName != nil && resolvedExternalModuleName.Exports()[ast.InternalSymbolNameDefault] != nil }) if defaultExport != nil { diagnostic.AddRelatedInfo(createDiagnosticForNode(defaultExport, diagnostics.X_export_Asterisk_does_not_re_export_a_default)) @@ -14894,12 +14894,12 @@ func (c *Checker) reportNonDefaultExport(moduleSymbol *ast.Symbol, node *ast.Nod } func (c *Checker) resolveExportByName(moduleSymbol *ast.Symbol, name string, sourceNode *ast.Node, dontResolveAlias bool) *ast.Symbol { - exportValue := moduleSymbol.Exports[ast.InternalSymbolNameExportEquals] + exportValue := moduleSymbol.Exports()[ast.InternalSymbolNameExportEquals] var exportSymbol *ast.Symbol if exportValue != nil { exportSymbol = c.getPropertyOfTypeEx(c.getTypeOfSymbol(exportValue), name, true /*skipObjectFunctionPropertyAugment*/, false /*includeTypeOnlyMembers*/) } else { - exportSymbol = moduleSymbol.Exports[name] + exportSymbol = moduleSymbol.Exports()[name] } resolved := c.resolveSymbolEx(exportSymbol, dontResolveAlias) c.markSymbolOfAliasDeclarationIfTypeOnly(sourceNode, nil) @@ -14981,7 +14981,7 @@ func (c *Checker) getExternalModuleMember(node *ast.Node, specifier *ast.Node, d } var symbolFromVariable *ast.Symbol // First check if module was specified with "export=". If so, get the member from the resolved type - if moduleSymbol != nil && moduleSymbol.Exports[ast.InternalSymbolNameExportEquals] != nil { + if moduleSymbol != nil && moduleSymbol.Exports()[ast.InternalSymbolNameExportEquals] != nil { symbolFromVariable = c.getPropertyOfTypeEx(c.getTypeOfSymbol(targetSymbol), nameText, true /*skipObjectFunctionPropertyAugment*/, false /*includeTypeOnlyMembers*/) } else { symbolFromVariable = c.getPropertyOfVariable(targetSymbol, nameText) @@ -14989,13 +14989,13 @@ func (c *Checker) getExternalModuleMember(node *ast.Node, specifier *ast.Node, d // if symbolFromVariable is export - get its final target symbolFromVariable = c.resolveSymbolEx(symbolFromVariable, dontResolveAlias) exportContainer := targetSymbol - if moduleSymbol != nil && moduleSymbol.Exports[ast.InternalSymbolNameExportEquals] != nil { + if moduleSymbol != nil && moduleSymbol.Exports()[ast.InternalSymbolNameExportEquals] != nil { // For `export =` modules, supplemental type/namespace exports live on the original module symbol. exportContainer = moduleSymbol } symbolFromModule := c.getExportOfModule(exportContainer, nameText, specifier, dontResolveAlias) if symbolFromModule == nil && nameText == ast.InternalSymbolNameDefault { - file := core.Find(moduleSymbol.Declarations, ast.IsSourceFile) + file := core.Find(moduleSymbol.Declarations(), ast.IsSourceFile) if c.isOnlyImportableAsDefault(moduleSpecifier, moduleSymbol, importAttributesType) || c.canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier) { symbolFromModule = c.resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) if symbolFromModule == nil { @@ -15022,8 +15022,8 @@ func (c *Checker) getExternalModuleMember(node *ast.Node, specifier *ast.Node, d } func (c *Checker) getPropertyOfVariable(symbol *ast.Symbol, name string) *ast.Symbol { - if symbol.Flags&ast.SymbolFlagsVariable != 0 { - typeAnnotation := symbol.ValueDeclaration.Type() + if symbol.Flags()&ast.SymbolFlagsVariable != 0 { + typeAnnotation := symbol.ValueDeclaration().Type() if typeAnnotation != nil { return c.resolveSymbol(c.getPropertyOfType(c.getTypeFromTypeNode(typeAnnotation), name)) } @@ -15053,27 +15053,27 @@ func (c *Checker) combineValueAndTypeSymbols(valueSymbol *ast.Symbol, typeSymbol if valueSymbol == c.unknownSymbol && typeSymbol == c.unknownSymbol { return c.unknownSymbol } - if typeSymbol.Flags&ast.SymbolFlagsValue != 0 { + if typeSymbol.Flags()&ast.SymbolFlagsValue != 0 { return typeSymbol } - if valueSymbol.Flags&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 { + if valueSymbol.Flags()&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 { return valueSymbol } - result := c.newSymbol(valueSymbol.Flags|typeSymbol.Flags, valueSymbol.Name) - debug.Assert(len(valueSymbol.Declarations) > 0 || len(typeSymbol.Declarations) > 0) - result.Declarations = slices.Compact(slices.Concat(valueSymbol.Declarations, typeSymbol.Declarations)) - result.Parent = valueSymbol.Parent - if result.Parent == nil { - result.Parent = typeSymbol.Parent + result := c.newSymbol(valueSymbol.Flags()|typeSymbol.Flags(), valueSymbol.Name()) + debug.Assert(len(valueSymbol.Declarations()) > 0 || len(typeSymbol.Declarations()) > 0) + result.SetDeclarations(slices.Compact(slices.Concat(valueSymbol.Declarations(), typeSymbol.Declarations()))) + result.SetParent(valueSymbol.Parent()) + if result.Parent() == nil { + result.SetParent(typeSymbol.Parent()) } - result.ValueDeclaration = valueSymbol.ValueDeclaration - result.Members = maps.Clone(typeSymbol.Members) - result.Exports = maps.Clone(valueSymbol.Exports) + result.SetValueDeclaration(valueSymbol.ValueDeclaration()) + result.SetMembers(maps.Clone(typeSymbol.Members())) + result.SetExports(maps.Clone(valueSymbol.Exports())) return result } func (c *Checker) getExportOfModule(symbol *ast.Symbol, nameText string, specifier *ast.Node, dontResolveAlias bool) *ast.Symbol { - if symbol.Flags&ast.SymbolFlagsModule != 0 { + if symbol.Flags()&ast.SymbolFlagsModule != 0 { exportSymbol := c.getExportsOfSymbol(symbol)[nameText] resolved := c.resolveSymbolEx(exportSymbol, dontResolveAlias) exportStarDeclaration := c.moduleSymbolLinks.Get(symbol).typeOnlyExportStarMap[nameText] @@ -15136,7 +15136,7 @@ func (c *Checker) canHaveSyntheticDefault(file *ast.Node, moduleSymbol *ast.Symb if file == nil || file.AsSourceFile().IsDeclarationFile { // Definitely cannot have a synthetic default if they have a syntactic default member specified defaultExportSymbol := c.resolveExportByName(moduleSymbol, ast.InternalSymbolNameDefault /*sourceNode*/, nil /*dontResolveAlias*/, true) // Dont resolve alias because we want the immediately exported symbol's declaration - if defaultExportSymbol != nil && core.Some(defaultExportSymbol.Declarations, isSyntacticDefault) { + if defaultExportSymbol != nil && core.Some(defaultExportSymbol.Declarations(), isSyntacticDefault) { return false } // It _might_ still be incorrect to assume there is no __esModule marker on the import at runtime, even if there is no `default` member @@ -15180,11 +15180,11 @@ func (c *Checker) errorNoModuleMemberSymbol(moduleSymbol *ast.Symbol, targetSymb if suggestion != nil { suggestionName := c.symbolToString(suggestion) diagnostic := c.error(name, diagnostics.X_0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName) - if suggestion.ValueDeclaration != nil { - diagnostic.AddRelatedInfo(createDiagnosticForNode(suggestion.ValueDeclaration, diagnostics.X_0_is_declared_here, suggestionName)) + if suggestion.ValueDeclaration() != nil { + diagnostic.AddRelatedInfo(createDiagnosticForNode(suggestion.ValueDeclaration(), diagnostics.X_0_is_declared_here, suggestionName)) } } else { - if moduleSymbol.Exports[ast.InternalSymbolNameDefault] != nil { + if moduleSymbol.Exports()[ast.InternalSymbolNameDefault] != nil { c.error(name, diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName) } else { c.reportNonExportedMember(name, declarationName, moduleSymbol, moduleName) @@ -15194,10 +15194,10 @@ func (c *Checker) errorNoModuleMemberSymbol(moduleSymbol *ast.Symbol, targetSymb func (c *Checker) reportNonExportedMember(name *ast.Node, declarationName string, moduleSymbol *ast.Symbol, moduleName string) { var localSymbol *ast.Symbol - if locals := moduleSymbol.ValueDeclaration.Locals(); locals != nil { + if locals := moduleSymbol.ValueDeclaration().Locals(); locals != nil { localSymbol = locals[name.Text()] } - exports := moduleSymbol.Exports + exports := moduleSymbol.Exports() if localSymbol != nil { if exportedEqualsSymbol := exports[ast.InternalSymbolNameExportEquals]; exportedEqualsSymbol != nil { if c.getSymbolIfSameReference(exportedEqualsSymbol, localSymbol) != nil { @@ -15215,7 +15215,7 @@ func (c *Checker) reportNonExportedMember(name *ast.Node, declarationName string } else { diagnostic = c.error(name, diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName) } - for i, decl := range localSymbol.Declarations { + for i, decl := range localSymbol.Declarations() { diagnostic.AddRelatedInfo(createDiagnosticForNode(decl, core.IfElse(i == 0, diagnostics.X_0_is_declared_here, diagnostics.X_and_here), declarationName)) } } @@ -15933,7 +15933,7 @@ func (c *Checker) GetAmbientModules() []*ast.Symbol { func (c *Checker) resolveExternalModuleSymbol(moduleSymbol *ast.Symbol, dontResolveAlias bool) *ast.Symbol { if moduleSymbol != nil { - exportEquals := c.resolveSymbolEx(moduleSymbol.Exports[ast.InternalSymbolNameExportEquals], dontResolveAlias) + exportEquals := c.resolveSymbolEx(moduleSymbol.Exports()[ast.InternalSymbolNameExportEquals], dontResolveAlias) if exportEquals != nil { return c.getMergedSymbol(exportEquals) } @@ -15968,7 +15968,7 @@ func (c *Checker) resolveESModuleSymbol(moduleSymbol *ast.Symbol, node *ast.Node return c.cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent) } - targetFile := core.Find(moduleSymbol.Declarations, ast.IsSourceFile) + targetFile := core.Find(moduleSymbol.Declarations(), ast.IsSourceFile) usageMode := c.getEmitSyntaxForModuleSpecifierExpression(reference) var exportModuleDotExportsSymbol *ast.Symbol if namespaceImport != nil && targetFile != nil && @@ -15990,7 +15990,7 @@ func (c *Checker) resolveESModuleSymbol(moduleSymbol *ast.Symbol, node *ast.Node if typ.Flags()&TypeFlagsStructuredType != 0 { moduleType = c.getTypeWithSyntheticDefaultImportType(typ, symbol, moduleSymbol, reference) } else { - moduleType = c.createDefaultPropertyWrapperForModule(symbol, symbol.Parent, nil) + moduleType = c.createDefaultPropertyWrapperForModule(symbol, symbol.Parent(), nil) } return c.cloneTypeAsModuleType(symbol, moduleType, referenceParent) } @@ -16027,12 +16027,12 @@ func (c *Checker) getTypeWithSyntheticDefaultImportType(t *Type, symbol *ast.Sym if cached := c.cachedTypes[key]; cached != nil { return cached } - file := core.Find(originalSymbol.Declarations, ast.IsSourceFile) + file := core.Find(originalSymbol.Declarations(), ast.IsSourceFile) hasSyntheticDefault := c.canHaveSyntheticDefault(file, originalSymbol, false /*dontResolveAlias*/, moduleSpecifier) var syntheticType *Type if hasSyntheticDefault { anonymousSymbol := c.newSymbol(ast.SymbolFlagsTypeLiteral, ast.InternalSymbolNameType) - anonymousSymbol.Declarations = originalSymbol.Declarations + anonymousSymbol.SetDeclarations(originalSymbol.Declarations()) defaultContainingObject := c.createDefaultPropertyWrapperForModule(symbol, originalSymbol, anonymousSymbol) c.valueSymbolLinks.Get(anonymousSymbol).resolvedType = defaultContainingObject if c.isValidSpreadType(t) { @@ -16062,14 +16062,14 @@ func (c *Checker) isCommonJSRequire(node *ast.Node) bool { return true } // project includes symbol named 'require' - make sure that it is ambient and local non-alias - if resolvedRequire == nil || resolvedRequire.Flags&ast.SymbolFlagsAlias != 0 { + if resolvedRequire == nil || resolvedRequire.Flags()&ast.SymbolFlagsAlias != 0 { return false } var targetDeclarationKind ast.Kind - if resolvedRequire.Flags&ast.SymbolFlagsFunction != 0 { + if resolvedRequire.Flags()&ast.SymbolFlagsFunction != 0 { targetDeclarationKind = ast.KindFunctionDeclaration - } else if resolvedRequire.Flags&ast.SymbolFlagsVariable != 0 { + } else if resolvedRequire.Flags()&ast.SymbolFlagsVariable != 0 { targetDeclarationKind = ast.KindVariableDeclaration } else { targetDeclarationKind = ast.KindUnknown @@ -16085,24 +16085,24 @@ func (c *Checker) isCommonJSRequire(node *ast.Node) bool { func (c *Checker) createDefaultPropertyWrapperForModule(symbol *ast.Symbol, originalSymbol *ast.Symbol, anonymousSymbol *ast.Symbol) *Type { memberTable := make(ast.SymbolTable) newSymbol := c.newSymbol(ast.SymbolFlagsAlias, ast.InternalSymbolNameDefault) - newSymbol.Parent = originalSymbol + newSymbol.SetParent(originalSymbol) c.valueSymbolLinks.Get(newSymbol).nameType = c.getStringLiteralType("default") c.aliasSymbolLinks.Get(newSymbol).aliasTarget = c.resolveSymbol(symbol) memberTable[ast.InternalSymbolNameDefault] = newSymbol if anonymousSymbol == nil && originalSymbol != nil { anonymousSymbol = c.newSymbol(ast.SymbolFlagsObjectLiteral, ast.InternalSymbolNameObject) - anonymousSymbol.Declarations = originalSymbol.Declarations + anonymousSymbol.SetDeclarations(originalSymbol.Declarations()) } return c.newAnonymousType(anonymousSymbol, memberTable, nil, nil, nil) } func (c *Checker) cloneTypeAsModuleType(symbol *ast.Symbol, moduleType *Type, referenceParent *ast.Node) *ast.Symbol { - result := c.newSymbol(symbol.Flags, symbol.Name) - result.Declarations = slices.Clone(symbol.Declarations) - result.ValueDeclaration = symbol.ValueDeclaration - result.Members = maps.Clone(symbol.Members) - result.Exports = maps.Clone(symbol.Exports) - result.Parent = symbol.Parent + result := c.newSymbol(symbol.Flags(), symbol.Name()) + result.SetDeclarations(slices.Clone(symbol.Declarations())) + result.SetValueDeclaration(symbol.ValueDeclaration()) + result.SetMembers(maps.Clone(symbol.Members())) + result.SetExports(maps.Clone(symbol.Exports())) + result.SetParent(symbol.Parent()) links := c.exportTypeLinks.Get(result) links.target = symbol links.originatingImport = referenceParent @@ -16170,9 +16170,9 @@ func (c *Checker) resolveEntityName(name *ast.Node, meaning ast.SymbolFlags, ign symbol = c.getMergedSymbol(c.resolveName(resolveLocation, name.Text(), meaning, nil, true /*isUse*/, false /*excludeGlobals*/)) if symbol == nil { alias := c.getMergedSymbol(c.resolveName(resolveLocation, name.Text(), ast.SymbolFlagsAlias, nil, true /*isUse*/, false /*excludeGlobals*/)) - if alias != nil && alias.Name == ast.InternalSymbolNameExportEquals { + if alias != nil && alias.Name() == ast.InternalSymbolNameExportEquals { // resolve typedefs exported from commonjs, stored on the module symbol - symbol = alias.Parent + symbol = alias.Parent() } } if symbol == nil && message != nil { @@ -16192,11 +16192,11 @@ func (c *Checker) resolveEntityName(name *ast.Node, meaning ast.SymbolFlags, ign } if symbol != nil && symbol != c.unknownSymbol { if !ast.NodeIsSynthesized(name) && ast.IsEntityName(name) && - (symbol.Flags&ast.SymbolFlagsAlias != 0 || name.Parent != nil && name.Parent.Kind == ast.KindExportAssignment) { + (symbol.Flags()&ast.SymbolFlagsAlias != 0 || name.Parent != nil && name.Parent.Kind == ast.KindExportAssignment) { c.markSymbolOfAliasDeclarationIfTypeOnly(getAliasDeclarationFromName(name), nil) } // We know a symbol with the given meaning exists along the alias chain, so resolve until we find it. - for symbol.Flags&meaning == 0 && !dontResolveAlias && symbol.Flags&ast.SymbolFlagsAlias != 0 { + for symbol.Flags()&meaning == 0 && !dontResolveAlias && symbol.Flags()&ast.SymbolFlagsAlias != 0 { symbol = c.resolveAlias(symbol) } } @@ -16211,13 +16211,13 @@ func (c *Checker) resolveQualifiedName(name *ast.Node, left *ast.Node, right *as if namespace == c.unknownSymbol { return namespace } - if namespace.ValueDeclaration != nil && - ast.IsInJSFile(namespace.ValueDeclaration) && + if namespace.ValueDeclaration() != nil && + ast.IsInJSFile(namespace.ValueDeclaration()) && c.compilerOptions.GetModuleResolutionKind() != core.ModuleResolutionKindBundler && - ast.IsVariableDeclaration(namespace.ValueDeclaration) && - namespace.ValueDeclaration.Initializer() != nil && - c.isCommonJSRequire(namespace.ValueDeclaration.Initializer()) { - moduleName := namespace.ValueDeclaration.Initializer().Arguments()[0] + ast.IsVariableDeclaration(namespace.ValueDeclaration()) && + namespace.ValueDeclaration().Initializer() != nil && + c.isCommonJSRequire(namespace.ValueDeclaration().Initializer()) { + moduleName := namespace.ValueDeclaration().Initializer().Arguments()[0] moduleSym := c.resolveExternalModuleName(moduleName, moduleName, false /*ignoreErrors*/, nil) if moduleSym != nil { resolvedModuleSymbol := c.resolveExternalModuleSymbol(moduleSym, false /*dontResolveAlias*/) @@ -16228,7 +16228,7 @@ func (c *Checker) resolveQualifiedName(name *ast.Node, left *ast.Node, right *as } text := right.Text() symbol := c.getMergedSymbol(c.getSymbol(c.getExportsOfSymbol(namespace), text, meaning)) - if symbol == nil && namespace.Flags&ast.SymbolFlagsAlias != 0 { + if symbol == nil && namespace.Flags()&ast.SymbolFlagsAlias != 0 { // `namespace` can be resolved further if there was a symbol merge with a re-export symbol = c.getMergedSymbol(c.getSymbol(c.getExportsOfSymbol(c.resolveAlias(namespace)), text, meaning)) } @@ -16289,37 +16289,37 @@ func (c *Checker) getSuggestedSymbolForNonexistentModule(name *ast.Node, targetM } func (c *Checker) getFullyQualifiedName(symbol *ast.Symbol, containingLocation *ast.Node) string { - if symbol.Parent != nil { - return c.getFullyQualifiedName(symbol.Parent, containingLocation) + "." + c.symbolToString(symbol) + if symbol.Parent() != nil { + return c.getFullyQualifiedName(symbol.Parent(), containingLocation) + "." + c.symbolToString(symbol) } return c.symbolToStringEx(symbol, containingLocation, ast.SymbolFlagsAll, SymbolFormatFlagsDoNotIncludeSymbolChain|SymbolFormatFlagsAllowAnyNodeKind) } func (c *Checker) getExportsOfSymbol(symbol *ast.Symbol) ast.SymbolTable { - if symbol.Flags&ast.SymbolFlagsLateBindingContainer != 0 { + if symbol.Flags()&ast.SymbolFlagsLateBindingContainer != 0 { return c.getResolvedMembersOrExportsOfSymbol(symbol, MembersOrExportsResolutionKindResolvedExports) } - if symbol.Flags&ast.SymbolFlagsModule != 0 { + if symbol.Flags()&ast.SymbolFlagsModule != 0 { return c.getExportsOfModule(symbol) } - return symbol.Exports + return symbol.Exports() } func (c *Checker) getResolvedMembersOrExportsOfSymbol(symbol *ast.Symbol, resolutionKind MembersOrExportsResolutionKind) ast.SymbolTable { links := c.membersAndExportsLinks.Get(symbol) if links[resolutionKind] == nil { isStatic := resolutionKind == MembersOrExportsResolutionKindResolvedExports - earlySymbols := symbol.Exports + earlySymbols := symbol.Exports() switch { case !isStatic: - earlySymbols = symbol.Members - case symbol.Flags&ast.SymbolFlagsModule != 0: + earlySymbols = symbol.Members() + case symbol.Flags()&ast.SymbolFlagsModule != 0: earlySymbols, _ = c.getExportsOfModuleWorker(symbol) } links[resolutionKind] = earlySymbols // fill in any as-yet-unresolved late-bound members. var lateSymbols ast.SymbolTable - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { for _, member := range getMembersOfDeclaration(decl) { if isStatic == ast.HasStaticModifier(member) { switch { @@ -16338,8 +16338,8 @@ func (c *Checker) getResolvedMembersOrExportsOfSymbol(symbol *ast.Symbol, resolu } } if isStatic { - if assignmentSymbol := symbol.Exports[ast.InternalSymbolNameAssignmentDeclaration]; assignmentSymbol != nil { - for _, member := range assignmentSymbol.Declarations { + if assignmentSymbol := symbol.Exports()[ast.InternalSymbolNameAssignmentDeclaration]; assignmentSymbol != nil { + for _, member := range assignmentSymbol.Declarations() { if c.hasLateBindableName(member) { if lateSymbols == nil { lateSymbols = make(ast.SymbolTable) @@ -16401,7 +16401,7 @@ func (c *Checker) lateBindMember(parent *ast.Symbol, earlySymbols ast.SymbolTabl } if isTypeUsableAsPropertyName(t) { memberName := getPropertyNameFromType(t) - symbolFlags := decl.Symbol().Flags + symbolFlags := decl.Symbol().Flags() // Get or add a late-bound symbol for the member. This allows us to merge late-bound accessor declarations. lateSymbol := lateSymbols[memberName] if lateSymbol == nil { @@ -16410,14 +16410,14 @@ func (c *Checker) lateBindMember(parent *ast.Symbol, earlySymbols ast.SymbolTabl } // Report an error if there's a symbol declaration with the same name and conflicting flags. earlySymbol := earlySymbols[memberName] - if lateSymbol.Flags&getExcludedSymbolFlags(symbolFlags) != 0 { + if lateSymbol.Flags()&getExcludedSymbolFlags(symbolFlags) != 0 { // If we have an existing early-bound member, combine its declarations so that we can // report an error at each declaration. var declarations []*ast.Node if earlySymbol != nil { - declarations = core.Concatenate(earlySymbol.Declarations, lateSymbol.Declarations) + declarations = core.Concatenate(earlySymbol.Declarations(), lateSymbol.Declarations()) } else { - declarations = lateSymbol.Declarations + declarations = lateSymbol.Declarations() } name := memberName if t.flags&TypeFlagsUniqueESSymbol != 0 { @@ -16427,15 +16427,15 @@ func (c *Checker) lateBindMember(parent *ast.Symbol, earlySymbols ast.SymbolTabl c.error(core.OrElse(ast.GetNameOfDeclaration(d), d), diagnostics.Duplicate_identifier_0, name) } c.error(core.OrElse(declName, decl), diagnostics.Duplicate_identifier_0, name) - if lateSymbol.Flags&ast.SymbolFlagsAccessor != 0 && lateSymbol.Flags&ast.SymbolFlagsAccessor != symbolFlags&ast.SymbolFlagsAccessor { - lateSymbol.Flags |= ast.SymbolFlagsAccessor + if lateSymbol.Flags()&ast.SymbolFlagsAccessor != 0 && lateSymbol.Flags()&ast.SymbolFlagsAccessor != symbolFlags&ast.SymbolFlagsAccessor { + lateSymbol.SetFlags(lateSymbol.Flags() | ast.SymbolFlagsAccessor) } lateSymbol = c.newSymbolEx(ast.SymbolFlagsNone, memberName, ast.CheckFlagsLate) } c.valueSymbolLinks.Get(lateSymbol).nameType = t c.addDeclarationToLateBoundSymbol(lateSymbol, decl, symbolFlags) - if lateSymbol.Parent == nil { - lateSymbol.Parent = parent + if lateSymbol.Parent() == nil { + lateSymbol.SetParent(parent) } links.resolvedSymbol = lateSymbol } @@ -16452,41 +16452,41 @@ func (c *Checker) lateBindIndexSignature(parent *ast.Symbol, earlySymbols ast.Sy indexSymbol = c.newSymbolEx(ast.SymbolFlagsNone, ast.InternalSymbolNameIndex, ast.CheckFlagsLate) } else { indexSymbol = c.cloneSymbol(early) - indexSymbol.CheckFlags |= ast.CheckFlagsLate + indexSymbol.SetCheckFlags(indexSymbol.CheckFlags() | ast.CheckFlagsLate) } lateSymbols[ast.InternalSymbolNameIndex] = indexSymbol } // Then just add the computed name as a late bound declaration // (note: unlike `addDeclarationToLateBoundSymbol` we do not set up a `.lateSymbol` on `decl`'s links, // since that would point at an index symbol and not a single property symbol, like most consumers would expect) - if len(indexSymbol.Declarations) == 0 || decl.Symbol().Flags&ast.SymbolFlagsReplaceableByMethod == 0 { - indexSymbol.Declarations = append(indexSymbol.Declarations, decl) + if len(indexSymbol.Declarations()) == 0 || decl.Symbol().Flags()&ast.SymbolFlagsReplaceableByMethod == 0 { + indexSymbol.SetDeclarations(append(indexSymbol.Declarations(), decl)) } } func isNotReplacableByMethod(decl *ast.Node) bool { - return decl.Symbol().Flags&ast.SymbolFlagsReplaceableByMethod == 0 + return decl.Symbol().Flags()&ast.SymbolFlagsReplaceableByMethod == 0 } // Adds a declaration to a late-bound dynamic member. This performs the same function for // late-bound members that `addDeclarationToSymbol` in binder.ts performs for early-bound // members. func (c *Checker) addDeclarationToLateBoundSymbol(symbol *ast.Symbol, member *ast.Node, symbolFlags ast.SymbolFlags) { - debug.Assert(symbol.CheckFlags&ast.CheckFlagsLate != 0, "Expected a late-bound symbol.") + debug.Assert(symbol.CheckFlags()&ast.CheckFlagsLate != 0, "Expected a late-bound symbol.") c.lateBoundLinks.Get(member.Symbol()).lateSymbol = symbol - if len(symbol.Declarations) == 0 || member.Symbol().Flags&ast.SymbolFlagsReplaceableByMethod == 0 { - symbol.Flags |= symbolFlags - symbol.Declarations = append(symbol.Declarations, member) - } else if symbol.Flags&ast.SymbolFlagsReplaceableByMethod != 0 && member.Symbol().Flags&ast.SymbolFlagsMethod != 0 { + if len(symbol.Declarations()) == 0 || member.Symbol().Flags()&ast.SymbolFlagsReplaceableByMethod == 0 { + symbol.SetFlags(symbol.Flags() | symbolFlags) + symbol.SetDeclarations(append(symbol.Declarations(), member)) + } else if symbol.Flags()&ast.SymbolFlagsReplaceableByMethod != 0 && member.Symbol().Flags()&ast.SymbolFlagsMethod != 0 { // Remove all replacable-by-method members, along with their flags. - symbol.Declarations = append(core.Filter(symbol.Declarations, isNotReplacableByMethod), member) - oldFlags := symbol.Flags - symbol.Flags = ast.SymbolFlagsTransient - for _, d := range symbol.Declarations { - symbol.Flags |= d.Symbol().Flags + symbol.SetDeclarations(append(core.Filter(symbol.Declarations(), isNotReplacableByMethod), member)) + oldFlags := symbol.Flags() + symbol.SetFlags(ast.SymbolFlagsTransient) + for _, d := range symbol.Declarations() { + symbol.SetFlags(symbol.Flags() | d.Symbol().Flags()) } if oldFlags&ast.SymbolFlagsAccessor != 0 { - symbol.Flags |= ast.SymbolFlagsAccessor + symbol.SetFlags(symbol.Flags() | ast.SymbolFlagsAccessor) } } if symbolFlags&ast.SymbolFlagsValue != 0 { @@ -16500,10 +16500,10 @@ func (c *Checker) addDeclarationToLateBoundSymbol(symbol *ast.Symbol, member *as * For a description of late-binding, see `lateBindMember`. */ func (c *Checker) getMembersOfSymbol(symbol *ast.Symbol) ast.SymbolTable { - if symbol.Flags&ast.SymbolFlagsLateBindingContainer != 0 { + if symbol.Flags()&ast.SymbolFlagsLateBindingContainer != 0 { return c.getResolvedMembersOrExportsOfSymbol(symbol, MembersOrExportsResolutionKindResolvedMembers) } - return symbol.Members + return symbol.Members() } func (c *Checker) getExportsOfModule(moduleSymbol *ast.Symbol) ast.SymbolTable { @@ -16525,7 +16525,7 @@ type ExportCollisionTable = map[string]*ExportCollision func (c *Checker) getExportsOfModuleWorker(moduleSymbol *ast.Symbol) (exports ast.SymbolTable, typeOnlyExportStarMap map[string]*ast.Node) { var visitedSymbols []*ast.Symbol - nonTypeOnlyNames := collections.NewSetWithSizeHint[string](len(moduleSymbol.Exports)) + nonTypeOnlyNames := collections.NewSetWithSizeHint[string](len(moduleSymbol.Exports())) // The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example, // module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error. var visit func(*ast.Symbol, *ast.Node, bool) ast.SymbolTable @@ -16534,21 +16534,21 @@ func (c *Checker) getExportsOfModuleWorker(moduleSymbol *ast.Symbol) (exports as // Add non-type-only names before checking if we've visited this module, // because we might have visited it via an 'export type *', and visiting // again with 'export *' will override the type-onlyness of its exports. - for name := range symbol.Exports { + for name := range symbol.Exports() { nonTypeOnlyNames.Add(name) } } - if symbol == nil || symbol.Exports == nil || slices.Contains(visitedSymbols, symbol) { + if symbol == nil || symbol.Exports() == nil || slices.Contains(visitedSymbols, symbol) { return nil } visitedSymbols = append(visitedSymbols, symbol) - symbols := maps.Clone(symbol.Exports) + symbols := maps.Clone(symbol.Exports()) // All export * declarations are collected in an __export symbol by the binder - exportStars := symbol.Exports[ast.InternalSymbolNameExportStar] + exportStars := symbol.Exports()[ast.InternalSymbolNameExportStar] if exportStars != nil { nestedSymbols := make(ast.SymbolTable) lookupTable := make(ExportCollisionTable) - for _, node := range exportStars.Declarations { + for _, node := range exportStars.Declarations() { resolvedModule := c.resolveExternalModuleName(node, node.ModuleSpecifier(), false /*ignoreErrors*/, c.getTypeFromImportAttributes(ast.GetImportAttributes(node))) exportedSymbols := visit(resolvedModule, node, isTypeOnly || node.IsTypeOnly()) c.extendExportSymbols(nestedSymbols, exportedSymbols, lookupTable, node) @@ -16576,7 +16576,7 @@ func (c *Checker) getExportsOfModuleWorker(moduleSymbol *ast.Symbol) (exports as } var originalModule *ast.Symbol if moduleSymbol != nil { - if c.resolveSymbolEx(moduleSymbol.Exports[ast.InternalSymbolNameExportEquals], false /*dontResolveAlias*/) != nil { + if c.resolveSymbolEx(moduleSymbol.Exports()[ast.InternalSymbolNameExportEquals], false /*dontResolveAlias*/) != nil { originalModule = moduleSymbol } } @@ -16587,16 +16587,16 @@ func (c *Checker) getExportsOfModuleWorker(moduleSymbol *ast.Symbol) (exports as exports = make(ast.SymbolTable) } // A CommonJS module defined by an 'export=' might also export typedefs, stored on the original module - if originalModule != nil && len(originalModule.Exports) > 1 { - for _, symbol := range originalModule.Exports { - if symbol.Name == ast.InternalSymbolNameExportEquals || symbol.Name == ast.InternalSymbolNameExportStar { + if originalModule != nil && len(originalModule.Exports()) > 1 { + for _, symbol := range originalModule.Exports() { + if symbol.Name() == ast.InternalSymbolNameExportEquals || symbol.Name() == ast.InternalSymbolNameExportStar { continue } flags := c.getSymbolFlags(symbol) if flags&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 && flags&ast.SymbolFlagsValue == 0 && - exports[symbol.Name] == nil { - exports[symbol.Name] = symbol + exports[symbol.Name()] == nil { + exports[symbol.Name()] = symbol } } } @@ -16642,7 +16642,7 @@ func (c *Checker) ResolveAlias(symbol *ast.Symbol) (*ast.Symbol, bool) { // meaning. Pure aliases are eagerly resolved and any type-only markers are back-propagated to the original // symbol. The function panics if the argument is not a symbol with an alias meaning. func (c *Checker) resolveAlias(symbol *ast.Symbol) *ast.Symbol { - if symbol.Flags&ast.SymbolFlagsAlias == 0 { + if symbol.Flags()&ast.SymbolFlagsAlias == 0 { panic("Should only get alias here") } links := c.aliasSymbolLinks.Get(symbol) @@ -16687,22 +16687,22 @@ func (c *Checker) tryResolveAlias(symbol *ast.Symbol) *ast.Symbol { } func (c *Checker) resolveAliasWithDeprecationCheck(symbol *ast.Symbol, location *ast.Node) *ast.Symbol { - if symbol.Flags&ast.SymbolFlagsAlias == 0 || c.isDeprecatedSymbol(symbol) || c.getDeclarationOfAliasSymbol(symbol) == nil { + if symbol.Flags()&ast.SymbolFlagsAlias == 0 || c.isDeprecatedSymbol(symbol) || c.getDeclarationOfAliasSymbol(symbol) == nil { return symbol } targetSymbol := c.resolveAlias(symbol) if targetSymbol == c.unknownSymbol { return targetSymbol } - for symbol.Flags&ast.SymbolFlagsAlias != 0 { + for symbol.Flags()&ast.SymbolFlagsAlias != 0 { target := c.getImmediateAliasedSymbol(symbol) if target != nil { if target == targetSymbol { break } - if len(target.Declarations) != 0 { + if len(target.Declarations()) != 0 { if c.isDeprecatedSymbol(target) { - c.addDeprecatedSuggestion(location, target.Declarations, target.Name) + c.addDeprecatedSuggestion(location, target.Declarations(), target.Name()) break } else { if symbol == targetSymbol { @@ -16746,9 +16746,9 @@ func (c *Checker) getSymbolFlagsEx(symbol *ast.Symbol, excludeTypeOnlyMeanings b var seenSymbols collections.Set[*ast.Symbol] var flags ast.SymbolFlags if !excludeLocalMeanings { - flags = symbol.Flags + flags = symbol.Flags() } - for symbol.Flags&ast.SymbolFlagsAlias != 0 { + for symbol.Flags()&ast.SymbolFlagsAlias != 0 { if excludeTypeOnlyMeanings && c.getTypeOnlyAliasDeclaration(symbol) != nil { break } @@ -16756,7 +16756,7 @@ func (c *Checker) getSymbolFlagsEx(symbol *ast.Symbol, excludeTypeOnlyMeanings b if target == c.unknownSymbol { return ast.SymbolFlagsAll } - if target.Flags&ast.SymbolFlagsAlias != 0 { + if target.Flags()&ast.SymbolFlagsAlias != 0 { // Optimization - try to avoid creating or adding to `seenSymbols` if possible if target == symbol || seenSymbols.Has(target) { break @@ -16766,14 +16766,14 @@ func (c *Checker) getSymbolFlagsEx(symbol *ast.Symbol, excludeTypeOnlyMeanings b } seenSymbols.Add(target) } - flags |= target.Flags + flags |= target.Flags() symbol = target } return flags } func (c *Checker) getDeclarationOfAliasSymbol(symbol *ast.Symbol) *ast.Node { - return core.FindLast(symbol.Declarations, ast.IsAliasSymbolDeclaration) + return core.FindLast(symbol.Declarations(), ast.IsAliasSymbolDeclaration) } func (c *Checker) getTypeOfSymbolWithDeferredType(symbol *ast.Symbol) *Type { @@ -16810,18 +16810,18 @@ func (c *Checker) getWriteTypeOfSymbolWithDeferredType(symbol *ast.Symbol) *Type // properties deriving from set accessors will either pre-compute or defer the union or // intersection of the writeTypes of their constituents. func (c *Checker) getWriteTypeOfSymbol(symbol *ast.Symbol) *Type { - if symbol.CheckFlags&ast.CheckFlagsSyntheticProperty != 0 { - if symbol.CheckFlags&ast.CheckFlagsDeferredType != 0 { + if symbol.CheckFlags()&ast.CheckFlagsSyntheticProperty != 0 { + if symbol.CheckFlags()&ast.CheckFlagsDeferredType != 0 { return c.getWriteTypeOfSymbolWithDeferredType(symbol) } links := c.valueSymbolLinks.Get(symbol) return core.OrElse(links.writeType, links.resolvedType) } - if symbol.Flags&ast.SymbolFlagsProperty != 0 { - return c.removeMissingType(c.getTypeOfSymbol(symbol), symbol.Flags&ast.SymbolFlagsOptional != 0) + if symbol.Flags()&ast.SymbolFlagsProperty != 0 { + return c.removeMissingType(c.getTypeOfSymbol(symbol), symbol.Flags()&ast.SymbolFlagsOptional != 0) } - if symbol.Flags&ast.SymbolFlagsAccessor != 0 { - if symbol.CheckFlags&ast.CheckFlagsInstantiated != 0 { + if symbol.Flags()&ast.SymbolFlagsAccessor != 0 { + if symbol.CheckFlags()&ast.CheckFlagsInstantiated != 0 { return c.getWriteTypeOfInstantiatedSymbol(symbol) } return c.getWriteTypeOfAccessors(symbol) @@ -16869,38 +16869,38 @@ func (c *Checker) GetTypeOfSymbolAtLocation(symbol *ast.Symbol, location *ast.No } func (c *Checker) getTypeOfSymbol(symbol *ast.Symbol) *Type { - if symbol.CheckFlags&ast.CheckFlagsDeferredType != 0 { + if symbol.CheckFlags()&ast.CheckFlagsDeferredType != 0 { return c.getTypeOfSymbolWithDeferredType(symbol) } - if symbol.CheckFlags&ast.CheckFlagsInstantiated != 0 { + if symbol.CheckFlags()&ast.CheckFlagsInstantiated != 0 { return c.getTypeOfInstantiatedSymbol(symbol) } - if symbol.CheckFlags&ast.CheckFlagsMapped != 0 { + if symbol.CheckFlags()&ast.CheckFlagsMapped != 0 { return c.getTypeOfMappedSymbol(symbol) } - if symbol.CheckFlags&ast.CheckFlagsReverseMapped != 0 { + if symbol.CheckFlags()&ast.CheckFlagsReverseMapped != 0 { return c.getTypeOfReverseMappedSymbol(symbol) } - if symbol.Flags&ast.SymbolFlagsAccessor != 0 { + if symbol.Flags()&ast.SymbolFlagsAccessor != 0 { return c.getTypeOfAccessors(symbol) } - if symbol.Flags&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty) != 0 { + if symbol.Flags()&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty) != 0 { return c.getTypeOfVariableOrParameterOrProperty(symbol) } - if symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule) != 0 { + if symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule) != 0 { return c.getTypeOfFuncClassEnumModule(symbol) } - if symbol.Flags&ast.SymbolFlagsEnumMember != 0 { + if symbol.Flags()&ast.SymbolFlagsEnumMember != 0 { return c.getTypeOfEnumMember(symbol) } - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { return c.getTypeOfAlias(symbol) } return c.errorType } func (c *Checker) getNonMissingTypeOfSymbol(symbol *ast.Symbol) *Type { - return c.removeMissingType(c.getTypeOfSymbol(symbol), symbol.Flags&ast.SymbolFlagsOptional != 0) + return c.removeMissingType(c.getTypeOfSymbol(symbol), symbol.Flags()&ast.SymbolFlagsOptional != 0) } func (c *Checker) getTypeOfInstantiatedSymbol(symbol *ast.Symbol) *Type { @@ -16940,7 +16940,7 @@ func (c *Checker) getTypeOfVariableOrParameterOrProperty(symbol *ast.Symbol) *Ty } func (c *Checker) isParameterOfContextSensitiveSignature(symbol *ast.Symbol) bool { - decl := symbol.ValueDeclaration + decl := symbol.ValueDeclaration() if decl == nil { return false } @@ -16955,15 +16955,15 @@ func (c *Checker) isParameterOfContextSensitiveSignature(symbol *ast.Symbol) boo func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbol) *Type { // Handle prototype property - if symbol.Flags&ast.SymbolFlagsPrototype != 0 { + if symbol.Flags()&ast.SymbolFlagsPrototype != 0 { return c.getTypeOfPrototypeProperty(symbol) } // CommonsJS require and module both have type any. if symbol == c.requireSymbol { return c.anyType } - debug.Assert(symbol.ValueDeclaration != nil) - declaration := symbol.ValueDeclaration + debug.Assert(symbol.ValueDeclaration() != nil) + declaration := symbol.ValueDeclaration() if ast.IsSourceFile(declaration) && ast.IsJsonSourceFile(declaration.AsSourceFile()) { statements := declaration.Statements() if len(statements) == 0 { @@ -16975,11 +16975,11 @@ func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbo if !c.pushTypeResolution(symbol, TypeSystemPropertyNameType) { return c.reportCircularityError(symbol) } - if symbol.Flags&ast.SymbolFlagsModuleExports != 0 { - if symbol.Name == "exports" { - return c.getTypeOfSymbol(c.resolveExternalModuleSymbol(symbol.ValueDeclaration.Symbol(), false /*dontResolveAlias*/)) + if symbol.Flags()&ast.SymbolFlagsModuleExports != 0 { + if symbol.Name() == "exports" { + return c.getTypeOfSymbol(c.resolveExternalModuleSymbol(symbol.ValueDeclaration().Symbol(), false /*dontResolveAlias*/)) } - return c.newAnonymousType(symbol, symbol.Members, nil, nil, nil) + return c.newAnonymousType(symbol, symbol.Members(), nil, nil, nil) } var result *Type switch declaration.Kind { @@ -17112,7 +17112,7 @@ func (c *Checker) getTypeForVariableLikeDeclaration(declaration *ast.Node, inclu } // Use contextual parameter type if one is available var t *Type - if declaration.Symbol().Name == ast.InternalSymbolNameThis { + if declaration.Symbol().Name() == ast.InternalSymbolNameThis { t = c.getContextualThisParameterType(fn) } else { t = c.getContextuallyTypedParameterType(declaration) @@ -17214,12 +17214,12 @@ func (c *Checker) padObjectLiteralType(t *Type, pattern *ast.Node) *Type { } members := make(ast.SymbolTable) for _, prop := range c.getPropertiesOfObjectType(t) { - members[prop.Name] = prop + members[prop.Name()] = prop } for _, e := range missingElements { symbol := c.newSymbol(ast.SymbolFlagsProperty|ast.SymbolFlagsOptional, c.getPropertyNameFromBindingElement(e)) c.valueSymbolLinks.Get(symbol).resolvedType = c.getTypeFromBindingElement(e, false /*includePatternInType*/, true /*reportErrors*/) - members[symbol.Name] = symbol + members[symbol.Name()] = symbol } result := c.newAnonymousType(t.symbol, members, nil, nil, c.getIndexInfosOfType(t)) result.objectFlags = t.objectFlags @@ -17289,24 +17289,24 @@ func (c *Checker) getTypeOfFuncClassEnumModule(symbol *ast.Symbol) *Type { } func (c *Checker) getTypeOfFuncClassEnumModuleWorker(symbol *ast.Symbol) *Type { - if symbol.Flags&ast.SymbolFlagsModule != 0 && isShorthandAmbientModuleSymbol(symbol) { + if symbol.Flags()&ast.SymbolFlagsModule != 0 && isShorthandAmbientModuleSymbol(symbol) { return c.anyType - } else if symbol.Flags&ast.SymbolFlagsValueModule != 0 && symbol.ValueDeclaration != nil && - ast.IsSourceFile(symbol.ValueDeclaration) && symbol.ValueDeclaration.AsSourceFile().CommonJSModuleIndicator != nil { + } else if symbol.Flags()&ast.SymbolFlagsValueModule != 0 && symbol.ValueDeclaration() != nil && + ast.IsSourceFile(symbol.ValueDeclaration()) && symbol.ValueDeclaration().AsSourceFile().CommonJSModuleIndicator != nil { resolvedModule := c.resolveExternalModuleSymbol(symbol, false /*dontResolveAlias*/) if resolvedModule != symbol { return c.getTypeOfSymbol(resolvedModule) } } t := c.newObjectType(ObjectFlagsAnonymous, symbol) - if symbol.Flags&ast.SymbolFlagsClass != 0 { + if symbol.Flags()&ast.SymbolFlagsClass != 0 { baseTypeVariable := c.getBaseTypeVariableOfClass(symbol) if baseTypeVariable != nil { return c.getIntersectionType([]*Type{t, baseTypeVariable}) } return t } - if c.strictNullChecks && symbol.Flags&ast.SymbolFlagsOptional != 0 { + if c.strictNullChecks && symbol.Flags()&ast.SymbolFlagsOptional != 0 { return c.getOptionalType(t /*isProperty*/, true) } return t @@ -17353,7 +17353,7 @@ func (c *Checker) getBaseConstructorTypeOfClass(t *Type) *Type { c.resolveStructuredTypeMembers(baseConstructorType) } if !c.popTypeResolution() { - c.error(t.symbol.ValueDeclaration, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_base_expression, c.symbolToString(t.symbol)) + c.error(t.symbol.ValueDeclaration(), diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_base_expression, c.symbolToString(t.symbol)) if data.resolvedBaseConstructorType == nil { data.resolvedBaseConstructorType = c.errorType } @@ -17370,8 +17370,8 @@ func (c *Checker) getBaseConstructorTypeOfClass(t *Type) *Type { ctorReturn = c.getReturnTypeOfSignature(ctorSigs[0]) } } - if baseConstructorType.symbol.Declarations != nil { - err.AddRelatedInfo(createDiagnosticForNode(baseConstructorType.symbol.Declarations[0], diagnostics.Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1, c.symbolToString(baseConstructorType.symbol), c.TypeToString(ctorReturn))) + if baseConstructorType.symbol.Declarations() != nil { + err.AddRelatedInfo(createDiagnosticForNode(baseConstructorType.symbol.Declarations()[0], diagnostics.Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1, c.symbolToString(baseConstructorType.symbol), c.TypeToString(ctorReturn))) } } if data.resolvedBaseConstructorType == nil { @@ -17419,7 +17419,7 @@ func signatureHasRestParameter(sig *Signature) bool { } func (c *Checker) getTypeOfParameter(symbol *ast.Symbol) *Type { - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() return c.addOptionalityEx(c.getTypeOfSymbol(symbol), false, declaration != nil && (declaration.Initializer() != nil || isOptionalDeclaration(declaration))) } @@ -17492,8 +17492,8 @@ func (c *Checker) getConstraintOrUnknownFromTypeParameter(t *Type) *Type { func (c *Checker) getInferredTypeParameterConstraint(t *Type, omitTypeReferences bool) *Type { var inferences []*Type - if t.symbol != nil && len(t.symbol.Declarations) != 0 { - for _, declaration := range t.symbol.Declarations { + if t.symbol != nil && len(t.symbol.Declarations()) != 0 { + for _, declaration := range t.symbol.Declarations() { if ast.IsInferTypeNode(declaration.Parent) { // When an 'infer T' declaration is immediately contained in a type reference node // (such as 'Foo'), T's constraint is inferred from the constraint of the @@ -17576,7 +17576,7 @@ func (c *Checker) getTypeParametersForTypeReferenceOrImport(node *ast.Node) []*T func (c *Checker) getTypeParametersForTypeAndSymbol(t *Type, symbol *ast.Symbol) []*Type { if !c.isErrorType(t) { - if symbol.Flags&ast.SymbolFlagsTypeAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsTypeAlias != 0 { if typeParameters := c.typeAliasLinks.Get(symbol).typeParameters; len(typeParameters) != 0 { return typeParameters } @@ -17698,7 +17698,7 @@ func (c *Checker) getConstraintOfDistributiveConditionalType(t *Type) *Type { func (c *Checker) getDeclaredTypeOfClassOrInterface(symbol *ast.Symbol) *Type { links := c.declaredTypeLinks.Get(symbol) if links.declaredType == nil { - kind := core.IfElse(symbol.Flags&ast.SymbolFlagsClass != 0, ObjectFlagsClass, ObjectFlagsInterface) + kind := core.IfElse(symbol.Flags()&ast.SymbolFlagsClass != 0, ObjectFlagsClass, ObjectFlagsInterface) t := c.newObjectType(kind, symbol) links.declaredType = t outerTypeParameters := c.getOuterTypeParametersOfClassOrInterface(symbol) @@ -17733,7 +17733,7 @@ func (c *Checker) getDeclaredTypeOfClassOrInterface(symbol *ast.Symbol) *Type { * and if none of the base interfaces have a "this" type. */ func (c *Checker) isThislessInterface(symbol *ast.Symbol) bool { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if ast.IsInterfaceDeclaration(declaration) { if declaration.Flags&ast.NodeFlagsContainsThis != 0 { return false @@ -17743,7 +17743,7 @@ func (c *Checker) isThislessInterface(symbol *ast.Symbol) bool { name := ast.GetHeritageClauseElementName(node) if ast.IsEntityName(name) || ast.IsEntityNameExpression(name) { baseSymbol := c.resolveEntityName(name, ast.SymbolFlagsType, true /*ignoreErrors*/, false, nil) - if baseSymbol == nil || baseSymbol.Flags&ast.SymbolFlagsInterface == 0 || c.getDeclaredTypeOfClassOrInterface(baseSymbol).AsInterfaceType().thisType != nil { + if baseSymbol == nil || baseSymbol.Flags()&ast.SymbolFlagsInterface == 0 || c.getDeclaredTypeOfClassOrInterface(baseSymbol).AsInterfaceType().thisType != nil { return false } } @@ -18051,7 +18051,7 @@ func isUnconstrainedTypeParameter(tp *Type) bool { if target.symbol == nil { return false } - for _, d := range target.symbol.Declarations { + for _, d := range target.symbol.Declarations() { if ast.IsTypeParameterDeclaration(d) && (d.AsTypeParameterDeclaration().Constraint != nil || ast.IsMappedTypeNode(d.Parent) || ast.IsInferTypeNode(d.Parent)) { return false } @@ -18223,7 +18223,7 @@ func (c *Checker) getRestType(source *Type, properties []*ast.Node, symbol *ast. } members := make(ast.SymbolTable) for _, prop := range spreadableProperties { - members[prop.Name] = c.getSpreadSymbol(prop, false /*readonly*/) + members[prop.Name()] = c.getSpreadSymbol(prop, false /*readonly*/) } result := c.newAnonymousType(symbol, members, nil, nil, c.getIndexInfosOfType(source)) result.objectFlags |= ObjectFlagsObjectRestType @@ -18333,7 +18333,7 @@ func (c *Checker) getTypeFromObjectBindingPattern(pattern *ast.Node, includePatt flags := ast.SymbolFlagsProperty | core.IfElse(e.Initializer() != nil, ast.SymbolFlagsOptional, 0) symbol := c.newSymbol(flags, text) c.valueSymbolLinks.Get(symbol).resolvedType = c.getTypeFromBindingElement(e, includePatternInType, reportErrors) - members[symbol.Name] = symbol + members[symbol.Name()] = symbol } var indexInfos []*IndexInfo if stringIndexInfo != nil { @@ -18474,14 +18474,14 @@ func (c *Checker) getWidenedTypeForAssignmentDeclaration(symbol *ast.Symbol) *Ty } if t == nil { var types []*Type - for i, declaration := range symbol.Declarations { + for i, declaration := range symbol.Declarations() { if ast.IsBinaryExpression(declaration) && declaration.Type() != nil { t = c.getTypeFromTypeNode(declaration.Type()) break } if assignedType := c.getAssignmentDeclarationInitializerType(declaration); assignedType != nil { // We ignore initial assignments of undefined to CommonJS exports when there are multiple assignment declarations - if ast.GetAssignmentDeclarationKind(declaration) != ast.JSDeclarationKindExportsProperty || i != 0 || len(symbol.Declarations) == 1 || assignedType.flags&TypeFlagsUndefined == 0 { + if ast.GetAssignmentDeclarationKind(declaration) != ast.JSDeclarationKindExportsProperty || i != 0 || len(symbol.Declarations()) == 1 || assignedType.flags&TypeFlagsUndefined == 0 { types = core.AppendIfUnique(types, assignedType) } } @@ -18500,9 +18500,9 @@ func (c *Checker) getWidenedTypeForAssignmentDeclaration(symbol *ast.Symbol) *Ty } t = c.getWidenedType(t) // report an all-nullable or empty union as an implicit any in JS files - if symbol.ValueDeclaration != nil && ast.IsInJSFile(symbol.ValueDeclaration) && + if symbol.ValueDeclaration() != nil && ast.IsInJSFile(symbol.ValueDeclaration()) && c.filterType(t, func(c *Type) bool { return c.Flags() & ^TypeFlagsNullable != 0 }) == c.neverType { - c.reportImplicitAny(symbol.ValueDeclaration, c.anyType, WideningKindNormal) + c.reportImplicitAny(symbol.ValueDeclaration(), c.anyType, WideningKindNormal) return c.anyType } return t @@ -18540,9 +18540,9 @@ func (c *Checker) getAssignmentDeclarationInitializerType(node *ast.Node) *Type // const f: { (): void, a: string[] } = () => {}; // f.a = []; func (c *Checker) hasParentWithTypeAnnotation(symbol *ast.Symbol) bool { - if symbol.Parent != nil && symbol.Parent.ValueDeclaration != nil && ast.IsFunctionExpressionOrArrowFunction(symbol.Parent.ValueDeclaration) { - if possiblyAnnotatedSymbol := c.getSymbolOfNode(symbol.Parent.ValueDeclaration.Parent); possiblyAnnotatedSymbol != nil && possiblyAnnotatedSymbol.ValueDeclaration != nil { - return possiblyAnnotatedSymbol.ValueDeclaration.Type() != nil + if symbol.Parent() != nil && symbol.Parent().ValueDeclaration() != nil && ast.IsFunctionExpressionOrArrowFunction(symbol.Parent().ValueDeclaration()) { + if possiblyAnnotatedSymbol := c.getSymbolOfNode(symbol.Parent().ValueDeclaration().Parent); possiblyAnnotatedSymbol != nil && possiblyAnnotatedSymbol.ValueDeclaration() != nil { + return possiblyAnnotatedSymbol.ValueDeclaration().Type() != nil } } return false @@ -18584,7 +18584,7 @@ func (c *Checker) getTypeFromPropertyDescriptor(node *ast.Node) *Type { // when no declaration sites have JSDoc type annotations, and when at least one declaration site is in the body of // a class constructor. func (c *Checker) isConstructorDeclaredThisProperty(symbol *ast.Symbol) (thisAssignmentDeclarationKind, *ast.Node) { - if symbol.ValueDeclaration == nil || !ast.IsBinaryExpression(symbol.ValueDeclaration) { + if symbol.ValueDeclaration() == nil || !ast.IsBinaryExpression(symbol.ValueDeclaration()) { return thisAssignmentDeclarationNone, nil } if kind, ok := c.thisExpandoKinds[symbol]; ok { @@ -18596,7 +18596,7 @@ func (c *Checker) isConstructorDeclaredThisProperty(symbol *ast.Symbol) (thisAss } allThis := true var typeAnnotation *ast.Node - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if !ast.IsBinaryExpression(declaration) { allThis = false break @@ -18804,12 +18804,12 @@ func (c *Checker) getWidenedTypeOfObjectLiteral(t *Type, context *WideningContex } members := make(ast.SymbolTable) for _, prop := range c.getPropertiesOfObjectType(t) { - members[prop.Name] = c.getWidenedProperty(prop, context) + members[prop.Name()] = c.getWidenedProperty(prop, context) } if context != nil { for _, prop := range c.getPropertiesOfContext(context) { - if _, ok := members[prop.Name]; !ok { - members[prop.Name] = c.getUndefinedProperty(prop) + if _, ok := members[prop.Name()]; !ok { + members[prop.Name()] = c.getUndefinedProperty(prop) } } } @@ -18829,7 +18829,7 @@ func (c *Checker) getWidenedTypeOfObjectLiteral(t *Type, context *WideningContex } func (c *Checker) getWidenedProperty(prop *ast.Symbol, context *WideningContext) *ast.Symbol { - if prop.Flags&ast.SymbolFlagsProperty == 0 { + if prop.Flags()&ast.SymbolFlagsProperty == 0 { // Since get accessors already widen their return value there is no need to // widen accessor based properties here. return prop @@ -18837,7 +18837,7 @@ func (c *Checker) getWidenedProperty(prop *ast.Symbol, context *WideningContext) original := c.getTypeOfSymbol(prop) var propContext *WideningContext if context != nil { - propContext = context.getChildContext(prop.Name) + propContext = context.getChildContext(prop.Name()) } widened := c.getWidenedTypeWithContext(original, propContext) if widened == original { @@ -18864,7 +18864,7 @@ func (c *Checker) getPropertiesOfContext(context *WideningContext) []*ast.Symbol for _, t := range c.getSiblingsOfContext(context) { if isObjectLiteralType(t) && t.objectFlags&ObjectFlagsContainsSpread == 0 { for _, prop := range c.getPropertiesOfType(t) { - names.Set(prop.Name, prop) + names.Set(prop.Name(), prop) } } } @@ -18890,12 +18890,12 @@ func (c *Checker) getSiblingsOfContext(context *WideningContext) []*Type { } func (c *Checker) getUndefinedProperty(prop *ast.Symbol) *ast.Symbol { - if cached := c.undefinedProperties[prop.Name]; cached != nil { + if cached := c.undefinedProperties[prop.Name()]; cached != nil { return cached } result := c.createSymbolWithType(prop, c.undefinedOrMissingType) - result.Flags |= ast.SymbolFlagsOptional - c.undefinedProperties[prop.Name] = result + result.SetFlags(result.Flags() | ast.SymbolFlagsOptional) + c.undefinedProperties[prop.Name()] = result return result } @@ -18915,7 +18915,7 @@ func (c *Checker) getTypeOfAccessors(symbol *ast.Symbol) *Type { } getter := ast.GetDeclarationOfKind(symbol, ast.KindGetAccessor) setter := ast.GetDeclarationOfKind(symbol, ast.KindSetAccessor) - accessor := core.Find(symbol.Declarations, ast.IsAutoAccessorPropertyDeclaration) + accessor := core.Find(symbol.Declarations(), ast.IsAutoAccessorPropertyDeclaration) // We try to resolve a getter type annotation, a setter type annotation, or a getter function // body return type inference, in that order. t := c.getAnnotatedAccessorType(getter) @@ -19078,8 +19078,8 @@ func (c *Checker) getNonNullableTypeIfNeeded(t *Type) *Type { } func (c *Checker) getDeclarationNodeFlagsFromSymbol(s *ast.Symbol) ast.NodeFlags { - if s.ValueDeclaration != nil { - return c.getCombinedNodeFlagsCached(s.ValueDeclaration) + if s.ValueDeclaration() != nil { + return c.getCombinedNodeFlagsCached(s.ValueDeclaration()) } return ast.NodeFlagsNone } @@ -19219,18 +19219,18 @@ func (c *Checker) typeResolutionHasProperty(r *TypeResolution) bool { } func (c *Checker) reportCircularityError(symbol *ast.Symbol) *Type { - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() // Check if variable has type annotation that circularly references the variable itself if declaration != nil { if declaration.Type() != nil { - c.error(symbol.ValueDeclaration, diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) + c.error(symbol.ValueDeclaration(), diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, c.symbolToString(symbol)) return c.errorType } // Check if variable has initializer that circularly references the variable itself if c.noImplicitAny && (!ast.IsParameterDeclaration(declaration) || declaration.Initializer() != nil) { - c.error(symbol.ValueDeclaration, diagnostics.X_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, c.symbolToString(symbol)) + c.error(symbol.ValueDeclaration(), diagnostics.X_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, c.symbolToString(symbol)) } - } else if symbol.Flags&ast.SymbolFlagsAlias != 0 { + } else if symbol.Flags()&ast.SymbolFlagsAlias != 0 { node := c.getDeclarationOfAliasSymbol(symbol) if node != nil { c.error(node, diagnostics.Circular_definition_of_import_alias_0, c.symbolToString(symbol)) @@ -19264,9 +19264,9 @@ func (c *Checker) getPropertiesOfUnionOrIntersectionType(t *Type) []*ast.Symbol props := []*ast.Symbol{} for _, current := range d.types { for _, prop := range c.getPropertiesOfType(current) { - if !checked.Has(prop.Name) { - checked.Add(prop.Name) - combinedProp := c.getPropertyOfUnionOrIntersectionType(t, prop.Name, t.flags&TypeFlagsIntersection != 0 /*skipObjectFunctionPropertyAugment*/) + if !checked.Has(prop.Name()) { + checked.Add(prop.Name()) + combinedProp := c.getPropertyOfUnionOrIntersectionType(t, prop.Name(), t.flags&TypeFlagsIntersection != 0 /*skipObjectFunctionPropertyAugment*/) if combinedProp != nil { props = append(props, combinedProp) } @@ -19302,7 +19302,7 @@ func (c *Checker) getPropertyOfTypeEx(t *Type, name string, skipObjectFunctionPr resolved := c.resolveStructuredTypeMembers(t) symbol := resolved.members[name] if symbol != nil { - if !includeTypeOnlyMembers && t.symbol != nil && t.symbol.Flags&ast.SymbolFlagsValueModule != 0 && c.moduleSymbolLinks.Get(t.symbol).typeOnlyExportStarMap[name] != nil { + if !includeTypeOnlyMembers && t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsValueModule != 0 && c.moduleSymbolLinks.Get(t.symbol).typeOnlyExportStarMap[name] != nil { // If this is the type of a module, `resolved.members.get(name)` might have effectively skipped over // an `export type * from './foo'`, leaving `symbolIsValue` unable to see that the symbol is being // viewed through a type-only export. @@ -19572,18 +19572,18 @@ func (c *Checker) getBaseTypes(t *Type) []*Type { switch { case t.objectFlags&ObjectFlagsTuple != 0: data.resolvedBaseTypes = []*Type{c.getTupleBaseType(t)} - case t.symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0: - if t.symbol.Flags&ast.SymbolFlagsClass != 0 { + case t.symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0: + if t.symbol.Flags()&ast.SymbolFlagsClass != 0 { c.resolveBaseTypesOfClass(t) } - if t.symbol.Flags&ast.SymbolFlagsInterface != 0 { + if t.symbol.Flags()&ast.SymbolFlagsInterface != 0 { c.resolveBaseTypesOfInterface(t) } default: panic("Unhandled case in getBaseTypes") } - if !c.popTypeResolution() && t.symbol.Declarations != nil { - for _, declaration := range t.symbol.Declarations { + if !c.popTypeResolution() && t.symbol.Declarations() != nil { + for _, declaration := range t.symbol.Declarations() { if ast.IsClassDeclaration(declaration) || ast.IsInterfaceDeclaration(declaration) { c.reportCircularBaseType(declaration, t) } @@ -19624,7 +19624,7 @@ func (c *Checker) resolveBaseTypesOfClass(t *Type) { if baseConstructorType.symbol != nil { originalBaseType = c.getDeclaredTypeOfSymbol(baseConstructorType.symbol) } - if baseConstructorType.symbol != nil && baseConstructorType.symbol.Flags&ast.SymbolFlagsClass != 0 && c.areAllOuterTypeParametersApplied(originalBaseType) { + if baseConstructorType.symbol != nil && baseConstructorType.symbol.Flags()&ast.SymbolFlagsClass != 0 && c.areAllOuterTypeParametersApplied(originalBaseType) { // When base constructor type is a class with no captured type arguments we know that the constructors all have the same type parameters as the // class and all return the instance type of the class. There is no need for further checks and we can apply the // type arguments in the same manner as a type reference to get the same error reporting experience. @@ -19654,7 +19654,7 @@ func (c *Checker) resolveBaseTypesOfClass(t *Type) { return } if t == reducedBaseType || c.hasBaseType(reducedBaseType, t) { - c.error(t.symbol.ValueDeclaration, diagnostics.Type_0_recursively_references_itself_as_a_base_type, c.TypeToString(t)) + c.error(t.symbol.ValueDeclaration(), diagnostics.Type_0_recursively_references_itself_as_a_base_type, c.TypeToString(t)) return } t.AsInterfaceType().resolvedBaseTypes = []*Type{reducedBaseType} @@ -19893,7 +19893,7 @@ func (c *Checker) instantiateSignatureInContextOf(signature *Signature, contextu func (c *Checker) resolveBaseTypesOfInterface(t *Type) { data := t.AsInterfaceType() - for _, declaration := range t.symbol.Declarations { + for _, declaration := range t.symbol.Declarations() { if ast.IsInterfaceDeclaration(declaration) { for _, node := range ast.GetExtendsHeritageClauseElements(declaration) { baseType := c.getReducedType(c.getTypeFromTypeNode(node)) @@ -19994,11 +19994,11 @@ func (c *Checker) getTypeWithThisArgument(t *Type, thisArgument *Type, needAppar func (c *Checker) addInheritedMembers(symbols ast.SymbolTable, baseSymbols []*ast.Symbol) ast.SymbolTable { for _, base := range baseSymbols { if !isStaticPrivateIdentifierProperty(base) { - if s, ok := symbols[base.Name]; !ok || s.Flags&ast.SymbolFlagsValue == 0 { + if s, ok := symbols[base.Name()]; !ok || s.Flags()&ast.SymbolFlagsValue == 0 { if symbols == nil { symbols = make(ast.SymbolTable) } - symbols[base.Name] = base + symbols[base.Name()] = base } } } @@ -20036,7 +20036,7 @@ func (c *Checker) getIndexInfosOfIndexSymbol(indexSymbol *ast.Symbol, siblingSym readonlyComputedNumberProperty := true readonlyComputedSymbolProperty := true var propertySymbols []*ast.Symbol - for _, declaration := range indexSymbol.Declarations { + for _, declaration := range indexSymbol.Declarations() { if ast.IsIndexSignatureDeclaration(declaration) { parameters := declaration.Parameters() returnTypeNode := declaration.Type() @@ -20123,7 +20123,7 @@ func (c *Checker) getObjectLiteralIndexInfo(isReadonly bool, properties []*ast.S keyType == c.esSymbolType && c.isSymbolWithSymbolName(prop) { propTypes = append(propTypes, c.getTypeOfSymbol(prop)) if c.isSymbolWithComputedName(prop) { - components = append(components, prop.Declarations[0]) + components = append(components, prop.Declarations()[0]) } } } @@ -20138,27 +20138,27 @@ func (c *Checker) isSymbolWithSymbolName(symbol *ast.Symbol) bool { if IsKnownSymbol(symbol) { return true } - if len(symbol.Declarations) != 0 { - name := symbol.Declarations[0].Name() + if len(symbol.Declarations()) != 0 { + name := symbol.Declarations()[0].Name() return name != nil && ast.IsComputedPropertyName(name) && c.isTypeAssignableToKind(c.checkComputedPropertyName(name), TypeFlagsESSymbol) } return false } func (c *Checker) isSymbolWithNumericName(symbol *ast.Symbol) bool { - if isNumericLiteralName(symbol.Name) { + if isNumericLiteralName(symbol.Name()) { return true } - if len(symbol.Declarations) != 0 { - name := symbol.Declarations[0].Name() + if len(symbol.Declarations()) != 0 { + name := symbol.Declarations()[0].Name() return name != nil && c.isNumericName(name) } return false } func (c *Checker) isSymbolWithComputedName(symbol *ast.Symbol) bool { - if len(symbol.Declarations) != 0 { - name := symbol.Declarations[0].Name() + if len(symbol.Declarations()) != 0 { + name := symbol.Declarations()[0].Name() return name != nil && ast.IsComputedPropertyName(name) } return false @@ -20204,7 +20204,7 @@ func (c *Checker) getSignaturesOfSymbol(symbol *ast.Symbol) []*Signature { return nil } var result []*Signature - for i, decl := range symbol.Declarations { + for i, decl := range symbol.Declarations() { if !ast.IsFunctionLike(decl) { continue } @@ -20212,7 +20212,7 @@ func (c *Checker) getSignaturesOfSymbol(symbol *ast.Symbol) []*Signature { // an implementation node if it has a body and the previous node is of the same kind and immediately // precedes the implementation node (i.e. has the same parent and ends where the implementation starts). if i > 0 && decl.Body() != nil { - previous := symbol.Declarations[i-1] + previous := symbol.Declarations()[i-1] if decl.Parent == previous.Parent && decl.Kind == previous.Kind && (decl.Pos() == previous.End() || previous.Flags&ast.NodeFlagsReparsed != 0) { continue @@ -20252,11 +20252,11 @@ func (c *Checker) getSignatureFromDeclaration(declaration *ast.Node) *Signature paramSymbol := param.Symbol() typeNode := param.Type() // Include parameter symbol instead of property symbol in the signature - if paramSymbol != nil && paramSymbol.Flags&ast.SymbolFlagsProperty != 0 && !ast.IsBindingPattern(param.Name()) { - resolvedSymbol := c.resolveName(param, paramSymbol.Name, ast.SymbolFlagsValue, nil /*nameNotFoundMessage*/, false /*isUse*/, false /*excludeGlobals*/) + if paramSymbol != nil && paramSymbol.Flags()&ast.SymbolFlagsProperty != 0 && !ast.IsBindingPattern(param.Name()) { + resolvedSymbol := c.resolveName(param, paramSymbol.Name(), ast.SymbolFlagsValue, nil /*nameNotFoundMessage*/, false /*isUse*/, false /*excludeGlobals*/) paramSymbol = resolvedSymbol } - if i == 0 && paramSymbol.Name == ast.InternalSymbolNameThis { + if i == 0 && paramSymbol.Name() == ast.InternalSymbolNameThis { hasThisParameter = true thisParameter = param.Symbol() } else { @@ -20670,7 +20670,7 @@ func (c *Checker) checkAndAggregateReturnExpressionTypes(fn *ast.Node, checkMode expr = ast.SkipParentheses(expr.Expression()) } if ast.IsCallExpression(expr) && ast.IsIdentifier(expr.Expression()) && c.checkExpressionCached(expr.Expression()).symbol == c.getMergedSymbol(fn.Symbol()) && - (!ast.IsFunctionExpressionOrArrowFunction(fn.Symbol().ValueDeclaration) || c.isConstantReference(expr.Expression())) { + (!ast.IsFunctionExpressionOrArrowFunction(fn.Symbol().ValueDeclaration()) || c.isConstantReference(expr.Expression())) { hasReturnOfTypeNever = true return false } @@ -20912,9 +20912,9 @@ func (c *Checker) reportWideningErrorsInType(t *Type) bool { errorReported = c.reportWideningErrorsInType(s) if !errorReported { // we need to account for property types coming from object literal type normalization in unions - valueDeclaration := core.Find(p.Declarations, func(d *ast.Node) bool { - valueDeclaration := d.Symbol().ValueDeclaration - return valueDeclaration != nil && valueDeclaration.Parent == t.symbol.ValueDeclaration + valueDeclaration := core.Find(p.Declarations(), func(d *ast.Node) bool { + valueDeclaration := d.Symbol().ValueDeclaration() + return valueDeclaration != nil && valueDeclaration.Parent == t.symbol.ValueDeclaration() }) if valueDeclaration != nil { c.error(valueDeclaration, diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, c.symbolToString(p), c.TypeToString(c.getWidenedType(s))) @@ -21055,7 +21055,7 @@ func (c *Checker) resolveAnonymousTypeMembers(t *Type) { return } symbol := c.getMergedSymbol(t.symbol) - if symbol.Flags&ast.SymbolFlagsTypeLiteral != 0 { + if symbol.Flags()&ast.SymbolFlagsTypeLiteral != 0 { c.setStructuredTypeMembers(t, nil, nil, nil, nil) members := c.getMembersOfSymbol(symbol) callSignatures := c.getSignaturesOfSymbol(members[ast.InternalSymbolNameCall]) @@ -21070,15 +21070,15 @@ func (c *Checker) resolveAnonymousTypeMembers(t *Type) { if symbol == c.globalThisSymbol { varsOnly := make(ast.SymbolTable) for _, p := range members { - if p.Flags&ast.SymbolFlagsBlockScoped == 0 && !(p.Flags&ast.SymbolFlagsValueModule != 0 && len(p.Declarations) != 0 && core.Every(p.Declarations, ast.IsAmbientModule)) { - varsOnly[p.Name] = p + if p.Flags()&ast.SymbolFlagsBlockScoped == 0 && !(p.Flags()&ast.SymbolFlagsValueModule != 0 && len(p.Declarations()) != 0 && core.Every(p.Declarations(), ast.IsAmbientModule)) { + varsOnly[p.Name()] = p } } members = varsOnly } var baseConstructorIndexInfo *IndexInfo c.setStructuredTypeMembers(t, members, nil, nil, nil) - if symbol.Flags&ast.SymbolFlagsClass != 0 { + if symbol.Flags()&ast.SymbolFlagsClass != 0 { classType := c.getDeclaredTypeOfClassOrInterface(symbol) baseConstructorType := c.getBaseConstructorTypeOfClass(classType) if baseConstructorType.flags&(TypeFlagsObject|TypeFlagsIntersection|TypeFlagsTypeVariable) != 0 { @@ -21096,7 +21096,7 @@ func (c *Checker) resolveAnonymousTypeMembers(t *Type) { if baseConstructorIndexInfo != nil { indexInfos = append(indexInfos, baseConstructorIndexInfo) } - if symbol.Flags&ast.SymbolFlagsEnum != 0 && (c.getDeclaredTypeOfSymbol(symbol).flags&TypeFlagsEnum != 0 || core.Some(d.properties, func(prop *ast.Symbol) bool { + if symbol.Flags()&ast.SymbolFlagsEnum != 0 && (c.getDeclaredTypeOfSymbol(symbol).flags&TypeFlagsEnum != 0 || core.Some(d.properties, func(prop *ast.Symbol) bool { return c.getTypeOfSymbol(prop).flags&TypeFlagsNumberLike != 0 })) { indexInfos = append(indexInfos, c.enumNumberIndexInfo) @@ -21107,14 +21107,14 @@ func (c *Checker) resolveAnonymousTypeMembers(t *Type) { // typeof with a qualified name expression that circularly references the type we are // in the process of resolving (see issue #6072). The temporarily empty signature list // will never be observed because a qualified name can't reference signatures. - if symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { + if symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { d.signatures = c.getSignaturesOfSymbol(symbol) d.callSignatureCount = len(d.signatures) } // And likewise for construct signatures for classes - if symbol.Flags&ast.SymbolFlagsClass != 0 { + if symbol.Flags()&ast.SymbolFlagsClass != 0 { classType := c.getDeclaredTypeOfClassOrInterface(symbol) - constructSignatures := c.getSignaturesOfSymbol(symbol.Members[ast.InternalSymbolNameConstructor]) + constructSignatures := c.getSignaturesOfSymbol(symbol.Members()[ast.InternalSymbolNameConstructor]) if len(constructSignatures) == 0 { constructSignatures = c.getDefaultConstructSignatures(classType) } @@ -21128,7 +21128,7 @@ func (c *Checker) createInstantiatedSymbolTable(symbols []*ast.Symbol, m *TypeMa } result := make(ast.SymbolTable, len(symbols)) for _, symbol := range symbols { - result[symbol.Name] = c.instantiateSymbol(symbol, m) + result[symbol.Name()] = c.instantiateSymbol(symbol, m) } return result } @@ -21157,7 +21157,7 @@ func (c *Checker) instantiateSymbol(symbol *ast.Symbol, m *TypeMapper) *ast.Symb // If the type of the symbol is already resolved, and if that type could not possibly // be affected by instantiation, simply return the symbol itself. if links.resolvedType != nil && !c.couldContainTypeVariables(links.resolvedType) { - if symbol.Flags&ast.SymbolFlagsSetAccessor == 0 { + if symbol.Flags()&ast.SymbolFlagsSetAccessor == 0 { return symbol } // If we're a setter, check writeType. @@ -21165,7 +21165,7 @@ func (c *Checker) instantiateSymbol(symbol *ast.Symbol, m *TypeMapper) *ast.Symb return symbol } } - if symbol.CheckFlags&ast.CheckFlagsInstantiated != 0 { + if symbol.CheckFlags()&ast.CheckFlagsInstantiated != 0 { // If symbol being instantiated is itself a instantiation, fetch the original target and combine the // type mappers. This ensures that original type identities are properly preserved and that aliases // always reference a non-aliases. @@ -21174,11 +21174,11 @@ func (c *Checker) instantiateSymbol(symbol *ast.Symbol, m *TypeMapper) *ast.Symb } // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. - result := c.newSymbol(symbol.Flags, symbol.Name) - result.CheckFlags = ast.CheckFlagsInstantiated | symbol.CheckFlags&(ast.CheckFlagsReadonly|ast.CheckFlagsLate|ast.CheckFlagsOptionalParameter|ast.CheckFlagsRestParameter) - result.Declarations = symbol.Declarations - result.Parent = symbol.Parent - result.ValueDeclaration = symbol.ValueDeclaration + result := c.newSymbol(symbol.Flags(), symbol.Name()) + result.SetCheckFlags(ast.CheckFlagsInstantiated | symbol.CheckFlags()&(ast.CheckFlagsReadonly|ast.CheckFlagsLate|ast.CheckFlagsOptionalParameter|ast.CheckFlagsRestParameter)) + result.SetDeclarations(symbol.Declarations()) + result.SetParent(symbol.Parent()) + result.SetValueDeclaration(symbol.ValueDeclaration()) resultLinks := c.valueSymbolLinks.Get(result) resultLinks.target = symbol resultLinks.mapper = m @@ -21192,8 +21192,8 @@ func (c *Checker) instantiateSymbol(symbol *ast.Symbol, m *TypeMapper) *ast.Symb // inferred from their initializers and function members with inferred return types are conservatively // assumed not to be free of "this" references. func isThisless(symbol *ast.Symbol) bool { - if len(symbol.Declarations) == 1 { - declaration := symbol.Declarations[0] + if len(symbol.Declarations()) == 1 { + declaration := symbol.Declarations()[0] if declaration != nil { switch declaration.Kind { case ast.KindParameter: @@ -21322,15 +21322,15 @@ func (c *Checker) resolveMappedTypeMembers(t *Type) { if isTypeUsableAsPropertyName(keyType) { modifiersProp = c.getPropertyOfType(modifiersType, getPropertyNameFromType(keyType)) } - isOptional := templateModifiers&MappedTypeModifiersIncludeOptional != 0 || templateModifiers&MappedTypeModifiersExcludeOptional == 0 && modifiersProp != nil && modifiersProp.Flags&ast.SymbolFlagsOptional != 0 + isOptional := templateModifiers&MappedTypeModifiersIncludeOptional != 0 || templateModifiers&MappedTypeModifiersExcludeOptional == 0 && modifiersProp != nil && modifiersProp.Flags()&ast.SymbolFlagsOptional != 0 isReadonly := templateModifiers&MappedTypeModifiersIncludeReadonly != 0 || templateModifiers&MappedTypeModifiersExcludeReadonly == 0 && modifiersProp != nil && c.isReadonlySymbol(modifiersProp) - stripOptional := c.strictNullChecks && !isOptional && modifiersProp != nil && modifiersProp.Flags&ast.SymbolFlagsOptional != 0 + stripOptional := c.strictNullChecks && !isOptional && modifiersProp != nil && modifiersProp.Flags()&ast.SymbolFlagsOptional != 0 var lateFlag ast.CheckFlags if modifiersProp != nil { - lateFlag = modifiersProp.CheckFlags & ast.CheckFlagsLate + lateFlag = modifiersProp.CheckFlags() & ast.CheckFlagsLate } prop := c.newSymbol(ast.SymbolFlagsProperty|core.IfElse(isOptional, ast.SymbolFlagsOptional, 0), propName) - prop.CheckFlags = lateFlag | ast.CheckFlagsMapped | core.IfElse(isReadonly, ast.CheckFlagsReadonly, 0) | core.IfElse(stripOptional, ast.CheckFlagsStripOptional, 0) + prop.SetCheckFlags(lateFlag | ast.CheckFlagsMapped | core.IfElse(isReadonly, ast.CheckFlagsReadonly, 0) | core.IfElse(stripOptional, ast.CheckFlagsStripOptional, 0)) valueLinks := c.valueSymbolLinks.Get(prop) valueLinks.containingType = t valueLinks.nameType = propNameType @@ -21339,7 +21339,7 @@ func (c *Checker) resolveMappedTypeMembers(t *Type) { if modifiersProp != nil { mappedLinks.syntheticOrigin = modifiersProp if shouldLinkPropDeclarations { - prop.Declarations = modifiersProp.Declarations + prop.SetDeclarations(modifiersProp.Declarations()) } } members[propName] = prop @@ -21392,9 +21392,9 @@ func (c *Checker) getTypeOfMappedSymbol(symbol *ast.Symbol) *Type { // type, we include 'undefined' in the type. Similarly, when creating a non-optional property in strictNullChecks // mode, if the underlying property is optional we remove 'undefined' from the type. switch { - case c.strictNullChecks && symbol.Flags&ast.SymbolFlagsOptional != 0 && !c.maybeTypeOfKind(propType, TypeFlagsUndefined|TypeFlagsVoid): + case c.strictNullChecks && symbol.Flags()&ast.SymbolFlagsOptional != 0 && !c.maybeTypeOfKind(propType, TypeFlagsUndefined|TypeFlagsVoid): propType = c.getOptionalType(propType, true /*isProperty*/) - case symbol.CheckFlags&ast.CheckFlagsStripOptional != 0: + case symbol.CheckFlags()&ast.CheckFlagsStripOptional != 0: propType = c.removeMissingOrUndefinedType(propType) } if c.popTypeResolution() { @@ -21468,21 +21468,21 @@ func (c *Checker) getArrayMemberCallSignatures(t *Type) []*Signature { // Check if union is exclusively instantiations of a member of the global Array or ReadonlyArray type. var memberName string for i, t := range t.Types() { - if t.objectFlags&ObjectFlagsInstantiated == 0 || t.symbol == nil || t.symbol.Parent == nil || !c.isArrayOrTupleSymbol(t.symbol.Parent) { + if t.objectFlags&ObjectFlagsInstantiated == 0 || t.symbol == nil || t.symbol.Parent() == nil || !c.isArrayOrTupleSymbol(t.symbol.Parent()) { return nil } if i == 0 { - memberName = t.symbol.Name - } else if memberName != t.symbol.Name { + memberName = t.symbol.Name() + } else if memberName != t.symbol.Name() { return nil } } // Transform the type from `(A[] | B[])["member"]` to `(A | B)[]["member"]` (since we pretend array is covariant anyway). arrayArg := c.mapType(t, func(t *Type) *Type { - return getMappedType(core.IfElse(c.isReadonlyArraySymbol(t.symbol.Parent), c.globalReadonlyArrayType, c.globalArrayType).AsInterfaceType().TypeParameters()[0], t.Mapper()) + return getMappedType(core.IfElse(c.isReadonlyArraySymbol(t.symbol.Parent()), c.globalReadonlyArrayType, c.globalArrayType).AsInterfaceType().TypeParameters()[0], t.Mapper()) }) arrayType := c.createArrayTypeEx(arrayArg, someType(t, func(t *Type) bool { - return c.isReadonlyArraySymbol(t.symbol.Parent) + return c.isReadonlyArraySymbol(t.symbol.Parent()) })) return c.getSignaturesOfType(c.getTypeOfPropertyOfType(arrayType, memberName), SignatureKindCall) } @@ -21590,7 +21590,7 @@ func (c *Checker) combineUnionOrIntersectionMemberSignatures(left *Signature, ri declaration := left.declaration params := c.combineUnionOrIntersectionParameters(left, right, paramMapper, isUnion) lastParam := core.LastOrNil(params) - if lastParam != nil && lastParam.CheckFlags&ast.CheckFlagsRestParameter != 0 { + if lastParam != nil && lastParam.CheckFlags()&ast.CheckFlagsRestParameter != 0 { flags |= SignatureFlagsHasRestParameter } thisParam := c.combineUnionOrIntersectionThisParam(left.thisParameter, right.thisParameter, paramMapper, isUnion) @@ -21810,7 +21810,7 @@ func (c *Checker) getPropertyOfObjectType(t *Type, name string) *ast.Symbol { func (c *Checker) getPropertyOfUnionOrIntersectionType(t *Type, name string, skipObjectFunctionPropertyAugment bool) *ast.Symbol { prop := c.getUnionOrIntersectionProperty(t, name, skipObjectFunctionPropertyAugment) // We need to filter out partial properties in union types - if prop != nil && prop.CheckFlags&ast.CheckFlagsReadPartial != 0 { + if prop != nil && prop.CheckFlags()&ast.CheckFlagsReadPartial != 0 { return nil } return prop @@ -21835,7 +21835,7 @@ func (c *Checker) getUnionOrIntersectionProperty(t *Type, name string, skipObjec if prop != nil { cache[name] = prop // Propagate an entry from the non-augmented cache to the augmented cache unless the property is partial. - if skipObjectFunctionPropertyAugment && prop.CheckFlags&ast.CheckFlagsPartial == 0 { + if skipObjectFunctionPropertyAugment && prop.CheckFlags()&ast.CheckFlagsPartial == 0 { augmentedCache := ast.GetSymbolTable(&t.AsUnionOrIntersectionType().propertyCache) if augmentedCache[name] == nil { augmentedCache[name] = prop @@ -21868,16 +21868,16 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s if prop != nil { modifiers = getDeclarationModifierFlagsFromSymbol(prop) writeModifiers := getDeclarationModifierFlagsFromSymbolEx(prop, true /*isWrite*/) - if prop.Flags&ast.SymbolFlagsClassMember != 0 { + if prop.Flags()&ast.SymbolFlagsClassMember != 0 { if isUnion { - optionalFlag |= prop.Flags & ast.SymbolFlagsOptional + optionalFlag |= prop.Flags() & ast.SymbolFlagsOptional } else { - optionalFlag &= prop.Flags + optionalFlag &= prop.Flags() } } if singleProp == nil { singleProp = prop - propFlags = core.OrElse(prop.Flags&ast.SymbolFlagsAccessor, ast.SymbolFlagsProperty) + propFlags = core.OrElse(prop.Flags()&ast.SymbolFlagsAccessor, ast.SymbolFlagsProperty) } else if prop != singleProp { isInstantiation := c.getTargetSymbol(prop) == c.getTargetSymbol(singleProp) // If the symbols are instances of one another with identical types - consider the symbols @@ -21887,7 +21887,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s // If we merged instantiations of a generic type, we replicate the symbol parent resetting behavior we used // to do when we recorded multiple distinct symbols so that we still get, eg, `Array.length` printed // back and not `Array.length` when we're looking at a `.length` access on a `string[] | number[]` - mergedInstantiations = singleProp.Parent != nil && len(c.getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(singleProp.Parent)) != 0 + mergedInstantiations = singleProp.Parent() != nil && len(c.getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(singleProp.Parent())) != 0 } else { if propSet.Size() == 0 { propSet.Add(singleProp) @@ -21898,7 +21898,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s // and overriding a property in a derived class redefines it completely at runtime // so a get accessor can't be merged with a set accessor in a base class, // for that reason the accessor flags are only used when they are the same in all constituents - if propFlags&ast.SymbolFlagsAccessor != 0 && (prop.Flags&ast.SymbolFlagsAccessor != (propFlags & ast.SymbolFlagsAccessor)) { + if propFlags&ast.SymbolFlagsAccessor != 0 && (prop.Flags()&ast.SymbolFlagsAccessor != (propFlags & ast.SymbolFlagsAccessor)) { propFlags = (propFlags &^ ast.SymbolFlagsAccessor) | ast.SymbolFlagsProperty } } @@ -21984,14 +21984,14 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s // They also have a `.containingType` set, which affects some services endpoints behavior, like `getRootSymbol` var singlePropType *Type var singlePropMapper *TypeMapper - if singleProp.Flags&ast.SymbolFlagsTransient != 0 { + if singleProp.Flags()&ast.SymbolFlagsTransient != 0 { links := c.valueSymbolLinks.Get(singleProp) singlePropType = links.resolvedType singlePropMapper = links.mapper } clone := c.createSymbolWithType(singleProp, singlePropType) - if singleProp.ValueDeclaration != nil { - clone.Parent = singleProp.ValueDeclaration.Symbol().Parent + if singleProp.ValueDeclaration() != nil { + clone.SetParent(singleProp.ValueDeclaration().Symbol().Parent()) } links := c.valueSymbolLinks.Get(clone) links.containingType = containingType @@ -22011,11 +22011,11 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s var hasNonUniformValueDeclaration bool for prop := range propSet.Values() { if firstValueDeclaration == nil { - firstValueDeclaration = prop.ValueDeclaration - } else if prop.ValueDeclaration != nil && prop.ValueDeclaration != firstValueDeclaration { + firstValueDeclaration = prop.ValueDeclaration() + } else if prop.ValueDeclaration() != nil && prop.ValueDeclaration() != firstValueDeclaration { hasNonUniformValueDeclaration = true } - for _, declaration := range prop.Declarations { + for _, declaration := range prop.Declarations() { declarations = core.AppendIfUnique(declarations, declaration) } t := c.getTypeOfSymbol(prop) @@ -22043,18 +22043,18 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s } propTypes = append(propTypes, indexTypes...) result := c.newSymbolEx(propFlags|optionalFlag, name, checkFlags|syntheticFlag) - result.Declarations = declarations + result.SetDeclarations(declarations) if !hasNonUniformValueDeclaration && firstValueDeclaration != nil { - result.ValueDeclaration = firstValueDeclaration + result.SetValueDeclaration(firstValueDeclaration) // Inherit information about parent type. - result.Parent = firstValueDeclaration.Symbol().Parent + result.SetParent(firstValueDeclaration.Symbol().Parent()) } links := c.valueSymbolLinks.Get(result) links.containingType = containingType links.nameType = nameType if len(propTypes) > 2 { // When `propTypes` has the potential to explode in size when normalized, defer normalization until absolutely needed - result.CheckFlags |= ast.CheckFlagsDeferredType + result.SetCheckFlags(result.CheckFlags() | ast.CheckFlagsDeferredType) deferred := c.deferredSymbolLinks.Get(result) deferred.parent = containingType deferred.constituents = propTypes @@ -22079,7 +22079,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s func (c *Checker) getTargetSymbol(s *ast.Symbol) *ast.Symbol { // if symbol is instantiated its flags are not copied from the 'target' // so we'll need to get back original 'target' symbol to work with correct set of flags - if s != nil && s.CheckFlags&ast.CheckFlagsInstantiated != 0 { + if s != nil && s.CheckFlags()&ast.CheckFlagsInstantiated != 0 { return c.valueSymbolLinks.Get(s).target } return s @@ -22090,23 +22090,23 @@ func (c *Checker) getTargetSymbol(s *ast.Symbol) *ast.Symbol { * Note that this is not tracked well within the compiler, so the answer may be incorrect. */ func isPrototypeProperty(symbol *ast.Symbol) bool { - return symbol.Flags&ast.SymbolFlagsMethod != 0 || symbol.CheckFlags&ast.CheckFlagsSyntheticMethod != 0 + return symbol.Flags()&ast.SymbolFlagsMethod != 0 || symbol.CheckFlags()&ast.CheckFlagsSyntheticMethod != 0 } func (c *Checker) hasCommonDeclaration(symbols *collections.OrderedSet[*ast.Symbol]) bool { var commonDeclarations collections.Set[*ast.Node] for symbol := range symbols.Values() { - if len(symbol.Declarations) == 0 { + if len(symbol.Declarations()) == 0 { return false } if commonDeclarations.Len() == 0 { - for _, d := range symbol.Declarations { + for _, d := range symbol.Declarations() { commonDeclarations.Add(d) } continue } for d := range commonDeclarations.Keys() { - if !slices.Contains(symbol.Declarations, d) { + if !slices.Contains(symbol.Declarations(), d) { commonDeclarations.Delete(d) } } @@ -22118,10 +22118,10 @@ func (c *Checker) hasCommonDeclaration(symbols *collections.OrderedSet[*ast.Symb } func (c *Checker) createSymbolWithType(source *ast.Symbol, t *Type) *ast.Symbol { - symbol := c.newSymbolEx(source.Flags, source.Name, source.CheckFlags&ast.CheckFlagsReadonly) - symbol.Declarations = source.Declarations - symbol.Parent = source.Parent - symbol.ValueDeclaration = source.ValueDeclaration + symbol := c.newSymbolEx(source.Flags(), source.Name(), source.CheckFlags()&ast.CheckFlagsReadonly) + symbol.SetDeclarations(source.Declarations()) + symbol.SetParent(source.Parent()) + symbol.SetValueDeclaration(source.ValueDeclaration()) links := c.valueSymbolLinks.Get(symbol) links.resolvedType = t links.target = source @@ -22277,7 +22277,7 @@ func (c *Checker) somePropertyReducesToNever(t *Type) bool { var counts collections.OrderedMap[string, int] for _, t := range t.Types() { for _, prop := range c.getPropertiesOfType(t) { - counts.Set(prop.Name, counts.GetOrZero(prop.Name)+1) + counts.Set(prop.Name(), counts.GetOrZero(prop.Name())+1) } } // Check if any property appears in more than one constituent type and reduces to 'never'. @@ -22333,12 +22333,12 @@ func (c *Checker) elaborateNeverIntersection(chain *ast.Diagnostic, node *ast.No func (c *Checker) isDiscriminantWithNeverType(prop *ast.Symbol) bool { // Return true for a synthetic non-optional property with non-uniform types, where at least one is // a literal type and none is never, that reduces to never. - return prop.Flags&ast.SymbolFlagsOptional == 0 && prop.CheckFlags&(ast.CheckFlagsNonUniformAndLiteral|ast.CheckFlagsHasNeverType) == ast.CheckFlagsNonUniformAndLiteral && c.getTypeOfSymbol(prop).flags&TypeFlagsNever != 0 + return prop.Flags()&ast.SymbolFlagsOptional == 0 && prop.CheckFlags()&(ast.CheckFlagsNonUniformAndLiteral|ast.CheckFlagsHasNeverType) == ast.CheckFlagsNonUniformAndLiteral && c.getTypeOfSymbol(prop).flags&TypeFlagsNever != 0 } func isConflictingPrivateProperty(prop *ast.Symbol) bool { // Return true for a synthetic property with multiple declarations, at least one of which is private. - return prop.ValueDeclaration == nil && prop.CheckFlags&ast.CheckFlagsContainsPrivate != 0 + return prop.ValueDeclaration() == nil && prop.CheckFlags()&ast.CheckFlagsContainsPrivate != 0 } func (c *Checker) getTypeArguments(t *Type) []*Type { @@ -22397,7 +22397,7 @@ func (c *Checker) getMinTypeArgumentCount(typeParameters []*Type) int { } func (c *Checker) hasTypeParameterDefault(t *Type) bool { - return t.symbol != nil && core.Some(t.symbol.Declarations, func(d *ast.Node) bool { + return t.symbol != nil && core.Some(t.symbol.Declarations(), func(d *ast.Node) bool { return ast.IsTypeParameterDeclaration(d) && d.AsTypeParameterDeclaration().DefaultType != nil }) } @@ -22470,7 +22470,7 @@ func (c *Checker) getResolvedTypeParameterDefault(t *Type) *Type { d.resolvedDefaultType = c.resolvingDefaultType defaultType := c.noConstraintType if t.symbol != nil { - defaultDeclaration := core.FirstNonNil(t.symbol.Declarations, func(decl *ast.Node) *ast.Node { + defaultDeclaration := core.FirstNonNil(t.symbol.Declarations(), func(decl *ast.Node) *ast.Node { if ast.IsTypeParameterDeclaration(decl) { return decl.AsTypeParameterDeclaration().DefaultType } @@ -22506,7 +22506,7 @@ func (c *Checker) getNamedMembers(members ast.SymbolTable, container *ast.Symbol // likely to contain discriminating differences. See for example https://github.com/microsoft/TypeScript/tsc/issues/1968. result := make([]*ast.Symbol, 0, len(members)) var containedCount int - if container != nil && container.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { + if container != nil && container.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { for id, symbol := range members { if c.isNamedMember(symbol, id) && c.isDeclarationContainedBy(symbol, container) { result = append(result, symbol) @@ -22515,7 +22515,7 @@ func (c *Checker) getNamedMembers(members ast.SymbolTable, container *ast.Symbol containedCount = len(result) } for id, symbol := range members { - if c.isNamedMember(symbol, id) && (container == nil || container.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) == 0 || !c.isDeclarationContainedBy(symbol, container)) { + if c.isNamedMember(symbol, id) && (container == nil || container.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) == 0 || !c.isDeclarationContainedBy(symbol, container)) { result = append(result, symbol) } } @@ -22525,8 +22525,8 @@ func (c *Checker) getNamedMembers(members ast.SymbolTable, container *ast.Symbol } func (c *Checker) isDeclarationContainedBy(symbol *ast.Symbol, container *ast.Symbol) bool { - if declaration := symbol.ValueDeclaration; declaration != nil { - for _, d := range container.Declarations { + if declaration := symbol.ValueDeclaration(); declaration != nil { + for _, d := range container.Declarations() { if declaration.Loc.ContainedBy(d.Loc) { return true } @@ -22544,7 +22544,7 @@ func (c *Checker) symbolIsValue(symbol *ast.Symbol) bool { } func (c *Checker) symbolIsValueEx(symbol *ast.Symbol, includeTypeOnlyMembers bool) bool { - return symbol.Flags&ast.SymbolFlagsValue != 0 || symbol.Flags&ast.SymbolFlagsAlias != 0 && + return symbol.Flags()&ast.SymbolFlagsValue != 0 || symbol.Flags()&ast.SymbolFlagsAlias != 0 && c.getSymbolFlagsEx(symbol, !includeTypeOnlyMembers, false /*excludeLocalMeanings*/)&ast.SymbolFlagsValue != 0 } @@ -22613,7 +22613,7 @@ func (c *Checker) getCircularTypeNames() []string { if t.alias != nil { symbol = t.alias.symbol } - if symbol != nil && len(symbol.Name) != 0 && symbol.Name[0] != '\xFE' { + if symbol != nil && len(symbol.Name()) != 0 && symbol.Name()[0] != '\xFE' { if name := c.SymbolToString(symbol); !slices.Contains(circularTypeNames, name) { circularTypeNames = append(circularTypeNames, name) } @@ -22671,7 +22671,7 @@ func (c *Checker) couldContainTypeVariablesWorker(t *Type) bool { } result := t.flags&TypeFlagsInstantiable != 0 || t.flags&TypeFlagsObject != 0 && !c.isNonGenericTopLevelType(t) && (objectFlags&ObjectFlagsReference != 0 && (t.AsTypeReference().node != nil || core.Some(c.getTypeArguments(t), c.couldContainTypeVariables)) || - objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && t.symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsObjectLiteral) != 0 && t.symbol.Declarations != nil || + objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && t.symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsObjectLiteral) != 0 && t.symbol.Declarations() != nil || objectFlags&(ObjectFlagsMapped|ObjectFlagsReverseMapped|ObjectFlagsObjectRestType|ObjectFlagsInstantiationExpressionType) != 0) || t.flags&TypeFlagsUnionOrIntersection != 0 && t.flags&TypeFlagsEnumLiteral == 0 && !c.isNonGenericTopLevelType(t) && core.Some(t.Types(), c.couldContainTypeVariables) t.objectFlags |= ObjectFlagsCouldContainTypeVariablesComputed | core.IfElse(result, ObjectFlagsCouldContainTypeVariables, 0) @@ -22791,7 +22791,7 @@ func (c *Checker) getObjectTypeInstantiation(t *Type, m *TypeMapper, alias *Type case t.objectFlags&ObjectFlagsInstantiationExpressionType != 0: declaration = t.AsInstantiationExpressionType().node default: - declaration = t.symbol.Declarations[0] + declaration = t.symbol.Declarations()[0] } links := c.typeNodeLinks.Get(declaration) switch { @@ -22814,9 +22814,9 @@ func (c *Checker) getObjectTypeInstantiation(t *Type, m *TypeMapper, alias *Type typeParameters = core.Filter(typeParameters, func(tp *Type) bool { return c.isTypeParameterPossiblyReferenced(tp, declaration) }) - } else if target.symbol.Flags&(ast.SymbolFlagsMethod|ast.SymbolFlagsTypeLiteral) != 0 { + } else if target.symbol.Flags()&(ast.SymbolFlagsMethod|ast.SymbolFlagsTypeLiteral) != 0 { typeParameters = core.Filter(typeParameters, func(tp *Type) bool { - return core.Some(t.symbol.Declarations, func(d *ast.Node) bool { + return core.Some(t.symbol.Declarations(), func(d *ast.Node) bool { return c.isTypeParameterPossiblyReferenced(tp, d) }) }) @@ -22896,7 +22896,7 @@ func (c *Checker) isTypeParameterPossiblyReferenced(tp *Type, node *ast.Node) bo firstIdentifier := ast.GetFirstIdentifier(entityName) if !ast.IsThisIdentifier(firstIdentifier) { firstIdentifierSymbol := c.getResolvedSymbol(firstIdentifier) - tpDeclaration := tp.symbol.Declarations[0] // There is exactly one declaration, otherwise `containsReference` is not called + tpDeclaration := tp.symbol.Declarations()[0] // There is exactly one declaration, otherwise `containsReference` is not called var tpScope *ast.Node switch { case ast.IsTypeParameterDeclaration(tpDeclaration): @@ -22905,7 +22905,7 @@ func (c *Checker) isTypeParameterPossiblyReferenced(tp *Type, node *ast.Node) bo tpScope = tpDeclaration // Type parameter is the this type, and its declaration is the class declaration. } if tpScope != nil { - return core.Some(firstIdentifierSymbol.Declarations, func(d *ast.Node) bool { return isNodeDescendantOf(d, tpScope) }) || + return core.Some(firstIdentifierSymbol.Declarations(), func(d *ast.Node) bool { return isNodeDescendantOf(d, tpScope) }) || core.Some(node.TypeArguments(), containsReference) } } @@ -22923,8 +22923,8 @@ func (c *Checker) isTypeParameterPossiblyReferenced(tp *Type, node *ast.Node) bo // between the node and the type parameter declaration, if the node contains actual references to the // type parameter, or if the node contains type queries that we can't prove couldn't contain references to the type parameter, // we consider the type parameter possibly referenced. - if tp.symbol != nil && len(tp.symbol.Declarations) == 1 { - container := tp.symbol.Declarations[0].Parent + if tp.symbol != nil && len(tp.symbol.Declarations()) == 1 { + container := tp.symbol.Declarations()[0].Parent for n := node; n != container; n = n.Parent { if n == nil || ast.IsBlock(n) || ast.IsConditionalTypeNode(n) && containsReference(n.AsConditionalTypeNode().ExtendsType) { return true @@ -23468,7 +23468,7 @@ func (c *Checker) getESSymbolLikeTypeForNode(node *ast.Node) *Type { var b strings.Builder b.WriteString(ast.InternalSymbolNamePrefix) b.WriteByte('@') - b.WriteString(symbol.Name) + b.WriteString(symbol.Name()) b.WriteByte('@') b.WriteString(strconv.FormatUint(uint64(ast.GetSymbolId(symbol)), 10)) uniqueType = c.newUniqueESSymbolType(symbol, b.String()) @@ -23644,7 +23644,7 @@ func (c *Checker) getUnresolvedSymbolForEntityName(name *ast.Node) *ast.Symbol { if result == nil { result = c.newSymbolEx(ast.SymbolFlagsTypeAlias, text, ast.CheckFlagsUnresolved) c.unresolvedSymbols[path] = result - result.Parent = parentSymbol + result.SetParent(parentSymbol) c.typeAliasLinks.Get(result).declaredType = c.unresolvedType } return result @@ -23653,20 +23653,20 @@ func (c *Checker) getUnresolvedSymbolForEntityName(name *ast.Node) *ast.Symbol { } func getSymbolPath(symbol *ast.Symbol) string { - if symbol.Parent != nil { - return getSymbolPath(symbol.Parent) + "." + symbol.Name + if symbol.Parent() != nil { + return getSymbolPath(symbol.Parent()) + "." + symbol.Name() } - return symbol.Name + return symbol.Name() } func (c *Checker) getTypeReferenceType(node *ast.Node, symbol *ast.Symbol) *Type { if symbol == c.unknownSymbol { return c.errorType } - if symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { + if symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { return c.getTypeFromClassOrInterfaceReference(node, symbol) } - if symbol.Flags&ast.SymbolFlagsTypeAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsTypeAlias != 0 { return c.getTypeFromTypeAliasReference(node, symbol) } // Get type from reference to named type that cannot be generic (enum or type parameter) @@ -23787,7 +23787,7 @@ func (c *Checker) isResolvedByTypeAlias(node *ast.Node) bool { func (c *Checker) mayResolveTypeAlias(node *ast.Node) bool { switch node.Kind { case ast.KindTypeReference: - return c.resolveTypeReferenceName(node, ast.SymbolFlagsType, false).Flags&ast.SymbolFlagsTypeAlias != 0 + return c.resolveTypeReferenceName(node, ast.SymbolFlagsType, false).Flags()&ast.SymbolFlagsTypeAlias != 0 case ast.KindTypeQuery: return true case ast.KindTypeOperator: @@ -24095,7 +24095,7 @@ func (c *Checker) getTupleElementType(t *Type, index int) *Type { */ func (c *Checker) getTypeFromTypeAliasReference(node *ast.Node, symbol *ast.Symbol) *Type { typeArguments := node.TypeArguments() - if symbol.CheckFlags&ast.CheckFlagsUnresolved != 0 { + if symbol.CheckFlags()&ast.CheckFlagsUnresolved != 0 { alias := &TypeAlias{symbol: symbol, typeArguments: core.Map(typeArguments, c.getTypeFromTypeNode)} key := getAliasKey(alias) errorType := c.errorTypes[key] @@ -24136,7 +24136,7 @@ func (c *Checker) getTypeFromTypeAliasReference(node *ast.Node, symbol *ast.Symb // we ensure the exported symbol is used to refer to the type when it is reserialized later if aliasSymbol != nil && aliasSymbol != c.unknownSymbol { resolved := c.resolveAlias(aliasSymbol) - if resolved != nil && resolved.Flags&ast.SymbolFlagsTypeAlias != 0 { + if resolved != nil && resolved.Flags()&ast.SymbolFlagsTypeAlias != 0 { newAliasSymbol = resolved aliasTypeArguments = c.getTypeArgumentsFromNode(node) } @@ -24157,7 +24157,7 @@ func (c *Checker) getTypeFromTypeAliasReference(node *ast.Node, symbol *ast.Symb func (c *Checker) getTypeAliasInstantiation(symbol *ast.Symbol, typeArguments []*Type, alias *TypeAlias) *Type { t := c.getDeclaredTypeOfSymbol(symbol) if t == c.intrinsicMarkerType { - if typeKind, ok := intrinsicTypeKinds[symbol.Name]; ok && len(typeArguments) == 1 { + if typeKind, ok := intrinsicTypeKinds[symbol.Name()]; ok && len(typeArguments) == 1 { switch typeKind { case IntrinsicTypeKindNoInfer: return c.getNoInferType(typeArguments[0]) @@ -24171,7 +24171,7 @@ func (c *Checker) getTypeAliasInstantiation(symbol *ast.Symbol, typeArguments [] key := getTypeAliasInstantiationKey(typeArguments, alias) instantiation := links.instantiations[key] if instantiation == nil { - mapper := newTypeMapper(typeParameters, c.fillMissingTypeArguments(typeArguments, typeParameters, c.getMinTypeArgumentCount(typeParameters), ast.IsInJSFile(symbol.ValueDeclaration))) + mapper := newTypeMapper(typeParameters, c.fillMissingTypeArguments(typeArguments, typeParameters, c.getMinTypeArgumentCount(typeParameters), ast.IsInJSFile(symbol.ValueDeclaration()))) instantiation = c.instantiateTypeWithAlias(t, mapper, alias) links.instantiations[key] = instantiation } @@ -24179,7 +24179,7 @@ func (c *Checker) getTypeAliasInstantiation(symbol *ast.Symbol, typeArguments [] } func isLocalTypeAlias(symbol *ast.Symbol) bool { - declaration := core.Find(symbol.Declarations, isTypeAlias) + declaration := core.Find(symbol.Declarations(), isTypeAlias) return declaration != nil && ast.GetContainingFunction(declaration) != nil } @@ -24193,17 +24193,17 @@ func (c *Checker) getDeclaredTypeOfSymbol(symbol *ast.Symbol) *Type { func (c *Checker) tryGetDeclaredTypeOfSymbol(symbol *ast.Symbol) *Type { switch { - case symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0: + case symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0: return c.getDeclaredTypeOfClassOrInterface(symbol) - case symbol.Flags&ast.SymbolFlagsTypeParameter != 0: + case symbol.Flags()&ast.SymbolFlagsTypeParameter != 0: return c.getDeclaredTypeOfTypeParameter(symbol) - case symbol.Flags&ast.SymbolFlagsTypeAlias != 0: + case symbol.Flags()&ast.SymbolFlagsTypeAlias != 0: return c.getDeclaredTypeOfTypeAlias(symbol) - case symbol.Flags&ast.SymbolFlagsEnum != 0: + case symbol.Flags()&ast.SymbolFlagsEnum != 0: return c.getDeclaredTypeOfEnum(symbol) - case symbol.Flags&ast.SymbolFlagsEnumMember != 0: + case symbol.Flags()&ast.SymbolFlagsEnumMember != 0: return c.getDeclaredTypeOfEnumMember(symbol) - case symbol.Flags&ast.SymbolFlagsAlias != 0: + case symbol.Flags()&ast.SymbolFlagsAlias != 0: return c.getDeclaredTypeOfAlias(symbol) } return nil @@ -24258,10 +24258,10 @@ func (c *Checker) getOuterTypeParametersOfClassOrInterface(symbol *ast.Symbol) [ // Returns the declaration used to obtain a class, interface, or function symbol's outer type parameters. func (c *Checker) getClassOrInterfaceLikeDeclaration(symbol *ast.Symbol) *ast.Node { - if symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsFunction) != 0 { - return symbol.ValueDeclaration + if symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsFunction) != 0 { + return symbol.ValueDeclaration() } - return core.Find(symbol.Declarations, func(d *ast.Node) bool { + return core.Find(symbol.Declarations(), func(d *ast.Node) bool { if ast.IsInterfaceDeclaration(d) { return true } @@ -24319,7 +24319,7 @@ func (c *Checker) getOuterTypeParameters(node *ast.Node, includeThisTypes bool) func (c *Checker) getInferTypeParameters(node *ast.Node) []*Type { var result []*Type for _, symbol := range node.Locals() { - if symbol.Flags&ast.SymbolFlagsTypeParameter != 0 { + if symbol.Flags()&ast.SymbolFlagsTypeParameter != 0 { result = append(result, c.getDeclaredTypeOfSymbol(symbol)) } } @@ -24334,7 +24334,7 @@ func (c *Checker) getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol *as } func (c *Checker) appendLocalTypeParametersOfClassOrInterfaceOrTypeAlias(types []*Type, symbol *ast.Symbol) []*Type { - for _, node := range symbol.Declarations { + for _, node := range symbol.Declarations() { if ast.NodeKindIs(node, ast.KindInterfaceDeclaration, ast.KindClassDeclaration, ast.KindClassExpression) || isTypeAlias(node) { types = c.appendTypeParameters(types, node.TypeParameters()) } @@ -24368,7 +24368,7 @@ func (c *Checker) getDeclaredTypeOfTypeAlias(symbol *ast.Symbol) *Type { if !c.pushTypeResolution(symbol, TypeSystemPropertyNameDeclaredType) { return c.errorType } - declaration := core.Find(symbol.Declarations, ast.IsTypeOrJSTypeAliasDeclaration) + declaration := core.Find(symbol.Declarations(), ast.IsTypeOrJSTypeAliasDeclaration) typeNode := declaration.Type() t := c.getTypeFromTypeNode(typeNode) if c.popTypeResolution() { @@ -24380,7 +24380,7 @@ func (c *Checker) getDeclaredTypeOfTypeAlias(symbol *ast.Symbol) *Type { links.instantiations = make(map[CacheHashKey]*Type) links.instantiations[getTypeListKey(typeParameters)] = t } - if t == c.intrinsicMarkerType && symbol.Name == "BuiltinIteratorReturn" { + if t == c.intrinsicMarkerType && symbol.Name() == "BuiltinIteratorReturn" { t = c.getBuiltinIteratorReturnType() } } else { @@ -24402,7 +24402,7 @@ func (c *Checker) getDeclaredTypeOfEnum(symbol *ast.Symbol) *Type { links := c.declaredTypeLinks.Get(symbol) if !(links.declaredType != nil) { var memberTypeList []*Type - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if declaration.Kind == ast.KindEnumDeclaration { for _, member := range declaration.Members() { if !ast.HasDynamicName(member) { @@ -24562,14 +24562,14 @@ func (c *Checker) evaluateEntity(expr *ast.Node, location *ast.Node) evaluator.R return evaluator.NewResult(jsnum.FromString(expr.Text()), false, false, false) } } - if symbol.Flags&ast.SymbolFlagsEnumMember != 0 { + if symbol.Flags()&ast.SymbolFlagsEnumMember != 0 { if location != nil { return c.evaluateEnumMember(expr, symbol, location) } - return c.getEnumMemberValue(symbol.ValueDeclaration) + return c.getEnumMemberValue(symbol.ValueDeclaration()) } if c.isConstantVariable(symbol) { - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() if declaration != nil && ast.IsVariableDeclaration(declaration) && declaration.Type() == nil && declaration.Initializer() != nil && (location == nil || declaration != location && c.isBlockScopedNameDeclaredBeforeUse(declaration, location)) { result := c.evaluate(declaration.Initializer(), declaration) @@ -24584,14 +24584,14 @@ func (c *Checker) evaluateEntity(expr *ast.Node, location *ast.Node) evaluator.R root := expr.Expression() if ast.IsEntityNameExpression(root) && ast.IsStringLiteralLike(expr.AsElementAccessExpression().ArgumentExpression) { rootSymbol := c.resolveEntityName(root, ast.SymbolFlagsValue, true /*ignoreErrors*/, false, nil) - if rootSymbol != nil && rootSymbol.Flags&ast.SymbolFlagsEnum != 0 { + if rootSymbol != nil && rootSymbol.Flags()&ast.SymbolFlagsEnum != 0 { name := expr.AsElementAccessExpression().ArgumentExpression.Text() - member := rootSymbol.Exports[name] + member := rootSymbol.Exports()[name] if member != nil { if location != nil { return c.evaluateEnumMember(expr, member, location) } - return c.getEnumMemberValue(member.ValueDeclaration) + return c.getEnumMemberValue(member.ValueDeclaration()) } } } @@ -24601,7 +24601,7 @@ func (c *Checker) evaluateEntity(expr *ast.Node, location *ast.Node) evaluator.R } func (c *Checker) evaluateEnumMember(expr *ast.Node, symbol *ast.Symbol, location *ast.Node) evaluator.Result { - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() if declaration == nil || declaration == location { c.error(expr, diagnostics.Property_0_is_used_before_being_assigned, c.symbolToString(symbol)) return evaluator.NewResult(nil, false, false, false) @@ -25139,10 +25139,10 @@ func (c *Checker) getTypeFromImportTypeNode(node *ast.Node) *Type { // a CommonJS module might have typedefs exported alongside an export= // !!! immediateModuleSymbol := c.resolveExternalModuleSymbol(innerModuleSymbol, true /*dontResolveAlias*/) - if immediateModuleSymbol != nil && core.Some(immediateModuleSymbol.Declarations, func(d *ast.Node) bool { + if immediateModuleSymbol != nil && core.Some(immediateModuleSymbol.Declarations(), func(d *ast.Node) bool { return ast.GetAssignmentDeclarationKind(d) == ast.JSDeclarationKindModuleExports }) { - symbolFromModule = c.getSymbol(c.getExportsOfSymbol(immediateModuleSymbol.Parent), current.Text(), meaning) + symbolFromModule = c.getSymbol(c.getExportsOfSymbol(immediateModuleSymbol.Parent()), current.Text(), meaning) } } } @@ -25211,10 +25211,10 @@ func (c *Checker) getGlobalImportMetaExpressionType() *Type { symbol := c.newSymbol(ast.SymbolFlagsNone, "ImportMetaExpression") importMetaType := c.getGlobalImportMetaType() metaPropertySymbol := c.newSymbolEx(ast.SymbolFlagsProperty, "meta", ast.CheckFlagsReadonly) - metaPropertySymbol.Parent = symbol + metaPropertySymbol.SetParent(symbol) c.valueSymbolLinks.Get(metaPropertySymbol).resolvedType = importMetaType members := createSymbolTable([]*ast.Symbol{metaPropertySymbol}) - symbol.Members = members + symbol.SetMembers(members) c.deferredGlobalImportMetaExpressionType = c.newAnonymousType(symbol, members, nil, nil, nil) } return c.deferredGlobalImportMetaExpressionType @@ -25317,7 +25317,7 @@ func (c *Checker) createTupleTargetType(elementInfos []TupleElementInfo, readonl property := c.newSymbolEx(ast.SymbolFlagsProperty|core.IfElse(flags&ElementFlagsOptional != 0, ast.SymbolFlagsOptional, 0), strconv.Itoa(i), core.IfElse(readonly, ast.CheckFlagsReadonly, 0)) c.valueSymbolLinks.Get(property).resolvedType = typeParameter // c.valueSymbolLinks.get(property).tupleLabelDeclaration = elementInfos[i].labeledDeclaration - members[property.Name] = property + members[property.Name()] = property } } } @@ -25332,7 +25332,7 @@ func (c *Checker) createTupleTargetType(elementInfos []TupleElementInfo, readonl } c.valueSymbolLinks.Get(lengthSymbol).resolvedType = c.getUnionType(literalTypes) } - members[lengthSymbol.Name] = lengthSymbol + members[lengthSymbol.Name()] = lengthSymbol t := c.newObjectType(ObjectFlagsTuple|ObjectFlagsReference, nil) d := t.AsTupleType() d.thisType = c.newTypeParameter(nil) @@ -25994,7 +25994,7 @@ func (c *Checker) getBaseTypeOfLiteralTypeForComparison(t *Type) *Type { } func (c *Checker) getBaseTypeOfEnumLikeType(t *Type) *Type { - if t.flags&TypeFlagsEnumLike != 0 && t.symbol.Flags&ast.SymbolFlagsEnumMember != 0 { + if t.flags&TypeFlagsEnumLike != 0 && t.symbol.Flags()&ast.SymbolFlagsEnumMember != 0 { return c.getDeclaredTypeOfSymbol(c.getParentOfSymbol(t.symbol)) } return t @@ -26525,7 +26525,7 @@ func (c *Checker) removeSubtypes(types []*Type, hasObjectTypes bool) []*Type { } count++ if keyProperty != nil && target.flags&(TypeFlagsObject|TypeFlagsIntersection|TypeFlagsInstantiableNonPrimitive) != 0 { - t := c.getTypeOfPropertyOfType(target, keyProperty.Name) + t := c.getTypeOfPropertyOfType(target, keyProperty.Name()) if t != nil && isUnitType(t) && c.getRegularTypeOfLiteralType(t) != keyPropertyType { continue } @@ -27001,7 +27001,7 @@ func (c *Checker) filterTypes(types []*Type, predicate func(*Type) bool) { func (c *Checker) IsEmptyAnonymousObjectType(t *Type) bool { return t.objectFlags&ObjectFlagsAnonymous != 0 && (t.objectFlags&ObjectFlagsMembersResolved != 0 && c.isEmptyResolvedType(t.AsStructuredType()) || - t.symbol != nil && t.symbol.Flags&ast.SymbolFlagsTypeLiteral != 0 && len(c.getMembersOfSymbol(t.symbol)) == 0) + t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsTypeLiteral != 0 && len(c.getMembersOfSymbol(t.symbol)) == 0) } func (c *Checker) isEmptyResolvedType(t *StructuredType) bool { @@ -27273,10 +27273,10 @@ func (c *Checker) getLiteralTypeFromProperty(prop *ast.Symbol, include TypeFlags if includeNonPublic || getDeclarationModifierFlagsFromSymbol(prop)&ast.ModifierFlagsNonPublicAccessibilityModifier == 0 { t := c.valueSymbolLinks.Get(c.getLateBoundSymbol(prop)).nameType if t == nil { - if prop.Name == ast.InternalSymbolNameDefault { + if prop.Name() == ast.InternalSymbolNameDefault { t = c.getStringLiteralType("default") } else { - name := ast.GetNameOfDeclaration(prop.ValueDeclaration) + name := ast.GetNameOfDeclaration(prop.ValueDeclaration()) if name != nil { t = c.getLiteralTypeFromPropertyName(name) } @@ -27545,7 +27545,7 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy } prop := c.getPropertyOfType(objectType, propName) if prop != nil { - if accessFlags&AccessFlagsReportDeprecated != 0 && accessNode != nil && len(prop.Declarations) != 0 && c.isDeprecatedSymbol(prop) && c.isUncalledFunctionReference(accessNode, prop) { + if accessFlags&AccessFlagsReportDeprecated != 0 && accessNode != nil && len(prop.Declarations()) != 0 && c.isDeprecatedSymbol(prop) && c.isUncalledFunctionReference(accessNode, prop) { var deprecatedNode *ast.Node if accessExpression != nil { deprecatedNode = accessExpression.AsElementAccessExpression().ArgumentExpression @@ -27554,7 +27554,7 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy } else { deprecatedNode = accessNode } - c.addDeprecatedSuggestion(deprecatedNode, prop.Declarations, propName) + c.addDeprecatedSuggestion(deprecatedNode, prop.Declarations(), propName) } if accessExpression != nil { c.markPropertyAsReferenced(prop, accessExpression, c.isSelfTypeAccess(accessExpression.Expression(), objectType.symbol)) @@ -27642,7 +27642,7 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy // be included in the result type if accessFlags&AccessFlagsIncludeUndefined != 0 && !(objectType.symbol != nil && - objectType.symbol.Flags&(ast.SymbolFlagsRegularEnum|ast.SymbolFlagsConstEnum) != 0 && + objectType.symbol.Flags()&(ast.SymbolFlagsRegularEnum|ast.SymbolFlagsConstEnum) != 0 && (indexType.symbol != nil && indexType.flags&TypeFlagsEnumLiteral != 0 && c.getParentOfSymbol(indexType.symbol) == objectType.symbol)) { @@ -27668,7 +27668,7 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy return c.getUnionType(append(types, c.undefinedType)) } } - if objectType.symbol == c.globalThisSymbol && hasPropName && c.globalThisSymbol.Exports[propName] != nil && c.globalThisSymbol.Exports[propName].Flags&ast.SymbolFlagsBlockScoped != 0 { + if objectType.symbol == c.globalThisSymbol && hasPropName && c.globalThisSymbol.Exports()[propName] != nil && c.globalThisSymbol.Exports()[propName].Flags()&ast.SymbolFlagsBlockScoped != 0 { c.error(accessExpression, diagnostics.Property_0_does_not_exist_on_type_1, propName, c.TypeToString(objectType)) } else if c.noImplicitAny && accessFlags&AccessFlagsSuppressNoImplicitAnyError == 0 { if hasPropName && c.typeHasStaticProperty(propName, objectType) { @@ -27741,7 +27741,7 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy func (c *Checker) typeHasStaticProperty(propName string, containingType *Type) bool { if containingType.symbol != nil { prop := c.getPropertyOfType(c.getTypeOfSymbol(containingType.symbol), propName) - return prop != nil && prop.ValueDeclaration != nil && ast.IsStatic(prop.ValueDeclaration) + return prop != nil && prop.ValueDeclaration() != nil && ast.IsStatic(prop.ValueDeclaration()) } return false } @@ -27749,7 +27749,7 @@ func (c *Checker) typeHasStaticProperty(propName string, containingType *Type) b func (c *Checker) getSuggestionForNonexistentProperty(name string, containingType *Type) string { symbol := c.getSpellingSuggestionForName(name, slices.Values(c.getPropertiesOfType(containingType)), ast.SymbolFlagsValue) if symbol != nil { - return symbol.Name + return symbol.Name() } return "" } @@ -27812,25 +27812,25 @@ func (c *Checker) isAssignmentToReadonlyEntity(expr *ast.Node, symbol *ast.Symbo if ast.IsIdentifier(node) { expressionSymbol := c.getResolvedSymbol(node) // CommonJS module.exports is never readonly - if expressionSymbol.Flags&ast.SymbolFlagsModuleExports != 0 { + if expressionSymbol.Flags()&ast.SymbolFlagsModuleExports != 0 { return false } } } if c.isReadonlySymbol(symbol) { // Allow assignments to readonly properties within constructors of the same class declaration. - if symbol.Flags&ast.SymbolFlagsProperty != 0 && ast.IsAccessExpression(expr) && expr.Expression().Kind == ast.KindThisKeyword { + if symbol.Flags()&ast.SymbolFlagsProperty != 0 && ast.IsAccessExpression(expr) && expr.Expression().Kind == ast.KindThisKeyword { // Look for if this is the constructor for the class that `symbol` is a property of. ctor := c.getControlFlowContainer(expr) if ctor == nil || !ast.IsConstructorDeclaration(ctor) { return true } - if symbol.ValueDeclaration != nil { - isAssignmentDeclaration := ast.IsBinaryExpression(symbol.ValueDeclaration) - isLocalPropertyDeclaration := ctor.Parent == symbol.ValueDeclaration.Parent - isLocalParameterProperty := ctor == symbol.ValueDeclaration.Parent - isLocalThisPropertyAssignment := isAssignmentDeclaration && symbol.Parent.ValueDeclaration == ctor.Parent - isLocalThisPropertyAssignmentConstructorFunction := isAssignmentDeclaration && symbol.Parent.ValueDeclaration == ctor + if symbol.ValueDeclaration() != nil { + isAssignmentDeclaration := ast.IsBinaryExpression(symbol.ValueDeclaration()) + isLocalPropertyDeclaration := ctor.Parent == symbol.ValueDeclaration().Parent + isLocalParameterProperty := ctor == symbol.ValueDeclaration().Parent + isLocalThisPropertyAssignment := isAssignmentDeclaration && symbol.Parent().ValueDeclaration() == ctor.Parent + isLocalThisPropertyAssignmentConstructorFunction := isAssignmentDeclaration && symbol.Parent().ValueDeclaration() == ctor isWriteableSymbol := isLocalPropertyDeclaration || isLocalParameterProperty || isLocalThisPropertyAssignment || isLocalThisPropertyAssignmentConstructorFunction return !isWriteableSymbol } @@ -27842,7 +27842,7 @@ func (c *Checker) isAssignmentToReadonlyEntity(expr *ast.Node, symbol *ast.Symbo node := ast.SkipParentheses(expr.Expression()) if ast.IsIdentifier(node) { expressionSymbol := c.getResolvedSymbol(node) - if expressionSymbol.Flags&ast.SymbolFlagsAlias != 0 { + if expressionSymbol.Flags()&ast.SymbolFlagsAlias != 0 { declaration := c.getDeclarationOfAliasSymbol(expressionSymbol) return declaration != nil && ast.IsNamespaceImport(declaration) } @@ -27864,12 +27864,12 @@ func (c *Checker) isThisPropertyAccessInConstructor(node *ast.Node, prop *ast.Sy func (c *Checker) isAutoTypedProperty(symbol *ast.Symbol) bool { // A property is auto-typed when its declaration has no type annotation or initializer and we're in // noImplicitAny mode or a .js file. - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() return declaration != nil && ast.IsPropertyDeclaration(declaration) && declaration.Type() == nil && declaration.Initializer() == nil && c.noImplicitAny } func (c *Checker) getDeclaringConstructor(symbol *ast.Symbol) *ast.Node { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { container := ast.GetThisContainer(declaration, false /*includeArrowFunctions*/, false /*includeClassComputedPropertyName*/) if container != nil && ast.IsConstructorDeclaration(container) { return container @@ -28192,7 +28192,7 @@ func isConstEnumObjectType(t *Type) bool { } func isConstEnumSymbol(symbol *ast.Symbol) bool { - return symbol.Flags&ast.SymbolFlagsConstEnum != 0 + return symbol.Flags()&ast.SymbolFlagsConstEnum != 0 } func (c *Checker) compareProperties(sourceProp *ast.Symbol, targetProp *ast.Symbol, compareTypes func(source *Type, target *Type) Ternary) Ternary { @@ -28212,7 +28212,7 @@ func (c *Checker) compareProperties(sourceProp *ast.Symbol, targetProp *ast.Symb return TernaryFalse } } else { - if (sourceProp.Flags & ast.SymbolFlagsOptional) != (targetProp.Flags & ast.SymbolFlagsOptional) { + if (sourceProp.Flags() & ast.SymbolFlagsOptional) != (targetProp.Flags() & ast.SymbolFlagsOptional) { return TernaryFalse } } @@ -28230,15 +28230,15 @@ func compareTypesEqual(s *Type, t *Type) Ternary { } func (c *Checker) markPropertyAsReferenced(prop *ast.Symbol, nodeForCheckWriteOnly *ast.Node, isSelfTypeAccess bool) { - if prop.Flags&ast.SymbolFlagsClassMember == 0 || prop.ValueDeclaration == nil { + if prop.Flags()&ast.SymbolFlagsClassMember == 0 || prop.ValueDeclaration() == nil { return } - hasPrivateModifier := ast.HasModifier(prop.ValueDeclaration, ast.ModifierFlagsPrivate) - hasPrivateIdentifier := prop.ValueDeclaration.Name() != nil && ast.IsPrivateIdentifier(prop.ValueDeclaration.Name()) + hasPrivateModifier := ast.HasModifier(prop.ValueDeclaration(), ast.ModifierFlagsPrivate) + hasPrivateIdentifier := prop.ValueDeclaration().Name() != nil && ast.IsPrivateIdentifier(prop.ValueDeclaration().Name()) if !hasPrivateModifier && !hasPrivateIdentifier { return } - if nodeForCheckWriteOnly != nil && ast.IsWriteOnlyAccess(nodeForCheckWriteOnly) && prop.Flags&ast.SymbolFlagsSetAccessor == 0 { + if nodeForCheckWriteOnly != nil && ast.IsWriteOnlyAccess(nodeForCheckWriteOnly) && prop.Flags()&ast.SymbolFlagsSetAccessor == 0 { return } if isSelfTypeAccess { @@ -28249,7 +28249,7 @@ func (c *Checker) markPropertyAsReferenced(prop *ast.Symbol, nodeForCheckWriteOn } } target := prop - if prop.CheckFlags&ast.CheckFlagsInstantiated != 0 { + if prop.CheckFlags()&ast.CheckFlagsInstantiated != 0 { target = c.valueSymbolLinks.Get(prop).target } c.symbolReferenceLinks.Get(target).referenceKinds |= ast.SymbolFlagsAll @@ -28707,7 +28707,7 @@ func (c *Checker) transformTypeOfMembers(t *Type, f func(propertyType *Type) *Ty if updated != original { property = c.createSymbolWithType(property, updated) } - members[property.Name] = property + members[property.Name()] = property } return members } @@ -28998,7 +28998,7 @@ func (c *Checker) markPropertyAliasReferenced(location *ast.Node /*PropertyAcces prop = c.getPropertyOfType(apparentType, right.Text()) } } - if !(prop != nil && (isConstEnumOrConstEnumOnlyModule(prop) || prop.Flags&ast.SymbolFlagsEnumMember != 0 && location.Parent.Kind == ast.KindEnumMember)) { + if !(prop != nil && (isConstEnumOrConstEnumOnlyModule(prop) || prop.Flags()&ast.SymbolFlagsEnumMember != 0 && location.Parent.Kind == ast.KindEnumMember)) { c.markAliasReferenced(parentSymbol, location) } } @@ -29053,7 +29053,7 @@ func (c *Checker) markJsxAliasReferenced(node *ast.Node /*JsxOpeningLikeElement // if jsx emit was not jsxFactory as there wont be error being emitted c.symbolReferenced(jsxFactorySym, ast.SymbolFlagsAll) // If react/jsxFactory symbol is alias, mark it as referenced - if c.canCollectSymbolAliasAccessibilityData && jsxFactorySym.Flags&ast.SymbolFlagsAlias != 0 && c.getTypeOnlyAliasDeclaration(jsxFactorySym) == nil { + if c.canCollectSymbolAliasAccessibilityData && jsxFactorySym.Flags()&ast.SymbolFlagsAlias != 0 && c.getTypeOnlyAliasDeclaration(jsxFactorySym) == nil { c.markAliasSymbolAsReferenced(jsxFactorySym) } } @@ -29085,11 +29085,11 @@ func (c *Checker) markExportSpecifierAliasReferenced(location *ast.ExportSpecifi return // Skip for invalid syntax like this: export { "x" } } symbol := c.resolveName(exportedName, exportedName.Text(), ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace|ast.SymbolFlagsAlias, nil /*nameNotFoundMessage*/, true /*isUse*/, false /*excludeGlobals*/) - if symbol != nil && (symbol == c.undefinedSymbol || symbol == c.globalThisSymbol || symbol.Declarations != nil && ast.IsGlobalSourceFile(ast.GetDeclarationContainer(symbol.Declarations[0]))) { + if symbol != nil && (symbol == c.undefinedSymbol || symbol == c.globalThisSymbol || symbol.Declarations() != nil && ast.IsGlobalSourceFile(ast.GetDeclarationContainer(symbol.Declarations()[0]))) { // Do nothing, non-local symbol } else { target := symbol - if target != nil && target.Flags&ast.SymbolFlagsAlias != 0 { + if target != nil && target.Flags()&ast.SymbolFlagsAlias != 0 { target = c.resolveAlias(target) } if target == nil || c.getSymbolFlags(target)&ast.SymbolFlagsValue != 0 { @@ -29390,7 +29390,7 @@ func (c *Checker) markEntityNameOrEntityExpressionAsReference(typeName *ast.Node meaning := core.IfElse(typeName.Kind == ast.KindIdentifier, ast.SymbolFlagsType, ast.SymbolFlagsNamespace) | ast.SymbolFlagsAlias rootSymbol := c.resolveName(rootName, rootName.Text(), meaning, nil /*nameNotFoundMessage*/, true /*isUse*/, false /*excludeGlobals*/) - if rootSymbol != nil && rootSymbol.Flags&ast.SymbolFlagsAlias != 0 { + if rootSymbol != nil && rootSymbol.Flags()&ast.SymbolFlagsAlias != 0 { if c.canCollectSymbolAliasAccessibilityData && c.symbolIsValue(rootSymbol) && !isConstEnumOrConstEnumOnlyModule(c.resolveAlias(rootSymbol)) && @@ -29400,10 +29400,10 @@ func (c *Checker) markEntityNameOrEntityExpressionAsReference(typeName *ast.Node c.compilerOptions.GetIsolatedModules() && c.compilerOptions.GetEmitModuleKind() >= core.ModuleKindES2015 && !c.symbolIsValue(rootSymbol) && - !core.Some(rootSymbol.Declarations, ast.IsTypeOnlyImportOrExportDeclaration) { + !core.Some(rootSymbol.Declarations(), ast.IsTypeOnlyImportOrExportDeclaration) { diag := c.error(typeName, diagnostics.A_type_referenced_in_a_decorated_signature_must_be_imported_with_import_type_or_a_namespace_import_when_isolatedModules_and_emitDecoratorMetadata_are_enabled) var aliasDeclaration *ast.Node - for _, decl := range rootSymbol.Declarations { + for _, decl := range rootSymbol.Declarations() { if ast.IsAliasSymbolDeclaration(decl) { aliasDeclaration = decl break @@ -29658,7 +29658,7 @@ func (c *Checker) getDefinitelyFalsyPartOfType(t *Type) *Type { func (c *Checker) getConstraintDeclaration(t *Type) *ast.Node { if t.symbol != nil { - for _, d := range t.symbol.Declarations { + for _, d := range t.symbol.Declarations() { if ast.IsTypeParameterDeclaration(d) { if constraint := d.AsTypeParameterDeclaration().Constraint; constraint != nil { return constraint @@ -29786,7 +29786,7 @@ func (c *Checker) getStringMappingType(symbol *ast.Symbol, t *Type) *Type { } func applyStringMapping(symbol *ast.Symbol, str string) string { - switch intrinsicTypeKinds[symbol.Name] { + switch intrinsicTypeKinds[symbol.Name()] { case IntrinsicTypeKindUppercase: return stringutil.ToUpperJS(str) case IntrinsicTypeKindLowercase: @@ -29802,7 +29802,7 @@ func applyStringMapping(symbol *ast.Symbol, str string) string { } func (c *Checker) applyTemplateStringMapping(symbol *ast.Symbol, texts []string, types []*Type) ([]string, []*Type) { - switch intrinsicTypeKinds[symbol.Name] { + switch intrinsicTypeKinds[symbol.Name()] { case IntrinsicTypeKindUppercase, IntrinsicTypeKindLowercase: return core.Map(texts, func(t string) string { return applyStringMapping(symbol, t) }), core.Map(types, func(t *Type) *Type { return c.getStringMappingType(symbol, t) }) @@ -29853,7 +29853,7 @@ func (c *Checker) substituteIndexedMappedType(objectType *Type, index *Type) *Ty func (c *Checker) couldAccessOptionalProperty(objectType *Type, indexType *Type) bool { indexConstraint := c.getBaseConstraintOfType(indexType) return indexConstraint != nil && core.Some(c.getPropertiesOfType(objectType), func(p *ast.Symbol) bool { - return p.Flags&ast.SymbolFlagsOptional != 0 && c.isTypeAssignableTo(c.getLiteralTypeFromProperty(p, TypeFlagsStringOrNumberLiteralOrUnique, false), indexConstraint) + return p.Flags()&ast.SymbolFlagsOptional != 0 && c.isTypeAssignableTo(c.getLiteralTypeFromProperty(p, TypeFlagsStringOrNumberLiteralOrUnique, false), indexConstraint) }) } @@ -30159,7 +30159,7 @@ func (c *Checker) getContextualTypeForStaticPropertyDeclaration(declaration *ast if ast.IsExpression(declaration.Parent) { // Don't contextually type a static property by its own class, its type might still be in-progress and that would cause spurious circularities if parentType := c.getContextualType(declaration.Parent, contextFlags); parentType != nil && parentType.symbol != c.getSymbolOfDeclaration(declaration.Parent) { - return c.getTypeOfPropertyOfContextualType(parentType, c.getSymbolOfDeclaration(declaration).Name) + return c.getTypeOfPropertyOfContextualType(parentType, c.getSymbolOfDeclaration(declaration).Name()) } } return nil @@ -30364,7 +30364,7 @@ func (c *Checker) getContextualTypeForBinaryOperand(node *ast.Node, contextFlags // unless it's an assignment declaration. if node == binary.Right { target := ast.GetLeftmostExpression(binary.Left, false) - if !(ast.IsIdentifier(target) && c.getResolvedSymbol(target).Flags&ast.SymbolFlagsModuleExports != 0) { + if !(ast.IsIdentifier(target) && c.getResolvedSymbol(target).Flags()&ast.SymbolFlagsModuleExports != 0) { return c.getContextualTypeForAssignmentExpression(binary) } } @@ -30394,7 +30394,7 @@ func (c *Checker) getContextualTypeForAssignmentExpression(binary *ast.BinaryExp switch expr.Kind { case ast.KindIdentifier: symbol := c.getExportSymbolOfValueSymbolIfExported(c.getResolvedSymbol(expr)) - if symbol.Flags&ast.SymbolFlagsModuleExports != 0 { + if symbol.Flags()&ast.SymbolFlagsModuleExports != 0 { // No contextual type for an expression of the form 'module.exports = expr'. return nil } @@ -30403,8 +30403,8 @@ func (c *Checker) getContextualTypeForAssignmentExpression(binary *ast.BinaryExp // 'F.id = expr' or 'F[xxx] = expr'. If 'F' is declared as a variable with a type annotation, we can obtain a // contextual type from the annotated type without triggering a circularity. Otherwise, the assignment // declaration has no contextual type. - if symbol.ValueDeclaration != nil && ast.IsVariableDeclaration(symbol.ValueDeclaration) { - if typeNode := symbol.ValueDeclaration.Type(); typeNode != nil { + if symbol.ValueDeclaration() != nil && ast.IsVariableDeclaration(symbol.ValueDeclaration()) { + if typeNode := symbol.ValueDeclaration().Type(); typeNode != nil { if ast.IsPropertyAccessExpression(left) { return c.getTypeOfPropertyOfContextualType(c.getTypeFromTypeNode(typeNode), left.Name().Text()) } @@ -30440,12 +30440,12 @@ func (c *Checker) getContextualTypeForAssignmentExpression(binary *ast.BinaryExp } } if symbol != nil { - if d := symbol.ValueDeclaration; d != nil && (ast.IsPropertyDeclaration(d) || ast.IsPropertySignatureDeclaration(d)) && d.Type() == nil && d.Initializer() == nil { + if d := symbol.ValueDeclaration(); d != nil && (ast.IsPropertyDeclaration(d) || ast.IsPropertySignatureDeclaration(d)) && d.Type() == nil && d.Initializer() == nil { // No contextual type for 'this.xxx = expr', where xxx is declared as a property with no type annotation or initializer. return nil } } - if binary.Symbol != nil && binary.Symbol.ValueDeclaration != nil && binary.Symbol.ValueDeclaration.Type() == nil { + if binary.Symbol != nil && binary.Symbol.ValueDeclaration() != nil && binary.Symbol.ValueDeclaration().Type() == nil { // We have an assignment declaration 'this.xxx = expr' with no (synthetic) type annotation if !ast.IsObjectLiteralMethod(c.getThisContainer(expr, false, false)) { return nil @@ -30476,7 +30476,7 @@ func (c *Checker) getContextualTypeForObjectLiteralElement(element *ast.Node, co // in the type. It will just be "__computed", which does not appear in any // SymbolTable. symbol := c.getSymbolOfDeclaration(element) - return c.getTypeOfPropertyOfContextualTypeEx(t, symbol.Name, c.valueSymbolLinks.Get(symbol).nameType) + return c.getTypeOfPropertyOfContextualTypeEx(t, symbol.Name(), c.valueSymbolLinks.Get(symbol).nameType) } if ast.HasDynamicName(element) { name := ast.GetNameOfDeclaration(element) @@ -31187,7 +31187,7 @@ func (c *Checker) getTypeOfConcretePropertyOfContextualType(t *Type, name string if prop == nil || c.isCircularMappedProperty(prop) { return nil } - return c.removeMissingType(c.getTypeOfSymbol(prop), prop.Flags&ast.SymbolFlagsOptional != 0) + return c.removeMissingType(c.getTypeOfSymbol(prop), prop.Flags()&ast.SymbolFlagsOptional != 0) } func (c *Checker) getTypeFromIndexInfosOfContextualType(t *Type, name string, nameType *Type) *Type { @@ -31208,7 +31208,7 @@ func (c *Checker) getTypeFromIndexInfosOfContextualType(t *Type, name string, na } func (c *Checker) isCircularMappedProperty(symbol *ast.Symbol) bool { - if symbol.CheckFlags&ast.CheckFlagsMapped != 0 { + if symbol.CheckFlags()&ast.CheckFlagsMapped != 0 { links := c.valueSymbolLinks.Get(symbol) return links.resolvedType == nil && c.findResolutionCycleStartIndex(symbol, TypeSystemPropertyNameType) >= 0 } @@ -31269,9 +31269,9 @@ func (d *ObjectLiteralDiscriminator) len() int { func (d *ObjectLiteralDiscriminator) name(index int) string { if index < len(d.props) { - return d.props[index].Symbol().Name + return d.props[index].Symbol().Name() } - return d.members[index-len(d.props)].Name + return d.members[index-len(d.props)].Name() } func (d *ObjectLiteralDiscriminator) matches(index int, t *Type) bool { @@ -31312,15 +31312,15 @@ func (c *Checker) discriminateContextualTypeByObjectMembers(node *ast.Node, cont return false } if ast.IsPropertyAssignment(p) { - return c.isPossiblyDiscriminantValue(p.Initializer()) && c.isDiscriminantProperty(contextualType, symbol.Name) + return c.isPossiblyDiscriminantValue(p.Initializer()) && c.isDiscriminantProperty(contextualType, symbol.Name()) } if ast.IsShorthandPropertyAssignment(p) { - return c.isDiscriminantProperty(contextualType, symbol.Name) + return c.isDiscriminantProperty(contextualType, symbol.Name()) } return false }) discriminantMembers := core.Filter(c.getPropertiesOfType(contextualType), func(s *ast.Symbol) bool { - return s.Flags&ast.SymbolFlagsOptional != 0 && node.Symbol().Members[s.Name] == nil && c.isDiscriminantProperty(contextualType, s.Name) + return s.Flags()&ast.SymbolFlagsOptional != 0 && node.Symbol().Members()[s.Name()] == nil && c.isDiscriminantProperty(contextualType, s.Name()) }) discriminator := &ObjectLiteralDiscriminator{c: c, props: discriminantProperties, members: discriminantMembers} discriminated = c.discriminateTypeByDiscriminableItems(contextualType, discriminator) @@ -31333,7 +31333,7 @@ func (c *Checker) getMatchingUnionConstituentForObjectLiteral(unionType *Type, n keyPropertyName := c.getKeyPropertyName(unionType) if keyPropertyName != "" { propNode := core.Find(node.Properties(), func(p *ast.Node) bool { - return p.Symbol() != nil && ast.IsPropertyAssignment(p) && p.Symbol().Name == keyPropertyName && c.isPossiblyDiscriminantValue(p.Initializer()) + return p.Symbol() != nil && ast.IsPropertyAssignment(p) && p.Symbol().Name() == keyPropertyName && c.isPossiblyDiscriminantValue(p.Initializer()) }) if propNode != nil { propType := c.getContextFreeTypeOfExpression(propNode.Initializer()) @@ -32649,10 +32649,10 @@ func (c *Checker) getApplicableIndexSymbol(t *Type, keyType *Type) *ast.Symbol { } if len(declarations) != 0 { symbol := c.newSymbol(ast.SymbolFlagsProperty, ast.InternalSymbolNameIndex) - symbol.CheckFlags |= ast.CheckFlagsIndexSymbol - symbol.Declarations = declarations - symbol.ValueDeclaration = declarations[0] - symbol.Parent = t.symbol + symbol.SetCheckFlags(symbol.CheckFlags() | ast.CheckFlagsIndexSymbol) + symbol.SetDeclarations(declarations) + symbol.SetValueDeclaration(declarations[0]) + symbol.SetParent(t.symbol) links := c.valueSymbolLinks.Get(symbol) links.resolvedType = info.valueType info.indexSymbol = symbol @@ -32686,7 +32686,7 @@ func (c *Checker) containsArgumentsReference(node *ast.Node) bool { } switch node.Kind { case ast.KindIdentifier: - return node.Text() == c.argumentsSymbol.Name && c.IsArgumentsSymbol(c.getResolvedSymbol(node)) + return node.Text() == c.argumentsSymbol.Name() && c.IsArgumentsSymbol(c.getResolvedSymbol(node)) case ast.KindPropertyDeclaration, ast.KindMethodDeclaration, ast.KindGetAccessor, ast.KindSetAccessor: if ast.IsComputedPropertyName(node.Name()) { return visit(node.Name()) diff --git a/tsc/internal/checker/emitresolver.go b/tsc/internal/checker/emitresolver.go index 4953359de14da..f0058eb2b28e3 100644 --- a/tsc/internal/checker/emitresolver.go +++ b/tsc/internal/checker/emitresolver.go @@ -102,7 +102,7 @@ func (r *EmitResolver) IsLateBound(node *ast.Node) bool { if symbol == nil { return false } - return symbol.CheckFlags&ast.CheckFlagsLate != 0 + return symbol.CheckFlags()&ast.CheckFlagsLate != 0 } func (r *EmitResolver) GetEnumMemberValue(node *ast.Node) evaluator.Result { @@ -186,7 +186,7 @@ func (r *EmitResolver) markLinkedAliases(node *ast.Node) { visited[ast.GetSymbolId(exportSymbol)] = struct{}{} var nextSymbol *ast.Symbol - for _, declaration := range exportSymbol.Declarations { + for _, declaration := range exportSymbol.Declarations() { r.checker.emitResolverLinks.declarationLinks.Get(declaration).isVisible = core.TSTrue if ast.IsInternalModuleImportEqualsDeclaration(declaration) { @@ -272,8 +272,8 @@ func (r *EmitResolver) IsImportRequiredByAugmentation(decl *ast.ImportDeclaratio for s := range maps.Values(exports) { merged := r.checker.getMergedSymbol(s) if merged != s { - if len(merged.Declarations) > 0 { - for _, d := range merged.Declarations { + if len(merged.Declarations()) > 0 { + for _, d := range merged.Declarations() { declFile := ast.GetSourceFileOfNode(d) if declFile == importTarget { return true @@ -355,7 +355,7 @@ func (r *EmitResolver) IsExpandoFunctionDeclarationUnsafe(node *ast.Node) bool { // this is substantially different from strada, but so is expando property checking props := r.GetPropertiesOfContainerFunction(node) for _, p := range props { - if ast.IsExpandoPropertyDeclaration(p.ValueDeclaration) { + if ast.IsExpandoPropertyDeclaration(p.ValueDeclaration()) { return true } } @@ -381,7 +381,7 @@ func (r *EmitResolver) IsSymbolAccessible(symbol *ast.Symbol, enclosingDeclarati } func isConstEnumOrConstEnumOnlyModule(s *ast.Symbol) bool { - return isConstEnumSymbol(s) || s.Flags&ast.SymbolFlagsConstEnumOnlyModule != 0 + return isConstEnumSymbol(s) || s.Flags()&ast.SymbolFlagsConstEnumOnlyModule != 0 } func (r *EmitResolver) IsReferencedAliasDeclaration(node *ast.Node) bool { @@ -456,8 +456,8 @@ func (r *EmitResolver) isAliasResolvedToValue(symbol *ast.Symbol, excludeTypeOnl if symbol == nil { return false } - if symbol.ValueDeclaration != nil { - if container := ast.GetSourceFileOfNode(symbol.ValueDeclaration); container != nil { + if symbol.ValueDeclaration() != nil { + if container := ast.GetSourceFileOfNode(symbol.ValueDeclaration()); container != nil { fileSymbol := c.getSymbolOfDeclaration(container.AsNode()) // Ensures cjs export assignment is setup, since this symbol may point at, and merge with, the file itself. // If we don't, the merge may not have yet occurred, and the flags check below will be missing flags that @@ -862,13 +862,13 @@ func (r *EmitResolver) GetTypeReferenceSerializationKind(typeName *ast.Node, loc if ast.IsQualifiedName(typeName) { rootValueSymbol := r.checker.resolveEntityName(ast.GetFirstIdentifier(typeName), ast.SymbolFlagsValue, true, true, location) - if rootValueSymbol != nil && len(rootValueSymbol.Declarations) > 0 { - isTypeOnly = core.Every(rootValueSymbol.Declarations, ast.IsTypeOnlyImportOrExportDeclaration) + if rootValueSymbol != nil && len(rootValueSymbol.Declarations()) > 0 { + isTypeOnly = core.Every(rootValueSymbol.Declarations(), ast.IsTypeOnlyImportOrExportDeclaration) } } valueSymbol := r.checker.resolveEntityName(typeName, ast.SymbolFlagsValue, true, true, location) resolvedValueSymbol := valueSymbol - if valueSymbol != nil && valueSymbol.Flags&ast.SymbolFlagsAlias != 0 { + if valueSymbol != nil && valueSymbol.Flags()&ast.SymbolFlagsAlias != 0 { resolvedValueSymbol = r.checker.resolveAlias(valueSymbol) } @@ -877,7 +877,7 @@ func (r *EmitResolver) GetTypeReferenceSerializationKind(typeName *ast.Node, loc // Resolve the symbol as a type so that we can provide a more useful hint for the type serializer. typeSymbol := r.checker.resolveEntityName(typeName, ast.SymbolFlagsType, true, true, location) resolvedTypeSymbol := typeSymbol - if typeSymbol != nil && typeSymbol.Flags&ast.SymbolFlagsAlias != 0 { + if typeSymbol != nil && typeSymbol.Flags()&ast.SymbolFlagsAlias != 0 { resolvedTypeSymbol = r.checker.resolveAlias(typeSymbol) } // In case the value symbol can't be resolved (e.g. because of missing declarations), use type symbol for reachability check. @@ -982,23 +982,23 @@ func (r *EmitResolver) IsThisPropertyAssignmentDeclarationRedundant(node *ast.No defer r.checkerMu.Unlock() s := r.checker.getSymbolOfDeclaration(node) - if s == nil || s.Parent == nil { + if s == nil || s.Parent() == nil { return false } - parentType := r.checker.getDeclaredTypeOfSymbol(s.Parent) + parentType := r.checker.getDeclaredTypeOfSymbol(s.Parent()) if parentType == nil { return false } for _, base := range r.checker.getBaseTypes(parentType) { - baseProp := r.checker.getPropertyOfType(base, s.Name) + baseProp := r.checker.getPropertyOfType(base, s.Name()) if baseProp == nil { continue } - if baseProp.Flags&(ast.SymbolFlagsAccessor|ast.SymbolFlagsMethod|ast.SymbolFlagsFunction) != 0 { + if baseProp.Flags()&(ast.SymbolFlagsAccessor|ast.SymbolFlagsMethod|ast.SymbolFlagsFunction) != 0 { return true } if r.checker.isReadonlySymbol(baseProp) == r.checker.isReadonlySymbol(s) && - (s.Flags&ast.SymbolFlagsOptional) == (baseProp.Flags&ast.SymbolFlagsOptional) && + (s.Flags()&ast.SymbolFlagsOptional) == (baseProp.Flags()&ast.SymbolFlagsOptional) && r.checker.isTypeIdenticalTo(r.checker.getTypeOfSymbol(s), r.checker.getTypeOfSymbol(baseProp)) { return true } diff --git a/tsc/internal/checker/emitsupport.go b/tsc/internal/checker/emitsupport.go index 37e08a0052b46..3da782c9ab4c4 100644 --- a/tsc/internal/checker/emitsupport.go +++ b/tsc/internal/checker/emitsupport.go @@ -166,7 +166,7 @@ func (c *Checker) isEntityNameVisible(entityName *ast.Node, enclosingDeclaration symbol := c.resolveName(enclosingDeclaration, firstIdentifier.Text(), meaning, nil, false, false) - if symbol != nil && symbol.Flags&ast.SymbolFlagsTypeParameter != 0 && meaning&ast.SymbolFlagsType != 0 { + if symbol != nil && symbol.Flags()&ast.SymbolFlagsTypeParameter != 0 && meaning&ast.SymbolFlagsType != 0 { return printer.SymbolAccessibilityResult{Accessibility: printer.SymbolAccessibilityAccessible} } @@ -215,7 +215,7 @@ func (c *Checker) hasVisibleDeclarations(symbol *ast.Symbol, shouldComputeAliasT addVisibleAlias = noopAddVisibleAlias } - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if ast.IsIdentifier(declaration) { continue } @@ -242,7 +242,7 @@ func (c *Checker) hasVisibleDeclarations(symbol *ast.Symbol, shouldComputeAliasT continue } if ast.IsBindingElement(declaration) { - if symbol.Flags&ast.SymbolFlagsAlias != 0 && ast.IsInJSFile(declaration) && declaration.Parent != nil && declaration.Parent.Parent != nil && // exported import-like top-level JS require statement + if symbol.Flags()&ast.SymbolFlagsAlias != 0 && ast.IsInJSFile(declaration) && declaration.Parent != nil && declaration.Parent.Parent != nil && // exported import-like top-level JS require statement ast.IsVariableDeclaration(declaration.Parent.Parent) && declaration.Parent.Parent.Parent.Parent != nil && ast.IsVariableStatement(declaration.Parent.Parent.Parent.Parent) && !ast.HasSyntacticModifier(declaration.Parent.Parent.Parent.Parent, ast.ModifierFlagsExport) && @@ -251,7 +251,7 @@ func (c *Checker) hasVisibleDeclarations(symbol *ast.Symbol, shouldComputeAliasT addVisibleAlias(declaration, declaration.Parent.Parent.Parent.Parent) continue } - if symbol.Flags&ast.SymbolFlagsBlockScopedVariable != 0 { + if symbol.Flags()&ast.SymbolFlagsBlockScopedVariable != 0 { rootDeclaration := ast.WalkUpBindingElementsAndPatterns(declaration) if ast.IsParameterDeclaration(rootDeclaration) { return nil @@ -293,7 +293,7 @@ func (c *Checker) requiresAddingImplicitUndefined(declaration *ast.Node, symbol } t := c.getTypeOfSymbol(symbol) c.mappedSymbolLinks.Has(symbol) - return (symbol.Flags&ast.SymbolFlagsProperty != 0) && (symbol.Flags&ast.SymbolFlagsOptional != 0) && isOptionalDeclaration(declaration) && c.ReverseMappedSymbolLinks.Has(symbol) && c.ReverseMappedSymbolLinks.Get(symbol).mappedType != nil && containsNonMissingUndefinedType(c, t) + return (symbol.Flags()&ast.SymbolFlagsProperty != 0) && (symbol.Flags()&ast.SymbolFlagsOptional != 0) && isOptionalDeclaration(declaration) && c.ReverseMappedSymbolLinks.Has(symbol) && c.ReverseMappedSymbolLinks.Get(symbol).mappedType != nil && containsNonMissingUndefinedType(c, t) case ast.KindParameter, ast.KindJSDocParameterTag: return c.requiresAddingImplicitUndefinedWorker(declaration, enclosingDeclaration) default: diff --git a/tsc/internal/checker/flow.go b/tsc/internal/checker/flow.go index d08254cc8ef88..24d2f4f48b566 100644 --- a/tsc/internal/checker/flow.go +++ b/tsc/internal/checker/flow.go @@ -386,7 +386,7 @@ func (c *Checker) narrowType(f *FlowState, t *Type, expr *ast.Node, assumeTrue b if !c.isMatchingReference(f.reference, expr) && c.inlineLevel < 5 { symbol := c.getResolvedSymbol(expr) if c.isConstantVariable(symbol) { - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() if declaration != nil && ast.IsVariableDeclaration(declaration) && declaration.Type() == nil && declaration.Initializer() != nil && c.isConstantReference(f.reference) { c.inlineLevel++ result := c.narrowType(f, t, declaration.Initializer(), assumeTrue) @@ -988,9 +988,9 @@ func (c *Checker) narrowTypeByPrivateIdentifierInInExpression(f *FlowState, t *T if symbol == nil { return t } - classSymbol := symbol.Parent + classSymbol := symbol.Parent() var targetType *Type - if ast.HasStaticModifier(symbol.ValueDeclaration) { + if ast.HasStaticModifier(symbol.ValueDeclaration()) { targetType = c.getTypeOfSymbol(classSymbol) } else { targetType = c.getDeclaredTypeOfSymbol(classSymbol) @@ -1024,7 +1024,7 @@ func (c *Checker) narrowTypeByInKeyword(f *FlowState, t *Type, nameType *Type, a func (c *Checker) isTypePresencePossible(t *Type, propName string, assumeTrue bool) bool { prop := c.getPropertyOfType(t, propName) if prop != nil { - return prop.Flags&ast.SymbolFlagsOptional != 0 || prop.CheckFlags&ast.CheckFlagsPartial != 0 || assumeTrue + return prop.Flags()&ast.SymbolFlagsOptional != 0 || prop.CheckFlags()&ast.CheckFlagsPartial != 0 || assumeTrue } return c.getApplicableIndexInfoForName(t, propName) != nil || !assumeTrue } @@ -1462,7 +1462,7 @@ func (c *Checker) getCandidateDiscriminantPropertyAccess(f *FlowState, expr *ast // parameter declared in the same parameter list is a candidate. if ast.IsIdentifier(expr) { symbol := c.getResolvedSymbol(expr) - declaration := c.getExportSymbolOfValueSymbolIfExported(symbol).ValueDeclaration + declaration := c.getExportSymbolOfValueSymbolIfExported(symbol).ValueDeclaration() if declaration != nil && (ast.IsBindingElement(declaration) || ast.IsParameterDeclaration(declaration)) && f.reference == declaration.Parent && declaration.Initializer() == nil && !hasDotDotDotToken(declaration) { return declaration } @@ -1475,7 +1475,7 @@ func (c *Checker) getCandidateDiscriminantPropertyAccess(f *FlowState, expr *ast case ast.IsIdentifier(expr): symbol := c.getResolvedSymbol(expr) if c.isConstantVariable(symbol) { - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() initializer := getCandidateVariableDeclarationInitializer(declaration) // Given 'const x = obj.kind', allow 'x' as an alias for 'obj.kind' if initializer != nil && ast.IsAccessExpression(initializer) && c.isMatchingReference(f.reference, initializer.Expression()) { @@ -1752,10 +1752,10 @@ func (c *Checker) tryGetElementAccessExpressionName(node *ast.ElementAccessExpre func (c *Checker) tryGetNameFromEntityNameExpression(node *ast.Node) (string, bool) { symbol := c.resolveEntityName(node, ast.SymbolFlagsValue, true /*ignoreErrors*/, false, nil) - if symbol == nil || !(c.isConstantVariable(symbol) || (symbol.Flags&ast.SymbolFlagsEnumMember != 0)) { + if symbol == nil || !(c.isConstantVariable(symbol) || (symbol.Flags()&ast.SymbolFlagsEnumMember != 0)) { return "", false } - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() if declaration == nil { return "", false } @@ -1818,7 +1818,7 @@ func (c *Checker) isConstantReference(node *ast.Node) bool { case ast.KindIdentifier: if !ast.IsThisInTypeQuery(node) { symbol := c.getResolvedSymbol(node) - return c.isConstantVariable(symbol) || c.isParameterOrMutableLocalVariable(symbol) && !c.isSymbolAssigned(symbol) || symbol.ValueDeclaration != nil && ast.IsFunctionExpression(symbol.ValueDeclaration) + return c.isConstantVariable(symbol) || c.isParameterOrMutableLocalVariable(symbol) && !c.isSymbolAssigned(symbol) || symbol.ValueDeclaration() != nil && ast.IsFunctionExpression(symbol.ValueDeclaration()) } case ast.KindPropertyAccessExpression, ast.KindElementAccessExpression: // The resolvedSymbol property is initialized by checkPropertyAccess or checkElementAccess before we get here. @@ -2158,17 +2158,17 @@ func (c *Checker) getExplicitTypeOfSymbol(symbol *ast.Symbol, diagnostic *ast.Di return nil } defer c.resolvingExplicitTypeOfSymbol.Delete(symbol) - if symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsValueModule) != 0 { + if symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsValueModule) != 0 { return c.getTypeOfSymbol(symbol) } - if symbol.Flags&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty) != 0 { - if symbol.CheckFlags&ast.CheckFlagsMapped != 0 { + if symbol.Flags()&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty) != 0 { + if symbol.CheckFlags()&ast.CheckFlagsMapped != 0 { origin := c.mappedSymbolLinks.Get(symbol).syntheticOrigin if origin != nil && c.getExplicitTypeOfSymbol(origin, diagnostic) != nil { return c.getTypeOfSymbol(symbol) } } - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() if declaration != nil { if c.isDeclarationWithExplicitTypeAnnotation(declaration) { return c.getTypeOfSymbol(symbol) @@ -2465,10 +2465,10 @@ func (c *Checker) getTypePredicateArgument(predicate *TypePredicate, callExpress func (c *Checker) getFlowTypeInConstructor(symbol *ast.Symbol, constructor *ast.Node) *Type { var accessName *ast.Node - if strings.HasPrefix(symbol.Name, ast.InternalSymbolNamePrefix+"#") { - accessName = c.factory.NewPrivateIdentifier(symbol.Name[strings.Index(symbol.Name, "@")+1:]) + if strings.HasPrefix(symbol.Name(), ast.InternalSymbolNamePrefix+"#") { + accessName = c.factory.NewPrivateIdentifier(symbol.Name()[strings.Index(symbol.Name(), "@")+1:]) } else { - accessName = c.factory.NewIdentifier(symbol.Name) + accessName = c.factory.NewIdentifier(symbol.Name()) } reference := c.factory.NewPropertyAccessExpression(c.factory.NewKeywordExpression(ast.KindThisKeyword), nil, accessName, ast.NodeFlagsNone) reference.Expression().Parent = reference @@ -2476,7 +2476,7 @@ func (c *Checker) getFlowTypeInConstructor(symbol *ast.Symbol, constructor *ast. reference.FlowNodeData().FlowNode = constructor.AsConstructorDeclaration().ReturnFlowNode flowType := c.getFlowTypeOfProperty(reference, symbol) if c.noImplicitAny && (flowType == c.autoType || flowType == c.autoArrayType) { - c.error(symbol.ValueDeclaration, diagnostics.Member_0_implicitly_has_an_1_type, c.symbolToString(symbol), c.TypeToString(flowType)) + c.error(symbol.ValueDeclaration(), diagnostics.Member_0_implicitly_has_an_1_type, c.symbolToString(symbol), c.TypeToString(flowType)) } // We don't infer a type if assignments are only null or undefined. if everyType(flowType, c.IsNullableType) { @@ -2487,10 +2487,10 @@ func (c *Checker) getFlowTypeInConstructor(symbol *ast.Symbol, constructor *ast. func (c *Checker) getFlowTypeInStaticBlocks(symbol *ast.Symbol, staticBlocks []*ast.Node) *Type { var accessName *ast.Node - if strings.HasPrefix(symbol.Name, ast.InternalSymbolNamePrefix+"#") { - accessName = c.factory.NewPrivateIdentifier(symbol.Name[strings.Index(symbol.Name, "@")+1:]) + if strings.HasPrefix(symbol.Name(), ast.InternalSymbolNamePrefix+"#") { + accessName = c.factory.NewPrivateIdentifier(symbol.Name()[strings.Index(symbol.Name(), "@")+1:]) } else { - accessName = c.factory.NewIdentifier(symbol.Name) + accessName = c.factory.NewIdentifier(symbol.Name()) } for _, staticBlock := range staticBlocks { reference := c.factory.NewPropertyAccessExpression(c.factory.NewKeywordExpression(ast.KindThisKeyword), nil, accessName, ast.NodeFlagsNone) @@ -2499,7 +2499,7 @@ func (c *Checker) getFlowTypeInStaticBlocks(symbol *ast.Symbol, staticBlocks []* reference.FlowNodeData().FlowNode = staticBlock.AsClassStaticBlockDeclaration().ReturnFlowNode flowType := c.getFlowTypeOfProperty(reference, symbol) if c.noImplicitAny && (flowType == c.autoType || flowType == c.autoArrayType) { - c.error(symbol.ValueDeclaration, diagnostics.Member_0_implicitly_has_an_1_type, c.symbolToString(symbol), c.TypeToString(flowType)) + c.error(symbol.ValueDeclaration(), diagnostics.Member_0_implicitly_has_an_1_type, c.symbolToString(symbol), c.TypeToString(flowType)) } // We don't infer a type if assignments are only null or undefined. if everyType(flowType, c.IsNullableType) { @@ -2672,7 +2672,7 @@ func (c *Checker) isPastLastAssignment(symbol *ast.Symbol, location *ast.Node) b } func (c *Checker) ensureAssignmentsMarked(symbol *ast.Symbol) { - parent := ast.FindAncestor(symbol.ValueDeclaration, ast.IsFunctionOrSourceFile) + parent := ast.FindAncestor(symbol.ValueDeclaration(), ast.IsFunctionOrSourceFile) if parent == nil { return } @@ -2707,9 +2707,9 @@ func (c *Checker) markNodeAssignmentsWorker(node *ast.Node) bool { links := c.markedAssignmentSymbolLinks.Get(symbol) if pos := links.lastAssignmentPos; pos == 0 || pos != math.MaxInt32 { referencingFunction := ast.FindAncestor(node, ast.IsFunctionOrSourceFile) - declaringFunction := ast.FindAncestor(symbol.ValueDeclaration, ast.IsFunctionOrSourceFile) + declaringFunction := ast.FindAncestor(symbol.ValueDeclaration(), ast.IsFunctionOrSourceFile) if referencingFunction == declaringFunction { - links.lastAssignmentPos = int32(c.extendAssignmentPosition(node, symbol.ValueDeclaration)) + links.lastAssignmentPos = int32(c.extendAssignmentPosition(node, symbol.ValueDeclaration())) } else { links.lastAssignmentPos = math.MaxInt32 } diff --git a/tsc/internal/checker/grammarchecks.go b/tsc/internal/checker/grammarchecks.go index a1334617242b5..93bed4b355296 100644 --- a/tsc/internal/checker/grammarchecks.go +++ b/tsc/internal/checker/grammarchecks.go @@ -246,7 +246,7 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has return c.grammarErrorOnFirstToken(node, diagnostics.Decorators_are_not_valid_here) } } else if c.legacyDecorators && (node.Kind == ast.KindGetAccessor || node.Kind == ast.KindSetAccessor) { - accessors := ast.GetAllAccessorDeclarationsForDeclaration(node, c.getSymbolOfDeclaration(node).Declarations) + accessors := ast.GetAllAccessorDeclarationsForDeclaration(node, c.getSymbolOfDeclaration(node).Declarations()) if ast.HasDecorators(accessors.FirstAccessor) && node == accessors.SecondAccessor { return c.grammarErrorOnFirstToken(node, diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name) } diff --git a/tsc/internal/checker/inference.go b/tsc/internal/checker/inference.go index 43f0930bfc5a2..c71e412fef47f 100644 --- a/tsc/internal/checker/inference.go +++ b/tsc/internal/checker/inference.go @@ -282,7 +282,7 @@ func (c *Checker) inferFromAliasTypeArguments(n *InferenceState, source *Type, t // Simply infer from source type arguments to target type arguments, with defaults applied. params := c.typeAliasLinks.Get(source.alias.symbol).typeParameters minParams := c.getMinTypeArgumentCount(params) - nodeIsInJsFile := ast.IsInJSFile(source.alias.symbol.ValueDeclaration) + nodeIsInJsFile := ast.IsInJSFile(source.alias.symbol.ValueDeclaration()) sourceTypes := c.fillMissingTypeArguments(source.alias.typeArguments, params, minParams, nodeIsInJsFile) targetTypes := c.fillMissingTypeArguments(target.alias.typeArguments, params, minParams, nodeIsInJsFile) c.inferFromTypeArguments(n, sourceTypes, targetTypes, c.getAliasVariances(source.alias.symbol)) @@ -839,9 +839,9 @@ func (c *Checker) inferFromObjectTypes(n *InferenceState, source *Type, target * func (c *Checker) inferFromProperties(n *InferenceState, source *Type, target *Type) { properties := c.getPropertiesOfObjectType(target) for _, targetProp := range properties { - sourceProp := c.getPropertyOfType(source, targetProp.Name) - if sourceProp != nil && !core.Some(sourceProp.Declarations, c.isSkipDirectInferenceNode) { - c.inferFromTypes(n, c.removeMissingType(c.getTypeOfSymbol(sourceProp), sourceProp.Flags&ast.SymbolFlagsOptional != 0), c.removeMissingType(c.getTypeOfSymbol(targetProp), targetProp.Flags&ast.SymbolFlagsOptional != 0)) + sourceProp := c.getPropertyOfType(source, targetProp.Name()) + if sourceProp != nil && !core.Some(sourceProp.Declarations(), c.isSkipDirectInferenceNode) { + c.inferFromTypes(n, c.removeMissingType(c.getTypeOfSymbol(sourceProp), sourceProp.Flags()&ast.SymbolFlagsOptional != 0), c.removeMissingType(c.getTypeOfSymbol(targetProp), targetProp.Flags()&ast.SymbolFlagsOptional != 0)) } } } @@ -932,7 +932,7 @@ func (c *Checker) inferFromIndexTypes(n *InferenceState, source *Type, target *T for _, prop := range c.getPropertiesOfType(source) { if c.isApplicableIndexType(c.getLiteralTypeFromProperty(prop, TypeFlagsStringOrNumberLiteralOrUnique, false), targetInfo.keyType) { propType := c.getTypeOfSymbol(prop) - if prop.Flags&ast.SymbolFlagsOptional != 0 { + if prop.Flags()&ast.SymbolFlagsOptional != 0 { propType = c.removeMissingOrUndefinedType(propType) } propTypes = append(propTypes, propType) @@ -1130,8 +1130,8 @@ func (c *Checker) resolveReverseMappedTypeMembers(t *Type) { } } checkFlags := ast.CheckFlagsReverseMapped | core.IfElse(readonlyMask && c.isReadonlySymbol(prop), ast.CheckFlagsReadonly, 0) - inferredProp := c.newSymbolEx(ast.SymbolFlagsProperty|prop.Flags&optionalMask, prop.Name, checkFlags) - inferredProp.Declarations = prop.Declarations + inferredProp := c.newSymbolEx(ast.SymbolFlagsProperty|prop.Flags()&optionalMask, prop.Name(), checkFlags) + inferredProp.SetDeclarations(prop.Declarations()) c.valueSymbolLinks.Get(inferredProp).nameType = c.valueSymbolLinks.Get(prop).nameType links := c.ReverseMappedSymbolLinks.Get(inferredProp) links.propertyType = c.getTypeOfSymbol(prop) @@ -1148,7 +1148,7 @@ func (c *Checker) resolveReverseMappedTypeMembers(t *Type) { links.mappedType = r.mappedType links.constraintType = r.constraintType } - members[prop.Name] = inferredProp + members[prop.Name()] = inferredProp } c.setStructuredTypeMembers(t, members, nil, nil, indexInfos) } @@ -1247,8 +1247,8 @@ func (c *Checker) createEmptyObjectTypeFromStringLiteral(t *Type) *Type { literalProp := c.newSymbol(ast.SymbolFlagsProperty, name) c.valueSymbolLinks.Get(literalProp).resolvedType = c.anyType if t.symbol != nil { - literalProp.Declarations = t.symbol.Declarations - literalProp.ValueDeclaration = t.symbol.ValueDeclaration + literalProp.SetDeclarations(t.symbol.Declarations()) + literalProp.SetValueDeclaration(t.symbol.ValueDeclaration()) } members[name] = literalProp } @@ -1628,7 +1628,7 @@ func (c *Checker) literalTypesWithSameBaseType(types []*Type) bool { } func (c *Checker) isFromInferenceBlockedSource(t *Type) bool { - return t.symbol != nil && core.Some(t.symbol.Declarations, c.isSkipDirectInferenceNode) + return t.symbol != nil && core.Some(t.symbol.Declarations(), c.isSkipDirectInferenceNode) } func (c *Checker) isSkipDirectInferenceNode(node *ast.Node) bool { @@ -1670,7 +1670,7 @@ func hasInferenceCandidatesOrDefault(info *InferenceInfo) bool { func hasTypeParameterDefault(tp *Type) bool { if tp.symbol != nil { - for _, d := range tp.symbol.Declarations { + for _, d := range tp.symbol.Declarations() { if ast.IsTypeParameterDeclaration(d) && d.AsTypeParameterDeclaration().DefaultType != nil { return true } diff --git a/tsc/internal/checker/jsx.go b/tsc/internal/checker/jsx.go index e05f24634cc7f..4e7dc902d23c6 100644 --- a/tsc/internal/checker/jsx.go +++ b/tsc/internal/checker/jsx.go @@ -275,17 +275,17 @@ func (c *Checker) discriminateContextualTypeByJSXAttributes(node *ast.Node, cont return false } initializer := p.Initializer() - return (initializer == nil || c.isPossiblyDiscriminantValue(initializer)) && c.isDiscriminantProperty(contextualType, symbol.Name) + return (initializer == nil || c.isPossiblyDiscriminantValue(initializer)) && c.isDiscriminantProperty(contextualType, symbol.Name()) }) discriminantMembers := core.Filter(c.getPropertiesOfType(contextualType), func(s *ast.Symbol) bool { - if s.Flags&ast.SymbolFlagsOptional == 0 || node.Symbol() == nil { + if s.Flags()&ast.SymbolFlagsOptional == 0 || node.Symbol() == nil { return false } element := node.Parent.Parent - if s.Name == jsxChildrenPropertyName && ast.IsJsxElement(element) && len(ast.GetSemanticJsxChildren(element.Children().Nodes)) != 0 { + if s.Name() == jsxChildrenPropertyName && ast.IsJsxElement(element) && len(ast.GetSemanticJsxChildren(element.Children().Nodes)) != 0 { return false } - return node.Symbol().Members[s.Name] == nil && c.isDiscriminantProperty(contextualType, s.Name) + return node.Symbol().Members()[s.Name()] == nil && c.isDiscriminantProperty(contextualType, s.Name()) }) discriminator := &ObjectLiteralDiscriminator{c: c, props: discriminantProperties, members: discriminantMembers} discriminated := c.discriminateTypeByDiscriminableItems(contextualType, discriminator) @@ -466,8 +466,8 @@ func (c *Checker) elaborateIterableOrArrayLikeTargetElementwise(iterator iter.Se diag := createDiagnosticForNode(prop, diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_type_of_the_target, c.TypeToString(specificSource), c.TypeToString(targetPropType)) c.reportDiagnostic(diag, diagnosticOutput) } else { - targetIsOptional := propName != ast.InternalSymbolNameMissing && core.OrElse(c.getPropertyOfType(tupleOrArrayLikeTargetParts, propName), c.unknownSymbol).Flags&ast.SymbolFlagsOptional != 0 - sourceIsOptional := propName != ast.InternalSymbolNameMissing && core.OrElse(c.getPropertyOfType(source, propName), c.unknownSymbol).Flags&ast.SymbolFlagsOptional != 0 + targetIsOptional := propName != ast.InternalSymbolNameMissing && core.OrElse(c.getPropertyOfType(tupleOrArrayLikeTargetParts, propName), c.unknownSymbol).Flags()&ast.SymbolFlagsOptional != 0 + sourceIsOptional := propName != ast.InternalSymbolNameMissing && core.OrElse(c.getPropertyOfType(source, propName), c.unknownSymbol).Flags()&ast.SymbolFlagsOptional != 0 targetPropType = c.removeMissingType(targetPropType, targetIsOptional) sourcePropType = c.removeMissingType(sourcePropType, targetIsOptional && sourceIsOptional) result := c.checkTypeRelatedToEx(specificSource, targetPropType, relation, prop, nil, diagnosticOutput) @@ -523,12 +523,12 @@ func (c *Checker) getJSXFragmentType(node *ast.Node) *Type { links.jsxFragmentType = c.errorType return links.jsxFragmentType } - if jsxFactorySymbol.Name == ReactNames.Fragment { + if jsxFactorySymbol.Name() == ReactNames.Fragment { links.jsxFragmentType = c.getTypeOfSymbol(jsxFactorySymbol) return links.jsxFragmentType } resolvedAlias := jsxFactorySymbol - if jsxFactorySymbol.Flags&ast.SymbolFlagsAlias != 0 { + if jsxFactorySymbol.Flags()&ast.SymbolFlagsAlias != 0 { resolvedAlias = c.resolveAlias(jsxFactorySymbol) } @@ -670,8 +670,8 @@ func (c *Checker) checkApplicableSignatureForJsxCallLikeElement(node *ast.Node, // We will not report errors in this function for fragments, since we do not check them in this function diag := NewDiagnosticForNode(tagName, diagnostics.Tag_0_expects_at_least_1_arguments_but_the_JSX_factory_2_provides_at_most_3, entityNameToString(tagName), absoluteMinArgCount, entityNameToString(factory), maxParamCount) tagNameSymbol := c.getSymbolAtLocation(tagName, false) - if tagNameSymbol != nil && tagNameSymbol.ValueDeclaration != nil { - diag.AddRelatedInfo(NewDiagnosticForNode(tagNameSymbol.ValueDeclaration, diagnostics.X_0_is_declared_here, entityNameToString(tagName))) + if tagNameSymbol != nil && tagNameSymbol.ValueDeclaration() != nil { + diag.AddRelatedInfo(NewDiagnosticForNode(tagNameSymbol.ValueDeclaration(), diagnostics.X_0_is_declared_here, entityNameToString(tagName))) } c.reportDiagnostic(diag, diagnosticOutput) } @@ -741,18 +741,18 @@ func (c *Checker) createJsxAttributesTypeFromAttributesProperty(openingLikeEleme if ast.IsJsxAttribute(attributeDecl) { exprType := c.checkJsxAttribute(attributeDecl, checkMode) objectFlags |= exprType.objectFlags & ObjectFlagsPropagatingFlags - attributeSymbol := c.newSymbol(ast.SymbolFlagsProperty|member.Flags, member.Name) - attributeSymbol.Declarations = member.Declarations - attributeSymbol.Parent = member.Parent - if member.ValueDeclaration != nil { - attributeSymbol.ValueDeclaration = member.ValueDeclaration + attributeSymbol := c.newSymbol(ast.SymbolFlagsProperty|member.Flags(), member.Name()) + attributeSymbol.SetDeclarations(member.Declarations()) + attributeSymbol.SetParent(member.Parent()) + if member.ValueDeclaration() != nil { + attributeSymbol.SetValueDeclaration(member.ValueDeclaration()) } links := c.valueSymbolLinks.Get(attributeSymbol) links.resolvedType = exprType links.target = member - attributesTable[attributeSymbol.Name] = attributeSymbol + attributesTable[attributeSymbol.Name()] = attributeSymbol if allAttributesTable != nil { - allAttributesTable[attributeSymbol.Name] = attributeSymbol + allAttributesTable[attributeSymbol.Name()] = attributeSymbol } if attributeDecl.Name().Text() == jsxChildrenPropertyName { explicitlySpecifyChildrenAttribute = true @@ -843,9 +843,9 @@ func (c *Checker) createJsxAttributesTypeFromAttributesProperty(openingLikeEleme links.resolvedType = c.createArrayType(c.getUnionType(childTypes)) } // Fake up a property declaration for the children - childrenPropSymbol.ValueDeclaration = c.factory.NewPropertySignatureDeclaration(nil, c.factory.NewIdentifier(jsxChildrenPropertyName), nil /*postfixToken*/, nil /*type*/, nil /*initializer*/) - childrenPropSymbol.ValueDeclaration.Parent = attributeParent - childrenPropSymbol.ValueDeclaration.AsPropertySignatureDeclaration().Symbol = childrenPropSymbol + childrenPropSymbol.SetValueDeclaration(c.factory.NewPropertySignatureDeclaration(nil, c.factory.NewIdentifier(jsxChildrenPropertyName), nil /*postfixToken*/, nil /*type*/, nil /*initializer*/)) + childrenPropSymbol.ValueDeclaration().Parent = attributeParent + childrenPropSymbol.ValueDeclaration().AsPropertySignatureDeclaration().Symbol = childrenPropSymbol childPropMap := make(ast.SymbolTable) childPropMap[jsxChildrenPropertyName] = childrenPropSymbol spread = c.getSpreadType(spread, c.newAnonymousType(attributesSymbol, childPropMap, nil, nil, nil), attributesSymbol, objectFlags|c.getPropagatingFlagsOfTypes(childTypes, TypeFlagsNone), false /*readonly*/) @@ -1030,7 +1030,7 @@ func (c *Checker) getJsxManagedAttributesFromLocatedAttributes(context *ast.Node func (c *Checker) instantiateAliasOrInterfaceWithDefaults(managedSym *ast.Symbol, typeArguments []*Type, inJavaScript bool) *Type { declaredManagedType := c.getDeclaredTypeOfSymbol(managedSym) // fetches interface type, or initializes symbol links type parameters - if managedSym.Flags&ast.SymbolFlagsTypeAlias != 0 { + if managedSym.Flags()&ast.SymbolFlagsTypeAlias != 0 { params := c.typeAliasLinks.Get(managedSym).typeParameters if len(params) >= len(typeArguments) { args := c.fillMissingTypeArguments(typeArguments, params, len(typeArguments), inJavaScript) @@ -1049,7 +1049,7 @@ func (c *Checker) instantiateAliasOrInterfaceWithDefaults(managedSym *ast.Symbol func (c *Checker) getJsxLibraryManagedAttributes(jsxNamespace *ast.Symbol) *ast.Symbol { if jsxNamespace != nil { - return c.getSymbol(jsxNamespace.Exports, JsxNames.LibraryManagedAttributes, ast.SymbolFlagsType) + return c.getSymbol(jsxNamespace.Exports(), JsxNames.LibraryManagedAttributes, ast.SymbolFlagsType) } return nil } @@ -1057,7 +1057,7 @@ func (c *Checker) getJsxLibraryManagedAttributes(jsxNamespace *ast.Symbol) *ast. func (c *Checker) getJsxElementTypeSymbol(jsxNamespace *ast.Symbol) *ast.Symbol { // JSX.ElementType [symbol] if jsxNamespace != nil { - return c.getSymbol(jsxNamespace.Exports, JsxNames.ElementType, ast.SymbolFlagsType) + return c.getSymbol(jsxNamespace.Exports(), JsxNames.ElementType, ast.SymbolFlagsType) } return nil } @@ -1091,7 +1091,7 @@ func (c *Checker) getJsxElementChildrenPropertyName(jsxNamespace *ast.Symbol) st func (c *Checker) getNameFromJsxElementAttributesContainer(nameOfAttribPropContainer string, jsxNamespace *ast.Symbol) string { // JSX.ElementAttributesProperty | JSX.ElementChildrenAttribute [symbol] if jsxNamespace != nil { - jsxElementAttribPropInterfaceSym := c.getSymbol(jsxNamespace.Exports, nameOfAttribPropContainer, ast.SymbolFlagsType) + jsxElementAttribPropInterfaceSym := c.getSymbol(jsxNamespace.Exports(), nameOfAttribPropContainer, ast.SymbolFlagsType) if jsxElementAttribPropInterfaceSym != nil { jsxElementAttribPropInterfaceType := c.getDeclaredTypeOfSymbol(jsxElementAttribPropInterfaceSym) propertiesOfJsxElementAttribPropInterface := c.getPropertiesOfType(jsxElementAttribPropInterfaceType) @@ -1100,11 +1100,11 @@ func (c *Checker) getNameFromJsxElementAttributesContainer(nameOfAttribPropConta return "" } if len(propertiesOfJsxElementAttribPropInterface) == 1 { - return propertiesOfJsxElementAttribPropInterface[0].Name + return propertiesOfJsxElementAttribPropInterface[0].Name() } - if len(propertiesOfJsxElementAttribPropInterface) > 1 && len(jsxElementAttribPropInterfaceSym.Declarations) != 0 { + if len(propertiesOfJsxElementAttribPropInterface) > 1 && len(jsxElementAttribPropInterfaceSym.Declarations()) != 0 { // More than one property on ElementAttributesProperty is an error - c.error(jsxElementAttribPropInterfaceSym.Declarations[0], diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property, nameOfAttribPropContainer) + c.error(jsxElementAttribPropInterfaceSym.Declarations()[0], diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property, nameOfAttribPropContainer) } } } diff --git a/tsc/internal/checker/nodebuilder.go b/tsc/internal/checker/nodebuilder.go index e6ccb962191f7..a4fb793b334bf 100644 --- a/tsc/internal/checker/nodebuilder.go +++ b/tsc/internal/checker/nodebuilder.go @@ -186,7 +186,7 @@ func (b *NodeBuilder) ExpandSymbolForHover(symbol *ast.Symbol, meaning ast.Symbo } func simplifyClassDeclaration(f *ast.NodeFactory, classDecl *ast.Node, symbol *ast.Symbol) *ast.Node { - classDeclarations := core.Filter(symbol.Declarations, ast.IsClassLike) + classDeclarations := core.Filter(symbol.Declarations(), ast.IsClassLike) var originalClassDecl *ast.Node if len(classDeclarations) > 0 { originalClassDecl = classDeclarations[0] @@ -210,7 +210,7 @@ func simplifyClassDeclaration(f *ast.NodeFactory, classDecl *ast.Node, symbol *a } func simplifyModifiers(f *ast.NodeFactory, newDecl *ast.Node, isDeclKind func(*ast.Node) bool, symbol *ast.Symbol) *ast.Node { - decls := core.Filter(symbol.Declarations, isDeclKind) + decls := core.Filter(symbol.Declarations(), isDeclKind) var declWithModifiers *ast.Node if len(decls) > 0 { declWithModifiers = decls[0] diff --git a/tsc/internal/checker/nodebuilder_hover.go b/tsc/internal/checker/nodebuilder_hover.go index d07e229b20451..b048c5d1618c6 100644 --- a/tsc/internal/checker/nodebuilder_hover.go +++ b/tsc/internal/checker/nodebuilder_hover.go @@ -24,23 +24,23 @@ func isExpanding(ctx *NodeBuilderContext) bool { // modifier computation, alias resolution, visited symbols tracking). func (b *NodeBuilderImpl) expandSymbolForHover(symbol *ast.Symbol) []*ast.Node { var results []*ast.Node - if symbol.Flags&ast.SymbolFlagsEnum != 0 { + if symbol.Flags()&ast.SymbolFlagsEnum != 0 { if node := b.expandEnumDecl(symbol); node != nil { results = append(results, node) } } - if symbol.Flags&ast.SymbolFlagsClass != 0 { + if symbol.Flags()&ast.SymbolFlagsClass != 0 { if node := b.expandClassDecl(symbol); node != nil { results = append(results, node) } } // Module/namespace before interface (matching Strada ordering for merged declarations) - if symbol.Flags&(ast.SymbolFlagsValueModule|ast.SymbolFlagsNamespaceModule) != 0 { + if symbol.Flags()&(ast.SymbolFlagsValueModule|ast.SymbolFlagsNamespaceModule) != 0 { if node := b.expandModuleDecl(symbol); node != nil { results = append(results, node) } } - if symbol.Flags&ast.SymbolFlagsInterface != 0 && symbol.Flags&ast.SymbolFlagsClass == 0 { + if symbol.Flags()&ast.SymbolFlagsInterface != 0 && symbol.Flags()&ast.SymbolFlagsClass == 0 { if node := b.expandInterfaceDecl(symbol); node != nil { results = append(results, node) } @@ -53,7 +53,7 @@ func (b *NodeBuilderImpl) expandEnumDecl(symbol *ast.Symbol) *ast.Node { name := ast.SymbolName(symbol) b.ctx.approximateLength += 9 + len(name) memberProps := core.Filter(b.ch.getPropertiesOfType(b.ch.getTypeOfSymbol(symbol)), func(p *ast.Symbol) bool { - return p.Flags&ast.SymbolFlagsEnumMember != 0 + return p.Flags()&ast.SymbolFlagsEnumMember != 0 }) var members []*ast.Node for i, p := range memberProps { @@ -61,21 +61,21 @@ func (b *NodeBuilderImpl) expandEnumDecl(symbol *ast.Symbol) *ast.Node { b.ctx.expansionTruncated = true members = append(members, b.f.NewEnumMember(b.f.NewStringLiteral(fmt.Sprintf(" ... %d more ... ", len(memberProps)-i-1), 0), nil)) last := memberProps[len(memberProps)-1] - members = append(members, b.f.NewEnumMember(b.f.NewIdentifier(last.Name), b.enumMemberInitializer(last))) + members = append(members, b.f.NewEnumMember(b.f.NewIdentifier(last.Name()), b.enumMemberInitializer(last))) break } - memberDecl := core.Find(p.Declarations, ast.IsEnumMember) + memberDecl := core.Find(p.Declarations(), ast.IsEnumMember) var initializer *ast.Node if memberDecl != nil && memberDecl.AsEnumMember().Initializer != nil { initializer = b.f.DeepCloneNode(memberDecl.AsEnumMember().Initializer) } else { initializer = b.enumMemberInitializer(p) } - b.ctx.approximateLength += 4 + len(p.Name) + b.ctx.approximateLength += 4 + len(p.Name()) if initializer != nil { b.ctx.approximateLength += 5 // " = " + value estimate } - members = append(members, b.f.NewEnumMember(b.f.NewIdentifier(p.Name), initializer)) + members = append(members, b.f.NewEnumMember(b.f.NewIdentifier(p.Name()), initializer)) } constModifier := ast.ModifierFlagsNone @@ -90,7 +90,7 @@ func (b *NodeBuilderImpl) expandEnumDecl(symbol *ast.Symbol) *ast.Node { } func (b *NodeBuilderImpl) enumMemberInitializer(p *ast.Symbol) *ast.Node { - memberDecl := core.Find(p.Declarations, ast.IsEnumMember) + memberDecl := core.Find(p.Declarations(), ast.IsEnumMember) if memberDecl == nil { return nil } @@ -112,7 +112,7 @@ func (b *NodeBuilderImpl) expandClassDecl(symbol *ast.Symbol) *ast.Node { name := ast.SymbolName(symbol) b.ctx.approximateLength += 9 + len(name) - classLikeDeclarations := core.Filter(symbol.Declarations, ast.IsClassLike) + classLikeDeclarations := core.Filter(symbol.Declarations(), ast.IsClassLike) originalDecl := core.FirstOrNil(classLikeDeclarations) oldEnclosing := b.ctx.enclosingDeclaration if originalDecl != nil { @@ -127,7 +127,7 @@ func (b *NodeBuilderImpl) expandClassDecl(symbol *ast.Symbol) *ast.Node { classType := b.ch.getTypeWithThisArgument(declaredType, nil, false) baseTypes := b.ch.getBaseTypes(b.ch.getTargetType(classType)) staticType := b.ch.getTypeOfSymbol(symbol) - isClass := staticType.symbol != nil && staticType.symbol.ValueDeclaration != nil && ast.IsClassLike(staticType.symbol.ValueDeclaration) + isClass := staticType.symbol != nil && staticType.symbol.ValueDeclaration() != nil && ast.IsClassLike(staticType.symbol.ValueDeclaration()) var staticBaseType *Type if isClass { staticBaseType = b.ch.getBaseConstructorTypeOfClass(declaredType) @@ -152,7 +152,7 @@ func (b *NodeBuilderImpl) expandClassDecl(symbol *ast.Symbol) *ast.Node { // Static members staticProps := core.Filter(b.ch.getPropertiesOfType(staticType), func(p *ast.Symbol) bool { - return p.Flags&ast.SymbolFlagsPrototype == 0 && p.Name != "prototype" && !b.isNamespaceMember(p) + return p.Flags()&ast.SymbolFlagsPrototype == 0 && p.Name() != "prototype" && !b.isNamespaceMember(p) }) var staticMembers []*ast.Node staticMembers = b.serializePropertiesWithTruncation(staticProps, staticMembers) @@ -236,7 +236,7 @@ func (b *NodeBuilderImpl) expandInterfaceDecl(symbol *ast.Symbol) *ast.Node { b.ctx.approximateLength += 14 + len(name) interfaceType := b.ch.getDeclaredTypeOfClassOrInterface(symbol) - interfaceDeclarations := core.Filter(symbol.Declarations, ast.IsInterfaceDeclaration) + interfaceDeclarations := core.Filter(symbol.Declarations(), ast.IsInterfaceDeclaration) localParams := b.ch.getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) typeParamDecls := core.Map(localParams, func(p *Type) *ast.Node { return b.typeParameterToDeclaration(p) }) baseTypes := b.ch.getBaseTypes(interfaceType) @@ -298,7 +298,7 @@ func (b *NodeBuilderImpl) hoverHeritageClauses(declarations []*ast.Node) []*ast. // with truncation checks matching Strada's createTypeNodesFromResolvedType behavior. func (b *NodeBuilderImpl) serializePropertiesWithTruncation(properties []*ast.Symbol, elements []*ast.Node) []*ast.Node { properties = core.Filter(properties, func(p *ast.Symbol) bool { - return p.Flags&ast.SymbolFlagsPrototype == 0 + return p.Flags()&ast.SymbolFlagsPrototype == 0 }) for i, p := range properties { if b.checkTruncationLengthIfExpanding() && (i+3 < len(properties)-1) { @@ -316,8 +316,8 @@ func (b *NodeBuilderImpl) serializePropertiesWithTruncation(properties []*ast.Sy // serializeConstructors builds constructor signature(s) for a class, with base type filtering. func (b *NodeBuilderImpl) serializeConstructors(staticType *Type, staticBaseType *Type, isClass bool, symbol *ast.Symbol) []*ast.Node { isNonConstructable := !isClass && - symbol.ValueDeclaration != nil && - ast.IsInJSFile(symbol.ValueDeclaration) && + symbol.ValueDeclaration() != nil && + ast.IsInJSFile(symbol.ValueDeclaration()) && len(b.ch.getSignaturesOfType(staticType, SignatureKindConstruct)) == 0 if isNonConstructable { b.ctx.approximateLength += 21 @@ -384,15 +384,15 @@ func (b *NodeBuilderImpl) serializeIndexSignaturesOfType(input *Type, baseType * // based on its symbol flags (type alias, enum, class, interface, nested namespace, or variable). func (b *NodeBuilderImpl) serializeNamespaceMember(resolved *ast.Symbol, name string) *ast.Node { switch { - case resolved.Flags&ast.SymbolFlagsTypeAlias != 0: + case resolved.Flags()&ast.SymbolFlagsTypeAlias != 0: return b.serializeTypeAliasForNamespace(resolved, name) - case resolved.Flags&ast.SymbolFlagsEnum != 0: + case resolved.Flags()&ast.SymbolFlagsEnum != 0: return b.expandEnumDecl(resolved) - case resolved.Flags&ast.SymbolFlagsClass != 0: + case resolved.Flags()&ast.SymbolFlagsClass != 0: return b.expandClassDecl(resolved) - case resolved.Flags&ast.SymbolFlagsInterface != 0: + case resolved.Flags()&ast.SymbolFlagsInterface != 0: return b.expandInterfaceDecl(resolved) - case resolved.Flags&(ast.SymbolFlagsValueModule|ast.SymbolFlagsNamespaceModule) != 0: + case resolved.Flags()&(ast.SymbolFlagsValueModule|ast.SymbolFlagsNamespaceModule) != 0: return b.expandModuleDecl(resolved) default: t := b.ch.getWidenedType(b.ch.getTypeOfSymbol(resolved)) @@ -418,7 +418,7 @@ func (b *NodeBuilderImpl) expandModuleDecl(symbol *ast.Symbol) *ast.Node { if !b.isNamespaceMember(sym) { continue } - if !scanner.IsIdentifierText(sym.Name, core.LanguageVariantStandard) { + if !scanner.IsIdentifierText(sym.Name(), core.LanguageVariantStandard) { continue } members = append(members, sym) @@ -449,32 +449,32 @@ func (b *NodeBuilderImpl) expandModuleDecl(symbol *ast.Symbol) *ast.Node { } // Handle alias/re-export symbols - if m.Flags&ast.SymbolFlagsAlias != 0 { + if m.Flags()&ast.SymbolFlagsAlias != 0 { aliasDecl := b.ch.getDeclarationOfAliasSymbol(m) target := b.ch.getMergedSymbol(b.ch.getTargetOfAliasDeclaration(aliasDecl)) if target != nil { // If the alias target is a local symbol (not itself an export), emit its declaration first - if target.Flags&(ast.SymbolFlagsBlockScopedVariable|ast.SymbolFlagsFunctionScopedVariable|ast.SymbolFlagsProperty) != 0 { + if target.Flags()&(ast.SymbolFlagsBlockScopedVariable|ast.SymbolFlagsFunctionScopedVariable|ast.SymbolFlagsProperty) != 0 { if emittedLocals.AddIfAbsent(target) { localType := b.ch.getWidenedType(b.ch.getTypeOfSymbol(target)) - b.ctx.approximateLength += len(target.Name) + 5 + b.ctx.approximateLength += len(target.Name()) + 5 localStmt := b.f.NewVariableStatement(nil, b.f.NewVariableDeclarationList(b.f.NewNodeList([]*ast.Node{ - b.f.NewVariableDeclaration(b.f.NewIdentifier(target.Name), nil, b.serializeTypeForDeclaration(nil, localType, target, true), nil), + b.f.NewVariableDeclaration(b.f.NewIdentifier(target.Name()), nil, b.serializeTypeForDeclaration(nil, localType, target, true), nil), }), ast.NodeFlagsLet)) bodyStmts = append(bodyStmts, hoverStatement{node: localStmt, isLocal: true}) } } - targetName := target.Name - b.ctx.approximateLength += 16 + len(m.Name) + targetName := target.Name() + b.ctx.approximateLength += 16 + len(m.Name()) var propertyName *ast.Node - if m.Name != targetName { + if m.Name() != targetName { propertyName = b.f.NewIdentifier(targetName) } stmt := b.f.NewExportDeclaration( nil, false, b.f.NewNamedExports(b.f.NewNodeList([]*ast.Node{ - b.f.NewExportSpecifier(false, propertyName, b.f.NewIdentifier(m.Name)), + b.f.NewExportSpecifier(false, propertyName, b.f.NewIdentifier(m.Name())), })), nil, nil, ) @@ -486,27 +486,27 @@ func (b *NodeBuilderImpl) expandModuleDecl(symbol *ast.Symbol) *ast.Node { resolved := b.ch.resolveSymbol(m) // Handle functions as function declarations - if resolved.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { + if resolved.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { t := b.ch.getTypeOfSymbol(resolved) sigs := b.ch.getSignaturesOfType(t, SignatureKindCall) for _, sig := range sigs { b.ctx.approximateLength++ decl := b.signatureToSignatureDeclarationHelper(sig, ast.KindFunctionDeclaration, &SignatureToSignatureDeclarationOptions{ - name: b.f.NewIdentifier(m.Name), + name: b.f.NewIdentifier(m.Name()), }) bodyStmts = append(bodyStmts, hoverStatement{node: decl}) } // If the function also has namespace characteristics, emit an empty namespace. merged := b.ch.getMergedSymbol(resolved) - hasModuleExports := merged.Flags&(ast.SymbolFlagsValueModule|ast.SymbolFlagsNamespaceModule) != 0 && merged.Exports != nil && len(merged.Exports) != 0 + hasModuleExports := merged.Flags()&(ast.SymbolFlagsValueModule|ast.SymbolFlagsNamespaceModule) != 0 && merged.Exports() != nil && len(merged.Exports()) != 0 if !hasModuleExports { - bodyStmts = append(bodyStmts, hoverStatement{node: b.f.NewModuleDeclaration(nil, ast.KindNamespaceKeyword, b.f.NewIdentifier(m.Name), nil /*attributes*/, b.f.NewModuleBlock(b.f.NewNodeList(nil)))}) + bodyStmts = append(bodyStmts, hoverStatement{node: b.f.NewModuleDeclaration(nil, ast.KindNamespaceKeyword, b.f.NewIdentifier(m.Name()), nil /*attributes*/, b.f.NewModuleBlock(b.f.NewNodeList(nil)))}) } continue } // Handle remaining member kinds (type alias, enum, class, interface, namespace, variable) - if node := b.serializeNamespaceMember(resolved, m.Name); node != nil { + if node := b.serializeNamespaceMember(resolved, m.Name()); node != nil { bodyStmts = append(bodyStmts, hoverStatement{node: node}) } } @@ -545,7 +545,7 @@ func (b *NodeBuilderImpl) expandModuleDecl(symbol *ast.Symbol) *ast.Node { keyword = ast.KindModuleKeyword } var attributes *ast.TypeLiteralNodeNode - if declaration := core.Find(symbol.Declarations, func(declaration *ast.Node) bool { + if declaration := core.Find(symbol.Declarations(), func(declaration *ast.Node) bool { return ast.IsModuleDeclaration(declaration) && declaration.AsModuleDeclaration().Attributes != nil }); declaration != nil { attributes = b.f.DeepCloneNode(declaration.AsModuleDeclaration().Attributes) @@ -575,15 +575,15 @@ func (b *NodeBuilderImpl) filterInheritedProperties(t *Type, baseTypes []*Type, // Build a lookup from property name to symbol for parent-identity comparison. propsByName := make(map[string]*ast.Symbol, len(properties)) for _, p := range properties { - propsByName[p.Name] = p + propsByName[p.Name()] = p } // Collect names of properties inherited unchanged from base types. var inherited collections.Set[string] for _, base := range baseTypes { baseWithThis := b.ch.getTypeWithThisArgument(base, b.ch.getTargetType(t).AsInterfaceType().thisType, false) for _, prop := range b.ch.getPropertiesOfType(baseWithThis) { - if existing, ok := propsByName[prop.Name]; ok && prop.Parent == existing.Parent { - inherited.Add(prop.Name) + if existing, ok := propsByName[prop.Name()]; ok && prop.Parent() == existing.Parent() { + inherited.Add(prop.Name()) } } } @@ -591,15 +591,15 @@ func (b *NodeBuilderImpl) filterInheritedProperties(t *Type, baseTypes []*Type, return properties } return core.Filter(properties, func(p *ast.Symbol) bool { - return !inherited.Has(p.Name) + return !inherited.Has(p.Name()) }) } func (b *NodeBuilderImpl) isNamespaceMember(p *ast.Symbol) bool { - return p.Flags&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace|ast.SymbolFlagsAlias) != 0 || - !(p.Flags&ast.SymbolFlagsPrototype != 0 || p.Name == "prototype" || (p.ValueDeclaration != nil && ast.HasStaticModifier(p.ValueDeclaration) && ast.IsClassLike(p.ValueDeclaration.Parent))) + return p.Flags()&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace|ast.SymbolFlagsAlias) != 0 || + !(p.Flags()&ast.SymbolFlagsPrototype != 0 || p.Name() == "prototype" || (p.ValueDeclaration() != nil && ast.HasStaticModifier(p.ValueDeclaration()) && ast.IsClassLike(p.ValueDeclaration().Parent))) } func isHashPrivate(s *ast.Symbol) bool { - return s.ValueDeclaration != nil && s.ValueDeclaration.Name() != nil && ast.IsPrivateIdentifier(s.ValueDeclaration.Name()) + return s.ValueDeclaration() != nil && s.ValueDeclaration().Name() != nil && ast.IsPrivateIdentifier(s.ValueDeclaration().Name()) } diff --git a/tsc/internal/checker/nodebuilderimpl.go b/tsc/internal/checker/nodebuilderimpl.go index 4592b3c656c43..cd4643ac6f273 100644 --- a/tsc/internal/checker/nodebuilderimpl.go +++ b/tsc/internal/checker/nodebuilderimpl.go @@ -187,7 +187,7 @@ func (b *NodeBuilderImpl) isExpandableType(t *Type, isAlias bool) bool { return true } if objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && - t.symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule|ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { + t.symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule|ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { return true } return false @@ -336,7 +336,7 @@ func getAccessStack(ref *ast.Node) []*ast.Node { } func isClassInstanceSide(c *Checker, t *Type) bool { - return t.symbol != nil && t.symbol.Flags&ast.SymbolFlagsClass != 0 && (t == c.getDeclaredTypeOfClassOrInterface(t.symbol) || (t.flags&TypeFlagsObject != 0 && t.objectFlags&ObjectFlagsIsClassInstanceClone != 0)) + return t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsClass != 0 && (t == c.getDeclaredTypeOfClassOrInterface(t.symbol) || (t.flags&TypeFlagsObject != 0 && t.objectFlags&ObjectFlagsIsClassInstanceClone != 0)) } func (b *NodeBuilderImpl) createElidedInformationPlaceholder() *ast.TypeNode { @@ -451,7 +451,7 @@ func (b *NodeBuilderImpl) serializeTypeName(node *ast.Node, isTypeOf bool, typeA } resolvedSymbol := symbol - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { resolvedSymbol = b.ch.resolveAlias(symbol) } @@ -584,8 +584,8 @@ func (b *NodeBuilderImpl) getResolvedTypeWithoutAbstractConstructSignatures(t *S func (b *NodeBuilderImpl) symbolToNode(symbol *ast.Symbol, meaning ast.SymbolFlags) *ast.Node { if b.ctx.internalFlags&nodebuilder.InternalFlagsWriteComputedProps != 0 { - if symbol.ValueDeclaration != nil { - name := ast.GetNameOfDeclaration(symbol.ValueDeclaration) + if symbol.ValueDeclaration() != nil { + name := ast.GetNameOfDeclaration(symbol.ValueDeclaration()) if name != nil && ast.IsComputedPropertyName(name) { return name } @@ -594,7 +594,7 @@ func (b *NodeBuilderImpl) symbolToNode(symbol *ast.Symbol, meaning ast.SymbolFla nameType := b.ch.valueSymbolLinks.Get(symbol).nameType if nameType != nil && nameType.flags&(TypeFlagsEnumLiteral|TypeFlagsUniqueESSymbol) != 0 { oldEnclosing := b.ctx.enclosingDeclaration - b.ctx.enclosingDeclaration = nameType.symbol.ValueDeclaration + b.ctx.enclosingDeclaration = nameType.symbol.ValueDeclaration() result := b.f.NewComputedPropertyName(b.symbolToExpressionWorker(nameType.symbol, meaning)) b.ctx.enclosingDeclaration = oldEnclosing return result @@ -641,9 +641,9 @@ func (b *NodeBuilderImpl) createEntityNameFromSymbolChain(chain []*ast.Symbol, i // TODO: Audit usages of symbolToEntityNameNode - they should probably all be symbolToName func (b *NodeBuilderImpl) symbolToEntityNameNode(symbol *ast.Symbol) *ast.EntityName { - identifier := b.newIdentifier(symbol.Name, symbol) - if symbol.Parent != nil { - return b.f.NewQualifiedName(b.symbolToEntityNameNode(symbol.Parent), identifier) + identifier := b.newIdentifier(symbol.Name(), symbol) + if symbol.Parent() != nil { + return b.f.NewQualifiedName(b.symbolToEntityNameNode(symbol.Parent()), identifier) } return identifier } @@ -654,7 +654,7 @@ func (b *NodeBuilderImpl) symbolToTypeNode(symbol *ast.Symbol, mask ast.SymbolFl return nil // TODO: shouldn't be possible, `lookupSymbolChain` should always at least return the input symbol and issue an error } isTypeOf := mask == ast.SymbolFlagsValue - if core.Some(chain[0].Declarations, hasNonGlobalAugmentationExternalModuleSymbol) { + if core.Some(chain[0].Declarations(), hasNonGlobalAugmentationExternalModuleSymbol) { // module is root, must use `ImportTypeNode` var nonRootParts *ast.Node if len(chain) > 1 { @@ -701,7 +701,7 @@ func (b *NodeBuilderImpl) symbolToTypeNode(symbol *ast.Symbol, mask ast.SymbolFl // If ultimately we can only name the symbol with a reference that dives into a `node_modules` folder, we should error // since declaration files with these kinds of references are liable to fail when published :( b.ctx.encounteredError = true - b.ctx.tracker.ReportLikelyUnsafeImportRequiredError(oldSpecifierResult.specifier.AsString(), symbol.Name) + b.ctx.tracker.ReportLikelyUnsafeImportRequiredError(oldSpecifierResult.specifier.AsString(), symbol.Name()) } } @@ -773,9 +773,9 @@ func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index exports := b.ch.getExportsOfSymbol(parent) if exports != nil { // avoid exhaustive iteration in the common case - res, ok := exports[symbol.Name] - if symbol.Name != ast.InternalSymbolNameExportEquals && !isLateBoundName(symbol.Name) && ok && res != nil && b.ch.getSymbolIfSameReference(res, symbol) != nil { - symbolName = symbol.Name + res, ok := exports[symbol.Name()] + if symbol.Name() != ast.InternalSymbolNameExportEquals && !isLateBoundName(symbol.Name()) && ok && res != nil && b.ch.getSymbolIfSameReference(res, symbol) != nil { + symbolName = symbol.Name() } else { results := make(map[*ast.Symbol]string, 1) for name, ex := range exports { @@ -796,7 +796,7 @@ func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index if len(symbolName) == 0 { var name *ast.Node - for _, d := range symbol.Declarations { + for _, d := range symbol.Declarations() { name = ast.GetNameOfDeclaration(d) if name != nil { break @@ -817,8 +817,8 @@ func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index b.ctx.approximateLength += len(symbolName) + 1 if (b.ctx.flags&nodebuilder.FlagsForbidIndexedAccessSymbolReferences == 0) && parent != nil && - b.ch.getMembersOfSymbol(parent) != nil && b.ch.getMembersOfSymbol(parent)[symbol.Name] != nil && - b.ch.getSymbolIfSameReference(b.ch.getMembersOfSymbol(parent)[symbol.Name], symbol) != nil { + b.ch.getMembersOfSymbol(parent) != nil && b.ch.getMembersOfSymbol(parent)[symbol.Name()] != nil && + b.ch.getSymbolIfSameReference(b.ch.getMembersOfSymbol(parent)[symbol.Name()], symbol) != nil { // Should use an indexed access lhs := b.createAccessFromSymbolChain(chain, index-1, stopper, overrideTypeArguments) if ast.IsIndexedAccessTypeNode(lhs) { @@ -868,7 +868,7 @@ func (b *NodeBuilderImpl) createExpressionFromSymbolChain(chain []*ast.Symbol, i b.ctx.flags ^= nodebuilder.FlagsInInitialEntityName } - if startsWithSingleOrDoubleQuote(symbolName) && core.Some(symbol.Declarations, hasNonGlobalAugmentationExternalModuleSymbol) { + if startsWithSingleOrDoubleQuote(symbolName) && core.Some(symbol.Declarations(), hasNonGlobalAugmentationExternalModuleSymbol) { specifierResult := b.getSpecifierForModuleSymbol(symbol, core.ResolutionModeNone) b.ctx.approximateLength += 2 + len(specifierResult.specifier) return b.newStringLiteral(specifierResult.specifier.AsString()) @@ -891,7 +891,7 @@ func (b *NodeBuilderImpl) createExpressionFromSymbolChain(chain []*ast.Symbol, i } var expression *ast.Expression - if startsWithSingleOrDoubleQuote(symbolName) && symbol.Flags&ast.SymbolFlagsEnumMember == 0 { + if startsWithSingleOrDoubleQuote(symbolName) && symbol.Flags()&ast.SymbolFlagsEnumMember == 0 { literalText := stringutil.UnquoteString(symbolName) b.ctx.approximateLength += len(literalText) + 2 expression = b.newStringLiteralEx(literalText, symbolName[0] == '\'') @@ -976,23 +976,23 @@ func (b *NodeBuilderImpl) getNameOfSymbolAsWritten(symbol *ast.Symbol) string { if ok { symbol = result } - if symbol.Name == ast.InternalSymbolNameDefault && (b.ctx.flags&nodebuilder.FlagsUseAliasDefinedOutsideCurrentScope == 0) && + if symbol.Name() == ast.InternalSymbolNameDefault && (b.ctx.flags&nodebuilder.FlagsUseAliasDefinedOutsideCurrentScope == 0) && // If it's not the first part of an entity name, it must print as `default` ((b.ctx.flags&nodebuilder.FlagsInInitialEntityName == 0) || // if the symbol is synthesized, it will only be referenced externally it must print as `default` - len(symbol.Declarations) == 0 || + len(symbol.Declarations()) == 0 || // if not in the same binding context (source file, module declaration), it must print as `default` - (b.ctx.enclosingDeclaration != nil && ast.FindAncestor(symbol.Declarations[0], isDefaultBindingContext) != ast.FindAncestor(b.ctx.enclosingDeclaration, isDefaultBindingContext))) { + (b.ctx.enclosingDeclaration != nil && ast.FindAncestor(symbol.Declarations()[0], isDefaultBindingContext) != ast.FindAncestor(b.ctx.enclosingDeclaration, isDefaultBindingContext))) { return "default" } - if len(symbol.Declarations) > 0 { - name := core.FirstNonNil(symbol.Declarations, ast.GetNameOfDeclaration) // Try using a declaration with a name, first + if len(symbol.Declarations()) > 0 { + name := core.FirstNonNil(symbol.Declarations(), ast.GetNameOfDeclaration) // Try using a declaration with a name, first if name != nil { // !!! TODO: JS Object.defineProperty declarations // if ast.IsCallExpression(declaration) && ast.IsBindableObjectDefinePropertyCall(declaration) { // return symbol.Name // } - if ast.IsComputedPropertyName(name) && symbol.CheckFlags&ast.CheckFlagsLate == 0 { + if ast.IsComputedPropertyName(name) && symbol.CheckFlags()&ast.CheckFlagsLate == 0 { if b.ch.valueSymbolLinks.Has(symbol) && b.ch.valueSymbolLinks.Get(symbol).nameType != nil && b.ch.valueSymbolLinks.Get(symbol).nameType.flags&TypeFlagsStringOrNumberLiteral != 0 { result := b.getNameOfSymbolFromNameType(symbol) if len(result) > 0 { @@ -1002,7 +1002,7 @@ func (b *NodeBuilderImpl) getNameOfSymbolAsWritten(symbol *ast.Symbol) string { } return scanner.DeclarationNameToString(name) } - declaration := symbol.Declarations[0] // Declaration may be nameless, but we'll try anyway + declaration := symbol.Declarations()[0] // Declaration may be nameless, but we'll try anyway if declaration.Parent != nil && declaration.Parent.Kind == ast.KindVariableDeclaration { return scanner.DeclarationNameToString(declaration.Parent.AsVariableDeclaration().Name()) } @@ -1022,7 +1022,7 @@ func (b *NodeBuilderImpl) getNameOfSymbolAsWritten(symbol *ast.Symbol) string { if len(name) > 0 { return name } - return ast.EscapeInternalSymbolName(symbol.Name) + return ast.EscapeInternalSymbolName(symbol.Name()) } // The full set of type parameters for a generic class or interface type consists of its outer type parameters plus @@ -1067,7 +1067,7 @@ func (b *NodeBuilderImpl) lookupSymbolChain(symbol *ast.Symbol, meaning ast.Symb func (b *NodeBuilderImpl) lookupSymbolChainWorker(symbol *ast.Symbol, meaning ast.SymbolFlags, yieldModuleSymbol bool) []*ast.Symbol { // Try to get qualified name if the symbol is not a type parameter and there is an enclosing declaration. var chain []*ast.Symbol - isTypeParameter := symbol.Flags&ast.SymbolFlagsTypeParameter != 0 + isTypeParameter := symbol.Flags()&ast.SymbolFlagsTypeParameter != 0 if !isTypeParameter && (b.ctx.enclosingDeclaration != nil || b.ctx.flags&nodebuilder.FlagsUseFullyQualifiedType != 0) && (b.ctx.internalFlags&nodebuilder.InternalFlagsDoNotIncludeSymbolChain == 0) { res := b.getSymbolChain(symbol, meaning /*endOfChain*/, true, yieldModuleSymbol) chain = res @@ -1101,7 +1101,7 @@ func (b *NodeBuilderImpl) getSymbolChain(symbol *ast.Symbol, meaning ast.SymbolF parents := b.ch.getContainersOfSymbol(root, b.ctx.enclosingDeclaration, meaning) if len(parents) > 0 { parentSpecifiers := core.Map(parents, func(symbol *ast.Symbol) sortedSymbolNamePair { - if core.Some(symbol.Declarations, hasNonGlobalAugmentationExternalModuleSymbol) { + if core.Some(symbol.Declarations(), hasNonGlobalAugmentationExternalModuleSymbol) { return sortedSymbolNamePair{symbol, b.getSpecifierForModuleSymbol(symbol, core.ResolutionModeNone).specifier.AsString()} } return sortedSymbolNamePair{symbol, ""} @@ -1111,8 +1111,8 @@ func (b *NodeBuilderImpl) getSymbolChain(symbol *ast.Symbol, meaning ast.SymbolF parent := pair.sym parentChain := b.getSymbolChain(parent, getQualifiedLeftMeaning(meaning), false, yieldModuleSymbol) if len(parentChain) > 0 { - if parent.Exports != nil { - exported, ok := parent.Exports[ast.InternalSymbolNameExportEquals] + if parent.Exports() != nil { + exported, ok := parent.Exports()[ast.InternalSymbolNameExportEquals] if ok && b.ch.getSymbolIfSameReference(exported, symbol) != nil { // parentChain root _is_ symbol - symbol is a module export=, so it kinda looks like it's own parent // No need to lookup an alias for the symbol in itself @@ -1141,9 +1141,9 @@ func (b *NodeBuilderImpl) getSymbolChain(symbol *ast.Symbol, meaning ast.SymbolF // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. endOfChain || // If a parent symbol is an anonymous type, don't write it. - (symbol.Flags&(ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsObjectLiteral) == 0) { + (symbol.Flags()&(ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsObjectLiteral) == 0) { // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) - if !endOfChain && !yieldModuleSymbol && core.Some(symbol.Declarations, hasNonGlobalAugmentationExternalModuleSymbol) { + if !endOfChain && !yieldModuleSymbol && core.Some(symbol.Declarations(), hasNonGlobalAugmentationExternalModuleSymbol) { return nil } return []*ast.Symbol{symbol} @@ -1260,7 +1260,7 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri file := ast.GetDeclarationOfKind(symbol, ast.KindSourceFile) if file == nil { - equivalentSymbol := core.FirstNonNil(symbol.Declarations, func(d *ast.Node) *ast.Symbol { + equivalentSymbol := core.FirstNonNil(symbol.Declarations(), func(d *ast.Node) *ast.Symbol { return b.ch.getFileSymbolIfFileSymbolExportEqualsContainer(d, symbol) }) if equivalentSymbol != nil { @@ -1269,19 +1269,19 @@ func (b *NodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri } if file == nil { - if declaration := core.Find(symbol.Declarations, ast.IsModuleWithStringLiteralName); declaration != nil { + if declaration := core.Find(symbol.Declarations(), ast.IsModuleWithStringLiteralName); declaration != nil { specifier := tspath.ToModuleSpecifier(declaration.Name().Text()) if originalImportAttributesType != nil && b.moduleSpecifierResolvesToSymbol(specifier, originalImportAttributesType, symbol) { return moduleSpecifierResult{specifier: specifier, importAttributesType: originalImportAttributesType} } return moduleSpecifierResult{specifier: specifier, importAttributesType: b.ch.getTypeOfModuleImportAttributes(symbol)} } - if specifier, ok := ast.TryGetAmbientModuleNameFromSymbolName(symbol.Name); ok { + if specifier, ok := ast.TryGetAmbientModuleNameFromSymbolName(symbol.Name()); ok { return moduleSpecifierResult{specifier: tspath.ToModuleSpecifier(specifier)} } } if b.ctx.enclosingFile == nil { - if specifier, ok := ast.TryGetAmbientModuleNameFromSymbolName(symbol.Name); ok { + if specifier, ok := ast.TryGetAmbientModuleNameFromSymbolName(symbol.Name()); ok { return moduleSpecifierResult{specifier: tspath.ToModuleSpecifier(specifier)} } return moduleSpecifierResult{specifier: ast.GetSourceFileOfModule(symbol).FileName().AsModuleSpecifier()} @@ -1367,7 +1367,7 @@ func (b *NodeBuilderImpl) createImportAttributesForModuleSpecifier(result module if !isEmptyAttributesType { properties = slices.Clone(b.ch.getPropertiesOfType(result.importAttributesType)) } - slices.SortFunc(properties, func(a, b *ast.Symbol) int { return strings.Compare(a.Name, b.Name) }) + slices.SortFunc(properties, func(a, b *ast.Symbol) int { return strings.Compare(a.Name(), b.Name()) }) attributes := make([]*ast.Node, 0, len(properties)+1) resolutionMode := "" if importModeOverride != core.ResolutionModeNone { @@ -1376,7 +1376,7 @@ func (b *NodeBuilderImpl) createImportAttributesForModuleSpecifier(result module b.ctx.approximateLength += len("resolution-mode") + len(resolutionMode) + 6 // `"resolution-mode": "value"` } for _, property := range properties { - name := property.Name + name := property.Name() propertyType := b.ch.getTypeOfSymbol(property) if propertyType.flags&TypeFlagsStringLiteral == 0 { continue @@ -1468,7 +1468,7 @@ func (b *NodeBuilderImpl) setTextRange(range_ *ast.Node, location *ast.Node) *as func (b *NodeBuilderImpl) typeParameterShadowsOtherTypeParameterInScope(name string, typeParameter *Type) bool { result := b.ch.resolveName(b.ctx.enclosingDeclaration, name, ast.SymbolFlagsType, nil, false, false) - if result != nil && result.Flags&ast.SymbolFlagsTypeParameter != 0 { + if result != nil && result.Flags()&ast.SymbolFlagsTypeParameter != 0 { return result != typeParameter.symbol } return false @@ -1484,8 +1484,8 @@ func (b *NodeBuilderImpl) typeParameterToName(typeParameter *Type) *ast.Identifi if !ast.IsIdentifier(result) { return b.f.NewIdentifier("(Missing type parameter)").AsIdentifier() } - if typeParameter.symbol != nil && len(typeParameter.symbol.Declarations) > 0 { - decl := typeParameter.symbol.Declarations[0] + if typeParameter.symbol != nil && len(typeParameter.symbol.Declarations()) > 0 { + decl := typeParameter.symbol.Declarations()[0] if decl != nil && ast.IsTypeParameterDeclaration(decl) { result = b.setTextRange(result, decl.Name()) } @@ -1696,16 +1696,16 @@ func (b *NodeBuilderImpl) symbolToTypeParameterDeclarations(symbol *ast.Symbol) func (b *NodeBuilderImpl) typeParametersToTypeParameterDeclarations(symbol *ast.Symbol) []*ast.Node { targetSymbol := b.ch.getTargetSymbol(symbol) - if targetSymbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface|ast.SymbolFlagsAlias) != 0 { + if targetSymbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface|ast.SymbolFlagsAlias) != 0 { var results []*ast.Node params := b.ch.getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) for _, param := range params { results = append(results, b.typeParameterToDeclaration(param)) } return results - } else if targetSymbol.Flags&ast.SymbolFlagsFunction != 0 { + } else if targetSymbol.Flags()&ast.SymbolFlagsFunction != 0 { var results []*ast.Node - for _, param := range b.ch.getTypeParametersFromDeclaration(symbol.ValueDeclaration) { + for _, param := range b.ch.getTypeParametersFromDeclaration(symbol.ValueDeclaration()) { results = append(results, b.typeParameterToDeclaration(param)) } return results @@ -1718,7 +1718,7 @@ func getEffectiveParameterDeclaration(symbol *ast.Symbol) *ast.Node { if parameterDeclaration != nil { return parameterDeclaration } - if symbol.Flags&ast.SymbolFlagsTransient == 0 { + if symbol.Flags()&ast.SymbolFlagsTransient == 0 { return ast.GetDeclarationOfKind(symbol, ast.KindJSDocParameterTag) } return nil @@ -1737,13 +1737,13 @@ func (b *NodeBuilderImpl) symbolToParameterDeclaration(parameterSymbol *ast.Symb modifiers = b.f.NewModifierList(clones) } } - isRest := parameterDeclaration != nil && isRestParameter(parameterDeclaration) || parameterSymbol.CheckFlags&ast.CheckFlagsRestParameter != 0 + isRest := parameterDeclaration != nil && isRestParameter(parameterDeclaration) || parameterSymbol.CheckFlags()&ast.CheckFlagsRestParameter != 0 var dotDotDotToken *ast.Node if isRest { dotDotDotToken = b.f.NewToken(ast.KindDotDotDotToken) } name := b.parameterToParameterDeclarationName(parameterSymbol, parameterDeclaration) - isOptional := parameterDeclaration != nil && b.ch.isOptionalParameter(parameterDeclaration) || parameterSymbol.CheckFlags&ast.CheckFlagsOptionalParameter != 0 + isOptional := parameterDeclaration != nil && b.ch.isOptionalParameter(parameterDeclaration) || parameterSymbol.CheckFlags()&ast.CheckFlagsOptionalParameter != 0 var questionToken *ast.Node if isOptional { questionToken = b.f.NewToken(ast.KindQuestionToken) @@ -1757,13 +1757,13 @@ func (b *NodeBuilderImpl) symbolToParameterDeclaration(parameterSymbol *ast.Symb parameterTypeNode, /*initializer*/ nil, ) - b.ctx.approximateLength += len(parameterSymbol.Name) + 3 + b.ctx.approximateLength += len(parameterSymbol.Name()) + 3 return parameterNode } func (b *NodeBuilderImpl) parameterToParameterDeclarationName(parameterSymbol *ast.Symbol, parameterDeclaration *ast.Node) *ast.Node { if parameterDeclaration == nil || parameterDeclaration.Name() == nil { - return b.newIdentifier(parameterSymbol.Name, parameterSymbol) + return b.newIdentifier(parameterSymbol.Name(), parameterSymbol) } name := parameterDeclaration.Name() @@ -1883,7 +1883,7 @@ func (b *NodeBuilderImpl) signatureToSignatureDeclarationHelper(signature *Signa b.ctx.flags &^= nodebuilder.FlagsSuppressAnyReturnType // If the expanded parameter list had a variadic in a non-trailing position, don't expand it parameters := core.Map(core.IfElse(core.Some(expandedParams, func(p *ast.Symbol) bool { - return p != expandedParams[len(expandedParams)-1] && p.CheckFlags&ast.CheckFlagsRestParameter != 0 + return p != expandedParams[len(expandedParams)-1] && p.CheckFlags()&ast.CheckFlagsRestParameter != 0 }), signature.parameters, expandedParams), func(parameter *ast.Symbol) *ast.Node { return b.symbolToParameterDeclaration(parameter, kind == ast.KindConstructor) }) @@ -2253,10 +2253,10 @@ func hasTypeAnnotation(declaration *ast.Declaration) bool { func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declaration, t *Type, symbol *ast.Symbol, tryReuse bool) *ast.Node { if declaration == nil { if symbol != nil { - declaration = symbol.ValueDeclaration + declaration = symbol.ValueDeclaration() if declaration == nil { // TODO: prefer annotated declarations like in strada (but does this ever even matter in practice? All callers should supply a declaration!) - declaration = core.FirstOrNil(symbol.Declarations) + declaration = core.FirstOrNil(symbol.Declarations()) } } } @@ -2273,9 +2273,9 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati } else { t = b.ctx.enclosingSymbolTypes[ast.GetSymbolId(symbol)] if t == nil { - if symbol.Flags&ast.SymbolFlagsAccessor != 0 && declaration.Kind == ast.KindSetAccessor { + if symbol.Flags()&ast.SymbolFlagsAccessor != 0 && declaration.Kind == ast.KindSetAccessor { t = b.ch.instantiateType(b.ch.getWriteTypeOfSymbol(symbol), b.ctx.mapper) - } else if symbol != nil && (symbol.Flags&(ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsSignature) == 0) { + } else if symbol != nil && (symbol.Flags()&(ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsSignature) == 0) { t = b.ch.instantiateType(b.ch.getWidenedLiteralType(b.ch.getTypeOfSymbol(symbol)), b.ctx.mapper) } else { t = b.ch.errorType @@ -2291,7 +2291,7 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati } restoreFlags := b.saveRestoreFlags() - if t.flags&TypeFlagsUniqueESSymbol != 0 && t.symbol == symbol && (b.ctx.enclosingDeclaration == nil || core.Some(symbol.Declarations, func(d *ast.Declaration) bool { + if t.flags&TypeFlagsUniqueESSymbol != 0 && t.symbol == symbol && (b.ctx.enclosingDeclaration == nil || core.Some(symbol.Declarations(), func(d *ast.Declaration) bool { return ast.GetSourceFileOfNode(d) == b.ctx.enclosingFile })) { b.ctx.flags |= nodebuilder.FlagsAllowUniqueESSymbolType @@ -2311,7 +2311,7 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati pt = b.pc.GetTypeOfDeclaration(declaration) } if (pt == nil || pt.Kind == pseudochecker.PseudoTypeKindNoResult) && ast.IsBinaryExpression(declaration) && symbol != nil { - if decl := core.Find(symbol.Declarations, hasTypeAnnotation); decl != nil { + if decl := core.Find(symbol.Declarations(), hasTypeAnnotation); decl != nil { // Binary expressions have a first-in-wins type annotation system. The first one with an annotation supplies the type for the rest. pt = b.pc.GetTypeOfDeclaration(decl) } @@ -2385,7 +2385,7 @@ func (b *NodeBuilderImpl) shouldUsePlaceholderForProperty(propertySymbol *ast.Sy // for deep mappings which likely come from expressions, while truncating those parts which // come from mappings over library functions. // Condition (3) limits printing of possibly infinitely deep reverse mapped types. - if propertySymbol.CheckFlags&ast.CheckFlagsReverseMapped == 0 { + if propertySymbol.CheckFlags()&ast.CheckFlagsReverseMapped == 0 { return false } // (1) @@ -2500,21 +2500,21 @@ func (b *NodeBuilderImpl) isSingleQuotedStringNamed(d *ast.Declaration) bool { func (b *NodeBuilderImpl) getPropertyNameNodeForSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node) *ast.Node { // For hash-private names, clone the original private identifier from the declaration - if symbol.ValueDeclaration != nil { - declName := symbol.ValueDeclaration.Name() + if symbol.ValueDeclaration() != nil { + declName := symbol.ValueDeclaration().Name() if declName != nil && ast.IsPrivateIdentifier(declName) { return b.f.DeepCloneNode(declName) } } - stringNamed := len(symbol.Declarations) != 0 && core.Every(symbol.Declarations, b.isStringNamed) - singleQuote := len(symbol.Declarations) != 0 && core.Every(symbol.Declarations, b.isSingleQuotedStringNamed) - isMethod := symbol.Flags&ast.SymbolFlagsMethod != 0 + stringNamed := len(symbol.Declarations()) != 0 && core.Every(symbol.Declarations(), b.isStringNamed) + singleQuote := len(symbol.Declarations()) != 0 && core.Every(symbol.Declarations(), b.isSingleQuotedStringNamed) + isMethod := symbol.Flags()&ast.SymbolFlagsMethod != 0 fromNameType := b.getPropertyNameNodeForSymbolFromNameType(symbol, enclosingDeclaration, singleQuote, stringNamed, isMethod) if fromNameType != nil { return fromNameType } - name := symbol.Name + name := symbol.Name() const privateNamePrefix = ast.InternalSymbolNamePrefix + "#" if strings.HasPrefix(name, privateNamePrefix) { // symbol IDs are unstable - replace #nnn# with #private# @@ -2540,7 +2540,7 @@ func (b *NodeBuilderImpl) getPropertyNameNodeForSymbolFromNameType(symbol *ast.S enumEnclosingDeclaration = b.ctx.enclosingFile.AsNode() } if nameType.flags&TypeFlagsEnumLiteral != 0 { - enumSymbol := nameType.symbol.Parent + enumSymbol := nameType.symbol.Parent() if enumSymbol == nil { enumSymbol = nameType.symbol } @@ -2579,7 +2579,7 @@ func (b *NodeBuilderImpl) getPropertyNameNodeForSymbolFromNameType(symbol *ast.S } func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, typeElements []*ast.TypeElement) []*ast.TypeElement { - propertyIsReverseMapped := propertySymbol.CheckFlags&ast.CheckFlagsReverseMapped != 0 + propertyIsReverseMapped := propertySymbol.CheckFlags()&ast.CheckFlagsReverseMapped != 0 var propertyType *Type if b.shouldUsePlaceholderForProperty(propertySymbol) { propertyType = b.ch.anyType @@ -2588,9 +2588,9 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t } saveEnclosingDeclaration := b.ctx.enclosingDeclaration b.ctx.enclosingDeclaration = nil - if isLateBoundName(propertySymbol.Name) { - if len(propertySymbol.Declarations) > 0 { - decl := propertySymbol.Declarations[0] + if isLateBoundName(propertySymbol.Name()) { + if len(propertySymbol.Declarations()) > 0 { + decl := propertySymbol.Declarations()[0] if b.ch.hasLateBindableName(decl) { if ast.IsBinaryExpression(decl) { name := ast.GetNameOfDeclaration(decl) @@ -2605,10 +2605,10 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t b.ctx.tracker.ReportNonSerializableProperty(b.ch.symbolToString(propertySymbol)) } } - if propertySymbol.ValueDeclaration != nil { - b.ctx.enclosingDeclaration = propertySymbol.ValueDeclaration - } else if len(propertySymbol.Declarations) > 0 && propertySymbol.Declarations[0] != nil { - b.ctx.enclosingDeclaration = propertySymbol.Declarations[0] + if propertySymbol.ValueDeclaration() != nil { + b.ctx.enclosingDeclaration = propertySymbol.ValueDeclaration() + } else if len(propertySymbol.Declarations()) > 0 && propertySymbol.Declarations()[0] != nil { + b.ctx.enclosingDeclaration = propertySymbol.Declarations()[0] } else { b.ctx.enclosingDeclaration = saveEnclosingDeclaration } @@ -2616,11 +2616,11 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t b.ctx.enclosingDeclaration = saveEnclosingDeclaration b.ctx.approximateLength += len(ast.SymbolName(propertySymbol)) + 1 - if propertySymbol.Flags&ast.SymbolFlagsAccessor != 0 { + if propertySymbol.Flags()&ast.SymbolFlagsAccessor != 0 { writeType := b.ch.getWriteTypeOfSymbol(propertySymbol) if !b.ch.isErrorType(propertyType) && !b.ch.isErrorType(writeType) { propDeclaration := ast.GetDeclarationOfKind(propertySymbol, ast.KindPropertyDeclaration) - if propertyType != writeType || propertySymbol.Parent != nil && propertySymbol.Parent.Flags&ast.SymbolFlagsClass != 0 && propDeclaration == nil { + if propertyType != writeType || propertySymbol.Parent() != nil && propertySymbol.Parent().Flags()&ast.SymbolFlagsClass != 0 && propDeclaration == nil { symbolMapper := b.ch.valueSymbolLinks.Get(propertySymbol).mapper if getterDeclaration := ast.GetDeclarationOfKind(propertySymbol, ast.KindGetAccessor); getterDeclaration != nil { getterSignature := b.ch.getSignatureFromDeclaration(getterDeclaration) @@ -2645,7 +2645,7 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t typeElements = append(typeElements, setter) } return typeElements - } else if propertySymbol.Parent != nil && propertySymbol.Parent.Flags&ast.SymbolFlagsClass != 0 && propDeclaration != nil && core.Find(propDeclaration.ModifierNodes(), func(m *ast.Node) bool { + } else if propertySymbol.Parent() != nil && propertySymbol.Parent().Flags()&ast.SymbolFlagsClass != 0 && propDeclaration != nil && core.Find(propDeclaration.ModifierNodes(), func(m *ast.Node) bool { return m.Kind == ast.KindAccessorKeyword }) != nil { fakeGetterSignature := b.ch.newSignature(SignatureFlagsNone, nil, nil, nil, nil, propertyType, nil, 0) @@ -2668,12 +2668,12 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t } var optionalToken *ast.Node - if propertySymbol.Flags&ast.SymbolFlagsOptional != 0 { + if propertySymbol.Flags()&ast.SymbolFlagsOptional != 0 { optionalToken = b.f.NewToken(ast.KindQuestionToken) } else { optionalToken = nil } - if propertySymbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 && len(b.ch.getPropertiesOfObjectType(propertyType)) == 0 && !b.ch.isReadonlySymbol(propertySymbol) { + if propertySymbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 && len(b.ch.getPropertiesOfObjectType(propertyType)) == 0 && !b.ch.isReadonlySymbol(propertySymbol) { signatures := b.ch.getSignaturesOfType(b.ch.filterType(propertyType, func(t *Type) bool { return t.flags&TypeFlagsUndefined == 0 }), SignatureKindCall) @@ -2682,7 +2682,7 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t name: propertyName, questionToken: optionalToken, }) - b.setCommentRange(methodDeclaration, core.Coalesce(signature.declaration, propertySymbol.ValueDeclaration)) + b.setCommentRange(methodDeclaration, core.Coalesce(signature.declaration, propertySymbol.ValueDeclaration())) typeElements = append(typeElements, methodDeclaration) } if len(signatures) != 0 || optionalToken == nil { @@ -2713,7 +2713,7 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t } propertySignature := b.f.NewPropertySignatureDeclaration(modifiers, propertyName, optionalToken, propertyTypeNode, nil) - b.setCommentRange(propertySignature, propertySymbol.ValueDeclaration) + b.setCommentRange(propertySignature, propertySymbol.ValueDeclaration()) typeElements = append(typeElements, propertySignature) return typeElements @@ -2752,16 +2752,16 @@ func (b *NodeBuilderImpl) createTypeNodesFromResolvedType(resolvedType *Structur i := 0 for _, propertySymbol := range properties { - if isExpanding(b.ctx) && propertySymbol.Flags&ast.SymbolFlagsPrototype != 0 { + if isExpanding(b.ctx) && propertySymbol.Flags()&ast.SymbolFlagsPrototype != 0 { continue } i++ if b.ctx.flags&nodebuilder.FlagsWriteClassExpressionAsTypeLiteral != 0 { - if propertySymbol.Flags&ast.SymbolFlagsPrototype != 0 { + if propertySymbol.Flags()&ast.SymbolFlagsPrototype != 0 { continue } if getDeclarationModifierFlagsFromSymbol(propertySymbol)&(ast.ModifierFlagsPrivate|ast.ModifierFlagsProtected) != 0 { - b.ctx.tracker.ReportPrivateInBaseOfClassExpression(propertySymbol.Name) + b.ctx.tracker.ReportPrivateInBaseOfClassExpression(propertySymbol.Name()) } if IsPrivateIdentifierSymbol(propertySymbol) { b.ctx.tracker.ReportPrivateInBaseOfClassExpression(ast.SymbolName(propertySymbol)) @@ -2824,7 +2824,7 @@ func (b *NodeBuilderImpl) createTypeNodeFromObjectType(t *Type) *ast.TypeNode { }) // count the number of type elements excluding abstract constructors typeElementCount := len(callSigs) + (len(ctorSigs) - len(abstractSignatures)) + len(resolved.indexInfos) + core.IfElse(b.ctx.flags&nodebuilder.FlagsWriteClassExpressionAsTypeLiteral != 0, core.CountWhere(resolved.properties, func(p *ast.Symbol) bool { - return p.Flags&ast.SymbolFlagsPrototype == 0 + return p.Flags()&ast.SymbolFlagsPrototype == 0 }), len(resolved.properties)) // don't include an empty object literal if there were no other static-side // properties to write, i.e. `abstract class C { }` becomes `abstract new () => {}` @@ -2847,8 +2847,8 @@ func (b *NodeBuilderImpl) createTypeNodeFromObjectType(t *Type) *ast.TypeNode { } func getTypeAliasForTypeLiteral(c *Checker, t *Type) *ast.Symbol { - if t.symbol != nil && t.symbol.Flags&ast.SymbolFlagsTypeLiteral != 0 && t.symbol.Declarations != nil { - node := ast.WalkUpParenthesizedTypes(t.symbol.Declarations[0].Parent) + if t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsTypeLiteral != 0 && t.symbol.Declarations() != nil { + node := ast.WalkUpParenthesizedTypes(t.symbol.Declarations()[0].Parent) if ast.IsTypeAliasDeclaration(node) { return c.getSymbolOfDeclaration(node) } @@ -2858,16 +2858,16 @@ func getTypeAliasForTypeLiteral(c *Checker, t *Type) *ast.Symbol { func (b *NodeBuilderImpl) shouldWriteTypeOfFunctionSymbol(symbol *ast.Symbol, typeId TypeId) (bool, *ast.Symbol) { // `typeof C.name` can only be written when the member name is a valid identifier - isStaticMethodSymbol := symbol.Flags&ast.SymbolFlagsMethod != 0 && scanner.IsIdentifierText(symbol.Name, core.LanguageVariantStandard) && core.Some(symbol.Declarations, func(declaration *ast.Node) bool { + isStaticMethodSymbol := symbol.Flags()&ast.SymbolFlagsMethod != 0 && scanner.IsIdentifierText(symbol.Name(), core.LanguageVariantStandard) && core.Some(symbol.Declarations(), func(declaration *ast.Node) bool { return ast.IsStatic(declaration) && !b.ch.isLateBindableIndexSignature(ast.GetNameOfDeclaration(declaration)) }) isNonLocalFunctionSymbol := false isFunctionExpressionSymbol := false - if symbol.Flags&ast.SymbolFlagsFunction != 0 { - if symbol.Parent != nil { + if symbol.Flags()&ast.SymbolFlagsFunction != 0 { + if symbol.Parent() != nil { isNonLocalFunctionSymbol = true } else { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if declaration.Parent.Kind == ast.KindSourceFile || declaration.Parent.Kind == ast.KindModuleBlock { isNonLocalFunctionSymbol = true break @@ -2884,8 +2884,8 @@ func (b *NodeBuilderImpl) shouldWriteTypeOfFunctionSymbol(symbol *ast.Symbol, ty } } if isStaticMethodSymbol || isNonLocalFunctionSymbol { - if isFunctionExpressionSymbol && symbol.ValueDeclaration != nil && symbol.ValueDeclaration.Parent != nil && symbol.ValueDeclaration.Parent != b.ctx.enclosingDeclaration { - symbol = b.ch.getMergedSymbol(symbol.ValueDeclaration.Parent.Symbol()) + if isFunctionExpressionSymbol && symbol.ValueDeclaration() != nil && symbol.ValueDeclaration().Parent != nil && symbol.ValueDeclaration().Parent != b.ctx.enclosingDeclaration { + symbol = b.ch.getMergedSymbol(symbol.ValueDeclaration().Parent.Symbol()) } // typeof is allowed only for static/non local functions return (b.ctx.flags&nodebuilder.FlagsUseTypeOfFunction != 0 || b.ctx.visitedTypes.Has(typeId)) && // it is type of the symbol uses itself recursively @@ -2902,7 +2902,7 @@ func (b *NodeBuilderImpl) shouldEmitTypeOfSymbol(forceExpansion bool, forceClass if forceExpansion { return false, symbol } - nonFunctionResult := symbol.Flags&ast.SymbolFlagsClass != 0 && !forceClassExpansion && b.ch.getBaseTypeVariableOfClass(symbol) == nil && !(symbol.ValueDeclaration != nil && ast.IsClassLike(symbol.ValueDeclaration) && b.ctx.flags&nodebuilder.FlagsWriteClassExpressionAsTypeLiteral != 0 && (!ast.IsClassDeclaration(symbol.ValueDeclaration) || b.ch.IsSymbolAccessible(symbol, b.ctx.enclosingDeclaration, isInstanceType, false /*shouldComputeAliasesToMakeVisible*/).Accessibility != printer.SymbolAccessibilityAccessible)) || symbol.Flags&(ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule) != 0 + nonFunctionResult := symbol.Flags()&ast.SymbolFlagsClass != 0 && !forceClassExpansion && b.ch.getBaseTypeVariableOfClass(symbol) == nil && !(symbol.ValueDeclaration() != nil && ast.IsClassLike(symbol.ValueDeclaration()) && b.ctx.flags&nodebuilder.FlagsWriteClassExpressionAsTypeLiteral != 0 && (!ast.IsClassDeclaration(symbol.ValueDeclaration()) || b.ch.IsSymbolAccessible(symbol, b.ctx.enclosingDeclaration, isInstanceType, false /*shouldComputeAliasesToMakeVisible*/).Accessibility != printer.SymbolAccessibilityAccessible)) || symbol.Flags()&(ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule) != 0 if nonFunctionResult { return true, symbol } @@ -3159,7 +3159,7 @@ func (b *NodeBuilderImpl) arrayOrTupleTypeToNode(t *Type) *ast.TypeNode { func (b *NodeBuilderImpl) typeReferenceToTypeNode(t *Type) *ast.TypeNode { var typeArguments []*Type = b.ch.getTypeArguments(t) - if b.ctx.flags&nodebuilder.FlagsWriteClassExpressionAsTypeLiteral != 0 && t.symbol.ValueDeclaration != nil && ast.IsClassLike(t.symbol.ValueDeclaration) && !b.ch.IsValueSymbolAccessible(t.symbol, b.ctx.enclosingDeclaration) { + if b.ctx.flags&nodebuilder.FlagsWriteClassExpressionAsTypeLiteral != 0 && t.symbol.ValueDeclaration() != nil && ast.IsClassLike(t.symbol.ValueDeclaration()) && !b.ch.IsValueSymbolAccessible(t.symbol, b.ctx.enclosingDeclaration) { return b.createAnonymousTypeNode(t) } else { outerTypeParameters := t.Target().AsInterfaceType().OuterTypeParameters() @@ -3246,7 +3246,7 @@ func (b *NodeBuilderImpl) visitAndTransformType(t *Type, transform func(b *NodeB return b.createCyclicStructurePlaceholder() } - isConstructorObject := t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && t.symbol.Flags&ast.SymbolFlagsClass != 0 + isConstructorObject := t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsClass != 0 var id *CompositeSymbolIdentity switch { case isArrayOrTuple: @@ -3414,7 +3414,7 @@ func (b *NodeBuilderImpl) typeToTypeNode(t *Type) *ast.TypeNode { } expandingEnum := false if t.flags&TypeFlagsEnumLike != 0 { - if t.symbol.Flags&ast.SymbolFlagsEnumMember != 0 { + if t.symbol.Flags()&ast.SymbolFlagsEnumMember != 0 { parentSymbol := b.ch.getParentOfSymbol(t.symbol) parentName := b.symbolToTypeNode(parentSymbol, ast.SymbolFlagsType, nil) if b.ch.getDeclaredTypeOfSymbol(parentSymbol) == t { @@ -3518,7 +3518,7 @@ func (b *NodeBuilderImpl) typeToTypeNode(t *Type) *ast.TypeNode { if !b.shouldExpandType(t, true /*isAlias*/) { sym := t.alias.Symbol() typeArgumentNodes := b.mapToTypeNodes(t.alias.TypeArguments(), false /*isBareList*/) - if isReservedMemberName(sym.Name) && sym.Flags&ast.SymbolFlagsClass == 0 { + if isReservedMemberName(sym.Name()) && sym.Flags()&ast.SymbolFlagsClass == 0 { return b.f.NewTypeReferenceNode(b.f.NewIdentifier(""), typeArgumentNodes) } if typeArgumentNodes != nil && len(typeArgumentNodes.Nodes) == 1 && sym == b.ch.globalArrayType.symbol { @@ -3727,12 +3727,12 @@ func (b *NodeBuilderImpl) lookupInstantiatedTypeArgumentNodes(chain []*ast.Symbo if b.shouldWriteTypeParametersInQualifiedName(chain, index) { symbol := chain[index] nextSymbol := chain[index+1] - if nextSymbol.CheckFlags&ast.CheckFlagsInstantiated == 0 { + if nextSymbol.CheckFlags()&ast.CheckFlagsInstantiated == 0 { return nil } targetSymbol := symbol - if symbol.Flags&ast.SymbolFlagsAlias != 0 && !b.ch.canGetTypeParametersOfClassOrInterface(symbol) { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 && !b.ch.canGetTypeParametersOfClassOrInterface(symbol) { targetSymbol = b.ch.resolveAlias(symbol) } diff --git a/tsc/internal/checker/nodebuilderscopes.go b/tsc/internal/checker/nodebuilderscopes.go index 59b5fcd479b55..244d598682c59 100644 --- a/tsc/internal/checker/nodebuilderscopes.go +++ b/tsc/internal/checker/nodebuilderscopes.go @@ -175,9 +175,9 @@ func (b *NodeBuilderImpl) enterNewScope(declaration *ast.Node, expandedParams [] if originalParameters != nil && originalParam != param { // Can't reference the expanded parameter name, just the original, unless we've expanded the param list for some reason if originalParam != nil { - add(originalParam.Name, originalParam) + add(originalParam.Name(), originalParam) } - } else if !core.Some(param.Declarations, func(d *ast.Node) bool { + } else if !core.Some(param.Declarations(), func(d *ast.Node) bool { var bindElement func(e *ast.BindingElement) var bindPattern func(e *ast.BindingPattern) @@ -202,7 +202,7 @@ func (b *NodeBuilderImpl) enterNewScope(declaration *ast.Node, expandedParams [] } symbol := b.ch.getSymbolOfDeclaration(e.AsNode()) if symbol != nil { // omitted expressions are now parsed as nameless binding patterns and also have no symbol - add(symbol.Name, symbol) + add(symbol.Name(), symbol) } } bindElement = bindElementWorker @@ -214,7 +214,7 @@ func (b *NodeBuilderImpl) enterNewScope(declaration *ast.Node, expandedParams [] } return false }) { - add(param.Name, param) + add(param.Name(), param) } } }) diff --git a/tsc/internal/checker/nodecopy.go b/tsc/internal/checker/nodecopy.go index 5b2a0739f7612..c098604800dc0 100644 --- a/tsc/internal/checker/nodecopy.go +++ b/tsc/internal/checker/nodecopy.go @@ -298,7 +298,7 @@ func getExistingNodeTreeVisitor(b *NodeBuilderImpl, bound *recoveryBoundary) *as var name *ast.Node if sym != nil { type_ = b.ch.getDeclaredTypeOfSymbol(sym) - if sym.Flags&ast.SymbolFlagsTypeParameter != 0 { + if sym.Flags()&ast.SymbolFlagsTypeParameter != 0 { name = b.typeParameterToName(type_).AsNode() } } @@ -337,7 +337,7 @@ func getExistingNodeTreeVisitor(b *NodeBuilderImpl, bound *recoveryBoundary) *as return introducesError, attachSymbolToLeftmostIdentifier(leftmost, node, sym), nil } sym = b.ch.resolveEntityName(leftmost, meaning, true, true, nil) - if b.ctx.enclosingDeclaration != nil && !(sym != nil && sym.Flags&ast.SymbolFlagsTypeParameter != 0) { + if b.ctx.enclosingDeclaration != nil && !(sym != nil && sym.Flags()&ast.SymbolFlagsTypeParameter != 0) { sym = b.ch.getExportSymbolOfValueSymbolIfExported(sym) // Some declarations may be transplanted to a new location. // When this happens we need to make sure that the name has the same meaning at both locations @@ -365,12 +365,12 @@ func getExistingNodeTreeVisitor(b *NodeBuilderImpl, bound *recoveryBoundary) *as if sym != nil { // If a parameter is resolvable in the current context it is also visible, so no need to go to symbol accesibility - if sym.Flags&ast.SymbolFlagsFunctionScopedVariable != 0 && sym.ValueDeclaration != nil { - if ast.IsPartOfParameterDeclaration(sym.ValueDeclaration) || ast.IsJSDocParameterTag(sym.ValueDeclaration) { + if sym.Flags()&ast.SymbolFlagsFunctionScopedVariable != 0 && sym.ValueDeclaration() != nil { + if ast.IsPartOfParameterDeclaration(sym.ValueDeclaration()) || ast.IsJSDocParameterTag(sym.ValueDeclaration()) { return introducesError, attachSymbolToLeftmostIdentifier(leftmost, node, sym), nil } } - if sym.Flags&ast.SymbolFlagsTypeParameter == 0 /* Type parameters are visible in the current context if they are are resolvable */ && !ast.IsDeclarationName(node) && + if sym.Flags()&ast.SymbolFlagsTypeParameter == 0 /* Type parameters are visible in the current context if they are are resolvable */ && !ast.IsDeclarationName(node) && b.ch.IsSymbolAccessible(sym, enclosingDeclaration, meaning, false).Accessibility != printer.SymbolAccessibilityAccessible { b.ctx.tracker.ReportInferenceFallback(node) introducesError = true @@ -421,7 +421,7 @@ func getExistingNodeTreeVisitor(b *NodeBuilderImpl, bound *recoveryBoundary) *as if s == nil { return nil // ??? } - if s.Flags&ast.SymbolFlagsTypeParameter != 0 { + if s.Flags()&ast.SymbolFlagsTypeParameter != 0 { declaredType := b.ch.getDeclaredTypeOfSymbol(s) if b.ctx.mapper != nil && getMappedType(declaredType, b.ctx.mapper) != declaredType { return nil // refers to type parameter remapped by context (TODO improvement: just return the remapped param name?) diff --git a/tsc/internal/checker/printer.go b/tsc/internal/checker/printer.go index 234e3e4b0818d..b84c967883d88 100644 --- a/tsc/internal/checker/printer.go +++ b/tsc/internal/checker/printer.go @@ -311,8 +311,8 @@ func (c *Checker) ExpandSymbolForHover(symbol *ast.Symbol, meaning ast.SymbolFla } p := createPrinterWithRemoveComments(nodeBuilder.EmitContext()) var sourceFile *ast.SourceFile - if symbol.ValueDeclaration != nil { - sourceFile = ast.GetSourceFileOfNode(symbol.ValueDeclaration) + if symbol.ValueDeclaration() != nil { + sourceFile = ast.GetSourceFileOfNode(symbol.ValueDeclaration()) } var b strings.Builder for i, node := range nodes { diff --git a/tsc/internal/checker/pseudotypenodebuilder.go b/tsc/internal/checker/pseudotypenodebuilder.go index 9daf4b686fc43..40ca59da0ebec 100644 --- a/tsc/internal/checker/pseudotypenodebuilder.go +++ b/tsc/internal/checker/pseudotypenodebuilder.go @@ -425,7 +425,7 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType // which are two elements in pt.Elements but only one symbol in targetProps. targetDeclCount := 0 for _, prop := range targetProps { - targetDeclCount += len(prop.Declarations) + targetDeclCount += len(prop.Declarations()) } if len(pt.Elements) != targetDeclCount { return false @@ -434,13 +434,13 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType var targetProp *ast.Symbol elemSymbol := e.Name.Parent.Symbol() if elemSymbol != nil { - targetProp = b.ch.getPropertyOfType(undefinedStripped, elemSymbol.Name) + targetProp = b.ch.getPropertyOfType(undefinedStripped, elemSymbol.Name()) } if targetProp == nil { // Name lookup failed or returned no result; search target properties // for one whose declaration name node matches the one we have for _, prop := range targetProps { - if prop.ValueDeclaration != nil && prop.ValueDeclaration.Name() == e.Name { + if prop.ValueDeclaration() != nil && prop.ValueDeclaration().Name() == e.Name { targetProp = prop break } @@ -452,7 +452,7 @@ func (b *NodeBuilderImpl) pseudoTypeEquivalentToType(t *pseudochecker.PseudoType return false } } - targetIsOptional := targetProp.Flags&ast.SymbolFlagsOptional != 0 + targetIsOptional := targetProp.Flags()&ast.SymbolFlagsOptional != 0 if e.Optional != targetIsOptional { if reportErrors { b.ctx.tracker.ReportInferenceFallback(e.Name.Parent) @@ -612,7 +612,7 @@ func (b *NodeBuilderImpl) pseudoParametersEquivalentToParameters(params []*pseud } for i, p := range params { targetParam := targetSig.parameters[i] - if p.Optional != b.ch.isOptionalParameter(targetParam.ValueDeclaration) { + if p.Optional != b.ch.isOptionalParameter(targetParam.ValueDeclaration()) { if reportErrors { b.ctx.tracker.ReportInferenceFallback(p.Name.Parent) } diff --git a/tsc/internal/checker/relater.go b/tsc/internal/checker/relater.go index afb28721c8b9b..a9bc484fef1d2 100644 --- a/tsc/internal/checker/relater.go +++ b/tsc/internal/checker/relater.go @@ -235,7 +235,7 @@ func (c *Checker) isSimpleTypeRelatedTo(source *Type, target *Type, relation *Re if s&TypeFlagsESSymbolLike != 0 && t&TypeFlagsESSymbol != 0 { return true } - if s&TypeFlagsEnum != 0 && t&TypeFlagsEnum != 0 && source.symbol.Name == target.symbol.Name && c.isEnumTypeRelatedTo(source.symbol, target.symbol, errorReporter) { + if s&TypeFlagsEnum != 0 && t&TypeFlagsEnum != 0 && source.symbol.Name() == target.symbol.Name() && c.isEnumTypeRelatedTo(source.symbol, target.symbol, errorReporter) { return true } if s&TypeFlagsEnumLiteral != 0 && t&TypeFlagsEnumLiteral != 0 { @@ -279,12 +279,12 @@ func (c *Checker) isSimpleTypeRelatedTo(source *Type, target *Type, relation *Re } func (c *Checker) isEnumTypeRelatedTo(source *ast.Symbol, target *ast.Symbol, errorReporter ErrorReporter) bool { - sourceSymbol := core.IfElse(source.Flags&ast.SymbolFlagsEnumMember != 0, c.getParentOfSymbol(source), source) - targetSymbol := core.IfElse(target.Flags&ast.SymbolFlagsEnumMember != 0, c.getParentOfSymbol(target), target) + sourceSymbol := core.IfElse(source.Flags()&ast.SymbolFlagsEnumMember != 0, c.getParentOfSymbol(source), source) + targetSymbol := core.IfElse(target.Flags()&ast.SymbolFlagsEnumMember != 0, c.getParentOfSymbol(target), target) if sourceSymbol == targetSymbol { return true } - if sourceSymbol.Name != targetSymbol.Name || sourceSymbol.Flags&ast.SymbolFlagsRegularEnum == 0 || targetSymbol.Flags&ast.SymbolFlagsRegularEnum == 0 { + if sourceSymbol.Name() != targetSymbol.Name() || sourceSymbol.Flags()&ast.SymbolFlagsRegularEnum == 0 || targetSymbol.Flags()&ast.SymbolFlagsRegularEnum == 0 { return false } key := EnumRelationKey{sourceId: ast.GetSymbolId(sourceSymbol), targetId: ast.GetSymbolId(targetSymbol)} @@ -293,9 +293,9 @@ func (c *Checker) isEnumTypeRelatedTo(source *ast.Symbol, target *ast.Symbol, er } targetEnumType := c.getTypeOfSymbol(targetSymbol) for _, sourceProperty := range c.getPropertiesOfType(c.getTypeOfSymbol(sourceSymbol)) { - if sourceProperty.Flags&ast.SymbolFlagsEnumMember != 0 { - targetProperty := c.getPropertyOfType(targetEnumType, sourceProperty.Name) - if targetProperty == nil || targetProperty.Flags&ast.SymbolFlagsEnumMember == 0 { + if sourceProperty.Flags()&ast.SymbolFlagsEnumMember != 0 { + targetProperty := c.getPropertyOfType(targetEnumType, sourceProperty.Name()) + if targetProperty == nil || targetProperty.Flags()&ast.SymbolFlagsEnumMember == 0 { if errorReporter != nil { errorReporter(diagnostics.Property_0_is_missing_in_type_1, c.symbolToString(sourceProperty), c.TypeToStringEx(c.getDeclaredTypeOfSymbol(targetSymbol), nil /*enclosingDeclaration*/, TypeFormatFlagsUseFullyQualifiedType, nil)) } @@ -569,8 +569,8 @@ func (c *Checker) elaborateElement(source *Type, target *Type, relation *Relatio diags = append(diags, createDiagnosticForNode(prop, diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_type_of_the_target, c.TypeToString(specificSource), c.TypeToString(targetPropType))) } else { propName := c.getPropertyNameFromIndex(nameType, nil /*accessNode*/) - targetIsOptional := core.OrElse(c.getPropertyOfType(target, propName), c.unknownSymbol).Flags&ast.SymbolFlagsOptional != 0 - sourceIsOptional := core.OrElse(c.getPropertyOfType(source, propName), c.unknownSymbol).Flags&ast.SymbolFlagsOptional != 0 + targetIsOptional := core.OrElse(c.getPropertyOfType(target, propName), c.unknownSymbol).Flags()&ast.SymbolFlagsOptional != 0 + sourceIsOptional := core.OrElse(c.getPropertyOfType(source, propName), c.unknownSymbol).Flags()&ast.SymbolFlagsOptional != 0 targetPropType = c.removeMissingType(targetPropType, targetIsOptional) sourcePropType = c.removeMissingType(sourcePropType, targetIsOptional && sourceIsOptional) result := c.checkTypeRelatedToEx(specificSource, targetPropType, relation, prop, errorMessage, &diags) @@ -597,12 +597,12 @@ func (c *Checker) elaborateElement(source *Type, target *Type, relation *Relatio diagnostic.AddRelatedInfo(createDiagnosticForNode(indexInfo.declaration, diagnostics.The_expected_type_comes_from_this_index_signature)) } } - if !issuedElaboration && (targetProp != nil && len(targetProp.Declarations) != 0 || target.symbol != nil && len(target.symbol.Declarations) != 0) { + if !issuedElaboration && (targetProp != nil && len(targetProp.Declarations()) != 0 || target.symbol != nil && len(target.symbol.Declarations()) != 0) { var targetNode *ast.Node - if targetProp != nil && len(targetProp.Declarations) != 0 { - targetNode = targetProp.Declarations[0] + if targetProp != nil && len(targetProp.Declarations()) != 0 { + targetNode = targetProp.Declarations()[0] } else { - targetNode = target.symbol.Declarations[0] + targetNode = target.symbol.Declarations()[0] } if propertyName == "" || nameType.flags&TypeFlagsUniqueESSymbol != 0 { propertyName = c.TypeToString(nameType) @@ -662,8 +662,8 @@ func (c *Checker) elaborateArrowFunction(node *ast.Node, source *Type, target *T c.checkTypeRelatedToEx(sourceReturn, targetReturn, relation, returnExpression, nil /*headMessage*/, &diags) if len(diags) != 0 { diagnostic := diags[0] - if target.symbol != nil && len(target.symbol.Declarations) != 0 { - diagnostic.AddRelatedInfo(createDiagnosticForNode(target.symbol.Declarations[0], diagnostics.The_expected_type_comes_from_the_return_type_of_this_signature)) + if target.symbol != nil && len(target.symbol.Declarations()) != 0 { + diagnostic.AddRelatedInfo(createDiagnosticForNode(target.symbol.Declarations()[0], diagnostics.The_expected_type_comes_from_the_return_type_of_this_signature)) } if ast.GetFunctionFlags(node)&ast.FunctionFlagsAsync == 0 && c.getTypeOfPropertyOfType(sourceReturn, "then") == nil && c.checkTypeRelatedTo(c.createPromiseType(sourceReturn), targetReturn, relation, nil /*errorNode*/) { diagnostic.AddRelatedInfo(createDiagnosticForNode(node, diagnostics.Did_you_mean_to_mark_this_function_as_async)) @@ -680,7 +680,7 @@ func (c *Checker) isWeakType(t *Type) bool { if t.flags&TypeFlagsObject != 0 { resolved := c.resolveStructuredTypeMembers(t) return len(resolved.signatures) == 0 && len(resolved.indexInfos) == 0 && len(resolved.properties) > 0 && core.Every(resolved.properties, func(p *ast.Symbol) bool { - return p.Flags&ast.SymbolFlagsOptional != 0 + return p.Flags()&ast.SymbolFlagsOptional != 0 }) } if t.flags&TypeFlagsSubstitution != 0 { @@ -694,7 +694,7 @@ func (c *Checker) isWeakType(t *Type) bool { func (c *Checker) hasCommonProperties(source *Type, target *Type, isComparingJsxAttributes bool) bool { for _, prop := range c.getPropertiesOfType(source) { - if c.isKnownProperty(target, prop.Name, isComparingJsxAttributes) { + if c.isKnownProperty(target, prop.Name(), isComparingJsxAttributes) { return true } } @@ -846,7 +846,7 @@ func getRecursionIdentityFromTarget(t *Type) RecursionId { // unique AST node. return asRecursionId(t.AsTypeReference().node) } - if t.symbol != nil && !(t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol.Flags&ast.SymbolFlagsClass != 0) && t.objectFlags&ObjectFlagsFromTypeNode == 0 { + if t.symbol != nil && !(t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol.Flags()&ast.SymbolFlagsClass != 0) && t.objectFlags&ObjectFlagsFromTypeNode == 0 { // We track object types that have a symbol by that symbol (representing the origin of the type), but // exclude the static sides of classes (since they share their symbols with the instance sides) and type // references that originate in resolution of AST type nodes (since such type nodes cannot be the source @@ -981,8 +981,8 @@ func (c *Checker) getUnmatchedPropertiesWorker(source *Type, target *Type, requi if isStaticPrivateIdentifierProperty(targetProp) { continue } - if requireOptionalProperties || targetProp.Flags&ast.SymbolFlagsOptional == 0 && targetProp.CheckFlags&ast.CheckFlagsPartial == 0 { - sourceProp := c.getPropertyOfType(source, targetProp.Name) + if requireOptionalProperties || targetProp.Flags()&ast.SymbolFlagsOptional == 0 && targetProp.CheckFlags()&ast.CheckFlagsPartial == 0 { + sourceProp := c.getPropertyOfType(source, targetProp.Name()) if sourceProp == nil { if propsOut == nil { return targetProp @@ -1012,7 +1012,7 @@ func excludeProperties(properties []*ast.Symbol, excludedProperties collections. var reduced []*ast.Symbol var excluded bool for i, prop := range properties { - if !excludedProperties.Has(prop.Name) { + if !excludedProperties.Has(prop.Name()) { if excluded { reduced = append(reduced, prop) } @@ -1038,7 +1038,7 @@ func (d *TypeDiscriminator) len() int { } func (d *TypeDiscriminator) name(index int) string { - return d.props[index].Name + return d.props[index].Name() } func (d *TypeDiscriminator) matches(index int, t *Type) bool { @@ -1070,7 +1070,7 @@ func (c *Checker) findMatchingDiscriminantType(source *Type, target *Type, isRel func (c *Checker) findDiscriminantProperties(sourceProperties []*ast.Symbol, target *Type) []*ast.Symbol { var result []*ast.Symbol for _, sourceProperty := range sourceProperties { - if c.isDiscriminantProperty(target, sourceProperty.Name) { + if c.isDiscriminantProperty(target, sourceProperty.Name()) { result = append(result, sourceProperty) } } @@ -1080,14 +1080,14 @@ func (c *Checker) findDiscriminantProperties(sourceProperties []*ast.Symbol, tar func (c *Checker) isDiscriminantProperty(t *Type, name string) bool { if t != nil && t.flags&TypeFlagsUnion != 0 { prop := c.getUnionOrIntersectionProperty(t, name, false /*skipObjectFunctionPropertyAugment*/) - if prop != nil && prop.CheckFlags&ast.CheckFlagsSyntheticProperty != 0 { - if prop.CheckFlags&ast.CheckFlagsIsDiscriminantComputed == 0 { - prop.CheckFlags |= ast.CheckFlagsIsDiscriminantComputed - if prop.CheckFlags&ast.CheckFlagsNonUniformAndLiteral == ast.CheckFlagsNonUniformAndLiteral && !c.isGenericType(c.getTypeOfSymbol(prop)) { - prop.CheckFlags |= ast.CheckFlagsIsDiscriminant + if prop != nil && prop.CheckFlags()&ast.CheckFlagsSyntheticProperty != 0 { + if prop.CheckFlags()&ast.CheckFlagsIsDiscriminantComputed == 0 { + prop.SetCheckFlags(prop.CheckFlags() | ast.CheckFlagsIsDiscriminantComputed) + if prop.CheckFlags()&ast.CheckFlagsNonUniformAndLiteral == ast.CheckFlagsNonUniformAndLiteral && !c.isGenericType(c.getTypeOfSymbol(prop)) { + prop.SetCheckFlags(prop.CheckFlags() | ast.CheckFlagsIsDiscriminant) } } - return prop.CheckFlags&ast.CheckFlagsIsDiscriminant != 0 + return prop.CheckFlags()&ast.CheckFlagsIsDiscriminant != 0 } } return false @@ -1154,7 +1154,7 @@ func (c *Checker) getKeyPropertyCandidateName(types []*Type) string { if t.flags&(TypeFlagsObject|TypeFlagsInstantiableNonPrimitive) != 0 { for _, p := range c.getPropertiesOfType(t) { if isUnitType(c.getTypeOfSymbol(p)) { - return p.Name + return p.Name() } } } @@ -1270,13 +1270,13 @@ func isNonPrimitiveType(t *Type) bool { func (c *Checker) getTypeNamesForErrorDisplay(left *Type, right *Type) (string, string) { var leftStr string if c.symbolValueDeclarationIsContextSensitive(left.symbol) { - leftStr = c.typeToString(left, left.symbol.ValueDeclaration) + leftStr = c.typeToString(left, left.symbol.ValueDeclaration()) } else { leftStr = c.TypeToString(left) } var rightStr string if c.symbolValueDeclarationIsContextSensitive(right.symbol) { - rightStr = c.typeToString(right, right.symbol.ValueDeclaration) + rightStr = c.typeToString(right, right.symbol.ValueDeclaration()) } else { rightStr = c.TypeToString(right) } @@ -1292,7 +1292,7 @@ func (c *Checker) getTypeNameForErrorDisplay(t *Type) string { } func (c *Checker) symbolValueDeclarationIsContextSensitive(symbol *ast.Symbol) bool { - return symbol != nil && symbol.ValueDeclaration != nil && ast.IsExpression(symbol.ValueDeclaration) && !c.isContextSensitive(symbol.ValueDeclaration) + return symbol != nil && symbol.ValueDeclaration() != nil && ast.IsExpression(symbol.ValueDeclaration()) && !c.isContextSensitive(symbol.ValueDeclaration()) } func (c *Checker) typeCouldHaveTopLevelSingletonTypes(t *Type) bool { @@ -1450,7 +1450,7 @@ func (c *Checker) createMarkerType(symbol *ast.Symbol, source *Type, target *Typ return t } var result *Type - if symbol.Flags&ast.SymbolFlagsTypeAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsTypeAlias != 0 { result = c.getTypeAliasInstantiation(symbol, c.instantiateTypes(c.typeAliasLinks.Get(symbol).typeParameters, mapper), nil) } else { result = c.createTypeReference(t, c.instantiateTypes(t.AsInterfaceType().TypeParameters(), mapper)) @@ -1466,7 +1466,7 @@ func (c *Checker) isMarkerType(t *Type) bool { func (c *Checker) getTypeParameterModifiers(tp *Type) ast.ModifierFlags { var flags ast.ModifierFlags if tp.symbol != nil { - for _, d := range tp.symbol.Declarations { + for _, d := range tp.symbol.Declarations() { flags |= d.ModifierFlags() } } @@ -1860,7 +1860,7 @@ func (c *Checker) getRestTypeAtPosition(source *Signature, pos int, readonly boo func (c *Checker) getNameableDeclarationAtPosition(signature *Signature, pos int) *ast.Node { paramCount := len(signature.parameters) - core.IfElse(signatureHasRestParameter(signature), 1, 0) if pos < paramCount { - decl := signature.parameters[pos].ValueDeclaration + decl := signature.parameters[pos].ValueDeclaration() if decl != nil && c.isValidDeclarationForTupleLabel(decl) { return decl } @@ -1877,8 +1877,8 @@ func (c *Checker) getNameableDeclarationAtPosition(signature *Signature, pos int } return nil } - if restParameter.ValueDeclaration != nil && c.isValidDeclarationForTupleLabel(restParameter.ValueDeclaration) { - return restParameter.ValueDeclaration + if restParameter.ValueDeclaration() != nil && c.isValidDeclarationForTupleLabel(restParameter.ValueDeclaration()) { + return restParameter.ValueDeclaration() } } return nil @@ -1962,7 +1962,7 @@ func (c *Checker) isInstantiatedGenericParameter(signature *Signature, pos int) func (c *Checker) getParameterNameAtPosition(signature *Signature, pos int) string { paramCount := len(signature.parameters) - core.IfElse(signatureHasRestParameter(signature), 1, 0) if pos < paramCount { - return signature.parameters[pos].Name + return signature.parameters[pos].Name() } restParameter := signature.parameters[paramCount] restType := c.getTypeOfSymbol(restParameter) @@ -1970,19 +1970,19 @@ func (c *Checker) getParameterNameAtPosition(signature *Signature, pos int) stri index := pos - paramCount return c.getTupleElementLabel(restType.TargetTupleType().elementInfos[index], restParameter, index) } - return restParameter.Name + return restParameter.Name() } func (c *Checker) getTupleElementLabel(elementInfo TupleElementInfo, restSymbol *ast.Symbol, index int) string { if elementInfo.labeledDeclaration != nil { return elementInfo.labeledDeclaration.Name().Text() } - if restSymbol != nil && restSymbol.ValueDeclaration != nil && ast.IsParameterDeclaration(restSymbol.ValueDeclaration) { - return c.getTupleElementLabelFromBindingElement(restSymbol.ValueDeclaration, index, elementInfo.flags) + if restSymbol != nil && restSymbol.ValueDeclaration() != nil && ast.IsParameterDeclaration(restSymbol.ValueDeclaration()) { + return c.getTupleElementLabelFromBindingElement(restSymbol.ValueDeclaration(), index, elementInfo.flags) } var rootName string if restSymbol != nil { - rootName = restSymbol.Name + rootName = restSymbol.Name() } else { rootName = "arg" } @@ -2126,7 +2126,7 @@ func (c *Checker) createTypePredicateFromTypePredicateNode(node *ast.Node, signa } kind := core.IfElse(predicateNode.AssertsModifier != nil, TypePredicateKindAssertsIdentifier, TypePredicateKindIdentifier) name := predicateNode.ParameterName.Text() - index := core.FindIndex(signature.parameters, func(p *ast.Symbol) bool { return p.Name == name }) + index := core.FindIndex(signature.parameters, func(p *ast.Symbol) bool { return p.Name() == name }) return c.newTypePredicate(kind, name, int32(index), t) } @@ -2764,7 +2764,7 @@ func (r *Relater) hasExcessProperties(source *Type, target *Type, reportErrors b } for _, prop := range r.c.getPropertiesOfType(source) { if shouldCheckAsExcessProperty(prop, source.symbol) && !isIgnoredJsxProperty(source, prop) { - if !r.c.isKnownProperty(reducedTarget, prop.Name, isComparingJsxAttributes) { + if !r.c.isKnownProperty(reducedTarget, prop.Name(), isComparingJsxAttributes) { if reportErrors { // Report error in terms of object types in the target as those are the only ones // we check in isKnownProperty. @@ -2778,10 +2778,10 @@ func (r *Relater) hasExcessProperties(source *Type, target *Type, reportErrors b if ast.IsJsxAttributes(r.errorNode) || ast.IsJsxOpeningLikeElement(r.errorNode) || ast.IsJsxOpeningLikeElement(r.errorNode.Parent) { // JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal. // However, using an object-literal error message will be very confusing to the users so we give different a message. - if prop.ValueDeclaration != nil && ast.IsJsxAttribute(prop.ValueDeclaration) && ast.GetSourceFileOfNode(r.errorNode) == ast.GetSourceFileOfNode(prop.ValueDeclaration.Name()) { + if prop.ValueDeclaration() != nil && ast.IsJsxAttribute(prop.ValueDeclaration()) && ast.GetSourceFileOfNode(r.errorNode) == ast.GetSourceFileOfNode(prop.ValueDeclaration().Name()) { // Note that extraneous children (as in `extra`) don't pass this check, // since `children` is a Kind.PropertySignature instead of a Kind.JsxAttribute. - r.errorNode = prop.ValueDeclaration.Name() + r.errorNode = prop.ValueDeclaration().Name() } propName := r.c.symbolToString(prop) suggestionSymbol := r.c.getSuggestedSymbolForNonexistentJSXAttribute(propName, errorTarget) @@ -2794,13 +2794,13 @@ func (r *Relater) hasExcessProperties(source *Type, target *Type, reportErrors b // use the property's value declaration if the property is assigned inside the literal itself var objectLiteralDeclaration *ast.Node if source.symbol != nil { - objectLiteralDeclaration = core.FirstOrNil(source.symbol.Declarations) + objectLiteralDeclaration = core.FirstOrNil(source.symbol.Declarations()) } var suggestion string - if prop.ValueDeclaration != nil && ast.IsObjectLiteralElement(prop.ValueDeclaration) && - ast.FindAncestor(prop.ValueDeclaration, func(d *ast.Node) bool { return d == objectLiteralDeclaration }) != nil && + if prop.ValueDeclaration() != nil && ast.IsObjectLiteralElement(prop.ValueDeclaration()) && + ast.FindAncestor(prop.ValueDeclaration(), func(d *ast.Node) bool { return d == objectLiteralDeclaration }) != nil && ast.GetSourceFileOfNode(objectLiteralDeclaration) == ast.GetSourceFileOfNode(r.errorNode) { - name := prop.ValueDeclaration.Name() + name := prop.ValueDeclaration().Name() r.errorNode = name if ast.IsIdentifier(name) { suggestion = r.c.getSuggestionForNonexistentProperty(name.Text(), errorTarget) @@ -2815,7 +2815,7 @@ func (r *Relater) hasExcessProperties(source *Type, target *Type, reportErrors b } return true } - if checkTypes != nil && r.isRelatedTo(r.c.getTypeOfSymbol(prop), r.c.getTypeOfPropertyInTypes(checkTypes, prop.Name), RecursionFlagsBoth, reportErrors) == TernaryFalse { + if checkTypes != nil && r.isRelatedTo(r.c.getTypeOfSymbol(prop), r.c.getTypeOfPropertyInTypes(checkTypes, prop.Name()), RecursionFlagsBoth, reportErrors) == TernaryFalse { if reportErrors { r.reportError(diagnostics.Types_of_property_0_are_incompatible, r.c.symbolToString(prop)) } @@ -2853,11 +2853,11 @@ func (c *Checker) getTypeOfPropertyInType(t *Type, name string) *Type { } func shouldCheckAsExcessProperty(prop *ast.Symbol, container *ast.Symbol) bool { - return prop.ValueDeclaration != nil && container.ValueDeclaration != nil && prop.ValueDeclaration.Parent == container.ValueDeclaration + return prop.ValueDeclaration() != nil && container.ValueDeclaration() != nil && prop.ValueDeclaration().Parent == container.ValueDeclaration() } func isIgnoredJsxProperty(source *Type, sourceProp *ast.Symbol) bool { - return source.objectFlags&ObjectFlagsJsxAttributes != 0 && isHyphenatedJsxName(sourceProp.Name) + return source.objectFlags&ObjectFlagsJsxAttributes != 0 && isHyphenatedJsxName(sourceProp.Name()) } func (c *Checker) isTypeSubsetOf(source *Type, target *Type) bool { @@ -3429,7 +3429,7 @@ func (r *Relater) structuredTypeRelatedToWorker(source *Type, target *Type, repo } params := r.c.typeAliasLinks.Get(source.alias.symbol).typeParameters minParams := r.c.getMinTypeArgumentCount(params) - nodeIsInJsFile := ast.IsInJSFile(source.alias.symbol.ValueDeclaration) + nodeIsInJsFile := ast.IsInJSFile(source.alias.symbol.ValueDeclaration()) sourceTypes := r.c.fillMissingTypeArguments(source.alias.typeArguments, params, minParams, nodeIsInJsFile) targetTypes := r.c.fillMissingTypeArguments(target.alias.typeArguments, params, minParams, nodeIsInJsFile) varianceResult, ok := relateVariances(sourceTypes, targetTypes, variances, intersectionState) @@ -4057,7 +4057,7 @@ func (r *Relater) typeRelatedToDiscriminatedType(source *Type, target *Type) Ter for i, sourceProperty := range sourcePropertiesFiltered { sourcePropertyType := r.c.getNonMissingTypeOfSymbol(sourceProperty) sourceDiscriminantTypes[i] = sourcePropertyType.Distributed() - excludedProperties.Add(sourceProperty.Name) + excludedProperties.Add(sourceProperty.Name()) } // Build the cartesian product discriminantCombinations := make([][]*Type, numCombinations) @@ -4081,7 +4081,7 @@ func (r *Relater) typeRelatedToDiscriminatedType(source *Type, target *Type) Ter for _, t := range target.Types() { for i := range sourcePropertiesFiltered { sourceProperty := sourcePropertiesFiltered[i] - targetProperty := r.c.getPropertyOfType(t, sourceProperty.Name) + targetProperty := r.c.getPropertyOfType(t, sourceProperty.Name()) if targetProperty == nil { continue outer } @@ -4271,7 +4271,7 @@ func (r *Relater) propertiesRelatedTo(source *Type, target *Type, reportErrors b } if isObjectLiteralType(target) { for _, sourceProp := range excludeProperties(r.c.getPropertiesOfType(source), excludedProperties) { - if r.c.getPropertyOfObjectType(target, sourceProp.Name) == nil { + if r.c.getPropertyOfObjectType(target, sourceProp.Name()) == nil { if reportErrors { r.reportError(diagnostics.Property_0_does_not_exist_on_type_1, r.c.symbolToString(sourceProp), r.c.TypeToString(target)) } @@ -4284,8 +4284,8 @@ func (r *Relater) propertiesRelatedTo(source *Type, target *Type, reportErrors b properties := r.c.getPropertiesOfType(target) numericNamesOnly := isTupleType(source) && isTupleType(target) for _, targetProp := range excludeProperties(properties, excludedProperties) { - name := targetProp.Name - if targetProp.Flags&ast.SymbolFlagsPrototype == 0 && (!numericNamesOnly || isNumericLiteralName(name) || name == "length") && (!optionalsOnly || targetProp.Flags&ast.SymbolFlagsOptional != 0) { + name := targetProp.Name() + if targetProp.Flags()&ast.SymbolFlagsPrototype == 0 && (!numericNamesOnly || isNumericLiteralName(name) || name == "length") && (!optionalsOnly || targetProp.Flags()&ast.SymbolFlagsOptional != 0) { sourceProp := r.c.getPropertyOfType(source, name) if sourceProp != nil && sourceProp != targetProp { related := r.propertyRelatedTo(source, target, sourceProp, targetProp, r.c.getNonMissingTypeOfSymbol, reportErrors, intersectionState, r.relation == r.c.comparableRelation) @@ -4304,7 +4304,7 @@ func (r *Relater) propertyRelatedTo(source *Type, target *Type, sourceProp *ast. targetPropFlags := getDeclarationModifierFlagsFromSymbol(targetProp) switch { case sourcePropFlags&ast.ModifierFlagsPrivate != 0 || targetPropFlags&ast.ModifierFlagsPrivate != 0: - if sourceProp.ValueDeclaration != targetProp.ValueDeclaration { + if sourceProp.ValueDeclaration() != targetProp.ValueDeclaration() { if reportErrors { if sourcePropFlags&ast.ModifierFlagsPrivate != 0 && targetPropFlags&ast.ModifierFlagsPrivate != 0 { r.reportError(diagnostics.Types_have_separate_declarations_of_a_private_property_0, r.c.symbolToString(targetProp)) @@ -4347,7 +4347,7 @@ func (r *Relater) propertyRelatedTo(source *Type, target *Type, sourceProp *ast. return TernaryFalse } // When checking for comparability, be more lenient with optional properties. - if !skipOptional && sourceProp.Flags&ast.SymbolFlagsOptional != 0 && targetProp.Flags&ast.SymbolFlagsClassMember != 0 && targetProp.Flags&ast.SymbolFlagsOptional == 0 { + if !skipOptional && sourceProp.Flags()&ast.SymbolFlagsOptional != 0 && targetProp.Flags()&ast.SymbolFlagsClassMember != 0 && targetProp.Flags()&ast.SymbolFlagsOptional == 0 { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... // S' and T are object types and, for each member M in T.. @@ -4364,7 +4364,7 @@ func (r *Relater) propertyRelatedTo(source *Type, target *Type, sourceProp *ast. } func (r *Relater) isPropertySymbolTypeRelated(sourceProp *ast.Symbol, targetProp *ast.Symbol, getTypeOfSourceProperty func(sym *ast.Symbol) *Type, reportErrors bool, intersectionState IntersectionState) Ternary { - targetIsOptional := r.c.strictNullChecks && targetProp.CheckFlags&ast.CheckFlagsPartial != 0 + targetIsOptional := r.c.strictNullChecks && targetProp.CheckFlags()&ast.CheckFlagsPartial != 0 effectiveTarget := r.c.addOptionalityEx(r.c.getNonMissingTypeOfSymbol(targetProp), false /*isProperty*/, targetIsOptional) // source could resolve to `any` and that's not related to `unknown` target under strict subtype relation if effectiveTarget.flags&core.IfElse(r.relation == r.c.strictSubtypeRelation, TypeFlagsAny, TypeFlagsAnyOrUnknown) != 0 { @@ -4376,12 +4376,12 @@ func (r *Relater) isPropertySymbolTypeRelated(sourceProp *ast.Symbol, targetProp func (r *Relater) reportUnmatchedProperty(source *Type, target *Type, unmatchedProperty *ast.Symbol, requireOptionalProperties bool) { // give specific error in case where private names have the same description - if unmatchedProperty.ValueDeclaration != nil && - unmatchedProperty.ValueDeclaration.Name() != nil && - ast.IsPrivateIdentifier(unmatchedProperty.ValueDeclaration.Name()) && + if unmatchedProperty.ValueDeclaration() != nil && + unmatchedProperty.ValueDeclaration().Name() != nil && + ast.IsPrivateIdentifier(unmatchedProperty.ValueDeclaration().Name()) && source.symbol != nil && - source.symbol.Flags&ast.SymbolFlagsClass != 0 { - privateIdentifierDescription := unmatchedProperty.ValueDeclaration.Name().Text() + source.symbol.Flags()&ast.SymbolFlagsClass != 0 { + privateIdentifierDescription := unmatchedProperty.ValueDeclaration().Name().Text() symbolTableKey := binder.GetSymbolNameForPrivateIdentifier(source.symbol, privateIdentifierDescription) if r.c.getPropertyOfType(source, symbolTableKey) != nil { r.reportError(diagnostics.Property_0_in_type_1_refers_to_a_different_member_that_cannot_be_accessed_from_within_type_2, privateIdentifierDescription, r.c.SymbolToString(source.symbol), r.c.SymbolToString(target.symbol)) @@ -4393,8 +4393,8 @@ func (r *Relater) reportUnmatchedProperty(source *Type, target *Type, unmatchedP sourceType, targetType := r.c.getTypeNamesForErrorDisplay(source, target) propName := r.c.symbolToString(unmatchedProperty) r.reportError(diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2, propName, sourceType, targetType) - if len(unmatchedProperty.Declarations) != 0 { - r.relatedInfo = append(r.relatedInfo, createDiagnosticForNode(unmatchedProperty.Declarations[0], diagnostics.X_0_is_declared_here, propName)) + if len(unmatchedProperty.Declarations()) != 0 { + r.relatedInfo = append(r.relatedInfo, createDiagnosticForNode(unmatchedProperty.Declarations()[0], diagnostics.X_0_is_declared_here, propName)) } } else if r.tryElaborateArrayLikeErrors(source, target, false /*reportErrors*/) { sourceType, targetType := r.c.getTypeNamesForErrorDisplay(source, target) @@ -4457,7 +4457,7 @@ func (r *Relater) propertiesIdenticalTo(source *Type, target *Type, excludedProp } result := TernaryTrue for _, sourceProp := range sourceProperties { - targetProp := r.c.getPropertyOfObjectType(target, sourceProp.Name) + targetProp := r.c.getPropertyOfObjectType(target, sourceProp.Name()) if targetProp == nil { return TernaryFalse } @@ -4658,7 +4658,7 @@ func (c *Checker) isObjectTypeWithInferableIndex(t *Type) bool { return core.Every(t.Types(), c.isObjectTypeWithInferableIndex) } return t.symbol != nil && - t.symbol.Flags&(ast.SymbolFlagsObjectLiteral|ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule) != 0 && t.symbol.Flags&ast.SymbolFlagsClass == 0 && !c.typeHasCallOrConstructSignatures(t) || + t.symbol.Flags()&(ast.SymbolFlagsObjectLiteral|ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsEnum|ast.SymbolFlagsValueModule) != 0 && t.symbol.Flags()&ast.SymbolFlagsClass == 0 && !c.typeHasCallOrConstructSignatures(t) || t.objectFlags&(ObjectFlagsJSLiteral|ObjectFlagsObjectRestType) != 0 || t.objectFlags&ObjectFlagsReverseMapped != 0 && c.isObjectTypeWithInferableIndex(t.AsReverseMappedType().source) } @@ -4680,7 +4680,7 @@ func (r *Relater) membersRelatedToIndexInfo(source *Type, targetInfo *IndexInfo, if r.c.isApplicableIndexType(r.c.getLiteralTypeFromProperty(prop, TypeFlagsStringOrNumberLiteralOrUnique, false), keyType) { propType := r.c.getNonMissingTypeOfSymbol(prop) var t *Type - if r.c.exactOptionalPropertyTypes || propType.flags&TypeFlagsUndefined != 0 || keyType == r.c.numberType || prop.Flags&ast.SymbolFlagsOptional == 0 { + if r.c.exactOptionalPropertyTypes || propType.flags&TypeFlagsUndefined != 0 || keyType == r.c.numberType || prop.Flags()&ast.SymbolFlagsOptional == 0 { t = propType } else { t = r.c.getTypeWithFacts(propType, TypeFactsNEUndefined) @@ -4770,12 +4770,12 @@ func (r *Relater) reportErrorResults(originalSource *Type, originalTarget *Type, } } r.reportRelationError(headMessage, source, target) - if source.flags&TypeFlagsTypeParameter != 0 && source.symbol != nil && len(source.symbol.Declarations) != 0 && r.c.getConstraintOfType(source) == nil { + if source.flags&TypeFlagsTypeParameter != 0 && source.symbol != nil && len(source.symbol.Declarations()) != 0 && r.c.getConstraintOfType(source) == nil { syntheticParam := r.c.cloneTypeParameter(source) syntheticParam.AsTypeParameter().constraint = r.c.instantiateType(target, newSimpleTypeMapper(source, syntheticParam)) if r.c.hasNonCircularBaseConstraint(syntheticParam) { targetConstraintString := r.c.TypeToString(target) - r.relatedInfo = append(r.relatedInfo, NewDiagnosticForNode(source.symbol.Declarations[0], diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString)) + r.relatedInfo = append(r.relatedInfo, NewDiagnosticForNode(source.symbol.Declarations()[0], diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString)) } } } diff --git a/tsc/internal/checker/services.go b/tsc/internal/checker/services.go index 73d70a79293c7..cdcb404ba271d 100644 --- a/tsc/internal/checker/services.go +++ b/tsc/internal/checker/services.go @@ -30,7 +30,7 @@ func (c *Checker) getSymbolsInScope(location *ast.Node, meaning ast.SymbolFlags) // and it doesn't already exists in the symbol table. copySymbol := func(symbol *ast.Symbol, meaning ast.SymbolFlags) { if symbol.CombinedLocalAndExportSymbolFlags()&meaning != 0 { - id := symbol.Name + id := symbol.Name() // We will copy all symbol regardless of its reserved name because // symbolsToArray will check whether the key is a reserved name and // it will not copy symbol with reserved name to the array @@ -54,7 +54,7 @@ func (c *Checker) getSymbolsInScope(location *ast.Node, meaning ast.SymbolFlags) // Similar condition as in `resolveNameHelper` if ast.GetDeclarationOfKind(symbol, ast.KindExportSpecifier) == nil && ast.GetDeclarationOfKind(symbol, ast.KindNamespaceExport) == nil && - symbol.Name != ast.InternalSymbolNameDefault { + symbol.Name() != ast.InternalSymbolNameDefault { copySymbol(symbol, meaning) } } @@ -84,9 +84,9 @@ func (c *Checker) getSymbolsInScope(location *ast.Node, meaning ast.SymbolFlags) } fallthrough case ast.KindModuleDeclaration: - copyLocallyVisibleExportSymbols(c.getSymbolOfDeclaration(location).Exports, meaning&ast.SymbolFlagsModuleMember) + copyLocallyVisibleExportSymbols(c.getSymbolOfDeclaration(location).Exports(), meaning&ast.SymbolFlagsModuleMember) case ast.KindEnumDeclaration: - copySymbols(c.getSymbolOfDeclaration(location).Exports, meaning&ast.SymbolFlagsEnumMember) + copySymbols(c.getSymbolOfDeclaration(location).Exports(), meaning&ast.SymbolFlagsEnumMember) case ast.KindClassExpression: className := location.AsClassExpression().Name() if className != nil { @@ -216,11 +216,11 @@ func (c *Checker) GetAllPossiblePropertiesOfTypes(types []*Type) []*ast.Symbol { for _, memberType := range types { augmentedProps := c.getAugmentedPropertiesOfType(memberType) for _, p := range augmentedProps { - if _, ok := props[p.Name]; !ok { - prop := c.createUnionOrIntersectionProperty(unionType, p.Name, false /*skipObjectFunctionPropertyAugment*/) + if _, ok := props[p.Name()]; !ok { + prop := c.createUnionOrIntersectionProperty(unionType, p.Name(), false /*skipObjectFunctionPropertyAugment*/) // May be undefined if the property is private if prop != nil { - props[p.Name] = prop + props[p.Name()] = prop } } } @@ -284,8 +284,8 @@ func (c *Checker) getAugmentedPropertiesOfType(t *Type) []*ast.Symbol { } if functionType != nil { for _, p := range c.getPropertiesOfType(functionType) { - if _, ok := propsByName[p.Name]; !ok { - propsByName[p.Name] = p + if _, ok := propsByName[p.Name()]; !ok { + propsByName[p.Name()] = p } } } @@ -393,7 +393,7 @@ func (c *Checker) runWithoutResolvedSignatureCaching[T any](node *ast.Node, fn f } func (c *Checker) SkipAlias(symbol *ast.Symbol) *ast.Symbol { - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { return c.GetAliasedSymbol(symbol) } return symbol @@ -419,15 +419,15 @@ func (c *Checker) GetMappedTypeSymbolOfProperty(symbol *ast.Symbol) *ast.Symbol } func (c *Checker) getImmediateRootSymbols(symbol *ast.Symbol) []*ast.Symbol { - if symbol.CheckFlags&ast.CheckFlagsSynthetic != 0 { + if symbol.CheckFlags()&ast.CheckFlagsSynthetic != 0 { return core.MapNonNil( c.valueSymbolLinks.Get(symbol).containingType.Types(), func(t *Type) *ast.Symbol { - return c.getPropertyOfType(t, symbol.Name) + return c.getPropertyOfType(t, symbol.Name()) }, ) } - if symbol.Flags&ast.SymbolFlagsTransient != 0 { + if symbol.Flags()&ast.SymbolFlagsTransient != 0 { if c.spreadLinks.Has(symbol) { leftSpread := c.spreadLinks.Get(symbol).leftSpread rightSpread := c.spreadLinks.Get(symbol).rightSpread @@ -469,7 +469,7 @@ func (c *Checker) tryGetTarget(symbol *ast.Symbol) *ast.Symbol { } func (c *Checker) GetExportSymbolOfSymbol(symbol *ast.Symbol) *ast.Symbol { - return c.getMergedSymbol(core.IfElse(symbol.ExportSymbol != nil, symbol.ExportSymbol, symbol)) + return c.getMergedSymbol(core.IfElse(symbol.ExportSymbol() != nil, symbol.ExportSymbol(), symbol)) } func (c *Checker) GetExportSpecifierLocalTargetSymbol(node *ast.Node) *ast.Symbol { @@ -587,7 +587,7 @@ func (c *Checker) GetReferencesToSymbolInFile( sourceFile *ast.SourceFile, symbol *ast.Symbol, ) []*ast.Node { - identifierText := symbol.Name + identifierText := symbol.Name() var result []*ast.Node for _, token := range getPossibleSymbolReferenceNodes(sourceFile, identifierText, sourceFile.AsNode()) { if !ast.IsIdentifier(token) { @@ -884,9 +884,9 @@ func (c *Checker) GetConstantValue(node *ast.Node) any { nil, /*location*/ ) } - if symbol != nil && symbol.Flags&ast.SymbolFlagsEnumMember != 0 { + if symbol != nil && symbol.Flags()&ast.SymbolFlagsEnumMember != 0 { // inline property\index accesses only for const enums - member := symbol.ValueDeclaration + member := symbol.ValueDeclaration() if ast.IsEnumConst(member.Parent) { return c.getEnumMemberValue(member).Value } @@ -1005,14 +1005,14 @@ func isKnownGenericTypeName(name string) bool { } func (c *Checker) GetFirstTypeArgumentFromKnownType(t *Type) *Type { - if t.objectFlags&ObjectFlagsReference != 0 && t.symbol != nil && isKnownGenericTypeName(t.symbol.Name) { - symbol := c.getGlobalSymbol(t.symbol.Name, ast.SymbolFlagsType, nil) + if t.objectFlags&ObjectFlagsReference != 0 && t.symbol != nil && isKnownGenericTypeName(t.symbol.Name()) { + symbol := c.getGlobalSymbol(t.symbol.Name(), ast.SymbolFlagsType, nil) if symbol != nil && symbol == t.Target().symbol { return core.FirstOrNil(c.getTypeArguments(t)) } } - if t.alias != nil && isKnownGenericTypeName(t.alias.symbol.Name) { - symbol := c.getGlobalSymbol(t.alias.symbol.Name, ast.SymbolFlagsType, nil) + if t.alias != nil && isKnownGenericTypeName(t.alias.symbol.Name()) { + symbol := c.getGlobalSymbol(t.alias.symbol.Name(), ast.SymbolFlagsType, nil) if symbol != nil && symbol == t.alias.symbol { return core.FirstOrNil(t.alias.typeArguments) } @@ -1124,7 +1124,7 @@ func (c *Checker) IsLibSymbolForHoverVerbosity(symbol *ast.Symbol) bool { if symbol == nil { return false } - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { sf := ast.GetSourceFileOfNode(decl) if sf != nil && c.program.IsSourceFileDefaultLibrary(sf.PathKey()) { return true diff --git a/tsc/internal/checker/symbolaccessibility.go b/tsc/internal/checker/symbolaccessibility.go index 6115adea5d373..86d1cc0dae146 100644 --- a/tsc/internal/checker/symbolaccessibility.go +++ b/tsc/internal/checker/symbolaccessibility.go @@ -42,7 +42,7 @@ func (c *Checker) IsAnySymbolAccessible(symbols []*ast.Symbol, enclosingDeclarat } } if allowModules { - if core.Some(symbol.Declarations, hasNonGlobalAugmentationExternalModuleSymbol) { + if core.Some(symbol.Declarations(), hasNonGlobalAugmentationExternalModuleSymbol) { if shouldComputeAliasesToMakeVisible { earlyModuleBail = true // Generally speaking, we want to use the aliases that already exist to refer to a module, if present @@ -115,7 +115,7 @@ func getQualifiedLeftMeaning(rightMeaning ast.SymbolFlags) ast.SymbolFlags { } func (c *Checker) getWithAlternativeContainers(container *ast.Symbol, symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) []*ast.Symbol { - additionalContainers := core.MapNonNil(container.Declarations, func(d *ast.Node) *ast.Symbol { + additionalContainers := core.MapNonNil(container.Declarations(), func(d *ast.Node) *ast.Symbol { return c.getFileSymbolIfFileSymbolExportEqualsContainer(d, container) }) var reexportContainers []*ast.Symbol @@ -125,7 +125,7 @@ func (c *Checker) getWithAlternativeContainers(container *ast.Symbol, symbol *as objectLiteralContainer := c.getVariableDeclarationOfObjectLiteral(container, meaning) leftMeaning := getQualifiedLeftMeaning(meaning) if enclosingDeclaration != nil && - container.Flags&leftMeaning != 0 && + container.Flags()&leftMeaning != 0 && len(c.getAccessibleSymbolChain(container, enclosingDeclaration, ast.SymbolFlagsNamespace /*useOnlyExternalAliasing*/, false)) > 0 { // This order expresses a preference for the real container if it is in scope res := append(append([]*ast.Symbol{container}, additionalContainers...), reexportContainers...) @@ -138,13 +138,13 @@ func (c *Checker) getWithAlternativeContainers(container *ast.Symbol, symbol *as // which may be acting like a namespace (eg, `Symbol` acts like a namespace when looking up `Symbol.toStringTag`) var variableMatches []*ast.Symbol if (meaning == ast.SymbolFlagsValue && - container.Flags&leftMeaning == 0) && - container.Flags&ast.SymbolFlagsType != 0 && + container.Flags()&leftMeaning == 0) && + container.Flags()&ast.SymbolFlagsType != 0 && c.getDeclaredTypeOfSymbol(container).flags&TypeFlagsObject != 0 { c.someSymbolTableInScope(enclosingDeclaration, func(t ast.SymbolTable, _ symbolTableID, _ bool, _ bool, _ *ast.Node) bool { found := false for _, s := range t { - if s.Flags&leftMeaning != 0 && c.getTypeOfSymbol(s) == c.getDeclaredTypeOfSymbol(container) { + if s.Flags()&leftMeaning != 0 && c.getTypeOfSymbol(s) == c.getDeclaredTypeOfSymbol(container) { variableMatches = append(variableMatches, s) found = true } @@ -230,10 +230,10 @@ func (c *Checker) getVariableDeclarationOfObjectLiteral(symbol *ast.Symbol, mean if meaning&ast.SymbolFlagsValue == 0 { return nil } - if len(symbol.Declarations) == 0 { + if len(symbol.Declarations()) == 0 { return nil } - firstDecl := symbol.Declarations[0] + firstDecl := symbol.Declarations()[0] if firstDecl.Parent == nil { return nil } @@ -260,10 +260,10 @@ func (c *Checker) getExternalModuleContainer(declaration *ast.Node) *ast.Symbol func (c *Checker) getFileSymbolIfFileSymbolExportEqualsContainer(d *ast.Node, container *ast.Symbol) *ast.Symbol { fileSymbol := c.getExternalModuleContainer(d) - if fileSymbol == nil || fileSymbol.Exports == nil { + if fileSymbol == nil || fileSymbol.Exports() == nil { return nil } - exported, ok := fileSymbol.Exports[ast.InternalSymbolNameExportEquals] + exported, ok := fileSymbol.Exports()[ast.InternalSymbolNameExportEquals] if !ok || exported == nil { return nil } @@ -280,11 +280,11 @@ func (c *Checker) getFileSymbolIfFileSymbolExportEqualsContainer(d *ast.Node, co func (c *Checker) getContainersOfSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) []*ast.Symbol { container := c.getParentOfSymbol(symbol) // Type parameters end up in the `members` lists but are not externally visible - if container != nil && (symbol.Flags&ast.SymbolFlagsTypeParameter == 0) { + if container != nil && (symbol.Flags()&ast.SymbolFlagsTypeParameter == 0) { return c.getWithAlternativeContainers(container, symbol, enclosingDeclaration, meaning) } var candidates []*ast.Symbol - for _, d := range symbol.Declarations { + for _, d := range symbol.Declarations() { if !ast.IsAmbientModule(d) && d.Parent != nil { // direct children of a module if hasNonGlobalAugmentationExternalModuleSymbol(d.Parent) { @@ -346,14 +346,14 @@ func (c *Checker) getAliasForSymbolInContainer(container *ast.Symbol, symbol *as } // Check if container is a thing with an `export=` which points directly at `symbol`, and if so, return // the container itself as the alias for the symbol - if container.Exports != nil { - exportEquals, ok := container.Exports[ast.InternalSymbolNameExportEquals] + if container.Exports() != nil { + exportEquals, ok := container.Exports()[ast.InternalSymbolNameExportEquals] if ok && exportEquals != nil && c.getSymbolIfSameReference(exportEquals, symbol) != nil { return container } } exports := c.getExportsOfSymbol(container) - quick, ok := exports[symbol.Name] + quick, ok := exports[symbol.Name()] if ok && quick != nil && c.getSymbolIfSameReference(quick, symbol) != nil { return quick } @@ -519,7 +519,7 @@ func (c *Checker) getSymbolTableAliases(symbols ast.SymbolTable, tableId symbolT } var aliases []*ast.Symbol for _, sym := range symbols { - if sym.Flags&ast.SymbolFlagsAlias != 0 { + if sym.Flags()&ast.SymbolFlagsAlias != 0 { aliases = append(aliases, sym) } } @@ -541,7 +541,7 @@ func (c *Checker) trySymbolTable( ) []*ast.Symbol { isGlobals := tableId == stKindGlobals // If symbol is directly available by its name in the symbol table - res, ok := symbols[ctx.symbol.Name] + res, ok := symbols[ctx.symbol.Name()] if ok && res != nil && c.isAccessible(ctx, res /*resolvedAliasSymbol*/, nil, ignoreQualification) { return []*ast.Symbol{ctx.symbol} } @@ -551,8 +551,8 @@ func (c *Checker) trySymbolTable( // Check for ExportSymbol by direct name lookup rather than discovering it during // the alias iteration below (where it would never match, since only alias-flagged // symbols are iterated). - if ok && res != nil && res.ExportSymbol != nil { - if c.isAccessible(ctx, c.getMergedSymbol(res.ExportSymbol) /*resolvedAliasSymbol*/, nil, ignoreQualification) { + if ok && res != nil && res.ExportSymbol() != nil { + if c.isAccessible(ctx, c.getMergedSymbol(res.ExportSymbol()) /*resolvedAliasSymbol*/, nil, ignoreQualification) { candidateChains = append(candidateChains, []*ast.Symbol{ctx.symbol}) } } @@ -561,13 +561,13 @@ func (c *Checker) trySymbolTable( // This avoids iterating thousands of non-alias symbols in large tables like globals. for _, symbolFromSymbolTable := range c.getSymbolTableAliases(symbols, tableId) { // for every non-default, non-export= alias symbol in scope, check if it refers to or can chain to the target symbol - if symbolFromSymbolTable.Name != ast.InternalSymbolNameExportEquals && - symbolFromSymbolTable.Name != ast.InternalSymbolNameDefault && + if symbolFromSymbolTable.Name() != ast.InternalSymbolNameExportEquals && + symbolFromSymbolTable.Name() != ast.InternalSymbolNameDefault && !(isUMDExportSymbol(symbolFromSymbolTable) && ctx.enclosingDeclaration != nil && ast.IsExternalModule(ast.GetSourceFileOfNode(ctx.enclosingDeclaration))) && // If `!useOnlyExternalAliasing`, we can use any type of alias to get the name - (!ctx.useOnlyExternalAliasing || core.Some(symbolFromSymbolTable.Declarations, ast.IsExternalModuleImportEqualsDeclaration)) && + (!ctx.useOnlyExternalAliasing || core.Some(symbolFromSymbolTable.Declarations(), ast.IsExternalModuleImportEqualsDeclaration)) && // If we're looking up a local name to reference directly, omit namespace reexports, otherwise when we're trawling through an export list to make a dotted name, we can keep it - (isLocalNameLookup && !core.Some(symbolFromSymbolTable.Declarations, isNamespaceReexportDeclaration) || !isLocalNameLookup) && + (isLocalNameLookup && !core.Some(symbolFromSymbolTable.Declarations(), isNamespaceReexportDeclaration) || !isLocalNameLookup) && // While exports are generally considered to be in scope, export-specifier declared symbols are _not_ // See similar comment in `resolveName` for details (ignoreQualification || len(getDeclarationsOfKind(symbolFromSymbolTable, ast.KindExportSpecifier)) == 0) { @@ -610,7 +610,7 @@ func (c *Checker) compareSymbolChainsWorker(a []*ast.Symbol, b []*ast.Symbol) in } func isUMDExportSymbol(symbol *ast.Symbol) bool { - return symbol != nil && len(symbol.Declarations) > 0 && symbol.Declarations[0] != nil && ast.IsNamespaceExportDeclaration(symbol.Declarations[0]) + return symbol != nil && len(symbol.Declarations()) > 0 && symbol.Declarations()[0] != nil && ast.IsNamespaceExportDeclaration(symbol.Declarations()[0]) } func isNamespaceReexportDeclaration(node *ast.Node) bool { @@ -664,9 +664,9 @@ func (c *Checker) isAccessible( if symbol == c.getMergedSymbol(symbolFromSymbolTable) { likeSymbols = true } - if !likeSymbols && resolvedAliasSymbol != nil && resolvedAliasSymbol.Flags&ast.SymbolFlagsAlias != 0 { + if !likeSymbols && resolvedAliasSymbol != nil && resolvedAliasSymbol.Flags()&ast.SymbolFlagsAlias != 0 { var seenAliases collections.Set[*ast.Symbol] - for resolvedAliasSymbol.Flags&ast.SymbolFlagsAlias != 0 && !seenAliases.Has(resolvedAliasSymbol) { + for resolvedAliasSymbol.Flags()&ast.SymbolFlagsAlias != 0 && !seenAliases.Has(resolvedAliasSymbol) { seenAliases.Add(resolvedAliasSymbol) resolvedAliasSymbol = c.getMergedSymbol(c.resolveAlias(resolvedAliasSymbol)) if symbol == resolvedAliasSymbol { @@ -681,7 +681,7 @@ func (c *Checker) isAccessible( // if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table) // and if symbolFromSymbolTable or alias resolution matches the symbol, // check the symbol can be qualified, it is only then this symbol is accessible - return !core.Some(symbolFromSymbolTable.Declarations, hasNonGlobalAugmentationExternalModuleSymbol) && + return !core.Some(symbolFromSymbolTable.Declarations(), hasNonGlobalAugmentationExternalModuleSymbol) && (ignoreQualification || c.canQualifySymbol(ctx, c.getMergedSymbol(symbolFromSymbolTable), ctx.meaning)) } @@ -693,14 +693,14 @@ func (c *Checker) canQualifySymbol( // If the symbol is equivalent and doesn't need further qualification, this symbol is accessible return !c.needsQualification(symbolFromSymbolTable, ctx.enclosingDeclaration, meaning) || // If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too - len(c.getAccessibleSymbolChainEx(accessibleSymbolChainContext{symbolFromSymbolTable.Parent, ctx.enclosingDeclaration, getQualifiedLeftMeaning(meaning), ctx.useOnlyExternalAliasing, ctx.visitedSymbolTablesMap})) > 0 + len(c.getAccessibleSymbolChainEx(accessibleSymbolChainContext{symbolFromSymbolTable.Parent(), ctx.enclosingDeclaration, getQualifiedLeftMeaning(meaning), ctx.useOnlyExternalAliasing, ctx.visitedSymbolTablesMap})) > 0 } func (c *Checker) needsQualification(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) bool { qualify := false c.someSymbolTableInScope(enclosingDeclaration, func(symbolTable ast.SymbolTable, _ symbolTableID, _ bool, _ bool, _ *ast.Node) bool { // If symbol of this name is not available in the symbol table we are ok - res, ok := symbolTable[symbol.Name] + res, ok := symbolTable[symbol.Name()] if !ok || res == nil { return false } @@ -716,11 +716,11 @@ func (c *Checker) needsQualification(symbol *ast.Symbol, enclosingDeclaration *a } // Qualify if the symbol from symbol table has same meaning as expected - shouldResolveAlias := symbolFromSymbolTable.Flags&ast.SymbolFlagsAlias != 0 && ast.GetDeclarationOfKind(symbolFromSymbolTable, ast.KindExportSpecifier) == nil + shouldResolveAlias := symbolFromSymbolTable.Flags()&ast.SymbolFlagsAlias != 0 && ast.GetDeclarationOfKind(symbolFromSymbolTable, ast.KindExportSpecifier) == nil if shouldResolveAlias { symbolFromSymbolTable = c.resolveAlias(symbolFromSymbolTable) } - flags := symbolFromSymbolTable.Flags + flags := symbolFromSymbolTable.Flags() if shouldResolveAlias { flags = c.getSymbolFlags(symbolFromSymbolTable) } @@ -737,8 +737,8 @@ func (c *Checker) needsQualification(symbol *ast.Symbol, enclosingDeclaration *a } func isPropertyOrMethodDeclarationSymbol(symbol *ast.Symbol) bool { - if len(symbol.Declarations) > 0 { - for _, declaration := range symbol.Declarations { + if len(symbol.Declarations()) > 0 { + for _, declaration := range symbol.Declarations() { switch declaration.Kind { case ast.KindPropertyDeclaration, ast.KindMethodDeclaration, @@ -771,7 +771,7 @@ func (c *Checker) someSymbolTableInScope( break } sym := c.getSymbolOfDeclaration(ast.GetReparsedNodeForNode(location)) - if callback(sym.Exports, symbolTableIDFromExports(sym), false, true, location) { + if callback(sym.Exports(), symbolTableIDFromExports(sym), false, true, location) { return true } case ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration: @@ -785,8 +785,8 @@ func (c *Checker) someSymbolTableInScope( var table ast.SymbolTable sym := c.getSymbolOfDeclaration(location) // TODO: Should this filtered table be cached in some way? - for key, memberSymbol := range sym.Members { - if memberSymbol.Flags&(ast.SymbolFlagsType & ^ast.SymbolFlagsAssignment) != 0 { + for key, memberSymbol := range sym.Members() { + if memberSymbol.Flags()&(ast.SymbolFlagsType & ^ast.SymbolFlagsAssignment) != 0 { if table == nil { table = make(ast.SymbolTable) } @@ -860,7 +860,7 @@ func (c *Checker) isSymbolAccessibleWorker(symbol *ast.Symbol, enclosingDeclarat // This could be a symbol that is not exported in the external module // or it could be a symbol from different external module that is not aliased and hence cannot be named - symbolExternalModule := core.FirstNonNil(symbol.Declarations, c.getExternalModuleContainer) + symbolExternalModule := core.FirstNonNil(symbol.Declarations(), c.getExternalModuleContainer) if symbolExternalModule != nil { enclosingExternalModule := c.getExternalModuleContainer(enclosingDeclaration) if symbolExternalModule != enclosingExternalModule { diff --git a/tsc/internal/checker/symboltracker.go b/tsc/internal/checker/symboltracker.go index 1a1b7ad28bec8..7ee61191feace 100644 --- a/tsc/internal/checker/symboltracker.go +++ b/tsc/internal/checker/symboltracker.go @@ -32,7 +32,7 @@ func (this *SymbolTrackerImpl) TrackSymbol(symbol *ast.Symbol, enclosingDeclarat return true } // Skip recording type parameters as they dont contribute to late painted statements - if symbol.Flags&ast.SymbolFlagsTypeParameter == 0 { + if symbol.Flags()&ast.SymbolFlagsTypeParameter == 0 { this.context.trackedSymbols = append(this.context.trackedSymbols, &TrackedSymbolArgs{symbol, enclosingDeclaration, meaning}) } } diff --git a/tsc/internal/checker/utilities.go b/tsc/internal/checker/utilities.go index 82071d2dde43d..ff729bc30b393 100644 --- a/tsc/internal/checker/utilities.go +++ b/tsc/internal/checker/utilities.go @@ -69,7 +69,7 @@ func hasReadonlyModifier(node *ast.Node) bool { } func isStaticPrivateIdentifierProperty(s *ast.Symbol) bool { - return s.ValueDeclaration != nil && ast.IsPrivateIdentifierClassElementDeclaration(s.ValueDeclaration) && ast.IsStatic(s.ValueDeclaration) + return s.ValueDeclaration() != nil && ast.IsPrivateIdentifierClassElementDeclaration(s.ValueDeclaration()) && ast.IsStatic(s.ValueDeclaration()) } func isEmptyObjectLiteral(expression *ast.Node) bool { @@ -195,7 +195,7 @@ func canHaveLocals(node *ast.Node) bool { } func isShorthandAmbientModuleSymbol(moduleSymbol *ast.Symbol) bool { - return isShorthandAmbientModule(moduleSymbol.ValueDeclaration) + return isShorthandAmbientModule(moduleSymbol.ValueDeclaration()) } func isShorthandAmbientModule(node *ast.Node) bool { @@ -254,7 +254,7 @@ func isSyntacticDefault(node *ast.Node) bool { } func hasExportAssignmentSymbol(moduleSymbol *ast.Symbol) bool { - return moduleSymbol.Exports[ast.InternalSymbolNameExportEquals] != nil + return moduleSymbol.Exports()[ast.InternalSymbolNameExportEquals] != nil } func isTypeAlias(node *ast.Node) bool { @@ -353,7 +353,7 @@ func createSymbolTable(symbols []*ast.Symbol) ast.SymbolTable { } result := make(ast.SymbolTable) for _, symbol := range symbols { - result[symbol.Name] = symbol + result[symbol.Name()] = symbol } return result } @@ -372,16 +372,16 @@ func (c *Checker) compareSymbolsWorker(s1, s2 *ast.Symbol) int { if s2 == nil { return -1 } - if len(s1.Declarations) != 0 && len(s2.Declarations) != 0 { - if r := c.compareNodes(s1.Declarations[0], s2.Declarations[0]); r != 0 { + if len(s1.Declarations()) != 0 && len(s2.Declarations()) != 0 { + if r := c.compareNodes(s1.Declarations()[0], s2.Declarations()[0]); r != 0 { return r } - } else if len(s1.Declarations) != 0 { + } else if len(s1.Declarations()) != 0 { return -1 - } else if len(s2.Declarations) != 0 { + } else if len(s2.Declarations()) != 0 { return 1 } - if r := strings.Compare(s1.Name, s2.Name); r != 0 { + if r := strings.Compare(s1.Name(), s2.Name()); r != 0 { return r } // Fall back to symbol IDs. This is a last resort that should happen only when symbols have @@ -441,11 +441,11 @@ func CompareTypes(t1, t2 *Type) int { // Order other unnamed or identically named object types by symbol. if t1.objectFlags&ObjectFlagsInstantiationExpressionType != 0 && t2.objectFlags&ObjectFlagsInstantiationExpressionType != 0 { var declaration1, declaration2 *ast.Node - if t1.symbol != nil && len(t1.symbol.Declarations) != 0 { - declaration1 = t1.symbol.Declarations[0] + if t1.symbol != nil && len(t1.symbol.Declarations()) != 0 { + declaration1 = t1.symbol.Declarations()[0] } - if t2.symbol != nil && len(t2.symbol.Declarations) != 0 { - declaration2 = t2.symbol.Declarations[0] + if t2.symbol != nil && len(t2.symbol.Declarations()) != 0 { + declaration2 = t2.symbol.Declarations()[0] } // A single instantiation expression can produce multiple types for union constituents, // so compare their source declarations before comparing the shared expression node. @@ -641,7 +641,7 @@ func compareTypeNames(t1, t2 *Type) int { if s2 == nil { return -1 } - if c := strings.Compare(s1.Name, s2.Name); c != 0 { + if c := strings.Compare(s1.Name(), s2.Name()); c != 0 { return c } // Keep distinct same-named declarations together before comparing alias arguments or structure. @@ -759,39 +759,39 @@ func getDeclarationModifierFlagsFromSymbol(s *ast.Symbol) ast.ModifierFlags { } func getDeclarationModifierFlagsFromSymbolEx(s *ast.Symbol, isWrite bool) ast.ModifierFlags { - if s.CheckFlags&ast.CheckFlagsSynthetic != 0 { + if s.CheckFlags()&ast.CheckFlagsSynthetic != 0 { var accessModifier ast.ModifierFlags switch { - case !isWrite && s.CheckFlags&ast.CheckFlagsContainsPublic != 0 || isWrite && s.CheckFlags&ast.CheckFlagsContainsWritePublic != 0: + case !isWrite && s.CheckFlags()&ast.CheckFlagsContainsPublic != 0 || isWrite && s.CheckFlags()&ast.CheckFlagsContainsWritePublic != 0: accessModifier = ast.ModifierFlagsPublic - case !isWrite && s.CheckFlags&ast.CheckFlagsContainsProtected != 0 || isWrite && s.CheckFlags&ast.CheckFlagsContainsWriteProtected != 0: + case !isWrite && s.CheckFlags()&ast.CheckFlagsContainsProtected != 0 || isWrite && s.CheckFlags()&ast.CheckFlagsContainsWriteProtected != 0: accessModifier = ast.ModifierFlagsProtected - case !isWrite && s.CheckFlags&ast.CheckFlagsContainsPrivate != 0 || isWrite && s.CheckFlags&ast.CheckFlagsContainsWritePrivate != 0: + case !isWrite && s.CheckFlags()&ast.CheckFlagsContainsPrivate != 0 || isWrite && s.CheckFlags()&ast.CheckFlagsContainsWritePrivate != 0: accessModifier = ast.ModifierFlagsPrivate } - if s.CheckFlags&ast.CheckFlagsContainsStatic != 0 { + if s.CheckFlags()&ast.CheckFlagsContainsStatic != 0 { return accessModifier | ast.ModifierFlagsStatic } return accessModifier } - if s.ValueDeclaration != nil { + if s.ValueDeclaration() != nil { var declaration *ast.Node if isWrite { - declaration = core.Find(s.Declarations, ast.IsSetAccessorDeclaration) + declaration = core.Find(s.Declarations(), ast.IsSetAccessorDeclaration) } - if declaration == nil && s.Flags&ast.SymbolFlagsGetAccessor != 0 { - declaration = core.Find(s.Declarations, ast.IsGetAccessorDeclaration) + if declaration == nil && s.Flags()&ast.SymbolFlagsGetAccessor != 0 { + declaration = core.Find(s.Declarations(), ast.IsGetAccessorDeclaration) } if declaration == nil { - declaration = s.ValueDeclaration + declaration = s.ValueDeclaration() } flags := ast.GetCombinedModifierFlags(declaration) - if s.Parent != nil && s.Parent.Flags&ast.SymbolFlagsClass != 0 { + if s.Parent() != nil && s.Parent().Flags()&ast.SymbolFlagsClass != 0 { return flags } return flags & ^ast.ModifierFlagsAccessibilityModifier } - if s.Flags&ast.SymbolFlagsPrototype != 0 { + if s.Flags()&ast.SymbolFlagsPrototype != 0 { return ast.ModifierFlagsPublic | ast.ModifierFlagsStatic } return ast.ModifierFlagsNone @@ -1016,14 +1016,14 @@ func isVariableDeclarationInVariableStatement(node *ast.Node) bool { } func IsKnownSymbol(symbol *ast.Symbol) bool { - return isLateBoundName(symbol.Name) + return isLateBoundName(symbol.Name()) } func IsPrivateIdentifierSymbol(symbol *ast.Symbol) bool { if symbol == nil { return false } - return strings.HasPrefix(symbol.Name, ast.InternalSymbolNamePrefix+"#") + return strings.HasPrefix(symbol.Name(), ast.InternalSymbolNamePrefix+"#") } func isLateBoundName(name string) bool { @@ -1081,13 +1081,13 @@ func isInfinityOrNaNString(name string) bool { } func (c *Checker) isConstantVariable(symbol *ast.Symbol) bool { - return symbol.Flags&ast.SymbolFlagsVariable != 0 && (c.getDeclarationNodeFlagsFromSymbol(symbol)&ast.NodeFlagsConstant) != 0 + return symbol.Flags()&ast.SymbolFlagsVariable != 0 && (c.getDeclarationNodeFlagsFromSymbol(symbol)&ast.NodeFlagsConstant) != 0 } func (c *Checker) isParameterOrMutableLocalVariable(symbol *ast.Symbol) bool { // Return true if symbol is a parameter, a catch clause variable, or a mutable local variable - if symbol.ValueDeclaration != nil { - declaration := ast.GetRootDeclaration(symbol.ValueDeclaration) + if symbol.ValueDeclaration() != nil { + declaration := ast.GetRootDeclaration(symbol.ValueDeclaration()) return declaration != nil && (ast.IsParameterDeclaration(declaration) || ast.IsVariableDeclaration(declaration) && (ast.IsCatchClause(declaration.Parent) || c.isMutableLocalVariableDeclaration(declaration))) } return false @@ -1302,7 +1302,7 @@ func getEnclosingContainer(node *ast.Node) *ast.Node { } func getDeclarationsOfKind(symbol *ast.Symbol, kind ast.Kind) []*ast.Node { - return core.Filter(symbol.Declarations, func(d *ast.Node) bool { return d.Kind == kind }) + return core.Filter(symbol.Declarations(), func(d *ast.Node) bool { return d.Kind == kind }) } func hasType(node *ast.Node) bool { @@ -1631,9 +1631,9 @@ func tryGetPropertyAccessOrIdentifierToString(expr *ast.Node) string { } func allDeclarationsInSameSourceFile(symbol *ast.Symbol) bool { - if len(symbol.Declarations) > 1 { + if len(symbol.Declarations()) > 1 { var sourceFile *ast.SourceFile - for i, d := range symbol.Declarations { + for i, d := range symbol.Declarations() { if i == 0 { sourceFile = ast.GetSourceFileOfNode(d) } else if ast.GetSourceFileOfNode(d) != sourceFile { @@ -1698,7 +1698,7 @@ func symbolsToArray(symbols ast.SymbolTable) []*ast.Symbol { } func SkipAlias(symbol *ast.Symbol, checker *Checker) *ast.Symbol { - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { return checker.GetAliasedSymbol(symbol) } return symbol @@ -1780,17 +1780,17 @@ func (c *Checker) isUncheckedJSSuggestion(node *ast.Node, suggestion *ast.Symbol if c.compilerOptions.CheckJs.IsUnknown() && file.CheckJsDirective == nil && (file.ScriptKind == core.ScriptKindJS || file.ScriptKind == core.ScriptKindJSX) { var declarationFile *ast.SourceFile if suggestion != nil { - if firstDeclaration := core.FirstOrNil(suggestion.Declarations); firstDeclaration != nil { + if firstDeclaration := core.FirstOrNil(suggestion.Declarations()); firstDeclaration != nil { declarationFile = ast.GetSourceFileOfNode(firstDeclaration) } } suggestionHasNoExtendsOrDecorators := suggestion == nil || - suggestion.ValueDeclaration == nil || - !ast.IsClassLike(suggestion.ValueDeclaration) || - len(ast.GetExtendsHeritageClauseElements(suggestion.ValueDeclaration)) != 0 || - ast.ClassOrConstructorParameterIsDecorated(false, suggestion.ValueDeclaration) + suggestion.ValueDeclaration() == nil || + !ast.IsClassLike(suggestion.ValueDeclaration()) || + len(ast.GetExtendsHeritageClauseElements(suggestion.ValueDeclaration())) != 0 || + ast.ClassOrConstructorParameterIsDecorated(false, suggestion.ValueDeclaration()) return !(file != declarationFile && declarationFile != nil && ast.IsGlobalSourceFile(declarationFile.AsNode())) && - !(excludeClasses && suggestion != nil && suggestion.Flags&ast.SymbolFlagsClass != 0 && suggestionHasNoExtendsOrDecorators) && + !(excludeClasses && suggestion != nil && suggestion.Flags()&ast.SymbolFlagsClass != 0 && suggestionHasNoExtendsOrDecorators) && !(node != nil && excludeClasses && ast.IsPropertyAccessExpression(node) && node.Expression().Kind == ast.KindThisKeyword && suggestionHasNoExtendsOrDecorators) } } diff --git a/tsc/internal/execute/incremental/affectedfileshandler.go b/tsc/internal/execute/incremental/affectedfileshandler.go index 5f8d918ceea9f..50ca58e8f676b 100644 --- a/tsc/internal/execute/incremental/affectedfileshandler.go +++ b/tsc/internal/execute/incremental/affectedfileshandler.go @@ -230,8 +230,8 @@ func (h *affectedFilesHandler) handleDtsMayChangeOfAffectedFile(dtsMayChange dts var done func() // If exported const enum, we need to ensure that js files are emitted as well since the const enum value changed if affectedFile.Symbol != nil { - for _, exported := range affectedFile.Symbol.Exports { - if exported.Flags&ast.SymbolFlagsConstEnum != 0 { + for _, exported := range affectedFile.Symbol.Exports() { + if exported.Flags()&ast.SymbolFlagsConstEnum != 0 { invalidateJsFiles = true break } @@ -242,8 +242,8 @@ func (h *affectedFilesHandler) handleDtsMayChangeOfAffectedFile(dtsMayChange dts if aliased == exported { continue } - if (aliased.Flags & ast.SymbolFlagsConstEnum) != 0 { - if slices.ContainsFunc(aliased.Declarations, func(d *ast.Node) bool { + if (aliased.Flags() & ast.SymbolFlagsConstEnum) != 0 { + if slices.ContainsFunc(aliased.Declarations(), func(d *ast.Node) bool { return ast.GetSourceFileOfNode(d) == affectedFile }) { invalidateJsFiles = true diff --git a/tsc/internal/execute/incremental/programtosnapshot.go b/tsc/internal/execute/incremental/programtosnapshot.go index 3470c2dc41082..b817bc44d5b76 100644 --- a/tsc/internal/execute/incremental/programtosnapshot.go +++ b/tsc/internal/execute/incremental/programtosnapshot.go @@ -261,7 +261,7 @@ func addReferencedFilesFromSymbol(file *ast.SourceFile, referencedFiles *collect if symbol == nil { return } - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { fileOfDecl := ast.GetSourceFileOfNode(declaration) if fileOfDecl == nil { continue diff --git a/tsc/internal/ls/autoimport/export.go b/tsc/internal/ls/autoimport/export.go index c0c82fb341d14..4ed8512b05327 100644 --- a/tsc/internal/ls/autoimport/export.go +++ b/tsc/internal/ls/autoimport/export.go @@ -141,14 +141,14 @@ func (e *Export) IsUnresolvedAlias() bool { } func SymbolToExport(symbol *ast.Symbol, ch *checker.Checker) *Export { - if symbol.Parent != nil && checker.IsExternalModuleSymbol(symbol.Parent) { - if moduleID, moduleFileName, ok := tryGetModuleIDAndFileNameOfModuleSymbol(symbol.Parent); ok { - return extractFirstExport(symbol, ch, moduleID, moduleFileName, ast.GetSourceFileOfModule(symbol.Parent)) + if symbol.Parent() != nil && checker.IsExternalModuleSymbol(symbol.Parent()) { + if moduleID, moduleFileName, ok := tryGetModuleIDAndFileNameOfModuleSymbol(symbol.Parent()); ok { + return extractFirstExport(symbol, ch, moduleID, moduleFileName, ast.GetSourceFileOfModule(symbol.Parent())) } return nil } - declaration := core.FirstOrNil(symbol.Declarations) + declaration := core.FirstOrNil(symbol.Declarations()) if declaration == nil { return nil } @@ -169,7 +169,7 @@ func SymbolToExport(symbol *ast.Symbol, ch *checker.Checker) *Export { if export := tryGetModuleExport(ast.InternalSymbolNameExportEquals, target, moduleSymbol, ch, moduleID, moduleFileName, file); export != nil { return export } - return tryGetModuleExport(symbol.Name, target, moduleSymbol, ch, moduleID, moduleFileName, file) + return tryGetModuleExport(symbol.Name(), target, moduleSymbol, ch, moduleID, moduleFileName, file) } func tryGetModuleExport(exportName string, target *ast.Symbol, moduleSymbol *ast.Symbol, ch *checker.Checker, moduleID ModuleID, moduleFileName tspath.RootedFilePath, file *ast.SourceFile) *Export { @@ -183,6 +183,6 @@ func tryGetModuleExport(exportName string, target *ast.Symbol, moduleSymbol *ast func extractFirstExport(symbol *ast.Symbol, ch *checker.Checker, moduleID ModuleID, moduleFileName tspath.RootedFilePath, file *ast.SourceFile) *Export { var exports []*Export extractor := newSymbolExtractor("", ch, tspath.CaseInsensitive, nil) - extractor.extractFromSymbol(symbol.Name, symbol, moduleID, moduleFileName, file, &exports) + extractor.extractFromSymbol(symbol.Name(), symbol, moduleID, moduleFileName, file, &exports) return core.FirstOrNil(exports) } diff --git a/tsc/internal/ls/autoimport/extract.go b/tsc/internal/ls/autoimport/extract.go index 08a5a5b459857..12ea044255167 100644 --- a/tsc/internal/ls/autoimport/extract.go +++ b/tsc/internal/ls/autoimport/extract.go @@ -111,7 +111,7 @@ func (e *exportExtractor) extractFromFile(file *ast.SourceFile) []*Export { var exportCount int for _, statement := range file.Statements.Nodes { if ast.IsModuleWithStringLiteralName(statement) && isNonPatternAmbientModuleDeclaration(file, statement.AsModuleDeclaration()) { - exportCount += len(statement.AsModuleDeclaration().Symbol.Exports) + exportCount += len(statement.AsModuleDeclaration().Symbol.Exports()) } } exports := make([]*Export, 0, exportCount) @@ -144,11 +144,11 @@ func (e *exportExtractor) extractFromModule(file *ast.SourceFile) []*Export { }) var augmentationExportCount int for _, decl := range moduleAugmentations { - augmentationExportCount += len(decl.Symbol.Exports) + augmentationExportCount += len(decl.Symbol.Exports()) } moduleID := e.getModuleID(file) - exports := make([]*Export, 0, len(file.Symbol.Exports)+augmentationExportCount) - for name, symbol := range file.Symbol.Exports { + exports := make([]*Export, 0, len(file.Symbol.Exports())+augmentationExportCount) + for name, symbol := range file.Symbol.Exports() { e.extractFromSymbol(name, symbol, moduleID, file.FileName(), file, &exports) } for _, decl := range moduleAugmentations { @@ -176,7 +176,7 @@ func (e *exportExtractor) extractFromModule(file *ast.SourceFile) []*Export { } func (e *exportExtractor) extractFromModuleDeclaration(decl *ast.ModuleDeclaration, file *ast.SourceFile, moduleID ModuleID, moduleFileName tspath.RootedFilePath, exports *[]*Export) { - for name, symbol := range decl.Symbol.Exports { + for name, symbol := range decl.Symbol.Exports() { e.extractFromSymbol(name, symbol, moduleID, moduleFileName, file, exports) } } @@ -188,10 +188,10 @@ func (e *symbolExtractor) extractFromSymbol(name string, symbol *ast.Symbol, mod if name == ast.InternalSymbolNameExportStar { checkerLease := &checkerLease{checker: e.checker} - allExports := e.checker.GetExportsOfModule(symbol.Parent) + allExports := e.checker.GetExportsOfModule(symbol.Parent()) // allExports includes named exports from the file that will be processed separately; // we want to add only the ones that come from the star - for name, namedExport := range symbol.Parent.Exports { + for name, namedExport := range symbol.Parent().Exports() { if name != ast.InternalSymbolNameExportStar { idx := slices.Index(allExports, namedExport) if idx >= 0 || shouldIgnoreSymbol(namedExport) { @@ -204,11 +204,11 @@ func (e *symbolExtractor) extractFromSymbol(name string, symbol *ast.Symbol, mod for _, reexportedSymbol := range allExports { export, _ := e.createExport(reexportedSymbol, moduleID, moduleFileName, ExportSyntaxStar, file, checkerLease) if export != nil { - parent := checkerLease.GetChecker().GetMergedSymbol(reexportedSymbol.Parent) + parent := checkerLease.GetChecker().GetMergedSymbol(reexportedSymbol.Parent()) if parent != nil && parent.IsExternalModule() { if targetModuleID, ok := e.getModuleIDForSymbol(parent); ok { export.Target = ExportID{ - ExportName: reexportedSymbol.Name, + ExportName: reexportedSymbol.Name(), ModuleID: targetModuleID, } } @@ -230,9 +230,9 @@ func (e *symbolExtractor) extractFromSymbol(name string, symbol *ast.Symbol, mod *exports = append(*exports, export) if target != nil { - if syntax == ExportSyntaxEquals && target.Flags&ast.SymbolFlagsNamespace != 0 { - *exports = slices.Grow(*exports, len(target.Exports)) - for innerName, namedExport := range target.Exports { + if syntax == ExportSyntaxEquals && target.Flags()&ast.SymbolFlagsNamespace != 0 { + *exports = slices.Grow(*exports, len(target.Exports())) + for innerName, namedExport := range target.Exports() { if innerName != ast.InternalSymbolNameExportStar { export, _ := e.createExport(namedExport, moduleID, moduleFileName, syntax, file, checkerLease) if export != nil { @@ -243,7 +243,7 @@ func (e *symbolExtractor) extractFromSymbol(name string, symbol *ast.Symbol, mod } } } else if syntax == ExportSyntaxCommonJSModuleExports { - expression := symbol.Declarations[0].AsBinaryExpression().Right + expression := symbol.Declarations()[0].AsBinaryExpression().Right if expression.Kind == ast.KindObjectLiteralExpression { // what is actually desirable here? I think it would be reasonable to only treat these as exports // if *every* property is a shorthand property or identifier: identifier @@ -251,7 +251,7 @@ func (e *symbolExtractor) extractFromSymbol(name string, symbol *ast.Symbol, mod *exports = slices.Grow(*exports, len(expression.AsObjectLiteralExpression().Properties.Nodes)) for _, prop := range expression.AsObjectLiteralExpression().Properties.Nodes { if ast.IsShorthandPropertyAssignment(prop) || ast.IsPropertyAssignment(prop) && prop.AsPropertyAssignment().Name().Kind == ast.KindIdentifier { - export, _ := e.createExport(expression.Symbol().Members[prop.Name().Text()], moduleID, moduleFileName, syntax, file, checkerLease) + export, _ := e.createExport(expression.Symbol().Members()[prop.Name().Text()], moduleID, moduleFileName, syntax, file, checkerLease) if export != nil { export.through = name *exports = append(*exports, export) @@ -269,7 +269,7 @@ func (e *symbolExtractor) createExport(symbol *ast.Symbol, moduleID ModuleID, mo } export := &Export{ - ExportName: symbol.Name, + ExportName: symbol.Name(), ModuleID: moduleID, ModuleFileName: moduleFileName, Syntax: syntax, @@ -280,37 +280,37 @@ func (e *symbolExtractor) createExport(symbol *ast.Symbol, moduleID ModuleID, mo if syntax == ExportSyntaxUMD { export.ExportName = ast.InternalSymbolNameExportEquals - export.localName = symbol.Name + export.localName = symbol.Name() } var targetSymbol *ast.Symbol - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { targetSymbol = e.tryResolveSymbol(symbol, syntax, checkerLease) if targetSymbol != nil { var decl *ast.Node - if len(targetSymbol.Declarations) > 0 { - decl = targetSymbol.Declarations[0] - } else if targetSymbol.CheckFlags&ast.CheckFlagsMapped != 0 { - if mappedDecl := checkerLease.GetChecker().GetMappedTypeSymbolOfProperty(targetSymbol); mappedDecl != nil && len(mappedDecl.Declarations) > 0 { - decl = mappedDecl.Declarations[0] + if len(targetSymbol.Declarations()) > 0 { + decl = targetSymbol.Declarations()[0] + } else if targetSymbol.CheckFlags()&ast.CheckFlagsMapped != 0 { + if mappedDecl := checkerLease.GetChecker().GetMappedTypeSymbolOfProperty(targetSymbol); mappedDecl != nil && len(mappedDecl.Declarations()) > 0 { + decl = mappedDecl.Declarations()[0] } } if decl == nil { // !!! consider GetImmediateAliasedSymbol to go as far as we can - decl = symbol.Declarations[0] + decl = symbol.Declarations()[0] } if decl == nil { panic("no declaration for aliased symbol") } - parent := targetSymbol.Parent + parent := targetSymbol.Parent() if checker := checkerLease.TryChecker(); checker != nil { export.Flags = checker.GetSymbolFlags(targetSymbol) export.IsTypeOnly = checker.GetTypeOnlyAliasDeclaration(symbol) != nil parent = checker.GetMergedSymbol(parent) } else { - export.Flags = targetSymbol.Flags - export.IsTypeOnly = core.Some(symbol.Declarations, ast.IsPartOfTypeOnlyImportOrExportDeclaration) + export.Flags = targetSymbol.Flags() + export.IsTypeOnly = core.Some(symbol.Declarations(), ast.IsPartOfTypeOnlyImportOrExportDeclaration) } export.ScriptElementKind = lsutil.GetSymbolKind(checkerLease.TryChecker(), targetSymbol, decl) export.ScriptElementKindModifiers = lsutil.GetSymbolModifiers(checkerLease.TryChecker(), targetSymbol) @@ -321,16 +321,16 @@ func (e *symbolExtractor) createExport(symbol *ast.Symbol, moduleID ModuleID, mo } } export.Target = ExportID{ - ExportName: targetSymbol.Name, + ExportName: targetSymbol.Name(), ModuleID: targetModuleID, } } } else { - export.ScriptElementKind = lsutil.GetSymbolKind(checkerLease.TryChecker(), symbol, symbol.Declarations[0]) + export.ScriptElementKind = lsutil.GetSymbolKind(checkerLease.TryChecker(), symbol, symbol.Declarations()[0]) export.ScriptElementKindModifiers = lsutil.GetSymbolModifiers(checkerLease.TryChecker(), symbol) } - if symbol.Name == ast.InternalSymbolNameDefault || symbol.Name == ast.InternalSymbolNameExportEquals { + if symbol.Name() == ast.InternalSymbolNameDefault || symbol.Name() == ast.InternalSymbolNameExportEquals { namedSymbol := symbol if s := binder.GetLocalSymbolForExportDefault(symbol); s != nil { namedSymbol = s @@ -386,7 +386,7 @@ func (e *symbolExtractor) tryResolveSymbol(symbol *ast.Symbol, syntax ExportSynt } // !!! check if module.exports = foo is marked as an alias case ExportSyntaxEquals: - if symbol.Name != ast.InternalSymbolNameExportEquals { + if symbol.Name() != ast.InternalSymbolNameExportEquals { break } fallthrough @@ -413,14 +413,14 @@ func (e *symbolExtractor) tryResolveSymbol(symbol *ast.Symbol, syntax ExportSynt } func shouldIgnoreSymbol(symbol *ast.Symbol) bool { - if symbol.Flags&ast.SymbolFlagsPrototype != 0 { + if symbol.Flags()&ast.SymbolFlagsPrototype != 0 { return true } return false } func getSyntax(symbol *ast.Symbol) ExportSyntax { - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { switch decl.Kind { case ast.KindExportSpecifier: return ExportSyntaxNamed @@ -464,8 +464,8 @@ func isUnusableName(name string) bool { // file name, and uses the lowercased moduleID only for ambient modules where no // original file name is available. func fileNameForDefaultExportName(targetSymbol *ast.Symbol, moduleFileName tspath.RootedFilePath, moduleID ModuleID) string { - if targetSymbol != nil && len(targetSymbol.Declarations) > 0 { - if fn := ast.GetSourceFileOfNode(targetSymbol.Declarations[0]).FileName(); fn != "" { + if targetSymbol != nil && len(targetSymbol.Declarations()) > 0 { + if fn := ast.GetSourceFileOfNode(targetSymbol.Declarations()[0]).FileName(); fn != "" { return fn.AsString() } } diff --git a/tsc/internal/ls/autoimport/import_adder.go b/tsc/internal/ls/autoimport/import_adder.go index ca2fd62d80ecd..facc01393ad0b 100644 --- a/tsc/internal/ls/autoimport/import_adder.go +++ b/tsc/internal/ls/autoimport/import_adder.go @@ -463,7 +463,7 @@ func TryGetAutoImportableReferenceFromTypeNode(importTypeNode *ast.TypeNode, idT // If a type checker and multiple files are available, consider using `forEachNameOfDefaultExport` // instead, which searches for names of re-exported defaults/namespaces in target files. func getNameForExportedSymbol(symbol *ast.Symbol, preferCapitalized bool) string { - if symbol.Name == ast.InternalSymbolNameExportEquals || symbol.Name == ast.InternalSymbolNameDefault { + if symbol.Name() == ast.InternalSymbolNameExportEquals || symbol.Name() == ast.InternalSymbolNameDefault { // Names for default exports: // - export default foo => foo // - export { foo as default } => foo @@ -472,10 +472,10 @@ func getNameForExportedSymbol(symbol *ast.Symbol, preferCapitalized bool) string if name != "" { return name } - debug.Assert(symbol.Parent != nil, "Expected exported symbol to have module symbol as parent") - return lsutil.ModuleSymbolToValidIdentifier(symbol.Parent, preferCapitalized) + debug.Assert(symbol.Parent() != nil, "Expected exported symbol to have module symbol as parent") + return lsutil.ModuleSymbolToValidIdentifier(symbol.Parent(), preferCapitalized) } - return symbol.Name + return symbol.Name() } func replaceFirstIdentifierOfEntityName(factory *ast.NodeFactory, name *ast.EntityName, newIdentifier *ast.IdentifierNode) *ast.EntityName { diff --git a/tsc/internal/ls/autoimport/util.go b/tsc/internal/ls/autoimport/util.go index 7194163f16761..73b4461913afc 100644 --- a/tsc/internal/ls/autoimport/util.go +++ b/tsc/internal/ls/autoimport/util.go @@ -115,7 +115,7 @@ func getPackageNamesInNodeModules(nodeModulesDir tspath.RootedDirectoryPath, fs } func getDefaultLikeExportNameFromDeclaration(symbol *ast.Symbol) string { - for _, d := range symbol.Declarations { + for _, d := range symbol.Declarations() { // "export default" in this case. See `ExportAssignment`for more details. if ast.IsExportAssignment(d) { if innerExpression := ast.SkipOuterExpressions(d.Expression(), ast.OEKAll); ast.IsIdentifier(innerExpression) { @@ -124,7 +124,7 @@ func getDefaultLikeExportNameFromDeclaration(symbol *ast.Symbol) string { continue } // "export { ~ as default }" - if ast.IsExportSpecifier(d) && d.Symbol().Flags == ast.SymbolFlagsAlias && d.PropertyName() != nil { + if ast.IsExportSpecifier(d) && d.Symbol().Flags() == ast.SymbolFlagsAlias && d.PropertyName() != nil { if d.PropertyName().Kind == ast.KindIdentifier { return d.PropertyName().Text() } @@ -134,8 +134,8 @@ func getDefaultLikeExportNameFromDeclaration(symbol *ast.Symbol) string { if name := ast.GetNameOfDeclaration(d); name != nil && name.Kind == ast.KindIdentifier { return name.Text() } - if symbol.Parent != nil && !checker.IsExternalModuleSymbol(symbol.Parent) { - return symbol.Parent.Name + if symbol.Parent() != nil && !checker.IsExternalModuleSymbol(symbol.Parent()) { + return symbol.Parent().Name() } } return "" diff --git a/tsc/internal/ls/callhierarchy.go b/tsc/internal/ls/callhierarchy.go index f04de1e0bf85d..4796bcb3b7630 100644 --- a/tsc/internal/ls/callhierarchy.go +++ b/tsc/internal/ls/callhierarchy.go @@ -325,9 +325,9 @@ func findImplementation(c *checker.Checker, node *ast.Node) *ast.Node { if ast.IsFunctionDeclaration(node) || ast.IsMethodDeclaration(node) { symbol := getSymbolOfCallHierarchyDeclaration(c, node) - if symbol != nil && symbol.ValueDeclaration != nil { - if ast.IsFunctionLikeDeclaration(symbol.ValueDeclaration) && symbol.ValueDeclaration.Body() != nil { - return symbol.ValueDeclaration + if symbol != nil && symbol.ValueDeclaration() != nil { + if ast.IsFunctionLikeDeclaration(symbol.ValueDeclaration()) && symbol.ValueDeclaration().Body() != nil { + return symbol.ValueDeclaration() } } return nil @@ -342,7 +342,7 @@ func findAllInitialDeclarations(c *checker.Checker, node *ast.Node) []*ast.Node } symbol := getSymbolOfCallHierarchyDeclaration(c, node) - if symbol == nil || symbol.Declarations == nil { + if symbol == nil || symbol.Declarations() == nil { return nil } @@ -351,12 +351,12 @@ func findAllInitialDeclarations(c *checker.Checker, node *ast.Node) []*ast.Node pos int } - indices := make([]int, len(symbol.Declarations)) + indices := make([]int, len(symbol.Declarations())) for i := range indices { indices[i] = i } - keys := make([]declKey, len(symbol.Declarations)) - for i, decl := range symbol.Declarations { + keys := make([]declKey, len(symbol.Declarations())) + for i, decl := range symbol.Declarations() { keys[i] = declKey{ file: ast.GetSourceFileOfNode(decl).FileName(), pos: decl.Pos(), @@ -374,7 +374,7 @@ func findAllInitialDeclarations(c *checker.Checker, node *ast.Node) []*ast.Node var lastDecl *ast.Node for _, i := range indices { - decl := symbol.Declarations[i] + decl := symbol.Declarations()[i] if isValidCallHierarchyDeclaration(decl) { if lastDecl == nil || lastDecl.Parent != decl.Parent || lastDecl.End() != decl.Pos() { declarations = append(declarations, decl) @@ -482,12 +482,12 @@ func resolveCallHierarchyDeclaration(program *compiler.Program, location *ast.No if !followingSymbol { symbol := c.GetSymbolAtLocation(location) if symbol != nil { - if (symbol.Flags & ast.SymbolFlagsAlias) != 0 { + if (symbol.Flags() & ast.SymbolFlagsAlias) != 0 { symbol = c.GetAliasedSymbol(symbol) } - if symbol.ValueDeclaration != nil { + if symbol.ValueDeclaration() != nil { followingSymbol = true - location = symbol.ValueDeclaration + location = symbol.ValueDeclaration() continue } } diff --git a/tsc/internal/ls/codeactions_fixclassincorrectlyimplementsinterface.go b/tsc/internal/ls/codeactions_fixclassincorrectlyimplementsinterface.go index beb69a6675d09..b91cc1b1c44b4 100644 --- a/tsc/internal/ls/codeactions_fixclassincorrectlyimplementsinterface.go +++ b/tsc/internal/ls/codeactions_fixclassincorrectlyimplementsinterface.go @@ -181,7 +181,7 @@ func getMissingMembers(typeChecker *checker.Checker, classDeclaration *ast.Node, var classMembers ast.SymbolTable if classDeclaration.Symbol() != nil { - classMembers = classDeclaration.Symbol().Members + classMembers = classDeclaration.Symbol().Members() } var missingMembers []*ast.Symbol @@ -190,15 +190,15 @@ func getMissingMembers(typeChecker *checker.Checker, classDeclaration *ast.Node, if symbol == nil { continue } - if classMembers != nil && classMembers[symbol.Name] != nil { + if classMembers != nil && classMembers[symbol.Name()] != nil { continue } - if inheritedMembers[symbol.Name] != nil || seenMembers[symbol.Name] != nil { + if inheritedMembers[symbol.Name()] != nil || seenMembers[symbol.Name()] != nil { continue } flags := checker.GetDeclarationModifierFlagsFromSymbol(symbol) if flags&ast.ModifierFlagsPrivate == 0 { - seenMembers[symbol.Name] = symbol + seenMembers[symbol.Name()] = symbol missingMembers = append(missingMembers, symbol) } } @@ -224,7 +224,7 @@ func getInheritedMembers(typeChecker *checker.Checker, classDeclaration *ast.Nod } flags := checker.GetDeclarationModifierFlagsFromSymbol(symbol) if flags&ast.ModifierFlagsPrivate == 0 { - inheritedMembers[symbol.Name] = symbol + inheritedMembers[symbol.Name()] = symbol } } return inheritedMembers diff --git a/tsc/internal/ls/codeactions_fixmissingtypeannotation.go b/tsc/internal/ls/codeactions_fixmissingtypeannotation.go index 7f25f281c5609..783f2207f78aa 100644 --- a/tsc/internal/ls/codeactions_fixmissingtypeannotation.go +++ b/tsc/internal/ls/codeactions_fixmissingtypeannotation.go @@ -261,11 +261,11 @@ func (f *isolatedDeclarationsFixer) createNamespaceForExpandoProperties(expandoF var newProperties []*ast.Node for _, symbol := range elements { - if !scanner.IsIdentifierText(symbol.Name, core.LanguageVariantStandard) { + if !scanner.IsIdentifierText(symbol.Name(), core.LanguageVariantStandard) { continue } // skip symbols that already have a variable declaration - if symbol.ValueDeclaration != nil && ast.IsVariableDeclaration(symbol.ValueDeclaration) { + if symbol.ValueDeclaration() != nil && ast.IsVariableDeclaration(symbol.ValueDeclaration()) { continue } @@ -275,7 +275,7 @@ func (f *isolatedDeclarationsFixer) createNamespaceForExpandoProperties(expandoF continue } - varDecl := factory.NewVariableDeclaration(factory.NewIdentifier(symbol.Name), nil, typeNode, nil) + varDecl := factory.NewVariableDeclaration(factory.NewIdentifier(symbol.Name()), nil, typeNode, nil) exportToken := factory.NewToken(ast.KindExportKeyword) varDeclList := factory.NewVariableDeclarationList(factory.NewNodeList([]*ast.Node{varDecl}), ast.NodeFlagsNone) varStmt := factory.NewVariableStatement(factory.NewModifierList([]*ast.Node{exportToken}), varDeclList) @@ -523,7 +523,7 @@ func findExpandoFunction(ch *checker.Checker, node *ast.Node) *ast.Node { properties := ch.GetPropertiesOfType(targetType) found := false for _, p := range properties { - if p.ValueDeclaration == expandoDeclaration || p.ValueDeclaration == expandoDeclaration.Parent { + if p.ValueDeclaration() == expandoDeclaration || p.ValueDeclaration() == expandoDeclaration.Parent { found = true break } @@ -533,11 +533,11 @@ func findExpandoFunction(ch *checker.Checker, node *ast.Node) *ast.Node { } symbol := targetType.Symbol() - if symbol == nil || symbol.ValueDeclaration == nil { + if symbol == nil || symbol.ValueDeclaration() == nil { return nil } - fn := symbol.ValueDeclaration + fn := symbol.ValueDeclaration() if (ast.IsFunctionExpression(fn) || ast.IsArrowFunction(fn)) && ast.IsVariableDeclaration(fn.Parent) { return fn.Parent } @@ -1249,7 +1249,7 @@ func typeParamHasDefault(tp *checker.Type) bool { if sym == nil { return false } - for _, decl := range sym.Declarations { + for _, decl := range sym.Declarations() { if ast.IsTypeParameterDeclaration(decl) && decl.AsTypeParameterDeclaration().DefaultType != nil { return true } @@ -1379,13 +1379,13 @@ func getIdentifierNameForNode(node *ast.Node) string { // addSymbolToExistingImport finds the existing import declaration for the symbol's module // and adds the symbol name to the named imports. func (f *isolatedDeclarationsFixer) addSymbolToExistingImport(sym *ast.Symbol) { - if sym == nil || sym.Parent == nil { + if sym == nil || sym.Parent() == nil { return } // Find the module specifier for this symbol - moduleSymbol := sym.Parent - symbolName := sym.Name + moduleSymbol := sym.Parent() + symbolName := sym.Name() // Walk the source file's import declarations to find the one importing from the same module for _, stmt := range f.sourceFile.Statements.Nodes { diff --git a/tsc/internal/ls/codeactions_importfixes.go b/tsc/internal/ls/codeactions_importfixes.go index 49bc0f51c3f76..0055dfc74e4c2 100644 --- a/tsc/internal/ls/codeactions_importfixes.go +++ b/tsc/internal/ls/codeactions_importfixes.go @@ -257,7 +257,7 @@ func getFixesInfoForUMDImport(token *ast.Node, view *autoimport.View, ch *checke } result = append(result, &fixInfo{ fix: fix, - symbolName: umdSymbol.Name, + symbolName: umdSymbol.Name(), errorIdentifierText: errorIdentifierText, }) } @@ -294,9 +294,9 @@ func getUmdSymbol(token *ast.Node, ch *checker.Checker) *ast.Symbol { } func isUMDExportSymbol(symbol *ast.Symbol) bool { - return symbol != nil && len(symbol.Declarations) > 0 && - symbol.Declarations[0] != nil && - ast.IsNamespaceExportDeclaration(symbol.Declarations[0]) + return symbol != nil && len(symbol.Declarations()) > 0 && + symbol.Declarations()[0] != nil && + ast.IsNamespaceExportDeclaration(symbol.Declarations()[0]) } func getFixesInfoForNonUMDImport(fixContext *CodeFixContext, symbolToken *ast.Node, view *autoimport.View, ch *checker.Checker) []*fixInfo { @@ -415,8 +415,8 @@ func needsJsxNamespaceFix(jsxNamespace string, symbolToken *ast.Node, ch *checke if namespaceSymbol == nil { return true } - if slices.ContainsFunc(namespaceSymbol.Declarations, ast.IsTypeOnlyImportOrExportDeclaration) { - return (namespaceSymbol.Flags & ast.SymbolFlagsValue) == 0 + if slices.ContainsFunc(namespaceSymbol.Declarations(), ast.IsTypeOnlyImportOrExportDeclaration) { + return (namespaceSymbol.Flags() & ast.SymbolFlagsValue) == 0 } return false } diff --git a/tsc/internal/ls/codeactions_missingmemberfixer.go b/tsc/internal/ls/codeactions_missingmemberfixer.go index 8368acd005bed..4f1cf6caf0a36 100644 --- a/tsc/internal/ls/codeactions_missingmemberfixer.go +++ b/tsc/internal/ls/codeactions_missingmemberfixer.go @@ -50,13 +50,13 @@ func (f *missingMemberFixer) createNodeBuilder() (*checker.NodeBuilder, map[*ast } func (f *missingMemberFixer) createMemberFromSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, sourceFile *ast.SourceFile, body *ast.FunctionBody, preserveOptional preserveOptionalFlags, abstract bool) []*ast.Node { - declarations := symbol.Declarations + declarations := symbol.Declarations() declaration := core.FirstOrNil(declarations) quotePreference := lsutil.GetQuotePreference(sourceFile, f.preferences) ambient := enclosingDeclaration.Flags&ast.NodeFlagsAmbient != 0 signatureOnly := ambient || abstract - optional := symbol.Flags&ast.SymbolFlagsOptional != 0 + optional := symbol.Flags()&ast.SymbolFlagsOptional != 0 kind := ast.KindPropertySignature if declaration != nil { kind = declaration.Kind @@ -84,7 +84,7 @@ func (f *missingMemberFixer) createMemberFromSymbol(symbol *ast.Symbol, enclosin case ast.KindGetAccessor, ast.KindSetAccessor: nodeBuilder, idToSymbol := f.createNodeBuilder() - accessors := ast.GetAllAccessorDeclarations(symbol.Declarations, declaration) + accessors := ast.GetAllAccessorDeclarations(symbol.Declarations(), declaration) var orderedAccessors []*ast.Node if accessors.SecondAccessor == nil { orderedAccessors = append(orderedAccessors, accessors.FirstAccessor) @@ -325,7 +325,7 @@ func (f *missingMemberFixer) createSignatureDeclarationFromSignatures(signatures maxNonRestArgs := len(maxArgsSignature.Parameters()) - core.IfElse(maxArgsSignature.HasRestParameter(), 1, 0) parameterNames := make([]string, 0, len(maxArgsSignature.Parameters())) for _, symbol := range maxArgsSignature.Parameters() { - parameterNames = append(parameterNames, symbol.Name) + parameterNames = append(parameterNames, symbol.Name()) } parameters := createDummyParameters(f.changeTracker.NodeFactory, maxNonRestArgs, parameterNames, nil /*types*/, minArgumentCount, ast.IsInJSFile(enclosingDeclaration)) @@ -404,7 +404,7 @@ func (f *missingMemberFixer) importTypeNode(typeNode *ast.TypeNode, idToSymbol m func (f *missingMemberFixer) getExportedSymbol(symbol *ast.Symbol) *ast.Symbol { symbol = f.typeChecker.GetExportSymbolOfSymbol(symbol) - if symbol == nil || symbol.Parent == nil { + if symbol == nil || symbol.Parent() == nil { return nil } return symbol @@ -487,7 +487,7 @@ func createDummyParameters(factory *ast.NodeFactory, argCount int, names []strin } func createDeclarationName(factory *ast.NodeFactory, typeChecker *checker.Checker, symbol *ast.Symbol, declaration *ast.Node) *ast.PropertyName { - if symbol != nil && symbol.CheckFlags&ast.CheckFlagsMapped != 0 { + if symbol != nil && symbol.CheckFlags()&ast.CheckFlagsMapped != 0 { nameType := typeChecker.GetNameTypeOfSymbol(symbol) if nameType != nil && checker.IsTypeUsableAsPropertyName(nameType) { return factory.NewIdentifier(checker.GetPropertyNameFromType(nameType)) @@ -497,7 +497,7 @@ func createDeclarationName(factory *ast.NodeFactory, typeChecker *checker.Checke return declaration.Name().Clone(factory) } if symbol != nil { - return factory.NewIdentifier(symbol.Name) + return factory.NewIdentifier(symbol.Name()) } return nil } diff --git a/tsc/internal/ls/completions.go b/tsc/internal/ls/completions.go index ff0f180d5b84d..2bfa4fb9faba9 100644 --- a/tsc/internal/ls/completions.go +++ b/tsc/internal/ls/completions.go @@ -812,7 +812,7 @@ func (l *LanguageService) getCompletionData( // For a computed property with an accessible name like `Symbol.iterator`, // we'll add a completion for the *name* `Symbol` instead of for the property. // If this is e.g. [Symbol.iterator], add a completion for `Symbol`. - computedPropertyName := core.FirstNonNil(symbol.Declarations, func(decl *ast.Node) *ast.Node { + computedPropertyName := core.FirstNonNil(symbol.Declarations(), func(decl *ast.Node) *ast.Node { name := ast.GetNameOfDeclaration(decl) if name != nil && name.Kind == ast.KindComputedPropertyName { return name @@ -838,10 +838,10 @@ func (l *LanguageService) getCompletionData( if firstAccessibleSymbolId != 0 && seenPropertySymbols.AddIfAbsent(firstAccessibleSymbolId) { symbols = append(symbols, firstAccessibleSymbol) symbolToSortTextMap[firstAccessibleSymbolId] = SortTextGlobalsOrKeywords - moduleSymbol := firstAccessibleSymbol.Parent + moduleSymbol := firstAccessibleSymbol.Parent() if moduleSymbol == nil || !checker.IsExternalModuleSymbol(moduleSymbol) || - typeChecker.TryGetMemberInModuleExportsAndProperties(firstAccessibleSymbol.Name, moduleSymbol) != firstAccessibleSymbol { + typeChecker.TryGetMemberInModuleExportsAndProperties(firstAccessibleSymbol.Name(), moduleSymbol) != firstAccessibleSymbol { symbolToOriginInfoMap[len(symbols)-1] = &symbolOriginInfo{kind: getNullableSymbolOriginInfoKind(symbolOriginInfoKindSymbolMember, insertQuestionDot)} } else { // !!! auto-import symbol @@ -927,7 +927,7 @@ func (l *LanguageService) getCompletionData( symbol := typeChecker.GetSymbolAtLocation(node) if symbol != nil { symbol := checker.SkipAlias(symbol, typeChecker) - if symbol.Flags&(ast.SymbolFlagsModule|ast.SymbolFlagsEnum) != 0 { + if symbol.Flags()&(ast.SymbolFlagsModule|ast.SymbolFlagsEnum) != 0 { var valueAccessNode *ast.Node if isImportType { valueAccessNode = node @@ -941,7 +941,7 @@ func (l *LanguageService) getCompletionData( panic("getExporsOfModule() should all be defined") } isValidValueAccess := func(s *ast.Symbol) bool { - return typeChecker.IsValidPropertyAccess(valueAccessNode, s.Name) + return typeChecker.IsValidPropertyAccess(valueAccessNode, s.Name()) } isValidTypeAccess := func(s *ast.Symbol) bool { return symbolCanBeReferencedAtTypeLocation(s, typeChecker, collections.Set[ast.SymbolId]{}) @@ -949,8 +949,8 @@ func (l *LanguageService) getCompletionData( var isValidAccess bool if isNamespaceName { // At `namespace N.M/**/`, if this is the only declaration of `M`, don't include `M` as a completion. - isValidAccess = exportedSymbol.Flags&ast.SymbolFlagsNamespace != 0 && - !core.Every(exportedSymbol.Declarations, func(declaration *ast.Declaration) bool { + isValidAccess = exportedSymbol.Flags()&ast.SymbolFlagsNamespace != 0 && + !core.Every(exportedSymbol.Declarations(), func(declaration *ast.Declaration) bool { return declaration.Parent == node.Parent }) } else if isRhsOfImportDeclaration { @@ -969,7 +969,7 @@ func (l *LanguageService) getCompletionData( // If the module is merged with a value, we must get the type of the class and add its properties (for inherited static methods). if !isTypeLocation && !insideJSDocTagTypeExpression && core.Some( - symbol.Declarations, + symbol.Declarations(), func(decl *ast.Declaration) bool { return decl.Kind != ast.KindSourceFile && decl.Kind != ast.KindModuleDeclaration && decl.Kind != ast.KindEnumDeclaration }, @@ -1051,12 +1051,12 @@ func (l *LanguageService) getCompletionData( existingMemberNames := collections.Set[string]{} for _, member := range existingMembers { - existingMemberNames.Add(member.Name) + existingMemberNames.Add(member.Name()) } symbols = append( symbols, - core.Filter(members, func(member *ast.Symbol) bool { return !existingMemberNames.Has(member.Name) })..., + core.Filter(members, func(member *ast.Symbol) bool { return !existingMemberNames.Has(member.Name()) })..., ) completionKind = CompletionKindObjectPropertyDeclaration @@ -1169,10 +1169,10 @@ func (l *LanguageService) getCompletionData( // Set sort texts. for _, member := range filteredMembers { symbolId := ast.GetSymbolId(member) - if spreadMemberNames.Has(member.Name) { + if spreadMemberNames.Has(member.Name()) { symbolToSortTextMap[symbolId] = SortTextMemberDeclaredBySpreadAssignment } - if member.Flags&ast.SymbolFlagsOptional != 0 { + if member.Flags()&ast.SymbolFlagsOptional != 0 { _, ok := symbolToSortTextMap[symbolId] if !ok { symbolToSortTextMap[symbolId] = SortTextOptionalMember @@ -1405,7 +1405,7 @@ func (l *LanguageService) getCompletionData( localSymbol := localsContainer.Symbol() var localExports ast.SymbolTable if localSymbol != nil { - localExports = localSymbol.Exports + localExports = localSymbol.Exports() } for name, symbol := range localsContainer.Locals() { symbols = append(symbols, symbol) @@ -1509,7 +1509,7 @@ func (l *LanguageService) getCompletionData( symbols = append(symbols, filterClassMembersList(baseSymbols, decl.Members(), classElementModifierFlags, file, position)...) for index, symbol := range symbols { - declaration := symbol.ValueDeclaration + declaration := symbol.ValueDeclaration() if declaration != nil && ast.IsClassElement(declaration) && declaration.Name() != nil && ast.IsComputedPropertyName(declaration.Name()) { @@ -1551,7 +1551,7 @@ func (l *LanguageService) getCompletionData( if spreadMemberNames.Has(ast.SymbolName(symbol)) { symbolToSortTextMap[symbolId] = SortTextMemberDeclaredBySpreadAssignment } - if symbol.Flags&ast.SymbolFlagsOptional != 0 { + if symbol.Flags()&ast.SymbolFlagsOptional != 0 { _, ok := symbolToSortTextMap[symbolId] if !ok { symbolToSortTextMap[symbolId] = SortTextOptionalMember @@ -1627,13 +1627,13 @@ func (l *LanguageService) getCompletionData( for index, symbol := range symbols { symbolId := ast.GetSymbolId(symbol) if !typeChecker.IsArgumentsSymbol(symbol) && - !core.Some(symbol.Declarations, func(decl *ast.Declaration) bool { + !core.Some(symbol.Declarations(), func(decl *ast.Declaration) bool { return ast.GetSourceFileOfNode(decl) == file }) { symbolToSortTextMap[symbolId] = SortTextGlobalsOrKeywords } - if typeOnlyAliasNeedsPromotion && symbol.Flags&ast.SymbolFlagsValue == 0 { - typeOnlyAliasDeclaration := core.Find(symbol.Declarations, ast.IsTypeOnlyImportDeclaration) + if typeOnlyAliasNeedsPromotion && symbol.Flags()&ast.SymbolFlagsValue == 0 { + typeOnlyAliasDeclaration := core.Find(symbol.Declarations(), ast.IsTypeOnlyImportDeclaration) if typeOnlyAliasDeclaration != nil { origin := &symbolOriginInfo{ kind: symbolOriginInfoKindTypeOnlyAlias, @@ -1851,8 +1851,8 @@ func (l *LanguageService) completionInfoFromData( return !tracker.hasValue(literal) }) data.symbols = core.Filter(data.symbols, func(symbol *ast.Symbol) bool { - if symbol.ValueDeclaration != nil && ast.IsEnumMember(symbol.ValueDeclaration) { - value := typeChecker.GetConstantValue(symbol.ValueDeclaration) + if symbol.ValueDeclaration() != nil && ast.IsEnumMember(symbol.ValueDeclaration()) { + value := typeChecker.GetConstantValue(symbol.ValueDeclaration()) if value != nil && tracker.hasValue(value) { return false } @@ -2029,8 +2029,8 @@ func (l *LanguageService) getCompletionEntriesFromSymbols( // True for locals; false for globals, module exports from other files, `this.` completions. shouldShadowLaterSymbols := (origin == nil || originIsTypeOnlyAlias(origin)) && - !(symbol.Parent == nil && - !core.Some(symbol.Declarations, func(d *ast.Node) bool { return ast.GetSourceFileOfNode(d) == file })) + !(symbol.Parent() == nil && + !core.Some(symbol.Declarations(), func(d *ast.Node) bool { return ast.GetSourceFileOfNode(d) == file })) uniques[name] = shouldShadowLaterSymbols var sym *ast.Symbol if includeSymbols { @@ -2499,7 +2499,7 @@ func (l *LanguageService) createObjectLiteralMethod(snippetPrinter *snippetPrint factory := snippetPrinter.factory emitContext := snippetPrinter.emitContext - declaration := core.FirstOrNil(symbol.Declarations) + declaration := core.FirstOrNil(symbol.Declarations()) if !isObjectLiteralMethodCompletionCandidateDeclaration(declaration) { return nil } @@ -2617,7 +2617,7 @@ func (l *LanguageService) collectObjectLiteralMethodSymbols(ctx context.Context, } func isObjectLiteralMethodSymbol(symbol *ast.Symbol) bool { - return symbol.Flags&(ast.SymbolFlagsProperty|ast.SymbolFlagsMethod) != 0 + return symbol.Flags()&(ast.SymbolFlagsProperty|ast.SymbolFlagsMethod) != 0 } func (l *LanguageService) printObjectLiteralMethodLabelDetail(method *ast.Node, file *ast.SourceFile, factory *ast.NodeFactory) string { @@ -2701,7 +2701,7 @@ func (l *LanguageService) getEntryForMemberCompletion(ctx context.Context, typeC } allowedModifiers := modifiers | ast.ModifierFlagsOverride | ast.ModifierFlagsPublic - if symbol.Flags&ast.SymbolFlagsMethod != 0 { + if symbol.Flags()&ast.SymbolFlagsMethod != 0 { allowedModifiers |= ast.ModifierFlagsAsync } else { allowedModifiers |= ast.ModifierFlagsAmbient | ast.ModifierFlagsReadonly @@ -2868,7 +2868,7 @@ func (l *LanguageService) createImportAdder(ctx context.Context, typeChecker *ch func isRecommendedCompletionMatch(localSymbol *ast.Symbol, recommendedCompletion *ast.Symbol, typeChecker *checker.Checker) bool { return localSymbol == recommendedCompletion || - localSymbol.Flags&ast.SymbolFlagsExportValue != 0 && typeChecker.GetExportSymbolOfSymbol(localSymbol) == recommendedCompletion + localSymbol.Flags()&ast.SymbolFlagsExportValue != 0 && typeChecker.GetExportSymbolOfSymbol(localSymbol) == recommendedCompletion } // Ported from vscode. @@ -3050,7 +3050,7 @@ func isClassLikeMemberCompletion(symbol *ast.Symbol, location *ast.Node, file *a return false } memberFlags := ast.SymbolFlagsClassMember & ast.SymbolFlagsEnumMemberExcludes - return symbol.Flags&memberFlags != 0 && + return symbol.Flags()&memberFlags != 0 && (ast.IsClassLike(location) || (location.Parent != nil && location.Parent.Parent != nil && ast.IsClassElement(location.Parent) && location == location.Parent.Name() && lsutil.GetLastToken(location.Parent, file) == location.Parent.Name() && ast.IsClassLike(location.Parent.Parent)) || (location.Parent != nil && ast.IsSyntaxList(location) && ast.IsClassLike(location.Parent))) @@ -3059,7 +3059,7 @@ func isClassLikeMemberCompletion(symbol *ast.Symbol, location *ast.Node, file *a func symbolAppearsToBeTypeOnly(symbol *ast.Symbol, typeChecker *checker.Checker) bool { flags := checker.SkipAlias(symbol, typeChecker).CombinedLocalAndExportSymbolFlags() return flags&ast.SymbolFlagsValue == 0 && - (len(symbol.Declarations) == 0 || !ast.IsInJSFile(symbol.Declarations[0]) || flags&ast.SymbolFlagsType != 0) + (len(symbol.Declarations()) == 0 || !ast.IsInJSFile(symbol.Declarations()[0]) || flags&ast.SymbolFlagsType != 0) } func shouldIncludeSymbol( @@ -3070,7 +3070,7 @@ func shouldIncludeSymbol( typeChecker *checker.Checker, compilerOptions *core.CompilerOptions, ) bool { - allFlags := symbol.Flags + allFlags := symbol.Flags() location := data.location // export = /**/ here we want to get all meanings, so any symbol is ok if location.Parent != nil && ast.IsExportAssignment(location.Parent) { @@ -3081,7 +3081,7 @@ func shouldIncludeSymbol( // `const a = /* no 'a' here */` if closestSymbolDeclaration != nil && ast.IsVariableDeclaration(closestSymbolDeclaration) && - symbol.ValueDeclaration == closestSymbolDeclaration { + symbol.ValueDeclaration() == closestSymbolDeclaration { return false } @@ -3089,10 +3089,10 @@ func shouldIncludeSymbol( // `function f(a = /* no 'a' and 'b' here */, b) { }` or // `function f(a: T, b: T2) { }` var symbolDeclaration *ast.Declaration - if symbol.ValueDeclaration != nil { - symbolDeclaration = symbol.ValueDeclaration - } else if len(symbol.Declarations) > 0 { - symbolDeclaration = symbol.Declarations[0] + if symbol.ValueDeclaration() != nil { + symbolDeclaration = symbol.ValueDeclaration() + } else if len(symbol.Declarations()) > 0 { + symbolDeclaration = symbol.Declarations()[0] } if closestSymbolDeclaration != nil && symbolDeclaration != nil { @@ -3131,12 +3131,12 @@ func shouldIncludeSymbol( compilerOptions.AllowUmdGlobalAccess != core.TSTrue && symbol != symbolOrigin && data.symbolToSortTextMap[ast.GetSymbolId(symbol)] == SortTextGlobalsOrKeywords && - symbol.Parent != nil && checker.IsExternalModuleSymbol(symbol.Parent) { + symbol.Parent() != nil && checker.IsExternalModuleSymbol(symbol.Parent()) { return false } allFlags = allFlags | symbolOrigin.CombinedLocalAndExportSymbolFlags() - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { allFlags = allFlags | typeChecker.GetSymbolFlags(symbol) } @@ -3175,7 +3175,7 @@ func getCompletionEntryDisplayNameForSymbol( if name == "" || // If the symbol is external module, don't show it in the completion list // (i.e declare module "http" { const x; } | // <= request completion here, "http" should not be there) - symbol.Flags&ast.SymbolFlagsModule != 0 && startsWithQuote(name) || + symbol.Flags()&ast.SymbolFlagsModule != 0 && startsWithQuote(name) || // If the symbol is the internal name of an ES symbol, it is not a valid entry. Internal names for ES symbols start with "__@" checker.IsKnownSymbol(symbol) { return "", false @@ -3184,10 +3184,10 @@ func getCompletionEntryDisplayNameForSymbol( variant := core.IfElse(isJsxIdentifierExpected, core.LanguageVariantJSX, core.LanguageVariantStandard) // name is a valid identifier or private identifier text if scanner.IsIdentifierText(name, variant) || - symbol.ValueDeclaration != nil && ast.IsPrivateIdentifierClassElementDeclaration(symbol.ValueDeclaration) { + symbol.ValueDeclaration() != nil && ast.IsPrivateIdentifierClassElementDeclaration(symbol.ValueDeclaration()) { return name, false } - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { // Allow non-identifier import/export aliases since we can insert them as string literals return name, true } @@ -3377,15 +3377,15 @@ func symbolCanBeReferencedAtTypeLocation(symbol *ast.Symbol, typeChecker *checke // This code used to just test the result of `skipAlias`, but that would ignore any locally introduced meanings. return nonAliasCanBeReferencedAtTypeLocation(symbol, typeChecker, seenModules) || nonAliasCanBeReferencedAtTypeLocation( - checker.SkipAlias(core.IfElse(symbol.ExportSymbol != nil, symbol.ExportSymbol, symbol), typeChecker), + checker.SkipAlias(core.IfElse(symbol.ExportSymbol() != nil, symbol.ExportSymbol(), symbol), typeChecker), typeChecker, seenModules, ) } func nonAliasCanBeReferencedAtTypeLocation(symbol *ast.Symbol, typeChecker *checker.Checker, seenModules collections.Set[ast.SymbolId]) bool { - return symbol.Flags&ast.SymbolFlagsType != 0 || typeChecker.IsUnknownSymbol(symbol) || - symbol.Flags&ast.SymbolFlagsModule != 0 && seenModules.AddIfAbsent(ast.GetSymbolId(symbol)) && + return symbol.Flags()&ast.SymbolFlagsType != 0 || typeChecker.IsUnknownSymbol(symbol) || + symbol.Flags()&ast.SymbolFlagsModule != 0 && seenModules.AddIfAbsent(ast.GetSymbolId(symbol)) && core.Some( typeChecker.GetExportsOfModule(symbol), func(e *ast.Symbol) bool { return symbolCanBeReferencedAtTypeLocation(e, typeChecker, seenModules) }, @@ -3423,17 +3423,17 @@ func getFirstSymbolInChain(symbol *ast.Symbol, enclosingDeclaration *ast.Node, t if len(chain) > 0 { return chain[0] } - if symbol.Parent != nil { - if isModuleSymbol(symbol.Parent) { + if symbol.Parent() != nil { + if isModuleSymbol(symbol.Parent()) { return symbol } - return getFirstSymbolInChain(symbol.Parent, enclosingDeclaration, typeChecker) + return getFirstSymbolInChain(symbol.Parent(), enclosingDeclaration, typeChecker) } return nil } func isModuleSymbol(symbol *ast.Symbol) bool { - return core.Some(symbol.Declarations, func(decl *ast.Declaration) bool { return decl.Kind == ast.KindSourceFile }) + return core.Some(symbol.Declarations(), func(decl *ast.Declaration) bool { return decl.Kind == ast.KindSourceFile }) } func getNullableSymbolOriginInfoKind(kind symbolOriginInfoKind, insertQuestionDot bool) symbolOriginInfoKind { @@ -3444,9 +3444,9 @@ func getNullableSymbolOriginInfoKind(kind symbolOriginInfoKind, insertQuestionDo } func isStaticProperty(symbol *ast.Symbol) bool { - return symbol.ValueDeclaration != nil && - symbol.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsStatic != 0 && - ast.IsClassLike(symbol.ValueDeclaration.Parent) + return symbol.ValueDeclaration() != nil && + symbol.ValueDeclaration().ModifierFlags()&ast.ModifierFlagsStatic != 0 && + ast.IsClassLike(symbol.ValueDeclaration().Parent) } // getContextualTypeForConditionalExpression handles completion within a conditional expression @@ -3586,7 +3586,7 @@ func getRecommendedCompletion(previousToken *ast.Node, contextualType *checker.T symbol := t.Symbol() // Don't make a recommended completion for an abstract class. if symbol != nil && - symbol.Flags&(ast.SymbolFlagsEnumMember|ast.SymbolFlagsEnum|ast.SymbolFlagsClass) != 0 && + symbol.Flags()&(ast.SymbolFlagsEnumMember|ast.SymbolFlagsEnum|ast.SymbolFlagsClass) != 0 && !isAbstractConstructorSymbol(symbol) { return getFirstSymbolInChain(symbol, previousToken, typeChecker) } @@ -3596,7 +3596,7 @@ func getRecommendedCompletion(previousToken *ast.Node, contextualType *checker.T } func isAbstractConstructorSymbol(symbol *ast.Symbol) bool { - if symbol.Flags&ast.SymbolFlagsClass != 0 { + if symbol.Flags()&ast.SymbolFlagsClass != 0 { declaration := ast.GetClassLikeDeclarationOfSymbol(symbol) return declaration != nil && ast.HasSyntacticModifier(declaration, ast.ModifierFlagsAbstract) } @@ -3666,7 +3666,7 @@ func isInTypeParameterDefault(contextToken *ast.Node) bool { } func isDeprecated(symbol *ast.Symbol, typeChecker *checker.Checker) bool { - declarations := checker.SkipAlias(symbol, typeChecker).Declarations + declarations := checker.SkipAlias(symbol, typeChecker).Declarations() return len(declarations) > 0 && core.Every(declarations, func(decl *ast.Declaration) bool { return typeChecker.IsDeprecatedDeclaration(decl) }) } @@ -4308,7 +4308,7 @@ func getConstraintOfTypeArgumentProperty(node *ast.Node, typeChecker *checker.Ch // Try to get the reparsed node first - we may be in JSDoc. reparsed := ast.GetReparsedNodeForNode(node) if symbol := reparsed.Symbol(); symbol != nil { - return typeChecker.GetTypeOfPropertyOfContextualType(t, symbol.Name) + return typeChecker.GetTypeOfPropertyOfContextualType(t, symbol.Name()) } // In some cases, we won't have a corresponding symbol @@ -4443,10 +4443,10 @@ func getPropertiesForObjectExpression( // function f(x: T) {} // f({ abc/**/: "" }) // `abc` is a member of `T` but only because it declares itself hasDeclarationOtherThanSelf := func(member *ast.Symbol) bool { - if len(member.Declarations) == 0 { + if len(member.Declarations()) == 0 { return true } - return core.Some(member.Declarations, func(decl *ast.Declaration) bool { return decl.Parent != obj }) + return core.Some(member.Declarations(), func(decl *ast.Declaration) bool { return decl.Parent != obj }) } properties := getApparentProperties(t, obj, typeChecker) @@ -4535,7 +4535,7 @@ func filterObjectMembersList( } filteredSymbols := core.Filter(contextualMemberSymbols, func(m *ast.Symbol) bool { - return !existingMemberNames.Has(m.Name) + return !existingMemberNames.Has(m.Name()) }) return filteredSymbols, membersDeclaredBySpreadAssignment @@ -4558,7 +4558,7 @@ func setMemberDeclaredBySpreadAssignment(declaration *ast.Node, members *collect properties = t.AsStructuredType().Properties() } for _, property := range properties { - members.Add(property.Name) + members.Add(property.Name()) } } @@ -4733,9 +4733,9 @@ func filterClassMembersList( return core.Filter(baseSymbols, func(propertySymbol *ast.Symbol) bool { return !existingMemberNames.Has(ast.SymbolName(propertySymbol)) && - len(propertySymbol.Declarations) > 0 && + len(propertySymbol.Declarations()) > 0 && checker.GetDeclarationModifierFlagsFromSymbol(propertySymbol)&ast.ModifierFlagsPrivate == 0 && - !(propertySymbol.ValueDeclaration != nil && ast.IsPrivateIdentifierClassElementDeclaration(propertySymbol.ValueDeclaration)) + !(propertySymbol.ValueDeclaration() != nil && ast.IsPrivateIdentifierClassElementDeclaration(propertySymbol.ValueDeclaration())) }) } @@ -4825,7 +4825,7 @@ func filterJsxAttributes( } } - return core.Filter(symbols, func(a *ast.Symbol) bool { return !existingNames.Has(a.Name) }), + return core.Filter(symbols, func(a *ast.Symbol) bool { return !existingNames.Has(a.Name()) }), &membersDeclaredBySpreadAssignment } @@ -5675,8 +5675,8 @@ func (l *LanguageService) getSymbolCompletionFromItemData( origin := data.symbolToOriginInfoMap[index] displayName, _ := getCompletionEntryDisplayNameForSymbol(file, preferences, symbol, origin, data.completionKind, data.isJsxIdentifierExpected) if displayName == itemData.Name && - (itemData.Source == string(completionSourceClassMemberSnippet) && symbol.Flags&ast.SymbolFlagsClassMember != 0 || - itemData.Source == string(completionSourceObjectLiteralMethodSnippet) && symbol.Flags&(ast.SymbolFlagsProperty|ast.SymbolFlagsMethod) != 0 || + (itemData.Source == string(completionSourceClassMemberSnippet) && symbol.Flags()&ast.SymbolFlagsClassMember != 0 || + itemData.Source == string(completionSourceObjectLiteralMethodSnippet) && symbol.Flags()&(ast.SymbolFlagsProperty|ast.SymbolFlagsMethod) != 0 || getSourceFromOrigin(origin) == itemData.Source || itemData.Source == string(completionSourceObjectLiteralMemberWithComma)) { return detailsData{ @@ -6626,11 +6626,11 @@ func (l *LanguageService) getExhaustiveCaseSnippets( // Enums if t.IsEnumLiteral() { debug.Assert(t.Symbol() != nil, "An enum member type should have a symbol") - debug.Assert(t.Symbol().Parent != nil, "An enum member type should have a parent symbol (the enum symbol)") + debug.Assert(t.Symbol().Parent() != nil, "An enum member type should have a parent symbol (the enum symbol)") // Filter existing enums by their values var enumValue any - if t.Symbol().ValueDeclaration != nil { - enumValue = c.GetConstantValue(t.Symbol().ValueDeclaration) + if t.Symbol().ValueDeclaration() != nil { + enumValue = c.GetConstantValue(t.Symbol().ValueDeclaration()) } if enumValue != nil { if tracker.hasValue(enumValue) { diff --git a/tsc/internal/ls/definition.go b/tsc/internal/ls/definition.go index c1d3d4b6b63de..eb1761a6d98d2 100644 --- a/tsc/internal/ls/definition.go +++ b/tsc/internal/ls/definition.go @@ -65,7 +65,7 @@ func (l *LanguageService) provideDefinitionAtPosition(ctx context.Context, progr if node.Kind == ast.KindOverrideKeyword { if sym := getSymbolForOverriddenMember(c, node); sym != nil { - return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, sym.Declarations, nil /*reference*/, spanmap.FeatureDefinition) + return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, sym.Declarations(), nil /*reference*/, spanmap.FeatureDefinition) } } @@ -151,8 +151,8 @@ func (l *LanguageService) provideTypeDefinitionAtPosition(ctx context.Context, p if len(declarations) != 0 { return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, declarations, nil /*reference*/, spanmap.FeatureTypeDefinition) } - if symbol.Flags&ast.SymbolFlagsValue == 0 && symbol.Flags&ast.SymbolFlagsType != 0 { - return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, symbol.Declarations, nil /*reference*/, spanmap.FeatureTypeDefinition) + if symbol.Flags()&ast.SymbolFlagsValue == 0 && symbol.Flags()&ast.SymbolFlagsType != 0 { + return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, symbol.Declarations(), nil /*reference*/, spanmap.FeatureTypeDefinition) } } @@ -314,7 +314,7 @@ func getDeclarationsFromLocation(c *checker.Checker, node *ast.Node) []*ast.Node shorthandSymbol := c.GetResolvedSymbol(node) var declarations []*ast.Node if shorthandSymbol != nil { - declarations = shorthandSymbol.Declarations + declarations = shorthandSymbol.Declarations() } contextualDeclarations := getDeclarationsFromObjectLiteralElement(c, node) return core.Concatenate(declarations, contextualDeclarations) @@ -341,7 +341,7 @@ func getDeclarationsFromLocation(c *checker.Checker, node *ast.Node) []*ast.Node var result []*ast.Node for _, unionType := range types { if prop := c.GetPropertyOfType(unionType, name); prop != nil { - result = append(result, prop.Declarations...) + result = append(result, prop.Declarations()...) } } return result @@ -351,12 +351,12 @@ func getDeclarationsFromLocation(c *checker.Checker, node *ast.Node) []*ast.Node node = getDeclarationNameForKeyword(node) if symbol := c.GetSymbolAtLocation(node); symbol != nil { - if symbol.Flags&ast.SymbolFlagsClass != 0 && symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsVariable) == 0 && node.Kind == ast.KindConstructorKeyword { - if constructor := symbol.Members[ast.InternalSymbolNameConstructor]; constructor != nil { + if symbol.Flags()&ast.SymbolFlagsClass != 0 && symbol.Flags()&(ast.SymbolFlagsFunction|ast.SymbolFlagsVariable) == 0 && node.Kind == ast.KindConstructorKeyword { + if constructor := symbol.Members()[ast.InternalSymbolNameConstructor]; constructor != nil { symbol = constructor } } - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { if resolved, ok := c.ResolveAlias(symbol); ok { symbol = resolved } @@ -365,8 +365,8 @@ func getDeclarationsFromLocation(c *checker.Checker, node *ast.Node) []*ast.Node if len(objectLiteralElementDeclarations) > 0 { return objectLiteralElementDeclarations } - if len(symbol.Declarations) > 0 { - return symbol.Declarations + if len(symbol.Declarations()) > 0 { + return symbol.Declarations() } } if indexInfos := c.GetIndexSignaturesAtLocation(node); len(indexInfos) != 0 { @@ -390,7 +390,7 @@ func getDeclarationsFromObjectLiteralElement(c *checker.Checker, node *ast.Node) properties := c.GetPropertySymbolsFromContextualType(element, contextualType, false /*unionSymbolOk*/) if core.Some(properties, func(p *ast.Symbol) bool { - return p.ValueDeclaration != nil && ast.IsObjectLiteralExpression(p.ValueDeclaration.Parent) && ast.IsObjectLiteralElement(p.ValueDeclaration) && p.ValueDeclaration.Name() == node + return p.ValueDeclaration() != nil && ast.IsObjectLiteralExpression(p.ValueDeclaration().Parent) && ast.IsObjectLiteralElement(p.ValueDeclaration()) && p.ValueDeclaration().Name() == node }) { if withoutNodeInferencesType := c.GetContextualType(element.Parent, checker.ContextFlagsIgnoreNodeInferences); withoutNodeInferencesType != nil { if withoutNodeInferencesProperties := c.GetPropertySymbolsFromContextualType(element, withoutNodeInferencesType, false /*unionSymbolOk*/); len(withoutNodeInferencesProperties) > 0 { @@ -401,7 +401,7 @@ func getDeclarationsFromObjectLiteralElement(c *checker.Checker, node *ast.Node) var result []*ast.Node for _, prop := range properties { - result = append(result, prop.Declarations...) + result = append(result, prop.Declarations()...) } return result } @@ -452,7 +452,7 @@ func symbolMatchesSignature(symbol *ast.Symbol, calledDeclaration *ast.Node) boo return false } calledSymbol := calledDeclaration.Symbol() - if symbol == calledSymbol || calledSymbol != nil && symbol == calledSymbol.Parent { + if symbol == calledSymbol || calledSymbol != nil && symbol == calledSymbol.Parent() { return true } parent := calledDeclaration.Parent @@ -494,7 +494,7 @@ func getTypeOfSymbolAtLocation(c *checker.Checker, symbol *ast.Symbol, node *ast t := c.GetTypeOfSymbolAtLocation(symbol, node) // If the type is just a function's inferred type, go-to-type should go to the return type instead since // go-to-definition takes you to the function anyway. - if t.Symbol() == symbol || t.Symbol() != nil && symbol.ValueDeclaration != nil && ast.IsVariableDeclaration(symbol.ValueDeclaration) && symbol.ValueDeclaration.Initializer() == t.Symbol().ValueDeclaration { + if t.Symbol() == symbol || t.Symbol() != nil && symbol.ValueDeclaration() != nil && ast.IsVariableDeclaration(symbol.ValueDeclaration()) && symbol.ValueDeclaration().Initializer() == t.Symbol().ValueDeclaration() { sigs := c.GetCallSignatures(t) if len(sigs) == 1 { return c.GetReturnTypeOfSignature(sigs[0]) @@ -507,7 +507,7 @@ func getDeclarationsFromType(t *checker.Type) []*ast.Node { var result []*ast.Node for _, t := range t.Distributed() { if t.Symbol() != nil { - for _, decl := range t.Symbol().Declarations { + for _, decl := range t.Symbol().Declarations() { result = core.AppendIfUnique(result, decl) } } diff --git a/tsc/internal/ls/displaypartswriter.go b/tsc/internal/ls/displaypartswriter.go index 170e9d5c22e0c..41610adfa5307 100644 --- a/tsc/internal/ls/displaypartswriter.go +++ b/tsc/internal/ls/displaypartswriter.go @@ -169,7 +169,7 @@ func classificationForSymbol(symbol *ast.Symbol) lsproto.ClassificationTypeName if symbol == nil { return lsproto.ClassificationTypeNameText } - flags := symbol.Flags + flags := symbol.Flags() switch { case flags&ast.SymbolFlagsVariable != 0: if isFirstDeclarationOfSymbolParameter(symbol) { @@ -209,7 +209,7 @@ func classificationForSymbol(symbol *ast.Symbol) lsproto.ClassificationTypeName // isFirstDeclarationOfSymbolParameter checks if the symbol's first declaration is a parameter. func isFirstDeclarationOfSymbolParameter(symbol *ast.Symbol) bool { - declarations := symbol.Declarations + declarations := symbol.Declarations() if len(declarations) == 0 { return false } diff --git a/tsc/internal/ls/documenthighlights.go b/tsc/internal/ls/documenthighlights.go index d4d16be78f083..47fe0092c7e8b 100644 --- a/tsc/internal/ls/documenthighlights.go +++ b/tsc/internal/ls/documenthighlights.go @@ -278,7 +278,7 @@ func (l *LanguageService) getFromAllDeclarations(nodeTest func(*ast.Node) bool, var symbolDecls []*ast.Node if ast.CanHaveSymbol(decl) { if symbol := decl.Symbol(); symbol != nil { - for _, d := range symbol.Declarations { + for _, d := range symbol.Declarations() { if nodeTest(d) { outer: for _, c := range getChildrenFromNonJSDocNode(d, sourceFile) { diff --git a/tsc/internal/ls/file_rename.go b/tsc/internal/ls/file_rename.go index 13ffb3cb9bc15..b3c1ca5e6eeb4 100644 --- a/tsc/internal/ls/file_rename.go +++ b/tsc/internal/ls/file_rename.go @@ -400,5 +400,5 @@ func isAmbientModuleSymbol(symbol *ast.Symbol) bool { if symbol == nil { return false } - return slices.ContainsFunc(symbol.Declarations, ast.IsModuleWithStringLiteralName) + return slices.ContainsFunc(symbol.Declarations(), ast.IsModuleWithStringLiteralName) } diff --git a/tsc/internal/ls/findallreferences.go b/tsc/internal/ls/findallreferences.go index ea287f75d7638..6e40e4aa1211c 100644 --- a/tsc/internal/ls/findallreferences.go +++ b/tsc/internal/ls/findallreferences.go @@ -134,8 +134,8 @@ func (s *SymbolAndEntries) DefinitionNode() *ast.Node { if s.definition.node != nil { return s.definition.node } - if s.definition.symbol != nil && len(s.definition.symbol.Declarations) > 0 { - return s.definition.symbol.Declarations[0] + if s.definition.symbol != nil && len(s.definition.symbol.Declarations()) > 0 { + return s.definition.symbol.Declarations()[0] } return nil } @@ -388,17 +388,17 @@ func skipPastExportOrImportSpecifierOrUnion(symbol *ast.Symbol, node *ast.Node, return getLocalSymbolForExportSpecifier(node, symbol, parent.AsExportSpecifier(), checker) } // If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references. - return core.FirstNonNil(symbol.Declarations, func(decl *ast.Node) *ast.Symbol { + return core.FirstNonNil(symbol.Declarations(), func(decl *ast.Node) *ast.Symbol { if decl.Parent == nil { // Ignore UMD module and global merge and CJS module end exports symbols - if symbol.Flags&(ast.SymbolFlagsTransient|ast.SymbolFlagsModuleExports) != 0 { + if symbol.Flags()&(ast.SymbolFlagsTransient|ast.SymbolFlagsModuleExports) != 0 { return nil } // Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here. - panic(fmt.Sprintf("Unexpected symbol at %s: %s", node.Kind.String(), symbol.Name)) + panic(fmt.Sprintf("Unexpected symbol at %s: %s", node.Kind.String(), symbol.Name())) } if decl.Parent.Kind == ast.KindTypeLiteral && decl.Parent.Parent.Kind == ast.KindUnionType { - return checker.GetPropertyOfType(checker.GetTypeFromTypeNode(decl.Parent.Parent), symbol.Name) + return checker.GetPropertyOfType(checker.GetTypeFromTypeNode(decl.Parent.Parent), symbol.Name()) } return nil }) @@ -407,18 +407,18 @@ func skipPastExportOrImportSpecifierOrUnion(symbol *ast.Symbol, node *ast.Node, func getSymbolScope(symbol *ast.Symbol) *ast.Node { // If this is the symbol of a named function expression or named class expression, // then named references are limited to its own scope. - valueDeclaration := symbol.ValueDeclaration + valueDeclaration := symbol.ValueDeclaration() if valueDeclaration != nil && (valueDeclaration.Kind == ast.KindFunctionExpression || valueDeclaration.Kind == ast.KindClassExpression) { return valueDeclaration } - if len(symbol.Declarations) == 0 { + if len(symbol.Declarations()) == 0 { return nil } - declarations := symbol.Declarations + declarations := symbol.Declarations() // If this is private property or method, the scope is the containing class - if symbol.Flags&(ast.SymbolFlagsProperty|ast.SymbolFlagsMethod) != 0 { + if symbol.Flags()&(ast.SymbolFlagsProperty|ast.SymbolFlagsMethod) != 0 { privateDeclaration := core.Find(declarations, func(d *ast.Node) bool { return ast.HasModifier(d, ast.ModifierFlagsPrivate) || ast.IsPrivateIdentifierClassElementDeclaration(d) }) @@ -442,8 +442,8 @@ func getSymbolScope(symbol *ast.Symbol) *ast.Node { - The parent is an external module: then we should only search in the module (and recurse on the export later). - But if the parent has `export as namespace`, the symbol is globally visible through that namespace. */ - exposedByParent := symbol.Parent != nil && symbol.Flags&ast.SymbolFlagsTypeParameter == 0 - if exposedByParent && !(checker.IsExternalModuleSymbol(symbol.Parent) && !isSourceFileWithGlobalExports(symbol.Parent.ValueDeclaration)) { + exposedByParent := symbol.Parent() != nil && symbol.Flags()&ast.SymbolFlagsTypeParameter == 0 + if exposedByParent && !(checker.IsExternalModuleSymbol(symbol.Parent()) && !isSourceFileWithGlobalExports(symbol.Parent().ValueDeclaration())) { return nil } @@ -510,7 +510,7 @@ func (l *LanguageService) getNonLocalDefinition(ctx context.Context, entry *Symb checker, done := program.GetTypeChecker(ctx) defer done() emitResolver := checker.NewEmitResolver(printer.NewEmitContext()) - for _, d := range entry.definition.symbol.Declarations { + for _, d := range entry.definition.symbol.Declarations() { if isDefinitionVisible(emitResolver, d) { file, startPos := getFileAndStartPosFromDeclaration(d) fileName := file.FileName() @@ -607,7 +607,7 @@ func (l *LanguageService) forEachOriginalDefinitionLocation( } program := l.GetProgram() - for _, d := range entry.definition.symbol.Declarations { + for _, d := range entry.definition.symbol.Declarations() { file, startPos := getFileAndStartPosFromDeclaration(d) fileName := file.FileName() if fileName.IsDeclarationFile() { @@ -882,8 +882,8 @@ func (l *LanguageService) definitionToReferencedSymbolDefinitionInfo(ctx context // Get the definition node var node *ast.Node - if len(symbol.Declarations) > 0 { - decl := symbol.Declarations[0] + if len(symbol.Declarations()) > 0 { + decl := symbol.Declarations()[0] node = core.OrElse(decl.Name(), decl) } else { node = originalNode @@ -1097,7 +1097,7 @@ func isDeclarationOfSymbol(node *ast.Node, target *ast.Symbol) bool { // !!! // const commonjsSource = source && isBinaryExpression(source) ? source.left as unknown as Declaration : undefined; - return source != nil && core.Some(target.Declarations, func(decl *ast.Node) bool { + return source != nil && core.Some(target.Declarations(), func(decl *ast.Node) bool { return decl == source }) } @@ -1229,7 +1229,7 @@ func (l *LanguageService) GetSignatureUsages(ctx context.Context, signatureDecl declNames := make(map[*ast.Node]bool) for _, entry := range entries { if entry.definition != nil && entry.definition.symbol != nil { - for _, decl := range entry.definition.symbol.Declarations { + for _, decl := range entry.definition.symbol.Declarations() { if n := decl.Name(); n != nil { declNames[n] = true } @@ -1332,15 +1332,15 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit return nil } - if symbol.Name == ast.InternalSymbolNameExportEquals { - if symbol.Parent == nil { + if symbol.Name() == ast.InternalSymbolNameExportEquals { + if symbol.Parent() == nil { return nil } - return l.getReferencedSymbolsForModule(checker, program, symbol.Parent, false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet) + return l.getReferencedSymbolsForModule(checker, program, symbol.Parent(), false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet) } moduleReferences := l.getReferencedSymbolsForModuleIfDeclaredBySourceFile(ctx, symbol, program, sourceFiles, checker, options, sourceFilesSet) - if moduleReferences != nil && symbol.Flags&ast.SymbolFlagsTransient == 0 { + if moduleReferences != nil && symbol.Flags()&ast.SymbolFlagsTransient == 0 { return moduleReferences } @@ -1400,18 +1400,18 @@ func isStringLiteralPropertyReference(node *ast.StringLiteralLike, checker *chec func (l *LanguageService) getReferencedSymbolsForModuleIfDeclaredBySourceFile(ctx context.Context, symbol *ast.Symbol, program *compiler.Program, sourceFiles []*ast.SourceFile, checker *checker.Checker, options refOptions, sourceFilesSet *collections.Set[tspath.RootedFilePath]) []*SymbolAndEntries { var moduleSourceFileName tspath.RootedFilePath - if symbol == nil || !((symbol.Flags&ast.SymbolFlagsModule != 0) && len(symbol.Declarations) != 0) { + if symbol == nil || !((symbol.Flags()&ast.SymbolFlagsModule != 0) && len(symbol.Declarations()) != 0) { return nil } - if moduleSourceFile := core.Find(symbol.Declarations, ast.IsSourceFile); moduleSourceFile != nil { + if moduleSourceFile := core.Find(symbol.Declarations(), ast.IsSourceFile); moduleSourceFile != nil { moduleSourceFileName = moduleSourceFile.AsSourceFile().FileName() } else { return nil } - exportEquals := symbol.Exports[ast.InternalSymbolNameExportEquals] + exportEquals := symbol.Exports()[ast.InternalSymbolNameExportEquals] // If exportEquals != nil, we're about to add references to `import("mod")` anyway, so don't double-count them. moduleReferences := l.getReferencedSymbolsForModule(checker, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet) - if exportEquals == nil || exportEquals.Flags&ast.SymbolFlagsAlias == 0 || !sourceFilesSet.Has(moduleSourceFileName) { + if exportEquals == nil || exportEquals.Flags()&ast.SymbolFlagsAlias == 0 || !sourceFilesSet.Has(moduleSourceFileName) { return moduleReferences } symbol, _ = checker.ResolveAlias(exportEquals) @@ -1733,7 +1733,7 @@ func getMergedAliasedSymbolOfNamespaceExportDeclaration(node *ast.Node, symbol * } func (l *LanguageService) getReferencedSymbolsForModule(checker *checker.Checker, program *compiler.Program, symbol *ast.Symbol, excludeImportTypeOfExportEquals bool, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[tspath.RootedFilePath]) []*SymbolAndEntries { - debug.Assert(symbol.ValueDeclaration != nil) + debug.Assert(symbol.ValueDeclaration() != nil) moduleRefs := findModuleReferences(program, sourceFiles, symbol, checker) references := core.MapNonNil(moduleRefs, func(reference ModuleReference) *ReferenceEntry { @@ -1780,8 +1780,8 @@ func (l *LanguageService) getReferencedSymbolsForModule(checker *checker.Checker }) // Add references to the module declarations themselves - if len(symbol.Declarations) > 0 { - for _, decl := range symbol.Declarations { + if len(symbol.Declarations()) > 0 { + for _, decl := range symbol.Declarations() { switch decl.Kind { case ast.KindSourceFile: // Don't include the source file itself. (This may not be ideal behavior, but awkward to include an entire file as a reference.) @@ -1798,9 +1798,9 @@ func (l *LanguageService) getReferencedSymbolsForModule(checker *checker.Checker } // Handle export equals declarations - exported := symbol.Exports[ast.InternalSymbolNameExportEquals] - if exported != nil && len(exported.Declarations) > 0 { - for _, decl := range exported.Declarations { + exported := symbol.Exports()[ast.InternalSymbolNameExportEquals] + if exported != nil && len(exported.Declarations()) > 0 { + for _, decl := range exported.Declarations() { sourceFile := ast.GetSourceFileOfNode(decl) if sourceFilesSet.Has(sourceFile.FileName()) { var node *ast.Node @@ -1863,15 +1863,15 @@ func getReferencedSymbolsForSymbol(ctx context.Context, program *compiler.Progra state := newState(ctx, program, sourceFiles, sourceFilesSet, node, checker, searchMeaning, options) var exportSpecifier *ast.Node - if isForRenameWithPrefixAndSuffixText(options) && len(symbol.Declarations) != 0 { - exportSpecifier = core.Find(symbol.Declarations, ast.IsExportSpecifier) + if isForRenameWithPrefixAndSuffixText(options) && len(symbol.Declarations()) != 0 { + exportSpecifier = core.Find(symbol.Declarations(), ast.IsExportSpecifier) } if exportSpecifier != nil { // When renaming at an export specifier, rename the export and not the thing being exported. state.getReferencesAtExportSpecifier(exportSpecifier.Name(), symbol, exportSpecifier.AsExportSpecifier(), state.createSearch(node, originalSymbol, ImpExpKindUnknown /*comingFrom*/, "", nil), true /*addReferencesHere*/, true /*alwaysGetReferences*/) - } else if node != nil && node.Kind == ast.KindDefaultKeyword && symbol.Name == ast.InternalSymbolNameDefault && symbol.Parent != nil { + } else if node != nil && node.Kind == ast.KindDefaultKeyword && symbol.Name() == ast.InternalSymbolNameDefault && symbol.Parent() != nil { state.addReference(node, symbol, entryKindNode) - state.searchForImportsOfExport(node, symbol, &ExportInfo{exportingModuleSymbol: symbol.Parent, exportKind: ExportKindDefault}) + state.searchForImportsOfExport(node, symbol, &ExportInfo{exportingModuleSymbol: symbol.Parent(), exportKind: ExportKindDefault}) } else { search := state.createSearch(node, symbol, ImpExpKindUnknown /*comingFrom*/, "", state.populateSearchSymbolSet(symbol, node, options.use == referenceUseRename, options.useAliasesForRename, options.implementations)) state.getReferencesInContainerOrFiles(symbol, search) @@ -2016,12 +2016,12 @@ func (state *refState) addReference(referenceLocation *ast.Node, symbol *ast.Sym func getReferenceEntriesForShorthandPropertyAssignment(node *ast.Node, checker *checker.Checker, addReference func(*ast.Node)) { refSymbol := checker.GetSymbolAtLocation(node) - if refSymbol == nil || refSymbol.ValueDeclaration == nil { + if refSymbol == nil || refSymbol.ValueDeclaration() == nil { return } - shorthandSymbol := checker.GetShorthandAssignmentValueSymbol(refSymbol.ValueDeclaration) - if shorthandSymbol != nil && len(shorthandSymbol.Declarations) > 0 { - for _, declaration := range shorthandSymbol.Declarations { + shorthandSymbol := checker.GetShorthandAssignmentValueSymbol(refSymbol.ValueDeclaration()) + if shorthandSymbol != nil && len(shorthandSymbol.Declarations()) > 0 { + for _, declaration := range shorthandSymbol.Declarations() { if ast.GetMeaningFromDeclaration(declaration)&ast.SemanticMeaningValue != 0 { addReference(declaration) } @@ -2038,10 +2038,10 @@ func tryGetClassByExtendingIdentifier(node *ast.Node) *ast.ClassLikeDeclaration } func getClassConstructorSymbol(classSymbol *ast.Symbol) *ast.Symbol { - if classSymbol.Members == nil { + if classSymbol.Members() == nil { return nil } - return classSymbol.Members[ast.InternalSymbolNameConstructor] + return classSymbol.Members()[ast.InternalSymbolNameConstructor] } func hasOwnConstructor(classDeclaration *ast.ClassLikeDeclaration) bool { @@ -2050,8 +2050,8 @@ func hasOwnConstructor(classDeclaration *ast.ClassLikeDeclaration) bool { func findOwnConstructorReferences(classSymbol *ast.Symbol, sourceFile *ast.SourceFile, addNode func(*ast.Node)) { constructorSymbol := getClassConstructorSymbol(classSymbol) - if constructorSymbol != nil && len(constructorSymbol.Declarations) > 0 { - for _, decl := range constructorSymbol.Declarations { + if constructorSymbol != nil && len(constructorSymbol.Declarations()) > 0 { + for _, decl := range constructorSymbol.Declarations() { if decl.Kind == ast.KindConstructor { if ctrKeyword := astnav.FindChildOfKind(decl, ast.KindConstructorKeyword, sourceFile); ctrKeyword != nil { addNode(ctrKeyword) @@ -2060,9 +2060,9 @@ func findOwnConstructorReferences(classSymbol *ast.Symbol, sourceFile *ast.Sourc } } - if classSymbol.Exports != nil { - for _, member := range classSymbol.Exports { - decl := member.ValueDeclaration + if classSymbol.Exports() != nil { + for _, member := range classSymbol.Exports() { + decl := member.ValueDeclaration() if decl != nil && decl.Kind == ast.KindMethodDeclaration { body := decl.Body() if body != nil { @@ -2079,11 +2079,11 @@ func findOwnConstructorReferences(classSymbol *ast.Symbol, sourceFile *ast.Sourc func findSuperConstructorAccesses(classDeclaration *ast.ClassLikeDeclaration, addNode func(*ast.Node)) { constructorSymbol := getClassConstructorSymbol(classDeclaration.Symbol()) - if constructorSymbol == nil || len(constructorSymbol.Declarations) == 0 { + if constructorSymbol == nil || len(constructorSymbol.Declarations()) == 0 { return } - for _, decl := range constructorSymbol.Declarations { + for _, decl := range constructorSymbol.Declarations() { if decl.Kind == ast.KindConstructor { body := decl.Body() if body != nil { @@ -2450,7 +2450,7 @@ func (state *refState) getReferencesAtExportSpecifier( // Go to the symbol we imported from and find references for it. func (state *refState) searchForImportedSymbol(symbol *ast.Symbol) { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { exportingFile := ast.GetSourceFileOfNode(declaration) // Need to search in the file even if it's not in the search-file set, because it might export the symbol. state.getReferencesInSourceFile(exportingFile, state.createSearch(declaration, symbol, ImpExpKindImport, "", nil), state.includesSourceFile(exportingFile)) @@ -2515,11 +2515,11 @@ func (state *refState) hasMatchingMeaning(referenceLocation *ast.Node) bool { } func (state *refState) getReferenceForShorthandProperty(referenceSymbol *ast.Symbol, search *refSearch) { - if referenceSymbol.Flags&ast.SymbolFlagsTransient != 0 || referenceSymbol.ValueDeclaration == nil { + if referenceSymbol.Flags()&ast.SymbolFlagsTransient != 0 || referenceSymbol.ValueDeclaration() == nil { return } - shorthandValueSymbol := state.checker.GetShorthandAssignmentValueSymbol(referenceSymbol.ValueDeclaration) - name := ast.GetNameOfDeclaration(referenceSymbol.ValueDeclaration) + shorthandValueSymbol := state.checker.GetShorthandAssignmentValueSymbol(referenceSymbol.ValueDeclaration()) + name := ast.GetNameOfDeclaration(referenceSymbol.ValueDeclaration()) // Because in short-hand property assignment, an identifier which stored as name of the short-hand property assignment // has two meanings: property name and property value. Therefore when we do findAllReference at the position where @@ -2573,7 +2573,7 @@ func (state *refState) getRelatedSymbol(search *refSearch, referenceSymbol *ast. } searchSym := core.Coalesce(baseSymbol, core.Coalesce(rootSymbol, sym)) if searchSym != nil && search.includes(searchSym) { - if rootSymbol != nil && sym.CheckFlags&ast.CheckFlagsSynthetic == 0 { + if rootSymbol != nil && sym.CheckFlags()&ast.CheckFlagsSynthetic == 0 { return rootSymbol } return sym @@ -2583,7 +2583,7 @@ func (state *refState) getRelatedSymbol(search *refSearch, referenceSymbol *ast. }, func(rootSymbol *ast.Symbol) bool { return !(len(search.parents) != 0 && !core.Some(search.parents, func(parent *ast.Symbol) bool { - return state.explicitlyInheritsFrom(rootSymbol.Parent, parent) + return state.explicitlyInheritsFrom(rootSymbol.Parent(), parent) })) }, ) @@ -2609,8 +2609,8 @@ func (state *refState) forEachRelatedSymbol( return result } // Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions - if rootSymbol.Parent != nil && rootSymbol.Parent.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 && allowBaseTypes(rootSymbol) { - result := getPropertySymbolsFromBaseTypes(rootSymbol.Parent, rootSymbol.Name, state.checker, func(base *ast.Symbol) *ast.Symbol { + if rootSymbol.Parent() != nil && rootSymbol.Parent().Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 && allowBaseTypes(rootSymbol) { + result := getPropertySymbolsFromBaseTypes(rootSymbol.Parent(), rootSymbol.Name(), state.checker, func(base *ast.Symbol) *ast.Symbol { return cbSymbol(sym, rootSymbol, base) }) if result != nil { @@ -2676,13 +2676,13 @@ func (state *refState) forEachRelatedSymbol( return res, entryKindNode } - if symbol.ValueDeclaration != nil && ast.IsParameterPropertyDeclaration(symbol.ValueDeclaration, symbol.ValueDeclaration.Parent) { - paramProp1, paramProp2 := state.checker.GetSymbolsOfParameterPropertyDeclaration(symbol.ValueDeclaration, symbol.Name) + if symbol.ValueDeclaration() != nil && ast.IsParameterPropertyDeclaration(symbol.ValueDeclaration(), symbol.ValueDeclaration().Parent) { + paramProp1, paramProp2 := state.checker.GetSymbolsOfParameterPropertyDeclaration(symbol.ValueDeclaration(), symbol.Name()) debug.Assert( - paramProp1.Flags&ast.SymbolFlagsFunctionScopedVariable != 0 && paramProp2.Flags&ast.SymbolFlagsClassMember != 0, + paramProp1.Flags()&ast.SymbolFlagsFunctionScopedVariable != 0 && paramProp2.Flags()&ast.SymbolFlagsClassMember != 0, "GetSymbolsOfParameterPropertyDeclaration must return (parameter, member) pair", ) - return fromRoot(core.IfElse(symbol.Flags&ast.SymbolFlagsFunctionScopedVariable != 0, paramProp2, paramProp1)), entryKindNode + return fromRoot(core.IfElse(symbol.Flags()&ast.SymbolFlagsFunctionScopedVariable != 0, paramProp2, paramProp1)), entryKindNode } if exportSpecifier := ast.GetDeclarationOfKind(symbol, ast.KindExportSpecifier); exportSpecifier != nil && (!isForRenamePopulateSearchSymbolSet || exportSpecifier.PropertyName() == nil) { @@ -2746,11 +2746,11 @@ func (state *refState) explicitlyInheritsFrom(symbol *ast.Symbol, parent *ast.Sy // Set to false initially to prevent infinite recursion state.inheritsFromCache[key] = false - if symbol.Declarations == nil { + if symbol.Declarations() == nil { return false } - inherits := core.Some(symbol.Declarations, func(declaration *ast.Node) bool { + inherits := core.Some(symbol.Declarations(), func(declaration *ast.Node) bool { superTypeNodes := getAllSuperTypeNodes(declaration) return core.Some(superTypeNodes, func(typeReference *ast.TypeNode) bool { typ := state.checker.GetTypeAtLocation(typeReference.AsNode()) diff --git a/tsc/internal/ls/hover.go b/tsc/internal/ls/hover.go index 249960e8021dd..7fd004cc0680b 100644 --- a/tsc/internal/ls/hover.go +++ b/tsc/internal/ls/hover.go @@ -107,7 +107,7 @@ func (l *LanguageService) ProvideHover(ctx context.Context, params *lsproto.Hove // shows the icon for whatever `x` actually is (const, function, ...) rather than a // generic alias icon. GetSymbolModifiers already accounts for the alias target itself. iconSymbol := symbol - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { if resolved := c.GetAliasedSymbol(symbol); resolved != nil && resolved != symbol { iconSymbol = resolved } @@ -247,7 +247,7 @@ func documentationFromSignature(getMappedLocation documentationLocationMapper, c } func documentationFromAlias(getMappedLocation documentationLocationMapper, c *checker.Checker, symbol *ast.Symbol, node *ast.Node, contentFormat lsproto.MarkupKind, commentOnly bool) string { - if symbol == nil || symbol.Flags&ast.SymbolFlagsAlias == 0 { + if symbol == nil || symbol.Flags()&ast.SymbolFlagsAlias == 0 { return "" } @@ -257,12 +257,12 @@ func documentationFromAlias(getMappedLocation documentationLocationMapper, c *ch } candidates := []*ast.Symbol{aliasedSymbol} - if aliasedSymbol.ExportSymbol != nil { - candidates = append(candidates, aliasedSymbol.ExportSymbol) + if aliasedSymbol.ExportSymbol() != nil { + candidates = append(candidates, aliasedSymbol.ExportSymbol()) } for _, candidate := range candidates { - aliasedDeclaration := core.OrElse(candidate.ValueDeclaration, core.FirstOrNil(candidate.Declarations)) + aliasedDeclaration := core.OrElse(candidate.ValueDeclaration(), core.FirstOrNil(candidate.Declarations())) if aliasedDeclaration == nil { continue } @@ -290,9 +290,9 @@ func documentationFromRootSymbols(getMappedLocation documentationLocationMapper, if rootSymbol == nil { continue } - declarations := rootSymbol.Declarations - if len(declarations) == 0 && rootSymbol.ValueDeclaration != nil { - declarations = []*ast.Node{rootSymbol.ValueDeclaration} + declarations := rootSymbol.Declarations() + if len(declarations) == 0 && rootSymbol.ValueDeclaration() != nil { + declarations = []*ast.Node{rootSymbol.ValueDeclaration()} } for _, declaration := range declarations { if documentation := getDocumentationFromDeclaration(getMappedLocation, c, rootSymbol, declaration, node, contentFormat, commentOnly); documentation != "" { @@ -521,7 +521,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol dpw.WriteSymbol(text, symbol) } writeModuleImportAttributes := func(symbol *ast.Symbol) { - declaration := core.Find(symbol.Declarations, func(declaration *ast.Node) bool { + declaration := core.Find(symbol.Declarations(), func(declaration *ast.Node) bool { return ast.IsModuleDeclaration(declaration) && declaration.AsModuleDeclaration().Attributes != nil }) if declaration == nil { @@ -581,7 +581,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol dpw.WriteKeyword(prefix) } writeSymbolClassified(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags) - if symbol.Flags&ast.SymbolFlagsOptional != 0 { + if symbol.Flags()&ast.SymbolFlagsOptional != 0 { dpw.WritePunctuation("?") } writeSignatureClassified(sig, container, typeFormatFlags|checker.TypeFormatFlagsWriteCallStyleSignature|checker.TypeFormatFlagsWriteTypeArgumentsOfSignature) @@ -617,11 +617,11 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol // Only offer symbol-level expansion for types that tryExpandSymbol handles: // class, interface, enum, namespace/module. For functions/variables/properties, // the node builder's probeTypeExpandability detects expandable type components. - if symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface|ast.SymbolFlagsNamespace) == 0 { + if symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface|ast.SymbolFlagsNamespace) == 0 { return false } var t *checker.Type - if symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { + if symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { t = c.GetDeclaredTypeOfSymbol(symbol) } else { t = c.GetTypeOfSymbolAtLocation(symbol, node) @@ -660,7 +660,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol var writeSymbol func(*ast.Symbol) writeSymbol = func(symbol *ast.Symbol) { // Recursively write all meanings of alias - if symbol.Flags&ast.SymbolFlagsAlias != 0 && visitedAliases.AddIfAbsent(symbol) { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 && visitedAliases.AddIfAbsent(symbol) { if aliasedSymbol := c.GetAliasedSymbol(symbol); aliasedSymbol != c.GetUnknownSymbol() { aliasLevel++ writeSymbol(aliasedSymbol) @@ -670,29 +670,29 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol var flags ast.SymbolFlags switch meaning { case ast.SemanticMeaningValue: - flags = symbol.Flags & (ast.SymbolFlagsValue | ast.SymbolFlagsSignature) + flags = symbol.Flags() & (ast.SymbolFlagsValue | ast.SymbolFlagsSignature) case ast.SemanticMeaningType: - flags = symbol.Flags & ast.SymbolFlagsType + flags = symbol.Flags() & ast.SymbolFlagsType case ast.SemanticMeaningNamespace: - flags = symbol.Flags & ast.SymbolFlagsNamespace + flags = symbol.Flags() & ast.SymbolFlagsNamespace default: - flags = symbol.Flags & (ast.SymbolFlagsValue | ast.SymbolFlagsSignature | ast.SymbolFlagsType | ast.SymbolFlagsNamespace) + flags = symbol.Flags() & (ast.SymbolFlagsValue | ast.SymbolFlagsSignature | ast.SymbolFlagsType | ast.SymbolFlagsNamespace) } if flags == 0 { if aliasLevel != 0 || dpw.String() != "" { return } - flags = symbol.Flags & (ast.SymbolFlagsValue | ast.SymbolFlagsSignature | ast.SymbolFlagsType | ast.SymbolFlagsNamespace) + flags = symbol.Flags() & (ast.SymbolFlagsValue | ast.SymbolFlagsSignature | ast.SymbolFlagsType | ast.SymbolFlagsNamespace) if flags == 0 { return } } - if flags&ast.SymbolFlagsProperty != 0 && symbol.ValueDeclaration != nil && ast.IsMethodDeclaration(symbol.ValueDeclaration) { + if flags&ast.SymbolFlagsProperty != 0 && symbol.ValueDeclaration() != nil && ast.IsMethodDeclaration(symbol.ValueDeclaration()) { flags = ast.SymbolFlagsMethod } if flags&(ast.SymbolFlagsVariable|ast.SymbolFlagsProperty|ast.SymbolFlagsAccessor) != 0 { writeNewLine() - if symbol.CheckFlags&ast.CheckFlagsIndexSymbol == 0 { + if symbol.CheckFlags()&ast.CheckFlagsIndexSymbol == 0 { switch { case flags&ast.SymbolFlagsProperty != 0: dpw.WritePunctuation("(") @@ -703,7 +703,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol dpw.Write("accessor") dpw.WritePunctuation(") ") default: - decl := symbol.ValueDeclaration + decl := symbol.ValueDeclaration() if decl != nil { decl = ast.GetRootDeclaration(decl) switch { @@ -725,12 +725,12 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol } } } - if symbol.Name == ast.InternalSymbolNameExportEquals && symbol.Parent != nil && symbol.Parent.Flags&ast.SymbolFlagsModule != 0 { + if symbol.Name() == ast.InternalSymbolNameExportEquals && symbol.Parent() != nil && symbol.Parent().Flags()&ast.SymbolFlagsModule != 0 { dpw.Write("exports") } else { writeSymbolClassified(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags) } - if symbol.Flags&ast.SymbolFlagsOptional != 0 { + if symbol.Flags()&ast.SymbolFlagsOptional != 0 { dpw.WritePunctuation("?") } dpw.WritePunctuation(": ") @@ -746,7 +746,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol // If the type is a constrained type parameter, support expansion: // Level 0: show just "T", signal canIncreaseVerbosity // Level 1+: show "T extends Constraint" with the constraint expanded at level-1 - if vc != nil && t.Symbol() != nil && t.Symbol().Flags&ast.SymbolFlagsTypeParameter != 0 && c.GetConstraintOfTypeParameter(t) != nil { + if vc != nil && t.Symbol() != nil && t.Symbol().Flags()&ast.SymbolFlagsTypeParameter != 0 && c.GetConstraintOfTypeParameter(t) != nil { if vc.Level > 0 { expandVC := &checker.VerbosityContext{ Level: vc.Level - 1, @@ -763,7 +763,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol writeTypeClassified(t, container, typeFormatFlags) } } - setDeclaration(core.OrElse(symbol.ValueDeclaration, core.FirstOrNil(symbol.Declarations))) + setDeclaration(core.OrElse(symbol.ValueDeclaration(), core.FirstOrNil(symbol.Declarations()))) } if flags&ast.SymbolFlagsEnumMember != 0 { writeNewLine() @@ -776,12 +776,12 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol dpw.WriteOperator(" = ") dpw.WriteLiteral(t.AsLiteralType().String()) } - setDeclaration(symbol.ValueDeclaration) + setDeclaration(symbol.ValueDeclaration()) } if flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0 { isMethod := flags&ast.SymbolFlagsMethod != 0 prefix := core.IfElse(isMethod, "method", "function ") - if ast.IsIdentifier(node) && (ast.IsFunctionLikeDeclaration(node.Parent) || ast.IsMethodSignatureDeclaration(node.Parent)) && node.Parent.Name() == node && slices.Contains(symbol.Declarations, node.Parent) { + if ast.IsIdentifier(node) && (ast.IsFunctionLikeDeclaration(node.Parent) || ast.IsMethodSignatureDeclaration(node.Parent)) && node.Parent.Name() == node && slices.Contains(symbol.Declarations(), node.Parent) { setDeclaration(node.Parent) signatures := []*checker.Signature{c.GetSignatureFromDeclaration(node.Parent)} writeSignatures(signatures, prefix, isMethod, symbol) @@ -794,7 +794,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol } writeSignatures(signatures, prefix, isMethod, symbol) } - setDeclaration(symbol.ValueDeclaration) + setDeclaration(symbol.ValueDeclaration()) } if flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { if node.Kind == ast.KindThisKeyword || ast.IsThisInTypeQuery(node) { @@ -826,7 +826,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol } if !tryExpandSymbol(symbol, flags) { if classExpression == nil { - if core.Some(symbol.Declarations, func(d *ast.Node) bool { + if core.Some(symbol.Declarations(), func(d *ast.Node) bool { return ast.IsClassDeclaration(d) && ast.HasAbstractModifier(d) }) { dpw.WriteKeyword("abstract ") @@ -848,15 +848,15 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol } } if flags&ast.SymbolFlagsClass != 0 { - setDeclaration(symbol.ValueDeclaration) + setDeclaration(symbol.ValueDeclaration()) } else { - setDeclaration(core.Find(symbol.Declarations, ast.IsInterfaceDeclaration)) + setDeclaration(core.Find(symbol.Declarations(), ast.IsInterfaceDeclaration)) } } if flags&ast.SymbolFlagsEnum != 0 { writeNewLine() if !tryExpandSymbol(symbol, flags) { - if core.Some(symbol.Declarations, func(d *ast.Node) bool { + if core.Some(symbol.Declarations(), func(d *ast.Node) bool { return ast.IsEnumDeclaration(d) && ast.IsEnumConst(d) }) { dpw.WriteKeyword("const ") @@ -864,17 +864,17 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol dpw.WriteKeyword("enum ") writeSymbolClassified(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags) } - setDeclaration(core.Find(symbol.Declarations, ast.IsEnumDeclaration)) + setDeclaration(core.Find(symbol.Declarations(), ast.IsEnumDeclaration)) } if flags&ast.SymbolFlagsModule != 0 { writeNewLine() if !tryExpandSymbol(symbol, flags) { - isModule := symbol.ValueDeclaration != nil && (ast.IsSourceFile(symbol.ValueDeclaration) || ast.IsAmbientModule(symbol.ValueDeclaration)) + isModule := symbol.ValueDeclaration() != nil && (ast.IsSourceFile(symbol.ValueDeclaration()) || ast.IsAmbientModule(symbol.ValueDeclaration())) dpw.WriteKeyword(core.IfElse(isModule, "module ", "namespace ")) writeSymbolClassified(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags) writeModuleImportAttributes(symbol) } - setDeclaration(core.Find(symbol.Declarations, ast.IsModuleDeclaration)) + setDeclaration(core.Find(symbol.Declarations(), ast.IsModuleDeclaration)) } if flags&ast.SymbolFlagsTypeParameter != 0 { writeNewLine() @@ -894,11 +894,11 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol writeTypeClassified(cons, container, typeFormatFlags) } // Show context: "in ClassName" or "in funcName(...)" - if symbol.Parent != nil { + if symbol.Parent() != nil { // Class/Interface type parameter dpw.WriteKeyword(" in ") - writeSymbolClassified(symbol.Parent, container, ast.SymbolFlagsNone, symbolFormatFlags) - if parentType := c.GetDeclaredTypeOfSymbol(symbol.Parent); parentType.AsInterfaceType() != nil { + writeSymbolClassified(symbol.Parent(), container, ast.SymbolFlagsNone, symbolFormatFlags) + if parentType := c.GetDeclaredTypeOfSymbol(symbol.Parent()); parentType.AsInterfaceType() != nil { parentParams := parentType.AsInterfaceType().LocalTypeParameters() writeTypeParams(parentParams) } @@ -929,7 +929,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol } } } - setDeclaration(core.Find(symbol.Declarations, ast.IsTypeParameterDeclaration)) + setDeclaration(core.Find(symbol.Declarations(), ast.IsTypeParameterDeclaration)) } if flags&ast.SymbolFlagsTypeAlias != 0 { writeNewLine() @@ -944,7 +944,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol typeAliasType = c.GetDeclaredTypeOfSymbol(symbol) } writeTypeClassified(typeAliasType, container, typeFormatFlags|checker.TypeFormatFlagsInTypeAlias) - setDeclaration(core.Find(symbol.Declarations, ast.IsTypeOrJSTypeAliasDeclaration)) + setDeclaration(core.Find(symbol.Declarations(), ast.IsTypeOrJSTypeAliasDeclaration)) } if flags&ast.SymbolFlagsSignature != 0 { writeNewLine() diff --git a/tsc/internal/ls/importTracker.go b/tsc/internal/ls/importTracker.go index d87a0d1255768..e4aa7f94dd940 100644 --- a/tsc/internal/ls/importTracker.go +++ b/tsc/internal/ls/importTracker.go @@ -178,7 +178,7 @@ func getImportersForExport( var indirectUserDeclarations []*ast.Node markSeenDirectImport := nodeSeenTracker() markSeenIndirectUser := nodeSeenTracker() - isAvailableThroughGlobal := isSourceFileWithGlobalExports(exportInfo.exportingModuleSymbol.ValueDeclaration) + isAvailableThroughGlobal := isSourceFileWithGlobalExports(exportInfo.exportingModuleSymbol.ValueDeclaration()) getDirectImports := func(moduleSymbol *ast.Symbol) []*ast.Node { return allDirectImports[moduleSymbol] @@ -203,7 +203,7 @@ func getImportersForExport( if moduleSymbol == nil { return } - debug.Assert(moduleSymbol.Flags&ast.SymbolFlagsModule != 0) + debug.Assert(moduleSymbol.Flags()&ast.SymbolFlagsModule != 0) for _, directImport := range getDirectImports(moduleSymbol) { if !ast.IsImportTypeNode(directImport) { addIndirectUser(getSourceFileLikeForImportDeclaration(directImport), true /*addTransitiveDependencies*/) @@ -309,7 +309,7 @@ func getImportersForExport( return sourceFiles } // Module augmentations may use this module's exports without importing it. - for _, decl := range exportInfo.exportingModuleSymbol.Declarations { + for _, decl := range exportInfo.exportingModuleSymbol.Declarations() { if ast.IsExternalModuleAugmentation(decl) && sourceFilesSet.Has(ast.GetSourceFileOfNode(decl).FileName()) { addIndirectUser(decl, false) } @@ -357,7 +357,7 @@ func getSearchesFromDirectImports( isNameMatch := func(name string) bool { // Use name of "default" even in `export =` case because we may have allowSyntheticDefaultImports - return name == exportSymbol.Name || exportKind != ExportKindNamed && name == ast.InternalSymbolNameDefault + return name == exportSymbol.Name() || exportKind != ExportKindNamed && name == ast.InternalSymbolNameDefault } // `import x = require("./x")` or `import * as x from "./x"`. @@ -385,7 +385,7 @@ func getSearchesFromDirectImports( singleReferences = append(singleReferences, propertyName) // If renaming `{ foo as bar }`, don't touch `bar`, just `foo`. // But do rename `foo` in ` { default as foo }` if that's the original export name. - if !isForRename || name.Text() == exportSymbol.Name { + if !isForRename || name.Text() == exportSymbol.Name() { // Search locally for `bar`. addSearch(name, checker.GetSymbolAtLocation(name)) } @@ -475,7 +475,7 @@ func getImportOrExportSymbol(node *ast.Node, symbol *ast.Symbol, checker *checke getExport := func() *ImportExportSymbol { getExportAssignmentExport := func(ex *ast.Node) *ImportExportSymbol { // Get the symbol for the `export =` node; its parent is the module it's the export of. - if ex.Symbol().Parent == nil { + if ex.Symbol().Parent() == nil { return nil } exportKind := core.IfElse(ex.AsExportAssignment().IsExportEquals, ExportKindExportEquals, ExportKindDefault) @@ -483,7 +483,7 @@ func getImportOrExportSymbol(node *ast.Node, symbol *ast.Symbol, checker *checke kind: ImpExpKindExport, symbol: symbol, exportInfo: &ExportInfo{ - exportingModuleSymbol: ex.Symbol().Parent, + exportingModuleSymbol: ex.Symbol().Parent(), exportKind: exportKind, }, } @@ -519,16 +519,16 @@ func getImportOrExportSymbol(node *ast.Node, symbol *ast.Symbol, checker *checke parent := node.Parent grandparent := parent.Parent - if symbol.ExportSymbol != nil { + if symbol.ExportSymbol() != nil { if ast.IsPropertyAccessExpression(parent) { // When accessing an export of a JS module, there's no alias. The symbol will still be flagged as an export even though we're at the use. // So check that we are at the declaration. - if ast.IsBinaryExpression(grandparent) && slices.Contains(symbol.Declarations, parent) { + if ast.IsBinaryExpression(grandparent) && slices.Contains(symbol.Declarations(), parent) { return getSpecialPropertyExport(grandparent, false /*useLhsSymbol*/) } return nil } - return exportInfo(symbol.ExportSymbol, getExportKindForDeclaration(parent)) + return exportInfo(symbol.ExportSymbol(), getExportKindForDeclaration(parent)) } else { exportNode := getExportNode(parent, node) switch { @@ -569,7 +569,7 @@ func getImportOrExportSymbol(node *ast.Node, symbol *ast.Symbol, checker *checke // JS destructuring from `require(...)` is import-like for references, but the binding element // itself is still a local variable symbol rather than an alias. var importedSymbol *ast.Symbol - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { importedSymbol = checker.GetImmediateAliasedSymbol(symbol) } else { importedSymbol = getPropertySymbolOfObjectBindingPatternWithoutPropertyName(symbol, checker) @@ -583,7 +583,7 @@ func getImportOrExportSymbol(node *ast.Node, symbol *ast.Symbol, checker *checke return nil } // Similarly, skip past the symbol for 'export =' - if importedSymbol.Name == "export=" { + if importedSymbol.Name() == "export=" { importedSymbol = getExportEqualsLocalSymbol(importedSymbol, checker) if importedSymbol == nil { return nil @@ -593,7 +593,7 @@ func getImportOrExportSymbol(node *ast.Node, symbol *ast.Symbol, checker *checke // If `importedName` is undefined, do continue searching as the export is anonymous. // (All imports returned from this function will be ignored anyway if we are in rename and this is a not a named export.) importedName := symbolNameNoDefault(importedSymbol) - if importedName == "" || importedName == ast.InternalSymbolNameDefault || importedName == symbol.Name { + if importedName == "" || importedName == ast.InternalSymbolNameDefault || importedName == symbol.Name() { return &ImportExportSymbol{ kind: ImpExpKindImport, symbol: importedSymbol, @@ -611,8 +611,8 @@ func getImportOrExportSymbol(node *ast.Node, symbol *ast.Symbol, checker *checke func getExportInfo(exportSymbol *ast.Symbol, exportKind ExportKind, c *checker.Checker) *ExportInfo { // Parent can be nil if an `export` is not at the top-level (which is a compile error). - if exportSymbol.Parent != nil { - exportingModuleSymbol := c.GetMergedSymbol(exportSymbol.Parent) + if exportSymbol.Parent() != nil { + exportingModuleSymbol := c.GetMergedSymbol(exportSymbol.Parent()) // `export` may appear in a namespace. In that case, just rely on global search. if checker.IsExternalModuleSymbol(exportingModuleSymbol) { return &ExportInfo{ @@ -668,7 +668,7 @@ func isExternalModuleImportEquals(node *ast.Node) bool { // If at an export specifier, go to the symbol it refers to. */ func skipExportSpecifierSymbol(symbol *ast.Symbol, checker *checker.Checker) *ast.Symbol { // For `export { foo } from './bar", there's nothing to skip, because it does not create a new alias. But `export { foo } does. - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { switch { case ast.IsExportSpecifier(declaration) && declaration.PropertyName() == nil && declaration.Parent.Parent.ModuleSpecifier() == nil: return core.OrElse(checker.GetExportSpecifierLocalTargetSymbol(declaration), symbol) @@ -683,10 +683,10 @@ func skipExportSpecifierSymbol(symbol *ast.Symbol, checker *checker.Checker) *as } func getExportEqualsLocalSymbol(importedSymbol *ast.Symbol, checker *checker.Checker) *ast.Symbol { - if importedSymbol.Flags&ast.SymbolFlagsAlias != 0 { + if importedSymbol.Flags()&ast.SymbolFlagsAlias != 0 { return checker.GetImmediateAliasedSymbol(importedSymbol) } - decl := importedSymbol.ValueDeclaration + decl := importedSymbol.ValueDeclaration() debug.Assert(decl != nil) switch { case ast.IsExportAssignment(decl): @@ -700,10 +700,10 @@ func getExportEqualsLocalSymbol(importedSymbol *ast.Symbol, checker *checker.Che } func symbolNameNoDefault(symbol *ast.Symbol) string { - if symbol.Name != ast.InternalSymbolNameDefault { - return symbol.Name + if symbol.Name() != ast.InternalSymbolNameDefault { + return symbol.Name() } - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { name := ast.GetNameOfDeclaration(decl) if name != nil && ast.IsIdentifier(name) { return name.Text() @@ -718,7 +718,7 @@ func findModuleReferences(program *compiler.Program, sourceFiles []*ast.SourceFi refs := []ModuleReference{} for _, referencingFile := range sourceFiles { - searchSourceFile := searchModuleSymbol.ValueDeclaration + searchSourceFile := searchModuleSymbol.ValueDeclaration() if searchSourceFile != nil && searchSourceFile.Kind == ast.KindSourceFile { // Check directives for _, ref := range referencingFile.ReferencedFiles { diff --git a/tsc/internal/ls/inlay_hints.go b/tsc/internal/ls/inlay_hints.go index c84c1394fccea..b74c97e187a7b 100644 --- a/tsc/internal/ls/inlay_hints.go +++ b/tsc/internal/ls/inlay_hints.go @@ -304,7 +304,7 @@ func (s *inlayHintState) addParameterTypeHint(node *ast.ParameterDeclarationNode } func (s *inlayHintState) getParameterDeclarationTypeHints(symbol *ast.Symbol) *lsproto.StringOrInlayHintLabelParts { - valueDeclaration := symbol.ValueDeclaration + valueDeclaration := symbol.ValueDeclaration() if valueDeclaration == nil || !ast.IsParameterDeclaration(valueDeclaration) { return nil } @@ -437,7 +437,7 @@ func isHintableLiteral(node *ast.Node) bool { func isModuleReferenceType(t *checker.Type) bool { symbol := t.Symbol() - return symbol != nil && symbol.Flags&ast.SymbolFlagsModule != 0 + return symbol != nil && symbol.Flags()&ast.SymbolFlagsModule != 0 } func (s *inlayHintState) getInlayHintLabelParts(node *ast.Node, idToSymbol map[*ast.IdentifierNode]*ast.Symbol) []*lsproto.InlayHintLabelPart { @@ -467,8 +467,8 @@ func (s *inlayHintState) getInlayHintLabelParts(node *ast.Node, idToSymbol map[* case ast.KindIdentifier: identifierText := node.Text() var name *ast.Node - if symbol := idToSymbol[node]; symbol != nil && len(symbol.Declarations) != 0 { - name = ast.GetNameOfDeclaration(symbol.Declarations[0]) + if symbol := idToSymbol[node]; symbol != nil && len(symbol.Declarations()) != 0 { + name = ast.GetNameOfDeclaration(symbol.Declarations()[0]) } if name != nil { parts = append(parts, s.getNodeDisplayPart(identifierText, name)) @@ -891,7 +891,7 @@ func (s *inlayHintState) getParameterIdentifierInfoAtPosition(signature *checker if pos == paramCount { return ¶meterInfo{ parameter: restId, - name: restParameter.Name, + name: restParameter.Name(), isRestParameter: true, } } @@ -899,8 +899,8 @@ func (s *inlayHintState) getParameterIdentifierInfoAtPosition(signature *checker } func getParameterDeclarationIdentifier(symbol *ast.Symbol) *ast.IdentifierNode { - if symbol.ValueDeclaration != nil && ast.IsParameterDeclaration(symbol.ValueDeclaration) && ast.IsIdentifier(symbol.ValueDeclaration.Name()) { - return symbol.ValueDeclaration.Name() + if symbol.ValueDeclaration() != nil && ast.IsParameterDeclaration(symbol.ValueDeclaration()) && ast.IsIdentifier(symbol.ValueDeclaration().Name()) { + return symbol.ValueDeclaration().Name() } return nil } diff --git a/tsc/internal/ls/jsdoc.go b/tsc/internal/ls/jsdoc.go index 3e7aadf363999..c3ac3eb1cbef6 100644 --- a/tsc/internal/ls/jsdoc.go +++ b/tsc/internal/ls/jsdoc.go @@ -31,7 +31,7 @@ func GetSymbolDocumentationComment(c *checker.Checker, symbol *ast.Symbol) strin } var parts []string var seen collections.Set[*ast.Node] - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { if decl == nil { continue } @@ -54,7 +54,7 @@ func GetSymbolJSDocTags(symbol *ast.Symbol) []JSDocTagInfo { } var infos []JSDocTagInfo var seen collections.Set[*ast.Node] - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { if decl == nil { continue } @@ -191,7 +191,7 @@ func getJSDocOrTag(c *checker.Checker, node *ast.Node, seenSymbols *collections. if name := node.PropertyNameOrName(); ast.IsIdentifier(name) { if objectType := c.GetTypeAtLocation(node.Parent); objectType != nil { if prop := c.GetPropertyOfType(objectType, name.Text()); prop != nil { - for _, d := range prop.Declarations { + for _, d := range prop.Declarations() { if jsdoc := getJSDoc(d); jsdoc != nil { return jsdoc } @@ -202,7 +202,7 @@ func getJSDocOrTag(c *checker.Checker, node *ast.Node, seenSymbols *collections. } if symbol := node.Symbol(); symbol != nil && node.Parent != nil { if ast.IsFunctionDeclaration(node) || ast.IsMethodDeclaration(node) || ast.IsMethodSignatureDeclaration(node) || ast.IsConstructorDeclaration(node) || ast.IsConstructSignatureDeclaration(node) { - firstSignature := core.Find(symbol.Declarations, ast.IsFunctionLike) + firstSignature := core.Find(symbol.Declarations(), ast.IsFunctionLike) if firstSignature != nil && node != firstSignature { if jsDoc := getJSDocOrTag(c, firstSignature, seenSymbols); jsDoc != nil { return jsDoc @@ -217,15 +217,15 @@ func getJSDocOrTag(c *checker.Checker, node *ast.Node, seenSymbols *collections. // This correctly handles intersection constructor types from mixins // (e.g., typeof MixinClass & T) by preserving the full intersection. staticBaseType := c.GetApparentType(c.GetBaseConstructorTypeOfClass(classType)) - if prop := c.GetPropertyOfType(staticBaseType, symbol.Name); prop != nil && prop.ValueDeclaration != nil && seenSymbols.AddIfAbsent(prop) { - if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration, seenSymbols); jsDoc != nil { + if prop := c.GetPropertyOfType(staticBaseType, symbol.Name()); prop != nil && prop.ValueDeclaration() != nil && seenSymbols.AddIfAbsent(prop) { + if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration(), seenSymbols); jsDoc != nil { return jsDoc } } } else { for _, baseType := range c.GetBaseTypes(classType) { - if prop := c.GetPropertyOfType(baseType, symbol.Name); prop != nil && prop.ValueDeclaration != nil && seenSymbols.AddIfAbsent(prop) { - if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration, seenSymbols); jsDoc != nil { + if prop := c.GetPropertyOfType(baseType, symbol.Name()); prop != nil && prop.ValueDeclaration() != nil && seenSymbols.AddIfAbsent(prop) { + if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration(), seenSymbols); jsDoc != nil { return jsDoc } } diff --git a/tsc/internal/ls/lsutil/symbol_display.go b/tsc/internal/ls/lsutil/symbol_display.go index 0f1fee4527494..58c9f01b70760 100644 --- a/tsc/internal/ls/lsutil/symbol_display.go +++ b/tsc/internal/ls/lsutil/symbol_display.go @@ -208,7 +208,7 @@ func getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker * // If this is a method from a mapped type, leave as a method so long as it still has a call signature, as opposed to e.g. // `{ [K in keyof I]: number }`. if len(roots) == 1 && - roots[0].Flags&ast.SymbolFlagsMethod != 0 && + roots[0].Flags()&ast.SymbolFlagsMethod != 0 && (typeChecker == nil || len(typeChecker.GetCallSignatures(typeChecker.GetNonNullableType(typeChecker.GetTypeOfSymbolAtLocation(symbol, location)))) > 0) { return ScriptElementKindMemberFunctionElement } @@ -230,13 +230,13 @@ func getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker * if flags&ast.SymbolFlagsVariable != 0 { if isFirstDeclarationOfSymbolParameter(symbol) { return ScriptElementKindParameterElement - } else if symbol.ValueDeclaration != nil && ast.IsVarConst(symbol.ValueDeclaration) { + } else if symbol.ValueDeclaration() != nil && ast.IsVarConst(symbol.ValueDeclaration()) { return ScriptElementKindConstElement - } else if symbol.ValueDeclaration != nil && ast.IsVarUsing(symbol.ValueDeclaration) { + } else if symbol.ValueDeclaration() != nil && ast.IsVarUsing(symbol.ValueDeclaration()) { return ScriptElementKindVariableUsingElement - } else if symbol.ValueDeclaration != nil && ast.IsVarAwaitUsing(symbol.ValueDeclaration) { + } else if symbol.ValueDeclaration() != nil && ast.IsVarAwaitUsing(symbol.ValueDeclaration()) { return ScriptElementKindVariableAwaitUsingElement - } else if core.Some(symbol.Declarations, ast.IsLet) { + } else if core.Some(symbol.Declarations(), ast.IsLet) { return ScriptElementKindLetElement } if isLocalVariableOrFunction(symbol) { @@ -269,11 +269,11 @@ func getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker * } if flags&ast.SymbolFlagsProperty != 0 { - if typeChecker != nil && flags&ast.SymbolFlagsTransient != 0 && symbol.CheckFlags&ast.CheckFlagsSynthetic != 0 { + if typeChecker != nil && flags&ast.SymbolFlagsTransient != 0 && symbol.CheckFlags()&ast.CheckFlagsSynthetic != 0 { // If union property is result of union of non method (property/accessors/variables), it is labeled as property var unionPropertyKind ScriptElementKind for _, rootSymbol := range roots { - if rootSymbol.Flags&(ast.SymbolFlagsPropertyOrAccessor|ast.SymbolFlagsVariable) != 0 { + if rootSymbol.Flags()&(ast.SymbolFlagsPropertyOrAccessor|ast.SymbolFlagsVariable) != 0 { unionPropertyKind = ScriptElementKindMemberVariableElement break } @@ -298,8 +298,8 @@ func getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker * func isFirstDeclarationOfSymbolParameter(symbol *ast.Symbol) bool { var declaration *ast.Node - if len(symbol.Declarations) > 0 { - declaration = symbol.Declarations[0] + if len(symbol.Declarations()) > 0 { + declaration = symbol.Declarations()[0] } result := ast.FindAncestorOrQuit(declaration, func(n *ast.Node) ast.FindAncestorResult { if ast.IsParameterDeclaration(n) { @@ -315,11 +315,11 @@ func isFirstDeclarationOfSymbolParameter(symbol *ast.Symbol) bool { } func isLocalVariableOrFunction(symbol *ast.Symbol) bool { - if symbol.Parent != nil { + if symbol.Parent() != nil { return false // This is exported symbol } - for _, decl := range symbol.Declarations { + for _, decl := range symbol.Declarations() { // Function expressions are local if decl.Kind == ast.KindFunctionExpression { return true @@ -352,13 +352,13 @@ func GetSymbolModifiers(typeChecker *checker.Checker, symbol *ast.Symbol) Script } modifiers := getNormalizedSymbolModifiers(typeChecker, symbol) - if symbol.Flags&ast.SymbolFlagsAlias != 0 && typeChecker != nil { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 && typeChecker != nil { resolvedSymbol := typeChecker.GetAliasedSymbol(symbol) if resolvedSymbol != symbol { modifiers |= getNormalizedSymbolModifiers(typeChecker, resolvedSymbol) } } - if symbol.Flags&ast.SymbolFlagsOptional != 0 { + if symbol.Flags()&ast.SymbolFlagsOptional != 0 { modifiers |= ScriptElementKindModifierOptional } @@ -367,9 +367,9 @@ func GetSymbolModifiers(typeChecker *checker.Checker, symbol *ast.Symbol) Script func getNormalizedSymbolModifiers(typeChecker *checker.Checker, symbol *ast.Symbol) ScriptElementKindModifier { var modifierSet ScriptElementKindModifier - if len(symbol.Declarations) > 0 { - declaration := symbol.Declarations[0] - declarations := symbol.Declarations[1:] + if len(symbol.Declarations()) > 0 { + declaration := symbol.Declarations()[0] + declarations := symbol.Declarations()[1:] // omit deprecated flag if some declarations are not deprecated var excludeFlags ast.ModifierFlags if len(declarations) > 0 && diff --git a/tsc/internal/ls/lsutil/utilities.go b/tsc/internal/ls/lsutil/utilities.go index 69c50f1cc9dd5..bd85ec586f839 100644 --- a/tsc/internal/ls/lsutil/utilities.go +++ b/tsc/internal/ls/lsutil/utilities.go @@ -113,7 +113,7 @@ func GetQuotePreference(sourceFile *ast.SourceFile, preferences UserPreferences) } func ModuleSymbolToValidIdentifier(moduleSymbol *ast.Symbol, forceCapitalize bool) string { - moduleName := moduleSymbol.Name + moduleName := moduleSymbol.Name() if ambientModuleName, ok := ast.TryGetAmbientModuleNameFromSymbolName(moduleName); ok { moduleName = ambientModuleName } diff --git a/tsc/internal/ls/rename.go b/tsc/internal/ls/rename.go index a41cea3ca0b8a..3415142ae6545 100644 --- a/tsc/internal/ls/rename.go +++ b/tsc/internal/ls/rename.go @@ -188,7 +188,7 @@ func (l *LanguageService) getRenameInfoForNode(ctx context.Context, newName stri } // Only allow a symbol to be renamed if it actually has at least one declaration. - if len(symbol.Declarations) == 0 { + if len(symbol.Declarations()) == 0 { return RenameInfo{}, false } @@ -227,14 +227,14 @@ func nodeIsEligibleForRename(node *ast.Node) bool { // renameBlockedReason returns a non-nil diagnostic message if the rename should be blocked // because the symbol is a library definition, a default keyword, or would cross node_modules boundaries. func (l *LanguageService) renameBlockedReason(sourceFile *ast.SourceFile, node *ast.Node, symbol *ast.Symbol, ch *checker.Checker, program *compiler.Program) *diagnostics.Message { - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if isDefinedInLibraryFile(program, declaration) { return diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library } } // Cannot rename `default` as in `import { default as foo } from "./someModule"` - if ast.IsIdentifier(node) && node.Text() == "default" && symbol.Parent != nil && symbol.Parent.Flags&ast.SymbolFlagsModule != 0 { + if ast.IsIdentifier(node) && node.Text() == "default" && symbol.Parent() != nil && symbol.Parent().Flags()&ast.SymbolFlagsModule != 0 { return diagnostics.You_cannot_rename_this_element } @@ -254,14 +254,14 @@ func isDefinedInLibraryFile(program *compiler.Program, declaration *ast.Node) bo // wouldRenameInOtherNodeModules checks if renaming the symbol would affect node_modules. func wouldRenameInOtherNodeModules(originalFile *ast.SourceFile, symbol *ast.Symbol, ch *checker.Checker, preferences lsutil.UserPreferences) *diagnostics.Message { sym := symbol - if !preferences.ProvidePrefixAndSuffixTextForRename.IsTrueOrUnknown() && sym.Flags&ast.SymbolFlagsAlias != 0 { - importSpecifier := core.Find(sym.Declarations, ast.IsImportSpecifier) + if !preferences.ProvidePrefixAndSuffixTextForRename.IsTrueOrUnknown() && sym.Flags()&ast.SymbolFlagsAlias != 0 { + importSpecifier := core.Find(sym.Declarations(), ast.IsImportSpecifier) if importSpecifier != nil && importSpecifier.AsImportSpecifier().PropertyName == nil { sym = ch.GetAliasedSymbol(sym) } } - declarations := sym.Declarations + declarations := sym.Declarations() if len(declarations) == 0 { return nil } @@ -308,7 +308,7 @@ func (l *LanguageService) getRenameInfoForModule(ctx context.Context, newName st return getRenameInfoError(ctx, diagnostics.File_rename_is_not_supported_by_the_editor), true } - moduleSourceFile := core.Find(moduleSymbol.Declarations, ast.IsSourceFile) + moduleSourceFile := core.Find(moduleSymbol.Declarations(), ast.IsSourceFile) if moduleSourceFile == nil { return RenameInfo{}, false } @@ -407,7 +407,7 @@ func (l *LanguageService) getTextForRename(originalNode *ast.Node, entry *Refere } else { originalSymbol = ch.GetSymbolAtLocation(originalNode) } - if originalSymbol != nil && slices.Contains(originalSymbol.Declarations, parent) { + if originalSymbol != nil && slices.Contains(originalSymbol.Declarations(), parent) { return name + " as " + newText } return newText diff --git a/tsc/internal/ls/semantictokens.go b/tsc/internal/ls/semantictokens.go index 24d4ca9c89f59..8580d0e0f48fc 100644 --- a/tsc/internal/ls/semantictokens.go +++ b/tsc/internal/ls/semantictokens.go @@ -257,7 +257,7 @@ func (l *LanguageService) collectSemanticTokensInRange(ctx context.Context, c *c symbol := c.GetSymbolAtLocation(node) if symbol != nil { // Resolve aliases - if symbol.Flags&ast.SymbolFlagsAlias != 0 { + if symbol.Flags()&ast.SymbolFlagsAlias != 0 { symbol = c.GetAliasedSymbol(symbol) } @@ -283,7 +283,7 @@ func (l *LanguageService) collectSemanticTokensInRange(ctx context.Context, c *c tokenType = reclassifyByType(c, node, tokenType) // Get the value declaration to check modifiers - if decl := symbol.ValueDeclaration; decl != nil { + if decl := symbol.ValueDeclaration(); decl != nil { modifiers := ast.GetCombinedModifierFlags(decl) nodeFlags := ast.GetCombinedNodeFlags(decl) @@ -294,7 +294,7 @@ func (l *LanguageService) collectSemanticTokensInRange(ctx context.Context, c *c tokenModifier |= tokenModifierAsync } if tokenType != tokenTypeClass && tokenType != tokenTypeInterface { - if (modifiers&ast.ModifierFlagsReadonly != 0) || (nodeFlags&ast.NodeFlagsConst != 0) || (symbol.Flags&ast.SymbolFlagsEnumMember != 0) { + if (modifiers&ast.ModifierFlagsReadonly != 0) || (nodeFlags&ast.NodeFlagsConst != 0) || (symbol.Flags()&ast.SymbolFlagsEnumMember != 0) { tokenModifier |= tokenModifierReadonly } } @@ -305,8 +305,8 @@ func (l *LanguageService) collectSemanticTokensInRange(ctx context.Context, c *c if declSourceFile != nil && program.IsSourceFileDefaultLibrary(declSourceFile.PathKey()) { tokenModifier |= tokenModifierDefaultLibrary } - } else if symbol.Declarations != nil { - for _, decl := range symbol.Declarations { + } else if symbol.Declarations() != nil { + for _, decl := range symbol.Declarations() { declSourceFile := ast.GetSourceFileOfNode(decl) if declSourceFile != nil && program.IsSourceFileDefaultLibrary(declSourceFile.PathKey()) { tokenModifier |= tokenModifierDefaultLibrary @@ -340,7 +340,7 @@ func (l *LanguageService) collectSemanticTokensInRange(ctx context.Context, c *c } func classifySymbol(symbol *ast.Symbol, meaning ast.SemanticMeaning) (tokenType, bool) { - flags := symbol.Flags + flags := symbol.Flags() if flags&ast.SymbolFlagsClass != 0 { return tokenTypeClass, true } @@ -360,9 +360,9 @@ func classifySymbol(symbol *ast.Symbol, meaning ast.SemanticMeaning) (tokenType, } // Check the value declaration - decl := symbol.ValueDeclaration - if decl == nil && len(symbol.Declarations) > 0 { - decl = symbol.Declarations[0] + decl := symbol.ValueDeclaration() + if decl == nil && len(symbol.Declarations()) > 0 { + decl = symbol.Declarations()[0] } if decl != nil { if ast.IsBindingElement(decl) { diff --git a/tsc/internal/ls/signaturehelp.go b/tsc/internal/ls/signaturehelp.go index 6e1fce510d96c..423c84dc0759b 100644 --- a/tsc/internal/ls/signaturehelp.go +++ b/tsc/internal/ls/signaturehelp.go @@ -319,7 +319,7 @@ func (l *LanguageService) createSignatureHelpItems(ctx context.Context, candidat // "\xFEtype". There is no meaningful name to show, so render the signature with // no prefix (as we already do when there is no call target symbol) rather than // leaking the internal name. - if callTargetSymbol != nil && !strings.HasPrefix(callTargetSymbol.Name, ast.InternalSymbolNamePrefix) { + if callTargetSymbol != nil && !strings.HasPrefix(callTargetSymbol.Name(), ast.InternalSymbolNamePrefix) { if useFullPrefix { callTargetDisplayParts.WriteString(c.SymbolToStringEx(callTargetSymbol, sourceFile.AsNode(), ast.SymbolFlagsNone, checker.SymbolFormatFlagsUseAliasDefinedOutsideCurrentScope)) } else { @@ -631,7 +631,7 @@ func (l *LanguageService) itemInfoForParameters(candidateSignature *checker.Sign if len(lists) == 1 { return true } - return len(parameterList) != 0 && parameterList[len(parameterList)-1] != nil && (parameterList[len(parameterList)-1].CheckFlags&ast.CheckFlagsRestParameter != 0) + return len(parameterList) != 0 && parameterList[len(parameterList)-1] != nil && (parameterList[len(parameterList)-1].CheckFlags()&ast.CheckFlagsRestParameter != 0) } result := make([]*signatureHelpItemInfo, len(lists)) @@ -672,11 +672,11 @@ const signatureHelpNodeBuilderFlags = nodebuilder.FlagsOmitParameterModifiers | // createSignatureHelpParameterFromLabel creates a signatureHelpParameter from a pre-computed label string. func (l *LanguageService) createSignatureHelpParameterFromLabel(parameter *ast.Symbol, label string, c *checker.Checker, docFormat lsproto.MarkupKind) signatureHelpParameter { - isOptional := parameter.CheckFlags&ast.CheckFlagsOptionalParameter != 0 - isRest := parameter.CheckFlags&ast.CheckFlagsRestParameter != 0 + isOptional := parameter.CheckFlags()&ast.CheckFlagsOptionalParameter != 0 + isRest := parameter.CheckFlags()&ast.CheckFlagsRestParameter != 0 var documentation *lsproto.StringOrMarkupContent - if parameter.ValueDeclaration != nil { - doc := getDocumentationFromDeclaration(l.documentationLocationMapper(spanmap.FeatureSignatureHelp), c, nil, parameter.ValueDeclaration, nil, docFormat, true /*commentOnly*/) + if parameter.ValueDeclaration() != nil { + doc := getDocumentationFromDeclaration(l.documentationLocationMapper(spanmap.FeatureSignatureHelp), c, nil, parameter.ValueDeclaration(), nil, docFormat, true /*commentOnly*/) if doc != "" { documentation = &lsproto.StringOrMarkupContent{ MarkupContent: &lsproto.MarkupContent{ @@ -1307,8 +1307,8 @@ func tryGetParameterInfo(startingToken *ast.Node, sourceFile *ast.SourceFile, c } func chooseBetterSymbol(s *ast.Symbol) *ast.Symbol { - if s.Name == ast.InternalSymbolNameType { - for _, d := range s.Declarations { + if s.Name() == ast.InternalSymbolNameType { + for _, d := range s.Declarations() { if ast.IsFunctionTypeNode(d) && ast.CanHaveSymbol(d.Parent) { return d.Parent.Symbol() } diff --git a/tsc/internal/ls/sourcedefinition.go b/tsc/internal/ls/sourcedefinition.go index 2ad3e3808b9b7..58eeda3b7b22e 100644 --- a/tsc/internal/ls/sourcedefinition.go +++ b/tsc/internal/ls/sourcedefinition.go @@ -230,7 +230,7 @@ func getSourceDefCheckerInfo( if len(declarations) == 0 && isPropertyName { if left := node.Parent.Expression(); left != nil { if prop := c.GetPropertyOfType(c.GetTypeAtLocation(left), node.Text()); prop != nil { - declarations = prop.Declarations + declarations = prop.Declarations() } } } @@ -254,7 +254,7 @@ func getSourceDefCheckerInfo( } } if sym := c.GetSymbolAtLocation(resolveNode); sym != nil { - for _, d := range sym.Declarations { + for _, d := range sym.Declarations() { if !ast.IsImportSpecifier(d) && !ast.IsImportClause(d) && !ast.IsNamespaceImport(d) && !ast.IsImportEqualsDeclaration(d) { continue } diff --git a/tsc/internal/ls/string_completions.go b/tsc/internal/ls/string_completions.go index dafb552280c38..c453bb239d3a5 100644 --- a/tsc/internal/ls/string_completions.go +++ b/tsc/internal/ls/string_completions.go @@ -400,7 +400,7 @@ func (l *LanguageService) getStringLiteralCompletionEntries( return n.PropertyNameOrName().Text() })...) uniques := core.Filter(exports, func(e *ast.Symbol) bool { - return e.Name != ast.InternalSymbolNameDefault && !existing.Has(e.Name) + return e.Name() != ast.InternalSymbolNameDefault && !existing.Has(e.Name()) }) return &stringLiteralCompletions{ fromProperties: &completionsFromProperties{ @@ -415,7 +415,7 @@ func (l *LanguageService) getStringLiteralCompletionEntries( return &stringLiteralCompletions{ fromProperties: &completionsFromProperties{ symbols: core.Filter(properties, func(s *ast.Symbol) bool { - return s.ValueDeclaration == nil || !ast.IsPrivateIdentifierClassElementDeclaration(s.ValueDeclaration) + return s.ValueDeclaration() == nil || !ast.IsPrivateIdentifierClassElementDeclaration(s.ValueDeclaration()) }), hasIndexSignature: false, }, @@ -522,7 +522,7 @@ func fromUnionableLiteralType( fromProperties: &completionsFromProperties{ symbols: core.Filter( result.symbols, - func(s *ast.Symbol) bool { return !slices.Contains(alreadyUsedTypes, s.Name) }, + func(s *ast.Symbol) bool { return !slices.Contains(alreadyUsedTypes, s.Name()) }, ), hasIndexSignature: result.hasIndexSignature, }, @@ -578,7 +578,7 @@ func stringLiteralCompletionsForObjectLiteral( func stringLiteralCompletionsFromProperties(t *checker.Type, typeChecker *checker.Checker) *completionsFromProperties { return &completionsFromProperties{ symbols: core.Filter(typeChecker.GetApparentProperties(t), func(s *ast.Symbol) bool { - return !(s.ValueDeclaration != nil && ast.IsPrivateIdentifierClassElementDeclaration(s.ValueDeclaration)) + return !(s.ValueDeclaration() != nil && ast.IsPrivateIdentifierClassElementDeclaration(s.ValueDeclaration())) }), hasIndexSignature: hasIndexSignature(t, typeChecker), } @@ -929,7 +929,7 @@ func getAmbientModuleName(symbol *ast.Symbol) string { if declaration != nil && ast.IsModuleWithStringLiteralName(declaration) { return declaration.Name().Text() } - return stringutil.StripQuotes(symbol.Name) + return stringutil.StripQuotes(symbol.Name()) } func (l *LanguageService) getCompletionEntriesFromTypings( @@ -2089,7 +2089,7 @@ func (l *LanguageService) stringLiteralCompletionDetails( case completion.fromProperties != nil: properties := completion.fromProperties for _, symbol := range properties.symbols { - if symbol.Name == name { + if symbol.Name() == name { return l.createCompletionDetailsForSymbol(item, symbol, checker, location, position, docFormat) } } diff --git a/tsc/internal/ls/utilities.go b/tsc/internal/ls/utilities.go index 1ba73cc62d9fd..a05994440d530 100644 --- a/tsc/internal/ls/utilities.go +++ b/tsc/internal/ls/utilities.go @@ -60,11 +60,11 @@ func isModuleSpecifierLike(node *ast.Node) bool { } func getNonModuleSymbolOfMergedModuleSymbol(symbol *ast.Symbol) *ast.Symbol { - if len(symbol.Declarations) == 0 || (symbol.Flags&(ast.SymbolFlagsModule|ast.SymbolFlagsTransient)) == 0 { + if len(symbol.Declarations()) == 0 || (symbol.Flags()&(ast.SymbolFlagsModule|ast.SymbolFlagsTransient)) == 0 { return nil } - if decl := core.Find(symbol.Declarations, func(d *ast.Node) bool { return !ast.IsSourceFile(d) && !ast.IsModuleDeclaration(d) }); decl != nil { + if decl := core.Find(symbol.Declarations(), func(d *ast.Node) bool { return !ast.IsSourceFile(d) && !ast.IsModuleDeclaration(d) }); decl != nil { return decl.Symbol() } return nil @@ -386,10 +386,10 @@ func isRightSideOfPropertyAccess(node *ast.Node) bool { } func isStaticSymbol(symbol *ast.Symbol) bool { - if symbol.ValueDeclaration == nil { + if symbol.ValueDeclaration() == nil { return false } - modifierFlags := symbol.ValueDeclaration.ModifierFlags() + modifierFlags := symbol.ValueDeclaration().ModifierFlags() return modifierFlags&ast.ModifierFlagsStatic != 0 } @@ -884,7 +884,7 @@ func getIntersectingMeaningFromDeclarations(node *ast.Node, symbol *ast.Symbol, } meaning := getMeaningFromLocation(node) - declarations := symbol.Declarations + declarations := symbol.Declarations() if len(declarations) == 0 { return meaning } @@ -943,11 +943,11 @@ func getParentSymbolsOfPropertyAccess(location *ast.Node, symbol *ast.Symbol, ch var possibleSymbols []*checker.Type if lhsType.Flags()&checker.TypeFlagsUnionOrIntersection != 0 { possibleSymbols = lhsType.Types() - } else if lhsType.Symbol() != symbol.Parent { + } else if lhsType.Symbol() != symbol.Parent() { possibleSymbols = []*checker.Type{lhsType} } return core.MapNonNil(possibleSymbols, func(t *checker.Type) *ast.Symbol { - if t.Symbol() != nil && t.Symbol().Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { + if t.Symbol() != nil && t.Symbol().Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0 { return t.Symbol() } return nil @@ -968,10 +968,10 @@ func getPropertySymbolsFromBaseTypes(symbol *ast.Symbol, propertyName string, ch // interface C extends C { // /*findRef*/propName: string; // } - if symbol.Flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) == 0 || !seen.AddIfAbsent(symbol) { + if symbol.Flags()&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) == 0 || !seen.AddIfAbsent(symbol) { return nil } - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { for _, typeReference := range getAllSuperTypeNodes(declaration) { if propertyType := checker.GetTypeAtLocation(typeReference); propertyType != nil && propertyType.Symbol() != nil { // Visit the typeReference as well to see if it directly or indirectly uses that property @@ -1090,8 +1090,8 @@ func newCaseClauseTracker(typeChecker *checker.Checker, clauses []*ast.CaseOrDef } } else { symbol := typeChecker.GetSymbolAtLocation(clause.Expression()) - if symbol != nil && symbol.ValueDeclaration != nil && ast.IsEnumMember(symbol.ValueDeclaration) { - enumValue := typeChecker.GetConstantValue(symbol.ValueDeclaration) + if symbol != nil && symbol.ValueDeclaration() != nil && ast.IsEnumMember(symbol.ValueDeclaration()) { + enumValue := typeChecker.GetConstantValue(symbol.ValueDeclaration()) if enumValue != nil { c.addValue(enumValue) } diff --git a/tsc/internal/modulespecifiers/specifiers.go b/tsc/internal/modulespecifiers/specifiers.go index 22a8102c0642a..96357d5d77005 100644 --- a/tsc/internal/modulespecifiers/specifiers.go +++ b/tsc/internal/modulespecifiers/specifiers.go @@ -110,7 +110,7 @@ type ambientModuleInfo struct { } func tryGetModuleNameFromAmbientModule(moduleSymbol *ast.Symbol, checker CheckerShape) ambientModuleInfo { - for _, decl := range moduleSymbol.Declarations { + for _, decl := range moduleSymbol.Declarations() { if ast.IsModuleWithStringLiteralName(decl) && (!ast.IsModuleAugmentationExternal(decl) || !tspath.IsExternalModuleNameRelative(decl.Name().Text())) { return ambientModuleInfo{name: tspath.ToModuleSpecifier(decl.Name().Text()), symbol: moduleSymbol} } @@ -126,7 +126,7 @@ func tryGetModuleNameFromAmbientModule(moduleSymbol *ast.Symbol, checker Checker * } */ // `import {c} from "m";` is valid, in which case, `moduleSymbol` is "ns", but the module name should be "m" - for _, d := range moduleSymbol.Declarations { + for _, d := range moduleSymbol.Declarations() { if !ast.IsModuleDeclaration(d) { continue } @@ -136,11 +136,11 @@ func tryGetModuleNameFromAmbientModule(moduleSymbol *ast.Symbol, checker Checker continue } - sym, ok := possibleContainer.Symbol().Exports[ast.InternalSymbolNameExportEquals] + sym, ok := possibleContainer.Symbol().Exports()[ast.InternalSymbolNameExportEquals] if !ok || sym == nil { continue } - exportAssignmentDecl := sym.ValueDeclaration + exportAssignmentDecl := sym.ValueDeclaration() if exportAssignmentDecl == nil || exportAssignmentDecl.Kind != ast.KindExportAssignment { continue } @@ -148,7 +148,7 @@ func tryGetModuleNameFromAmbientModule(moduleSymbol *ast.Symbol, checker Checker if exportSymbol == nil { continue } - if exportSymbol.Flags&ast.SymbolFlagsAlias != 0 { + if exportSymbol.Flags()&ast.SymbolFlagsAlias != 0 { exportSymbol = checker.GetAliasedSymbol(exportSymbol) } // TODO: Possible strada bug - isn't this insufficient in the presence of merge symbols? diff --git a/tsc/internal/printer/namegenerator.go b/tsc/internal/printer/namegenerator.go index be0e4d5741a7a..81078f087a3bd 100644 --- a/tsc/internal/printer/namegenerator.go +++ b/tsc/internal/printer/namegenerator.go @@ -366,7 +366,7 @@ func isUniqueLocalName(name string, container *ast.Node) bool { locals := node.Locals() if locals != nil { // We conservatively include alias symbols to cover cases where they're emitted as locals - if local, ok := locals[name]; ok && local.Flags&(ast.SymbolFlagsValue|ast.SymbolFlagsExportValue|ast.SymbolFlagsAlias) != 0 { + if local, ok := locals[name]; ok && local.Flags()&(ast.SymbolFlagsValue|ast.SymbolFlagsExportValue|ast.SymbolFlagsAlias) != 0 { return false } } diff --git a/tsc/internal/pseudochecker/lookup.go b/tsc/internal/pseudochecker/lookup.go index c2693a7ab1552..3fc7243df41f5 100644 --- a/tsc/internal/pseudochecker/lookup.go +++ b/tsc/internal/pseudochecker/lookup.go @@ -127,7 +127,7 @@ func (ch *PseudoChecker) typeFromVariable(declaration *ast.VariableDeclaration) return NewPseudoTypeDirect(t) } init := declaration.Initializer - if init != nil && declaration.Symbol != nil && (len(declaration.Symbol.Declarations) == 1 || core.CountWhere(declaration.Symbol.Declarations, ast.IsVariableDeclaration) == 1) { + if init != nil && declaration.Symbol != nil && (len(declaration.Symbol.Declarations()) == 1 || core.CountWhere(declaration.Symbol.Declarations(), ast.IsVariableDeclaration) == 1) { if !isContextuallyTyped(declaration.AsNode()) { // TODO: also should bail on expando declarations; reuse syntactic expando check used in declaration emit // TODO: Strada forces an inference fallback on `const` variables with template expression initializers, to leave space for template literal freshness in the future if ast.IsVarConst(declaration.AsNode()) && ast.IsTemplateExpression(init) { @@ -144,7 +144,7 @@ func (ch *PseudoChecker) typeFromVariable(declaration *ast.VariableDeclaration) } func (ch *PseudoChecker) typeFromAccessor(accessor *ast.Node) *PseudoType { - accessorDeclarations := ast.GetAllAccessorDeclarationsForDeclaration(accessor, accessor.DeclarationData().Symbol.Declarations) + accessorDeclarations := ast.GetAllAccessorDeclarationsForDeclaration(accessor, accessor.DeclarationData().Symbol.Declarations()) accessorType := ch.getTypeAnnotationFromAllAccessorDeclarations(accessor, accessorDeclarations) if accessorType != nil && !ast.IsTypePredicateNode(accessorType) { return NewPseudoTypeDirect(accessorType) @@ -361,7 +361,7 @@ func (ch *PseudoChecker) typeFromObjectLiteral(node *ast.ObjectLiteralExpression // roughly analogous to typeFromObjectLiteralAccessor in strada func (ch *PseudoChecker) getAccessorMember(accessor *ast.Node, name *ast.Node) *PseudoObjectElement { - allAccessors := ast.GetAllAccessorDeclarationsForDeclaration(accessor, accessor.Symbol().Declarations) // TODO: node preservation for late-bound accessor pairs? + allAccessors := ast.GetAllAccessorDeclarationsForDeclaration(accessor, accessor.Symbol().Declarations()) // TODO: node preservation for late-bound accessor pairs? // TODO: handle pseudo-annotations from get accessor return positions? if allAccessors.GetAccessor != nil && allAccessors.GetAccessor.Type != nil && diff --git a/tsc/internal/testutil/tsbaseline/type_symbol_baseline.go b/tsc/internal/testutil/tsbaseline/type_symbol_baseline.go index 343a85a74e973..0c800eca06752 100644 --- a/tsc/internal/testutil/tsbaseline/type_symbol_baseline.go +++ b/tsc/internal/testutil/tsbaseline/type_symbol_baseline.go @@ -422,9 +422,9 @@ func (walker *typeWriterWalker) writeTypeOrSymbol(node *ast.Node, isSymbolWalk b symbolString.WriteString("Symbol(") symbolString.WriteString(ast.EscapeAllInternalSymbolNames(fileChecker.SymbolToStringEx(symbol, node.Parent, ast.SymbolFlagsNone, checker.SymbolFormatFlagsAllowAnyNodeKind))) count := 0 - for _, declaration := range symbol.Declarations { + for _, declaration := range symbol.Declarations() { if count >= 5 { - fmt.Fprintf(&symbolString, " ... and %d more", len(symbol.Declarations)-count) + fmt.Fprintf(&symbolString, " ... and %d more", len(symbol.Declarations())-count) break } count++ diff --git a/tsc/internal/tracing/tracing.go b/tsc/internal/tracing/tracing.go index bcbf21817fb80..f13ba7bf07377 100644 --- a/tsc/internal/tracing/tracing.go +++ b/tsc/internal/tracing/tracing.go @@ -605,9 +605,9 @@ func (t *typeTracer) buildTypeDescriptor(typ TracedType, recursionIdentityMap ma // Symbol name - escape the internal symbol name prefix for valid JSON if sym := aliasSymbol; sym != nil { - desc.SymbolName = ast.EscapeAllInternalSymbolNames(sym.Name) + desc.SymbolName = ast.EscapeAllInternalSymbolNames(sym.Name()) } else if symbol != nil { - desc.SymbolName = ast.EscapeAllInternalSymbolNames(symbol.Name) + desc.SymbolName = ast.EscapeAllInternalSymbolNames(symbol.Name()) } // Tuple flag @@ -711,8 +711,8 @@ func (t *typeTracer) buildTypeDescriptor(typ TracedType, recursionIdentityMap ma if firstDeclSymbol == nil { firstDeclSymbol = symbol } - if firstDeclSymbol != nil && len(firstDeclSymbol.Declarations) > 0 { - desc.FirstDeclaration = getLocation(firstDeclSymbol.Declarations[0]) + if firstDeclSymbol != nil && len(firstDeclSymbol.Declarations()) > 0 { + desc.FirstDeclaration = getLocation(firstDeclSymbol.Declarations()[0]) } // Display text diff --git a/tsc/internal/transformers/declarations/diagnostics.go b/tsc/internal/transformers/declarations/diagnostics.go index 9b2d45476a354..1050afa933eff 100644 --- a/tsc/internal/transformers/declarations/diagnostics.go +++ b/tsc/internal/transformers/declarations/diagnostics.go @@ -584,7 +584,7 @@ func addParentDeclarationRelatedInfo(node *ast.Node, diag *ast.Diagnostic) { } func createAccessorTypeError(node *ast.Node) *ast.Diagnostic { - allDeclarations := ast.GetAllAccessorDeclarationsForDeclaration(node, node.Symbol().Declarations) + allDeclarations := ast.GetAllAccessorDeclarationsForDeclaration(node, node.Symbol().Declarations()) getAccessor := allDeclarations.GetAccessor setAccessor := allDeclarations.SetAccessor targetNode := node diff --git a/tsc/internal/transformers/declarations/tracker.go b/tsc/internal/transformers/declarations/tracker.go index 29735b2dc2b97..14d0fcd5e5032 100644 --- a/tsc/internal/transformers/declarations/tracker.go +++ b/tsc/internal/transformers/declarations/tracker.go @@ -121,8 +121,8 @@ func (s *SymbolTrackerImpl) ReportNonSerializableProperty(propertyName string) { // ReportNonlocalAugmentation implements checker.SymbolTracker. func (s *SymbolTrackerImpl) ReportNonlocalAugmentation(containingFile *ast.SourceFile, parentSymbol *ast.Symbol, augmentingSymbol *ast.Symbol) { - primaryDeclaration := core.Find(parentSymbol.Declarations, func(d *ast.Node) bool { return ast.GetSourceFileOfNode(d) == containingFile }) - augmentingDeclarations := core.Filter(augmentingSymbol.Declarations, func(d *ast.Node) bool { return ast.GetSourceFileOfNode(d) != containingFile }) + primaryDeclaration := core.Find(parentSymbol.Declarations(), func(d *ast.Node) bool { return ast.GetSourceFileOfNode(d) == containingFile }) + augmentingDeclarations := core.Filter(augmentingSymbol.Declarations(), func(d *ast.Node) bool { return ast.GetSourceFileOfNode(d) != containingFile }) if primaryDeclaration != nil && len(augmentingDeclarations) > 0 { for _, augmentations := range augmentingDeclarations { diag := createDiagnosticForNode(augmentations, diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized) @@ -187,7 +187,7 @@ func (s *SymbolTrackerImpl) errorDeclarationNameWithFallback() string { // TrackSymbol implements checker.SymbolTracker. func (s *SymbolTrackerImpl) TrackSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) bool { - if symbol.Flags&ast.SymbolFlagsTypeParameter != 0 { + if symbol.Flags()&ast.SymbolFlagsTypeParameter != 0 { return false } // When watching for a class expression symbol, record its usage without diff --git a/tsc/internal/transformers/declarations/transform.go b/tsc/internal/transformers/declarations/transform.go index 0daf681bfb59e..f0187f2f2590c 100644 --- a/tsc/internal/transformers/declarations/transform.go +++ b/tsc/internal/transformers/declarations/transform.go @@ -118,8 +118,8 @@ func NewDeclarationTransformer(host DeclarationEmitHost, resolver printer.EmitRe } props := resolver.GetPropertiesOfContainerFunction(node) for _, p := range props { - if ast.IsExpandoPropertyDeclaration(p.ValueDeclaration) { - errorTarget := p.ValueDeclaration + if ast.IsExpandoPropertyDeclaration(p.ValueDeclaration()) { + errorTarget := p.ValueDeclaration() if ast.IsBinaryExpression(errorTarget) { errorTarget = errorTarget.AsBinaryExpression().Left } @@ -354,8 +354,8 @@ func (tx *DeclarationTransformer) transformSourceFile(node *ast.SourceFile) *ast combinedStatements.Loc = statements.Loc // setTextRange if ast.IsExternalOrCommonJSModule(node) { if ast.IsInJSFile(node.AsNode()) { - if exportEquals := node.Symbol.Exports[ast.InternalSymbolNameExportEquals]; exportEquals != nil && len(exportEquals.Declarations) > 1 { - for _, node := range exportEquals.Declarations { + if exportEquals := node.Symbol.Exports()[ast.InternalSymbolNameExportEquals]; exportEquals != nil && len(exportEquals.Declarations()) > 1 { + for _, node := range exportEquals.Declarations() { tx.state.addDiagnostic(createDiagnosticForNode(node, diagnostics.Multiple_module_exports_assignments_cannot_be_serialized_for_declaration_emit)) } } @@ -1088,7 +1088,7 @@ func (tx *DeclarationTransformer) transformConstructSignatureDeclaration(input * } func (tx *DeclarationTransformer) omitPrivateMethodType(input *ast.Node) *ast.Node { - if input.Symbol() != nil && len(input.Symbol().Declarations) > 0 && input.Symbol().Declarations[0] != input { + if input.Symbol() != nil && len(input.Symbol().Declarations()) > 0 && input.Symbol().Declarations()[0] != input { return nil } var result *ast.Node @@ -1562,7 +1562,7 @@ func (tx *DeclarationTransformer) wrapInCJSExportNamespace(content *ast.Node) *a func isCommonJSAliasExport(node *ast.Node) bool { if ast.IsBinaryExpression(node) && ast.IsIdentifier(node.AsBinaryExpression().Right) { - if symbol := node.Symbol(); symbol != nil && len(symbol.Declarations) == 1 { + if symbol := node.Symbol(); symbol != nil && len(symbol.Declarations()) == 1 { return true } } @@ -2728,7 +2728,7 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp left := node.Left symbol := node.Symbol - if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 { + if symbol == nil || symbol.Flags()&ast.SymbolFlagsAssignment == 0 { return } diff --git a/tsc/internal/transformers/declarations/util.go b/tsc/internal/transformers/declarations/util.go index 422a62134808f..2f05e33035821 100644 --- a/tsc/internal/transformers/declarations/util.go +++ b/tsc/internal/transformers/declarations/util.go @@ -156,7 +156,7 @@ func shouldEmitFunctionProperties(input *ast.FunctionDeclaration) bool { if input.Body != nil { return true } - return !core.Every(input.Symbol.Declarations, func(decl *ast.Node) bool { + return !core.Every(input.Symbol.Declarations(), func(decl *ast.Node) bool { return !ast.IsFunctionDeclaration(decl) || decl.AsFunctionDeclaration().Body == nil }) }