diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 4968528f9d..1793bc63ef 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -1340,7 +1340,7 @@ func IsBindableStaticElementAccessExpression(node *Node, excludeThisKeyword bool return IsLiteralLikeElementAccess(node) && ((!excludeThisKeyword && node.Expression().Kind == KindThisKeyword) || IsEntityNameExpression(node.Expression()) || - IsBindableStaticAccessExpression(node.Expression() /*excludeThisKeyword*/, true)) + IsBindableStaticAccessExpression(node.Expression(), true /*excludeThisKeyword*/)) } func IsLiteralLikeElementAccess(node *Node) bool { @@ -2822,10 +2822,6 @@ func IsModuleExportsAccessExpression(node *Node) bool { return false } -func isLiteralLikeElementAccess(node *Node) bool { - return node.Kind == KindElementAccessExpression && IsStringOrNumericLiteralLike(node.AsElementAccessExpression().ArgumentExpression) -} - func IsCheckJSEnabledForFile(sourceFile *SourceFile, compilerOptions *core.CompilerOptions) bool { if sourceFile.CheckJsDirective != nil { return sourceFile.CheckJsDirective.Enabled @@ -3866,6 +3862,31 @@ func IsImportOrImportEqualsDeclaration(node *Node) bool { return IsImportDeclaration(node) || IsImportEqualsDeclaration(node) } +func IsKeyword(token Kind) bool { + return KindFirstKeyword <= token && token <= KindLastKeyword +} + +func IsNonContextualKeyword(token Kind) bool { + return IsKeyword(token) && !IsContextualKeyword(token) +} + +func HasModifier(node *Node, flags ModifierFlags) bool { + return node.ModifierFlags()&flags != 0 +} + +func IsExpandoInitializer(initializer *Node) bool { + if initializer == nil { + return false + } + if IsFunctionExpressionOrArrowFunction(initializer) { + return true + } + if IsInJSFile(initializer) { + return IsClassExpression(initializer) || (IsObjectLiteralExpression(initializer) && len(initializer.AsObjectLiteralExpression().Properties.Nodes) == 0) + } + return false +} + func GetContainingFunction(node *Node) *Node { return FindAncestor(node.Parent, IsFunctionLike) } diff --git a/internal/binder/binder.go b/internal/binder/binder.go index e215ef7ad3..1824ffcac1 100644 --- a/internal/binder/binder.go +++ b/internal/binder/binder.go @@ -1018,30 +1018,18 @@ func getInitializerSymbol(symbol *ast.Symbol) *ast.Symbol { case ast.IsVariableDeclaration(declaration) && (declaration.Parent.Flags&ast.NodeFlagsConst != 0 || ast.IsInJSFile(declaration)): initializer := declaration.Initializer() - if isExpandoInitializer(initializer) { + if ast.IsExpandoInitializer(initializer) { return initializer.Symbol() } case ast.IsBinaryExpression(declaration) && ast.IsInJSFile(declaration): initializer := declaration.AsBinaryExpression().Right - if isExpandoInitializer(initializer) { + if ast.IsExpandoInitializer(initializer) { return initializer.Symbol() } } return nil } -func isExpandoInitializer(initializer *ast.Node) bool { - if initializer == nil { - return false - } - if ast.IsFunctionExpressionOrArrowFunction(initializer) { - return true - } else if ast.IsInJSFile(initializer) { - return ast.IsClassExpression(initializer) || (ast.IsObjectLiteralExpression(initializer) && len(initializer.AsObjectLiteralExpression().Properties.Nodes) == 0) - } - return false -} - func (b *Binder) bindThisPropertyAssignment(node *ast.Node) { if !ast.IsInJSFile(node) { return diff --git a/internal/binder/referenceresolver.go b/internal/binder/referenceresolver.go index 8fbe5297e3..2e428044a7 100644 --- a/internal/binder/referenceresolver.go +++ b/internal/binder/referenceresolver.go @@ -11,6 +11,7 @@ type ReferenceResolver interface { GetReferencedImportDeclaration(node *ast.IdentifierNode) *ast.Declaration GetReferencedValueDeclaration(node *ast.IdentifierNode) *ast.Declaration GetReferencedValueDeclarations(node *ast.IdentifierNode) []*ast.Declaration + GetElementAccessExpressionName(expression *ast.ElementAccessExpression) string } type ReferenceResolverHooks struct { @@ -21,6 +22,7 @@ type ReferenceResolverHooks struct { GetSymbolOfDeclaration func(*ast.Declaration) *ast.Symbol GetTypeOnlyAliasDeclaration func(symbol *ast.Symbol, include ast.SymbolFlags) *ast.Declaration GetExportSymbolOfValueSymbolIfExported func(*ast.Symbol) *ast.Symbol + GetElementAccessExpressionName func(*ast.ElementAccessExpression) (string, bool) } var _ ReferenceResolver = &referenceResolver{} @@ -236,3 +238,14 @@ func (r *referenceResolver) GetReferencedValueDeclarations(node *ast.IdentifierN } return declarations } + +func (r *referenceResolver) GetElementAccessExpressionName(expression *ast.ElementAccessExpression) string { + if expression != nil { + if r.hooks.GetElementAccessExpressionName != nil { + if name, ok := r.hooks.GetElementAccessExpressionName(expression); ok { + return name + } + } + } + return "" +} diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 3d56796e37..48982081a7 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -4234,7 +4234,7 @@ func (c *Checker) checkBaseTypeAccessibility(t *Type, node *ast.Node) { signatures := c.getSignaturesOfType(t, SignatureKindConstruct) if len(signatures) != 0 { declaration := signatures[0].declaration - if declaration != nil && HasModifier(declaration, ast.ModifierFlagsPrivate) { + if declaration != nil && ast.HasModifier(declaration, ast.ModifierFlagsPrivate) { typeClassDeclaration := ast.GetClassLikeDeclarationOfSymbol(t.symbol) if !c.isNodeWithinClass(node, typeClassDeclaration) { c.error(node, diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private, c.getFullyQualifiedName(t.symbol, nil)) @@ -6489,7 +6489,7 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) { name := node.PropertyNameOrName().Text() c.addTypeOnlyDeclarationRelatedInfo(c.error(node, message, name), core.IfElse(isType, nil, typeOnlyAlias), name) } - if isType && node.Kind == ast.KindImportEqualsDeclaration && HasModifier(node, ast.ModifierFlagsExport) { + if isType && node.Kind == ast.KindImportEqualsDeclaration && ast.HasModifier(node, ast.ModifierFlagsExport) { c.error(node, diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_0_is_enabled, c.getIsolatedModulesLikeFlagName()) } case ast.KindExportSpecifier: @@ -6777,7 +6777,7 @@ func (c *Checker) checkUnusedClassMembers(node *ast.Node) { break // Already would have reported an error on the getter. } symbol := c.getSymbolOfDeclaration(member) - if !c.isReferenced(symbol) && (HasModifier(member, ast.ModifierFlagsPrivate) || member.Name() != nil && ast.IsPrivateIdentifier(member.Name())) && member.Flags&ast.NodeFlagsAmbient == 0 { + if !c.isReferenced(symbol) && (ast.HasModifier(member, ast.ModifierFlagsPrivate) || member.Name() != nil && ast.IsPrivateIdentifier(member.Name())) && member.Flags&ast.NodeFlagsAmbient == 0 { c.reportUnused(member, UnusedKindLocal, NewDiagnosticForNode(member.Name(), diagnostics.X_0_is_declared_but_its_value_is_never_read, c.symbolToString(symbol))) } case ast.KindConstructor: @@ -8337,7 +8337,7 @@ func (c *Checker) resolveNewExpression(node *ast.Node, candidatesOutArray *[]*Si } if expressionType.symbol != nil { valueDecl := ast.GetClassLikeDeclarationOfSymbol(expressionType.symbol) - if valueDecl != nil && HasModifier(valueDecl, ast.ModifierFlagsAbstract) { + if valueDecl != nil && ast.HasModifier(valueDecl, ast.ModifierFlagsAbstract) { c.error(node, diagnostics.Cannot_create_an_instance_of_an_abstract_class) return c.resolveErrorCall(node) } @@ -18912,7 +18912,7 @@ func (c *Checker) getIndexInfosOfIndexSymbol(indexSymbol *ast.Symbol, siblingSym } forEachType(c.getTypeFromTypeNode(typeNode), func(keyType *Type) { if c.isValidIndexKeyType(keyType) && findIndexInfo(indexInfos, keyType) == nil { - indexInfo := c.newIndexInfo(keyType, valueType, HasModifier(declaration, ast.ModifierFlagsReadonly), declaration, nil) + indexInfo := c.newIndexInfo(keyType, valueType, ast.HasModifier(declaration, ast.ModifierFlagsReadonly), declaration, nil) indexInfos = append(indexInfos, indexInfo) } }) @@ -26823,7 +26823,7 @@ func (c *Checker) markPropertyAsReferenced(prop *ast.Symbol, nodeForCheckWriteOn if prop.Flags&ast.SymbolFlagsClassMember == 0 || prop.ValueDeclaration == nil { return } - hasPrivateModifier := HasModifier(prop.ValueDeclaration, ast.ModifierFlagsPrivate) + hasPrivateModifier := ast.HasModifier(prop.ValueDeclaration, ast.ModifierFlagsPrivate) hasPrivateIdentifier := prop.ValueDeclaration.Name() != nil && ast.IsPrivateIdentifier(prop.ValueDeclaration.Name()) if !hasPrivateModifier && !hasPrivateIdentifier { return diff --git a/internal/checker/emitresolver.go b/internal/checker/emitresolver.go index 1a28c3c21e..71c1a60955 100644 --- a/internal/checker/emitresolver.go +++ b/internal/checker/emitresolver.go @@ -825,6 +825,7 @@ func (r *emitResolver) getReferenceResolver() binder.ReferenceResolver { GetSymbolOfDeclaration: r.checker.getSymbolOfDeclaration, GetTypeOnlyAliasDeclaration: r.checker.getTypeOnlyAliasDeclarationEx, GetExportSymbolOfValueSymbolIfExported: r.checker.getExportSymbolOfValueSymbolIfExported, + GetElementAccessExpressionName: r.checker.tryGetElementAccessExpressionName, }) } return r.referenceResolver @@ -879,6 +880,17 @@ func (r *emitResolver) GetReferencedValueDeclarations(node *ast.IdentifierNode) return r.getReferenceResolver().GetReferencedValueDeclarations(node) } +func (r *emitResolver) GetElementAccessExpressionName(expression *ast.ElementAccessExpression) string { + if !ast.IsParseTreeNode(expression.AsNode()) { + return "" + } + + r.checkerMu.Lock() + defer r.checkerMu.Unlock() + + return r.getReferenceResolver().GetElementAccessExpressionName(expression) +} + // TODO: the emit resolver being responsible for some amount of node construction is a very leaky abstraction, // and requires giving it access to a lot of context it's otherwise not required to have, which also further complicates the API // and likely reduces performance. There's probably some refactoring that could be done here to simplify this. diff --git a/internal/checker/utilities.go b/internal/checker/utilities.go index 3637b8d421..bd026c259c 100644 --- a/internal/checker/utilities.go +++ b/internal/checker/utilities.go @@ -76,12 +76,8 @@ func getSelectedModifierFlags(node *ast.Node, flags ast.ModifierFlags) ast.Modif return node.ModifierFlags() & flags } -func HasModifier(node *ast.Node, flags ast.ModifierFlags) bool { - return node.ModifierFlags()&flags != 0 -} - func hasReadonlyModifier(node *ast.Node) bool { - return HasModifier(node, ast.ModifierFlagsReadonly) + return ast.HasModifier(node, ast.ModifierFlagsReadonly) } func isStaticPrivateIdentifierProperty(s *ast.Symbol) bool { @@ -405,7 +401,7 @@ func declarationBelongsToPrivateAmbientMember(declaration *ast.Node) bool { } func isPrivateWithinAmbient(node *ast.Node) bool { - return (HasModifier(node, ast.ModifierFlagsPrivate) || ast.IsPrivateIdentifierClassElementDeclaration(node)) && node.Flags&ast.NodeFlagsAmbient != 0 + return (ast.HasModifier(node, ast.ModifierFlagsPrivate) || ast.IsPrivateIdentifierClassElementDeclaration(node)) && node.Flags&ast.NodeFlagsAmbient != 0 } func isTypeAssertion(node *ast.Node) bool { diff --git a/internal/ls/findallreferences.go b/internal/ls/findallreferences.go index 7e31e181e0..5dc45a5702 100644 --- a/internal/ls/findallreferences.go +++ b/internal/ls/findallreferences.go @@ -349,7 +349,7 @@ func getSymbolScope(symbol *ast.Symbol) *ast.Node { // If this is private property or method, the scope is the containing class if symbol.Flags&(ast.SymbolFlagsProperty|ast.SymbolFlagsMethod) != 0 { privateDeclaration := core.Find(declarations, func(d *ast.Node) bool { - return checker.HasModifier(d, ast.ModifierFlagsPrivate) || ast.IsPrivateIdentifierClassElementDeclaration(d) + return ast.HasModifier(d, ast.ModifierFlagsPrivate) || ast.IsPrivateIdentifierClassElementDeclaration(d) }) if privateDeclaration != nil { return ast.FindAncestorKind(privateDeclaration, ast.KindClassDeclaration) diff --git a/internal/parser/parser.go b/internal/parser/parser.go index ef87829bb6..a51566f02d 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -296,7 +296,7 @@ func (p *Parser) lookAhead(callback func(p *Parser) bool) bool { func (p *Parser) nextToken() ast.Kind { // if the keyword had an escape - if isKeyword(p.token) && (p.scanner.HasUnicodeEscape() || p.scanner.HasExtendedUnicodeEscape()) { + if ast.IsKeyword(p.token) && (p.scanner.HasUnicodeEscape() || p.scanner.HasExtendedUnicodeEscape()) { // issue a parse error for the escape p.parseErrorAtCurrentToken(diagnostics.Keywords_cannot_contain_escape_characters) } @@ -644,7 +644,7 @@ func (p *Parser) parsingContextErrors(context ParsingContext) { case PCHeritageClauseElement: p.parseErrorAtCurrentToken(diagnostics.Expression_expected) case PCVariableDeclarations: - if isKeyword(p.token) { + if ast.IsKeyword(p.token) { p.parseErrorAtCurrentToken(diagnostics.X_0_is_not_allowed_as_a_variable_declaration_name, scanner.TokenToString(p.token)) } else { p.parseErrorAtCurrentToken(diagnostics.Variable_declaration_expected) @@ -662,7 +662,7 @@ func (p *Parser) parsingContextErrors(context ParsingContext) { case PCJSDocParameters: p.parseErrorAtCurrentToken(diagnostics.Parameter_declaration_expected) case PCParameters: - if isKeyword(p.token) { + if ast.IsKeyword(p.token) { p.parseErrorAtCurrentToken(diagnostics.X_0_is_not_allowed_as_a_parameter_name, scanner.TokenToString(p.token)) } else { p.parseErrorAtCurrentToken(diagnostics.Parameter_declaration_expected) @@ -2352,7 +2352,7 @@ func (p *Parser) parseModuleExportName(disallowKeywords bool) (node *ast.Node, n if p.token == ast.KindStringLiteral { return p.parseLiteralExpression(false /*intern*/), nameOk } - if disallowKeywords && isKeyword(p.token) && !p.isIdentifier() { + if disallowKeywords && ast.IsKeyword(p.token) && !p.isIdentifier() { nameOk = false } return p.parseIdentifierName(), nameOk @@ -5835,7 +5835,7 @@ func (p *Parser) scanClassMemberStart() bool { // If we were able to get any potential identifier... if idToken != ast.KindUnknown { // If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse. - if !isKeyword(idToken) || idToken == ast.KindSetKeyword || idToken == ast.KindGetKeyword { + if !ast.IsKeyword(idToken) || idToken == ast.KindSetKeyword || idToken == ast.KindGetKeyword { return true } // If it *is* a keyword, but not an accessor, check a little farther along @@ -6235,10 +6235,6 @@ func (p *Parser) skipRangeTrivia(textRange core.TextRange) core.TextRange { return core.NewTextRange(scanner.SkipTrivia(p.sourceText, textRange.Pos()), textRange.End()) } -func isKeyword(token ast.Kind) bool { - return ast.KindFirstKeyword <= token && token <= ast.KindLastKeyword -} - func isReservedWord(token ast.Kind) bool { return ast.KindFirstReservedWord <= token && token <= ast.KindLastReservedWord } diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 6217557d5f..e81bf4f602 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/microsoft/typescript-go/internal/ast" + "github.com/microsoft/typescript-go/internal/collections" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/debug" "github.com/microsoft/typescript-go/internal/diagnostics" @@ -11,6 +12,7 @@ import ( "github.com/microsoft/typescript-go/internal/modulespecifiers" "github.com/microsoft/typescript-go/internal/nodebuilder" "github.com/microsoft/typescript-go/internal/printer" + "github.com/microsoft/typescript-go/internal/scanner" "github.com/microsoft/typescript-go/internal/transformers" "github.com/microsoft/typescript-go/internal/tspath" ) @@ -56,6 +58,7 @@ type DeclarationTransformer struct { resultHasExternalModuleIndicator bool suppressNewDiagnosticContexts bool lateStatementReplacementMap map[ast.NodeId]*ast.Node + expandoHosts collections.Set[ast.NodeId] rawReferencedFiles []ReferencedFilePair rawTypeReferenceDirectives []*ast.FileReference rawLibReferenceDirectives []*ast.FileReference @@ -124,7 +127,6 @@ func (tx *DeclarationTransformer) visit(node *ast.Node) *ast.Node { ast.KindContinueStatement, ast.KindDebuggerStatement, ast.KindDoStatement, - ast.KindExpressionStatement, ast.KindEmptyStatement, ast.KindForInStatement, ast.KindForOfStatement, @@ -141,6 +143,8 @@ func (tx *DeclarationTransformer) visit(node *ast.Node) *ast.Node { ast.KindBlock, ast.KindMissingDeclaration: return nil + case ast.KindExpressionStatement: + return tx.visitExpressionStatement(node.AsExpressionStatement()) // parts of things, things we just visit children of default: return tx.visitDeclarationSubtree(node) @@ -166,6 +170,7 @@ func (tx *DeclarationTransformer) visitSourceFile(node *ast.SourceFile) *ast.Nod tx.suppressNewDiagnosticContexts = false tx.state.lateMarkedStatements = make([]*ast.Node, 0) tx.lateStatementReplacementMap = make(map[ast.NodeId]*ast.Node) + tx.expandoHosts = collections.Set[ast.NodeId]{} tx.rawReferencedFiles = make([]ReferencedFilePair, 0) tx.rawTypeReferenceDirectives = make([]*ast.FileReference, 0) tx.rawLibReferenceDirectives = make([]*ast.FileReference, 0) @@ -231,12 +236,12 @@ func (tx *DeclarationTransformer) transformAndReplaceLatePaintedStatements(state next := tx.state.lateMarkedStatements[0] tx.state.lateMarkedStatements = tx.state.lateMarkedStatements[1:] - priorNeedsDeclare := tx.needsDeclare + saveNeedsDeclare := tx.needsDeclare tx.needsDeclare = next.Parent != nil && ast.IsSourceFile(next.Parent) && !(ast.IsExternalModule(next.Parent.AsSourceFile()) && tx.isBundledEmit) result := tx.transformTopLevelDeclaration(next) - tx.needsDeclare = priorNeedsDeclare + tx.needsDeclare = saveNeedsDeclare original := tx.EmitContext().MostOriginal(next) id := ast.GetNodeId(original) tx.lateStatementReplacementMap[id] = result @@ -789,8 +794,6 @@ func (tx *DeclarationTransformer) transformGetAccesorDeclaration(input *ast.GetA ) } -const defaultModifierFlagsMask = ast.ModifierFlagsAll ^ ast.ModifierFlagsPublic - func (tx *DeclarationTransformer) updateAccessorParamList(input *ast.Node, isPrivate bool) *ast.ParameterList { var newParams []*ast.Node if !isPrivate { @@ -955,11 +958,11 @@ func (tx *DeclarationTransformer) visitDeclarationStatements(input *ast.Node) *a tx.removeAllComments(assignment) return tx.Factory().NewSyntaxList([]*ast.Node{statement, assignment}) default: - result := tx.transformTopLevelDeclaration(input) - // Don't actually transform yet; just leave as original node - will be elided/swapped by late pass - original := tx.EmitContext().MostOriginal(input) - id := ast.GetNodeId(original) - tx.lateStatementReplacementMap[id] = result + id := ast.GetNodeId(tx.EmitContext().MostOriginal(input)) + if tx.lateStatementReplacementMap[id] == nil { + // Don't actually transform yet; just leave as original node - will be elided/swapped by late pass + tx.lateStatementReplacementMap[id] = tx.transformTopLevelDeclaration(input) + } return input } } @@ -1100,7 +1103,7 @@ func (tx *DeclarationTransformer) transformTopLevelDeclaration(input *ast.Node) if canProdiceDiagnostic { tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input) } - previousNeedsDeclare := tx.needsDeclare + saveNeedsDeclare := tx.needsDeclare var result *ast.Node switch input.Kind { @@ -1125,7 +1128,7 @@ func (tx *DeclarationTransformer) transformTopLevelDeclaration(input *ast.Node) tx.enclosingDeclaration = previousEnclosingDeclaration tx.state.getSymbolAccessibilityDiagnostic = oldDiag - tx.needsDeclare = previousNeedsDeclare + tx.needsDeclare = saveNeedsDeclare tx.state.errorNameNode = oldName return result } @@ -1153,7 +1156,7 @@ func (tx *DeclarationTransformer) transformInterfaceDeclaration(input *ast.Inter } func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.FunctionDeclaration) *ast.Node { - updated := tx.Factory().UpdateFunctionDeclaration( + return tx.Factory().UpdateFunctionDeclaration( input, tx.ensureModifiers(input.AsNode()), nil, @@ -1164,17 +1167,6 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi nil, /*fullSignature*/ nil, ) - if updated == nil || !tx.resolver.IsExpandoFunctionDeclaration(input.AsNode()) || !shouldEmitFunctionProperties(input) { - return updated - } - // Add expando function properties to result - - // !!! TODO: expando function support - // props := tx.resolver.GetPropertiesOfContainerFunction(input) - // if tx.state.isolatedDeclarations { - // tx.state.reportExpandoFunctionErrors(input.AsNode()) - // } - return updated // !!! } func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDeclaration) *ast.Node { @@ -1182,7 +1174,7 @@ func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDe // It'd be good to collapse those back in the declaration output, but the AST can't represent the // `namespace a.b.c` shape for the printer (without using invalid identifier names). mods := tx.ensureModifiers(input.AsNode()) - oldNeedsDeclare := tx.needsDeclare + saveNeedsDeclare := tx.needsDeclare tx.needsDeclare = false inner := input.Body keyword := input.Keyword @@ -1213,7 +1205,7 @@ func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDe } body := tx.Factory().UpdateModuleBlock(inner.AsModuleBlock(), lateStatements) - tx.needsDeclare = oldNeedsDeclare + tx.needsDeclare = saveNeedsDeclare tx.needsScopeFixMarker = oldNeedsScopeFix tx.resultHasScopeMarker = oldHasScopeFix @@ -1817,3 +1809,172 @@ func (tx *DeclarationTransformer) transformJSDocOptionalType(input *ast.JSDocOpt tx.EmitContext().SetOriginal(replacement, input.AsNode()) return replacement } + +func (tx *DeclarationTransformer) visitExpressionStatement(node *ast.ExpressionStatement) *ast.Node { + expression := node.Expression + if expression == nil { + return nil + } + + if expression.Kind == ast.KindBinaryExpression && + ast.GetAssignmentDeclarationKind(expression.AsBinaryExpression()) == ast.JSDeclarationKindProperty { + return tx.transformExpandoAssignment(expression.AsBinaryExpression()) + } + + return nil +} + +func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExpression) *ast.Node { + left := node.Left + + symbol := node.Symbol + if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 { + return nil + } + + ns := ast.GetLeftmostAccessExpression(left) + if ns == nil || ns.Kind != ast.KindIdentifier { + return nil + } + + declaration := tx.resolver.GetReferencedValueDeclaration(ns) + if declaration == nil { + return nil + } + + host := declaration.Symbol() + if host == nil { + return nil + } + + name := tx.Factory().NewIdentifier(ns.Text()) + property := tx.tryGetPropertyName(left) + if property == "" || !scanner.IsIdentifierText(property, core.LanguageVariantStandard) { + return nil + } + + tx.transformExpandoHost(name, declaration) + + if ast.IsFunctionDeclaration(declaration) && !shouldEmitFunctionProperties(declaration.AsFunctionDeclaration()) { + return nil + } + + isNonContextualKeywordName := ast.IsNonContextualKeyword(scanner.StringToToken(property)) + exportName := core.IfElse(isNonContextualKeywordName, tx.Factory().NewGeneratedNameForNode(left), tx.Factory().NewIdentifier(property)) + + synthesizedNamespace := tx.Factory().NewModuleDeclaration(nil /*modifiers*/, ast.KindNamespaceKeyword, name, tx.Factory().NewModuleBlock(tx.Factory().NewNodeList([]*ast.Node{}))) + synthesizedNamespace.Parent = tx.enclosingDeclaration + + declarationData := synthesizedNamespace.DeclarationData() + declarationData.Symbol = host + + containerData := synthesizedNamespace.LocalsContainerData() + containerData.Locals = make(ast.SymbolTable, 0) + + saveDiag := tx.state.getSymbolAccessibilityDiagnostic + tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node.AsNode()) + t := tx.resolver.CreateTypeOfExpression(tx.EmitContext(), left, synthesizedNamespace, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, tx.tracker) + tx.state.getSymbolAccessibilityDiagnostic = saveDiag + + statements := []*ast.Statement{ + tx.Factory().NewVariableStatement( + nil, /*modifiers*/ + tx.Factory().NewVariableDeclarationList( + ast.NodeFlagsNone, + tx.Factory().NewNodeList([]*ast.Node{ + tx.Factory().NewVariableDeclaration(exportName, nil /*exclamationToken*/, t, nil /*initializer*/), + }), + ), + ), + } + + if isNonContextualKeywordName { + namedExports := tx.Factory().NewNamedExports(tx.Factory().NewNodeList( + []*ast.Node{ + tx.Factory().NewExportSpecifier(false /*isTypeOnly*/, exportName, tx.Factory().NewIdentifier(left.Name().Text())), + }, + )) + statements = append(statements, tx.Factory().NewExportDeclaration(nil /*modifiers*/, false /*isTypeOnly*/, namedExports, nil /*moduleSpecifier*/, nil /*attributes*/)) + } + + flags := tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(declaration), ast.ModifierFlagsAll) + modifierFlags := ast.ModifierFlagsAmbient + + if flags&ast.ModifierFlagsExport != 0 { + if flags&ast.ModifierFlagsDefault == 0 { + modifierFlags |= ast.ModifierFlagsExport + } + tx.resultHasScopeMarker = true + tx.resultHasExternalModuleIndicator = true + } + + return tx.Factory().NewModuleDeclaration(tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)), ast.KindNamespaceKeyword, name, tx.Factory().NewModuleBlock(tx.Factory().NewNodeList(statements))) +} + +func (tx *DeclarationTransformer) transformExpandoHost(name *ast.Node, declaration *ast.Declaration) { + root := core.IfElse(ast.IsVariableDeclaration(declaration), declaration.Parent.Parent, declaration) + id := ast.GetNodeId(tx.EmitContext().MostOriginal(root)) + + if tx.expandoHosts.Has(id) { + return + } + + saveNeedsDeclare := tx.needsDeclare + tx.needsDeclare = true + + modifierFlags := tx.ensureModifierFlags(root) + defaultExport := modifierFlags&ast.ModifierFlagsExport != 0 && modifierFlags&ast.ModifierFlagsDefault != 0 + + tx.needsDeclare = saveNeedsDeclare + + if defaultExport { + modifierFlags |= ast.ModifierFlagsAmbient + modifierFlags ^= ast.ModifierFlagsDefault + modifierFlags ^= ast.ModifierFlagsExport + } + + modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)) + replacement := make([]*ast.Node, 0) + + if ast.IsFunctionDeclaration(declaration) { + typeParameters, parameters, asteriskToken := extractExpandoHostParams(declaration) + replacement = append(replacement, tx.Factory().UpdateFunctionDeclaration(declaration.AsFunctionDeclaration(), modifiers, asteriskToken, declaration.Name(), tx.ensureTypeParams(declaration, typeParameters), tx.updateParamList(declaration, parameters), tx.ensureType(declaration, false), nil /*fullSignature*/, nil /*body*/)) + } else if ast.IsVariableDeclaration(declaration) && ast.IsFunctionExpressionOrArrowFunction(declaration.Initializer()) { + fn := declaration.Initializer() + typeParameters, parameters, asteriskToken := extractExpandoHostParams(fn) + replacement = append(replacement, tx.Factory().NewFunctionDeclaration(modifiers, asteriskToken, tx.Factory().NewIdentifier(name.Text()), tx.ensureTypeParams(fn, typeParameters), tx.updateParamList(fn, parameters), tx.ensureType(fn, false), nil /*fullSignature*/, nil /*body*/)) + } else { + return + } + + if defaultExport { + replacement = append(replacement, tx.Factory().NewExportAssignment(nil /*modifiers*/, false /*isExportEquals*/, nil /*typeNode*/, name)) + } + + tx.expandoHosts.Add(id) + tx.lateStatementReplacementMap[id] = tx.Factory().NewSyntaxList(replacement) +} + +func extractExpandoHostParams(node *ast.Node) (typeParameters *ast.TypeParameterList, parameters *ast.ParameterList, asteriskToken *ast.TokenNode) { + switch node.Kind { + case ast.KindFunctionExpression: + fn := node.AsFunctionExpression() + return fn.TypeParameters, fn.Parameters, fn.AsteriskToken + case ast.KindArrowFunction: + fn := node.AsArrowFunction() + return fn.TypeParameters, fn.Parameters, fn.AsteriskToken + default: + fn := node.AsFunctionDeclaration() + return fn.TypeParameters, fn.Parameters, fn.AsteriskToken + } +} + +func (tx *DeclarationTransformer) tryGetPropertyName(node *ast.Node) string { + if ast.IsElementAccessExpression(node) { + return tx.resolver.GetElementAccessExpressionName(node.AsElementAccessExpression()) + } + if ast.IsPropertyAccessExpression(node) { + return node.Name().Text() + } + return "" +} diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js new file mode 100644 index 0000000000..c54f345dd5 --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js @@ -0,0 +1,57 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +//// [declarationEmitExpandoFunction.ts] +export function A() { + return 'A'; +} + +export function B() { + return 'B'; +} + +export enum C { + C +} + +A.a = C; +A.b = C; + +B.c = C; + + +//// [declarationEmitExpandoFunction.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.C = void 0; +exports.A = A; +exports.B = B; +function A() { + return 'A'; +} +function B() { + return 'B'; +} +var C; +(function (C) { + C[C["C"] = 0] = "C"; +})(C || (exports.C = C = {})); +A.a = C; +A.b = C; +B.c = C; + + +//// [declarationEmitExpandoFunction.d.ts] +export declare function A(): string; +export declare function B(): string; +export declare enum C { + C = 0 +} +export declare namespace A { + var a: typeof C; +} +export declare namespace A { + var b: typeof C; +} +export declare namespace B { + var c: typeof C; +} diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols new file mode 100644 index 0000000000..41183b30b5 --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +=== declarationEmitExpandoFunction.ts === +export function A() { +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) + + return 'A'; +} + +export function B() { +>B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 2, 1)) + + return 'B'; +} + +export enum C { +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 6, 1)) + + C +>C : Symbol(C.C, Decl(declarationEmitExpandoFunction.ts, 8, 15)) +} + +A.a = C; +>A.a : Symbol(A.a, Decl(declarationEmitExpandoFunction.ts, 10, 1)) +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) +>a : Symbol(A.a, Decl(declarationEmitExpandoFunction.ts, 10, 1)) +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 6, 1)) + +A.b = C; +>A.b : Symbol(A.b, Decl(declarationEmitExpandoFunction.ts, 12, 8)) +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) +>b : Symbol(A.b, Decl(declarationEmitExpandoFunction.ts, 12, 8)) +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 6, 1)) + +B.c = C; +>B.c : Symbol(B.c, Decl(declarationEmitExpandoFunction.ts, 13, 8)) +>B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 2, 1)) +>c : Symbol(B.c, Decl(declarationEmitExpandoFunction.ts, 13, 8)) +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 6, 1)) + diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types new file mode 100644 index 0000000000..0e7b87870c --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +=== declarationEmitExpandoFunction.ts === +export function A() { +>A : { (): string; a: typeof C; b: typeof C; } + + return 'A'; +>'A' : "A" +} + +export function B() { +>B : { (): string; c: typeof C; } + + return 'B'; +>'B' : "B" +} + +export enum C { +>C : C + + C +>C : C.C +} + +A.a = C; +>A.a = C : typeof C +>A.a : typeof C +>A : { (): string; a: typeof C; b: typeof C; } +>a : typeof C +>C : typeof C + +A.b = C; +>A.b = C : typeof C +>A.b : typeof C +>A : { (): string; a: typeof C; b: typeof C; } +>b : typeof C +>C : typeof C + +B.c = C; +>B.c = C : typeof C +>B.c : typeof C +>B : { (): string; c: typeof C; } +>c : typeof C +>C : typeof C + diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index 345ebd102f..9a3ef3a146 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -82,14 +82,32 @@ C.B = B; export declare class Foo { } //// [index1.d.ts] -export default function Example(): void; +declare function Example(): void; +export default Example; +declare namespace Example { + var Foo: typeof import("./foo").Foo; +} //// [index2.d.ts] import { Foo } from './foo'; export { Foo }; -export default function Example(): void; +declare function Example(): void; +export default Example; +declare namespace Example { + var Foo: typeof import("./foo").Foo; +} //// [index3.d.ts] export declare class Bar { } -export default function Example(): void; +declare function Example(): void; +export default Example; +declare namespace Example { + var Bar: typeof import("./index3").Bar; +} //// [index4.d.ts] export declare function C(): any; +export declare namespace C { + var A: () => void; +} +export declare namespace C { + var B: () => void; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index ff4abd456f..552d88daf0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -18,37 +18,38 @@ Object.defineProperty(exports, "Foo", { enumerable: true, get: function () { return foo_1.Foo; } }); function Example() { } Example.Foo = foo_1.Foo; -@@= skipped -31, +31 lines =@@ - export declare class Foo { +@@= skipped -32, +32 lines =@@ } //// [index1.d.ts] --declare function Example(): void; --declare namespace Example { -- var Foo: typeof import("./foo").Foo; --} + declare function Example(): void; ++export default Example; + declare namespace Example { + var Foo: typeof import("./foo").Foo; + } -export default Example; -+export default function Example(): void; //// [index2.d.ts] import { Foo } from './foo'; export { Foo }; --declare function Example(): void; --declare namespace Example { -- var Foo: typeof import("./foo").Foo; --} + declare function Example(): void; ++export default Example; + declare namespace Example { + var Foo: typeof import("./foo").Foo; + } -export default Example; -+export default function Example(): void; //// [index3.d.ts] export declare class Bar { } --declare function Example(): void; --declare namespace Example { -- var Bar: typeof import("./index3").Bar; --} + declare function Example(): void; ++export default Example; + declare namespace Example { + var Bar: typeof import("./index3").Bar; + } -export default Example; -+export default function Example(): void; //// [index4.d.ts] export declare function C(): any; --export declare namespace C { -- var A: () => void; -- var B: () => void; --} \ No newline at end of file + export declare namespace C { + var A: () => void; ++} ++export declare namespace C { + var B: () => void; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt new file mode 100644 index 0000000000..1ed386c351 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt @@ -0,0 +1,14 @@ +b.ts(4,1): error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. + + +==== a.ts (0 errors) ==== + interface I {} + export function f(): I { return null as I; } +==== b.ts (1 errors) ==== + import {f} from "./a"; + + export function q() {} + q.val = f(); + ~~~~~~~~~~~ +!!! error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff index fc2ba7171a..e5704b00b0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff @@ -1,18 +1,10 @@ --- old.declarationEmitExpandoPropertyPrivateName.errors.txt +++ new.declarationEmitExpandoPropertyPrivateName.errors.txt -@@= skipped -0, +0 lines =@@ --b.ts(4,1): error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. -- -- --==== a.ts (0 errors) ==== -- interface I {} -- export function f(): I { return null as I; } --==== b.ts (1 errors) ==== -- import {f} from "./a"; -- -- export function q() {} -- q.val = f(); +@@= skipped -8, +8 lines =@@ + + export function q() {} + q.val = f(); - ~~~~~ --!!! error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. -- -+ \ No newline at end of file ++ ~~~~~~~~~~~ + !!! error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js index 4b994cff3c..62611a4b50 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js @@ -31,3 +31,6 @@ export declare function f(): I; export {}; //// [b.d.ts] export declare function q(): void; +export declare namespace q { + var val: I; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff index e97c240744..1a0346d4ab 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff @@ -14,4 +14,7 @@ export declare function f(): I; export {}; +//// [b.d.ts] -+export declare function q(): void; \ No newline at end of file ++export declare function q(): void; ++export declare namespace q { ++ var val: I; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js index 02c1beb29a..cf2922f110 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js @@ -36,8 +36,8 @@ export interface Rect

{ readonly a: p; readonly b: p; } -export declare const Point: { - (x: number, y: number): Point; - zero: () => Point; -}; +export declare function Point(x: number, y: number): Point; export declare const Rect:

(a: p, b: p) => Rect

; +export declare namespace Point { + var zero: () => Point; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff index 6b591946c6..eca527388e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff @@ -1,10 +1,15 @@ --- old.declarationEmitExpandoWithGenericConstraint.js +++ new.declarationEmitExpandoWithGenericConstraint.js -@@= skipped -37, +37 lines =@@ +@@= skipped -35, +35 lines =@@ + readonly a: p; + readonly b: p; } - export declare const Point: { - (x: number, y: number): Point; +-export declare const Point: { +- (x: number, y: number): Point; - zero(): Point; -+ zero: () => Point; - }; - export declare const Rect:

(a: p, b: p) => Rect

; \ No newline at end of file +-}; ++export declare function Point(x: number, y: number): Point; + export declare const Rect:

(a: p, b: p) => Rect

; ++export declare namespace Point { ++ var zero: () => Point; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js index f5ce29f90a..0c8480ef02 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js @@ -25,5 +25,22 @@ baz.normal = false; //// [declarationEmitFunctionKeywordProp.d.ts] declare function foo(): void; +declare namespace foo { + var _a: boolean; + export { _a as null }; +} declare function bar(): void; +declare namespace bar { + var async: boolean; +} +declare namespace bar { + var normal: boolean; +} declare function baz(): void; +declare namespace baz { + var _b: boolean; + export { _b as class }; +} +declare namespace baz { + var normal: boolean; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff index 5628351b23..06133cdc84 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -1,21 +1,21 @@ --- old.declarationEmitFunctionKeywordProp.js +++ new.declarationEmitFunctionKeywordProp.js -@@= skipped -24, +24 lines =@@ - - //// [declarationEmitFunctionKeywordProp.d.ts] - declare function foo(): void; --declare namespace foo { -- var _a: boolean; -- export { _a as null }; --} +@@= skipped -31, +31 lines =@@ declare function bar(): void; --declare namespace bar { -- var async: boolean; -- var normal: boolean; --} + declare namespace bar { + var async: boolean; ++} ++declare namespace bar { + var normal: boolean; + } declare function baz(): void; --declare namespace baz { + declare namespace baz { - var _a: boolean; - export var normal: boolean; - export { _a as class }; --} \ No newline at end of file ++ var _b: boolean; ++ export { _b as class }; ++} ++declare namespace baz { ++ var normal: boolean; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js index fc844a9af6..9d36f2464b 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -36,3 +36,9 @@ const a = foo[dashStrMem]; //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; +export declare namespace foo { + var bar: number; +} +export declare namespace foo { + var strMemName: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 9b5edc4ae8..e6fc1de8ea 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff @@ -1,10 +1,10 @@ --- old.declarationEmitLateBoundAssignments.js +++ new.declarationEmitLateBoundAssignments.js -@@= skipped -35, +35 lines =@@ - - //// [declarationEmitLateBoundAssignments.d.ts] +@@= skipped -37, +37 lines =@@ export declare function foo(): void; --export declare namespace foo { -- var bar: number; -- var strMemName: string; --} \ No newline at end of file + export declare namespace foo { + var bar: number; ++} ++export declare namespace foo { + var strMemName: string; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js index dbace19f24..370aaf1b30 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js @@ -121,7 +121,13 @@ arrow10[emoji] = 0; //// [declarationEmitLateBoundAssignments2.d.ts] export declare function decl(): void; +export declare namespace decl { + var B: string; +} export declare function decl2(): void; +export declare namespace decl2 { + var C: number; +} export declare function decl3(): void; export declare function decl4(): void; export declare function decl5(): void; @@ -130,14 +136,14 @@ export declare function decl7(): void; export declare function decl8(): void; export declare function decl9(): void; export declare function decl10(): void; -export declare const arrow: { - (): void; - B: string; -}; -export declare const arrow2: { - (): void; - C: number; -}; +export declare function arrow(): void; +export declare namespace arrow { + var B: string; +} +export declare function arrow2(): void; +export declare namespace arrow2 { + var C: number; +} export declare const arrow3: { (): void; 77: number; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff index 7b63352120..d2275bb556 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff @@ -1,16 +1,8 @@ --- old.declarationEmitLateBoundAssignments2.js +++ new.declarationEmitLateBoundAssignments2.js -@@= skipped -120, +120 lines =@@ - - //// [declarationEmitLateBoundAssignments2.d.ts] - export declare function decl(): void; --export declare namespace decl { -- var B: string; --} - export declare function decl2(): void; --export declare namespace decl2 { -- var C: number; --} +@@= skipped -128, +128 lines =@@ + var C: number; + } export declare function decl3(): void; -export declare namespace decl3 { } export declare function decl4(): void; @@ -27,6 +19,22 @@ -export declare namespace decl9 { } export declare function decl10(): void; -export declare namespace decl10 { } - export declare const arrow: { +-export declare const arrow: { +- (): void; +- B: string; +-}; +-export declare const arrow2: { +- (): void; +- C: number; +-}; ++export declare function arrow(): void; ++export declare namespace arrow { ++ var B: string; ++} ++export declare function arrow2(): void; ++export declare namespace arrow2 { ++ var C: number; ++} + export declare const arrow3: { (): void; - B: string; \ No newline at end of file + 77: number; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js index b3e5b3073c..c807097433 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -26,3 +26,9 @@ const a = foo[dashStrMem]; //// [file.d.ts] export declare function foo(): void; +export declare namespace foo { + var bar: number; +} +export declare namespace foo { + var strMemName: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 62c383b58d..3f66ad50ff 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -8,5 +8,10 @@ -export namespace foo { - let bar: number; - let strMemName: string; --} -+export declare function foo(): void; \ No newline at end of file ++export declare function foo(): void; ++export declare namespace foo { ++ var bar: number; ++} ++export declare namespace foo { ++ var strMemName: string; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js index a5f9b593d5..1b37891205 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js @@ -45,3 +45,6 @@ if (Math.random()) { //// [expandoFunctionBlockShadowing.d.ts] export declare function X(): void; export declare function Y(): void; +export declare namespace Y { + var test: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index fa0b90a7ec..ad675825bb 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff @@ -11,11 +11,4 @@ +// https://github.com/microsoft/TypeScript/issues/56538 function X() { } if (Math.random()) { - const X = {}; -@@= skipped -23, +23 lines =@@ - //// [expandoFunctionBlockShadowing.d.ts] - export declare function X(): void; - export declare function Y(): void; --export declare namespace Y { -- var test: string; --} \ No newline at end of file + const X = {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js index 984cc06333..054a90b860 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js @@ -27,11 +27,11 @@ exports.expr2[s] = 0; //// [expandoFunctionExpressionsWithDynamicNames.d.ts] -export declare const expr: { - (): void; - X: number; -}; -export declare const expr2: { - (): void; - X: number; -}; +export declare function expr(): void; +export declare namespace expr { + var X: number; +} +export declare function expr2(): void; +export declare namespace expr2 { + var X: number; +} diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff index 91ce438ddd..df20fd2068 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff @@ -10,4 +10,24 @@ +// https://github.com/microsoft/TypeScript/issues/54809 const s = "X"; const expr = () => { }; - exports.expr = expr; \ No newline at end of file + exports.expr = expr; +@@= skipped -13, +13 lines =@@ + + + //// [expandoFunctionExpressionsWithDynamicNames.d.ts] +-export declare const expr: { +- (): void; +- X: number; +-}; +-export declare const expr2: { +- (): void; +- X: number; +-}; ++export declare function expr(): void; ++export declare namespace expr { ++ var X: number; ++} ++export declare function expr2(): void; ++export declare namespace expr2 { ++ var X: number; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js index 8f211bd237..6616dff493 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -22,11 +22,14 @@ errorOnMissingReturn.a = ""; //// [isolatedDeclarationErrors.d.ts] declare function errorOnAssignmentBelowDecl(): void; -declare const errorOnAssignmentBelow: { - (): void; - a: string; -}; -declare const errorOnMissingReturn: { - (): void; - a: string; -}; +declare namespace errorOnAssignmentBelowDecl { + var a: string; +} +declare function errorOnAssignmentBelow(): void; +declare namespace errorOnAssignmentBelow { + var a: string; +} +declare function errorOnMissingReturn(): void; +declare namespace errorOnMissingReturn { + var a: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index a2e2b81506..47bb029ded 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -8,11 +8,14 @@ + +//// [isolatedDeclarationErrors.d.ts] +declare function errorOnAssignmentBelowDecl(): void; -+declare const errorOnAssignmentBelow: { -+ (): void; -+ a: string; -+}; -+declare const errorOnMissingReturn: { -+ (): void; -+ a: string; -+}; \ No newline at end of file ++declare namespace errorOnAssignmentBelowDecl { ++ var a: string; ++} ++declare function errorOnAssignmentBelow(): void; ++declare namespace errorOnAssignmentBelow { ++ var a: string; ++} ++declare function errorOnMissingReturn(): void; ++declare namespace errorOnMissingReturn { ++ var a: string; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js index 52f0d4f7c5..32cbc8903c 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -25,3 +25,24 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] export declare function foo(): void; +export declare namespace foo { + var apply: () => void; +} +export declare namespace foo { + var call: () => void; +} +export declare namespace foo { + var bind: () => void; +} +export declare namespace foo { + var caller: () => void; +} +export declare namespace foo { + var toString: () => void; +} +export declare namespace foo { + var length: number; +} +export declare namespace foo { + var length: number; +} diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff index ea6e1338aa..158cd2ae6c 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -7,4 +7,25 @@ + + +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] -+export declare function foo(): void; \ No newline at end of file ++export declare function foo(): void; ++export declare namespace foo { ++ var apply: () => void; ++} ++export declare namespace foo { ++ var call: () => void; ++} ++export declare namespace foo { ++ var bind: () => void; ++} ++export declare namespace foo { ++ var caller: () => void; ++} ++export declare namespace foo { ++ var toString: () => void; ++} ++export declare namespace foo { ++ var length: number; ++} ++export declare namespace foo { ++ var length: number; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js index 9d4cfaead5..8e4843d111 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js @@ -19,11 +19,11 @@ SomeConstructor3.staticMember = "str"; //// [file.d.ts] declare const SomeConstructor: () => void; -declare const SomeConstructor2: { - (): void; - staticMember: string; -}; -declare const SomeConstructor3: { - (): void; - staticMember: string; -}; +declare function SomeConstructor2(): void; +declare namespace SomeConstructor2 { + var staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + var staticMember: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index 171c3332a5..d115dfd622 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -8,24 +8,18 @@ -declare class SomeConstructor { - x: number; -} --declare function SomeConstructor2(): void; --declare namespace SomeConstructor2 { ++declare const SomeConstructor: () => void; + declare function SomeConstructor2(): void; + declare namespace SomeConstructor2 { - let staticMember: string; --} --declare function SomeConstructor3(): void; --declare namespace SomeConstructor3 { ++ var staticMember: string; + } + declare function SomeConstructor3(): void; + declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} -declare class SomeConstructor3 { - x: number; --} -+declare const SomeConstructor: () => void; -+declare const SomeConstructor2: { -+ (): void; -+ staticMember: string; -+}; -+declare const SomeConstructor3: { -+ (): void; -+ staticMember: string; -+}; \ No newline at end of file ++ var staticMember: string; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js index b4b7986cec..4b6b926338 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -25,15 +25,15 @@ SelfReference.staticMember = "str"; //// [file.d.ts] declare const SomeConstructor: () => void; -declare const SomeConstructor2: { - (): void; - staticMember: string; -}; -declare const SomeConstructor3: { - (): void; - staticMember: string; -}; -declare const SelfReference: { - (): any; - staticMember: string; -}; +declare function SomeConstructor2(): void; +declare namespace SomeConstructor2 { + var staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + var staticMember: string; +} +declare function SelfReference(): any; +declare namespace SelfReference { + var staticMember: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 3b57bcf92d..74d665ccee 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -8,12 +8,14 @@ -declare class SomeConstructor { - x: number; -} --declare function SomeConstructor2(): void; --declare namespace SomeConstructor2 { ++declare const SomeConstructor: () => void; + declare function SomeConstructor2(): void; + declare namespace SomeConstructor2 { - let staticMember: string; --} --declare function SomeConstructor3(): void; --declare namespace SomeConstructor3 { ++ var staticMember: string; + } + declare function SomeConstructor3(): void; + declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} @@ -21,23 +23,14 @@ - x: number; -} -declare function SelfReference(): SelfReference; --declare namespace SelfReference { ++ var staticMember: string; ++} ++declare function SelfReference(): any; + declare namespace SelfReference { - let staticMember_2: string; - export { staticMember_2 as staticMember }; -} -declare class SelfReference { - x: number; --} -+declare const SomeConstructor: () => void; -+declare const SomeConstructor2: { -+ (): void; -+ staticMember: string; -+}; -+declare const SomeConstructor3: { -+ (): void; -+ staticMember: string; -+}; -+declare const SelfReference: { -+ (): any; -+ staticMember: string; -+}; \ No newline at end of file ++ var staticMember: string; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js index d3a96f6c16..cede538469 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js @@ -26,7 +26,18 @@ export default Foo; //// [jsxDeclarationsWithEsModuleInteropNoCrash.d.ts] /// +import PropTypes from 'prop-types'; declare function Foo({ bar }: { bar: any; }): JSX.Element; +declare namespace Foo { + var propTypes: { + bar: PropTypes.Requireable; + }; +} +declare namespace Foo { + var defaultProps: { + bar: boolean; + }; +} export default Foo; diff --git a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff index 1b8d5ca439..282833a6e0 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff @@ -5,10 +5,11 @@ //// [jsxDeclarationsWithEsModuleInteropNoCrash.d.ts] /// -export default Foo; ++import PropTypes from 'prop-types'; declare function Foo({ bar }: { bar: any; }): JSX.Element; --declare namespace Foo { + declare namespace Foo { - export { propTypes }; - export { defaultProps }; -} @@ -20,4 +21,13 @@ - export { bar_1 as bar }; -} -import PropTypes from 'prop-types'; ++ var propTypes: { ++ bar: PropTypes.Requireable; ++ }; ++} ++declare namespace Foo { ++ var defaultProps: { ++ bar: boolean; ++ }; ++} +export default Foo; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js index 328d1a72ea..05ce6daa8c 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js @@ -19,3 +19,6 @@ const x = foo[_private]; //// [index.d.ts] export declare function foo(): void; +export declare namespace foo { + var bar: number; +} diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff deleted file mode 100644 index 9b1699fd25..0000000000 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff +++ /dev/null @@ -1,9 +0,0 @@ ---- old.lateBoundFunctionMemberAssignmentDeclarations.js -+++ new.lateBoundFunctionMemberAssignmentDeclarations.js -@@= skipped -18, +18 lines =@@ - - //// [index.d.ts] - export declare function foo(): void; --export declare namespace foo { -- var bar: number; --} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js index 38bfb25afb..e79804a05e 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js @@ -47,6 +47,12 @@ assignmentToVoidZero2_1.j + assignmentToVoidZero2_1.k; //// [assignmentToVoidZero2.d.ts] export var j = 1; export var k = void 0; +declare namespace o { + var x: number; +} +declare namespace o { + var y: any; +} export {}; //// [importer.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff index 828b31c77b..a08ceb9494 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff @@ -25,6 +25,12 @@ -export const j: 1; +export var j = 1; +export var k = void 0; ++declare namespace o { ++ var x: number; ++} ++declare namespace o { ++ var y: any; ++} +export {}; //// [importer.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js index 7334c82bde..39c2df78a4 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js @@ -38,6 +38,13 @@ function f(k) { //// [mod1.d.ts] +declare namespace NS { + var K: { + new (): { + values(): /*elided*/ any; + }; + }; +} export var K = NS.K; export {}; //// [main.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff index 7951efe1d6..7dcf48b386 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff @@ -22,8 +22,14 @@ -export var K: { - new (): { - values(): /*elided*/ any; -- }; ++declare namespace NS { ++ var K: { ++ new (): { ++ values(): /*elided*/ any; ++ }; + }; -}; ++} +export var K = NS.K; +export {}; //// [main.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index c438749f3f..0565e4c96d 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -19,4 +19,8 @@ someFunc.someProp = 'yo'; //// [exportDefaultNamespace.d.ts] -export default function someFunc(): string; +declare function someFunc(): string; +export default someFunc; +declare namespace someFunc { + var someProp: string; +} diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff index c5f3a3a126..60f7690974 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -1,12 +1,11 @@ --- old.exportDefaultNamespace.js +++ new.exportDefaultNamespace.js -@@= skipped -18, +18 lines =@@ - +@@= skipped -19, +19 lines =@@ //// [exportDefaultNamespace.d.ts] --declare function someFunc(): string; --declare namespace someFunc { -- var someProp: string; --} --export default someFunc; -+export default function someFunc(): string; \ No newline at end of file + declare function someFunc(): string; ++export default someFunc; + declare namespace someFunc { + var someProp: string; + } +-export default someFunc; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js index 291c26285d..c4da697a19 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js @@ -129,6 +129,9 @@ C2.staticProp = function (x, y) { //// [jsDeclarationsClassMethod.d.ts] declare function C1(): void; +declare namespace C1 { + var staticProp: (x: any, y: any) => any; +} declare class C2 { /** * A comment method1 @@ -138,3 +141,6 @@ declare class C2 { */ method1(x: number, y: number): number; } +declare namespace C2 { + var staticProp: (x: any, y: any) => any; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff index 1520c1ddf2..864b04d0c7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff @@ -20,7 +20,7 @@ - */ - method(x: number, y: number): number; -} --declare namespace C1 { + declare namespace C1 { - /** - * A comment staticProp - * @param {number} x @@ -28,11 +28,11 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; --} ++ var staticProp: (x: any, y: any) => any; + } declare class C2 { /** - * A comment method1 -@@= skipped -33, +8 lines =@@ +@@= skipped -33, +11 lines =@@ * @returns {number} */ method1(x: number, y: number): number; @@ -43,8 +43,8 @@ - * @returns {number} - */ - method2(x: number, y: number): number; --} --declare namespace C2 { + } + declare namespace C2 { - /** - * A comment staticProp - * @param {number} x @@ -52,4 +52,5 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; ++ var staticProp: (x: any, y: any) => any; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js index 7b130e681b..72c30e4c2a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -52,6 +52,9 @@ module.exports.Strings = Strings; //// [source.d.ts] +declare namespace Handler { + var statische: () => void; +} export = Handler; export var Strings = Strings; export type HandlerOptions = { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff index 7b335ba61e..17b3390c8f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -19,15 +19,16 @@ module.exports.Strings = Strings; /** * @typedef {Object} HandlerOptions -@@= skipped -11, +13 lines =@@ +@@= skipped -10, +12 lines =@@ + //// [source.d.ts] - export = Handler; +-export = Handler; -declare class Handler { - static get OPTIONS(): number; - process(): void; -} --declare namespace Handler { + declare namespace Handler { - export { statische, Strings, HandlerOptions }; -} -declare function statische(): void; @@ -40,6 +41,9 @@ - * Should be able to export a type alias at the same time. - */ - name: string; ++ var statische: () => void; ++} ++export = Handler; +export var Strings = Strings; +export type HandlerOptions = { + name: String; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js index 96bb98ab89..84f368712e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js @@ -22,6 +22,8 @@ declare class Base { } export declare class Foo extends Base { } -export {}; +export declare namespace Foo { + var foo: string; +} //// [Bar.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff index f0e6cd5301..24118c9347 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff @@ -11,8 +11,12 @@ -} declare class Base { static foo: string; -+} -+export declare class Foo extends Base { } - export {}; - //// [Bar.d.ts] \ No newline at end of file +-export {}; ++export declare class Foo extends Base { ++} ++export declare namespace Foo { ++ var foo: string; ++} + //// [Bar.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js index 8038dc5993..479a6ab822 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -158,6 +158,44 @@ export type State = { timer: Timer; hook: Hook; }; +/** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ +/** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ +/** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ +/** + * New `Context` + * + * @class + * @param {Input} input + */ +declare function Context(input: Input): any; +declare namespace Context { + var prototype: { + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct(input: Input, handle?: any): State; + }; +} export = Context; //// [hook.d.ts] export type HookHandler = (arg: import("./context")) => void; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff index 6f918307d3..f4d945f527 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff @@ -46,6 +46,7 @@ - timeout: number; -} //// [context.d.ts] +-export = Context; +export type Timer = import("./timer"); +export type Hook = import("./hook"); +export type HookHandler = import("./hook").HookHandler; @@ -57,34 +58,13 @@ + timer: Timer; + hook: Hook; +}; - export = Context; --/** -- * Imports -- * -- * @typedef {import("./timer")} Timer -- * @typedef {import("./hook")} Hook -- * @typedef {import("./hook").HookHandler} HookHandler -- */ --/** -- * Input type definition -- * -- * @typedef {Object} Input -- * @prop {Timer} timer -- * @prop {Hook} hook -- */ --/** -- * State type definition -- * -- * @typedef {Object} State -- * @prop {Timer} timer -- * @prop {Hook} hook -- */ --/** -- * New `Context` -- * -- * @class -- * @param {Input} input -- */ + /** + * Imports + * +@@= skipped -45, +45 lines =@@ + * @class + * @param {Input} input + */ -declare function Context(input: Input): Context; -declare class Context { - /** @@ -123,9 +103,18 @@ - */ - construct(input: Input, handle?: HookHandler | undefined): State; -} --declare namespace Context { ++declare function Context(input: Input): any; + declare namespace Context { - export { Timer, Hook, HookHandler, Input, State }; --} ++ var prototype: { ++ /** ++ * @param {Input} input ++ * @param {HookHandler=} handle ++ * @returns {State} ++ */ ++ construct(input: Input, handle?: any): State; ++ }; + } -/** - * Imports - */ @@ -152,6 +141,7 @@ - timer: Timer; - hook: Hook; -}; ++export = Context; //// [hook.d.ts] +export type HookHandler = (arg: import("./context")) => void; export = Hook; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js index 4b6e7dcc70..f5a429881b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js @@ -25,5 +25,22 @@ baz.normal = false; //// [source.d.ts] declare function foo(): void; +declare namespace foo { + var _a: boolean; + export { _a as null }; +} declare function bar(): void; +declare namespace bar { + var async: boolean; +} +declare namespace bar { + var normal: boolean; +} declare function baz(): void; +declare namespace baz { + var _b: boolean; + export { _b as class }; +} +declare namespace baz { + var normal: boolean; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff index d529325b10..ca0bf04d42 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff @@ -1,22 +1,32 @@ --- old.jsDeclarationsFunctionKeywordProp.js +++ new.jsDeclarationsFunctionKeywordProp.js -@@= skipped -24, +24 lines =@@ - +@@= skipped -25, +25 lines =@@ //// [source.d.ts] declare function foo(): void; --declare namespace foo { + declare namespace foo { - let _null: boolean; - export { _null as null }; --} ++ var _a: boolean; ++ export { _a as null }; + } declare function bar(): void; --declare namespace bar { + declare namespace bar { - let async: boolean; - let normal: boolean; --} ++ var async: boolean; ++} ++declare namespace bar { ++ var normal: boolean; + } declare function baz(): void; --declare namespace baz { + declare namespace baz { - let _class: boolean; - export { _class as class }; - let normal_1: boolean; - export { normal_1 as normal }; --} \ No newline at end of file ++ var _b: boolean; ++ export { _b as class }; ++} ++declare namespace baz { ++ var normal: boolean; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js index b7bc4713a4..b8eb1d30f9 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -170,3 +170,282 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; +declare namespace foo { + var x: number; +} +declare namespace foo { + var y: number; +} +declare namespace foo { + var _a: number; + export { _a as break }; +} +declare namespace foo { + var _b: number; + export { _b as case }; +} +declare namespace foo { + var _c: number; + export { _c as catch }; +} +declare namespace foo { + var _d: number; + export { _d as class }; +} +declare namespace foo { + var _e: number; + export { _e as const }; +} +declare namespace foo { + var _f: number; + export { _f as continue }; +} +declare namespace foo { + var _g: number; + export { _g as debugger }; +} +declare namespace foo { + var _h: number; + export { _h as default }; +} +declare namespace foo { + var _j: number; + export { _j as delete }; +} +declare namespace foo { + var _k: number; + export { _k as do }; +} +declare namespace foo { + var _l: number; + export { _l as else }; +} +declare namespace foo { + var _m: number; + export { _m as enum }; +} +declare namespace foo { + var _o: number; + export { _o as export }; +} +declare namespace foo { + var _p: number; + export { _p as extends }; +} +declare namespace foo { + var _q: number; + export { _q as false }; +} +declare namespace foo { + var _r: number; + export { _r as finally }; +} +declare namespace foo { + var _s: number; + export { _s as for }; +} +declare namespace foo { + var _t: number; + export { _t as function }; +} +declare namespace foo { + var _u: number; + export { _u as if }; +} +declare namespace foo { + var _v: number; + export { _v as import }; +} +declare namespace foo { + var _w: number; + export { _w as in }; +} +declare namespace foo { + var _x: number; + export { _x as instanceof }; +} +declare namespace foo { + var _y: number; + export { _y as new }; +} +declare namespace foo { + var _z: number; + export { _z as null }; +} +declare namespace foo { + var _0: number; + export { _0 as return }; +} +declare namespace foo { + var _1: number; + export { _1 as super }; +} +declare namespace foo { + var _2: number; + export { _2 as switch }; +} +declare namespace foo { + var _3: number; + export { _3 as this }; +} +declare namespace foo { + var _4: number; + export { _4 as throw }; +} +declare namespace foo { + var _5: number; + export { _5 as true }; +} +declare namespace foo { + var _6: number; + export { _6 as try }; +} +declare namespace foo { + var _7: number; + export { _7 as typeof }; +} +declare namespace foo { + var _8: number; + export { _8 as var }; +} +declare namespace foo { + var _9: number; + export { _9 as void }; +} +declare namespace foo { + var _10: number; + export { _10 as while }; +} +declare namespace foo { + var _11: number; + export { _11 as with }; +} +declare namespace foo { + var _12: number; + export { _12 as implements }; +} +declare namespace foo { + var _13: number; + export { _13 as interface }; +} +declare namespace foo { + var _14: number; + export { _14 as let }; +} +declare namespace foo { + var _15: number; + export { _15 as package }; +} +declare namespace foo { + var _16: number; + export { _16 as private }; +} +declare namespace foo { + var _17: number; + export { _17 as protected }; +} +declare namespace foo { + var _18: number; + export { _18 as public }; +} +declare namespace foo { + var _19: number; + export { _19 as static }; +} +declare namespace foo { + var _20: number; + export { _20 as yield }; +} +declare namespace foo { + var abstract: number; +} +declare namespace foo { + var as: number; +} +declare namespace foo { + var asserts: number; +} +declare namespace foo { + var any: number; +} +declare namespace foo { + var async: number; +} +declare namespace foo { + var await: number; +} +declare namespace foo { + var boolean: number; +} +declare namespace foo { + var constructor: number; +} +declare namespace foo { + var declare: number; +} +declare namespace foo { + var get: number; +} +declare namespace foo { + var infer: number; +} +declare namespace foo { + var is: number; +} +declare namespace foo { + var keyof: number; +} +declare namespace foo { + var module: number; +} +declare namespace foo { + var namespace: number; +} +declare namespace foo { + var never: number; +} +declare namespace foo { + var readonly: number; +} +declare namespace foo { + var require: number; +} +declare namespace foo { + var number: number; +} +declare namespace foo { + var object: number; +} +declare namespace foo { + var set: number; +} +declare namespace foo { + var string: number; +} +declare namespace foo { + var symbol: number; +} +declare namespace foo { + var type: number; +} +declare namespace foo { + var undefined: number; +} +declare namespace foo { + var unique: number; +} +declare namespace foo { + var unknown: number; +} +declare namespace foo { + var from: number; +} +declare namespace foo { + var global: number; +} +declare namespace foo { + var bigint: number; +} +declare namespace foo { + var of: number; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff index fa3f869313..4dc3c418c2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff @@ -1,10 +1,9 @@ --- old.jsDeclarationsFunctionKeywordPropExhaustive.js +++ new.jsDeclarationsFunctionKeywordPropExhaustive.js -@@= skipped -169, +169 lines =@@ - +@@= skipped -170, +170 lines =@@ //// [source.d.ts] declare function foo(): void; --declare namespace foo { + declare namespace foo { - export let x: number; - export let y: number; - let _break: number; @@ -128,4 +127,281 @@ - export let global: number; - export let bigint: number; - export let of: number; --} \ No newline at end of file ++ var x: number; ++} ++declare namespace foo { ++ var y: number; ++} ++declare namespace foo { ++ var _a: number; ++ export { _a as break }; ++} ++declare namespace foo { ++ var _b: number; ++ export { _b as case }; ++} ++declare namespace foo { ++ var _c: number; ++ export { _c as catch }; ++} ++declare namespace foo { ++ var _d: number; ++ export { _d as class }; ++} ++declare namespace foo { ++ var _e: number; ++ export { _e as const }; ++} ++declare namespace foo { ++ var _f: number; ++ export { _f as continue }; ++} ++declare namespace foo { ++ var _g: number; ++ export { _g as debugger }; ++} ++declare namespace foo { ++ var _h: number; ++ export { _h as default }; ++} ++declare namespace foo { ++ var _j: number; ++ export { _j as delete }; ++} ++declare namespace foo { ++ var _k: number; ++ export { _k as do }; ++} ++declare namespace foo { ++ var _l: number; ++ export { _l as else }; ++} ++declare namespace foo { ++ var _m: number; ++ export { _m as enum }; ++} ++declare namespace foo { ++ var _o: number; ++ export { _o as export }; ++} ++declare namespace foo { ++ var _p: number; ++ export { _p as extends }; ++} ++declare namespace foo { ++ var _q: number; ++ export { _q as false }; ++} ++declare namespace foo { ++ var _r: number; ++ export { _r as finally }; ++} ++declare namespace foo { ++ var _s: number; ++ export { _s as for }; ++} ++declare namespace foo { ++ var _t: number; ++ export { _t as function }; ++} ++declare namespace foo { ++ var _u: number; ++ export { _u as if }; ++} ++declare namespace foo { ++ var _v: number; ++ export { _v as import }; ++} ++declare namespace foo { ++ var _w: number; ++ export { _w as in }; ++} ++declare namespace foo { ++ var _x: number; ++ export { _x as instanceof }; ++} ++declare namespace foo { ++ var _y: number; ++ export { _y as new }; ++} ++declare namespace foo { ++ var _z: number; ++ export { _z as null }; ++} ++declare namespace foo { ++ var _0: number; ++ export { _0 as return }; ++} ++declare namespace foo { ++ var _1: number; ++ export { _1 as super }; ++} ++declare namespace foo { ++ var _2: number; ++ export { _2 as switch }; ++} ++declare namespace foo { ++ var _3: number; ++ export { _3 as this }; ++} ++declare namespace foo { ++ var _4: number; ++ export { _4 as throw }; ++} ++declare namespace foo { ++ var _5: number; ++ export { _5 as true }; ++} ++declare namespace foo { ++ var _6: number; ++ export { _6 as try }; ++} ++declare namespace foo { ++ var _7: number; ++ export { _7 as typeof }; ++} ++declare namespace foo { ++ var _8: number; ++ export { _8 as var }; ++} ++declare namespace foo { ++ var _9: number; ++ export { _9 as void }; ++} ++declare namespace foo { ++ var _10: number; ++ export { _10 as while }; ++} ++declare namespace foo { ++ var _11: number; ++ export { _11 as with }; ++} ++declare namespace foo { ++ var _12: number; ++ export { _12 as implements }; ++} ++declare namespace foo { ++ var _13: number; ++ export { _13 as interface }; ++} ++declare namespace foo { ++ var _14: number; ++ export { _14 as let }; ++} ++declare namespace foo { ++ var _15: number; ++ export { _15 as package }; ++} ++declare namespace foo { ++ var _16: number; ++ export { _16 as private }; ++} ++declare namespace foo { ++ var _17: number; ++ export { _17 as protected }; ++} ++declare namespace foo { ++ var _18: number; ++ export { _18 as public }; ++} ++declare namespace foo { ++ var _19: number; ++ export { _19 as static }; ++} ++declare namespace foo { ++ var _20: number; ++ export { _20 as yield }; ++} ++declare namespace foo { ++ var abstract: number; ++} ++declare namespace foo { ++ var as: number; ++} ++declare namespace foo { ++ var asserts: number; ++} ++declare namespace foo { ++ var any: number; ++} ++declare namespace foo { ++ var async: number; ++} ++declare namespace foo { ++ var await: number; ++} ++declare namespace foo { ++ var boolean: number; ++} ++declare namespace foo { ++ var constructor: number; ++} ++declare namespace foo { ++ var declare: number; ++} ++declare namespace foo { ++ var get: number; ++} ++declare namespace foo { ++ var infer: number; ++} ++declare namespace foo { ++ var is: number; ++} ++declare namespace foo { ++ var keyof: number; ++} ++declare namespace foo { ++ var module: number; ++} ++declare namespace foo { ++ var namespace: number; ++} ++declare namespace foo { ++ var never: number; ++} ++declare namespace foo { ++ var readonly: number; ++} ++declare namespace foo { ++ var require: number; ++} ++declare namespace foo { ++ var number: number; ++} ++declare namespace foo { ++ var object: number; ++} ++declare namespace foo { ++ var set: number; ++} ++declare namespace foo { ++ var string: number; ++} ++declare namespace foo { ++ var symbol: number; ++} ++declare namespace foo { ++ var type: number; ++} ++declare namespace foo { ++ var undefined: number; ++} ++declare namespace foo { ++ var unique: number; ++} ++declare namespace foo { ++ var unknown: number; ++} ++declare namespace foo { ++ var from: number; ++} ++declare namespace foo { ++ var global: number; ++} ++declare namespace foo { ++ var bigint: number; ++} ++declare namespace foo { ++ var of: number; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js index 48d1497385..8a89d1edb4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js @@ -159,10 +159,26 @@ exports.origin = new source_1.Point2D(0, 0); * @param {number} len */ export declare function Vec(len: number): void; +export declare namespace Vec { + var prototype: { + /** + * @param {Vec} other + */ + dot(other: Vec): number; + magnitude(): number; + }; +} /** * @param {number} x * @param {number} y */ export declare function Point2D(x: number, y: number): any; +export declare namespace Point2D { + var prototype: { + __proto__: typeof Vec; + x: number; + y: number; + }; +} //// [referencer.d.ts] export declare const origin: any; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff index f1c814c9f1..ed8d9f8f75 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff @@ -28,8 +28,16 @@ - */ - dot(other: Vec): number; - magnitude(): number; --} +export declare function Vec(len: number): void; ++export declare namespace Vec { ++ var prototype: { ++ /** ++ * @param {Vec} other ++ */ ++ dot(other: Vec): number; ++ magnitude(): number; ++ }; + } /** * @param {number} x * @param {number} y @@ -52,8 +60,14 @@ - set y(y: number); - get y(): number; - __proto__: typeof Vec; --} +export declare function Point2D(x: number, y: number): any; ++export declare namespace Point2D { ++ var prototype: { ++ __proto__: typeof Vec; ++ x: number; ++ y: number; ++ }; + } //// [referencer.d.ts] -export const origin: Point2D; -import { Point2D } from "./source"; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index 25aba9ecba..e3f53cb229 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -34,6 +34,13 @@ MyClass.staticProperty = 123; //// [source.d.ts] export = MyClass; +declare function MyClass(): void; +declare namespace MyClass { + var staticMethod: () => void; +} +declare namespace MyClass { + var staticProperty: number; +} export type DoneCB = (failures: number) ; /** * Callback to be invoked when test execution is complete. diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index a39243d2a7..c52be93a6e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -10,11 +10,10 @@ module.exports = MyClass; function MyClass() { } MyClass.staticMethod = function () { }; -@@= skipped -15, +18 lines =@@ - +@@= skipped -16, +19 lines =@@ //// [source.d.ts] export = MyClass; --declare function MyClass(): void; + declare function MyClass(): void; -declare class MyClass { - method(): void; -} @@ -23,6 +22,12 @@ -} -declare function staticMethod(): void; -declare var staticProperty: number; ++declare namespace MyClass { ++ var staticMethod: () => void; ++} ++declare namespace MyClass { ++ var staticProperty: number; ++} +export type DoneCB = (failures: number) ; /** * Callback to be invoked when test execution is complete. diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js index d76ffef284..8a62f4e062 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -16,17 +16,12 @@ module.exports = foo; //// [index.d.ts] +declare function foo(): void; +declare namespace foo { + var foo: typeof import("."); +} +declare namespace foo { + var _a: typeof import("."); + export { _a as default }; +} export = foo; - - -//// [DtsFileErrors] - - -out/index.d.ts(1,10): error TS2304: Cannot find name 'foo'. - - -==== out/index.d.ts (1 errors) ==== - export = foo; - ~~~ -!!! error TS2304: Cannot find name 'foo'. - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff index b57b340c63..9b567ef448 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff @@ -9,22 +9,16 @@ //// [index.d.ts] - export = foo; --declare function foo(): void; --declare namespace foo { +-export = foo; + declare function foo(): void; + declare namespace foo { - export { foo }; - export { foo as default }; -} -+ -+ -+//// [DtsFileErrors] -+ -+ -+out/index.d.ts(1,10): error TS2304: Cannot find name 'foo'. -+ -+ -+==== out/index.d.ts (1 errors) ==== -+ export = foo; -+ ~~~ -+!!! error TS2304: Cannot find name 'foo'. -+ \ No newline at end of file ++ var foo: typeof import("."); ++} ++declare namespace foo { ++ var _a: typeof import("."); ++ export { _a as default }; ++} ++export = foo; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js index 7a1612bab4..8aa44cbc27 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -123,7 +123,15 @@ function j() { } //// [index.d.ts] export declare function a(): void; export declare function b(): void; +export declare namespace b { + var cat: string; +} export declare function c(): void; +export declare namespace c { + var Cls: { + new (): {}; + }; +} /** * @param {number} a * @param {number} b @@ -142,6 +150,9 @@ export declare function e(a: T, b: U): T & U; * @param {T} a */ export declare function f(a: T): T; +export declare namespace f { + var self: typeof f; +} /** * @param {{x: string}} a * @param {{y: typeof b}} b diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 75088fe6e6..8e2b016ad7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -25,14 +25,20 @@ -export function b(): void; -export namespace b { - let cat: string; --} ++export declare function a(): void; ++export declare function b(): void; ++export declare namespace b { ++ var cat: string; + } -export function c(): void; -export namespace c { - export { Cls }; --} -+export declare function a(): void; -+export declare function b(): void; +export declare function c(): void; ++export declare namespace c { ++ var Cls: { ++ new (): {}; ++ }; + } /** * @param {number} a * @param {number} b @@ -59,8 +65,10 @@ -export function i(): void; -export function j(): void; -declare class Cls { --} +export declare function f(a: T): T; ++export declare namespace f { ++ var self: typeof f; + } /** * @param {{x: string}} a * @param {{y: typeof b}} b @@ -77,7 +85,7 @@ /** * @param {{x: string}} a * @param {{y: typeof b}} b -@@= skipped -50, +38 lines =@@ +@@= skipped -50, +49 lines =@@ declare function hh(a: { x: string; }, b: { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js index 6be074102e..f707949cf4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -62,6 +62,13 @@ export {}; //// [base.d.ts] +declare class Base { + constructor(); +} +declare function BaseFactory(): Base; +declare namespace BaseFactory { + var Base: typeof Base; +} export = BaseFactory; //// [file.d.ts] export type BaseFactory = import('./base'); diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff index f2dae38cd5..13850b4946 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -16,13 +16,19 @@ //// [base.d.ts] - export = BaseFactory; --declare function BaseFactory(): Base; --declare namespace BaseFactory { +-export = BaseFactory; ++declare class Base { ++ constructor(); ++} + declare function BaseFactory(): Base; + declare namespace BaseFactory { - export { Base }; -} -declare class Base { -} ++ var Base: typeof Base; ++} ++export = BaseFactory; //// [file.d.ts] -type couldntThinkOfAny = { - (): {}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js index 3c6498cabf..25a713c08c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js @@ -50,6 +50,13 @@ export {}; //// [base.d.ts] +declare class Base { + constructor(); +} +declare function BaseFactory(): Base; +declare namespace BaseFactory { + var Base: typeof Base; +} export = BaseFactory; //// [file.d.ts] export type BaseFactory = typeof import('./base'); diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff index 4e00b4f79b..9f430cfe7a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff @@ -16,13 +16,19 @@ //// [base.d.ts] - export = BaseFactory; --declare function BaseFactory(): Base; --declare namespace BaseFactory { +-export = BaseFactory; ++declare class Base { ++ constructor(); ++} + declare function BaseFactory(): Base; + declare namespace BaseFactory { - export { Base }; -} -declare class Base { -} ++ var Base: typeof Base; ++} ++export = BaseFactory; //// [file.d.ts] -/** @typedef {typeof import('./base')} BaseFactory */ -/** diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index 8f6c583f8a..41c2f8c81b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -186,47 +186,57 @@ exports.default = Tree; //// [jsDeclarationsReactComponents1.d.ts] /// import PropTypes from "prop-types"; -declare const TabbedShowLayout: { - ({}: {}): JSX.Element; - propTypes: { +declare function TabbedShowLayout({}: {}): JSX.Element; +declare namespace TabbedShowLayout { + var propTypes: { version: PropTypes.Requireable; }; - defaultProps: { +} +declare namespace TabbedShowLayout { + var defaultProps: { tabs: undefined; }; -}; +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.d.ts] import React from "react"; -/** - * @type {React.SFC} - */ -declare const TabbedShowLayout: React.SFC; +declare function TabbedShowLayout(): JSX.Element; +declare namespace TabbedShowLayout { + var defaultProps: Partial<{}> | undefined; +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] -/** - * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} - */ -declare const TabbedShowLayout: { - defaultProps: { +declare function TabbedShowLayout(): JSX.Element; +declare namespace TabbedShowLayout { + var defaultProps: { tabs: string; }; -} & ((props?: { - elem: string; -}) => JSX.Element); +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] -declare const TabbedShowLayout: { - (prop: { - className: string; - }): JSX.Element; - defaultProps: { +declare function TabbedShowLayout(/** @type {{className: string}}*/ prop: { + className: string; +}): JSX.Element; +declare namespace TabbedShowLayout { + var defaultProps: { tabs: string; }; -}; +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents5.d.ts] +import PropTypes from 'prop-types'; declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; +declare namespace Tree { + var propTypes: { + classes: PropTypes.Requireable; + }; +} +declare namespace Tree { + var defaultProps: { + classes: {}; + parentSource: string; + }; +} export default Tree; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index 0422126dd6..4e509eca1c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -64,15 +64,17 @@ - } -} import PropTypes from "prop-types"; -+declare const TabbedShowLayout: { -+ ({}: {}): JSX.Element; -+ propTypes: { ++declare function TabbedShowLayout({}: {}): JSX.Element; ++declare namespace TabbedShowLayout { ++ var propTypes: { + version: PropTypes.Requireable; + }; -+ defaultProps: { ++} ++declare namespace TabbedShowLayout { ++ var defaultProps: { + tabs: undefined; + }; -+}; ++} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.d.ts] -export default TabbedShowLayout; @@ -81,45 +83,50 @@ - */ -declare const TabbedShowLayout: React.SFC; import React from "react"; -+/** -+ * @type {React.SFC} -+ */ -+declare const TabbedShowLayout: React.SFC; ++declare function TabbedShowLayout(): JSX.Element; ++declare namespace TabbedShowLayout { ++ var defaultProps: Partial<{}> | undefined; ++} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] -export default TabbedShowLayout; - /** - * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} - */ -@@= skipped -30, +29 lines =@@ - } & ((props?: { - elem: string; - }) => JSX.Element); +-/** +- * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} +- */ +-declare const TabbedShowLayout: { +- defaultProps: { ++declare function TabbedShowLayout(): JSX.Element; ++declare namespace TabbedShowLayout { ++ var defaultProps: { + tabs: string; + }; +-} & ((props?: { +- elem: string; +-}) => JSX.Element); ++} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] -+declare const TabbedShowLayout: { -+ (prop: { -+ className: string; -+ }): JSX.Element; -+ defaultProps: { -+ tabs: string; -+ }; -+}; - export default TabbedShowLayout; +-export default TabbedShowLayout; -declare function TabbedShowLayout(prop: { -- className: string; --}): JSX.Element; --declare namespace TabbedShowLayout { ++declare function TabbedShowLayout(/** @type {{className: string}}*/ prop: { + className: string; + }): JSX.Element; + declare namespace TabbedShowLayout { - namespace defaultProps { - let tabs: string; - } --} ++ var defaultProps: { ++ tabs: string; ++ }; + } ++export default TabbedShowLayout; //// [jsDeclarationsReactComponents5.d.ts] -export default Tree; ++import PropTypes from 'prop-types'; declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; --declare namespace Tree { + declare namespace Tree { - namespace propTypes { - let classes: PropTypes.Requireable; - } @@ -130,4 +137,14 @@ - } -} -import PropTypes from 'prop-types'; ++ var propTypes: { ++ classes: PropTypes.Requireable; ++ }; ++} ++declare namespace Tree { ++ var defaultProps: { ++ classes: {}; ++ parentSource: string; ++ }; ++} +export default Tree; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js index 83f4b967b4..3d7bf0d2a6 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js @@ -83,6 +83,13 @@ declare var Ns: { /** @implements {A} */ C5: any; }; +declare namespace Ns { + var C1: { + new (): { + method(): number; + }; + }; +} /** @implements {A} */ declare var C2: { new (): { @@ -106,3 +113,6 @@ declare class CC { }; } declare var C5: any; +declare namespace Ns { + var C5: any; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff index 97a55138f3..7119367ce6 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff @@ -4,23 +4,24 @@ /** @implements {A} */ declare class B3 implements A { } --declare namespace Ns { -- export { C1 }; -- export let C5: { +declare var Ns: { + /** @implements {A} */ + C1: { - new (): { - method(): number; - }; - }; --} ++ new (): { ++ method(): number; ++ }; ++ }; + /** @implements {A} */ + C5: any; +}; - /** @implements {A} */ - declare var C2: { - new (): { + declare namespace Ns { +- export { C1 }; +- export let C5: { ++ var C1: { + new (): { + method(): number; + }; +@@= skipped -14, +23 lines =@@ method(): number; }; }; @@ -38,7 +39,7 @@ declare class CC { /** @implements {A} */ C4: { -@@= skipped -26, +33 lines =@@ +@@= skipped -12, +17 lines =@@ }; } declare var C5: any; @@ -47,4 +48,6 @@ -} -declare class C3 implements A { - method(): number; --} \ No newline at end of file ++declare namespace Ns { ++ var C5: any; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js index 687fcfe9e3..ab6060fccf 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js @@ -171,3 +171,282 @@ foo.of = 1; //// [nullPropertyName.d.ts] declare function foo(): void; +declare namespace foo { + var x: number; +} +declare namespace foo { + var y: number; +} +declare namespace foo { + var _a: number; + export { _a as break }; +} +declare namespace foo { + var _b: number; + export { _b as case }; +} +declare namespace foo { + var _c: number; + export { _c as catch }; +} +declare namespace foo { + var _d: number; + export { _d as class }; +} +declare namespace foo { + var _e: number; + export { _e as const }; +} +declare namespace foo { + var _f: number; + export { _f as continue }; +} +declare namespace foo { + var _g: number; + export { _g as debugger }; +} +declare namespace foo { + var _h: number; + export { _h as default }; +} +declare namespace foo { + var _j: number; + export { _j as delete }; +} +declare namespace foo { + var _k: number; + export { _k as do }; +} +declare namespace foo { + var _l: number; + export { _l as else }; +} +declare namespace foo { + var _m: number; + export { _m as enum }; +} +declare namespace foo { + var _o: number; + export { _o as export }; +} +declare namespace foo { + var _p: number; + export { _p as extends }; +} +declare namespace foo { + var _q: number; + export { _q as false }; +} +declare namespace foo { + var _r: number; + export { _r as finally }; +} +declare namespace foo { + var _s: number; + export { _s as for }; +} +declare namespace foo { + var _t: number; + export { _t as function }; +} +declare namespace foo { + var _u: number; + export { _u as if }; +} +declare namespace foo { + var _v: number; + export { _v as import }; +} +declare namespace foo { + var _w: number; + export { _w as in }; +} +declare namespace foo { + var _x: number; + export { _x as instanceof }; +} +declare namespace foo { + var _y: number; + export { _y as new }; +} +declare namespace foo { + var _z: number; + export { _z as null }; +} +declare namespace foo { + var _0: number; + export { _0 as return }; +} +declare namespace foo { + var _1: number; + export { _1 as super }; +} +declare namespace foo { + var _2: number; + export { _2 as switch }; +} +declare namespace foo { + var _3: number; + export { _3 as this }; +} +declare namespace foo { + var _4: number; + export { _4 as throw }; +} +declare namespace foo { + var _5: number; + export { _5 as true }; +} +declare namespace foo { + var _6: number; + export { _6 as try }; +} +declare namespace foo { + var _7: number; + export { _7 as typeof }; +} +declare namespace foo { + var _8: number; + export { _8 as var }; +} +declare namespace foo { + var _9: number; + export { _9 as void }; +} +declare namespace foo { + var _10: number; + export { _10 as while }; +} +declare namespace foo { + var _11: number; + export { _11 as with }; +} +declare namespace foo { + var _12: number; + export { _12 as implements }; +} +declare namespace foo { + var _13: number; + export { _13 as interface }; +} +declare namespace foo { + var _14: number; + export { _14 as let }; +} +declare namespace foo { + var _15: number; + export { _15 as package }; +} +declare namespace foo { + var _16: number; + export { _16 as private }; +} +declare namespace foo { + var _17: number; + export { _17 as protected }; +} +declare namespace foo { + var _18: number; + export { _18 as public }; +} +declare namespace foo { + var _19: number; + export { _19 as static }; +} +declare namespace foo { + var _20: number; + export { _20 as yield }; +} +declare namespace foo { + var abstract: number; +} +declare namespace foo { + var as: number; +} +declare namespace foo { + var asserts: number; +} +declare namespace foo { + var any: number; +} +declare namespace foo { + var async: number; +} +declare namespace foo { + var await: number; +} +declare namespace foo { + var boolean: number; +} +declare namespace foo { + var constructor: number; +} +declare namespace foo { + var declare: number; +} +declare namespace foo { + var get: number; +} +declare namespace foo { + var infer: number; +} +declare namespace foo { + var is: number; +} +declare namespace foo { + var keyof: number; +} +declare namespace foo { + var module: number; +} +declare namespace foo { + var namespace: number; +} +declare namespace foo { + var never: number; +} +declare namespace foo { + var readonly: number; +} +declare namespace foo { + var require: number; +} +declare namespace foo { + var number: number; +} +declare namespace foo { + var object: number; +} +declare namespace foo { + var set: number; +} +declare namespace foo { + var string: number; +} +declare namespace foo { + var symbol: number; +} +declare namespace foo { + var type: number; +} +declare namespace foo { + var undefined: number; +} +declare namespace foo { + var unique: number; +} +declare namespace foo { + var unknown: number; +} +declare namespace foo { + var from: number; +} +declare namespace foo { + var global: number; +} +declare namespace foo { + var bigint: number; +} +declare namespace foo { + var of: number; +} diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff index 60cf26b0b5..a2d826927d 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff @@ -1,57 +1,194 @@ --- old.nullPropertyName.js +++ new.nullPropertyName.js -@@= skipped -170, +170 lines =@@ - +@@= skipped -171, +171 lines =@@ //// [nullPropertyName.d.ts] declare function foo(): void; --declare namespace foo { + declare namespace foo { - export var x: number; - export var y: number; -- var _a: number; -- var _b: number; -- var _c: number; -- var _d: number; -- var _e: number; -- var _f: number; -- var _g: number; -- var _h: number; -- var _j: number; -- var _k: number; -- var _l: number; -- var _m: number; -- var _o: number; -- var _p: number; -- var _q: number; -- var _r: number; -- var _s: number; -- var _t: number; -- var _u: number; -- var _v: number; -- var _w: number; -- var _x: number; -- var _y: number; -- var _z: number; -- var _0: number; -- var _1: number; -- var _2: number; -- var _3: number; -- var _4: number; -- var _5: number; -- var _6: number; -- var _7: number; -- var _8: number; -- var _9: number; -- var _10: number; -- var _11: number; -- var _12: number; -- var _13: number; -- var _14: number; -- var _15: number; -- var _16: number; -- var _17: number; -- var _18: number; -- var _19: number; -- var _20: number; ++ var x: number; ++} ++declare namespace foo { ++ var y: number; ++} ++declare namespace foo { + var _a: number; ++ export { _a as break }; ++} ++declare namespace foo { + var _b: number; ++ export { _b as case }; ++} ++declare namespace foo { + var _c: number; ++ export { _c as catch }; ++} ++declare namespace foo { + var _d: number; ++ export { _d as class }; ++} ++declare namespace foo { + var _e: number; ++ export { _e as const }; ++} ++declare namespace foo { + var _f: number; ++ export { _f as continue }; ++} ++declare namespace foo { + var _g: number; ++ export { _g as debugger }; ++} ++declare namespace foo { + var _h: number; ++ export { _h as default }; ++} ++declare namespace foo { + var _j: number; ++ export { _j as delete }; ++} ++declare namespace foo { + var _k: number; ++ export { _k as do }; ++} ++declare namespace foo { + var _l: number; ++ export { _l as else }; ++} ++declare namespace foo { + var _m: number; ++ export { _m as enum }; ++} ++declare namespace foo { + var _o: number; ++ export { _o as export }; ++} ++declare namespace foo { + var _p: number; ++ export { _p as extends }; ++} ++declare namespace foo { + var _q: number; ++ export { _q as false }; ++} ++declare namespace foo { + var _r: number; ++ export { _r as finally }; ++} ++declare namespace foo { + var _s: number; ++ export { _s as for }; ++} ++declare namespace foo { + var _t: number; ++ export { _t as function }; ++} ++declare namespace foo { + var _u: number; ++ export { _u as if }; ++} ++declare namespace foo { + var _v: number; ++ export { _v as import }; ++} ++declare namespace foo { + var _w: number; ++ export { _w as in }; ++} ++declare namespace foo { + var _x: number; ++ export { _x as instanceof }; ++} ++declare namespace foo { + var _y: number; ++ export { _y as new }; ++} ++declare namespace foo { + var _z: number; ++ export { _z as null }; ++} ++declare namespace foo { + var _0: number; ++ export { _0 as return }; ++} ++declare namespace foo { + var _1: number; ++ export { _1 as super }; ++} ++declare namespace foo { + var _2: number; ++ export { _2 as switch }; ++} ++declare namespace foo { + var _3: number; ++ export { _3 as this }; ++} ++declare namespace foo { + var _4: number; ++ export { _4 as throw }; ++} ++declare namespace foo { + var _5: number; ++ export { _5 as true }; ++} ++declare namespace foo { + var _6: number; ++ export { _6 as try }; ++} ++declare namespace foo { + var _7: number; ++ export { _7 as typeof }; ++} ++declare namespace foo { + var _8: number; ++ export { _8 as var }; ++} ++declare namespace foo { + var _9: number; ++ export { _9 as void }; ++} ++declare namespace foo { + var _10: number; ++ export { _10 as while }; ++} ++declare namespace foo { + var _11: number; ++ export { _11 as with }; ++} ++declare namespace foo { + var _12: number; ++ export { _12 as implements }; ++} ++declare namespace foo { + var _13: number; ++ export { _13 as interface }; ++} ++declare namespace foo { + var _14: number; ++ export { _14 as let }; ++} ++declare namespace foo { + var _15: number; ++ export { _15 as package }; ++} ++declare namespace foo { + var _16: number; ++ export { _16 as private }; ++} ++declare namespace foo { + var _17: number; ++ export { _17 as protected }; ++} ++declare namespace foo { + var _18: number; ++ export { _18 as public }; ++} ++declare namespace foo { + var _19: number; ++ export { _19 as static }; ++} ++declare namespace foo { + var _20: number; - export var abstract: number; - export var as: number; - export var asserts: number; @@ -84,4 +221,98 @@ - export var bigint: number; - export var of: number; - export { _a as break, _b as case, _c as catch, _d as class, _e as const, _f as continue, _g as debugger, _h as default, _j as delete, _k as do, _l as else, _m as enum, _o as export, _p as extends, _q as false, _r as finally, _s as for, _t as function, _u as if, _v as import, _w as in, _x as instanceof, _y as new, _z as null, _0 as return, _1 as super, _2 as switch, _3 as this, _4 as throw, _5 as true, _6 as try, _7 as typeof, _8 as var, _9 as void, _10 as while, _11 as with, _12 as implements, _13 as interface, _14 as let, _15 as package, _16 as private, _17 as protected, _18 as public, _19 as static, _20 as yield }; --} \ No newline at end of file ++ export { _20 as yield }; ++} ++declare namespace foo { ++ var abstract: number; ++} ++declare namespace foo { ++ var as: number; ++} ++declare namespace foo { ++ var asserts: number; ++} ++declare namespace foo { ++ var any: number; ++} ++declare namespace foo { ++ var async: number; ++} ++declare namespace foo { ++ var await: number; ++} ++declare namespace foo { ++ var boolean: number; ++} ++declare namespace foo { ++ var constructor: number; ++} ++declare namespace foo { ++ var declare: number; ++} ++declare namespace foo { ++ var get: number; ++} ++declare namespace foo { ++ var infer: number; ++} ++declare namespace foo { ++ var is: number; ++} ++declare namespace foo { ++ var keyof: number; ++} ++declare namespace foo { ++ var module: number; ++} ++declare namespace foo { ++ var namespace: number; ++} ++declare namespace foo { ++ var never: number; ++} ++declare namespace foo { ++ var readonly: number; ++} ++declare namespace foo { ++ var require: number; ++} ++declare namespace foo { ++ var number: number; ++} ++declare namespace foo { ++ var object: number; ++} ++declare namespace foo { ++ var set: number; ++} ++declare namespace foo { ++ var string: number; ++} ++declare namespace foo { ++ var symbol: number; ++} ++declare namespace foo { ++ var type: number; ++} ++declare namespace foo { ++ var undefined: number; ++} ++declare namespace foo { ++ var unique: number; ++} ++declare namespace foo { ++ var unknown: number; ++} ++declare namespace foo { ++ var from: number; ++} ++declare namespace foo { ++ var global: number; ++} ++declare namespace foo { ++ var bigint: number; ++} ++declare namespace foo { ++ var of: number; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js index 2726349e59..b31808bd20 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -170,29 +170,54 @@ var n = ExpandoExpr3.prop + ExpandoExpr3.m(13) + new ExpandoExpr3().n; //// [typeFromPropertyAssignment29.d.ts] declare function ExpandoDecl(n: number): string; +declare namespace ExpandoDecl { + var prop: number; +} +declare namespace ExpandoDecl { + var m: (n: number) => number; +} declare var n: number; -declare const ExpandoExpr: { - (n: number): string; - prop: { +declare function ExpandoExpr(n: number): string; +declare namespace ExpandoExpr { + var prop: { x: number; y?: undefined; } | { x?: undefined; y: string; }; - m: (n: number) => number; -}; +} +declare namespace ExpandoExpr { + var prop: { + x: number; + y?: undefined; + } | { + x?: undefined; + y: string; + }; +} +declare namespace ExpandoExpr { + var m: (n: number) => number; +} declare var n: number; -declare const ExpandoArrow: { - (n: number): string; - prop: number; - m: (n: number) => number; -}; +declare function ExpandoArrow(n: number): string; +declare namespace ExpandoArrow { + var prop: number; +} +declare namespace ExpandoArrow { + var m: (n: number) => number; +} declare function ExpandoNested(n: number): { (m: number): number; total: number; }; +declare namespace ExpandoNested { + var also: number; +} declare function ExpandoMerge(n: number): number; +declare namespace ExpandoMerge { + var p1: number; +} declare namespace ExpandoMerge { var p2: number; } @@ -202,6 +227,9 @@ declare namespace ExpandoMerge { declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; + declare namespace ExpandoNamespace { + var p6: number; + } export function foo(): typeof ExpandoNamespace; export {}; } diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index ec27c63891..c3bef5520a 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -31,53 +31,74 @@ }; ExpandoExpr3.prop = 3; ExpandoExpr3.m = function (n) { -@@= skipped -13, +11 lines =@@ - - //// [typeFromPropertyAssignment29.d.ts] +@@= skipped -15, +13 lines =@@ declare function ExpandoDecl(n: number): string; --declare namespace ExpandoDecl { -- var prop: number; + declare namespace ExpandoDecl { + var prop: number; - var m: (n: number) => number; -} - declare var n: number; - declare const ExpandoExpr: { - (n: number): string; -@@= skipped -14, +10 lines =@@ - x?: undefined; - y: string; - }; +-declare var n: number; +-declare const ExpandoExpr: { +- (n: number): string; +- prop: { +- x: number; +- y?: undefined; +- } | { +- x?: undefined; +- y: string; +- }; - m(n: number): number; -+ m: (n: number) => number; - }; - declare var n: number; - declare const ExpandoArrow: { - (n: number): string; - prop: number; +-}; +-declare var n: number; +-declare const ExpandoArrow: { +- (n: number): string; +- prop: number; - m(n: number): number; -+ m: (n: number) => number; - }; +-}; ++} ++declare namespace ExpandoDecl { ++ var m: (n: number) => number; ++} ++declare var n: number; ++declare function ExpandoExpr(n: number): string; ++declare namespace ExpandoExpr { ++ var prop: { ++ x: number; ++ y?: undefined; ++ } | { ++ x?: undefined; ++ y: string; ++ }; ++} ++declare namespace ExpandoExpr { ++ var prop: { ++ x: number; ++ y?: undefined; ++ } | { ++ x?: undefined; ++ y: string; ++ }; ++} ++declare namespace ExpandoExpr { ++ var m: (n: number) => number; ++} ++declare var n: number; ++declare function ExpandoArrow(n: number): string; ++declare namespace ExpandoArrow { ++ var prop: number; ++} ++declare namespace ExpandoArrow { ++ var m: (n: number) => number; ++} declare function ExpandoNested(n: number): { (m: number): number; total: number; - }; --declare namespace ExpandoNested { -- var also: number; --} - declare function ExpandoMerge(n: number): number; - declare namespace ExpandoMerge { -- var p1: number; --} --declare namespace ExpandoMerge { - var p2: number; - } - declare namespace ExpandoMerge { -@@= skipped -28, +22 lines =@@ +@@= skipped -40, +55 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; - namespace ExpandoNamespace { -- var p6: number; -- } - export function foo(): typeof ExpandoNamespace; - export {}; - } \ No newline at end of file ++ declare namespace ExpandoNamespace { + var p6: number; + } + export function foo(): typeof ExpandoNamespace; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js index 3c3d0d693b..32c4d0ca60 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js @@ -14,3 +14,42 @@ declare const foo: { blah: number; }; }; +declare namespace foo { + var baz: { + blah: number; + }; +} +declare namespace foo { + var blah: number; +} + + +//// [DtsFileErrors] + + +a.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'foo'. +a.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'foo'. +a.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'foo'. + + +==== a.d.ts (3 errors) ==== + declare const foo: { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. + baz: { + blah: number; + }; + }; + declare namespace foo { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. + var baz: { + blah: number; + }; + } + declare namespace foo { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. + var blah: number; + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff index aac1514602..0c5a6e3a9d 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff @@ -13,4 +13,43 @@ + baz: { + blah: number; + }; -+}; \ No newline at end of file ++}; ++declare namespace foo { ++ var baz: { ++ blah: number; ++ }; ++} ++declare namespace foo { ++ var blah: number; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++a.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'foo'. ++a.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'foo'. ++a.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'foo'. ++ ++ ++==== a.d.ts (3 errors) ==== ++ declare const foo: { ++ ~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. ++ baz: { ++ blah: number; ++ }; ++ }; ++ declare namespace foo { ++ ~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. ++ var baz: { ++ blah: number; ++ }; ++ } ++ declare namespace foo { ++ ~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. ++ var blah: number; ++ } ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js index 05ea5715ce..c6a71ddc88 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js @@ -30,4 +30,13 @@ map4.__underscores__(); //// [a.d.ts] declare function Multimap4(): void; +declare namespace Multimap4 { + var prototype: { + /** + * @param {string} key + * @returns {number} the value ok + */ + get(key: string): number; + }; +} declare const map4: any; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff index d5ffe64194..1e1f280301 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff @@ -14,6 +14,14 @@ - "add-on"(): void; - addon(): void; - __underscores__(): void; --} ++declare namespace Multimap4 { ++ var prototype: { ++ /** ++ * @param {string} key ++ * @returns {number} the value ok ++ */ ++ get(key: string): number; ++ }; + } -declare const map4: Multimap4; +declare const map4: any; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts new file mode 100644 index 0000000000..607d116295 --- /dev/null +++ b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts @@ -0,0 +1,18 @@ +// @declaration: true + +export function A() { + return 'A'; +} + +export function B() { + return 'B'; +} + +export enum C { + C +} + +A.a = C; +A.b = C; + +B.c = C;