From f8ba3fe7cd7e04e1ad73a23726ba266dcbb6d00f Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 6 Oct 2025 00:50:03 +0300 Subject: [PATCH 01/11] fix(1374): support declaration emit for expando functions --- internal/ast/utilities.go | 31 +- internal/binder/binder.go | 16 +- internal/checker/checker.go | 12 +- internal/checker/utilities.go | 8 +- internal/ls/findallreferences.go | 2 +- internal/parser/parser.go | 14 +- .../transformers/declarations/transform.go | 191 +++++++++--- .../declarationEmitExpandoFunction.js | 57 ++++ .../declarationEmitExpandoFunction.symbols | 40 +++ .../declarationEmitExpandoFunction.types | 45 +++ ...onEmitDefaultExportWithStaticAssignment.js | 24 +- ...tDefaultExportWithStaticAssignment.js.diff | 38 ++- ...nEmitExpandoPropertyPrivateName.errors.txt | 14 + ...ExpandoPropertyPrivateName.errors.txt.diff | 22 +- ...clarationEmitExpandoPropertyPrivateName.js | 3 + ...tionEmitExpandoPropertyPrivateName.js.diff | 5 +- ...arationEmitExpandoWithGenericConstraint.js | 43 +++ ...onEmitExpandoWithGenericConstraint.js.diff | 45 ++- ...clarationEmitFunctionDuplicateNamespace.js | 3 + ...tionEmitFunctionDuplicateNamespace.js.diff | 8 +- .../declarationEmitFunctionKeywordProp.js | 17 ++ ...declarationEmitFunctionKeywordProp.js.diff | 26 +- .../declarationEmitLateBoundAssignments.js | 3 + ...eclarationEmitLateBoundAssignments.js.diff | 8 +- .../declarationEmitLateBoundJSAssignments.js | 3 + ...larationEmitLateBoundJSAssignments.js.diff | 6 +- .../compiler/expandoFunctionBlockShadowing.js | 3 + .../expandoFunctionBlockShadowing.js.diff | 8 +- .../compiler/isolatedDeclarationErrors.js | 48 +++ .../isolatedDeclarationErrors.js.diff | 50 ++- ...olatedDeclarationErrorsExpandoFunctions.js | 58 ++++ ...dDeclarationErrorsExpandoFunctions.js.diff | 60 +++- .../jsDeclarationsGlobalFileConstFunction.js | 42 +++ ...eclarationsGlobalFileConstFunction.js.diff | 63 +++- ...eclarationsGlobalFileConstFunctionNamed.js | 9 + ...ationsGlobalFileConstFunctionNamed.js.diff | 40 +-- ...xDeclarationsWithEsModuleInteropNoCrash.js | 11 + ...arationsWithEsModuleInteropNoCrash.js.diff | 12 +- ...undFunctionMemberAssignmentDeclarations.js | 3 + ...nctionMemberAssignmentDeclarations.js.diff | 8 +- .../conformance/assignmentToVoidZero2.js | 6 + .../conformance/assignmentToVoidZero2.js.diff | 6 + .../commonJSImportNestedClassTypeReference.js | 7 + ...onJSImportNestedClassTypeReference.js.diff | 8 +- .../conformance/exportDefaultNamespace.js | 6 +- .../exportDefaultNamespace.js.diff | 14 +- .../conformance/jsDeclarationsClassMethod.js | 6 + .../jsDeclarationsClassMethod.js.diff | 13 +- .../conformance/jsDeclarationsClassStatic.js | 3 + .../jsDeclarationsClassStatic.js.diff | 10 +- .../conformance/jsDeclarationsClassStatic2.js | 4 +- .../jsDeclarationsClassStatic2.js.diff | 12 +- ...tionsFunctionClassesCjsExportAssignment.js | 10 + ...FunctionClassesCjsExportAssignment.js.diff | 37 ++- .../jsDeclarationsFunctionKeywordProp.js | 17 ++ .../jsDeclarationsFunctionKeywordProp.js.diff | 26 +- ...clarationsFunctionKeywordPropExhaustive.js | 279 +++++++++++++++++ ...tionsFunctionKeywordPropExhaustive.js.diff | 284 +++++++++++++++++- .../jsDeclarationsFunctionLikeClasses2.js | 16 + ...jsDeclarationsFunctionLikeClasses2.js.diff | 18 +- .../jsDeclarationsFunctionPrototypeStatic.js | 6 + ...eclarationsFunctionPrototypeStatic.js.diff | 6 + ...ationsFunctionWithDefaultAssignedMember.js | 20 +- ...sFunctionWithDefaultAssignedMember.js.diff | 22 +- .../conformance/jsDeclarationsFunctions.js | 11 + .../jsDeclarationsFunctions.js.diff | 20 +- ...tionsParameterTagReusesInputNodeInEmit1.js | 6 + ...ParameterTagReusesInputNodeInEmit1.js.diff | 10 +- ...tionsParameterTagReusesInputNodeInEmit2.js | 6 + ...ParameterTagReusesInputNodeInEmit2.js.diff | 10 +- .../jsDeclarationsReactComponents.js | 160 ++++++++++ .../jsDeclarationsReactComponents.js.diff | 176 ++++++++++- .../conformance/jsdocImplements_class.js | 10 + .../conformance/jsdocImplements_class.js.diff | 29 +- .../submodule/conformance/nullPropertyName.js | 279 +++++++++++++++++ .../conformance/nullPropertyName.js.diff | 284 +++++++++++++++++- .../typeFromPropertyAssignment29.js | 34 +++ .../typeFromPropertyAssignment29.js.diff | 52 +++- .../declarationEmitExpandoFunction.ts | 18 ++ 79 files changed, 2741 insertions(+), 299 deletions(-) create mode 100644 testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js create mode 100644 testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols create mode 100644 testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types create mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt create mode 100644 testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 1c65dee66c..4d718a4fc8 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 { @@ -2815,10 +2815,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 @@ -3860,3 +3856,28 @@ func IsJSDocNameReferenceContext(node *Node) bool { 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 +} diff --git a/internal/binder/binder.go b/internal/binder/binder.go index 8fde6ff763..7c8be437a5 100644 --- a/internal/binder/binder.go +++ b/internal/binder/binder.go @@ -1020,30 +1020,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/checker/checker.go b/internal/checker/checker.go index c6f59fa216..5a248a1424 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -4224,7 +4224,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)) @@ -6479,7 +6479,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: @@ -6767,7 +6767,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: @@ -8325,7 +8325,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) } @@ -18826,7 +18826,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) } }) @@ -26746,7 +26746,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/utilities.go b/internal/checker/utilities.go index e131201893..0f1550afcb 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 f9d6d814df..a5f0dcdf4b 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) @@ -2338,7 +2338,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 @@ -5815,7 +5815,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 @@ -6215,10 +6215,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 02bb0d9d41..37f9cfe1e5 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -11,6 +11,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" ) @@ -25,6 +26,14 @@ type OutputPaths interface { JsFilePath() string } +type DeclareModifier uint8 + +const ( + DeclareModifierNone DeclareModifier = 0 + DeclareModifierEligible DeclareModifier = 1 + DeclareModifierEnforced DeclareModifier = 2 +) + // Used to be passed in the TransformationContext, which is now just an EmitContext type DeclarationEmitHost interface { modulespecifiers.ModuleSpecifierGenerationHost @@ -49,7 +58,7 @@ type DeclarationTransformer struct { declarationMapPath string isBundledEmit bool - needsDeclare bool + declareModifier DeclareModifier needsScopeFixMarker bool resultHasScopeMarker bool enclosingDeclaration *ast.Node @@ -124,7 +133,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 +149,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) @@ -157,7 +167,7 @@ func (tx *DeclarationTransformer) visitSourceFile(node *ast.SourceFile) *ast.Nod } tx.isBundledEmit = false - tx.needsDeclare = true + tx.declareModifier = DeclareModifierEligible tx.needsScopeFixMarker = false tx.resultHasScopeMarker = false tx.enclosingDeclaration = node.AsNode() @@ -231,12 +241,16 @@ func (tx *DeclarationTransformer) transformAndReplaceLatePaintedStatements(state next := tx.state.lateMarkedStatements[0] tx.state.lateMarkedStatements = tx.state.lateMarkedStatements[1:] - priorNeedsDeclare := tx.needsDeclare - tx.needsDeclare = next.Parent != nil && ast.IsSourceFile(next.Parent) && !(ast.IsExternalModule(next.Parent.AsSourceFile()) && tx.isBundledEmit) + saveDeclareModifier := tx.declareModifier + tx.declareModifier = core.IfElse( + next.Parent != nil && ast.IsSourceFile(next.Parent) && !(ast.IsExternalModule(next.Parent.AsSourceFile()) && tx.isBundledEmit), + DeclareModifierEligible, + DeclareModifierNone, + ) result := tx.transformTopLevelDeclaration(next) - tx.needsDeclare = priorNeedsDeclare + tx.declareModifier = saveDeclareModifier original := tx.EmitContext().MostOriginal(next) id := ast.GetNodeId(original) tx.lateStatementReplacementMap[id] = result @@ -789,8 +803,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 { @@ -942,7 +954,7 @@ func (tx *DeclarationTransformer) visitDeclarationStatements(input *ast.Node) *a varDecl := tx.Factory().NewVariableDeclaration(newId, nil, type_, nil) tx.tracker.PopErrorFallbackNode() var modList *ast.ModifierList - if tx.needsDeclare { + if tx.declareModifier == DeclareModifierEligible { modList = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindDeclareKeyword)}) } else { modList = tx.Factory().NewModifierList([]*ast.Node{}) @@ -955,11 +967,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 +1112,7 @@ func (tx *DeclarationTransformer) transformTopLevelDeclaration(input *ast.Node) if canProdiceDiagnostic { tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input) } - previousNeedsDeclare := tx.needsDeclare + saveDeclareModifier := tx.declareModifier var result *ast.Node switch input.Kind { @@ -1125,13 +1137,13 @@ func (tx *DeclarationTransformer) transformTopLevelDeclaration(input *ast.Node) tx.enclosingDeclaration = previousEnclosingDeclaration tx.state.getSymbolAccessibilityDiagnostic = oldDiag - tx.needsDeclare = previousNeedsDeclare + tx.declareModifier = saveDeclareModifier tx.state.errorNameNode = oldName return result } func (tx *DeclarationTransformer) transformTypeAliasDeclaration(input *ast.TypeAliasDeclaration) *ast.Node { - tx.needsDeclare = false + tx.declareModifier = DeclareModifierNone return tx.Factory().UpdateTypeAliasDeclaration( input, tx.ensureModifiers(input.AsNode()), @@ -1153,7 +1165,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 +1176,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,8 +1183,8 @@ 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 - tx.needsDeclare = false + saveDeclareModifier := tx.declareModifier + tx.declareModifier = DeclareModifierNone inner := input.Body keyword := input.Keyword if keyword != ast.KindGlobalKeyword && (input.Name() == nil || !ast.IsStringLiteral(input.Name())) { @@ -1213,7 +1214,7 @@ func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDe } body := tx.Factory().UpdateModuleBlock(inner.AsModuleBlock(), lateStatements) - tx.needsDeclare = oldNeedsDeclare + tx.declareModifier = saveDeclareModifier tx.needsScopeFixMarker = oldNeedsScopeFix tx.resultHasScopeMarker = oldHasScopeFix @@ -1362,7 +1363,7 @@ func (tx *DeclarationTransformer) transformClassDeclaration(input *ast.ClassDecl nil, ) var mods *ast.ModifierList - if tx.needsDeclare { + if tx.declareModifier == DeclareModifierEligible { mods = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindDeclareKeyword)}) } statement := tx.Factory().NewVariableStatement( @@ -1507,8 +1508,13 @@ func (tx *DeclarationTransformer) ensureModifiers(node *ast.Node) *ast.ModifierL func (tx *DeclarationTransformer) ensureModifierFlags(node *ast.Node) ast.ModifierFlags { mask := ast.ModifierFlagsAll ^ (ast.ModifierFlagsPublic | ast.ModifierFlagsAsync | ast.ModifierFlagsOverride) // No async and override modifiers in declaration files additions := ast.ModifierFlagsNone - if tx.needsDeclare && !isAlwaysType(node) { + if tx.declareModifier == DeclareModifierEligible && !isAlwaysType(node) { + additions = ast.ModifierFlagsAmbient + } + if tx.declareModifier == DeclareModifierEnforced { additions = ast.ModifierFlagsAmbient + mask ^= ast.ModifierFlagsDefault + mask ^= ast.ModifierFlagsExport } parentIsFile := node.Parent.Kind == ast.KindSourceFile if !parentIsFile || (tx.isBundledEmit && parentIsFile && ast.IsExternalModule(node.Parent.AsSourceFile())) { @@ -1813,3 +1819,120 @@ 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 + right := node.Right + + if ast.IsElementAccessExpression(left) { + return nil + } + + symbol := node.Symbol + if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 { + return nil + } + + ns := ast.GetFirstIdentifier(left) + if ns == nil { + 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()) + 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(), right, synthesizedNamespace, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, tx.tracker) + tx.state.getSymbolAccessibilityDiagnostic = saveDiag + + nameToken := scanner.StringToToken(left.Name().Text()) + isNonContextualKeywordName := ast.IsNonContextualKeyword(nameToken) + + exportName := core.IfElse(isNonContextualKeywordName, tx.Factory().NewGeneratedNameForNode(left.Name()), tx.Factory().NewIdentifier(left.Name().Text())) + statements := []*ast.Statement{ + tx.Factory().NewVariableStatement( + nil, /*modifiers*/ + tx.Factory().NewVariableDeclarationList( + ast.NodeFlagsConst, + 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*/)) + } + + modifierFlags := ast.ModifierFlagsAmbient + replacement := make([]*ast.Node, 0) + + if ast.HasModifier(declaration, ast.ModifierFlagsExport) { + if ast.HasModifier(declaration, ast.ModifierFlagsDefault) { + if n := tx.transformExpandoHost(name, declaration); n != nil { + replacement = append(replacement, n) + } + } else { + modifierFlags |= ast.ModifierFlagsExport + } + tx.resultHasScopeMarker = true + tx.resultHasExternalModuleIndicator = true + } + + modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)) + namespace := tx.Factory().NewModuleDeclaration(modifiers, ast.KindNamespaceKeyword, name, tx.Factory().NewModuleBlock(tx.Factory().NewNodeList(statements))) + + replacement = append(replacement, namespace) + return tx.Factory().NewSyntaxList(replacement) +} + +func (tx *DeclarationTransformer) transformExpandoHost(name *ast.Node, node *ast.Node) *ast.Node { + id := ast.GetNodeId(tx.EmitContext().MostOriginal(node)) + if tx.lateStatementReplacementMap[id] == nil || ast.HasModifier(tx.lateStatementReplacementMap[id], ast.ModifierFlagsDefault) { + saveDeclareModifier := tx.declareModifier + tx.declareModifier = DeclareModifierEnforced + tx.lateStatementReplacementMap[id] = tx.transformTopLevelDeclaration(node) + tx.declareModifier = saveDeclareModifier + + return tx.Factory().NewExportAssignment(nil /*modifiers*/, false /*isExportEquals*/, nil /*typeNode*/, name) + } + return nil +} diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js new file mode 100644 index 0000000000..eab0cd657c --- /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 { + const a: typeof C; +} +export declare namespace A { + const b: typeof C; +} +export declare namespace B { + const 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..a886d4b371 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 { + const 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 { + const 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 { + const Bar: typeof import("./index3").Bar; +} //// [index4.d.ts] export declare function C(): any; +export declare namespace C { + const A: () => void; +} +export declare namespace C { + const B: () => void; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index ff4abd456f..c3fe1eafdf 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -18,37 +18,43 @@ 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 { + declare function Example(): void; ++export default Example; + declare namespace Example { - var Foo: typeof import("./foo").Foo; --} ++ const 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 { + declare function Example(): void; ++export default Example; + declare namespace Example { - var Foo: typeof import("./foo").Foo; --} ++ const 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 { + declare function Example(): void; ++export default Example; + declare namespace Example { - var Bar: typeof import("./index3").Bar; --} ++ const 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 { + export declare namespace C { - var A: () => void; - var B: () => void; --} \ No newline at end of file ++ const A: () => void; ++} ++export declare namespace C { ++ const 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..e018db2557 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 { + const val: I; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff index e97c240744..0886b8a890 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 { ++ const 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..9db3bade4d 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js @@ -41,3 +41,46 @@ export declare const Point: { zero: () => Point; }; export declare const Rect:

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

; +declare namespace Point { + const zero: () => Point; +} + + +//// [DtsFileErrors] + + +declarationEmitExpandoWithGenericConstraint.d.ts(1,18): error TS2451: Cannot redeclare block-scoped variable 'Point'. +declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. +declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2451: Cannot redeclare block-scoped variable 'Point'. +declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. +declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2451: Cannot redeclare block-scoped variable 'Point'. + + +==== declarationEmitExpandoWithGenericConstraint.d.ts (5 errors) ==== + export interface Point { + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. + readonly x: number; + readonly y: number; + } + export interface Rect

{ + readonly a: p; + readonly b: p; + } + export declare const Point: { + ~~~~~ +!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. + (x: number, y: number): Point; + zero: () => Point; + }; + export declare const Rect:

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

; + declare namespace Point { + ~~~~~ +!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. + const zero: () => Point; + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff index 6b591946c6..79768d419a 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff @@ -7,4 +7,47 @@ - zero(): Point; + zero: () => Point; }; - export declare const Rect:

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

; \ No newline at end of file + export declare const Rect:

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

; ++declare namespace Point { ++ const zero: () => Point; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++declarationEmitExpandoWithGenericConstraint.d.ts(1,18): error TS2451: Cannot redeclare block-scoped variable 'Point'. ++declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. ++declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2451: Cannot redeclare block-scoped variable 'Point'. ++declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. ++declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2451: Cannot redeclare block-scoped variable 'Point'. ++ ++ ++==== declarationEmitExpandoWithGenericConstraint.d.ts (5 errors) ==== ++ export interface Point { ++ ~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. ++ readonly x: number; ++ readonly y: number; ++ } ++ export interface Rect

{ ++ readonly a: p; ++ readonly b: p; ++ } ++ export declare const Point: { ++ ~~~~~ ++!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. ++ ~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. ++ (x: number, y: number): Point; ++ zero: () => Point; ++ }; ++ export declare const Rect:

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

; ++ declare namespace Point { ++ ~~~~~ ++!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. ++ ~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. ++ const zero: () => Point; ++ } ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js index 0fd62effd0..2b62861091 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js @@ -20,3 +20,6 @@ f.x = 2; //// [declarationEmitFunctionDuplicateNamespace.d.ts] declare function f(a: 0): 0; declare function f(a: 1): 1; +declare namespace f { + const x: 2; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff index c75018a359..fb005c3031 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff @@ -1,9 +1,9 @@ --- old.declarationEmitFunctionDuplicateNamespace.js +++ new.declarationEmitFunctionDuplicateNamespace.js -@@= skipped -19, +19 lines =@@ - //// [declarationEmitFunctionDuplicateNamespace.d.ts] +@@= skipped -20, +20 lines =@@ declare function f(a: 0): 0; declare function f(a: 1): 1; --declare namespace f { + declare namespace f { - var x: number; --} \ No newline at end of file ++ const x: 2; + } \ 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..b6f76943f9 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 { + const null_1: true; + export { null_1 as null }; +} declare function bar(): void; +declare namespace bar { + const async: true; +} +declare namespace bar { + const normal: false; +} declare function baz(): void; +declare namespace baz { + const class_1: true; + export { class_1 as class }; +} +declare namespace baz { + const normal: false; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff index 5628351b23..26a5ee2eb8 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -1,21 +1,31 @@ --- old.declarationEmitFunctionKeywordProp.js +++ new.declarationEmitFunctionKeywordProp.js -@@= skipped -24, +24 lines =@@ - +@@= skipped -25, +25 lines =@@ //// [declarationEmitFunctionKeywordProp.d.ts] declare function foo(): void; --declare namespace foo { + declare namespace foo { - var _a: boolean; - export { _a as null }; --} ++ const null_1: true; ++ export { null_1 as null }; + } declare function bar(): void; --declare namespace bar { + declare namespace bar { - var async: boolean; - var normal: boolean; --} ++ const async: true; ++} ++declare namespace bar { ++ const normal: false; + } 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 ++ const class_1: true; ++ export { class_1 as class }; ++} ++declare namespace baz { ++ const normal: false; + } \ 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..2b39f515ae 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -36,3 +36,6 @@ const a = foo[dashStrMem]; //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; +export declare namespace foo { + const bar: 12; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 9b5edc4ae8..11efae8688 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 =@@ - +@@= skipped -36, +36 lines =@@ //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; --export declare namespace foo { + export declare namespace foo { - var bar: number; - var strMemName: string; --} \ No newline at end of file ++ const bar: 12; + } \ 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..12b20f7940 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -26,3 +26,6 @@ const a = foo[dashStrMem]; //// [file.d.ts] export declare function foo(): void; +export declare namespace foo { + const bar: 12; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 62c383b58d..2688f0ab8e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -8,5 +8,7 @@ -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 { ++ const bar: 12; + } \ 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..715190191d 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 { + const test: "foo"; +} diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index fa0b90a7ec..001de3886e 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff @@ -12,10 +12,10 @@ function X() { } if (Math.random()) { const X = {}; -@@= skipped -23, +23 lines =@@ - //// [expandoFunctionBlockShadowing.d.ts] +@@= skipped -24, +24 lines =@@ export declare function X(): void; export declare function Y(): void; --export declare namespace Y { + export declare namespace Y { - var test: string; --} \ No newline at end of file ++ const test: "foo"; + } \ 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..c59c5984aa 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -22,11 +22,59 @@ errorOnMissingReturn.a = ""; //// [isolatedDeclarationErrors.d.ts] declare function errorOnAssignmentBelowDecl(): void; +declare namespace errorOnAssignmentBelowDecl { + const a: ""; +} declare const errorOnAssignmentBelow: { (): void; a: string; }; +declare namespace errorOnAssignmentBelow { + const a: ""; +} declare const errorOnMissingReturn: { (): void; a: string; }; +declare namespace errorOnMissingReturn { + const a: ""; +} + + +//// [DtsFileErrors] + + +isolatedDeclarationErrors.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. +isolatedDeclarationErrors.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. +isolatedDeclarationErrors.d.ts(12,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. +isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. + + +==== isolatedDeclarationErrors.d.ts (4 errors) ==== + declare function errorOnAssignmentBelowDecl(): void; + declare namespace errorOnAssignmentBelowDecl { + const a: ""; + } + declare const errorOnAssignmentBelow: { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. + (): void; + a: string; + }; + declare namespace errorOnAssignmentBelow { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. + const a: ""; + } + declare const errorOnMissingReturn: { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. + (): void; + a: string; + }; + declare namespace errorOnMissingReturn { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. + const a: ""; + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index a2e2b81506..b948b330d6 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -8,11 +8,59 @@ + +//// [isolatedDeclarationErrors.d.ts] +declare function errorOnAssignmentBelowDecl(): void; ++declare namespace errorOnAssignmentBelowDecl { ++ const a: ""; ++} +declare const errorOnAssignmentBelow: { + (): void; + a: string; +}; ++declare namespace errorOnAssignmentBelow { ++ const a: ""; ++} +declare const errorOnMissingReturn: { + (): void; + a: string; -+}; \ No newline at end of file ++}; ++declare namespace errorOnMissingReturn { ++ const a: ""; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++isolatedDeclarationErrors.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++isolatedDeclarationErrors.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++isolatedDeclarationErrors.d.ts(12,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++ ++ ++==== isolatedDeclarationErrors.d.ts (4 errors) ==== ++ declare function errorOnAssignmentBelowDecl(): void; ++ declare namespace errorOnAssignmentBelowDecl { ++ const a: ""; ++ } ++ declare const errorOnAssignmentBelow: { ++ ~~~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++ (): void; ++ a: string; ++ }; ++ declare namespace errorOnAssignmentBelow { ++ ~~~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++ const a: ""; ++ } ++ declare const errorOnMissingReturn: { ++ ~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++ (): void; ++ a: string; ++ }; ++ declare namespace errorOnMissingReturn { ++ ~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++ const a: ""; ++ } ++ \ 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..4478799d5f 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -25,3 +25,61 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] export declare function foo(): void; +export declare namespace foo { + const apply: () => void; +} +export declare namespace foo { + const call: () => void; +} +export declare namespace foo { + const bind: () => void; +} +export declare namespace foo { + const caller: () => void; +} +export declare namespace foo { + const toString: () => void; +} +export declare namespace foo { + const length: 10; +} +export declare namespace foo { + const length: 10; +} + + +//// [DtsFileErrors] + + +isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. +isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. + + +==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== + export declare function foo(): void; + export declare namespace foo { + const apply: () => void; + } + export declare namespace foo { + const call: () => void; + } + export declare namespace foo { + const bind: () => void; + } + export declare namespace foo { + const caller: () => void; + } + export declare namespace foo { + const toString: () => void; + } + export declare namespace foo { + const length: 10; + ~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'length'. + } + export declare namespace foo { + const length: 10; + ~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'length'. + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff index ea6e1338aa..626bf9c762 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -7,4 +7,62 @@ + + +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] -+export declare function foo(): void; \ No newline at end of file ++export declare function foo(): void; ++export declare namespace foo { ++ const apply: () => void; ++} ++export declare namespace foo { ++ const call: () => void; ++} ++export declare namespace foo { ++ const bind: () => void; ++} ++export declare namespace foo { ++ const caller: () => void; ++} ++export declare namespace foo { ++ const toString: () => void; ++} ++export declare namespace foo { ++ const length: 10; ++} ++export declare namespace foo { ++ const length: 10; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ++isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ++ ++ ++==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== ++ export declare function foo(): void; ++ export declare namespace foo { ++ const apply: () => void; ++ } ++ export declare namespace foo { ++ const call: () => void; ++ } ++ export declare namespace foo { ++ const bind: () => void; ++ } ++ export declare namespace foo { ++ const caller: () => void; ++ } ++ export declare namespace foo { ++ const toString: () => void; ++ } ++ export declare namespace foo { ++ const length: 10; ++ ~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'length'. ++ } ++ export declare namespace foo { ++ const length: 10; ++ ~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'length'. ++ } ++ \ 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..906dcf8d99 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js @@ -23,7 +23,49 @@ declare const SomeConstructor2: { (): void; staticMember: string; }; +declare namespace SomeConstructor2 { + const staticMember: "str"; +} declare const SomeConstructor3: { (): void; staticMember: string; }; +declare namespace SomeConstructor3 { + const staticMember: "str"; +} + + +//// [DtsFileErrors] + + +file.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. +file.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. +file.d.ts(9,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. +file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. + + +==== file.d.ts (4 errors) ==== + declare const SomeConstructor: () => void; + declare const SomeConstructor2: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. + (): void; + staticMember: string; + }; + declare namespace SomeConstructor2 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. + const staticMember: "str"; + } + declare const SomeConstructor3: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. + (): void; + staticMember: string; + }; + declare namespace SomeConstructor3 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. + const staticMember: "str"; + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index 171c3332a5..a75606a979 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -9,23 +9,62 @@ - x: number; -} -declare function SomeConstructor2(): void; --declare namespace SomeConstructor2 { -- let 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 namespace SomeConstructor2 { +- let staticMember: string; ++ const staticMember: "str"; + } +-declare function SomeConstructor3(): void; +declare const SomeConstructor3: { + (): void; + staticMember: string; -+}; \ No newline at end of file ++}; + declare namespace SomeConstructor3 { +- let staticMember_1: string; +- export { staticMember_1 as staticMember }; +-} +-declare class SomeConstructor3 { +- x: number; +-} ++ const staticMember: "str"; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++file.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++file.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++file.d.ts(9,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++ ++ ++==== file.d.ts (4 errors) ==== ++ declare const SomeConstructor: () => void; ++ declare const SomeConstructor2: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++ (): void; ++ staticMember: string; ++ }; ++ declare namespace SomeConstructor2 { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++ const staticMember: "str"; ++ } ++ declare const SomeConstructor3: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++ (): void; ++ staticMember: string; ++ }; ++ declare namespace SomeConstructor3 { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++ const staticMember: "str"; ++ } ++ \ 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..86a81e23be 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -29,11 +29,20 @@ declare const SomeConstructor2: { (): void; staticMember: string; }; +declare namespace SomeConstructor2 { + const staticMember: "str"; +} declare const SomeConstructor3: { (): void; staticMember: string; }; +declare namespace SomeConstructor3 { + const staticMember: "str"; +} declare const SelfReference: { (): any; staticMember: string; }; +declare namespace SelfReference { + const staticMember: "str"; +} diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 3b57bcf92d..732257e74b 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -9,11 +9,21 @@ - x: number; -} -declare function SomeConstructor2(): void; --declare namespace SomeConstructor2 { ++declare const SomeConstructor: () => void; ++declare const SomeConstructor2: { ++ (): void; ++ staticMember: string; ++}; + declare namespace SomeConstructor2 { - let staticMember: string; --} ++ const staticMember: "str"; + } -declare function SomeConstructor3(): void; --declare namespace SomeConstructor3 { ++declare const SomeConstructor3: { ++ (): void; ++ staticMember: string; ++}; + declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} @@ -21,23 +31,17 @@ - x: number; -} -declare function SelfReference(): SelfReference; --declare namespace SelfReference { ++ const staticMember: "str"; ++} ++declare const SelfReference: { ++ (): any; ++ staticMember: string; ++}; + 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 ++ const staticMember: "str"; + } \ 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..55ede3d96d 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 { + const propTypes: { + bar: PropTypes.Requireable; + }; +} +declare namespace Foo { + const 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..a9c1081d62 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'; ++ const propTypes: { ++ bar: PropTypes.Requireable; ++ }; ++} ++declare namespace Foo { ++ const 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..f383ecb4bb 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 { + const bar: 12; +} diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff index 9b1699fd25..c6663744d9 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff @@ -1,9 +1,9 @@ --- old.lateBoundFunctionMemberAssignmentDeclarations.js +++ new.lateBoundFunctionMemberAssignmentDeclarations.js -@@= skipped -18, +18 lines =@@ - +@@= skipped -19, +19 lines =@@ //// [index.d.ts] export declare function foo(): void; --export declare namespace foo { + export declare namespace foo { - var bar: number; --} \ No newline at end of file ++ const bar: 12; + } \ 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..ad9216d068 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 { + const x: 1; +} +declare namespace o { + const 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..f5c7f986be 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 { ++ const x: 1; ++} ++declare namespace o { ++ const 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..b362e8a78c 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 { + const 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..ec0cdbeade 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 { ++ const 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..c78574f0e7 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 { + const someProp: "yo"; +} diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff index c5f3a3a126..fff034915f 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -1,12 +1,12 @@ --- old.exportDefaultNamespace.js +++ new.exportDefaultNamespace.js -@@= skipped -18, +18 lines =@@ - +@@= skipped -19, +19 lines =@@ //// [exportDefaultNamespace.d.ts] --declare function someFunc(): string; --declare namespace someFunc { + declare function someFunc(): string; ++export default someFunc; + declare namespace someFunc { - var someProp: string; --} --export default someFunc; -+export default function someFunc(): string; \ No newline at end of file ++ const someProp: "yo"; + } +-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..8483569d1c 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 { + const 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 { + const 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..f248ddecfb 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; --} ++ const 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; ++ const 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..85037752df 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 { + const 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..4dbe14ad55 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; ++ const 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..a2597762c2 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 { + const foo: "foo"; +} //// [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..dabf27e3a4 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 { ++ const foo: "foo"; ++} + //// [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..7e381bd6b5 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -158,6 +158,16 @@ export type State = { timer: Timer; hook: Hook; }; +declare namespace Context { + const 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..7fa93121f0 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff @@ -46,18 +46,7 @@ - timeout: number; -} //// [context.d.ts] -+export type Timer = import("./timer"); -+export type Hook = import("./hook"); -+export type HookHandler = import("./hook").HookHandler; -+export type Input = { -+ timer: Timer; -+ hook: Hook; -+}; -+export type State = { -+ timer: Timer; -+ hook: Hook; -+}; - export = Context; +-export = Context; -/** - * Imports - * @@ -123,9 +112,28 @@ - */ - construct(input: Input, handle?: HookHandler | undefined): State; -} --declare namespace Context { ++export type Timer = import("./timer"); ++export type Hook = import("./hook"); ++export type HookHandler = import("./hook").HookHandler; ++export type Input = { ++ timer: Timer; ++ hook: Hook; ++}; ++export type State = { ++ timer: Timer; ++ hook: Hook; ++}; + declare namespace Context { - export { Timer, Hook, HookHandler, Input, State }; --} ++ const prototype: { ++ /** ++ * @param {Input} input ++ * @param {HookHandler=} handle ++ * @returns {State} ++ */ ++ construct(input: Input, handle?: any): State; ++ }; + } -/** - * Imports - */ @@ -152,6 +160,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..1b5cd59c2f 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 { + const null_1: true; + export { null_1 as null }; +} declare function bar(): void; +declare namespace bar { + const async: true; +} +declare namespace bar { + const normal: false; +} declare function baz(): void; +declare namespace baz { + const class_1: true; + export { class_1 as class }; +} +declare namespace baz { + const normal: false; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff index d529325b10..30eb70273e 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 }; --} ++ const null_1: true; ++ export { null_1 as null }; + } declare function bar(): void; --declare namespace bar { + declare namespace bar { - let async: boolean; - let normal: boolean; --} ++ const async: true; ++} ++declare namespace bar { ++ const normal: false; + } 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 ++ const class_1: true; ++ export { class_1 as class }; ++} ++declare namespace baz { ++ const normal: false; + } \ 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..f89cb76a5b 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 { + const x: 1; +} +declare namespace foo { + const y: 1; +} +declare namespace foo { + const break_1: 1; + export { break_1 as break }; +} +declare namespace foo { + const case_1: 1; + export { case_1 as case }; +} +declare namespace foo { + const catch_1: 1; + export { catch_1 as catch }; +} +declare namespace foo { + const class_1: 1; + export { class_1 as class }; +} +declare namespace foo { + const const_1: 1; + export { const_1 as const }; +} +declare namespace foo { + const continue_1: 1; + export { continue_1 as continue }; +} +declare namespace foo { + const debugger_1: 1; + export { debugger_1 as debugger }; +} +declare namespace foo { + const default_1: 1; + export { default_1 as default }; +} +declare namespace foo { + const delete_1: 1; + export { delete_1 as delete }; +} +declare namespace foo { + const do_1: 1; + export { do_1 as do }; +} +declare namespace foo { + const else_1: 1; + export { else_1 as else }; +} +declare namespace foo { + const enum_1: 1; + export { enum_1 as enum }; +} +declare namespace foo { + const export_1: 1; + export { export_1 as export }; +} +declare namespace foo { + const extends_1: 1; + export { extends_1 as extends }; +} +declare namespace foo { + const false_1: 1; + export { false_1 as false }; +} +declare namespace foo { + const finally_1: 1; + export { finally_1 as finally }; +} +declare namespace foo { + const for_1: 1; + export { for_1 as for }; +} +declare namespace foo { + const function_1: 1; + export { function_1 as function }; +} +declare namespace foo { + const if_1: 1; + export { if_1 as if }; +} +declare namespace foo { + const import_1: 1; + export { import_1 as import }; +} +declare namespace foo { + const in_1: 1; + export { in_1 as in }; +} +declare namespace foo { + const instanceof_1: 1; + export { instanceof_1 as instanceof }; +} +declare namespace foo { + const new_1: 1; + export { new_1 as new }; +} +declare namespace foo { + const null_1: 1; + export { null_1 as null }; +} +declare namespace foo { + const return_1: 1; + export { return_1 as return }; +} +declare namespace foo { + const super_1: 1; + export { super_1 as super }; +} +declare namespace foo { + const switch_1: 1; + export { switch_1 as switch }; +} +declare namespace foo { + const this_1: 1; + export { this_1 as this }; +} +declare namespace foo { + const throw_1: 1; + export { throw_1 as throw }; +} +declare namespace foo { + const true_1: 1; + export { true_1 as true }; +} +declare namespace foo { + const try_1: 1; + export { try_1 as try }; +} +declare namespace foo { + const typeof_1: 1; + export { typeof_1 as typeof }; +} +declare namespace foo { + const var_1: 1; + export { var_1 as var }; +} +declare namespace foo { + const void_1: 1; + export { void_1 as void }; +} +declare namespace foo { + const while_1: 1; + export { while_1 as while }; +} +declare namespace foo { + const with_1: 1; + export { with_1 as with }; +} +declare namespace foo { + const implements_1: 1; + export { implements_1 as implements }; +} +declare namespace foo { + const interface_1: 1; + export { interface_1 as interface }; +} +declare namespace foo { + const let_1: 1; + export { let_1 as let }; +} +declare namespace foo { + const package_1: 1; + export { package_1 as package }; +} +declare namespace foo { + const private_1: 1; + export { private_1 as private }; +} +declare namespace foo { + const protected_1: 1; + export { protected_1 as protected }; +} +declare namespace foo { + const public_1: 1; + export { public_1 as public }; +} +declare namespace foo { + const static_1: 1; + export { static_1 as static }; +} +declare namespace foo { + const yield_1: 1; + export { yield_1 as yield }; +} +declare namespace foo { + const abstract: 1; +} +declare namespace foo { + const as: 1; +} +declare namespace foo { + const asserts: 1; +} +declare namespace foo { + const any: 1; +} +declare namespace foo { + const async: 1; +} +declare namespace foo { + const await: 1; +} +declare namespace foo { + const boolean: 1; +} +declare namespace foo { + const constructor: 1; +} +declare namespace foo { + const declare: 1; +} +declare namespace foo { + const get: 1; +} +declare namespace foo { + const infer: 1; +} +declare namespace foo { + const is: 1; +} +declare namespace foo { + const keyof: 1; +} +declare namespace foo { + const module: 1; +} +declare namespace foo { + const namespace: 1; +} +declare namespace foo { + const never: 1; +} +declare namespace foo { + const readonly: 1; +} +declare namespace foo { + const require: 1; +} +declare namespace foo { + const number: 1; +} +declare namespace foo { + const object: 1; +} +declare namespace foo { + const set: 1; +} +declare namespace foo { + const string: 1; +} +declare namespace foo { + const symbol: 1; +} +declare namespace foo { + const type: 1; +} +declare namespace foo { + const undefined: 1; +} +declare namespace foo { + const unique: 1; +} +declare namespace foo { + const unknown: 1; +} +declare namespace foo { + const from: 1; +} +declare namespace foo { + const global: 1; +} +declare namespace foo { + const bigint: 1; +} +declare namespace foo { + const of: 1; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff index fa3f869313..d666f96ac3 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 ++ const x: 1; ++} ++declare namespace foo { ++ const y: 1; ++} ++declare namespace foo { ++ const break_1: 1; ++ export { break_1 as break }; ++} ++declare namespace foo { ++ const case_1: 1; ++ export { case_1 as case }; ++} ++declare namespace foo { ++ const catch_1: 1; ++ export { catch_1 as catch }; ++} ++declare namespace foo { ++ const class_1: 1; ++ export { class_1 as class }; ++} ++declare namespace foo { ++ const const_1: 1; ++ export { const_1 as const }; ++} ++declare namespace foo { ++ const continue_1: 1; ++ export { continue_1 as continue }; ++} ++declare namespace foo { ++ const debugger_1: 1; ++ export { debugger_1 as debugger }; ++} ++declare namespace foo { ++ const default_1: 1; ++ export { default_1 as default }; ++} ++declare namespace foo { ++ const delete_1: 1; ++ export { delete_1 as delete }; ++} ++declare namespace foo { ++ const do_1: 1; ++ export { do_1 as do }; ++} ++declare namespace foo { ++ const else_1: 1; ++ export { else_1 as else }; ++} ++declare namespace foo { ++ const enum_1: 1; ++ export { enum_1 as enum }; ++} ++declare namespace foo { ++ const export_1: 1; ++ export { export_1 as export }; ++} ++declare namespace foo { ++ const extends_1: 1; ++ export { extends_1 as extends }; ++} ++declare namespace foo { ++ const false_1: 1; ++ export { false_1 as false }; ++} ++declare namespace foo { ++ const finally_1: 1; ++ export { finally_1 as finally }; ++} ++declare namespace foo { ++ const for_1: 1; ++ export { for_1 as for }; ++} ++declare namespace foo { ++ const function_1: 1; ++ export { function_1 as function }; ++} ++declare namespace foo { ++ const if_1: 1; ++ export { if_1 as if }; ++} ++declare namespace foo { ++ const import_1: 1; ++ export { import_1 as import }; ++} ++declare namespace foo { ++ const in_1: 1; ++ export { in_1 as in }; ++} ++declare namespace foo { ++ const instanceof_1: 1; ++ export { instanceof_1 as instanceof }; ++} ++declare namespace foo { ++ const new_1: 1; ++ export { new_1 as new }; ++} ++declare namespace foo { ++ const null_1: 1; ++ export { null_1 as null }; ++} ++declare namespace foo { ++ const return_1: 1; ++ export { return_1 as return }; ++} ++declare namespace foo { ++ const super_1: 1; ++ export { super_1 as super }; ++} ++declare namespace foo { ++ const switch_1: 1; ++ export { switch_1 as switch }; ++} ++declare namespace foo { ++ const this_1: 1; ++ export { this_1 as this }; ++} ++declare namespace foo { ++ const throw_1: 1; ++ export { throw_1 as throw }; ++} ++declare namespace foo { ++ const true_1: 1; ++ export { true_1 as true }; ++} ++declare namespace foo { ++ const try_1: 1; ++ export { try_1 as try }; ++} ++declare namespace foo { ++ const typeof_1: 1; ++ export { typeof_1 as typeof }; ++} ++declare namespace foo { ++ const var_1: 1; ++ export { var_1 as var }; ++} ++declare namespace foo { ++ const void_1: 1; ++ export { void_1 as void }; ++} ++declare namespace foo { ++ const while_1: 1; ++ export { while_1 as while }; ++} ++declare namespace foo { ++ const with_1: 1; ++ export { with_1 as with }; ++} ++declare namespace foo { ++ const implements_1: 1; ++ export { implements_1 as implements }; ++} ++declare namespace foo { ++ const interface_1: 1; ++ export { interface_1 as interface }; ++} ++declare namespace foo { ++ const let_1: 1; ++ export { let_1 as let }; ++} ++declare namespace foo { ++ const package_1: 1; ++ export { package_1 as package }; ++} ++declare namespace foo { ++ const private_1: 1; ++ export { private_1 as private }; ++} ++declare namespace foo { ++ const protected_1: 1; ++ export { protected_1 as protected }; ++} ++declare namespace foo { ++ const public_1: 1; ++ export { public_1 as public }; ++} ++declare namespace foo { ++ const static_1: 1; ++ export { static_1 as static }; ++} ++declare namespace foo { ++ const yield_1: 1; ++ export { yield_1 as yield }; ++} ++declare namespace foo { ++ const abstract: 1; ++} ++declare namespace foo { ++ const as: 1; ++} ++declare namespace foo { ++ const asserts: 1; ++} ++declare namespace foo { ++ const any: 1; ++} ++declare namespace foo { ++ const async: 1; ++} ++declare namespace foo { ++ const await: 1; ++} ++declare namespace foo { ++ const boolean: 1; ++} ++declare namespace foo { ++ const constructor: 1; ++} ++declare namespace foo { ++ const declare: 1; ++} ++declare namespace foo { ++ const get: 1; ++} ++declare namespace foo { ++ const infer: 1; ++} ++declare namespace foo { ++ const is: 1; ++} ++declare namespace foo { ++ const keyof: 1; ++} ++declare namespace foo { ++ const module: 1; ++} ++declare namespace foo { ++ const namespace: 1; ++} ++declare namespace foo { ++ const never: 1; ++} ++declare namespace foo { ++ const readonly: 1; ++} ++declare namespace foo { ++ const require: 1; ++} ++declare namespace foo { ++ const number: 1; ++} ++declare namespace foo { ++ const object: 1; ++} ++declare namespace foo { ++ const set: 1; ++} ++declare namespace foo { ++ const string: 1; ++} ++declare namespace foo { ++ const symbol: 1; ++} ++declare namespace foo { ++ const type: 1; ++} ++declare namespace foo { ++ const undefined: 1; ++} ++declare namespace foo { ++ const unique: 1; ++} ++declare namespace foo { ++ const unknown: 1; ++} ++declare namespace foo { ++ const from: 1; ++} ++declare namespace foo { ++ const global: 1; ++} ++declare namespace foo { ++ const bigint: 1; ++} ++declare namespace foo { ++ const of: 1; + } \ 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..f30240ff09 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 { + const 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 { + const 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..87331e3e75 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 { ++ const 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 { ++ const 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..ed5c03b0c7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -34,6 +34,12 @@ MyClass.staticProperty = 123; //// [source.d.ts] export = MyClass; +declare namespace MyClass { + const staticMethod: () => void; +} +declare namespace MyClass { + const staticProperty: 123; +} 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..0799d74a9a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -23,6 +23,12 @@ -} -declare function staticMethod(): void; -declare var staticProperty: number; ++declare namespace MyClass { ++ const staticMethod: () => void; ++} ++declare namespace MyClass { ++ const staticProperty: 123; ++} +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..14c51d1f6e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -16,17 +16,11 @@ module.exports = foo; //// [index.d.ts] +declare namespace foo { + const foo: typeof import("."); +} +declare namespace foo { + const default_1: typeof import("."); + export { default_1 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..02762da945 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] ++declare namespace foo { ++ const foo: typeof import("."); ++} ++declare namespace foo { ++ const default_1: typeof import("."); ++ export { default_1 as default }; ++} 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 +-} \ 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..92d1bc5500 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 { + const cat: "cat"; +} export declare function c(): void; +export declare namespace c { + const 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 { + const 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..4ed26795df 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 { ++ const cat: "cat"; + } -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 { ++ const 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 { ++ const 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..025c012e05 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -62,6 +62,12 @@ export {}; //// [base.d.ts] +declare class Base { + constructor(); +} +declare namespace BaseFactory { + const 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..f89d2090f4 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; +-export = BaseFactory; -declare function BaseFactory(): Base; -declare namespace BaseFactory { - export { Base }; -} --declare class Base { + declare class Base { -} ++ constructor(); ++} ++declare namespace BaseFactory { ++ const 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..032e62b85b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js @@ -50,6 +50,12 @@ export {}; //// [base.d.ts] +declare class Base { + constructor(); +} +declare namespace BaseFactory { + const 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..820e06b537 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; +-export = BaseFactory; -declare function BaseFactory(): Base; -declare namespace BaseFactory { - export { Base }; -} --declare class Base { + declare class Base { -} ++ constructor(); ++} ++declare namespace BaseFactory { ++ const 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..69b2f16182 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -195,6 +195,16 @@ declare const TabbedShowLayout: { tabs: undefined; }; }; +declare namespace TabbedShowLayout { + const propTypes: { + version: PropTypes.Requireable; + }; +} +declare namespace TabbedShowLayout { + const defaultProps: { + tabs: undefined; + }; +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.d.ts] import React from "react"; @@ -202,6 +212,11 @@ import React from "react"; * @type {React.SFC} */ declare const TabbedShowLayout: React.SFC; +declare namespace TabbedShowLayout { + const defaultProps: { + tabs: string; + }; +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] /** @@ -214,6 +229,11 @@ declare const TabbedShowLayout: { } & ((props?: { elem: string; }) => JSX.Element); +declare namespace TabbedShowLayout { + const defaultProps: { + tabs: string; + }; +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] declare const TabbedShowLayout: { @@ -224,9 +244,149 @@ declare const TabbedShowLayout: { tabs: string; }; }; +declare namespace TabbedShowLayout { + const 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 { + const propTypes: { + classes: PropTypes.Requireable; + }; +} +declare namespace Tree { + const defaultProps: { + classes: {}; + parentSource: string; + }; +} export default Tree; + + +//// [DtsFileErrors] + + +out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents1.d.ts(12,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents1.d.ts(17,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents2.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents3.d.ts(4,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents3.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents4.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents4.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + + +==== out/jsDeclarationsReactComponents1.d.ts (3 errors) ==== + /// + import PropTypes from "prop-types"; + declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + ({}: {}): JSX.Element; + propTypes: { + version: PropTypes.Requireable; + }; + defaultProps: { + tabs: undefined; + }; + }; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const propTypes: { + version: PropTypes.Requireable; + }; + } + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const defaultProps: { + tabs: undefined; + }; + } + export default TabbedShowLayout; + +==== out/jsDeclarationsReactComponents2.d.ts (2 errors) ==== + import React from "react"; + /** + * @type {React.SFC} + */ + declare const TabbedShowLayout: React.SFC; + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const defaultProps: { + tabs: string; + }; + } + export default TabbedShowLayout; + +==== out/jsDeclarationsReactComponents3.d.ts (2 errors) ==== + /** + * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} + */ + declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + defaultProps: { + tabs: string; + }; + } & ((props?: { + elem: string; + }) => JSX.Element); + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const defaultProps: { + tabs: string; + }; + } + export default TabbedShowLayout; + +==== out/jsDeclarationsReactComponents4.d.ts (2 errors) ==== + declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + (prop: { + className: string; + }): JSX.Element; + defaultProps: { + tabs: string; + }; + }; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const defaultProps: { + tabs: string; + }; + } + export default TabbedShowLayout; + +==== out/jsDeclarationsReactComponents5.d.ts (0 errors) ==== + import PropTypes from 'prop-types'; + declare function Tree({ allowDropOnRoot }: { + allowDropOnRoot: any; + }): JSX.Element; + declare namespace Tree { + const propTypes: { + classes: PropTypes.Requireable; + }; + } + declare namespace Tree { + const defaultProps: { + classes: {}; + parentSource: string; + }; + } + export default Tree; + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index 0422126dd6..462190b8b5 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -73,6 +73,16 @@ + tabs: undefined; + }; +}; ++declare namespace TabbedShowLayout { ++ const propTypes: { ++ version: PropTypes.Requireable; ++ }; ++} ++declare namespace TabbedShowLayout { ++ const defaultProps: { ++ tabs: undefined; ++ }; ++} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.d.ts] -export default TabbedShowLayout; @@ -85,18 +95,32 @@ + * @type {React.SFC} + */ +declare const TabbedShowLayout: React.SFC; ++declare namespace TabbedShowLayout { ++ const defaultProps: { ++ tabs: string; ++ }; ++} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] -export default TabbedShowLayout; /** * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} */ -@@= skipped -30, +29 lines =@@ +@@= skipped -30, +44 lines =@@ } & ((props?: { elem: string; }) => JSX.Element); ++declare namespace TabbedShowLayout { ++ const defaultProps: { ++ tabs: string; ++ }; ++} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] +-export default TabbedShowLayout; +-declare function TabbedShowLayout(prop: { +- className: string; +-}): JSX.Element; +declare const TabbedShowLayout: { + (prop: { + className: string; @@ -105,21 +129,22 @@ + tabs: string; + }; +}; - export default TabbedShowLayout; --declare function TabbedShowLayout(prop: { -- className: string; --}): JSX.Element; --declare namespace TabbedShowLayout { + declare namespace TabbedShowLayout { - namespace defaultProps { - let tabs: string; - } --} ++ const 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 +155,137 @@ - } -} -import PropTypes from 'prop-types'; -+export default Tree; \ No newline at end of file ++ const propTypes: { ++ classes: PropTypes.Requireable; ++ }; ++} ++declare namespace Tree { ++ const defaultProps: { ++ classes: {}; ++ parentSource: string; ++ }; ++} ++export default Tree; ++ ++ ++//// [DtsFileErrors] ++ ++ ++out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents1.d.ts(12,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents1.d.ts(17,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents2.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents3.d.ts(4,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents3.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents4.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents4.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ ++ ++==== out/jsDeclarationsReactComponents1.d.ts (3 errors) ==== ++ /// ++ import PropTypes from "prop-types"; ++ declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ ({}: {}): JSX.Element; ++ propTypes: { ++ version: PropTypes.Requireable; ++ }; ++ defaultProps: { ++ tabs: undefined; ++ }; ++ }; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const propTypes: { ++ version: PropTypes.Requireable; ++ }; ++ } ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const defaultProps: { ++ tabs: undefined; ++ }; ++ } ++ export default TabbedShowLayout; ++ ++==== out/jsDeclarationsReactComponents2.d.ts (2 errors) ==== ++ import React from "react"; ++ /** ++ * @type {React.SFC} ++ */ ++ declare const TabbedShowLayout: React.SFC; ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const defaultProps: { ++ tabs: string; ++ }; ++ } ++ export default TabbedShowLayout; ++ ++==== out/jsDeclarationsReactComponents3.d.ts (2 errors) ==== ++ /** ++ * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} ++ */ ++ declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ defaultProps: { ++ tabs: string; ++ }; ++ } & ((props?: { ++ elem: string; ++ }) => JSX.Element); ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const defaultProps: { ++ tabs: string; ++ }; ++ } ++ export default TabbedShowLayout; ++ ++==== out/jsDeclarationsReactComponents4.d.ts (2 errors) ==== ++ declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ (prop: { ++ className: string; ++ }): JSX.Element; ++ defaultProps: { ++ tabs: string; ++ }; ++ }; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const defaultProps: { ++ tabs: string; ++ }; ++ } ++ export default TabbedShowLayout; ++ ++==== out/jsDeclarationsReactComponents5.d.ts (0 errors) ==== ++ import PropTypes from 'prop-types'; ++ declare function Tree({ allowDropOnRoot }: { ++ allowDropOnRoot: any; ++ }): JSX.Element; ++ declare namespace Tree { ++ const propTypes: { ++ classes: PropTypes.Requireable; ++ }; ++ } ++ declare namespace Tree { ++ const 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..2b53e12e04 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 { + const C1: { + new (): { + method(): number; + }; + }; +} /** @implements {A} */ declare var C2: { new (): { @@ -106,3 +113,6 @@ declare class CC { }; } declare var C5: any; +declare namespace Ns { + const 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..4aa7dcf871 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: { ++ const 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 { ++ const 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..596b51e972 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 { + const x: 1; +} +declare namespace foo { + const y: 1; +} +declare namespace foo { + const break_1: 1; + export { break_1 as break }; +} +declare namespace foo { + const case_1: 1; + export { case_1 as case }; +} +declare namespace foo { + const catch_1: 1; + export { catch_1 as catch }; +} +declare namespace foo { + const class_1: 1; + export { class_1 as class }; +} +declare namespace foo { + const const_1: 1; + export { const_1 as const }; +} +declare namespace foo { + const continue_1: 1; + export { continue_1 as continue }; +} +declare namespace foo { + const debugger_1: 1; + export { debugger_1 as debugger }; +} +declare namespace foo { + const default_1: 1; + export { default_1 as default }; +} +declare namespace foo { + const delete_1: 1; + export { delete_1 as delete }; +} +declare namespace foo { + const do_1: 1; + export { do_1 as do }; +} +declare namespace foo { + const else_1: 1; + export { else_1 as else }; +} +declare namespace foo { + const enum_1: 1; + export { enum_1 as enum }; +} +declare namespace foo { + const export_1: 1; + export { export_1 as export }; +} +declare namespace foo { + const extends_1: 1; + export { extends_1 as extends }; +} +declare namespace foo { + const false_1: 1; + export { false_1 as false }; +} +declare namespace foo { + const finally_1: 1; + export { finally_1 as finally }; +} +declare namespace foo { + const for_1: 1; + export { for_1 as for }; +} +declare namespace foo { + const function_1: 1; + export { function_1 as function }; +} +declare namespace foo { + const if_1: 1; + export { if_1 as if }; +} +declare namespace foo { + const import_1: 1; + export { import_1 as import }; +} +declare namespace foo { + const in_1: 1; + export { in_1 as in }; +} +declare namespace foo { + const instanceof_1: 1; + export { instanceof_1 as instanceof }; +} +declare namespace foo { + const new_1: 1; + export { new_1 as new }; +} +declare namespace foo { + const null_1: 1; + export { null_1 as null }; +} +declare namespace foo { + const return_1: 1; + export { return_1 as return }; +} +declare namespace foo { + const super_1: 1; + export { super_1 as super }; +} +declare namespace foo { + const switch_1: 1; + export { switch_1 as switch }; +} +declare namespace foo { + const this_1: 1; + export { this_1 as this }; +} +declare namespace foo { + const throw_1: 1; + export { throw_1 as throw }; +} +declare namespace foo { + const true_1: 1; + export { true_1 as true }; +} +declare namespace foo { + const try_1: 1; + export { try_1 as try }; +} +declare namespace foo { + const typeof_1: 1; + export { typeof_1 as typeof }; +} +declare namespace foo { + const var_1: 1; + export { var_1 as var }; +} +declare namespace foo { + const void_1: 1; + export { void_1 as void }; +} +declare namespace foo { + const while_1: 1; + export { while_1 as while }; +} +declare namespace foo { + const with_1: 1; + export { with_1 as with }; +} +declare namespace foo { + const implements_1: 1; + export { implements_1 as implements }; +} +declare namespace foo { + const interface_1: 1; + export { interface_1 as interface }; +} +declare namespace foo { + const let_1: 1; + export { let_1 as let }; +} +declare namespace foo { + const package_1: 1; + export { package_1 as package }; +} +declare namespace foo { + const private_1: 1; + export { private_1 as private }; +} +declare namespace foo { + const protected_1: 1; + export { protected_1 as protected }; +} +declare namespace foo { + const public_1: 1; + export { public_1 as public }; +} +declare namespace foo { + const static_1: 1; + export { static_1 as static }; +} +declare namespace foo { + const yield_1: 1; + export { yield_1 as yield }; +} +declare namespace foo { + const abstract: 1; +} +declare namespace foo { + const as: 1; +} +declare namespace foo { + const asserts: 1; +} +declare namespace foo { + const any: 1; +} +declare namespace foo { + const async: 1; +} +declare namespace foo { + const await: 1; +} +declare namespace foo { + const boolean: 1; +} +declare namespace foo { + const constructor: 1; +} +declare namespace foo { + const declare: 1; +} +declare namespace foo { + const get: 1; +} +declare namespace foo { + const infer: 1; +} +declare namespace foo { + const is: 1; +} +declare namespace foo { + const keyof: 1; +} +declare namespace foo { + const module: 1; +} +declare namespace foo { + const namespace: 1; +} +declare namespace foo { + const never: 1; +} +declare namespace foo { + const readonly: 1; +} +declare namespace foo { + const require: 1; +} +declare namespace foo { + const number: 1; +} +declare namespace foo { + const object: 1; +} +declare namespace foo { + const set: 1; +} +declare namespace foo { + const string: 1; +} +declare namespace foo { + const symbol: 1; +} +declare namespace foo { + const type: 1; +} +declare namespace foo { + const undefined: 1; +} +declare namespace foo { + const unique: 1; +} +declare namespace foo { + const unknown: 1; +} +declare namespace foo { + const from: 1; +} +declare namespace foo { + const global: 1; +} +declare namespace foo { + const bigint: 1; +} +declare namespace foo { + const of: 1; +} diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff index 60cf26b0b5..139a9c0ac2 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff @@ -1,10 +1,9 @@ --- 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; @@ -84,4 +83,281 @@ - 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 ++ const x: 1; ++} ++declare namespace foo { ++ const y: 1; ++} ++declare namespace foo { ++ const break_1: 1; ++ export { break_1 as break }; ++} ++declare namespace foo { ++ const case_1: 1; ++ export { case_1 as case }; ++} ++declare namespace foo { ++ const catch_1: 1; ++ export { catch_1 as catch }; ++} ++declare namespace foo { ++ const class_1: 1; ++ export { class_1 as class }; ++} ++declare namespace foo { ++ const const_1: 1; ++ export { const_1 as const }; ++} ++declare namespace foo { ++ const continue_1: 1; ++ export { continue_1 as continue }; ++} ++declare namespace foo { ++ const debugger_1: 1; ++ export { debugger_1 as debugger }; ++} ++declare namespace foo { ++ const default_1: 1; ++ export { default_1 as default }; ++} ++declare namespace foo { ++ const delete_1: 1; ++ export { delete_1 as delete }; ++} ++declare namespace foo { ++ const do_1: 1; ++ export { do_1 as do }; ++} ++declare namespace foo { ++ const else_1: 1; ++ export { else_1 as else }; ++} ++declare namespace foo { ++ const enum_1: 1; ++ export { enum_1 as enum }; ++} ++declare namespace foo { ++ const export_1: 1; ++ export { export_1 as export }; ++} ++declare namespace foo { ++ const extends_1: 1; ++ export { extends_1 as extends }; ++} ++declare namespace foo { ++ const false_1: 1; ++ export { false_1 as false }; ++} ++declare namespace foo { ++ const finally_1: 1; ++ export { finally_1 as finally }; ++} ++declare namespace foo { ++ const for_1: 1; ++ export { for_1 as for }; ++} ++declare namespace foo { ++ const function_1: 1; ++ export { function_1 as function }; ++} ++declare namespace foo { ++ const if_1: 1; ++ export { if_1 as if }; ++} ++declare namespace foo { ++ const import_1: 1; ++ export { import_1 as import }; ++} ++declare namespace foo { ++ const in_1: 1; ++ export { in_1 as in }; ++} ++declare namespace foo { ++ const instanceof_1: 1; ++ export { instanceof_1 as instanceof }; ++} ++declare namespace foo { ++ const new_1: 1; ++ export { new_1 as new }; ++} ++declare namespace foo { ++ const null_1: 1; ++ export { null_1 as null }; ++} ++declare namespace foo { ++ const return_1: 1; ++ export { return_1 as return }; ++} ++declare namespace foo { ++ const super_1: 1; ++ export { super_1 as super }; ++} ++declare namespace foo { ++ const switch_1: 1; ++ export { switch_1 as switch }; ++} ++declare namespace foo { ++ const this_1: 1; ++ export { this_1 as this }; ++} ++declare namespace foo { ++ const throw_1: 1; ++ export { throw_1 as throw }; ++} ++declare namespace foo { ++ const true_1: 1; ++ export { true_1 as true }; ++} ++declare namespace foo { ++ const try_1: 1; ++ export { try_1 as try }; ++} ++declare namespace foo { ++ const typeof_1: 1; ++ export { typeof_1 as typeof }; ++} ++declare namespace foo { ++ const var_1: 1; ++ export { var_1 as var }; ++} ++declare namespace foo { ++ const void_1: 1; ++ export { void_1 as void }; ++} ++declare namespace foo { ++ const while_1: 1; ++ export { while_1 as while }; ++} ++declare namespace foo { ++ const with_1: 1; ++ export { with_1 as with }; ++} ++declare namespace foo { ++ const implements_1: 1; ++ export { implements_1 as implements }; ++} ++declare namespace foo { ++ const interface_1: 1; ++ export { interface_1 as interface }; ++} ++declare namespace foo { ++ const let_1: 1; ++ export { let_1 as let }; ++} ++declare namespace foo { ++ const package_1: 1; ++ export { package_1 as package }; ++} ++declare namespace foo { ++ const private_1: 1; ++ export { private_1 as private }; ++} ++declare namespace foo { ++ const protected_1: 1; ++ export { protected_1 as protected }; ++} ++declare namespace foo { ++ const public_1: 1; ++ export { public_1 as public }; ++} ++declare namespace foo { ++ const static_1: 1; ++ export { static_1 as static }; ++} ++declare namespace foo { ++ const yield_1: 1; ++ export { yield_1 as yield }; ++} ++declare namespace foo { ++ const abstract: 1; ++} ++declare namespace foo { ++ const as: 1; ++} ++declare namespace foo { ++ const asserts: 1; ++} ++declare namespace foo { ++ const any: 1; ++} ++declare namespace foo { ++ const async: 1; ++} ++declare namespace foo { ++ const await: 1; ++} ++declare namespace foo { ++ const boolean: 1; ++} ++declare namespace foo { ++ const constructor: 1; ++} ++declare namespace foo { ++ const declare: 1; ++} ++declare namespace foo { ++ const get: 1; ++} ++declare namespace foo { ++ const infer: 1; ++} ++declare namespace foo { ++ const is: 1; ++} ++declare namespace foo { ++ const keyof: 1; ++} ++declare namespace foo { ++ const module: 1; ++} ++declare namespace foo { ++ const namespace: 1; ++} ++declare namespace foo { ++ const never: 1; ++} ++declare namespace foo { ++ const readonly: 1; ++} ++declare namespace foo { ++ const require: 1; ++} ++declare namespace foo { ++ const number: 1; ++} ++declare namespace foo { ++ const object: 1; ++} ++declare namespace foo { ++ const set: 1; ++} ++declare namespace foo { ++ const string: 1; ++} ++declare namespace foo { ++ const symbol: 1; ++} ++declare namespace foo { ++ const type: 1; ++} ++declare namespace foo { ++ const undefined: 1; ++} ++declare namespace foo { ++ const unique: 1; ++} ++declare namespace foo { ++ const unknown: 1; ++} ++declare namespace foo { ++ const from: 1; ++} ++declare namespace foo { ++ const global: 1; ++} ++declare namespace foo { ++ const bigint: 1; ++} ++declare namespace foo { ++ const of: 1; + } \ 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..34caf31d2f 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -170,6 +170,12 @@ var n = ExpandoExpr3.prop + ExpandoExpr3.m(13) + new ExpandoExpr3().n; //// [typeFromPropertyAssignment29.d.ts] declare function ExpandoDecl(n: number): string; +declare namespace ExpandoDecl { + const prop: 2; +} +declare namespace ExpandoDecl { + const m: (n: number) => number; +} declare var n: number; declare const ExpandoExpr: { (n: number): string; @@ -182,17 +188,42 @@ declare const ExpandoExpr: { }; m: (n: number) => number; }; +declare namespace ExpandoExpr { + const prop: { + x: number; + }; +} +declare namespace ExpandoExpr { + const prop: { + y: string; + }; +} +declare namespace ExpandoExpr { + const m: (n: number) => number; +} declare var n: number; declare const ExpandoArrow: { (n: number): string; prop: number; m: (n: number) => number; }; +declare namespace ExpandoArrow { + const prop: 2; +} +declare namespace ExpandoArrow { + const m: (n: number) => number; +} declare function ExpandoNested(n: number): { (m: number): number; total: number; }; +declare namespace ExpandoNested { + const also: -1; +} declare function ExpandoMerge(n: number): number; +declare namespace ExpandoMerge { + const p1: 111; +} declare namespace ExpandoMerge { var p2: number; } @@ -202,6 +233,9 @@ declare namespace ExpandoMerge { declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; + declare namespace ExpandoNamespace { + const p6: 42; + } 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..f84d7fd36e 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -31,24 +31,39 @@ }; ExpandoExpr3.prop = 3; ExpandoExpr3.m = function (n) { -@@= skipped -13, +11 lines =@@ - +@@= skipped -14, +12 lines =@@ //// [typeFromPropertyAssignment29.d.ts] declare function ExpandoDecl(n: number): string; --declare namespace ExpandoDecl { + declare namespace ExpandoDecl { - var prop: number; - var m: (n: number) => number; --} ++ const prop: 2; ++} ++declare namespace ExpandoDecl { ++ const m: (n: number) => number; + } declare var n: number; declare const ExpandoExpr: { - (n: number): string; -@@= skipped -14, +10 lines =@@ +@@= skipped -13, +15 lines =@@ x?: undefined; y: string; }; - m(n: number): number; + m: (n: number) => number; }; ++declare namespace ExpandoExpr { ++ const prop: { ++ x: number; ++ }; ++} ++declare namespace ExpandoExpr { ++ const prop: { ++ y: string; ++ }; ++} ++declare namespace ExpandoExpr { ++ const m: (n: number) => number; ++} declare var n: number; declare const ExpandoArrow: { (n: number): string; @@ -56,28 +71,35 @@ - m(n: number): number; + m: (n: number) => number; }; ++declare namespace ExpandoArrow { ++ const prop: 2; ++} ++declare namespace ExpandoArrow { ++ const m: (n: number) => number; ++} declare function ExpandoNested(n: number): { (m: number): number; total: number; }; --declare namespace ExpandoNested { + declare namespace ExpandoNested { - var also: number; --} ++ const also: -1; + } declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { - var p1: number; --} --declare namespace ExpandoMerge { - var p2: number; ++ const p1: 111; } declare namespace ExpandoMerge { -@@= skipped -28, +22 lines =@@ + var p2: number; +@@= skipped -28, +47 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; - namespace ExpandoNamespace { - var p6: number; -- } ++ declare namespace ExpandoNamespace { ++ const p6: 42; + } export function foo(): typeof ExpandoNamespace; - export {}; - } \ No newline at end of file + export {}; \ 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; From b8328536aaa85e093d835e9509b0ee078da18b69 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 6 Oct 2025 13:08:33 +0300 Subject: [PATCH 02/11] fix missing export --- internal/transformers/declarations/transform.go | 5 +++-- ...eclarationEmitExpandoWithGenericConstraint.js | 16 +++++----------- ...ationEmitExpandoWithGenericConstraint.js.diff | 16 +++++----------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 37f9cfe1e5..97a40797fc 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1905,8 +1905,9 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp modifierFlags := ast.ModifierFlagsAmbient replacement := make([]*ast.Node, 0) - if ast.HasModifier(declaration, ast.ModifierFlagsExport) { - if ast.HasModifier(declaration, ast.ModifierFlagsDefault) { + flags := ast.GetCombinedModifierFlags(declaration) + if flags & ast.ModifierFlagsExport != 0 { + if flags & ast.ModifierFlagsDefault != 0 { if n := tx.transformExpandoHost(name, declaration); n != nil { replacement = append(replacement, n) } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js index 9db3bade4d..2cd99f38e5 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js @@ -41,7 +41,7 @@ export declare const Point: { zero: () => Point; }; export declare const Rect:

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

; -declare namespace Point { +export declare namespace Point { const zero: () => Point; } @@ -50,13 +50,11 @@ declare namespace Point { declarationEmitExpandoWithGenericConstraint.d.ts(1,18): error TS2451: Cannot redeclare block-scoped variable 'Point'. -declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2451: Cannot redeclare block-scoped variable 'Point'. -declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. -declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2451: Cannot redeclare block-scoped variable 'Point'. +declarationEmitExpandoWithGenericConstraint.d.ts(14,26): error TS2451: Cannot redeclare block-scoped variable 'Point'. -==== declarationEmitExpandoWithGenericConstraint.d.ts (5 errors) ==== +==== declarationEmitExpandoWithGenericConstraint.d.ts (3 errors) ==== export interface Point { ~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'Point'. @@ -69,17 +67,13 @@ declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2451: Cannot re } export declare const Point: { ~~~~~ -!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. - ~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'Point'. (x: number, y: number): Point; zero: () => Point; }; export declare const Rect:

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

; - declare namespace Point { - ~~~~~ -!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. - ~~~~~ + export declare namespace Point { + ~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'Point'. const zero: () => Point; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff index 79768d419a..46da2754ed 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff @@ -8,7 +8,7 @@ + zero: () => Point; }; export declare const Rect:

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

; -+declare namespace Point { ++export declare namespace Point { + const zero: () => Point; +} + @@ -17,13 +17,11 @@ + + +declarationEmitExpandoWithGenericConstraint.d.ts(1,18): error TS2451: Cannot redeclare block-scoped variable 'Point'. -+declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. +declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2451: Cannot redeclare block-scoped variable 'Point'. -+declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. -+declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2451: Cannot redeclare block-scoped variable 'Point'. ++declarationEmitExpandoWithGenericConstraint.d.ts(14,26): error TS2451: Cannot redeclare block-scoped variable 'Point'. + + -+==== declarationEmitExpandoWithGenericConstraint.d.ts (5 errors) ==== ++==== declarationEmitExpandoWithGenericConstraint.d.ts (3 errors) ==== + export interface Point { + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. @@ -36,17 +34,13 @@ + } + export declare const Point: { + ~~~~~ -+!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. -+ ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. + (x: number, y: number): Point; + zero: () => Point; + }; + export declare const Rect:

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

; -+ declare namespace Point { -+ ~~~~~ -+!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. -+ ~~~~~ ++ export declare namespace Point { ++ ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. + const zero: () => Point; + } From d567d736e1b441823cd6486366ee641b4e054995 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 6 Oct 2025 14:01:43 +0300 Subject: [PATCH 03/11] fix formatting --- internal/transformers/declarations/transform.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 97a40797fc..d264c83dc0 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1906,8 +1906,8 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp replacement := make([]*ast.Node, 0) flags := ast.GetCombinedModifierFlags(declaration) - if flags & ast.ModifierFlagsExport != 0 { - if flags & ast.ModifierFlagsDefault != 0 { + if flags&ast.ModifierFlagsExport != 0 { + if flags&ast.ModifierFlagsDefault != 0 { if n := tx.transformExpandoHost(name, declaration); n != nil { replacement = append(replacement, n) } From ad033f6af9bf6703dabe24e5e5c003e4408d38fd Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 6 Oct 2025 14:46:02 +0300 Subject: [PATCH 04/11] fix expando prop type and keyword generated alias names --- .../transformers/declarations/transform.go | 5 +- ...clarationEmitFunctionDuplicateNamespace.js | 2 +- ...tionEmitFunctionDuplicateNamespace.js.diff | 2 +- .../declarationEmitFunctionKeywordProp.js | 14 +- ...declarationEmitFunctionKeywordProp.js.diff | 15 +- .../declarationEmitLateBoundAssignments.js | 2 +- ...eclarationEmitLateBoundAssignments.js.diff | 2 +- .../declarationEmitLateBoundJSAssignments.js | 2 +- ...larationEmitLateBoundJSAssignments.js.diff | 2 +- .../compiler/expandoFunctionBlockShadowing.js | 2 +- .../expandoFunctionBlockShadowing.js.diff | 2 +- .../compiler/isolatedDeclarationErrors.js | 12 +- .../isolatedDeclarationErrors.js.diff | 12 +- ...olatedDeclarationErrorsExpandoFunctions.js | 8 +- ...dDeclarationErrorsExpandoFunctions.js.diff | 8 +- .../jsDeclarationsGlobalFileConstFunction.js | 8 +- ...eclarationsGlobalFileConstFunction.js.diff | 8 +- ...eclarationsGlobalFileConstFunctionNamed.js | 6 +- ...ationsGlobalFileConstFunctionNamed.js.diff | 6 +- ...undFunctionMemberAssignmentDeclarations.js | 2 +- ...nctionMemberAssignmentDeclarations.js.diff | 2 +- .../conformance/assignmentToVoidZero2.js | 2 +- .../conformance/assignmentToVoidZero2.js.diff | 2 +- .../conformance/exportDefaultNamespace.js | 2 +- .../exportDefaultNamespace.js.diff | 2 +- .../conformance/jsDeclarationsClassStatic2.js | 2 +- .../jsDeclarationsClassStatic2.js.diff | 2 +- .../jsDeclarationsFunctionKeywordProp.js | 14 +- .../jsDeclarationsFunctionKeywordProp.js.diff | 14 +- ...clarationsFunctionKeywordPropExhaustive.js | 246 +++++++++--------- ...tionsFunctionKeywordPropExhaustive.js.diff | 246 +++++++++--------- .../jsDeclarationsFunctionPrototypeStatic.js | 2 +- ...eclarationsFunctionPrototypeStatic.js.diff | 2 +- ...ationsFunctionWithDefaultAssignedMember.js | 4 +- ...sFunctionWithDefaultAssignedMember.js.diff | 4 +- .../conformance/jsDeclarationsFunctions.js | 2 +- .../jsDeclarationsFunctions.js.diff | 2 +- .../jsDeclarationsReactComponents.js | 8 +- .../jsDeclarationsReactComponents.js.diff | 10 +- .../submodule/conformance/nullPropertyName.js | 246 +++++++++--------- .../conformance/nullPropertyName.js.diff | 246 +++++++++--------- .../typeFromPropertyAssignment29.js | 18 +- .../typeFromPropertyAssignment29.js.diff | 20 +- 43 files changed, 612 insertions(+), 606 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index d264c83dc0..46418b3d46 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1836,7 +1836,6 @@ func (tx *DeclarationTransformer) visitExpressionStatement(node *ast.ExpressionS func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExpression) *ast.Node { left := node.Left - right := node.Right if ast.IsElementAccessExpression(left) { return nil @@ -1874,13 +1873,13 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp saveDiag := tx.state.getSymbolAccessibilityDiagnostic tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node.AsNode()) - t := tx.resolver.CreateTypeOfExpression(tx.EmitContext(), right, synthesizedNamespace, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, tx.tracker) + t := tx.resolver.CreateTypeOfExpression(tx.EmitContext(), left, synthesizedNamespace, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, tx.tracker) tx.state.getSymbolAccessibilityDiagnostic = saveDiag nameToken := scanner.StringToToken(left.Name().Text()) isNonContextualKeywordName := ast.IsNonContextualKeyword(nameToken) - exportName := core.IfElse(isNonContextualKeywordName, tx.Factory().NewGeneratedNameForNode(left.Name()), tx.Factory().NewIdentifier(left.Name().Text())) + exportName := core.IfElse(isNonContextualKeywordName, tx.Factory().NewGeneratedNameForNode(left), tx.Factory().NewIdentifier(left.Name().Text())) statements := []*ast.Statement{ tx.Factory().NewVariableStatement( nil, /*modifiers*/ diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js index 2b62861091..4d3c363b4c 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js @@ -21,5 +21,5 @@ f.x = 2; declare function f(a: 0): 0; declare function f(a: 1): 1; declare namespace f { - const x: 2; + const x: number; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff index fb005c3031..7e6ab16dc9 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff @@ -5,5 +5,5 @@ declare function f(a: 1): 1; declare namespace f { - var x: number; -+ const x: 2; ++ const x: number; } \ 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 b6f76943f9..33fba14e69 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js @@ -26,21 +26,21 @@ baz.normal = false; //// [declarationEmitFunctionKeywordProp.d.ts] declare function foo(): void; declare namespace foo { - const null_1: true; - export { null_1 as null }; + const _a: boolean; + export { _a as null }; } declare function bar(): void; declare namespace bar { - const async: true; + const async: boolean; } declare namespace bar { - const normal: false; + const normal: boolean; } declare function baz(): void; declare namespace baz { - const class_1: true; - export { class_1 as class }; + const _b: boolean; + export { _b as class }; } declare namespace baz { - const normal: false; + const normal: boolean; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff index 26a5ee2eb8..cad69bf67f 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -5,27 +5,26 @@ declare function foo(): void; declare namespace foo { - var _a: boolean; -- export { _a as null }; -+ const null_1: true; -+ export { null_1 as null }; ++ const _a: boolean; + export { _a as null }; } declare function bar(): void; declare namespace bar { - var async: boolean; - var normal: boolean; -+ const async: true; ++ const async: boolean; +} +declare namespace bar { -+ const normal: false; ++ const normal: boolean; } declare function baz(): void; declare namespace baz { - var _a: boolean; - export var normal: boolean; - export { _a as class }; -+ const class_1: true; -+ export { class_1 as class }; ++ const _b: boolean; ++ export { _b as class }; +} +declare namespace baz { -+ const normal: false; ++ const 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 2b39f515ae..fb0ef42f69 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -37,5 +37,5 @@ const a = foo[dashStrMem]; //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; export declare namespace foo { - const bar: 12; + const bar: number; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 11efae8688..49d12959d1 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff @@ -6,5 +6,5 @@ export declare namespace foo { - var bar: number; - var strMemName: string; -+ const bar: 12; ++ const bar: 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 12b20f7940..c344a36d03 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -27,5 +27,5 @@ const a = foo[dashStrMem]; //// [file.d.ts] export declare function foo(): void; export declare namespace foo { - const bar: 12; + const bar: number; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 2688f0ab8e..be7cbb8a9a 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -10,5 +10,5 @@ - let strMemName: string; +export declare function foo(): void; +export declare namespace foo { -+ const bar: 12; ++ const bar: number; } \ 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 715190191d..bbfa5450a7 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js @@ -46,5 +46,5 @@ if (Math.random()) { export declare function X(): void; export declare function Y(): void; export declare namespace Y { - const test: "foo"; + const test: string; } diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index 001de3886e..f56b594ac8 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff @@ -17,5 +17,5 @@ export declare function Y(): void; export declare namespace Y { - var test: string; -+ const test: "foo"; ++ const test: string; } \ 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 c59c5984aa..577f55bdc9 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -23,21 +23,21 @@ errorOnMissingReturn.a = ""; //// [isolatedDeclarationErrors.d.ts] declare function errorOnAssignmentBelowDecl(): void; declare namespace errorOnAssignmentBelowDecl { - const a: ""; + const a: string; } declare const errorOnAssignmentBelow: { (): void; a: string; }; declare namespace errorOnAssignmentBelow { - const a: ""; + const a: string; } declare const errorOnMissingReturn: { (): void; a: string; }; declare namespace errorOnMissingReturn { - const a: ""; + const a: string; } @@ -53,7 +53,7 @@ isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scop ==== isolatedDeclarationErrors.d.ts (4 errors) ==== declare function errorOnAssignmentBelowDecl(): void; declare namespace errorOnAssignmentBelowDecl { - const a: ""; + const a: string; } declare const errorOnAssignmentBelow: { ~~~~~~~~~~~~~~~~~~~~~~ @@ -64,7 +64,7 @@ isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scop declare namespace errorOnAssignmentBelow { ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. - const a: ""; + const a: string; } declare const errorOnMissingReturn: { ~~~~~~~~~~~~~~~~~~~~ @@ -75,6 +75,6 @@ isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scop declare namespace errorOnMissingReturn { ~~~~~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. - const a: ""; + const a: string; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index b948b330d6..fcd76ee252 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -9,21 +9,21 @@ +//// [isolatedDeclarationErrors.d.ts] +declare function errorOnAssignmentBelowDecl(): void; +declare namespace errorOnAssignmentBelowDecl { -+ const a: ""; ++ const a: string; +} +declare const errorOnAssignmentBelow: { + (): void; + a: string; +}; +declare namespace errorOnAssignmentBelow { -+ const a: ""; ++ const a: string; +} +declare const errorOnMissingReturn: { + (): void; + a: string; +}; +declare namespace errorOnMissingReturn { -+ const a: ""; ++ const a: string; +} + + @@ -39,7 +39,7 @@ +==== isolatedDeclarationErrors.d.ts (4 errors) ==== + declare function errorOnAssignmentBelowDecl(): void; + declare namespace errorOnAssignmentBelowDecl { -+ const a: ""; ++ const a: string; + } + declare const errorOnAssignmentBelow: { + ~~~~~~~~~~~~~~~~~~~~~~ @@ -50,7 +50,7 @@ + declare namespace errorOnAssignmentBelow { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -+ const a: ""; ++ const a: string; + } + declare const errorOnMissingReturn: { + ~~~~~~~~~~~~~~~~~~~~ @@ -61,6 +61,6 @@ + declare namespace errorOnMissingReturn { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. -+ const a: ""; ++ const 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 4478799d5f..9ebccc55c2 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -41,10 +41,10 @@ export declare namespace foo { const toString: () => void; } export declare namespace foo { - const length: 10; + const length: number; } export declare namespace foo { - const length: 10; + const length: number; } @@ -73,12 +73,12 @@ isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot rede const toString: () => void; } export declare namespace foo { - const length: 10; + const length: number; ~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'length'. } export declare namespace foo { - const length: 10; + const length: number; ~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'length'. } diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff index 626bf9c762..e4a99a073a 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -24,10 +24,10 @@ + const toString: () => void; +} +export declare namespace foo { -+ const length: 10; ++ const length: number; +} +export declare namespace foo { -+ const length: 10; ++ const length: number; +} + + @@ -56,12 +56,12 @@ + const toString: () => void; + } + export declare namespace foo { -+ const length: 10; ++ const length: number; + ~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'length'. + } + export declare namespace foo { -+ const length: 10; ++ const length: number; + ~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'length'. + } diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js index 906dcf8d99..2c74979f38 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js @@ -24,14 +24,14 @@ declare const SomeConstructor2: { staticMember: string; }; declare namespace SomeConstructor2 { - const staticMember: "str"; + const staticMember: string; } declare const SomeConstructor3: { (): void; staticMember: string; }; declare namespace SomeConstructor3 { - const staticMember: "str"; + const staticMember: string; } @@ -55,7 +55,7 @@ file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeCons declare namespace SomeConstructor2 { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. - const staticMember: "str"; + const staticMember: string; } declare const SomeConstructor3: { ~~~~~~~~~~~~~~~~ @@ -66,6 +66,6 @@ file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeCons declare namespace SomeConstructor3 { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. - const staticMember: "str"; + const staticMember: string; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index a75606a979..d74d31f492 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -16,7 +16,7 @@ +}; declare namespace SomeConstructor2 { - let staticMember: string; -+ const staticMember: "str"; ++ const staticMember: string; } -declare function SomeConstructor3(): void; +declare const SomeConstructor3: { @@ -30,7 +30,7 @@ -declare class SomeConstructor3 { - x: number; -} -+ const staticMember: "str"; ++ const staticMember: string; +} + + @@ -54,7 +54,7 @@ + declare namespace SomeConstructor2 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -+ const staticMember: "str"; ++ const staticMember: string; + } + declare const SomeConstructor3: { + ~~~~~~~~~~~~~~~~ @@ -65,6 +65,6 @@ + declare namespace SomeConstructor3 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. -+ const staticMember: "str"; ++ const 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 86a81e23be..987b88bf81 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -30,19 +30,19 @@ declare const SomeConstructor2: { staticMember: string; }; declare namespace SomeConstructor2 { - const staticMember: "str"; + const staticMember: string; } declare const SomeConstructor3: { (): void; staticMember: string; }; declare namespace SomeConstructor3 { - const staticMember: "str"; + const staticMember: string; } declare const SelfReference: { (): any; staticMember: string; }; declare namespace SelfReference { - const staticMember: "str"; + const staticMember: string; } diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 732257e74b..dd631fa6b9 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -16,7 +16,7 @@ +}; declare namespace SomeConstructor2 { - let staticMember: string; -+ const staticMember: "str"; ++ const staticMember: string; } -declare function SomeConstructor3(): void; +declare const SomeConstructor3: { @@ -31,7 +31,7 @@ - x: number; -} -declare function SelfReference(): SelfReference; -+ const staticMember: "str"; ++ const staticMember: string; +} +declare const SelfReference: { + (): any; @@ -43,5 +43,5 @@ -} -declare class SelfReference { - x: number; -+ const staticMember: "str"; ++ const staticMember: string; } \ 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 f383ecb4bb..d15db8974e 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js @@ -20,5 +20,5 @@ const x = foo[_private]; //// [index.d.ts] export declare function foo(): void; export declare namespace foo { - const bar: 12; + const bar: number; } diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff index c6663744d9..900aef4bb5 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff @@ -5,5 +5,5 @@ export declare function foo(): void; export declare namespace foo { - var bar: number; -+ const bar: 12; ++ const 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 ad9216d068..62c7a70269 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js @@ -48,7 +48,7 @@ assignmentToVoidZero2_1.j + assignmentToVoidZero2_1.k; export var j = 1; export var k = void 0; declare namespace o { - const x: 1; + const x: number; } declare namespace o { const y: any; diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff index f5c7f986be..e5ca963b32 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff @@ -26,7 +26,7 @@ +export var j = 1; +export var k = void 0; +declare namespace o { -+ const x: 1; ++ const x: number; +} +declare namespace o { + const y: any; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index c78574f0e7..46d9bded17 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -22,5 +22,5 @@ someFunc.someProp = 'yo'; declare function someFunc(): string; export default someFunc; declare namespace someFunc { - const someProp: "yo"; + const someProp: string; } diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff index fff034915f..d88c830a16 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -7,6 +7,6 @@ +export default someFunc; declare namespace someFunc { - var someProp: string; -+ const someProp: "yo"; ++ const someProp: string; } -export default someFunc; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js index a2597762c2..6feb81f0d9 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js @@ -23,7 +23,7 @@ declare class Base { export declare class Foo extends Base { } export declare namespace Foo { - const foo: "foo"; + const 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 dabf27e3a4..6ba1fca32b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff @@ -16,7 +16,7 @@ +export declare class Foo extends Base { +} +export declare namespace Foo { -+ const foo: "foo"; ++ const foo: string; +} //// [Bar.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js index 1b5cd59c2f..733c932e5a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js @@ -26,21 +26,21 @@ baz.normal = false; //// [source.d.ts] declare function foo(): void; declare namespace foo { - const null_1: true; - export { null_1 as null }; + const _a: boolean; + export { _a as null }; } declare function bar(): void; declare namespace bar { - const async: true; + const async: boolean; } declare namespace bar { - const normal: false; + const normal: boolean; } declare function baz(): void; declare namespace baz { - const class_1: true; - export { class_1 as class }; + const _b: boolean; + export { _b as class }; } declare namespace baz { - const normal: false; + const normal: boolean; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff index 30eb70273e..88f1ff32fd 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff @@ -6,17 +6,17 @@ declare namespace foo { - let _null: boolean; - export { _null as null }; -+ const null_1: true; -+ export { null_1 as null }; ++ const _a: boolean; ++ export { _a as null }; } declare function bar(): void; declare namespace bar { - let async: boolean; - let normal: boolean; -+ const async: true; ++ const async: boolean; +} +declare namespace bar { -+ const normal: false; ++ const normal: boolean; } declare function baz(): void; declare namespace baz { @@ -24,9 +24,9 @@ - export { _class as class }; - let normal_1: boolean; - export { normal_1 as normal }; -+ const class_1: true; -+ export { class_1 as class }; ++ const _b: boolean; ++ export { _b as class }; +} +declare namespace baz { -+ const normal: false; ++ const 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 f89cb76a5b..e976844039 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -171,281 +171,281 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; declare namespace foo { - const x: 1; + const x: number; } declare namespace foo { - const y: 1; + const y: number; } declare namespace foo { - const break_1: 1; - export { break_1 as break }; + const _a: number; + export { _a as break }; } declare namespace foo { - const case_1: 1; - export { case_1 as case }; + const _b: number; + export { _b as case }; } declare namespace foo { - const catch_1: 1; - export { catch_1 as catch }; + const _c: number; + export { _c as catch }; } declare namespace foo { - const class_1: 1; - export { class_1 as class }; + const _d: number; + export { _d as class }; } declare namespace foo { - const const_1: 1; - export { const_1 as const }; + const _e: number; + export { _e as const }; } declare namespace foo { - const continue_1: 1; - export { continue_1 as continue }; + const _f: number; + export { _f as continue }; } declare namespace foo { - const debugger_1: 1; - export { debugger_1 as debugger }; + const _g: number; + export { _g as debugger }; } declare namespace foo { - const default_1: 1; - export { default_1 as default }; + const _h: number; + export { _h as default }; } declare namespace foo { - const delete_1: 1; - export { delete_1 as delete }; + const _j: number; + export { _j as delete }; } declare namespace foo { - const do_1: 1; - export { do_1 as do }; + const _k: number; + export { _k as do }; } declare namespace foo { - const else_1: 1; - export { else_1 as else }; + const _l: number; + export { _l as else }; } declare namespace foo { - const enum_1: 1; - export { enum_1 as enum }; + const _m: number; + export { _m as enum }; } declare namespace foo { - const export_1: 1; - export { export_1 as export }; + const _o: number; + export { _o as export }; } declare namespace foo { - const extends_1: 1; - export { extends_1 as extends }; + const _p: number; + export { _p as extends }; } declare namespace foo { - const false_1: 1; - export { false_1 as false }; + const _q: number; + export { _q as false }; } declare namespace foo { - const finally_1: 1; - export { finally_1 as finally }; + const _r: number; + export { _r as finally }; } declare namespace foo { - const for_1: 1; - export { for_1 as for }; + const _s: number; + export { _s as for }; } declare namespace foo { - const function_1: 1; - export { function_1 as function }; + const _t: number; + export { _t as function }; } declare namespace foo { - const if_1: 1; - export { if_1 as if }; + const _u: number; + export { _u as if }; } declare namespace foo { - const import_1: 1; - export { import_1 as import }; + const _v: number; + export { _v as import }; } declare namespace foo { - const in_1: 1; - export { in_1 as in }; + const _w: number; + export { _w as in }; } declare namespace foo { - const instanceof_1: 1; - export { instanceof_1 as instanceof }; + const _x: number; + export { _x as instanceof }; } declare namespace foo { - const new_1: 1; - export { new_1 as new }; + const _y: number; + export { _y as new }; } declare namespace foo { - const null_1: 1; - export { null_1 as null }; + const _z: number; + export { _z as null }; } declare namespace foo { - const return_1: 1; - export { return_1 as return }; + const _0: number; + export { _0 as return }; } declare namespace foo { - const super_1: 1; - export { super_1 as super }; + const _1: number; + export { _1 as super }; } declare namespace foo { - const switch_1: 1; - export { switch_1 as switch }; + const _2: number; + export { _2 as switch }; } declare namespace foo { - const this_1: 1; - export { this_1 as this }; + const _3: number; + export { _3 as this }; } declare namespace foo { - const throw_1: 1; - export { throw_1 as throw }; + const _4: number; + export { _4 as throw }; } declare namespace foo { - const true_1: 1; - export { true_1 as true }; + const _5: number; + export { _5 as true }; } declare namespace foo { - const try_1: 1; - export { try_1 as try }; + const _6: number; + export { _6 as try }; } declare namespace foo { - const typeof_1: 1; - export { typeof_1 as typeof }; + const _7: number; + export { _7 as typeof }; } declare namespace foo { - const var_1: 1; - export { var_1 as var }; + const _8: number; + export { _8 as var }; } declare namespace foo { - const void_1: 1; - export { void_1 as void }; + const _9: number; + export { _9 as void }; } declare namespace foo { - const while_1: 1; - export { while_1 as while }; + const _10: number; + export { _10 as while }; } declare namespace foo { - const with_1: 1; - export { with_1 as with }; + const _11: number; + export { _11 as with }; } declare namespace foo { - const implements_1: 1; - export { implements_1 as implements }; + const _12: number; + export { _12 as implements }; } declare namespace foo { - const interface_1: 1; - export { interface_1 as interface }; + const _13: number; + export { _13 as interface }; } declare namespace foo { - const let_1: 1; - export { let_1 as let }; + const _14: number; + export { _14 as let }; } declare namespace foo { - const package_1: 1; - export { package_1 as package }; + const _15: number; + export { _15 as package }; } declare namespace foo { - const private_1: 1; - export { private_1 as private }; + const _16: number; + export { _16 as private }; } declare namespace foo { - const protected_1: 1; - export { protected_1 as protected }; + const _17: number; + export { _17 as protected }; } declare namespace foo { - const public_1: 1; - export { public_1 as public }; + const _18: number; + export { _18 as public }; } declare namespace foo { - const static_1: 1; - export { static_1 as static }; + const _19: number; + export { _19 as static }; } declare namespace foo { - const yield_1: 1; - export { yield_1 as yield }; + const _20: number; + export { _20 as yield }; } declare namespace foo { - const abstract: 1; + const abstract: number; } declare namespace foo { - const as: 1; + const as: number; } declare namespace foo { - const asserts: 1; + const asserts: number; } declare namespace foo { - const any: 1; + const any: number; } declare namespace foo { - const async: 1; + const async: number; } declare namespace foo { - const await: 1; + const await: number; } declare namespace foo { - const boolean: 1; + const boolean: number; } declare namespace foo { - const constructor: 1; + const constructor: number; } declare namespace foo { - const declare: 1; + const declare: number; } declare namespace foo { - const get: 1; + const get: number; } declare namespace foo { - const infer: 1; + const infer: number; } declare namespace foo { - const is: 1; + const is: number; } declare namespace foo { - const keyof: 1; + const keyof: number; } declare namespace foo { - const module: 1; + const module: number; } declare namespace foo { - const namespace: 1; + const namespace: number; } declare namespace foo { - const never: 1; + const never: number; } declare namespace foo { - const readonly: 1; + const readonly: number; } declare namespace foo { - const require: 1; + const require: number; } declare namespace foo { - const number: 1; + const number: number; } declare namespace foo { - const object: 1; + const object: number; } declare namespace foo { - const set: 1; + const set: number; } declare namespace foo { - const string: 1; + const string: number; } declare namespace foo { - const symbol: 1; + const symbol: number; } declare namespace foo { - const type: 1; + const type: number; } declare namespace foo { - const undefined: 1; + const undefined: number; } declare namespace foo { - const unique: 1; + const unique: number; } declare namespace foo { - const unknown: 1; + const unknown: number; } declare namespace foo { - const from: 1; + const from: number; } declare namespace foo { - const global: 1; + const global: number; } declare namespace foo { - const bigint: 1; + const bigint: number; } declare namespace foo { - const of: 1; + const of: number; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff index d666f96ac3..64f641cc38 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff @@ -127,281 +127,281 @@ - export let global: number; - export let bigint: number; - export let of: number; -+ const x: 1; ++ const x: number; +} +declare namespace foo { -+ const y: 1; ++ const y: number; +} +declare namespace foo { -+ const break_1: 1; -+ export { break_1 as break }; ++ const _a: number; ++ export { _a as break }; +} +declare namespace foo { -+ const case_1: 1; -+ export { case_1 as case }; ++ const _b: number; ++ export { _b as case }; +} +declare namespace foo { -+ const catch_1: 1; -+ export { catch_1 as catch }; ++ const _c: number; ++ export { _c as catch }; +} +declare namespace foo { -+ const class_1: 1; -+ export { class_1 as class }; ++ const _d: number; ++ export { _d as class }; +} +declare namespace foo { -+ const const_1: 1; -+ export { const_1 as const }; ++ const _e: number; ++ export { _e as const }; +} +declare namespace foo { -+ const continue_1: 1; -+ export { continue_1 as continue }; ++ const _f: number; ++ export { _f as continue }; +} +declare namespace foo { -+ const debugger_1: 1; -+ export { debugger_1 as debugger }; ++ const _g: number; ++ export { _g as debugger }; +} +declare namespace foo { -+ const default_1: 1; -+ export { default_1 as default }; ++ const _h: number; ++ export { _h as default }; +} +declare namespace foo { -+ const delete_1: 1; -+ export { delete_1 as delete }; ++ const _j: number; ++ export { _j as delete }; +} +declare namespace foo { -+ const do_1: 1; -+ export { do_1 as do }; ++ const _k: number; ++ export { _k as do }; +} +declare namespace foo { -+ const else_1: 1; -+ export { else_1 as else }; ++ const _l: number; ++ export { _l as else }; +} +declare namespace foo { -+ const enum_1: 1; -+ export { enum_1 as enum }; ++ const _m: number; ++ export { _m as enum }; +} +declare namespace foo { -+ const export_1: 1; -+ export { export_1 as export }; ++ const _o: number; ++ export { _o as export }; +} +declare namespace foo { -+ const extends_1: 1; -+ export { extends_1 as extends }; ++ const _p: number; ++ export { _p as extends }; +} +declare namespace foo { -+ const false_1: 1; -+ export { false_1 as false }; ++ const _q: number; ++ export { _q as false }; +} +declare namespace foo { -+ const finally_1: 1; -+ export { finally_1 as finally }; ++ const _r: number; ++ export { _r as finally }; +} +declare namespace foo { -+ const for_1: 1; -+ export { for_1 as for }; ++ const _s: number; ++ export { _s as for }; +} +declare namespace foo { -+ const function_1: 1; -+ export { function_1 as function }; ++ const _t: number; ++ export { _t as function }; +} +declare namespace foo { -+ const if_1: 1; -+ export { if_1 as if }; ++ const _u: number; ++ export { _u as if }; +} +declare namespace foo { -+ const import_1: 1; -+ export { import_1 as import }; ++ const _v: number; ++ export { _v as import }; +} +declare namespace foo { -+ const in_1: 1; -+ export { in_1 as in }; ++ const _w: number; ++ export { _w as in }; +} +declare namespace foo { -+ const instanceof_1: 1; -+ export { instanceof_1 as instanceof }; ++ const _x: number; ++ export { _x as instanceof }; +} +declare namespace foo { -+ const new_1: 1; -+ export { new_1 as new }; ++ const _y: number; ++ export { _y as new }; +} +declare namespace foo { -+ const null_1: 1; -+ export { null_1 as null }; ++ const _z: number; ++ export { _z as null }; +} +declare namespace foo { -+ const return_1: 1; -+ export { return_1 as return }; ++ const _0: number; ++ export { _0 as return }; +} +declare namespace foo { -+ const super_1: 1; -+ export { super_1 as super }; ++ const _1: number; ++ export { _1 as super }; +} +declare namespace foo { -+ const switch_1: 1; -+ export { switch_1 as switch }; ++ const _2: number; ++ export { _2 as switch }; +} +declare namespace foo { -+ const this_1: 1; -+ export { this_1 as this }; ++ const _3: number; ++ export { _3 as this }; +} +declare namespace foo { -+ const throw_1: 1; -+ export { throw_1 as throw }; ++ const _4: number; ++ export { _4 as throw }; +} +declare namespace foo { -+ const true_1: 1; -+ export { true_1 as true }; ++ const _5: number; ++ export { _5 as true }; +} +declare namespace foo { -+ const try_1: 1; -+ export { try_1 as try }; ++ const _6: number; ++ export { _6 as try }; +} +declare namespace foo { -+ const typeof_1: 1; -+ export { typeof_1 as typeof }; ++ const _7: number; ++ export { _7 as typeof }; +} +declare namespace foo { -+ const var_1: 1; -+ export { var_1 as var }; ++ const _8: number; ++ export { _8 as var }; +} +declare namespace foo { -+ const void_1: 1; -+ export { void_1 as void }; ++ const _9: number; ++ export { _9 as void }; +} +declare namespace foo { -+ const while_1: 1; -+ export { while_1 as while }; ++ const _10: number; ++ export { _10 as while }; +} +declare namespace foo { -+ const with_1: 1; -+ export { with_1 as with }; ++ const _11: number; ++ export { _11 as with }; +} +declare namespace foo { -+ const implements_1: 1; -+ export { implements_1 as implements }; ++ const _12: number; ++ export { _12 as implements }; +} +declare namespace foo { -+ const interface_1: 1; -+ export { interface_1 as interface }; ++ const _13: number; ++ export { _13 as interface }; +} +declare namespace foo { -+ const let_1: 1; -+ export { let_1 as let }; ++ const _14: number; ++ export { _14 as let }; +} +declare namespace foo { -+ const package_1: 1; -+ export { package_1 as package }; ++ const _15: number; ++ export { _15 as package }; +} +declare namespace foo { -+ const private_1: 1; -+ export { private_1 as private }; ++ const _16: number; ++ export { _16 as private }; +} +declare namespace foo { -+ const protected_1: 1; -+ export { protected_1 as protected }; ++ const _17: number; ++ export { _17 as protected }; +} +declare namespace foo { -+ const public_1: 1; -+ export { public_1 as public }; ++ const _18: number; ++ export { _18 as public }; +} +declare namespace foo { -+ const static_1: 1; -+ export { static_1 as static }; ++ const _19: number; ++ export { _19 as static }; +} +declare namespace foo { -+ const yield_1: 1; -+ export { yield_1 as yield }; ++ const _20: number; ++ export { _20 as yield }; +} +declare namespace foo { -+ const abstract: 1; ++ const abstract: number; +} +declare namespace foo { -+ const as: 1; ++ const as: number; +} +declare namespace foo { -+ const asserts: 1; ++ const asserts: number; +} +declare namespace foo { -+ const any: 1; ++ const any: number; +} +declare namespace foo { -+ const async: 1; ++ const async: number; +} +declare namespace foo { -+ const await: 1; ++ const await: number; +} +declare namespace foo { -+ const boolean: 1; ++ const boolean: number; +} +declare namespace foo { -+ const constructor: 1; ++ const constructor: number; +} +declare namespace foo { -+ const declare: 1; ++ const declare: number; +} +declare namespace foo { -+ const get: 1; ++ const get: number; +} +declare namespace foo { -+ const infer: 1; ++ const infer: number; +} +declare namespace foo { -+ const is: 1; ++ const is: number; +} +declare namespace foo { -+ const keyof: 1; ++ const keyof: number; +} +declare namespace foo { -+ const module: 1; ++ const module: number; +} +declare namespace foo { -+ const namespace: 1; ++ const namespace: number; +} +declare namespace foo { -+ const never: 1; ++ const never: number; +} +declare namespace foo { -+ const readonly: 1; ++ const readonly: number; +} +declare namespace foo { -+ const require: 1; ++ const require: number; +} +declare namespace foo { -+ const number: 1; ++ const number: number; +} +declare namespace foo { -+ const object: 1; ++ const object: number; +} +declare namespace foo { -+ const set: 1; ++ const set: number; +} +declare namespace foo { -+ const string: 1; ++ const string: number; +} +declare namespace foo { -+ const symbol: 1; ++ const symbol: number; +} +declare namespace foo { -+ const type: 1; ++ const type: number; +} +declare namespace foo { -+ const undefined: 1; ++ const undefined: number; +} +declare namespace foo { -+ const unique: 1; ++ const unique: number; +} +declare namespace foo { -+ const unknown: 1; ++ const unknown: number; +} +declare namespace foo { -+ const from: 1; ++ const from: number; +} +declare namespace foo { -+ const global: 1; ++ const global: number; +} +declare namespace foo { -+ const bigint: 1; ++ const bigint: number; +} +declare namespace foo { -+ const of: 1; ++ const of: number; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index ed5c03b0c7..70cb996f77 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -38,7 +38,7 @@ declare namespace MyClass { const staticMethod: () => void; } declare namespace MyClass { - const staticProperty: 123; + const staticProperty: number; } export type DoneCB = (failures: number) ; /** diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 0799d74a9a..20e65c384f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -27,7 +27,7 @@ + const staticMethod: () => void; +} +declare namespace MyClass { -+ const staticProperty: 123; ++ const staticProperty: number; +} +export type DoneCB = (failures: number) ; /** diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js index 14c51d1f6e..f277c8e7d3 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -20,7 +20,7 @@ declare namespace foo { const foo: typeof import("."); } declare namespace foo { - const default_1: typeof import("."); - export { default_1 as default }; + const _a: typeof import("."); + export { _a as default }; } export = foo; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff index 02762da945..782b217755 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff @@ -13,8 +13,8 @@ + const foo: typeof import("."); +} +declare namespace foo { -+ const default_1: typeof import("."); -+ export { default_1 as default }; ++ const _a: typeof import("."); ++ export { _a as default }; +} export = foo; -declare function foo(): void; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js index 92d1bc5500..3344f4abd7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -124,7 +124,7 @@ function j() { } export declare function a(): void; export declare function b(): void; export declare namespace b { - const cat: "cat"; + const cat: string; } export declare function c(): void; export declare namespace c { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 4ed26795df..5f33df2f7a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -28,7 +28,7 @@ +export declare function a(): void; +export declare function b(): void; +export declare namespace b { -+ const cat: "cat"; ++ const cat: string; } -export function c(): void; -export namespace c { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index 69b2f16182..97c4e95c02 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -213,9 +213,7 @@ import React from "react"; */ declare const TabbedShowLayout: React.SFC; declare namespace TabbedShowLayout { - const defaultProps: { - tabs: string; - }; + const defaultProps: Partial<{}> | undefined; } export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] @@ -324,9 +322,7 @@ out/jsDeclarationsReactComponents4.d.ts(9,19): error TS2451: Cannot redeclare bl declare namespace TabbedShowLayout { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - const defaultProps: { - tabs: string; - }; + const defaultProps: Partial<{}> | undefined; } export default TabbedShowLayout; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index 462190b8b5..a034a07f47 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -96,9 +96,7 @@ + */ +declare const TabbedShowLayout: React.SFC; +declare namespace TabbedShowLayout { -+ const defaultProps: { -+ tabs: string; -+ }; ++ const defaultProps: Partial<{}> | undefined; +} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] @@ -106,7 +104,7 @@ /** * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} */ -@@= skipped -30, +44 lines =@@ +@@= skipped -30, +42 lines =@@ } & ((props?: { elem: string; }) => JSX.Element); @@ -223,9 +221,7 @@ + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ const defaultProps: { -+ tabs: string; -+ }; ++ const defaultProps: Partial<{}> | undefined; + } + export default TabbedShowLayout; + diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js index 596b51e972..f64da7a799 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js @@ -172,281 +172,281 @@ foo.of = 1; //// [nullPropertyName.d.ts] declare function foo(): void; declare namespace foo { - const x: 1; + const x: number; } declare namespace foo { - const y: 1; + const y: number; } declare namespace foo { - const break_1: 1; - export { break_1 as break }; + const _a: number; + export { _a as break }; } declare namespace foo { - const case_1: 1; - export { case_1 as case }; + const _b: number; + export { _b as case }; } declare namespace foo { - const catch_1: 1; - export { catch_1 as catch }; + const _c: number; + export { _c as catch }; } declare namespace foo { - const class_1: 1; - export { class_1 as class }; + const _d: number; + export { _d as class }; } declare namespace foo { - const const_1: 1; - export { const_1 as const }; + const _e: number; + export { _e as const }; } declare namespace foo { - const continue_1: 1; - export { continue_1 as continue }; + const _f: number; + export { _f as continue }; } declare namespace foo { - const debugger_1: 1; - export { debugger_1 as debugger }; + const _g: number; + export { _g as debugger }; } declare namespace foo { - const default_1: 1; - export { default_1 as default }; + const _h: number; + export { _h as default }; } declare namespace foo { - const delete_1: 1; - export { delete_1 as delete }; + const _j: number; + export { _j as delete }; } declare namespace foo { - const do_1: 1; - export { do_1 as do }; + const _k: number; + export { _k as do }; } declare namespace foo { - const else_1: 1; - export { else_1 as else }; + const _l: number; + export { _l as else }; } declare namespace foo { - const enum_1: 1; - export { enum_1 as enum }; + const _m: number; + export { _m as enum }; } declare namespace foo { - const export_1: 1; - export { export_1 as export }; + const _o: number; + export { _o as export }; } declare namespace foo { - const extends_1: 1; - export { extends_1 as extends }; + const _p: number; + export { _p as extends }; } declare namespace foo { - const false_1: 1; - export { false_1 as false }; + const _q: number; + export { _q as false }; } declare namespace foo { - const finally_1: 1; - export { finally_1 as finally }; + const _r: number; + export { _r as finally }; } declare namespace foo { - const for_1: 1; - export { for_1 as for }; + const _s: number; + export { _s as for }; } declare namespace foo { - const function_1: 1; - export { function_1 as function }; + const _t: number; + export { _t as function }; } declare namespace foo { - const if_1: 1; - export { if_1 as if }; + const _u: number; + export { _u as if }; } declare namespace foo { - const import_1: 1; - export { import_1 as import }; + const _v: number; + export { _v as import }; } declare namespace foo { - const in_1: 1; - export { in_1 as in }; + const _w: number; + export { _w as in }; } declare namespace foo { - const instanceof_1: 1; - export { instanceof_1 as instanceof }; + const _x: number; + export { _x as instanceof }; } declare namespace foo { - const new_1: 1; - export { new_1 as new }; + const _y: number; + export { _y as new }; } declare namespace foo { - const null_1: 1; - export { null_1 as null }; + const _z: number; + export { _z as null }; } declare namespace foo { - const return_1: 1; - export { return_1 as return }; + const _0: number; + export { _0 as return }; } declare namespace foo { - const super_1: 1; - export { super_1 as super }; + const _1: number; + export { _1 as super }; } declare namespace foo { - const switch_1: 1; - export { switch_1 as switch }; + const _2: number; + export { _2 as switch }; } declare namespace foo { - const this_1: 1; - export { this_1 as this }; + const _3: number; + export { _3 as this }; } declare namespace foo { - const throw_1: 1; - export { throw_1 as throw }; + const _4: number; + export { _4 as throw }; } declare namespace foo { - const true_1: 1; - export { true_1 as true }; + const _5: number; + export { _5 as true }; } declare namespace foo { - const try_1: 1; - export { try_1 as try }; + const _6: number; + export { _6 as try }; } declare namespace foo { - const typeof_1: 1; - export { typeof_1 as typeof }; + const _7: number; + export { _7 as typeof }; } declare namespace foo { - const var_1: 1; - export { var_1 as var }; + const _8: number; + export { _8 as var }; } declare namespace foo { - const void_1: 1; - export { void_1 as void }; + const _9: number; + export { _9 as void }; } declare namespace foo { - const while_1: 1; - export { while_1 as while }; + const _10: number; + export { _10 as while }; } declare namespace foo { - const with_1: 1; - export { with_1 as with }; + const _11: number; + export { _11 as with }; } declare namespace foo { - const implements_1: 1; - export { implements_1 as implements }; + const _12: number; + export { _12 as implements }; } declare namespace foo { - const interface_1: 1; - export { interface_1 as interface }; + const _13: number; + export { _13 as interface }; } declare namespace foo { - const let_1: 1; - export { let_1 as let }; + const _14: number; + export { _14 as let }; } declare namespace foo { - const package_1: 1; - export { package_1 as package }; + const _15: number; + export { _15 as package }; } declare namespace foo { - const private_1: 1; - export { private_1 as private }; + const _16: number; + export { _16 as private }; } declare namespace foo { - const protected_1: 1; - export { protected_1 as protected }; + const _17: number; + export { _17 as protected }; } declare namespace foo { - const public_1: 1; - export { public_1 as public }; + const _18: number; + export { _18 as public }; } declare namespace foo { - const static_1: 1; - export { static_1 as static }; + const _19: number; + export { _19 as static }; } declare namespace foo { - const yield_1: 1; - export { yield_1 as yield }; + const _20: number; + export { _20 as yield }; } declare namespace foo { - const abstract: 1; + const abstract: number; } declare namespace foo { - const as: 1; + const as: number; } declare namespace foo { - const asserts: 1; + const asserts: number; } declare namespace foo { - const any: 1; + const any: number; } declare namespace foo { - const async: 1; + const async: number; } declare namespace foo { - const await: 1; + const await: number; } declare namespace foo { - const boolean: 1; + const boolean: number; } declare namespace foo { - const constructor: 1; + const constructor: number; } declare namespace foo { - const declare: 1; + const declare: number; } declare namespace foo { - const get: 1; + const get: number; } declare namespace foo { - const infer: 1; + const infer: number; } declare namespace foo { - const is: 1; + const is: number; } declare namespace foo { - const keyof: 1; + const keyof: number; } declare namespace foo { - const module: 1; + const module: number; } declare namespace foo { - const namespace: 1; + const namespace: number; } declare namespace foo { - const never: 1; + const never: number; } declare namespace foo { - const readonly: 1; + const readonly: number; } declare namespace foo { - const require: 1; + const require: number; } declare namespace foo { - const number: 1; + const number: number; } declare namespace foo { - const object: 1; + const object: number; } declare namespace foo { - const set: 1; + const set: number; } declare namespace foo { - const string: 1; + const string: number; } declare namespace foo { - const symbol: 1; + const symbol: number; } declare namespace foo { - const type: 1; + const type: number; } declare namespace foo { - const undefined: 1; + const undefined: number; } declare namespace foo { - const unique: 1; + const unique: number; } declare namespace foo { - const unknown: 1; + const unknown: number; } declare namespace foo { - const from: 1; + const from: number; } declare namespace foo { - const global: 1; + const global: number; } declare namespace foo { - const bigint: 1; + const bigint: number; } declare namespace foo { - const of: 1; + const of: number; } diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff index 139a9c0ac2..386fe72392 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff @@ -83,281 +83,281 @@ - 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 }; -+ const x: 1; ++ const x: number; +} +declare namespace foo { -+ const y: 1; ++ const y: number; +} +declare namespace foo { -+ const break_1: 1; -+ export { break_1 as break }; ++ const _a: number; ++ export { _a as break }; +} +declare namespace foo { -+ const case_1: 1; -+ export { case_1 as case }; ++ const _b: number; ++ export { _b as case }; +} +declare namespace foo { -+ const catch_1: 1; -+ export { catch_1 as catch }; ++ const _c: number; ++ export { _c as catch }; +} +declare namespace foo { -+ const class_1: 1; -+ export { class_1 as class }; ++ const _d: number; ++ export { _d as class }; +} +declare namespace foo { -+ const const_1: 1; -+ export { const_1 as const }; ++ const _e: number; ++ export { _e as const }; +} +declare namespace foo { -+ const continue_1: 1; -+ export { continue_1 as continue }; ++ const _f: number; ++ export { _f as continue }; +} +declare namespace foo { -+ const debugger_1: 1; -+ export { debugger_1 as debugger }; ++ const _g: number; ++ export { _g as debugger }; +} +declare namespace foo { -+ const default_1: 1; -+ export { default_1 as default }; ++ const _h: number; ++ export { _h as default }; +} +declare namespace foo { -+ const delete_1: 1; -+ export { delete_1 as delete }; ++ const _j: number; ++ export { _j as delete }; +} +declare namespace foo { -+ const do_1: 1; -+ export { do_1 as do }; ++ const _k: number; ++ export { _k as do }; +} +declare namespace foo { -+ const else_1: 1; -+ export { else_1 as else }; ++ const _l: number; ++ export { _l as else }; +} +declare namespace foo { -+ const enum_1: 1; -+ export { enum_1 as enum }; ++ const _m: number; ++ export { _m as enum }; +} +declare namespace foo { -+ const export_1: 1; -+ export { export_1 as export }; ++ const _o: number; ++ export { _o as export }; +} +declare namespace foo { -+ const extends_1: 1; -+ export { extends_1 as extends }; ++ const _p: number; ++ export { _p as extends }; +} +declare namespace foo { -+ const false_1: 1; -+ export { false_1 as false }; ++ const _q: number; ++ export { _q as false }; +} +declare namespace foo { -+ const finally_1: 1; -+ export { finally_1 as finally }; ++ const _r: number; ++ export { _r as finally }; +} +declare namespace foo { -+ const for_1: 1; -+ export { for_1 as for }; ++ const _s: number; ++ export { _s as for }; +} +declare namespace foo { -+ const function_1: 1; -+ export { function_1 as function }; ++ const _t: number; ++ export { _t as function }; +} +declare namespace foo { -+ const if_1: 1; -+ export { if_1 as if }; ++ const _u: number; ++ export { _u as if }; +} +declare namespace foo { -+ const import_1: 1; -+ export { import_1 as import }; ++ const _v: number; ++ export { _v as import }; +} +declare namespace foo { -+ const in_1: 1; -+ export { in_1 as in }; ++ const _w: number; ++ export { _w as in }; +} +declare namespace foo { -+ const instanceof_1: 1; -+ export { instanceof_1 as instanceof }; ++ const _x: number; ++ export { _x as instanceof }; +} +declare namespace foo { -+ const new_1: 1; -+ export { new_1 as new }; ++ const _y: number; ++ export { _y as new }; +} +declare namespace foo { -+ const null_1: 1; -+ export { null_1 as null }; ++ const _z: number; ++ export { _z as null }; +} +declare namespace foo { -+ const return_1: 1; -+ export { return_1 as return }; ++ const _0: number; ++ export { _0 as return }; +} +declare namespace foo { -+ const super_1: 1; -+ export { super_1 as super }; ++ const _1: number; ++ export { _1 as super }; +} +declare namespace foo { -+ const switch_1: 1; -+ export { switch_1 as switch }; ++ const _2: number; ++ export { _2 as switch }; +} +declare namespace foo { -+ const this_1: 1; -+ export { this_1 as this }; ++ const _3: number; ++ export { _3 as this }; +} +declare namespace foo { -+ const throw_1: 1; -+ export { throw_1 as throw }; ++ const _4: number; ++ export { _4 as throw }; +} +declare namespace foo { -+ const true_1: 1; -+ export { true_1 as true }; ++ const _5: number; ++ export { _5 as true }; +} +declare namespace foo { -+ const try_1: 1; -+ export { try_1 as try }; ++ const _6: number; ++ export { _6 as try }; +} +declare namespace foo { -+ const typeof_1: 1; -+ export { typeof_1 as typeof }; ++ const _7: number; ++ export { _7 as typeof }; +} +declare namespace foo { -+ const var_1: 1; -+ export { var_1 as var }; ++ const _8: number; ++ export { _8 as var }; +} +declare namespace foo { -+ const void_1: 1; -+ export { void_1 as void }; ++ const _9: number; ++ export { _9 as void }; +} +declare namespace foo { -+ const while_1: 1; -+ export { while_1 as while }; ++ const _10: number; ++ export { _10 as while }; +} +declare namespace foo { -+ const with_1: 1; -+ export { with_1 as with }; ++ const _11: number; ++ export { _11 as with }; +} +declare namespace foo { -+ const implements_1: 1; -+ export { implements_1 as implements }; ++ const _12: number; ++ export { _12 as implements }; +} +declare namespace foo { -+ const interface_1: 1; -+ export { interface_1 as interface }; ++ const _13: number; ++ export { _13 as interface }; +} +declare namespace foo { -+ const let_1: 1; -+ export { let_1 as let }; ++ const _14: number; ++ export { _14 as let }; +} +declare namespace foo { -+ const package_1: 1; -+ export { package_1 as package }; ++ const _15: number; ++ export { _15 as package }; +} +declare namespace foo { -+ const private_1: 1; -+ export { private_1 as private }; ++ const _16: number; ++ export { _16 as private }; +} +declare namespace foo { -+ const protected_1: 1; -+ export { protected_1 as protected }; ++ const _17: number; ++ export { _17 as protected }; +} +declare namespace foo { -+ const public_1: 1; -+ export { public_1 as public }; ++ const _18: number; ++ export { _18 as public }; +} +declare namespace foo { -+ const static_1: 1; -+ export { static_1 as static }; ++ const _19: number; ++ export { _19 as static }; +} +declare namespace foo { -+ const yield_1: 1; -+ export { yield_1 as yield }; ++ const _20: number; ++ export { _20 as yield }; +} +declare namespace foo { -+ const abstract: 1; ++ const abstract: number; +} +declare namespace foo { -+ const as: 1; ++ const as: number; +} +declare namespace foo { -+ const asserts: 1; ++ const asserts: number; +} +declare namespace foo { -+ const any: 1; ++ const any: number; +} +declare namespace foo { -+ const async: 1; ++ const async: number; +} +declare namespace foo { -+ const await: 1; ++ const await: number; +} +declare namespace foo { -+ const boolean: 1; ++ const boolean: number; +} +declare namespace foo { -+ const constructor: 1; ++ const constructor: number; +} +declare namespace foo { -+ const declare: 1; ++ const declare: number; +} +declare namespace foo { -+ const get: 1; ++ const get: number; +} +declare namespace foo { -+ const infer: 1; ++ const infer: number; +} +declare namespace foo { -+ const is: 1; ++ const is: number; +} +declare namespace foo { -+ const keyof: 1; ++ const keyof: number; +} +declare namespace foo { -+ const module: 1; ++ const module: number; +} +declare namespace foo { -+ const namespace: 1; ++ const namespace: number; +} +declare namespace foo { -+ const never: 1; ++ const never: number; +} +declare namespace foo { -+ const readonly: 1; ++ const readonly: number; +} +declare namespace foo { -+ const require: 1; ++ const require: number; +} +declare namespace foo { -+ const number: 1; ++ const number: number; +} +declare namespace foo { -+ const object: 1; ++ const object: number; +} +declare namespace foo { -+ const set: 1; ++ const set: number; +} +declare namespace foo { -+ const string: 1; ++ const string: number; +} +declare namespace foo { -+ const symbol: 1; ++ const symbol: number; +} +declare namespace foo { -+ const type: 1; ++ const type: number; +} +declare namespace foo { -+ const undefined: 1; ++ const undefined: number; +} +declare namespace foo { -+ const unique: 1; ++ const unique: number; +} +declare namespace foo { -+ const unknown: 1; ++ const unknown: number; +} +declare namespace foo { -+ const from: 1; ++ const from: number; +} +declare namespace foo { -+ const global: 1; ++ const global: number; +} +declare namespace foo { -+ const bigint: 1; ++ const bigint: number; +} +declare namespace foo { -+ const of: 1; ++ const 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 34caf31d2f..d8cb78c6f8 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -171,7 +171,7 @@ var n = ExpandoExpr3.prop + ExpandoExpr3.m(13) + new ExpandoExpr3().n; //// [typeFromPropertyAssignment29.d.ts] declare function ExpandoDecl(n: number): string; declare namespace ExpandoDecl { - const prop: 2; + const prop: number; } declare namespace ExpandoDecl { const m: (n: number) => number; @@ -191,10 +191,18 @@ declare const ExpandoExpr: { declare namespace ExpandoExpr { const prop: { x: number; + y?: undefined; + } | { + x?: undefined; + y: string; }; } declare namespace ExpandoExpr { const prop: { + x: number; + y?: undefined; + } | { + x?: undefined; y: string; }; } @@ -208,7 +216,7 @@ declare const ExpandoArrow: { m: (n: number) => number; }; declare namespace ExpandoArrow { - const prop: 2; + const prop: number; } declare namespace ExpandoArrow { const m: (n: number) => number; @@ -218,11 +226,11 @@ declare function ExpandoNested(n: number): { total: number; }; declare namespace ExpandoNested { - const also: -1; + const also: number; } declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { - const p1: 111; + const p1: number; } declare namespace ExpandoMerge { var p2: number; @@ -234,7 +242,7 @@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; declare namespace ExpandoNamespace { - const p6: 42; + const 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 f84d7fd36e..44d8d51342 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -37,7 +37,7 @@ declare namespace ExpandoDecl { - var prop: number; - var m: (n: number) => number; -+ const prop: 2; ++ const prop: number; +} +declare namespace ExpandoDecl { + const m: (n: number) => number; @@ -54,10 +54,18 @@ +declare namespace ExpandoExpr { + const prop: { + x: number; ++ y?: undefined; ++ } | { ++ x?: undefined; ++ y: string; + }; +} +declare namespace ExpandoExpr { + const prop: { ++ x: number; ++ y?: undefined; ++ } | { ++ x?: undefined; + y: string; + }; +} @@ -72,7 +80,7 @@ + m: (n: number) => number; }; +declare namespace ExpandoArrow { -+ const prop: 2; ++ const prop: number; +} +declare namespace ExpandoArrow { + const m: (n: number) => number; @@ -83,23 +91,23 @@ }; declare namespace ExpandoNested { - var also: number; -+ const also: -1; ++ const also: number; } declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { - var p1: number; -+ const p1: 111; ++ const p1: number; } declare namespace ExpandoMerge { var p2: number; -@@= skipped -28, +47 lines =@@ +@@= skipped -28, +55 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; - namespace ExpandoNamespace { - var p6: number; + declare namespace ExpandoNamespace { -+ const p6: 42; ++ const p6: number; } export function foo(): typeof ExpandoNamespace; export {}; \ No newline at end of file From e6a602513e57b56db729e941f0b2af2174841bf2 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Tue, 7 Oct 2025 02:54:52 +0300 Subject: [PATCH 05/11] transform expando hosts --- .../transformers/declarations/transform.go | 132 +++++++++----- ...arationEmitExpandoWithGenericConstraint.js | 39 +--- ...onEmitExpandoWithGenericConstraint.js.diff | 48 +---- .../compiler/isolatedDeclarationErrors.js | 49 +---- .../isolatedDeclarationErrors.js.diff | 51 +----- .../jsDeclarationsGlobalFileConstFunction.js | 46 +---- ...eclarationsGlobalFileConstFunction.js.diff | 51 +----- ...eclarationsGlobalFileConstFunctionNamed.js | 15 +- ...ationsGlobalFileConstFunctionNamed.js.diff | 17 +- ...tionsFunctionClassesCjsExportAssignment.js | 28 +++ ...FunctionClassesCjsExportAssignment.js.diff | 57 ++---- .../jsDeclarationsFunctionPrototypeStatic.js | 1 + ...eclarationsFunctionPrototypeStatic.js.diff | 5 +- ...ationsFunctionWithDefaultAssignedMember.js | 1 + ...sFunctionWithDefaultAssignedMember.js.diff | 14 +- ...tionsParameterTagReusesInputNodeInEmit1.js | 1 + ...ParameterTagReusesInputNodeInEmit1.js.diff | 12 +- ...tionsParameterTagReusesInputNodeInEmit2.js | 1 + ...ParameterTagReusesInputNodeInEmit2.js.diff | 12 +- .../jsDeclarationsReactComponents.js | 158 +--------------- .../jsDeclarationsReactComponents.js.diff | 171 ++---------------- .../typeFromPropertyAssignment29.js | 18 +- .../typeFromPropertyAssignment29.js.diff | 43 +++-- 23 files changed, 236 insertions(+), 734 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 46418b3d46..91cc5289a6 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" @@ -58,13 +59,14 @@ type DeclarationTransformer struct { declarationMapPath string isBundledEmit bool - declareModifier DeclareModifier + needsDeclare bool needsScopeFixMarker bool resultHasScopeMarker bool enclosingDeclaration *ast.Node resultHasExternalModuleIndicator bool suppressNewDiagnosticContexts bool lateStatementReplacementMap map[ast.NodeId]*ast.Node + expandoHosts collections.Set[ast.NodeId] rawReferencedFiles []ReferencedFilePair rawTypeReferenceDirectives []*ast.FileReference rawLibReferenceDirectives []*ast.FileReference @@ -167,7 +169,7 @@ func (tx *DeclarationTransformer) visitSourceFile(node *ast.SourceFile) *ast.Nod } tx.isBundledEmit = false - tx.declareModifier = DeclareModifierEligible + tx.needsDeclare = true tx.needsScopeFixMarker = false tx.resultHasScopeMarker = false tx.enclosingDeclaration = node.AsNode() @@ -176,6 +178,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) @@ -241,16 +244,12 @@ func (tx *DeclarationTransformer) transformAndReplaceLatePaintedStatements(state next := tx.state.lateMarkedStatements[0] tx.state.lateMarkedStatements = tx.state.lateMarkedStatements[1:] - saveDeclareModifier := tx.declareModifier - tx.declareModifier = core.IfElse( - next.Parent != nil && ast.IsSourceFile(next.Parent) && !(ast.IsExternalModule(next.Parent.AsSourceFile()) && tx.isBundledEmit), - DeclareModifierEligible, - DeclareModifierNone, - ) + saveNeedsDeclare := tx.needsDeclare + tx.needsDeclare = next.Parent != nil && ast.IsSourceFile(next.Parent) && !(ast.IsExternalModule(next.Parent.AsSourceFile()) && tx.isBundledEmit) result := tx.transformTopLevelDeclaration(next) - tx.declareModifier = saveDeclareModifier + tx.needsDeclare = saveNeedsDeclare original := tx.EmitContext().MostOriginal(next) id := ast.GetNodeId(original) tx.lateStatementReplacementMap[id] = result @@ -954,7 +953,7 @@ func (tx *DeclarationTransformer) visitDeclarationStatements(input *ast.Node) *a varDecl := tx.Factory().NewVariableDeclaration(newId, nil, type_, nil) tx.tracker.PopErrorFallbackNode() var modList *ast.ModifierList - if tx.declareModifier == DeclareModifierEligible { + if tx.needsDeclare { modList = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindDeclareKeyword)}) } else { modList = tx.Factory().NewModifierList([]*ast.Node{}) @@ -1112,7 +1111,7 @@ func (tx *DeclarationTransformer) transformTopLevelDeclaration(input *ast.Node) if canProdiceDiagnostic { tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input) } - saveDeclareModifier := tx.declareModifier + saveNeedsDeclare := tx.needsDeclare var result *ast.Node switch input.Kind { @@ -1137,13 +1136,13 @@ func (tx *DeclarationTransformer) transformTopLevelDeclaration(input *ast.Node) tx.enclosingDeclaration = previousEnclosingDeclaration tx.state.getSymbolAccessibilityDiagnostic = oldDiag - tx.declareModifier = saveDeclareModifier + tx.needsDeclare = saveNeedsDeclare tx.state.errorNameNode = oldName return result } func (tx *DeclarationTransformer) transformTypeAliasDeclaration(input *ast.TypeAliasDeclaration) *ast.Node { - tx.declareModifier = DeclareModifierNone + tx.needsDeclare = false return tx.Factory().UpdateTypeAliasDeclaration( input, tx.ensureModifiers(input.AsNode()), @@ -1183,8 +1182,8 @@ 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()) - saveDeclareModifier := tx.declareModifier - tx.declareModifier = DeclareModifierNone + saveNeedsDeclare := tx.needsDeclare + tx.needsDeclare = false inner := input.Body keyword := input.Keyword if keyword != ast.KindGlobalKeyword && (input.Name() == nil || !ast.IsStringLiteral(input.Name())) { @@ -1214,7 +1213,7 @@ func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDe } body := tx.Factory().UpdateModuleBlock(inner.AsModuleBlock(), lateStatements) - tx.declareModifier = saveDeclareModifier + tx.needsDeclare = saveNeedsDeclare tx.needsScopeFixMarker = oldNeedsScopeFix tx.resultHasScopeMarker = oldHasScopeFix @@ -1363,7 +1362,7 @@ func (tx *DeclarationTransformer) transformClassDeclaration(input *ast.ClassDecl nil, ) var mods *ast.ModifierList - if tx.declareModifier == DeclareModifierEligible { + if tx.needsDeclare { mods = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindDeclareKeyword)}) } statement := tx.Factory().NewVariableStatement( @@ -1508,13 +1507,8 @@ func (tx *DeclarationTransformer) ensureModifiers(node *ast.Node) *ast.ModifierL func (tx *DeclarationTransformer) ensureModifierFlags(node *ast.Node) ast.ModifierFlags { mask := ast.ModifierFlagsAll ^ (ast.ModifierFlagsPublic | ast.ModifierFlagsAsync | ast.ModifierFlagsOverride) // No async and override modifiers in declaration files additions := ast.ModifierFlagsNone - if tx.declareModifier == DeclareModifierEligible && !isAlwaysType(node) { - additions = ast.ModifierFlagsAmbient - } - if tx.declareModifier == DeclareModifierEnforced { + if tx.needsDeclare && !isAlwaysType(node) { additions = ast.ModifierFlagsAmbient - mask ^= ast.ModifierFlagsDefault - mask ^= ast.ModifierFlagsExport } parentIsFile := node.Parent.Kind == ast.KindSourceFile if !parentIsFile || (tx.isBundledEmit && parentIsFile && ast.IsExternalModule(node.Parent.AsSourceFile())) { @@ -1901,38 +1895,90 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp statements = append(statements, tx.Factory().NewExportDeclaration(nil /*modifiers*/, false /*isTypeOnly*/, namedExports, nil /*moduleSpecifier*/, nil /*attributes*/)) } + tx.transformExpandoHost(name, declaration) + + flags := tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(declaration), ast.ModifierFlagsAll) modifierFlags := ast.ModifierFlagsAmbient - replacement := make([]*ast.Node, 0) - flags := ast.GetCombinedModifierFlags(declaration) if flags&ast.ModifierFlagsExport != 0 { - if flags&ast.ModifierFlagsDefault != 0 { - if n := tx.transformExpandoHost(name, declaration); n != nil { - replacement = append(replacement, n) - } - } else { + 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)) - namespace := tx.Factory().NewModuleDeclaration(modifiers, ast.KindNamespaceKeyword, name, tx.Factory().NewModuleBlock(tx.Factory().NewNodeList(statements))) + replacement := make([]*ast.Node, 0) - replacement = append(replacement, namespace) - return tx.Factory().NewSyntaxList(replacement) -} + var typeParameters *ast.TypeParameterList + var parameters *ast.ParameterList + var returnType *ast.Node + var asteriskToken *ast.TokenNode + + if ast.IsFunctionDeclaration(declaration) { + fn := declaration.AsFunctionDeclaration() + typeParameters = tx.ensureTypeParams(fn.AsNode(), fn.TypeParameters) + parameters = tx.updateParamList(fn.AsNode(), fn.Parameters) + returnType = tx.ensureType(fn.AsNode(), false) + asteriskToken = fn.AsteriskToken + } else if ast.IsVariableDeclaration(declaration) && ast.IsFunctionExpressionOrArrowFunction(declaration.Initializer()) { + if ast.IsFunctionExpression(declaration.Initializer()) { + fn := declaration.Initializer().AsFunctionExpression() + typeParameters = tx.ensureTypeParams(fn.AsNode(), fn.TypeParameters) + parameters = tx.updateParamList(fn.AsNode(), fn.Parameters) + returnType = tx.ensureType(fn.AsNode(), false) + asteriskToken = fn.AsteriskToken + } else if ast.IsArrowFunction(declaration.Initializer()) { + fn := declaration.Initializer().AsArrowFunction() + typeParameters = tx.ensureTypeParams(fn.AsNode(), fn.TypeParameters) + parameters = tx.updateParamList(fn.AsNode(), fn.Parameters) + returnType = tx.ensureType(fn.AsNode(), false) + asteriskToken = fn.AsteriskToken + } else { + return + } + } else { + return + } -func (tx *DeclarationTransformer) transformExpandoHost(name *ast.Node, node *ast.Node) *ast.Node { - id := ast.GetNodeId(tx.EmitContext().MostOriginal(node)) - if tx.lateStatementReplacementMap[id] == nil || ast.HasModifier(tx.lateStatementReplacementMap[id], ast.ModifierFlagsDefault) { - saveDeclareModifier := tx.declareModifier - tx.declareModifier = DeclareModifierEnforced - tx.lateStatementReplacementMap[id] = tx.transformTopLevelDeclaration(node) - tx.declareModifier = saveDeclareModifier + if ast.IsFunctionDeclaration(declaration) { + replacement = append(replacement, tx.Factory().UpdateFunctionDeclaration(root.AsFunctionDeclaration(), modifiers, asteriskToken, root.Name(), typeParameters, parameters, returnType, nil /*fullSignature*/, nil /*body*/)) + } else if ast.IsVariableDeclaration(declaration) { + replacement = append(replacement, tx.Factory().NewFunctionDeclaration(modifiers, asteriskToken, tx.Factory().NewIdentifier(name.Text()), typeParameters, parameters, returnType, nil /*fullSignature*/, nil /*body*/)) + } else { + return + } - return tx.Factory().NewExportAssignment(nil /*modifiers*/, false /*isExportEquals*/, nil /*typeNode*/, name) + if defaultExport { + replacement = append(replacement, tx.Factory().NewExportAssignment(nil /*modifiers*/, false /*isExportEquals*/, nil /*typeNode*/, name)) } - return nil + + tx.expandoHosts.Add(id) + tx.lateStatementReplacementMap[id] = tx.Factory().NewSyntaxList(replacement) } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js index 2cd99f38e5..4b03e9dfe2 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js @@ -36,45 +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 { const zero: () => Point; } - - -//// [DtsFileErrors] - - -declarationEmitExpandoWithGenericConstraint.d.ts(1,18): error TS2451: Cannot redeclare block-scoped variable 'Point'. -declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2451: Cannot redeclare block-scoped variable 'Point'. -declarationEmitExpandoWithGenericConstraint.d.ts(14,26): error TS2451: Cannot redeclare block-scoped variable 'Point'. - - -==== declarationEmitExpandoWithGenericConstraint.d.ts (3 errors) ==== - export interface Point { - ~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. - readonly x: number; - readonly y: number; - } - export interface Rect

{ - readonly a: p; - readonly b: p; - } - export declare const Point: { - ~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. - (x: number, y: number): Point; - zero: () => Point; - }; - export declare const Rect:

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

; - export declare namespace Point { - ~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. - const zero: () => Point; - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff index 46da2754ed..1b24394944 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff @@ -1,47 +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 function Point(x: number, y: number): Point; export declare const Rect:

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

; +export declare namespace Point { + const zero: () => Point; -+} -+ -+ -+//// [DtsFileErrors] -+ -+ -+declarationEmitExpandoWithGenericConstraint.d.ts(1,18): error TS2451: Cannot redeclare block-scoped variable 'Point'. -+declarationEmitExpandoWithGenericConstraint.d.ts(9,22): error TS2451: Cannot redeclare block-scoped variable 'Point'. -+declarationEmitExpandoWithGenericConstraint.d.ts(14,26): error TS2451: Cannot redeclare block-scoped variable 'Point'. -+ -+ -+==== declarationEmitExpandoWithGenericConstraint.d.ts (3 errors) ==== -+ export interface Point { -+ ~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. -+ readonly x: number; -+ readonly y: number; -+ } -+ export interface Rect

{ -+ readonly a: p; -+ readonly b: p; -+ } -+ export declare const Point: { -+ ~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. -+ (x: number, y: number): Point; -+ zero: () => Point; -+ }; -+ export declare const Rect:

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

; -+ export declare namespace Point { -+ ~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. -+ const zero: () => Point; -+ } -+ \ No newline at end of file ++} \ 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 577f55bdc9..5ed2dbdd7a 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -25,56 +25,11 @@ declare function errorOnAssignmentBelowDecl(): void; declare namespace errorOnAssignmentBelowDecl { const a: string; } -declare const errorOnAssignmentBelow: { - (): void; - a: string; -}; +declare function errorOnAssignmentBelow(): void; declare namespace errorOnAssignmentBelow { const a: string; } -declare const errorOnMissingReturn: { - (): void; - a: string; -}; +declare function errorOnMissingReturn(): void; declare namespace errorOnMissingReturn { const a: string; } - - -//// [DtsFileErrors] - - -isolatedDeclarationErrors.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -isolatedDeclarationErrors.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -isolatedDeclarationErrors.d.ts(12,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. -isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. - - -==== isolatedDeclarationErrors.d.ts (4 errors) ==== - declare function errorOnAssignmentBelowDecl(): void; - declare namespace errorOnAssignmentBelowDecl { - const a: string; - } - declare const errorOnAssignmentBelow: { - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. - (): void; - a: string; - }; - declare namespace errorOnAssignmentBelow { - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. - const a: string; - } - declare const errorOnMissingReturn: { - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. - (): void; - a: string; - }; - declare namespace errorOnMissingReturn { - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. - const a: string; - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index fcd76ee252..972f69be1f 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -11,56 +11,11 @@ +declare namespace errorOnAssignmentBelowDecl { + const a: string; +} -+declare const errorOnAssignmentBelow: { -+ (): void; -+ a: string; -+}; ++declare function errorOnAssignmentBelow(): void; +declare namespace errorOnAssignmentBelow { + const a: string; +} -+declare const errorOnMissingReturn: { -+ (): void; -+ a: string; -+}; ++declare function errorOnMissingReturn(): void; +declare namespace errorOnMissingReturn { + const a: string; -+} -+ -+ -+//// [DtsFileErrors] -+ -+ -+isolatedDeclarationErrors.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -+isolatedDeclarationErrors.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -+isolatedDeclarationErrors.d.ts(12,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. -+isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. -+ -+ -+==== isolatedDeclarationErrors.d.ts (4 errors) ==== -+ declare function errorOnAssignmentBelowDecl(): void; -+ declare namespace errorOnAssignmentBelowDecl { -+ const a: string; -+ } -+ declare const errorOnAssignmentBelow: { -+ ~~~~~~~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -+ (): void; -+ a: string; -+ }; -+ declare namespace errorOnAssignmentBelow { -+ ~~~~~~~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -+ const a: string; -+ } -+ declare const errorOnMissingReturn: { -+ ~~~~~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. -+ (): void; -+ a: string; -+ }; -+ declare namespace errorOnMissingReturn { -+ ~~~~~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. -+ const a: string; -+ } -+ \ No newline at end of file ++} \ 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 2c74979f38..4c5b98723d 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js @@ -19,53 +19,11 @@ SomeConstructor3.staticMember = "str"; //// [file.d.ts] declare const SomeConstructor: () => void; -declare const SomeConstructor2: { - (): void; - staticMember: string; -}; +declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { const staticMember: string; } -declare const SomeConstructor3: { - (): void; - staticMember: string; -}; +declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { const staticMember: string; } - - -//// [DtsFileErrors] - - -file.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -file.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -file.d.ts(9,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. -file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. - - -==== file.d.ts (4 errors) ==== - declare const SomeConstructor: () => void; - declare const SomeConstructor2: { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. - (): void; - staticMember: string; - }; - declare namespace SomeConstructor2 { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. - const staticMember: string; - } - declare const SomeConstructor3: { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. - (): void; - staticMember: string; - }; - declare namespace SomeConstructor3 { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. - const staticMember: string; - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index d74d31f492..f2e19a6a71 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -8,63 +8,18 @@ -declare class SomeConstructor { - x: number; -} --declare function SomeConstructor2(): void; +declare const SomeConstructor: () => void; -+declare const SomeConstructor2: { -+ (): void; -+ staticMember: string; -+}; + declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { - let staticMember: string; + const staticMember: string; } --declare function SomeConstructor3(): void; -+declare const SomeConstructor3: { -+ (): void; -+ staticMember: string; -+}; + declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} -declare class SomeConstructor3 { - x: number; --} + const staticMember: string; -+} -+ -+ -+//// [DtsFileErrors] -+ -+ -+file.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -+file.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -+file.d.ts(9,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. -+file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. -+ -+ -+==== file.d.ts (4 errors) ==== -+ declare const SomeConstructor: () => void; -+ declare const SomeConstructor2: { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -+ (): void; -+ staticMember: string; -+ }; -+ declare namespace SomeConstructor2 { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -+ const staticMember: string; -+ } -+ declare const SomeConstructor3: { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. -+ (): void; -+ staticMember: string; -+ }; -+ declare namespace SomeConstructor3 { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. -+ const staticMember: string; -+ } -+ \ No newline at end of file + } \ 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 987b88bf81..3f3d6812d2 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -25,24 +25,15 @@ SelfReference.staticMember = "str"; //// [file.d.ts] declare const SomeConstructor: () => void; -declare const SomeConstructor2: { - (): void; - staticMember: string; -}; +declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { const staticMember: string; } -declare const SomeConstructor3: { - (): void; - staticMember: string; -}; +declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { const staticMember: string; } -declare const SelfReference: { - (): any; - staticMember: string; -}; +declare function SelfReference(): any; declare namespace SelfReference { const staticMember: string; } diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index dd631fa6b9..5fe9783c4c 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -8,21 +8,13 @@ -declare class SomeConstructor { - x: number; -} --declare function SomeConstructor2(): void; +declare const SomeConstructor: () => void; -+declare const SomeConstructor2: { -+ (): void; -+ staticMember: string; -+}; + declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { - let staticMember: string; + const staticMember: string; } --declare function SomeConstructor3(): void; -+declare const SomeConstructor3: { -+ (): void; -+ staticMember: string; -+}; + declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; @@ -33,10 +25,7 @@ -declare function SelfReference(): SelfReference; + const staticMember: string; +} -+declare const SelfReference: { -+ (): any; -+ staticMember: string; -+}; ++declare function SelfReference(): any; declare namespace SelfReference { - let staticMember_2: string; - export { staticMember_2 as staticMember }; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js index 7e381bd6b5..53e9d57f2a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -158,6 +158,34 @@ 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 { const prototype: { /** diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff index 7fa93121f0..914cb5c5ad 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff @@ -47,33 +47,24 @@ -} //// [context.d.ts] -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 -- */ ++export type Timer = import("./timer"); ++export type Hook = import("./hook"); ++export type HookHandler = import("./hook").HookHandler; ++export type Input = { ++ timer: Timer; ++ hook: Hook; ++}; ++export type State = { ++ timer: Timer; ++ hook: Hook; ++}; + /** + * Imports + * +@@= skipped -45, +45 lines =@@ + * @class + * @param {Input} input + */ -declare function Context(input: Input): Context; -declare class Context { - /** @@ -112,17 +103,7 @@ - */ - construct(input: Input, handle?: HookHandler | undefined): State; -} -+export type Timer = import("./timer"); -+export type Hook = import("./hook"); -+export type HookHandler = import("./hook").HookHandler; -+export type Input = { -+ timer: Timer; -+ hook: Hook; -+}; -+export type State = { -+ timer: Timer; -+ hook: Hook; -+}; ++declare function Context(input: Input): any; declare namespace Context { - export { Timer, Hook, HookHandler, Input, State }; + const prototype: { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index 70cb996f77..01e43ad077 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -34,6 +34,7 @@ MyClass.staticProperty = 123; //// [source.d.ts] export = MyClass; +declare function MyClass(): void; declare namespace MyClass { const staticMethod: () => void; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 20e65c384f..7274ab2e2f 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; -} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js index f277c8e7d3..0afdb29769 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -16,6 +16,7 @@ module.exports = foo; //// [index.d.ts] +declare function foo(): void; declare namespace foo { const foo: typeof import("."); } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff index 782b217755..b9981c3481 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff @@ -9,16 +9,16 @@ //// [index.d.ts] -+declare namespace foo { +-export = foo; + declare function foo(): void; + declare namespace foo { +- export { foo }; +- export { foo as default }; +-} + const foo: typeof import("."); +} +declare namespace foo { + const _a: typeof import("."); + export { _a as default }; +} - export = foo; --declare function foo(): void; --declare namespace foo { -- export { foo }; -- export { foo as default }; --} \ No newline at end of file ++export = foo; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js index 025c012e05..4848b43f5f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -65,6 +65,7 @@ export {}; declare class Base { constructor(); } +declare function BaseFactory(): Base; declare namespace BaseFactory { const Base: typeof Base; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff index f89d2090f4..05f083572e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -17,15 +17,15 @@ //// [base.d.ts] -export = BaseFactory; --declare function BaseFactory(): Base; --declare namespace BaseFactory { ++declare class Base { ++ constructor(); ++} + declare function BaseFactory(): Base; + declare namespace BaseFactory { - export { Base }; -} - declare class Base { +-declare class Base { -} -+ constructor(); -+} -+declare namespace BaseFactory { + const Base: typeof Base; +} +export = BaseFactory; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js index 032e62b85b..152f6ae9ea 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js @@ -53,6 +53,7 @@ export {}; declare class Base { constructor(); } +declare function BaseFactory(): Base; declare namespace BaseFactory { const Base: typeof Base; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff index 820e06b537..7a0c146d6c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff @@ -17,15 +17,15 @@ //// [base.d.ts] -export = BaseFactory; --declare function BaseFactory(): Base; --declare namespace BaseFactory { ++declare class Base { ++ constructor(); ++} + declare function BaseFactory(): Base; + declare namespace BaseFactory { - export { Base }; -} - declare class Base { +-declare class Base { -} -+ constructor(); -+} -+declare namespace BaseFactory { + const Base: typeof Base; +} +export = BaseFactory; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index 97c4e95c02..0724599f44 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -186,15 +186,7 @@ exports.default = Tree; //// [jsDeclarationsReactComponents1.d.ts] /// import PropTypes from "prop-types"; -declare const TabbedShowLayout: { - ({}: {}): JSX.Element; - propTypes: { - version: PropTypes.Requireable; - }; - defaultProps: { - tabs: undefined; - }; -}; +declare function TabbedShowLayout({}: {}): JSX.Element; declare namespace TabbedShowLayout { const propTypes: { version: PropTypes.Requireable; @@ -208,25 +200,13 @@ declare namespace TabbedShowLayout { 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 { const defaultProps: Partial<{}> | undefined; } export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] -/** - * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} - */ -declare const TabbedShowLayout: { - defaultProps: { - tabs: string; - }; -} & ((props?: { - elem: string; -}) => JSX.Element); +declare function TabbedShowLayout(): JSX.Element; declare namespace TabbedShowLayout { const defaultProps: { tabs: string; @@ -234,14 +214,9 @@ declare namespace TabbedShowLayout { } export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] -declare const TabbedShowLayout: { - (prop: { - className: string; - }): JSX.Element; - defaultProps: { - tabs: string; - }; -}; +declare function TabbedShowLayout(/** @type {{className: string}}*/ prop: { + className: string; +}): JSX.Element; declare namespace TabbedShowLayout { const defaultProps: { tabs: string; @@ -265,124 +240,3 @@ declare namespace Tree { }; } export default Tree; - - -//// [DtsFileErrors] - - -out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents1.d.ts(12,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents1.d.ts(17,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents2.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents3.d.ts(4,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents3.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents4.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -out/jsDeclarationsReactComponents4.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - - -==== out/jsDeclarationsReactComponents1.d.ts (3 errors) ==== - /// - import PropTypes from "prop-types"; - declare const TabbedShowLayout: { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - ({}: {}): JSX.Element; - propTypes: { - version: PropTypes.Requireable; - }; - defaultProps: { - tabs: undefined; - }; - }; - declare namespace TabbedShowLayout { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - const propTypes: { - version: PropTypes.Requireable; - }; - } - declare namespace TabbedShowLayout { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - const defaultProps: { - tabs: undefined; - }; - } - export default TabbedShowLayout; - -==== out/jsDeclarationsReactComponents2.d.ts (2 errors) ==== - import React from "react"; - /** - * @type {React.SFC} - */ - declare const TabbedShowLayout: React.SFC; - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - declare namespace TabbedShowLayout { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - const defaultProps: Partial<{}> | undefined; - } - export default TabbedShowLayout; - -==== out/jsDeclarationsReactComponents3.d.ts (2 errors) ==== - /** - * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} - */ - declare const TabbedShowLayout: { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - defaultProps: { - tabs: string; - }; - } & ((props?: { - elem: string; - }) => JSX.Element); - declare namespace TabbedShowLayout { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - const defaultProps: { - tabs: string; - }; - } - export default TabbedShowLayout; - -==== out/jsDeclarationsReactComponents4.d.ts (2 errors) ==== - declare const TabbedShowLayout: { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - (prop: { - className: string; - }): JSX.Element; - defaultProps: { - tabs: string; - }; - }; - declare namespace TabbedShowLayout { - ~~~~~~~~~~~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - const defaultProps: { - tabs: string; - }; - } - export default TabbedShowLayout; - -==== out/jsDeclarationsReactComponents5.d.ts (0 errors) ==== - import PropTypes from 'prop-types'; - declare function Tree({ allowDropOnRoot }: { - allowDropOnRoot: any; - }): JSX.Element; - declare namespace Tree { - const propTypes: { - classes: PropTypes.Requireable; - }; - } - declare namespace Tree { - const defaultProps: { - classes: {}; - parentSource: string; - }; - } - export default Tree; - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index a034a07f47..59c49d45a2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -64,15 +64,7 @@ - } -} import PropTypes from "prop-types"; -+declare const TabbedShowLayout: { -+ ({}: {}): JSX.Element; -+ propTypes: { -+ version: PropTypes.Requireable; -+ }; -+ defaultProps: { -+ tabs: undefined; -+ }; -+}; ++declare function TabbedShowLayout({}: {}): JSX.Element; +declare namespace TabbedShowLayout { + const propTypes: { + version: PropTypes.Requireable; @@ -91,42 +83,34 @@ - */ -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 { + const defaultProps: Partial<{}> | undefined; +} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] -export default TabbedShowLayout; - /** - * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} - */ -@@= skipped -30, +42 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 { + const defaultProps: { -+ tabs: string; -+ }; + tabs: string; + }; +-} & ((props?: { +- elem: string; +-}) => JSX.Element); +} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] -export default TabbedShowLayout; -declare function TabbedShowLayout(prop: { -- className: string; --}): JSX.Element; -+declare const TabbedShowLayout: { -+ (prop: { -+ className: string; -+ }): JSX.Element; -+ defaultProps: { -+ tabs: string; -+ }; -+}; ++declare function TabbedShowLayout(/** @type {{className: string}}*/ prop: { + className: string; + }): JSX.Element; declare namespace TabbedShowLayout { - namespace defaultProps { - let tabs: string; @@ -163,125 +147,4 @@ + parentSource: string; + }; +} -+export default Tree; -+ -+ -+//// [DtsFileErrors] -+ -+ -+out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents1.d.ts(12,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents1.d.ts(17,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents2.d.ts(6,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents3.d.ts(4,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents3.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents4.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+out/jsDeclarationsReactComponents4.d.ts(9,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ -+ -+==== out/jsDeclarationsReactComponents1.d.ts (3 errors) ==== -+ /// -+ import PropTypes from "prop-types"; -+ declare const TabbedShowLayout: { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ ({}: {}): JSX.Element; -+ propTypes: { -+ version: PropTypes.Requireable; -+ }; -+ defaultProps: { -+ tabs: undefined; -+ }; -+ }; -+ declare namespace TabbedShowLayout { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ const propTypes: { -+ version: PropTypes.Requireable; -+ }; -+ } -+ declare namespace TabbedShowLayout { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ const defaultProps: { -+ tabs: undefined; -+ }; -+ } -+ export default TabbedShowLayout; -+ -+==== out/jsDeclarationsReactComponents2.d.ts (2 errors) ==== -+ import React from "react"; -+ /** -+ * @type {React.SFC} -+ */ -+ declare const TabbedShowLayout: React.SFC; -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ declare namespace TabbedShowLayout { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ const defaultProps: Partial<{}> | undefined; -+ } -+ export default TabbedShowLayout; -+ -+==== out/jsDeclarationsReactComponents3.d.ts (2 errors) ==== -+ /** -+ * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} -+ */ -+ declare const TabbedShowLayout: { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ defaultProps: { -+ tabs: string; -+ }; -+ } & ((props?: { -+ elem: string; -+ }) => JSX.Element); -+ declare namespace TabbedShowLayout { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ const defaultProps: { -+ tabs: string; -+ }; -+ } -+ export default TabbedShowLayout; -+ -+==== out/jsDeclarationsReactComponents4.d.ts (2 errors) ==== -+ declare const TabbedShowLayout: { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ (prop: { -+ className: string; -+ }): JSX.Element; -+ defaultProps: { -+ tabs: string; -+ }; -+ }; -+ declare namespace TabbedShowLayout { -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ const defaultProps: { -+ tabs: string; -+ }; -+ } -+ export default TabbedShowLayout; -+ -+==== out/jsDeclarationsReactComponents5.d.ts (0 errors) ==== -+ import PropTypes from 'prop-types'; -+ declare function Tree({ allowDropOnRoot }: { -+ allowDropOnRoot: any; -+ }): JSX.Element; -+ declare namespace Tree { -+ const propTypes: { -+ classes: PropTypes.Requireable; -+ }; -+ } -+ declare namespace Tree { -+ const defaultProps: { -+ classes: {}; -+ parentSource: string; -+ }; -+ } -+ export default Tree; -+ \ No newline at end of file ++export default Tree; \ 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 d8cb78c6f8..addcac20cb 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -177,17 +177,7 @@ declare namespace ExpandoDecl { const m: (n: number) => number; } declare var n: number; -declare const ExpandoExpr: { - (n: number): string; - prop: { - x: number; - y?: undefined; - } | { - x?: undefined; - y: string; - }; - m: (n: number) => number; -}; +declare function ExpandoExpr(n: number): string; declare namespace ExpandoExpr { const prop: { x: number; @@ -210,11 +200,7 @@ declare namespace ExpandoExpr { const 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 { const prop: number; } diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index 44d8d51342..376ddaac95 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -37,20 +37,32 @@ declare namespace ExpandoDecl { - var prop: number; - var m: (n: number) => number; +-} +-declare var n: number; +-declare const ExpandoExpr: { +- (n: number): string; +- prop: { +- x: number; +- y?: undefined; +- } | { +- x?: undefined; +- y: string; +- }; +- m(n: number): number; +-}; +-declare var n: number; +-declare const ExpandoArrow: { +- (n: number): string; +- prop: number; +- m(n: number): number; +-}; + const prop: number; +} +declare namespace ExpandoDecl { + const m: (n: number) => number; - } - declare var n: number; - declare const ExpandoExpr: { -@@= skipped -13, +15 lines =@@ - x?: undefined; - y: string; - }; -- m(n: number): number; -+ m: (n: number) => number; - }; ++} ++declare var n: number; ++declare function ExpandoExpr(n: number): string; +declare namespace ExpandoExpr { + const prop: { + x: number; @@ -72,13 +84,8 @@ +declare namespace ExpandoExpr { + const m: (n: number) => number; +} - declare var n: number; - declare const ExpandoArrow: { - (n: number): string; - prop: number; -- m(n: number): number; -+ m: (n: number) => number; - }; ++declare var n: number; ++declare function ExpandoArrow(n: number): string; +declare namespace ExpandoArrow { + const prop: number; +} @@ -100,7 +107,7 @@ } declare namespace ExpandoMerge { var p2: number; -@@= skipped -28, +55 lines =@@ +@@= skipped -41, +56 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; From a67479902867a92e74d2e0491936ca495a2db473 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Tue, 7 Oct 2025 02:58:43 +0300 Subject: [PATCH 06/11] cleanup --- .../transformers/declarations/transform.go | 64 ++++++------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 191a68fae3..0f5b3843c4 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -27,14 +27,6 @@ type OutputPaths interface { JsFilePath() string } -type DeclareModifier uint8 - -const ( - DeclareModifierNone DeclareModifier = 0 - DeclareModifierEligible DeclareModifier = 1 - DeclareModifierEnforced DeclareModifier = 2 -) - // Used to be passed in the TransformationContext, which is now just an EmitContext type DeclarationEmitHost interface { modulespecifiers.ModuleSpecifierGenerationHost @@ -1860,6 +1852,8 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp } name := tx.Factory().NewIdentifier(ns.Text()) + tx.transformExpandoHost(name, declaration) + synthesizedNamespace := tx.Factory().NewModuleDeclaration(nil /*modifiers*/, ast.KindNamespaceKeyword, name, tx.Factory().NewModuleBlock(tx.Factory().NewNodeList([]*ast.Node{}))) synthesizedNamespace.Parent = tx.enclosingDeclaration @@ -1899,8 +1893,6 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp statements = append(statements, tx.Factory().NewExportDeclaration(nil /*modifiers*/, false /*isTypeOnly*/, namedExports, nil /*moduleSpecifier*/, nil /*attributes*/)) } - tx.transformExpandoHost(name, declaration) - flags := tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(declaration), ast.ModifierFlagsAll) modifierFlags := ast.ModifierFlagsAmbient @@ -1940,41 +1932,13 @@ func (tx *DeclarationTransformer) transformExpandoHost(name *ast.Node, declarati modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)) replacement := make([]*ast.Node, 0) - var typeParameters *ast.TypeParameterList - var parameters *ast.ParameterList - var returnType *ast.Node - var asteriskToken *ast.TokenNode - if ast.IsFunctionDeclaration(declaration) { - fn := declaration.AsFunctionDeclaration() - typeParameters = tx.ensureTypeParams(fn.AsNode(), fn.TypeParameters) - parameters = tx.updateParamList(fn.AsNode(), fn.Parameters) - returnType = tx.ensureType(fn.AsNode(), false) - asteriskToken = fn.AsteriskToken + 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()) { - if ast.IsFunctionExpression(declaration.Initializer()) { - fn := declaration.Initializer().AsFunctionExpression() - typeParameters = tx.ensureTypeParams(fn.AsNode(), fn.TypeParameters) - parameters = tx.updateParamList(fn.AsNode(), fn.Parameters) - returnType = tx.ensureType(fn.AsNode(), false) - asteriskToken = fn.AsteriskToken - } else if ast.IsArrowFunction(declaration.Initializer()) { - fn := declaration.Initializer().AsArrowFunction() - typeParameters = tx.ensureTypeParams(fn.AsNode(), fn.TypeParameters) - parameters = tx.updateParamList(fn.AsNode(), fn.Parameters) - returnType = tx.ensureType(fn.AsNode(), false) - asteriskToken = fn.AsteriskToken - } else { - return - } - } else { - return - } - - if ast.IsFunctionDeclaration(declaration) { - replacement = append(replacement, tx.Factory().UpdateFunctionDeclaration(root.AsFunctionDeclaration(), modifiers, asteriskToken, root.Name(), typeParameters, parameters, returnType, nil /*fullSignature*/, nil /*body*/)) - } else if ast.IsVariableDeclaration(declaration) { - replacement = append(replacement, tx.Factory().NewFunctionDeclaration(modifiers, asteriskToken, tx.Factory().NewIdentifier(name.Text()), typeParameters, parameters, returnType, nil /*fullSignature*/, nil /*body*/)) + 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 } @@ -1986,3 +1950,17 @@ func (tx *DeclarationTransformer) transformExpandoHost(name *ast.Node, declarati 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 + } +} From 90a1027c47a845910f5980e478742d051ef10778 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Thu, 9 Oct 2025 17:03:11 +0300 Subject: [PATCH 07/11] resolve element access property names --- internal/binder/referenceresolver.go | 13 ++++++ internal/checker/emitresolver.go | 12 ++++++ .../transformers/declarations/transform.go | 30 +++++++++----- .../declarationEmitLateBoundAssignments.js | 3 ++ ...eclarationEmitLateBoundAssignments.js.diff | 3 ++ .../declarationEmitLateBoundAssignments2.js | 22 ++++++---- ...clarationEmitLateBoundAssignments2.js.diff | 33 +++++++++++---- .../declarationEmitLateBoundJSAssignments.js | 3 ++ ...larationEmitLateBoundJSAssignments.js.diff | 3 ++ ...andoFunctionExpressionsWithDynamicNames.js | 16 ++++---- ...unctionExpressionsWithDynamicNames.js.diff | 22 +++++++++- .../typeFromPropertyAssignment39.js | 39 ++++++++++++++++++ .../typeFromPropertyAssignment39.js.diff | 41 ++++++++++++++++++- .../typeFromPrototypeAssignment4.js | 9 ++++ .../typeFromPrototypeAssignment4.js.diff | 10 ++++- 15 files changed, 221 insertions(+), 38 deletions(-) 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/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/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 0f5b3843c4..826904d855 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1826,18 +1826,13 @@ func (tx *DeclarationTransformer) visitExpressionStatement(node *ast.ExpressionS func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExpression) *ast.Node { left := node.Left - - if ast.IsElementAccessExpression(left) { - return nil - } - symbol := node.Symbol if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 { return nil } - ns := ast.GetFirstIdentifier(left) - if ns == nil { + ns := ast.GetLeftmostAccessExpression(left) + if ns == nil || ns.Kind != ast.KindIdentifier { return nil } @@ -1852,7 +1847,14 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp } name := tx.Factory().NewIdentifier(ns.Text()) + property := tx.tryGetPropertyName(left) + if property == "" || !scanner.IsIdentifierText(property, core.LanguageVariantStandard) { + return nil + } + tx.transformExpandoHost(name, declaration) + 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 @@ -1868,10 +1870,6 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp t := tx.resolver.CreateTypeOfExpression(tx.EmitContext(), left, synthesizedNamespace, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, tx.tracker) tx.state.getSymbolAccessibilityDiagnostic = saveDiag - nameToken := scanner.StringToToken(left.Name().Text()) - isNonContextualKeywordName := ast.IsNonContextualKeyword(nameToken) - - exportName := core.IfElse(isNonContextualKeywordName, tx.Factory().NewGeneratedNameForNode(left), tx.Factory().NewIdentifier(left.Name().Text())) statements := []*ast.Statement{ tx.Factory().NewVariableStatement( nil, /*modifiers*/ @@ -1964,3 +1962,13 @@ func extractExpandoHostParams(node *ast.Node) (typeParameters *ast.TypeParameter 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/submodule/compiler/declarationEmitLateBoundAssignments.js b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js index fb0ef42f69..21b530af50 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -39,3 +39,6 @@ export declare function foo(): void; export declare namespace foo { const bar: number; } +export declare namespace foo { + const strMemName: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 49d12959d1..16fcf29f8c 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff @@ -7,4 +7,7 @@ - var bar: number; - var strMemName: string; + const bar: number; ++} ++export declare namespace foo { ++ const 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..b85447af98 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 { + const B: string; +} export declare function decl2(): void; +export declare namespace decl2 { + const 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 { + const B: string; +} +export declare function arrow2(): void; +export declare namespace arrow2 { + const 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..e7f39e3425 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff @@ -1,16 +1,17 @@ --- old.declarationEmitLateBoundAssignments2.js +++ new.declarationEmitLateBoundAssignments2.js -@@= skipped -120, +120 lines =@@ - +@@= skipped -121, +121 lines =@@ //// [declarationEmitLateBoundAssignments2.d.ts] export declare function decl(): void; --export declare namespace decl { + export declare namespace decl { - var B: string; --} ++ const B: string; + } export declare function decl2(): void; --export declare namespace decl2 { + export declare namespace decl2 { - var C: number; --} ++ const C: number; + } export declare function decl3(): void; -export declare namespace decl3 { } export declare function decl4(): void; @@ -27,6 +28,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 { ++ const B: string; ++} ++export declare function arrow2(): void; ++export declare namespace arrow2 { ++ const 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 c344a36d03..e4f6b2f1b2 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -29,3 +29,6 @@ export declare function foo(): void; export declare namespace foo { const bar: number; } +export declare namespace foo { + const strMemName: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index be7cbb8a9a..338f9a32de 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -11,4 +11,7 @@ +export declare function foo(): void; +export declare namespace foo { + const bar: number; ++} ++export declare namespace foo { ++ const strMemName: string; } \ 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..c2a5813340 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 { + const X: number; +} +export declare function expr2(): void; +export declare namespace expr2 { + const X: number; +} diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff index 91ce438ddd..9b4f1660f1 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 { ++ const X: number; ++} ++export declare function expr2(): void; ++export declare namespace expr2 { ++ const X: number; ++} \ 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..ad20a595df 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 { + const baz: { + blah: number; + }; +} +declare namespace foo { + const 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'. + const baz: { + blah: number; + }; + } + declare namespace foo { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. + const 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..c783abb722 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 { ++ const baz: { ++ blah: number; ++ }; ++} ++declare namespace foo { ++ const 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'. ++ const baz: { ++ blah: number; ++ }; ++ } ++ declare namespace foo { ++ ~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. ++ const 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..4cee856754 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 { + const 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..db21e270df 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 { ++ const 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 From 5f6eb6eeb720773e2e9225a6e1fe6579401f6879 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Thu, 9 Oct 2025 18:43:15 +0300 Subject: [PATCH 08/11] exclude expando initializers --- .../transformers/declarations/transform.go | 6 ++++ ...arationEmitExpandoWithGenericConstraint.js | 8 ++--- ...onEmitExpandoWithGenericConstraint.js.diff | 17 ++++------ ...olatedDeclarationErrorsExpandoFunctions.js | 34 ++----------------- ...dDeclarationErrorsExpandoFunctions.js.diff | 34 ++----------------- .../commonJSImportNestedClassTypeReference.js | 7 ---- ...onJSImportNestedClassTypeReference.js.diff | 8 +---- .../conformance/jsDeclarationsClassMethod.js | 6 ---- .../jsDeclarationsClassMethod.js.diff | 13 ++++--- .../conformance/jsDeclarationsClassStatic.js | 3 -- .../jsDeclarationsClassStatic.js.diff | 10 ++---- .../jsDeclarationsFunctionPrototypeStatic.js | 3 -- ...eclarationsFunctionPrototypeStatic.js.diff | 11 ++---- .../conformance/jsDeclarationsFunctions.js | 5 --- .../jsDeclarationsFunctions.js.diff | 17 ++++------ .../conformance/jsdocImplements_class.js | 7 ---- .../conformance/jsdocImplements_class.js.diff | 25 +++++++------- .../typeFromPropertyAssignment29.js | 9 ----- .../typeFromPropertyAssignment29.js.diff | 11 +----- .../typeFromPropertyAssignment39.js | 15 +------- .../typeFromPropertyAssignment39.js.diff | 27 ++++----------- 21 files changed, 60 insertions(+), 216 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 826904d855..0a279fb86a 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1826,11 +1826,17 @@ func (tx *DeclarationTransformer) visitExpressionStatement(node *ast.ExpressionS func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExpression) *ast.Node { left := node.Left + right := node.Right + symbol := node.Symbol if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 { return nil } + if ast.IsExpandoInitializer(right) { + return nil + } + ns := ast.GetLeftmostAccessExpression(left) if ns == nil || ns.Kind != ast.KindIdentifier { return nil diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js index 4b03e9dfe2..02c1beb29a 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 function Point(x: number, y: number): Point; +export declare const Point: { + (x: number, y: number): Point; + zero: () => Point; +}; export declare const Rect:

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

; -export declare namespace Point { - const zero: () => Point; -} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff index 1b24394944..6b591946c6 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff @@ -1,15 +1,10 @@ --- old.declarationEmitExpandoWithGenericConstraint.js +++ new.declarationEmitExpandoWithGenericConstraint.js -@@= skipped -35, +35 lines =@@ - readonly a: p; - readonly b: p; +@@= skipped -37, +37 lines =@@ } --export declare const Point: { -- (x: number, y: number): Point; + 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 { -+ const zero: () => Point; -+} \ No newline at end of file ++ zero: () => Point; + }; + export declare const Rect:

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

; \ 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 9ebccc55c2..6754c359be 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -25,21 +25,6 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] export declare function foo(): void; -export declare namespace foo { - const apply: () => void; -} -export declare namespace foo { - const call: () => void; -} -export declare namespace foo { - const bind: () => void; -} -export declare namespace foo { - const caller: () => void; -} -export declare namespace foo { - const toString: () => void; -} export declare namespace foo { const length: number; } @@ -51,27 +36,12 @@ export declare namespace foo { //// [DtsFileErrors] -isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. -isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. +isolatedDeclarationErrorsExpandoFunctions.d.ts(3,11): error TS2451: Cannot redeclare block-scoped variable 'length'. +isolatedDeclarationErrorsExpandoFunctions.d.ts(6,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== export declare function foo(): void; - export declare namespace foo { - const apply: () => void; - } - export declare namespace foo { - const call: () => void; - } - export declare namespace foo { - const bind: () => void; - } - export declare namespace foo { - const caller: () => void; - } - export declare namespace foo { - const toString: () => void; - } export declare namespace foo { const length: number; ~~~~~~ diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff index e4a99a073a..8ae6d64ca7 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -9,21 +9,6 @@ +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] +export declare function foo(): void; +export declare namespace foo { -+ const apply: () => void; -+} -+export declare namespace foo { -+ const call: () => void; -+} -+export declare namespace foo { -+ const bind: () => void; -+} -+export declare namespace foo { -+ const caller: () => void; -+} -+export declare namespace foo { -+ const toString: () => void; -+} -+export declare namespace foo { + const length: number; +} +export declare namespace foo { @@ -34,28 +19,13 @@ +//// [DtsFileErrors] + + -+isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. -+isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ++isolatedDeclarationErrorsExpandoFunctions.d.ts(3,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ++isolatedDeclarationErrorsExpandoFunctions.d.ts(6,11): error TS2451: Cannot redeclare block-scoped variable 'length'. + + +==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== + export declare function foo(): void; + export declare namespace foo { -+ const apply: () => void; -+ } -+ export declare namespace foo { -+ const call: () => void; -+ } -+ export declare namespace foo { -+ const bind: () => void; -+ } -+ export declare namespace foo { -+ const caller: () => void; -+ } -+ export declare namespace foo { -+ const toString: () => void; -+ } -+ export declare namespace foo { + const length: number; + ~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'length'. diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js index b362e8a78c..7334c82bde 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js @@ -38,13 +38,6 @@ function f(k) { //// [mod1.d.ts] -declare namespace NS { - const 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 ec0cdbeade..7951efe1d6 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff @@ -22,14 +22,8 @@ -export var K: { - new (): { - values(): /*elided*/ any; -+declare namespace NS { -+ const K: { -+ new (): { -+ values(): /*elided*/ any; -+ }; - }; +- }; -}; -+} +export var K = NS.K; +export {}; //// [main.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js index 8483569d1c..291c26285d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js @@ -129,9 +129,6 @@ C2.staticProp = function (x, y) { //// [jsDeclarationsClassMethod.d.ts] declare function C1(): void; -declare namespace C1 { - const staticProp: (x: any, y: any) => any; -} declare class C2 { /** * A comment method1 @@ -141,6 +138,3 @@ declare class C2 { */ method1(x: number, y: number): number; } -declare namespace C2 { - const 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 f248ddecfb..1520c1ddf2 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; -+ const staticProp: (x: any, y: any) => any; - } +-} declare class C2 { /** -@@= skipped -33, +11 lines =@@ + * A comment method1 +@@= skipped -33, +8 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,5 +52,4 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; -+ const 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 85037752df..7b130e681b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -52,9 +52,6 @@ module.exports.Strings = Strings; //// [source.d.ts] -declare namespace Handler { - const 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 4dbe14ad55..7b335ba61e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -19,16 +19,15 @@ module.exports.Strings = Strings; /** * @typedef {Object} HandlerOptions -@@= skipped -10, +12 lines =@@ - +@@= skipped -11, +13 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; @@ -41,9 +40,6 @@ - * Should be able to export a type alias at the same time. - */ - name: string; -+ const statische: () => void; -+} -+export = Handler; +export var Strings = Strings; +export type HandlerOptions = { + name: String; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index 01e43ad077..a562e6f4ac 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -35,9 +35,6 @@ MyClass.staticProperty = 123; //// [source.d.ts] export = MyClass; declare function MyClass(): void; -declare namespace MyClass { - const staticMethod: () => void; -} declare namespace MyClass { const staticProperty: number; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 7274ab2e2f..5b95761835 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -17,17 +17,12 @@ -declare class MyClass { - method(): void; -} --declare namespace MyClass { + declare namespace MyClass { - export { staticMethod, staticProperty, DoneCB }; --} ++ const staticProperty: number; + } -declare function staticMethod(): void; -declare var staticProperty: number; -+declare namespace MyClass { -+ const staticMethod: () => void; -+} -+declare namespace MyClass { -+ const staticProperty: number; -+} +export type DoneCB = (failures: number) ; /** * Callback to be invoked when test execution is complete. diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js index 3344f4abd7..32f41204ac 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -127,11 +127,6 @@ export declare namespace b { const cat: string; } export declare function c(): void; -export declare namespace c { - const Cls: { - new (): {}; - }; -} /** * @param {number} a * @param {number} b diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 5f33df2f7a..74d48f4125 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -25,20 +25,17 @@ -export function b(): void; -export namespace b { - let cat: string; +-} +-export function c(): void; +-export namespace c { +- export { Cls }; +-} +export declare function a(): void; +export declare function b(): void; +export declare namespace b { + const cat: string; - } --export function c(): void; --export namespace c { -- export { Cls }; ++} +export declare function c(): void; -+export declare namespace c { -+ const Cls: { -+ new (): {}; -+ }; - } /** * @param {number} a * @param {number} b @@ -85,7 +82,7 @@ /** * @param {{x: string}} a * @param {{y: typeof b}} b -@@= skipped -50, +49 lines =@@ +@@= skipped -50, +44 lines =@@ declare function hh(a: { x: string; }, b: { diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js index 2b53e12e04..931649231b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js @@ -83,13 +83,6 @@ declare var Ns: { /** @implements {A} */ C5: any; }; -declare namespace Ns { - const C1: { - new (): { - method(): number; - }; - }; -} /** @implements {A} */ declare var C2: { new (): { diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff index 4aa7dcf871..49cdad5368 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff @@ -4,24 +4,23 @@ /** @implements {A} */ declare class B3 implements A { } +-declare namespace Ns { +- export { C1 }; +- export let C5: { +declare var Ns: { + /** @implements {A} */ + C1: { -+ new (): { -+ method(): number; -+ }; -+ }; -+ /** @implements {A} */ -+ C5: any; -+}; - declare namespace Ns { -- export { C1 }; -- export let C5: { -+ const C1: { new (): { method(): number; }; -@@= skipped -14, +23 lines =@@ + }; +-} ++ /** @implements {A} */ ++ C5: any; ++}; + /** @implements {A} */ + declare var C2: { + new (): { method(): number; }; }; @@ -39,7 +38,7 @@ declare class CC { /** @implements {A} */ C4: { -@@= skipped -12, +17 lines =@@ +@@= skipped -26, +33 lines =@@ }; } declare var C5: any; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js index addcac20cb..85d0d07f48 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -173,9 +173,6 @@ declare function ExpandoDecl(n: number): string; declare namespace ExpandoDecl { const prop: number; } -declare namespace ExpandoDecl { - const m: (n: number) => number; -} declare var n: number; declare function ExpandoExpr(n: number): string; declare namespace ExpandoExpr { @@ -196,17 +193,11 @@ declare namespace ExpandoExpr { y: string; }; } -declare namespace ExpandoExpr { - const m: (n: number) => number; -} declare var n: number; declare function ExpandoArrow(n: number): string; declare namespace ExpandoArrow { const prop: number; } -declare namespace ExpandoArrow { - const m: (n: number) => number; -} declare function ExpandoNested(n: number): { (m: number): number; total: number; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index 376ddaac95..c9ac5651d8 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -58,9 +58,6 @@ -}; + const prop: number; +} -+declare namespace ExpandoDecl { -+ const m: (n: number) => number; -+} +declare var n: number; +declare function ExpandoExpr(n: number): string; +declare namespace ExpandoExpr { @@ -81,16 +78,10 @@ + y: string; + }; +} -+declare namespace ExpandoExpr { -+ const m: (n: number) => number; -+} +declare var n: number; +declare function ExpandoArrow(n: number): string; +declare namespace ExpandoArrow { + const prop: number; -+} -+declare namespace ExpandoArrow { -+ const m: (n: number) => number; +} declare function ExpandoNested(n: number): { (m: number): number; @@ -107,7 +98,7 @@ } declare namespace ExpandoMerge { var p2: number; -@@= skipped -41, +56 lines =@@ +@@= skipped -41, +47 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js index ad20a595df..214dbd24c9 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js @@ -14,11 +14,6 @@ declare const foo: { blah: number; }; }; -declare namespace foo { - const baz: { - blah: number; - }; -} declare namespace foo { const blah: number; } @@ -29,10 +24,9 @@ declare namespace foo { 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) ==== +==== a.d.ts (2 errors) ==== declare const foo: { ~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'foo'. @@ -42,13 +36,6 @@ a.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'foo'. }; declare namespace foo { ~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. - const baz: { - blah: number; - }; - } - declare namespace foo { - ~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'foo'. const blah: number; } diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff index c783abb722..b3aea003b5 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff @@ -4,24 +4,17 @@ //// [a.d.ts] --declare namespace foo { -- namespace baz { -- let blah: number; -- } --} +declare const foo: { + baz: { + blah: number; + }; +}; -+declare namespace foo { -+ const baz: { -+ blah: number; -+ }; -+} -+declare namespace foo { + declare namespace foo { +- namespace baz { +- let blah: number; +- } + const blah: number; -+} + } + + +//// [DtsFileErrors] @@ -29,10 +22,9 @@ + +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) ==== ++==== a.d.ts (2 errors) ==== + declare const foo: { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. @@ -43,13 +35,6 @@ + declare namespace foo { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. -+ const baz: { -+ blah: number; -+ }; -+ } -+ declare namespace foo { -+ ~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. + const blah: number; + } + \ No newline at end of file From ff68b7acecb1182e99020c292acf325044c86460 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Thu, 9 Oct 2025 20:22:40 +0300 Subject: [PATCH 09/11] deduplicate emitted namespaces --- .../transformers/declarations/transform.go | 12 ++-- .../declarationEmitLateBoundAssignments2.js | 16 ++--- ...clarationEmitLateBoundAssignments2.js.diff | 20 +----- ...andoFunctionExpressionsWithDynamicNames.js | 16 ++--- ...unctionExpressionsWithDynamicNames.js.diff | 22 +------ .../compiler/isolatedDeclarationErrors.js | 16 ++--- .../isolatedDeclarationErrors.js.diff | 16 ++--- ...olatedDeclarationErrorsExpandoFunctions.js | 34 +++++++++- ...dDeclarationErrorsExpandoFunctions.js.diff | 34 +++++++++- .../jsDeclarationsGlobalFileConstFunction.js | 16 ++--- ...eclarationsGlobalFileConstFunction.js.diff | 24 ++++--- ...eclarationsGlobalFileConstFunctionNamed.js | 24 +++---- ...ationsGlobalFileConstFunctionNamed.js.diff | 33 ++++++---- .../commonJSImportNestedClassTypeReference.js | 7 ++ ...onJSImportNestedClassTypeReference.js.diff | 8 ++- .../conformance/jsDeclarationsClassMethod.js | 6 ++ .../jsDeclarationsClassMethod.js.diff | 13 ++-- .../conformance/jsDeclarationsClassStatic.js | 3 + .../jsDeclarationsClassStatic.js.diff | 10 ++- .../jsDeclarationsFunctionPrototypeStatic.js | 3 + ...eclarationsFunctionPrototypeStatic.js.diff | 11 +++- .../conformance/jsDeclarationsFunctions.js | 5 ++ .../jsDeclarationsFunctions.js.diff | 17 +++-- .../jsDeclarationsReactComponents.js | 44 +++++++------ .../jsDeclarationsReactComponents.js.diff | 64 +++++++++--------- .../conformance/jsdocImplements_class.js | 3 - .../conformance/jsdocImplements_class.js.diff | 4 +- .../typeFromPropertyAssignment29.js | 30 ++++----- .../typeFromPropertyAssignment29.js.diff | 65 ++++++------------- .../typeFromPropertyAssignment39.js | 26 -------- .../typeFromPropertyAssignment39.js.diff | 36 ++-------- 31 files changed, 316 insertions(+), 322 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 0a279fb86a..0335133f52 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1826,17 +1826,12 @@ func (tx *DeclarationTransformer) visitExpressionStatement(node *ast.ExpressionS func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExpression) *ast.Node { left := node.Left - right := node.Right symbol := node.Symbol if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 { return nil } - if ast.IsExpandoInitializer(right) { - return nil - } - ns := ast.GetLeftmostAccessExpression(left) if ns == nil || ns.Kind != ast.KindIdentifier { return nil @@ -1847,6 +1842,13 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp return nil } + if ast.IsVariableDeclaration(declaration) { + id := ast.GetNodeId(tx.EmitContext().MostOriginal(declaration.Parent.Parent)) + if tx.lateStatementReplacementMap[id] != nil { + return nil + } + } + host := declaration.Symbol() if host == nil { return nil diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js index b85447af98..1a9f9ad05e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js @@ -136,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 function arrow(): void; -export declare namespace arrow { - const B: string; -} -export declare function arrow2(): void; -export declare namespace arrow2 { - const C: number; -} +export declare const arrow: { + (): void; + B: string; +}; +export declare const arrow2: { + (): void; + 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 e7f39e3425..07b2d0a35e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff @@ -28,22 +28,6 @@ -export declare namespace decl9 { } export declare function decl10(): void; -export declare namespace decl10 { } --export declare const arrow: { -- (): void; -- B: string; --}; --export declare const arrow2: { -- (): void; -- C: number; --}; -+export declare function arrow(): void; -+export declare namespace arrow { -+ const B: string; -+} -+export declare function arrow2(): void; -+export declare namespace arrow2 { -+ const C: number; -+} - export declare const arrow3: { + export declare const arrow: { (): void; - 77: number; \ No newline at end of file + B: string; \ 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 c2a5813340..984cc06333 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 function expr(): void; -export declare namespace expr { - const X: number; -} -export declare function expr2(): void; -export declare namespace expr2 { - const X: number; -} +export declare const expr: { + (): void; + X: number; +}; +export declare const expr2: { + (): void; + X: number; +}; diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff index 9b4f1660f1..91ce438ddd 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff @@ -10,24 +10,4 @@ +// https://github.com/microsoft/TypeScript/issues/54809 const s = "X"; const expr = () => { }; - 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 { -+ const X: number; -+} -+export declare function expr2(): void; -+export declare namespace expr2 { -+ const X: number; -+} \ No newline at end of file + exports.expr = expr; \ 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 5ed2dbdd7a..9e65f05947 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -25,11 +25,11 @@ declare function errorOnAssignmentBelowDecl(): void; declare namespace errorOnAssignmentBelowDecl { const a: string; } -declare function errorOnAssignmentBelow(): void; -declare namespace errorOnAssignmentBelow { - const a: string; -} -declare function errorOnMissingReturn(): void; -declare namespace errorOnMissingReturn { - const a: string; -} +declare const errorOnAssignmentBelow: { + (): void; + a: string; +}; +declare const errorOnMissingReturn: { + (): void; + a: string; +}; diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index 972f69be1f..2422cce86d 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -11,11 +11,11 @@ +declare namespace errorOnAssignmentBelowDecl { + const a: string; +} -+declare function errorOnAssignmentBelow(): void; -+declare namespace errorOnAssignmentBelow { -+ const a: string; -+} -+declare function errorOnMissingReturn(): void; -+declare namespace errorOnMissingReturn { -+ const a: string; -+} \ No newline at end of file ++declare const errorOnAssignmentBelow: { ++ (): void; ++ a: string; ++}; ++declare const errorOnMissingReturn: { ++ (): void; ++ 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 6754c359be..9ebccc55c2 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -25,6 +25,21 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] export declare function foo(): void; +export declare namespace foo { + const apply: () => void; +} +export declare namespace foo { + const call: () => void; +} +export declare namespace foo { + const bind: () => void; +} +export declare namespace foo { + const caller: () => void; +} +export declare namespace foo { + const toString: () => void; +} export declare namespace foo { const length: number; } @@ -36,12 +51,27 @@ export declare namespace foo { //// [DtsFileErrors] -isolatedDeclarationErrorsExpandoFunctions.d.ts(3,11): error TS2451: Cannot redeclare block-scoped variable 'length'. -isolatedDeclarationErrorsExpandoFunctions.d.ts(6,11): error TS2451: Cannot redeclare block-scoped variable 'length'. +isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. +isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== export declare function foo(): void; + export declare namespace foo { + const apply: () => void; + } + export declare namespace foo { + const call: () => void; + } + export declare namespace foo { + const bind: () => void; + } + export declare namespace foo { + const caller: () => void; + } + export declare namespace foo { + const toString: () => void; + } export declare namespace foo { const length: number; ~~~~~~ diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff index 8ae6d64ca7..e4a99a073a 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -9,6 +9,21 @@ +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] +export declare function foo(): void; +export declare namespace foo { ++ const apply: () => void; ++} ++export declare namespace foo { ++ const call: () => void; ++} ++export declare namespace foo { ++ const bind: () => void; ++} ++export declare namespace foo { ++ const caller: () => void; ++} ++export declare namespace foo { ++ const toString: () => void; ++} ++export declare namespace foo { + const length: number; +} +export declare namespace foo { @@ -19,13 +34,28 @@ +//// [DtsFileErrors] + + -+isolatedDeclarationErrorsExpandoFunctions.d.ts(3,11): error TS2451: Cannot redeclare block-scoped variable 'length'. -+isolatedDeclarationErrorsExpandoFunctions.d.ts(6,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ++isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ++isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. + + +==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== + export declare function foo(): void; + export declare namespace foo { ++ const apply: () => void; ++ } ++ export declare namespace foo { ++ const call: () => void; ++ } ++ export declare namespace foo { ++ const bind: () => void; ++ } ++ export declare namespace foo { ++ const caller: () => void; ++ } ++ export declare namespace foo { ++ const toString: () => void; ++ } ++ export declare namespace foo { + const length: number; + ~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'length'. diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js index 4c5b98723d..9d4cfaead5 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 function SomeConstructor2(): void; -declare namespace SomeConstructor2 { - const staticMember: string; -} -declare function SomeConstructor3(): void; -declare namespace SomeConstructor3 { - const staticMember: string; -} +declare const SomeConstructor2: { + (): void; + staticMember: string; +}; +declare const SomeConstructor3: { + (): void; + staticMember: string; +}; diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index f2e19a6a71..171c3332a5 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -8,18 +8,24 @@ -declare class SomeConstructor { - x: number; -} -+declare const SomeConstructor: () => void; - declare function SomeConstructor2(): void; - declare namespace SomeConstructor2 { +-declare function SomeConstructor2(): void; +-declare namespace SomeConstructor2 { - let staticMember: string; -+ const staticMember: string; - } - declare function SomeConstructor3(): void; - declare namespace SomeConstructor3 { +-} +-declare function SomeConstructor3(): void; +-declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} -declare class SomeConstructor3 { - x: number; -+ const staticMember: string; - } \ No newline at end of file +-} ++declare const SomeConstructor: () => void; ++declare const SomeConstructor2: { ++ (): void; ++ staticMember: string; ++}; ++declare const SomeConstructor3: { ++ (): void; ++ 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 3f3d6812d2..b4b7986cec 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 function SomeConstructor2(): void; -declare namespace SomeConstructor2 { - const staticMember: string; -} -declare function SomeConstructor3(): void; -declare namespace SomeConstructor3 { - const staticMember: string; -} -declare function SelfReference(): any; -declare namespace SelfReference { - const staticMember: string; -} +declare const SomeConstructor2: { + (): void; + staticMember: string; +}; +declare const SomeConstructor3: { + (): void; + staticMember: string; +}; +declare const SelfReference: { + (): any; + staticMember: string; +}; diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 5fe9783c4c..3b57bcf92d 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -8,14 +8,12 @@ -declare class SomeConstructor { - x: number; -} -+declare const SomeConstructor: () => void; - declare function SomeConstructor2(): void; - declare namespace SomeConstructor2 { +-declare function SomeConstructor2(): void; +-declare namespace SomeConstructor2 { - let staticMember: string; -+ const staticMember: string; - } - declare function SomeConstructor3(): void; - declare namespace SomeConstructor3 { +-} +-declare function SomeConstructor3(): void; +-declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} @@ -23,14 +21,23 @@ - x: number; -} -declare function SelfReference(): SelfReference; -+ const staticMember: string; -+} -+declare function SelfReference(): any; - declare namespace SelfReference { +-declare namespace SelfReference { - let staticMember_2: string; - export { staticMember_2 as staticMember }; -} -declare class SelfReference { - x: number; -+ const staticMember: string; - } \ No newline at end of file +-} ++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 diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js index 7334c82bde..b362e8a78c 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 { + const 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..ec0cdbeade 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 { ++ const K: { ++ new (): { ++ values(): /*elided*/ any; ++ }; + }; -}; ++} +export var K = NS.K; +export {}; //// [main.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js index 291c26285d..8483569d1c 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 { + const 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 { + const 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..f248ddecfb 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; --} ++ const 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; ++ const 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..85037752df 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 { + const 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..4dbe14ad55 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; ++ const statische: () => void; ++} ++export = Handler; +export var Strings = Strings; +export type HandlerOptions = { + name: String; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index a562e6f4ac..01e43ad077 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -35,6 +35,9 @@ MyClass.staticProperty = 123; //// [source.d.ts] export = MyClass; declare function MyClass(): void; +declare namespace MyClass { + const staticMethod: () => void; +} declare namespace MyClass { const staticProperty: number; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 5b95761835..7274ab2e2f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -17,12 +17,17 @@ -declare class MyClass { - method(): void; -} - declare namespace MyClass { +-declare namespace MyClass { - export { staticMethod, staticProperty, DoneCB }; -+ const staticProperty: number; - } +-} -declare function staticMethod(): void; -declare var staticProperty: number; ++declare namespace MyClass { ++ const staticMethod: () => void; ++} ++declare namespace MyClass { ++ const staticProperty: number; ++} +export type DoneCB = (failures: number) ; /** * Callback to be invoked when test execution is complete. diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js index 32f41204ac..3344f4abd7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -127,6 +127,11 @@ export declare namespace b { const cat: string; } export declare function c(): void; +export declare namespace c { + const Cls: { + new (): {}; + }; +} /** * @param {number} a * @param {number} b diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 74d48f4125..5f33df2f7a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -25,17 +25,20 @@ -export function b(): void; -export namespace b { - let cat: string; --} --export function c(): void; --export namespace c { -- export { Cls }; --} +export declare function a(): void; +export declare function b(): void; +export declare namespace b { + const cat: string; -+} + } +-export function c(): void; +-export namespace c { +- export { Cls }; +export declare function c(): void; ++export declare namespace c { ++ const Cls: { ++ new (): {}; ++ }; + } /** * @param {number} a * @param {number} b @@ -82,7 +85,7 @@ /** * @param {{x: string}} a * @param {{y: typeof b}} b -@@= skipped -50, +44 lines =@@ +@@= skipped -50, +49 lines =@@ declare function hh(a: { x: string; }, b: { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index 0724599f44..e70d8273b6 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -186,42 +186,44 @@ exports.default = Tree; //// [jsDeclarationsReactComponents1.d.ts] /// import PropTypes from "prop-types"; -declare function TabbedShowLayout({}: {}): JSX.Element; -declare namespace TabbedShowLayout { - const propTypes: { +declare const TabbedShowLayout: { + ({}: {}): JSX.Element; + propTypes: { version: PropTypes.Requireable; }; -} -declare namespace TabbedShowLayout { - const defaultProps: { + defaultProps: { tabs: undefined; }; -} +}; export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.d.ts] import React from "react"; -declare function TabbedShowLayout(): JSX.Element; -declare namespace TabbedShowLayout { - const defaultProps: Partial<{}> | undefined; -} +/** + * @type {React.SFC} + */ +declare const TabbedShowLayout: React.SFC; export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] -declare function TabbedShowLayout(): JSX.Element; -declare namespace TabbedShowLayout { - const defaultProps: { +/** + * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} + */ +declare const TabbedShowLayout: { + defaultProps: { tabs: string; }; -} +} & ((props?: { + elem: string; +}) => JSX.Element); export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] -declare function TabbedShowLayout(/** @type {{className: string}}*/ prop: { - className: string; -}): JSX.Element; -declare namespace TabbedShowLayout { - const defaultProps: { +declare const TabbedShowLayout: { + (prop: { + className: string; + }): JSX.Element; + defaultProps: { tabs: string; }; -} +}; export default TabbedShowLayout; //// [jsDeclarationsReactComponents5.d.ts] import PropTypes from 'prop-types'; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index 59c49d45a2..aa2a571506 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -64,17 +64,15 @@ - } -} import PropTypes from "prop-types"; -+declare function TabbedShowLayout({}: {}): JSX.Element; -+declare namespace TabbedShowLayout { -+ const propTypes: { ++declare const TabbedShowLayout: { ++ ({}: {}): JSX.Element; ++ propTypes: { + version: PropTypes.Requireable; + }; -+} -+declare namespace TabbedShowLayout { -+ const defaultProps: { ++ defaultProps: { + tabs: undefined; + }; -+} ++}; +export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.d.ts] -export default TabbedShowLayout; @@ -83,43 +81,39 @@ - */ -declare const TabbedShowLayout: React.SFC; import React from "react"; -+declare function TabbedShowLayout(): JSX.Element; -+declare namespace TabbedShowLayout { -+ const defaultProps: Partial<{}> | undefined; -+} ++/** ++ * @type {React.SFC} ++ */ ++declare const TabbedShowLayout: React.SFC; +export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] -export default TabbedShowLayout; --/** -- * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} -- */ --declare const TabbedShowLayout: { -- defaultProps: { -+declare function TabbedShowLayout(): JSX.Element; -+declare namespace TabbedShowLayout { -+ const defaultProps: { - tabs: string; - }; --} & ((props?: { -- elem: string; --}) => JSX.Element); -+} + /** + * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} + */ +@@= skipped -30, +29 lines =@@ + } & ((props?: { + elem: string; + }) => JSX.Element); +export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.d.ts] --export default TabbedShowLayout; ++declare const TabbedShowLayout: { ++ (prop: { ++ className: string; ++ }): JSX.Element; ++ defaultProps: { ++ tabs: string; ++ }; ++}; + export default TabbedShowLayout; -declare function TabbedShowLayout(prop: { -+declare function TabbedShowLayout(/** @type {{className: string}}*/ prop: { - className: string; - }): JSX.Element; - declare namespace TabbedShowLayout { +- className: string; +-}): JSX.Element; +-declare namespace TabbedShowLayout { - namespace defaultProps { - let tabs: string; - } -+ const defaultProps: { -+ tabs: string; -+ }; - } -+export default TabbedShowLayout; +-} //// [jsDeclarationsReactComponents5.d.ts] -export default Tree; +import PropTypes from 'prop-types'; diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js index 931649231b..83f4b967b4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js @@ -106,6 +106,3 @@ declare class CC { }; } declare var C5: any; -declare namespace Ns { - const 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 49cdad5368..97a55138f3 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff @@ -47,6 +47,4 @@ -} -declare class C3 implements A { - method(): number; -+declare namespace Ns { -+ const C5: any; - } \ No newline at end of file +-} \ 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 85d0d07f48..b01799aa79 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -173,31 +173,27 @@ declare function ExpandoDecl(n: number): string; declare namespace ExpandoDecl { const prop: number; } -declare var n: number; -declare function ExpandoExpr(n: number): string; -declare namespace ExpandoExpr { - const prop: { - x: number; - y?: undefined; - } | { - x?: undefined; - y: string; - }; +declare namespace ExpandoDecl { + const m: (n: number) => number; } -declare namespace ExpandoExpr { - const prop: { +declare var n: number; +declare const ExpandoExpr: { + (n: number): string; + prop: { x: number; y?: undefined; } | { x?: undefined; y: string; }; -} + m: (n: number) => number; +}; declare var n: number; -declare function ExpandoArrow(n: number): string; -declare namespace ExpandoArrow { - const prop: number; -} +declare const ExpandoArrow: { + (n: number): string; + prop: number; + m: (n: number) => number; +}; declare function ExpandoNested(n: number): { (m: number): number; total: number; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index c9ac5651d8..168f9751a7 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -37,52 +37,27 @@ declare namespace ExpandoDecl { - var prop: number; - var m: (n: number) => number; --} --declare var n: number; --declare const ExpandoExpr: { -- (n: number): string; -- prop: { -- x: number; -- y?: undefined; -- } | { -- x?: undefined; -- y: string; -- }; -- m(n: number): number; --}; --declare var n: number; --declare const ExpandoArrow: { -- (n: number): string; -- prop: number; -- m(n: number): number; --}; -+ const prop: number; -+} -+declare var n: number; -+declare function ExpandoExpr(n: number): string; -+declare namespace ExpandoExpr { -+ const prop: { -+ x: number; -+ y?: undefined; -+ } | { -+ x?: undefined; -+ y: string; -+ }; -+} -+declare namespace ExpandoExpr { -+ const prop: { -+ x: number; -+ y?: undefined; -+ } | { -+ x?: undefined; -+ y: string; -+ }; -+} -+declare var n: number; -+declare function ExpandoArrow(n: number): string; -+declare namespace ExpandoArrow { + const prop: number; +} ++declare namespace ExpandoDecl { ++ const m: (n: number) => number; + } + declare var n: number; + declare const ExpandoExpr: { +@@= skipped -13, +15 lines =@@ + x?: undefined; + y: string; + }; +- m(n: number): number; ++ m: (n: number) => number; + }; + declare var n: number; + declare const ExpandoArrow: { + (n: number): string; + prop: number; +- m(n: number): number; ++ m: (n: number) => number; + }; declare function ExpandoNested(n: number): { (m: number): number; total: number; @@ -98,7 +73,7 @@ } declare namespace ExpandoMerge { var p2: number; -@@= skipped -41, +47 lines =@@ +@@= skipped -28, +28 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js index 214dbd24c9..3c3d0d693b 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js @@ -14,29 +14,3 @@ declare const foo: { blah: number; }; }; -declare namespace foo { - const 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 (2 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'. - const 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 b3aea003b5..aac1514602 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff @@ -4,37 +4,13 @@ //// [a.d.ts] -+declare const foo: { -+ baz: { -+ blah: number; -+ }; -+}; - declare namespace foo { +-declare namespace foo { - namespace baz { - let blah: number; - } -+ const 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 (2 errors) ==== -+ declare const foo: { -+ ~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. -+ baz: { -+ blah: number; -+ }; +-} ++declare const foo: { ++ baz: { ++ blah: number; + }; -+ declare namespace foo { -+ ~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. -+ const blah: number; -+ } -+ \ No newline at end of file ++}; \ No newline at end of file From fb94aa24a2f4bd9e787430bc4510ccb96d591f51 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Thu, 9 Oct 2025 23:46:20 +0300 Subject: [PATCH 10/11] skip emitting function properties --- .../transformers/declarations/transform.go | 12 ++-- ...arationEmitExpandoWithGenericConstraint.js | 8 +-- ...onEmitExpandoWithGenericConstraint.js.diff | 17 +++-- ...clarationEmitFunctionDuplicateNamespace.js | 3 - ...tionEmitFunctionDuplicateNamespace.js.diff | 8 +-- .../declarationEmitLateBoundAssignments2.js | 16 ++--- ...clarationEmitLateBoundAssignments2.js.diff | 20 +++++- ...andoFunctionExpressionsWithDynamicNames.js | 16 ++--- ...unctionExpressionsWithDynamicNames.js.diff | 22 +++++- .../compiler/isolatedDeclarationErrors.js | 16 ++--- .../isolatedDeclarationErrors.js.diff | 16 ++--- .../jsDeclarationsGlobalFileConstFunction.js | 16 ++--- ...eclarationsGlobalFileConstFunction.js.diff | 24 +++---- ...eclarationsGlobalFileConstFunctionNamed.js | 24 +++---- ...ationsGlobalFileConstFunctionNamed.js.diff | 33 ++++----- .../jsDeclarationsReactComponents.js | 44 ++++++------ .../jsDeclarationsReactComponents.js.diff | 64 +++++++++-------- .../conformance/jsdocImplements_class.js | 10 +++ .../conformance/jsdocImplements_class.js.diff | 29 ++++---- .../typeFromPropertyAssignment29.js | 33 ++++++--- .../typeFromPropertyAssignment29.js.diff | 70 ++++++++++++++----- .../typeFromPropertyAssignment39.js | 39 +++++++++++ .../typeFromPropertyAssignment39.js.diff | 41 ++++++++++- 23 files changed, 373 insertions(+), 208 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 0335133f52..d8858d38cc 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1842,13 +1842,6 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp return nil } - if ast.IsVariableDeclaration(declaration) { - id := ast.GetNodeId(tx.EmitContext().MostOriginal(declaration.Parent.Parent)) - if tx.lateStatementReplacementMap[id] != nil { - return nil - } - } - host := declaration.Symbol() if host == nil { return nil @@ -1861,6 +1854,11 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp } 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)) diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js index 02c1beb29a..4b03e9dfe2 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 { + const zero: () => Point; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff index 6b591946c6..1b24394944 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 { ++ const zero: () => Point; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js index 4d3c363b4c..0fd62effd0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js @@ -20,6 +20,3 @@ f.x = 2; //// [declarationEmitFunctionDuplicateNamespace.d.ts] declare function f(a: 0): 0; declare function f(a: 1): 1; -declare namespace f { - const x: number; -} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff index 7e6ab16dc9..c75018a359 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff @@ -1,9 +1,9 @@ --- old.declarationEmitFunctionDuplicateNamespace.js +++ new.declarationEmitFunctionDuplicateNamespace.js -@@= skipped -20, +20 lines =@@ +@@= skipped -19, +19 lines =@@ + //// [declarationEmitFunctionDuplicateNamespace.d.ts] declare function f(a: 0): 0; declare function f(a: 1): 1; - declare namespace f { +-declare namespace f { - var x: number; -+ const x: number; - } \ No newline at end of file +-} \ 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 1a9f9ad05e..b85447af98 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js @@ -136,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 { + const B: string; +} +export declare function arrow2(): void; +export declare namespace arrow2 { + const 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 07b2d0a35e..e7f39e3425 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff @@ -28,6 +28,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 { ++ const B: string; ++} ++export declare function arrow2(): void; ++export declare namespace arrow2 { ++ const 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/expandoFunctionExpressionsWithDynamicNames.js b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js index 984cc06333..c2a5813340 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 { + const X: number; +} +export declare function expr2(): void; +export declare namespace expr2 { + const X: number; +} diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff index 91ce438ddd..9b4f1660f1 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 { ++ const X: number; ++} ++export declare function expr2(): void; ++export declare namespace expr2 { ++ const 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 9e65f05947..5ed2dbdd7a 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -25,11 +25,11 @@ declare function errorOnAssignmentBelowDecl(): void; declare namespace errorOnAssignmentBelowDecl { const a: string; } -declare const errorOnAssignmentBelow: { - (): void; - a: string; -}; -declare const errorOnMissingReturn: { - (): void; - a: string; -}; +declare function errorOnAssignmentBelow(): void; +declare namespace errorOnAssignmentBelow { + const a: string; +} +declare function errorOnMissingReturn(): void; +declare namespace errorOnMissingReturn { + const a: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index 2422cce86d..972f69be1f 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -11,11 +11,11 @@ +declare namespace errorOnAssignmentBelowDecl { + const a: string; +} -+declare const errorOnAssignmentBelow: { -+ (): void; -+ a: string; -+}; -+declare const errorOnMissingReturn: { -+ (): void; -+ a: string; -+}; \ No newline at end of file ++declare function errorOnAssignmentBelow(): void; ++declare namespace errorOnAssignmentBelow { ++ const a: string; ++} ++declare function errorOnMissingReturn(): void; ++declare namespace errorOnMissingReturn { ++ const a: string; ++} \ 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..4c5b98723d 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 { + const staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + const staticMember: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index 171c3332a5..f2e19a6a71 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 { ++ const 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 ++ const 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..3f3d6812d2 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 { + const staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + const staticMember: string; +} +declare function SelfReference(): any; +declare namespace SelfReference { + const staticMember: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 3b57bcf92d..5fe9783c4c 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 { ++ const 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 { ++ const 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 ++ const staticMember: string; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index e70d8273b6..0724599f44 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -186,44 +186,42 @@ 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 { + const propTypes: { version: PropTypes.Requireable; }; - defaultProps: { +} +declare namespace TabbedShowLayout { + const 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 { + const 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 { + const 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 { + const defaultProps: { tabs: string; }; -}; +} export default TabbedShowLayout; //// [jsDeclarationsReactComponents5.d.ts] import PropTypes from 'prop-types'; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index aa2a571506..59c49d45a2 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 { ++ const propTypes: { + version: PropTypes.Requireable; + }; -+ defaultProps: { ++} ++declare namespace TabbedShowLayout { ++ const defaultProps: { + tabs: undefined; + }; -+}; ++} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.d.ts] -export default TabbedShowLayout; @@ -81,39 +83,43 @@ - */ -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 { ++ const 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 { ++ const 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; - } --} ++ const defaultProps: { ++ tabs: string; ++ }; + } ++export default TabbedShowLayout; //// [jsDeclarationsReactComponents5.d.ts] -export default Tree; +import PropTypes from 'prop-types'; diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js index 83f4b967b4..2b53e12e04 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 { + const C1: { + new (): { + method(): number; + }; + }; +} /** @implements {A} */ declare var C2: { new (): { @@ -106,3 +113,6 @@ declare class CC { }; } declare var C5: any; +declare namespace Ns { + const 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..4aa7dcf871 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: { ++ const 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 { ++ const C5: any; + } \ 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 b01799aa79..addcac20cb 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -177,23 +177,36 @@ declare namespace ExpandoDecl { const m: (n: number) => number; } declare var n: number; -declare const ExpandoExpr: { - (n: number): string; - prop: { +declare function ExpandoExpr(n: number): string; +declare namespace ExpandoExpr { + const prop: { x: number; y?: undefined; } | { x?: undefined; y: string; }; - m: (n: number) => number; -}; +} +declare namespace ExpandoExpr { + const prop: { + x: number; + y?: undefined; + } | { + x?: undefined; + y: string; + }; +} +declare namespace ExpandoExpr { + const 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 { + const prop: number; +} +declare namespace ExpandoArrow { + const m: (n: number) => number; +} declare function ExpandoNested(n: number): { (m: number): number; total: number; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index 168f9751a7..376ddaac95 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -37,27 +37,61 @@ declare namespace ExpandoDecl { - var prop: number; - var m: (n: number) => number; +-} +-declare var n: number; +-declare const ExpandoExpr: { +- (n: number): string; +- prop: { +- x: number; +- y?: undefined; +- } | { +- x?: undefined; +- y: string; +- }; +- m(n: number): number; +-}; +-declare var n: number; +-declare const ExpandoArrow: { +- (n: number): string; +- prop: number; +- m(n: number): number; +-}; + const prop: number; +} +declare namespace ExpandoDecl { + const m: (n: number) => number; - } - declare var n: number; - declare const ExpandoExpr: { -@@= skipped -13, +15 lines =@@ - x?: undefined; - y: string; - }; -- m(n: number): number; -+ m: (n: number) => number; - }; - declare var n: number; - declare const ExpandoArrow: { - (n: number): string; - prop: number; -- m(n: number): number; -+ m: (n: number) => number; - }; ++} ++declare var n: number; ++declare function ExpandoExpr(n: number): string; ++declare namespace ExpandoExpr { ++ const prop: { ++ x: number; ++ y?: undefined; ++ } | { ++ x?: undefined; ++ y: string; ++ }; ++} ++declare namespace ExpandoExpr { ++ const prop: { ++ x: number; ++ y?: undefined; ++ } | { ++ x?: undefined; ++ y: string; ++ }; ++} ++declare namespace ExpandoExpr { ++ const m: (n: number) => number; ++} ++declare var n: number; ++declare function ExpandoArrow(n: number): string; ++declare namespace ExpandoArrow { ++ const prop: number; ++} ++declare namespace ExpandoArrow { ++ const m: (n: number) => number; ++} declare function ExpandoNested(n: number): { (m: number): number; total: number; @@ -73,7 +107,7 @@ } declare namespace ExpandoMerge { var p2: number; -@@= skipped -28, +28 lines =@@ +@@= skipped -41, +56 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js index 3c3d0d693b..ad20a595df 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 { + const baz: { + blah: number; + }; +} +declare namespace foo { + const 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'. + const baz: { + blah: number; + }; + } + declare namespace foo { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. + const 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..c783abb722 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 { ++ const baz: { ++ blah: number; ++ }; ++} ++declare namespace foo { ++ const 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'. ++ const baz: { ++ blah: number; ++ }; ++ } ++ declare namespace foo { ++ ~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. ++ const blah: number; ++ } ++ \ No newline at end of file From 8847dd79fec8c3bc4bff30897e740d601f7bc634 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Thu, 9 Oct 2025 23:57:33 +0300 Subject: [PATCH 11/11] use var instead of const --- .../transformers/declarations/transform.go | 2 +- .../declarationEmitExpandoFunction.js | 6 +- ...onEmitDefaultExportWithStaticAssignment.js | 10 +- ...tDefaultExportWithStaticAssignment.js.diff | 15 +- ...clarationEmitExpandoPropertyPrivateName.js | 2 +- ...tionEmitExpandoPropertyPrivateName.js.diff | 2 +- ...arationEmitExpandoWithGenericConstraint.js | 2 +- ...onEmitExpandoWithGenericConstraint.js.diff | 2 +- .../declarationEmitFunctionKeywordProp.js | 10 +- ...declarationEmitFunctionKeywordProp.js.diff | 19 +- .../declarationEmitLateBoundAssignments.js | 4 +- ...eclarationEmitLateBoundAssignments.js.diff | 9 +- .../declarationEmitLateBoundAssignments2.js | 8 +- ...clarationEmitLateBoundAssignments2.js.diff | 17 +- .../declarationEmitLateBoundJSAssignments.js | 4 +- ...larationEmitLateBoundJSAssignments.js.diff | 4 +- .../compiler/expandoFunctionBlockShadowing.js | 2 +- .../expandoFunctionBlockShadowing.js.diff | 9 +- ...andoFunctionExpressionsWithDynamicNames.js | 4 +- ...unctionExpressionsWithDynamicNames.js.diff | 4 +- .../compiler/isolatedDeclarationErrors.js | 6 +- .../isolatedDeclarationErrors.js.diff | 6 +- ...olatedDeclarationErrorsExpandoFunctions.js | 51 +--- ...dDeclarationErrorsExpandoFunctions.js.diff | 53 +--- .../jsDeclarationsGlobalFileConstFunction.js | 4 +- ...eclarationsGlobalFileConstFunction.js.diff | 4 +- ...eclarationsGlobalFileConstFunctionNamed.js | 6 +- ...ationsGlobalFileConstFunctionNamed.js.diff | 6 +- ...xDeclarationsWithEsModuleInteropNoCrash.js | 4 +- ...arationsWithEsModuleInteropNoCrash.js.diff | 4 +- ...undFunctionMemberAssignmentDeclarations.js | 2 +- ...nctionMemberAssignmentDeclarations.js.diff | 9 - .../conformance/assignmentToVoidZero2.js | 4 +- .../conformance/assignmentToVoidZero2.js.diff | 4 +- .../commonJSImportNestedClassTypeReference.js | 2 +- ...onJSImportNestedClassTypeReference.js.diff | 2 +- .../conformance/exportDefaultNamespace.js | 2 +- .../exportDefaultNamespace.js.diff | 3 +- .../conformance/jsDeclarationsClassMethod.js | 4 +- .../jsDeclarationsClassMethod.js.diff | 4 +- .../conformance/jsDeclarationsClassStatic.js | 2 +- .../jsDeclarationsClassStatic.js.diff | 2 +- .../conformance/jsDeclarationsClassStatic2.js | 2 +- .../jsDeclarationsClassStatic2.js.diff | 2 +- ...tionsFunctionClassesCjsExportAssignment.js | 2 +- ...FunctionClassesCjsExportAssignment.js.diff | 2 +- .../jsDeclarationsFunctionKeywordProp.js | 10 +- .../jsDeclarationsFunctionKeywordProp.js.diff | 10 +- ...clarationsFunctionKeywordPropExhaustive.js | 156 +++++------ ...tionsFunctionKeywordPropExhaustive.js.diff | 156 +++++------ .../jsDeclarationsFunctionLikeClasses2.js | 4 +- ...jsDeclarationsFunctionLikeClasses2.js.diff | 4 +- .../jsDeclarationsFunctionPrototypeStatic.js | 4 +- ...eclarationsFunctionPrototypeStatic.js.diff | 4 +- ...ationsFunctionWithDefaultAssignedMember.js | 4 +- ...sFunctionWithDefaultAssignedMember.js.diff | 4 +- .../conformance/jsDeclarationsFunctions.js | 6 +- .../jsDeclarationsFunctions.js.diff | 6 +- ...tionsParameterTagReusesInputNodeInEmit1.js | 2 +- ...ParameterTagReusesInputNodeInEmit1.js.diff | 2 +- ...tionsParameterTagReusesInputNodeInEmit2.js | 2 +- ...ParameterTagReusesInputNodeInEmit2.js.diff | 2 +- .../jsDeclarationsReactComponents.js | 14 +- .../jsDeclarationsReactComponents.js.diff | 14 +- .../conformance/jsdocImplements_class.js | 4 +- .../conformance/jsdocImplements_class.js.diff | 4 +- .../submodule/conformance/nullPropertyName.js | 156 +++++------ .../conformance/nullPropertyName.js.diff | 265 ++++++++---------- .../typeFromPropertyAssignment29.js | 20 +- .../typeFromPropertyAssignment29.js.diff | 38 +-- .../typeFromPropertyAssignment39.js | 8 +- .../typeFromPropertyAssignment39.js.diff | 8 +- .../typeFromPrototypeAssignment4.js | 2 +- .../typeFromPrototypeAssignment4.js.diff | 2 +- 74 files changed, 530 insertions(+), 708 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index d8858d38cc..e81bf4f602 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1880,7 +1880,7 @@ func (tx *DeclarationTransformer) transformExpandoAssignment(node *ast.BinaryExp tx.Factory().NewVariableStatement( nil, /*modifiers*/ tx.Factory().NewVariableDeclarationList( - ast.NodeFlagsConst, + ast.NodeFlagsNone, tx.Factory().NewNodeList([]*ast.Node{ tx.Factory().NewVariableDeclaration(exportName, nil /*exclamationToken*/, t, nil /*initializer*/), }), diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js index eab0cd657c..c54f345dd5 100644 --- a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js @@ -47,11 +47,11 @@ export declare enum C { C = 0 } export declare namespace A { - const a: typeof C; + var a: typeof C; } export declare namespace A { - const b: typeof C; + var b: typeof C; } export declare namespace B { - const c: typeof C; + var c: typeof C; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index a886d4b371..9a3ef3a146 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -85,7 +85,7 @@ export declare class Foo { declare function Example(): void; export default Example; declare namespace Example { - const Foo: typeof import("./foo").Foo; + var Foo: typeof import("./foo").Foo; } //// [index2.d.ts] import { Foo } from './foo'; @@ -93,7 +93,7 @@ export { Foo }; declare function Example(): void; export default Example; declare namespace Example { - const Foo: typeof import("./foo").Foo; + var Foo: typeof import("./foo").Foo; } //// [index3.d.ts] export declare class Bar { @@ -101,13 +101,13 @@ export declare class Bar { declare function Example(): void; export default Example; declare namespace Example { - const Bar: typeof import("./index3").Bar; + var Bar: typeof import("./index3").Bar; } //// [index4.d.ts] export declare function C(): any; export declare namespace C { - const A: () => void; + var A: () => void; } export declare namespace C { - const B: () => void; + var B: () => void; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index c3fe1eafdf..552d88daf0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -24,8 +24,7 @@ declare function Example(): void; +export default Example; declare namespace Example { -- var Foo: typeof import("./foo").Foo; -+ const Foo: typeof import("./foo").Foo; + var Foo: typeof import("./foo").Foo; } -export default Example; //// [index2.d.ts] @@ -34,8 +33,7 @@ declare function Example(): void; +export default Example; declare namespace Example { -- var Foo: typeof import("./foo").Foo; -+ const Foo: typeof import("./foo").Foo; + var Foo: typeof import("./foo").Foo; } -export default Example; //// [index3.d.ts] @@ -44,17 +42,14 @@ declare function Example(): void; +export default Example; declare namespace Example { -- var Bar: typeof import("./index3").Bar; -+ const Bar: typeof import("./index3").Bar; + var Bar: typeof import("./index3").Bar; } -export default Example; //// [index4.d.ts] export declare function C(): any; export declare namespace C { -- var A: () => void; -- var B: () => void; -+ const A: () => void; + var A: () => void; +} +export declare namespace C { -+ const B: () => void; + var B: () => void; } \ 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 e018db2557..62611a4b50 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js @@ -32,5 +32,5 @@ export {}; //// [b.d.ts] export declare function q(): void; export declare namespace q { - const val: I; + var val: I; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff index 0886b8a890..1a0346d4ab 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff @@ -16,5 +16,5 @@ +//// [b.d.ts] +export declare function q(): void; +export declare namespace q { -+ const val: I; ++ 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 4b03e9dfe2..cf2922f110 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js @@ -39,5 +39,5 @@ export interface Rect

{ export declare function Point(x: number, y: number): Point; export declare const Rect:

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

; export declare namespace Point { - const zero: () => 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 1b24394944..eca527388e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff @@ -11,5 +11,5 @@ +export declare function Point(x: number, y: number): Point; export declare const Rect:

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

; +export declare namespace Point { -+ const zero: () => 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 33fba14e69..0c8480ef02 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js @@ -26,21 +26,21 @@ baz.normal = false; //// [declarationEmitFunctionKeywordProp.d.ts] declare function foo(): void; declare namespace foo { - const _a: boolean; + var _a: boolean; export { _a as null }; } declare function bar(): void; declare namespace bar { - const async: boolean; + var async: boolean; } declare namespace bar { - const normal: boolean; + var normal: boolean; } declare function baz(): void; declare namespace baz { - const _b: boolean; + var _b: boolean; export { _b as class }; } declare namespace baz { - const normal: boolean; + var normal: boolean; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff index cad69bf67f..06133cdc84 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -1,30 +1,21 @@ --- old.declarationEmitFunctionKeywordProp.js +++ new.declarationEmitFunctionKeywordProp.js -@@= skipped -25, +25 lines =@@ - //// [declarationEmitFunctionKeywordProp.d.ts] - declare function foo(): void; - declare namespace foo { -- var _a: boolean; -+ const _a: boolean; - export { _a as null }; - } +@@= skipped -31, +31 lines =@@ declare function bar(): void; declare namespace bar { -- var async: boolean; -- var normal: boolean; -+ const async: boolean; + var async: boolean; +} +declare namespace bar { -+ const normal: boolean; + var normal: boolean; } declare function baz(): void; declare namespace baz { - var _a: boolean; - export var normal: boolean; - export { _a as class }; -+ const _b: boolean; ++ var _b: boolean; + export { _b as class }; +} +declare namespace baz { -+ const normal: boolean; ++ 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 21b530af50..9d36f2464b 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -37,8 +37,8 @@ const a = foo[dashStrMem]; //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; export declare namespace foo { - const bar: number; + var bar: number; } export declare namespace foo { - const strMemName: string; + var strMemName: string; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 16fcf29f8c..e6fc1de8ea 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff @@ -1,13 +1,10 @@ --- old.declarationEmitLateBoundAssignments.js +++ new.declarationEmitLateBoundAssignments.js -@@= skipped -36, +36 lines =@@ - //// [declarationEmitLateBoundAssignments.d.ts] +@@= skipped -37, +37 lines =@@ export declare function foo(): void; export declare namespace foo { -- var bar: number; -- var strMemName: string; -+ const bar: number; + var bar: number; +} +export declare namespace foo { -+ const strMemName: string; + 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 b85447af98..370aaf1b30 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js @@ -122,11 +122,11 @@ arrow10[emoji] = 0; //// [declarationEmitLateBoundAssignments2.d.ts] export declare function decl(): void; export declare namespace decl { - const B: string; + var B: string; } export declare function decl2(): void; export declare namespace decl2 { - const C: number; + var C: number; } export declare function decl3(): void; export declare function decl4(): void; @@ -138,11 +138,11 @@ export declare function decl9(): void; export declare function decl10(): void; export declare function arrow(): void; export declare namespace arrow { - const B: string; + var B: string; } export declare function arrow2(): void; export declare namespace arrow2 { - const C: number; + var C: number; } export declare const arrow3: { (): void; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff index e7f39e3425..d2275bb556 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff @@ -1,16 +1,7 @@ --- old.declarationEmitLateBoundAssignments2.js +++ new.declarationEmitLateBoundAssignments2.js -@@= skipped -121, +121 lines =@@ - //// [declarationEmitLateBoundAssignments2.d.ts] - export declare function decl(): void; - export declare namespace decl { -- var B: string; -+ const B: string; - } - export declare function decl2(): void; - export declare namespace decl2 { -- var C: number; -+ const C: number; +@@= skipped -128, +128 lines =@@ + var C: number; } export declare function decl3(): void; -export declare namespace decl3 { } @@ -38,11 +29,11 @@ -}; +export declare function arrow(): void; +export declare namespace arrow { -+ const B: string; ++ var B: string; +} +export declare function arrow2(): void; +export declare namespace arrow2 { -+ const C: number; ++ var C: number; +} export declare const arrow3: { (): void; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js index e4f6b2f1b2..c807097433 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -27,8 +27,8 @@ const a = foo[dashStrMem]; //// [file.d.ts] export declare function foo(): void; export declare namespace foo { - const bar: number; + var bar: number; } export declare namespace foo { - const strMemName: string; + var strMemName: string; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 338f9a32de..3f66ad50ff 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -10,8 +10,8 @@ - let strMemName: string; +export declare function foo(): void; +export declare namespace foo { -+ const bar: number; ++ var bar: number; +} +export declare namespace foo { -+ const strMemName: string; ++ 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 bbfa5450a7..1b37891205 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js @@ -46,5 +46,5 @@ if (Math.random()) { export declare function X(): void; export declare function Y(): void; export declare namespace Y { - const test: string; + var test: string; } diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index f56b594ac8..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 -24, +24 lines =@@ - export declare function X(): void; - export declare function Y(): void; - export declare namespace Y { -- var test: string; -+ const 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 c2a5813340..054a90b860 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js @@ -29,9 +29,9 @@ exports.expr2[s] = 0; //// [expandoFunctionExpressionsWithDynamicNames.d.ts] export declare function expr(): void; export declare namespace expr { - const X: number; + var X: number; } export declare function expr2(): void; export declare namespace expr2 { - const X: number; + var X: number; } diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff index 9b4f1660f1..df20fd2068 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionExpressionsWithDynamicNames.js.diff @@ -25,9 +25,9 @@ -}; +export declare function expr(): void; +export declare namespace expr { -+ const X: number; ++ var X: number; +} +export declare function expr2(): void; +export declare namespace expr2 { -+ const X: number; ++ 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 5ed2dbdd7a..6616dff493 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -23,13 +23,13 @@ errorOnMissingReturn.a = ""; //// [isolatedDeclarationErrors.d.ts] declare function errorOnAssignmentBelowDecl(): void; declare namespace errorOnAssignmentBelowDecl { - const a: string; + var a: string; } declare function errorOnAssignmentBelow(): void; declare namespace errorOnAssignmentBelow { - const a: string; + var a: string; } declare function errorOnMissingReturn(): void; declare namespace errorOnMissingReturn { - const a: string; + var a: string; } diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index 972f69be1f..47bb029ded 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -9,13 +9,13 @@ +//// [isolatedDeclarationErrors.d.ts] +declare function errorOnAssignmentBelowDecl(): void; +declare namespace errorOnAssignmentBelowDecl { -+ const a: string; ++ var a: string; +} +declare function errorOnAssignmentBelow(): void; +declare namespace errorOnAssignmentBelow { -+ const a: string; ++ var a: string; +} +declare function errorOnMissingReturn(): void; +declare namespace errorOnMissingReturn { -+ const a: string; ++ 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 9ebccc55c2..32cbc8903c 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -26,60 +26,23 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] export declare function foo(): void; export declare namespace foo { - const apply: () => void; + var apply: () => void; } export declare namespace foo { - const call: () => void; + var call: () => void; } export declare namespace foo { - const bind: () => void; + var bind: () => void; } export declare namespace foo { - const caller: () => void; + var caller: () => void; } export declare namespace foo { - const toString: () => void; + var toString: () => void; } export declare namespace foo { - const length: number; + var length: number; } export declare namespace foo { - const length: number; + var length: number; } - - -//// [DtsFileErrors] - - -isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. -isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. - - -==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== - export declare function foo(): void; - export declare namespace foo { - const apply: () => void; - } - export declare namespace foo { - const call: () => void; - } - export declare namespace foo { - const bind: () => void; - } - export declare namespace foo { - const caller: () => void; - } - export declare namespace foo { - const toString: () => void; - } - export declare namespace foo { - const length: number; - ~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'length'. - } - export declare namespace foo { - const length: number; - ~~~~~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'length'. - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff index e4a99a073a..158cd2ae6c 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -9,60 +9,23 @@ +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] +export declare function foo(): void; +export declare namespace foo { -+ const apply: () => void; ++ var apply: () => void; +} +export declare namespace foo { -+ const call: () => void; ++ var call: () => void; +} +export declare namespace foo { -+ const bind: () => void; ++ var bind: () => void; +} +export declare namespace foo { -+ const caller: () => void; ++ var caller: () => void; +} +export declare namespace foo { -+ const toString: () => void; ++ var toString: () => void; +} +export declare namespace foo { -+ const length: number; ++ var length: number; +} +export declare namespace foo { -+ const length: number; -+} -+ -+ -+//// [DtsFileErrors] -+ -+ -+isolatedDeclarationErrorsExpandoFunctions.d.ts(18,11): error TS2451: Cannot redeclare block-scoped variable 'length'. -+isolatedDeclarationErrorsExpandoFunctions.d.ts(21,11): error TS2451: Cannot redeclare block-scoped variable 'length'. -+ -+ -+==== isolatedDeclarationErrorsExpandoFunctions.d.ts (2 errors) ==== -+ export declare function foo(): void; -+ export declare namespace foo { -+ const apply: () => void; -+ } -+ export declare namespace foo { -+ const call: () => void; -+ } -+ export declare namespace foo { -+ const bind: () => void; -+ } -+ export declare namespace foo { -+ const caller: () => void; -+ } -+ export declare namespace foo { -+ const toString: () => void; -+ } -+ export declare namespace foo { -+ const length: number; -+ ~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'length'. -+ } -+ export declare namespace foo { -+ const length: number; -+ ~~~~~~ -+!!! error TS2451: Cannot redeclare block-scoped variable 'length'. -+ } -+ \ No newline at end of file ++ 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 4c5b98723d..8e4843d111 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js @@ -21,9 +21,9 @@ SomeConstructor3.staticMember = "str"; declare const SomeConstructor: () => void; declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { - const staticMember: string; + var staticMember: string; } declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { - const staticMember: string; + var staticMember: string; } diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index f2e19a6a71..d115dfd622 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -12,7 +12,7 @@ declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { - let staticMember: string; -+ const staticMember: string; ++ var staticMember: string; } declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { @@ -21,5 +21,5 @@ -} -declare class SomeConstructor3 { - x: number; -+ const staticMember: string; ++ 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 3f3d6812d2..4b6b926338 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -27,13 +27,13 @@ SelfReference.staticMember = "str"; declare const SomeConstructor: () => void; declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { - const staticMember: string; + var staticMember: string; } declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { - const staticMember: string; + var staticMember: string; } declare function SelfReference(): any; declare namespace SelfReference { - const staticMember: string; + var staticMember: string; } diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 5fe9783c4c..74d665ccee 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -12,7 +12,7 @@ declare function SomeConstructor2(): void; declare namespace SomeConstructor2 { - let staticMember: string; -+ const staticMember: string; ++ var staticMember: string; } declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { @@ -23,7 +23,7 @@ - x: number; -} -declare function SelfReference(): SelfReference; -+ const staticMember: string; ++ var staticMember: string; +} +declare function SelfReference(): any; declare namespace SelfReference { @@ -32,5 +32,5 @@ -} -declare class SelfReference { - x: number; -+ const staticMember: string; ++ 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 55ede3d96d..cede538469 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js @@ -31,12 +31,12 @@ declare function Foo({ bar }: { bar: any; }): JSX.Element; declare namespace Foo { - const propTypes: { + var propTypes: { bar: PropTypes.Requireable; }; } declare namespace Foo { - const defaultProps: { + var defaultProps: { bar: boolean; }; } diff --git a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff index a9c1081d62..282833a6e0 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff @@ -21,12 +21,12 @@ - export { bar_1 as bar }; -} -import PropTypes from 'prop-types'; -+ const propTypes: { ++ var propTypes: { + bar: PropTypes.Requireable; + }; +} +declare namespace Foo { -+ const defaultProps: { ++ var defaultProps: { + bar: boolean; + }; +} diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js index d15db8974e..05ce6daa8c 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js @@ -20,5 +20,5 @@ const x = foo[_private]; //// [index.d.ts] export declare function foo(): void; export declare namespace foo { - const bar: number; + 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 900aef4bb5..0000000000 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff +++ /dev/null @@ -1,9 +0,0 @@ ---- old.lateBoundFunctionMemberAssignmentDeclarations.js -+++ new.lateBoundFunctionMemberAssignmentDeclarations.js -@@= skipped -19, +19 lines =@@ - //// [index.d.ts] - export declare function foo(): void; - export declare namespace foo { -- var bar: number; -+ const 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 62c7a70269..e79804a05e 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js @@ -48,10 +48,10 @@ assignmentToVoidZero2_1.j + assignmentToVoidZero2_1.k; export var j = 1; export var k = void 0; declare namespace o { - const x: number; + var x: number; } declare namespace o { - const y: any; + var y: any; } export {}; //// [importer.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff index e5ca963b32..a08ceb9494 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff @@ -26,10 +26,10 @@ +export var j = 1; +export var k = void 0; +declare namespace o { -+ const x: number; ++ var x: number; +} +declare namespace o { -+ const y: any; ++ var y: any; +} +export {}; //// [importer.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js index b362e8a78c..39c2df78a4 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js @@ -39,7 +39,7 @@ function f(k) { //// [mod1.d.ts] declare namespace NS { - const K: { + var K: { new (): { values(): /*elided*/ any; }; diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff index ec0cdbeade..7dcf48b386 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff @@ -23,7 +23,7 @@ - new (): { - values(): /*elided*/ any; +declare namespace NS { -+ const K: { ++ var K: { + new (): { + values(): /*elided*/ any; + }; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index 46d9bded17..0565e4c96d 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -22,5 +22,5 @@ someFunc.someProp = 'yo'; declare function someFunc(): string; export default someFunc; declare namespace someFunc { - const someProp: string; + var someProp: string; } diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff index d88c830a16..60f7690974 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -6,7 +6,6 @@ declare function someFunc(): string; +export default someFunc; declare namespace someFunc { -- var someProp: string; -+ const someProp: string; + 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 8483569d1c..c4da697a19 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js @@ -130,7 +130,7 @@ C2.staticProp = function (x, y) { //// [jsDeclarationsClassMethod.d.ts] declare function C1(): void; declare namespace C1 { - const staticProp: (x: any, y: any) => any; + var staticProp: (x: any, y: any) => any; } declare class C2 { /** @@ -142,5 +142,5 @@ declare class C2 { method1(x: number, y: number): number; } declare namespace C2 { - const staticProp: (x: any, y: any) => any; + 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 f248ddecfb..864b04d0c7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff @@ -28,7 +28,7 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; -+ const staticProp: (x: any, y: any) => any; ++ var staticProp: (x: any, y: any) => any; } declare class C2 { /** @@ -52,5 +52,5 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; -+ const staticProp: (x: any, y: any) => any; ++ 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 85037752df..72c30e4c2a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -53,7 +53,7 @@ module.exports.Strings = Strings; //// [source.d.ts] declare namespace Handler { - const statische: () => void; + var statische: () => void; } export = Handler; export var Strings = Strings; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff index 4dbe14ad55..17b3390c8f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -41,7 +41,7 @@ - * Should be able to export a type alias at the same time. - */ - name: string; -+ const statische: () => void; ++ var statische: () => void; +} +export = Handler; +export var Strings = Strings; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js index 6feb81f0d9..84f368712e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js @@ -23,7 +23,7 @@ declare class Base { export declare class Foo extends Base { } export declare namespace Foo { - const foo: string; + 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 6ba1fca32b..24118c9347 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff @@ -16,7 +16,7 @@ +export declare class Foo extends Base { +} +export declare namespace Foo { -+ const foo: string; ++ 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 53e9d57f2a..479a6ab822 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -187,7 +187,7 @@ export type State = { */ declare function Context(input: Input): any; declare namespace Context { - const prototype: { + var prototype: { /** * @param {Input} input * @param {HookHandler=} handle diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff index 914cb5c5ad..f4d945f527 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff @@ -106,7 +106,7 @@ +declare function Context(input: Input): any; declare namespace Context { - export { Timer, Hook, HookHandler, Input, State }; -+ const prototype: { ++ var prototype: { + /** + * @param {Input} input + * @param {HookHandler=} handle diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js index 733c932e5a..f5a429881b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js @@ -26,21 +26,21 @@ baz.normal = false; //// [source.d.ts] declare function foo(): void; declare namespace foo { - const _a: boolean; + var _a: boolean; export { _a as null }; } declare function bar(): void; declare namespace bar { - const async: boolean; + var async: boolean; } declare namespace bar { - const normal: boolean; + var normal: boolean; } declare function baz(): void; declare namespace baz { - const _b: boolean; + var _b: boolean; export { _b as class }; } declare namespace baz { - const normal: boolean; + var normal: boolean; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff index 88f1ff32fd..ca0bf04d42 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff @@ -6,17 +6,17 @@ declare namespace foo { - let _null: boolean; - export { _null as null }; -+ const _a: boolean; ++ var _a: boolean; + export { _a as null }; } declare function bar(): void; declare namespace bar { - let async: boolean; - let normal: boolean; -+ const async: boolean; ++ var async: boolean; +} +declare namespace bar { -+ const normal: boolean; ++ var normal: boolean; } declare function baz(): void; declare namespace baz { @@ -24,9 +24,9 @@ - export { _class as class }; - let normal_1: boolean; - export { normal_1 as normal }; -+ const _b: boolean; ++ var _b: boolean; + export { _b as class }; +} +declare namespace baz { -+ const normal: boolean; ++ 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 e976844039..b8eb1d30f9 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -171,281 +171,281 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; declare namespace foo { - const x: number; + var x: number; } declare namespace foo { - const y: number; + var y: number; } declare namespace foo { - const _a: number; + var _a: number; export { _a as break }; } declare namespace foo { - const _b: number; + var _b: number; export { _b as case }; } declare namespace foo { - const _c: number; + var _c: number; export { _c as catch }; } declare namespace foo { - const _d: number; + var _d: number; export { _d as class }; } declare namespace foo { - const _e: number; + var _e: number; export { _e as const }; } declare namespace foo { - const _f: number; + var _f: number; export { _f as continue }; } declare namespace foo { - const _g: number; + var _g: number; export { _g as debugger }; } declare namespace foo { - const _h: number; + var _h: number; export { _h as default }; } declare namespace foo { - const _j: number; + var _j: number; export { _j as delete }; } declare namespace foo { - const _k: number; + var _k: number; export { _k as do }; } declare namespace foo { - const _l: number; + var _l: number; export { _l as else }; } declare namespace foo { - const _m: number; + var _m: number; export { _m as enum }; } declare namespace foo { - const _o: number; + var _o: number; export { _o as export }; } declare namespace foo { - const _p: number; + var _p: number; export { _p as extends }; } declare namespace foo { - const _q: number; + var _q: number; export { _q as false }; } declare namespace foo { - const _r: number; + var _r: number; export { _r as finally }; } declare namespace foo { - const _s: number; + var _s: number; export { _s as for }; } declare namespace foo { - const _t: number; + var _t: number; export { _t as function }; } declare namespace foo { - const _u: number; + var _u: number; export { _u as if }; } declare namespace foo { - const _v: number; + var _v: number; export { _v as import }; } declare namespace foo { - const _w: number; + var _w: number; export { _w as in }; } declare namespace foo { - const _x: number; + var _x: number; export { _x as instanceof }; } declare namespace foo { - const _y: number; + var _y: number; export { _y as new }; } declare namespace foo { - const _z: number; + var _z: number; export { _z as null }; } declare namespace foo { - const _0: number; + var _0: number; export { _0 as return }; } declare namespace foo { - const _1: number; + var _1: number; export { _1 as super }; } declare namespace foo { - const _2: number; + var _2: number; export { _2 as switch }; } declare namespace foo { - const _3: number; + var _3: number; export { _3 as this }; } declare namespace foo { - const _4: number; + var _4: number; export { _4 as throw }; } declare namespace foo { - const _5: number; + var _5: number; export { _5 as true }; } declare namespace foo { - const _6: number; + var _6: number; export { _6 as try }; } declare namespace foo { - const _7: number; + var _7: number; export { _7 as typeof }; } declare namespace foo { - const _8: number; + var _8: number; export { _8 as var }; } declare namespace foo { - const _9: number; + var _9: number; export { _9 as void }; } declare namespace foo { - const _10: number; + var _10: number; export { _10 as while }; } declare namespace foo { - const _11: number; + var _11: number; export { _11 as with }; } declare namespace foo { - const _12: number; + var _12: number; export { _12 as implements }; } declare namespace foo { - const _13: number; + var _13: number; export { _13 as interface }; } declare namespace foo { - const _14: number; + var _14: number; export { _14 as let }; } declare namespace foo { - const _15: number; + var _15: number; export { _15 as package }; } declare namespace foo { - const _16: number; + var _16: number; export { _16 as private }; } declare namespace foo { - const _17: number; + var _17: number; export { _17 as protected }; } declare namespace foo { - const _18: number; + var _18: number; export { _18 as public }; } declare namespace foo { - const _19: number; + var _19: number; export { _19 as static }; } declare namespace foo { - const _20: number; + var _20: number; export { _20 as yield }; } declare namespace foo { - const abstract: number; + var abstract: number; } declare namespace foo { - const as: number; + var as: number; } declare namespace foo { - const asserts: number; + var asserts: number; } declare namespace foo { - const any: number; + var any: number; } declare namespace foo { - const async: number; + var async: number; } declare namespace foo { - const await: number; + var await: number; } declare namespace foo { - const boolean: number; + var boolean: number; } declare namespace foo { - const constructor: number; + var constructor: number; } declare namespace foo { - const declare: number; + var declare: number; } declare namespace foo { - const get: number; + var get: number; } declare namespace foo { - const infer: number; + var infer: number; } declare namespace foo { - const is: number; + var is: number; } declare namespace foo { - const keyof: number; + var keyof: number; } declare namespace foo { - const module: number; + var module: number; } declare namespace foo { - const namespace: number; + var namespace: number; } declare namespace foo { - const never: number; + var never: number; } declare namespace foo { - const readonly: number; + var readonly: number; } declare namespace foo { - const require: number; + var require: number; } declare namespace foo { - const number: number; + var number: number; } declare namespace foo { - const object: number; + var object: number; } declare namespace foo { - const set: number; + var set: number; } declare namespace foo { - const string: number; + var string: number; } declare namespace foo { - const symbol: number; + var symbol: number; } declare namespace foo { - const type: number; + var type: number; } declare namespace foo { - const undefined: number; + var undefined: number; } declare namespace foo { - const unique: number; + var unique: number; } declare namespace foo { - const unknown: number; + var unknown: number; } declare namespace foo { - const from: number; + var from: number; } declare namespace foo { - const global: number; + var global: number; } declare namespace foo { - const bigint: number; + var bigint: number; } declare namespace foo { - const of: number; + var of: number; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff index 64f641cc38..4dc3c418c2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff @@ -127,281 +127,281 @@ - export let global: number; - export let bigint: number; - export let of: number; -+ const x: number; ++ var x: number; +} +declare namespace foo { -+ const y: number; ++ var y: number; +} +declare namespace foo { -+ const _a: number; ++ var _a: number; + export { _a as break }; +} +declare namespace foo { -+ const _b: number; ++ var _b: number; + export { _b as case }; +} +declare namespace foo { -+ const _c: number; ++ var _c: number; + export { _c as catch }; +} +declare namespace foo { -+ const _d: number; ++ var _d: number; + export { _d as class }; +} +declare namespace foo { -+ const _e: number; ++ var _e: number; + export { _e as const }; +} +declare namespace foo { -+ const _f: number; ++ var _f: number; + export { _f as continue }; +} +declare namespace foo { -+ const _g: number; ++ var _g: number; + export { _g as debugger }; +} +declare namespace foo { -+ const _h: number; ++ var _h: number; + export { _h as default }; +} +declare namespace foo { -+ const _j: number; ++ var _j: number; + export { _j as delete }; +} +declare namespace foo { -+ const _k: number; ++ var _k: number; + export { _k as do }; +} +declare namespace foo { -+ const _l: number; ++ var _l: number; + export { _l as else }; +} +declare namespace foo { -+ const _m: number; ++ var _m: number; + export { _m as enum }; +} +declare namespace foo { -+ const _o: number; ++ var _o: number; + export { _o as export }; +} +declare namespace foo { -+ const _p: number; ++ var _p: number; + export { _p as extends }; +} +declare namespace foo { -+ const _q: number; ++ var _q: number; + export { _q as false }; +} +declare namespace foo { -+ const _r: number; ++ var _r: number; + export { _r as finally }; +} +declare namespace foo { -+ const _s: number; ++ var _s: number; + export { _s as for }; +} +declare namespace foo { -+ const _t: number; ++ var _t: number; + export { _t as function }; +} +declare namespace foo { -+ const _u: number; ++ var _u: number; + export { _u as if }; +} +declare namespace foo { -+ const _v: number; ++ var _v: number; + export { _v as import }; +} +declare namespace foo { -+ const _w: number; ++ var _w: number; + export { _w as in }; +} +declare namespace foo { -+ const _x: number; ++ var _x: number; + export { _x as instanceof }; +} +declare namespace foo { -+ const _y: number; ++ var _y: number; + export { _y as new }; +} +declare namespace foo { -+ const _z: number; ++ var _z: number; + export { _z as null }; +} +declare namespace foo { -+ const _0: number; ++ var _0: number; + export { _0 as return }; +} +declare namespace foo { -+ const _1: number; ++ var _1: number; + export { _1 as super }; +} +declare namespace foo { -+ const _2: number; ++ var _2: number; + export { _2 as switch }; +} +declare namespace foo { -+ const _3: number; ++ var _3: number; + export { _3 as this }; +} +declare namespace foo { -+ const _4: number; ++ var _4: number; + export { _4 as throw }; +} +declare namespace foo { -+ const _5: number; ++ var _5: number; + export { _5 as true }; +} +declare namespace foo { -+ const _6: number; ++ var _6: number; + export { _6 as try }; +} +declare namespace foo { -+ const _7: number; ++ var _7: number; + export { _7 as typeof }; +} +declare namespace foo { -+ const _8: number; ++ var _8: number; + export { _8 as var }; +} +declare namespace foo { -+ const _9: number; ++ var _9: number; + export { _9 as void }; +} +declare namespace foo { -+ const _10: number; ++ var _10: number; + export { _10 as while }; +} +declare namespace foo { -+ const _11: number; ++ var _11: number; + export { _11 as with }; +} +declare namespace foo { -+ const _12: number; ++ var _12: number; + export { _12 as implements }; +} +declare namespace foo { -+ const _13: number; ++ var _13: number; + export { _13 as interface }; +} +declare namespace foo { -+ const _14: number; ++ var _14: number; + export { _14 as let }; +} +declare namespace foo { -+ const _15: number; ++ var _15: number; + export { _15 as package }; +} +declare namespace foo { -+ const _16: number; ++ var _16: number; + export { _16 as private }; +} +declare namespace foo { -+ const _17: number; ++ var _17: number; + export { _17 as protected }; +} +declare namespace foo { -+ const _18: number; ++ var _18: number; + export { _18 as public }; +} +declare namespace foo { -+ const _19: number; ++ var _19: number; + export { _19 as static }; +} +declare namespace foo { -+ const _20: number; ++ var _20: number; + export { _20 as yield }; +} +declare namespace foo { -+ const abstract: number; ++ var abstract: number; +} +declare namespace foo { -+ const as: number; ++ var as: number; +} +declare namespace foo { -+ const asserts: number; ++ var asserts: number; +} +declare namespace foo { -+ const any: number; ++ var any: number; +} +declare namespace foo { -+ const async: number; ++ var async: number; +} +declare namespace foo { -+ const await: number; ++ var await: number; +} +declare namespace foo { -+ const boolean: number; ++ var boolean: number; +} +declare namespace foo { -+ const constructor: number; ++ var constructor: number; +} +declare namespace foo { -+ const declare: number; ++ var declare: number; +} +declare namespace foo { -+ const get: number; ++ var get: number; +} +declare namespace foo { -+ const infer: number; ++ var infer: number; +} +declare namespace foo { -+ const is: number; ++ var is: number; +} +declare namespace foo { -+ const keyof: number; ++ var keyof: number; +} +declare namespace foo { -+ const module: number; ++ var module: number; +} +declare namespace foo { -+ const namespace: number; ++ var namespace: number; +} +declare namespace foo { -+ const never: number; ++ var never: number; +} +declare namespace foo { -+ const readonly: number; ++ var readonly: number; +} +declare namespace foo { -+ const require: number; ++ var require: number; +} +declare namespace foo { -+ const number: number; ++ var number: number; +} +declare namespace foo { -+ const object: number; ++ var object: number; +} +declare namespace foo { -+ const set: number; ++ var set: number; +} +declare namespace foo { -+ const string: number; ++ var string: number; +} +declare namespace foo { -+ const symbol: number; ++ var symbol: number; +} +declare namespace foo { -+ const type: number; ++ var type: number; +} +declare namespace foo { -+ const undefined: number; ++ var undefined: number; +} +declare namespace foo { -+ const unique: number; ++ var unique: number; +} +declare namespace foo { -+ const unknown: number; ++ var unknown: number; +} +declare namespace foo { -+ const from: number; ++ var from: number; +} +declare namespace foo { -+ const global: number; ++ var global: number; +} +declare namespace foo { -+ const bigint: number; ++ var bigint: number; +} +declare namespace foo { -+ const of: number; ++ 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 f30240ff09..8a89d1edb4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js @@ -160,7 +160,7 @@ exports.origin = new source_1.Point2D(0, 0); */ export declare function Vec(len: number): void; export declare namespace Vec { - const prototype: { + var prototype: { /** * @param {Vec} other */ @@ -174,7 +174,7 @@ export declare namespace Vec { */ export declare function Point2D(x: number, y: number): any; export declare namespace Point2D { - const prototype: { + var prototype: { __proto__: typeof Vec; x: number; y: number; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff index 87331e3e75..ed8d9f8f75 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff @@ -30,7 +30,7 @@ - magnitude(): number; +export declare function Vec(len: number): void; +export declare namespace Vec { -+ const prototype: { ++ var prototype: { + /** + * @param {Vec} other + */ @@ -62,7 +62,7 @@ - __proto__: typeof Vec; +export declare function Point2D(x: number, y: number): any; +export declare namespace Point2D { -+ const prototype: { ++ var prototype: { + __proto__: typeof Vec; + x: number; + y: number; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index 01e43ad077..e3f53cb229 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -36,10 +36,10 @@ MyClass.staticProperty = 123; export = MyClass; declare function MyClass(): void; declare namespace MyClass { - const staticMethod: () => void; + var staticMethod: () => void; } declare namespace MyClass { - const staticProperty: number; + var staticProperty: number; } export type DoneCB = (failures: number) ; /** diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 7274ab2e2f..c52be93a6e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -23,10 +23,10 @@ -declare function staticMethod(): void; -declare var staticProperty: number; +declare namespace MyClass { -+ const staticMethod: () => void; ++ var staticMethod: () => void; +} +declare namespace MyClass { -+ const staticProperty: number; ++ var staticProperty: number; +} +export type DoneCB = (failures: number) ; /** diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js index 0afdb29769..8a62f4e062 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -18,10 +18,10 @@ module.exports = foo; //// [index.d.ts] declare function foo(): void; declare namespace foo { - const foo: typeof import("."); + var foo: typeof import("."); } declare namespace foo { - const _a: typeof import("."); + var _a: typeof import("."); export { _a as default }; } export = foo; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff index b9981c3481..9b567ef448 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff @@ -15,10 +15,10 @@ - export { foo }; - export { foo as default }; -} -+ const foo: typeof import("."); ++ var foo: typeof import("."); +} +declare namespace foo { -+ const _a: typeof import("."); ++ 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 3344f4abd7..8aa44cbc27 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -124,11 +124,11 @@ function j() { } export declare function a(): void; export declare function b(): void; export declare namespace b { - const cat: string; + var cat: string; } export declare function c(): void; export declare namespace c { - const Cls: { + var Cls: { new (): {}; }; } @@ -151,7 +151,7 @@ export declare function e(a: T, b: U): T & U; */ export declare function f(a: T): T; export declare namespace f { - const self: typeof f; + var self: typeof f; } /** * @param {{x: string}} a diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 5f33df2f7a..8e2b016ad7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -28,14 +28,14 @@ +export declare function a(): void; +export declare function b(): void; +export declare namespace b { -+ const cat: string; ++ var cat: string; } -export function c(): void; -export namespace c { - export { Cls }; +export declare function c(): void; +export declare namespace c { -+ const Cls: { ++ var Cls: { + new (): {}; + }; } @@ -67,7 +67,7 @@ -declare class Cls { +export declare function f(a: T): T; +export declare namespace f { -+ const self: typeof f; ++ var self: typeof f; } /** * @param {{x: string}} a diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js index 4848b43f5f..f707949cf4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -67,7 +67,7 @@ declare class Base { } declare function BaseFactory(): Base; declare namespace BaseFactory { - const Base: typeof Base; + var Base: typeof Base; } export = BaseFactory; //// [file.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff index 05f083572e..13850b4946 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -26,7 +26,7 @@ -} -declare class Base { -} -+ const Base: typeof Base; ++ var Base: typeof Base; +} +export = BaseFactory; //// [file.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js index 152f6ae9ea..25a713c08c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js @@ -55,7 +55,7 @@ declare class Base { } declare function BaseFactory(): Base; declare namespace BaseFactory { - const Base: typeof Base; + var Base: typeof Base; } export = BaseFactory; //// [file.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff index 7a0c146d6c..9f430cfe7a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff @@ -26,7 +26,7 @@ -} -declare class Base { -} -+ const Base: typeof Base; ++ var Base: typeof Base; +} +export = BaseFactory; //// [file.d.ts] diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index 0724599f44..41c2f8c81b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -188,12 +188,12 @@ exports.default = Tree; import PropTypes from "prop-types"; declare function TabbedShowLayout({}: {}): JSX.Element; declare namespace TabbedShowLayout { - const propTypes: { + var propTypes: { version: PropTypes.Requireable; }; } declare namespace TabbedShowLayout { - const defaultProps: { + var defaultProps: { tabs: undefined; }; } @@ -202,13 +202,13 @@ export default TabbedShowLayout; import React from "react"; declare function TabbedShowLayout(): JSX.Element; declare namespace TabbedShowLayout { - const defaultProps: Partial<{}> | undefined; + var defaultProps: Partial<{}> | undefined; } export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] declare function TabbedShowLayout(): JSX.Element; declare namespace TabbedShowLayout { - const defaultProps: { + var defaultProps: { tabs: string; }; } @@ -218,7 +218,7 @@ declare function TabbedShowLayout(/** @type {{className: string}}*/ prop: { className: string; }): JSX.Element; declare namespace TabbedShowLayout { - const defaultProps: { + var defaultProps: { tabs: string; }; } @@ -229,12 +229,12 @@ declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; declare namespace Tree { - const propTypes: { + var propTypes: { classes: PropTypes.Requireable; }; } declare namespace Tree { - const defaultProps: { + var defaultProps: { classes: {}; parentSource: string; }; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index 59c49d45a2..4e509eca1c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -66,12 +66,12 @@ import PropTypes from "prop-types"; +declare function TabbedShowLayout({}: {}): JSX.Element; +declare namespace TabbedShowLayout { -+ const propTypes: { ++ var propTypes: { + version: PropTypes.Requireable; + }; +} +declare namespace TabbedShowLayout { -+ const defaultProps: { ++ var defaultProps: { + tabs: undefined; + }; +} @@ -85,7 +85,7 @@ import React from "react"; +declare function TabbedShowLayout(): JSX.Element; +declare namespace TabbedShowLayout { -+ const defaultProps: Partial<{}> | undefined; ++ var defaultProps: Partial<{}> | undefined; +} +export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.d.ts] @@ -97,7 +97,7 @@ - defaultProps: { +declare function TabbedShowLayout(): JSX.Element; +declare namespace TabbedShowLayout { -+ const defaultProps: { ++ var defaultProps: { tabs: string; }; -} & ((props?: { @@ -115,7 +115,7 @@ - namespace defaultProps { - let tabs: string; - } -+ const defaultProps: { ++ var defaultProps: { + tabs: string; + }; } @@ -137,12 +137,12 @@ - } -} -import PropTypes from 'prop-types'; -+ const propTypes: { ++ var propTypes: { + classes: PropTypes.Requireable; + }; +} +declare namespace Tree { -+ const defaultProps: { ++ var defaultProps: { + classes: {}; + parentSource: string; + }; diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js index 2b53e12e04..3d7bf0d2a6 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js @@ -84,7 +84,7 @@ declare var Ns: { C5: any; }; declare namespace Ns { - const C1: { + var C1: { new (): { method(): number; }; @@ -114,5 +114,5 @@ declare class CC { } declare var C5: any; declare namespace Ns { - const C5: any; + 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 4aa7dcf871..7119367ce6 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff @@ -17,7 +17,7 @@ declare namespace Ns { - export { C1 }; - export let C5: { -+ const C1: { ++ var C1: { new (): { method(): number; }; @@ -49,5 +49,5 @@ -declare class C3 implements A { - method(): number; +declare namespace Ns { -+ const C5: any; ++ 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 f64da7a799..ab6060fccf 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js @@ -172,281 +172,281 @@ foo.of = 1; //// [nullPropertyName.d.ts] declare function foo(): void; declare namespace foo { - const x: number; + var x: number; } declare namespace foo { - const y: number; + var y: number; } declare namespace foo { - const _a: number; + var _a: number; export { _a as break }; } declare namespace foo { - const _b: number; + var _b: number; export { _b as case }; } declare namespace foo { - const _c: number; + var _c: number; export { _c as catch }; } declare namespace foo { - const _d: number; + var _d: number; export { _d as class }; } declare namespace foo { - const _e: number; + var _e: number; export { _e as const }; } declare namespace foo { - const _f: number; + var _f: number; export { _f as continue }; } declare namespace foo { - const _g: number; + var _g: number; export { _g as debugger }; } declare namespace foo { - const _h: number; + var _h: number; export { _h as default }; } declare namespace foo { - const _j: number; + var _j: number; export { _j as delete }; } declare namespace foo { - const _k: number; + var _k: number; export { _k as do }; } declare namespace foo { - const _l: number; + var _l: number; export { _l as else }; } declare namespace foo { - const _m: number; + var _m: number; export { _m as enum }; } declare namespace foo { - const _o: number; + var _o: number; export { _o as export }; } declare namespace foo { - const _p: number; + var _p: number; export { _p as extends }; } declare namespace foo { - const _q: number; + var _q: number; export { _q as false }; } declare namespace foo { - const _r: number; + var _r: number; export { _r as finally }; } declare namespace foo { - const _s: number; + var _s: number; export { _s as for }; } declare namespace foo { - const _t: number; + var _t: number; export { _t as function }; } declare namespace foo { - const _u: number; + var _u: number; export { _u as if }; } declare namespace foo { - const _v: number; + var _v: number; export { _v as import }; } declare namespace foo { - const _w: number; + var _w: number; export { _w as in }; } declare namespace foo { - const _x: number; + var _x: number; export { _x as instanceof }; } declare namespace foo { - const _y: number; + var _y: number; export { _y as new }; } declare namespace foo { - const _z: number; + var _z: number; export { _z as null }; } declare namespace foo { - const _0: number; + var _0: number; export { _0 as return }; } declare namespace foo { - const _1: number; + var _1: number; export { _1 as super }; } declare namespace foo { - const _2: number; + var _2: number; export { _2 as switch }; } declare namespace foo { - const _3: number; + var _3: number; export { _3 as this }; } declare namespace foo { - const _4: number; + var _4: number; export { _4 as throw }; } declare namespace foo { - const _5: number; + var _5: number; export { _5 as true }; } declare namespace foo { - const _6: number; + var _6: number; export { _6 as try }; } declare namespace foo { - const _7: number; + var _7: number; export { _7 as typeof }; } declare namespace foo { - const _8: number; + var _8: number; export { _8 as var }; } declare namespace foo { - const _9: number; + var _9: number; export { _9 as void }; } declare namespace foo { - const _10: number; + var _10: number; export { _10 as while }; } declare namespace foo { - const _11: number; + var _11: number; export { _11 as with }; } declare namespace foo { - const _12: number; + var _12: number; export { _12 as implements }; } declare namespace foo { - const _13: number; + var _13: number; export { _13 as interface }; } declare namespace foo { - const _14: number; + var _14: number; export { _14 as let }; } declare namespace foo { - const _15: number; + var _15: number; export { _15 as package }; } declare namespace foo { - const _16: number; + var _16: number; export { _16 as private }; } declare namespace foo { - const _17: number; + var _17: number; export { _17 as protected }; } declare namespace foo { - const _18: number; + var _18: number; export { _18 as public }; } declare namespace foo { - const _19: number; + var _19: number; export { _19 as static }; } declare namespace foo { - const _20: number; + var _20: number; export { _20 as yield }; } declare namespace foo { - const abstract: number; + var abstract: number; } declare namespace foo { - const as: number; + var as: number; } declare namespace foo { - const asserts: number; + var asserts: number; } declare namespace foo { - const any: number; + var any: number; } declare namespace foo { - const async: number; + var async: number; } declare namespace foo { - const await: number; + var await: number; } declare namespace foo { - const boolean: number; + var boolean: number; } declare namespace foo { - const constructor: number; + var constructor: number; } declare namespace foo { - const declare: number; + var declare: number; } declare namespace foo { - const get: number; + var get: number; } declare namespace foo { - const infer: number; + var infer: number; } declare namespace foo { - const is: number; + var is: number; } declare namespace foo { - const keyof: number; + var keyof: number; } declare namespace foo { - const module: number; + var module: number; } declare namespace foo { - const namespace: number; + var namespace: number; } declare namespace foo { - const never: number; + var never: number; } declare namespace foo { - const readonly: number; + var readonly: number; } declare namespace foo { - const require: number; + var require: number; } declare namespace foo { - const number: number; + var number: number; } declare namespace foo { - const object: number; + var object: number; } declare namespace foo { - const set: number; + var set: number; } declare namespace foo { - const string: number; + var string: number; } declare namespace foo { - const symbol: number; + var symbol: number; } declare namespace foo { - const type: number; + var type: number; } declare namespace foo { - const undefined: number; + var undefined: number; } declare namespace foo { - const unique: number; + var unique: number; } declare namespace foo { - const unknown: number; + var unknown: number; } declare namespace foo { - const from: number; + var from: number; } declare namespace foo { - const global: number; + var global: number; } declare namespace foo { - const bigint: number; + var bigint: number; } declare namespace foo { - const of: number; + var of: number; } diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff index 386fe72392..a2d826927d 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff @@ -6,358 +6,313 @@ 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; -- export var abstract: number; -- export var as: number; -- export var asserts: number; -- export var any: number; -- export var async: number; -- export var await: number; -- export var boolean: number; -- export var constructor: number; -- export var declare: number; -- export var get: number; -- export var infer: number; -- export var is: number; -- export var keyof: number; -- export var module: number; -- export var namespace: number; -- export var never: number; -- export var readonly: number; -- export var require: number; -- export var number: number; -- export var object: number; -- export var set: number; -- export var string: number; -- export var symbol: number; -- export var type: number; -- export var undefined: number; -- export var unique: number; -- export var unknown: number; -- export var from: number; -- export var global: number; -- 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 }; -+ const x: number; ++ var x: number; +} +declare namespace foo { -+ const y: number; ++ var y: number; +} +declare namespace foo { -+ const _a: number; + var _a: number; + export { _a as break }; +} +declare namespace foo { -+ const _b: number; + var _b: number; + export { _b as case }; +} +declare namespace foo { -+ const _c: number; + var _c: number; + export { _c as catch }; +} +declare namespace foo { -+ const _d: number; + var _d: number; + export { _d as class }; +} +declare namespace foo { -+ const _e: number; + var _e: number; + export { _e as const }; +} +declare namespace foo { -+ const _f: number; + var _f: number; + export { _f as continue }; +} +declare namespace foo { -+ const _g: number; + var _g: number; + export { _g as debugger }; +} +declare namespace foo { -+ const _h: number; + var _h: number; + export { _h as default }; +} +declare namespace foo { -+ const _j: number; + var _j: number; + export { _j as delete }; +} +declare namespace foo { -+ const _k: number; + var _k: number; + export { _k as do }; +} +declare namespace foo { -+ const _l: number; + var _l: number; + export { _l as else }; +} +declare namespace foo { -+ const _m: number; + var _m: number; + export { _m as enum }; +} +declare namespace foo { -+ const _o: number; + var _o: number; + export { _o as export }; +} +declare namespace foo { -+ const _p: number; + var _p: number; + export { _p as extends }; +} +declare namespace foo { -+ const _q: number; + var _q: number; + export { _q as false }; +} +declare namespace foo { -+ const _r: number; + var _r: number; + export { _r as finally }; +} +declare namespace foo { -+ const _s: number; + var _s: number; + export { _s as for }; +} +declare namespace foo { -+ const _t: number; + var _t: number; + export { _t as function }; +} +declare namespace foo { -+ const _u: number; + var _u: number; + export { _u as if }; +} +declare namespace foo { -+ const _v: number; + var _v: number; + export { _v as import }; +} +declare namespace foo { -+ const _w: number; + var _w: number; + export { _w as in }; +} +declare namespace foo { -+ const _x: number; + var _x: number; + export { _x as instanceof }; +} +declare namespace foo { -+ const _y: number; + var _y: number; + export { _y as new }; +} +declare namespace foo { -+ const _z: number; + var _z: number; + export { _z as null }; +} +declare namespace foo { -+ const _0: number; + var _0: number; + export { _0 as return }; +} +declare namespace foo { -+ const _1: number; + var _1: number; + export { _1 as super }; +} +declare namespace foo { -+ const _2: number; + var _2: number; + export { _2 as switch }; +} +declare namespace foo { -+ const _3: number; + var _3: number; + export { _3 as this }; +} +declare namespace foo { -+ const _4: number; + var _4: number; + export { _4 as throw }; +} +declare namespace foo { -+ const _5: number; + var _5: number; + export { _5 as true }; +} +declare namespace foo { -+ const _6: number; + var _6: number; + export { _6 as try }; +} +declare namespace foo { -+ const _7: number; + var _7: number; + export { _7 as typeof }; +} +declare namespace foo { -+ const _8: number; + var _8: number; + export { _8 as var }; +} +declare namespace foo { -+ const _9: number; + var _9: number; + export { _9 as void }; +} +declare namespace foo { -+ const _10: number; + var _10: number; + export { _10 as while }; +} +declare namespace foo { -+ const _11: number; + var _11: number; + export { _11 as with }; +} +declare namespace foo { -+ const _12: number; + var _12: number; + export { _12 as implements }; +} +declare namespace foo { -+ const _13: number; + var _13: number; + export { _13 as interface }; +} +declare namespace foo { -+ const _14: number; + var _14: number; + export { _14 as let }; +} +declare namespace foo { -+ const _15: number; + var _15: number; + export { _15 as package }; +} +declare namespace foo { -+ const _16: number; + var _16: number; + export { _16 as private }; +} +declare namespace foo { -+ const _17: number; + var _17: number; + export { _17 as protected }; +} +declare namespace foo { -+ const _18: number; + var _18: number; + export { _18 as public }; +} +declare namespace foo { -+ const _19: number; + var _19: number; + export { _19 as static }; +} +declare namespace foo { -+ const _20: number; + var _20: number; +- export var abstract: number; +- export var as: number; +- export var asserts: number; +- export var any: number; +- export var async: number; +- export var await: number; +- export var boolean: number; +- export var constructor: number; +- export var declare: number; +- export var get: number; +- export var infer: number; +- export var is: number; +- export var keyof: number; +- export var module: number; +- export var namespace: number; +- export var never: number; +- export var readonly: number; +- export var require: number; +- export var number: number; +- export var object: number; +- export var set: number; +- export var string: number; +- export var symbol: number; +- export var type: number; +- export var undefined: number; +- export var unique: number; +- export var unknown: number; +- export var from: number; +- export var global: number; +- 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 }; + export { _20 as yield }; +} +declare namespace foo { -+ const abstract: number; ++ var abstract: number; +} +declare namespace foo { -+ const as: number; ++ var as: number; +} +declare namespace foo { -+ const asserts: number; ++ var asserts: number; +} +declare namespace foo { -+ const any: number; ++ var any: number; +} +declare namespace foo { -+ const async: number; ++ var async: number; +} +declare namespace foo { -+ const await: number; ++ var await: number; +} +declare namespace foo { -+ const boolean: number; ++ var boolean: number; +} +declare namespace foo { -+ const constructor: number; ++ var constructor: number; +} +declare namespace foo { -+ const declare: number; ++ var declare: number; +} +declare namespace foo { -+ const get: number; ++ var get: number; +} +declare namespace foo { -+ const infer: number; ++ var infer: number; +} +declare namespace foo { -+ const is: number; ++ var is: number; +} +declare namespace foo { -+ const keyof: number; ++ var keyof: number; +} +declare namespace foo { -+ const module: number; ++ var module: number; +} +declare namespace foo { -+ const namespace: number; ++ var namespace: number; +} +declare namespace foo { -+ const never: number; ++ var never: number; +} +declare namespace foo { -+ const readonly: number; ++ var readonly: number; +} +declare namespace foo { -+ const require: number; ++ var require: number; +} +declare namespace foo { -+ const number: number; ++ var number: number; +} +declare namespace foo { -+ const object: number; ++ var object: number; +} +declare namespace foo { -+ const set: number; ++ var set: number; +} +declare namespace foo { -+ const string: number; ++ var string: number; +} +declare namespace foo { -+ const symbol: number; ++ var symbol: number; +} +declare namespace foo { -+ const type: number; ++ var type: number; +} +declare namespace foo { -+ const undefined: number; ++ var undefined: number; +} +declare namespace foo { -+ const unique: number; ++ var unique: number; +} +declare namespace foo { -+ const unknown: number; ++ var unknown: number; +} +declare namespace foo { -+ const from: number; ++ var from: number; +} +declare namespace foo { -+ const global: number; ++ var global: number; +} +declare namespace foo { -+ const bigint: number; ++ var bigint: number; +} +declare namespace foo { -+ const of: number; ++ 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 addcac20cb..b31808bd20 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -171,15 +171,15 @@ var n = ExpandoExpr3.prop + ExpandoExpr3.m(13) + new ExpandoExpr3().n; //// [typeFromPropertyAssignment29.d.ts] declare function ExpandoDecl(n: number): string; declare namespace ExpandoDecl { - const prop: number; + var prop: number; } declare namespace ExpandoDecl { - const m: (n: number) => number; + var m: (n: number) => number; } declare var n: number; declare function ExpandoExpr(n: number): string; declare namespace ExpandoExpr { - const prop: { + var prop: { x: number; y?: undefined; } | { @@ -188,7 +188,7 @@ declare namespace ExpandoExpr { }; } declare namespace ExpandoExpr { - const prop: { + var prop: { x: number; y?: undefined; } | { @@ -197,26 +197,26 @@ declare namespace ExpandoExpr { }; } declare namespace ExpandoExpr { - const m: (n: number) => number; + var m: (n: number) => number; } declare var n: number; declare function ExpandoArrow(n: number): string; declare namespace ExpandoArrow { - const prop: number; + var prop: number; } declare namespace ExpandoArrow { - const m: (n: number) => number; + var m: (n: number) => number; } declare function ExpandoNested(n: number): { (m: number): number; total: number; }; declare namespace ExpandoNested { - const also: number; + var also: number; } declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { - const p1: number; + var p1: number; } declare namespace ExpandoMerge { var p2: number; @@ -228,7 +228,7 @@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; declare namespace ExpandoNamespace { - const p6: number; + 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 376ddaac95..c3bef5520a 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -31,11 +31,10 @@ }; ExpandoExpr3.prop = 3; ExpandoExpr3.m = function (n) { -@@= skipped -14, +12 lines =@@ - //// [typeFromPropertyAssignment29.d.ts] +@@= skipped -15, +13 lines =@@ declare function ExpandoDecl(n: number): string; declare namespace ExpandoDecl { -- var prop: number; + var prop: number; - var m: (n: number) => number; -} -declare var n: number; @@ -56,15 +55,14 @@ - prop: number; - m(n: number): number; -}; -+ const prop: number; +} +declare namespace ExpandoDecl { -+ const m: (n: number) => number; ++ var m: (n: number) => number; +} +declare var n: number; +declare function ExpandoExpr(n: number): string; +declare namespace ExpandoExpr { -+ const prop: { ++ var prop: { + x: number; + y?: undefined; + } | { @@ -73,7 +71,7 @@ + }; +} +declare namespace ExpandoExpr { -+ const prop: { ++ var prop: { + x: number; + y?: undefined; + } | { @@ -82,39 +80,25 @@ + }; +} +declare namespace ExpandoExpr { -+ const m: (n: number) => number; ++ var m: (n: number) => number; +} +declare var n: number; +declare function ExpandoArrow(n: number): string; +declare namespace ExpandoArrow { -+ const prop: number; ++ var prop: number; +} +declare namespace ExpandoArrow { -+ const m: (n: number) => number; ++ var m: (n: number) => number; +} declare function ExpandoNested(n: number): { (m: number): number; total: number; - }; - declare namespace ExpandoNested { -- var also: number; -+ const also: number; - } - declare function ExpandoMerge(n: number): number; - declare namespace ExpandoMerge { -- var p1: number; -+ const p1: number; - } - declare namespace ExpandoMerge { - var p2: number; -@@= skipped -41, +56 lines =@@ +@@= skipped -40, +55 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; - namespace ExpandoNamespace { -- var p6: number; + declare namespace ExpandoNamespace { -+ const p6: number; + var p6: number; } - export function foo(): typeof ExpandoNamespace; - export {}; \ No newline at end of file + 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 ad20a595df..32c4d0ca60 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js @@ -15,12 +15,12 @@ declare const foo: { }; }; declare namespace foo { - const baz: { + var baz: { blah: number; }; } declare namespace foo { - const blah: number; + var blah: number; } @@ -43,13 +43,13 @@ a.d.ts(11,19): error TS2451: Cannot redeclare block-scoped variable 'foo'. declare namespace foo { ~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'foo'. - const baz: { + var baz: { blah: number; }; } declare namespace foo { ~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'foo'. - const blah: number; + 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 c783abb722..0c5a6e3a9d 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment39.js.diff @@ -15,12 +15,12 @@ + }; +}; +declare namespace foo { -+ const baz: { ++ var baz: { + blah: number; + }; +} +declare namespace foo { -+ const blah: number; ++ var blah: number; +} + + @@ -43,13 +43,13 @@ + declare namespace foo { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. -+ const baz: { ++ var baz: { + blah: number; + }; + } + declare namespace foo { + ~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'foo'. -+ const blah: number; ++ 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 4cee856754..c6a71ddc88 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js @@ -31,7 +31,7 @@ map4.__underscores__(); //// [a.d.ts] declare function Multimap4(): void; declare namespace Multimap4 { - const prototype: { + var prototype: { /** * @param {string} key * @returns {number} the value ok diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff index db21e270df..1e1f280301 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff @@ -15,7 +15,7 @@ - addon(): void; - __underscores__(): void; +declare namespace Multimap4 { -+ const prototype: { ++ var prototype: { + /** + * @param {string} key + * @returns {number} the value ok