From e5d6bdedb0f652bc5c9cb7ad6984a93c3fc4b7dd Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Sun, 13 Jul 2025 15:33:54 +0300 Subject: [PATCH 1/9] fix(1374): support declaration emit for expando functions --- internal/ast/utilities.go | 90 +++++++- internal/checker/emitresolver.go | 53 ++++- internal/parser/parser.go | 14 +- internal/printer/emitresolver.go | 1 + .../transformers/declarations/transform.go | 200 +++++++++++++++++- .../declarationEmitExpandoFunction.js | 37 ++++ .../declarationEmitExpandoFunction.symbols | 22 ++ .../declarationEmitExpandoFunction.types | 24 +++ ...onEmitDefaultExportWithStaticAssignment.js | 26 ++- ...tDefaultExportWithStaticAssignment.js.diff | 45 ++-- ...nEmitExpandoPropertyPrivateName.errors.txt | 14 ++ ...ExpandoPropertyPrivateName.errors.txt.diff | 22 +- ...clarationEmitExpandoPropertyPrivateName.js | 4 + ...tionEmitExpandoPropertyPrivateName.js.diff | 11 +- .../declarationEmitFunctionKeywordProp.js | 13 ++ ...declarationEmitFunctionKeywordProp.js.diff | 23 +- .../declarationEmitLateBoundAssignments.js | 5 + ...eclarationEmitLateBoundAssignments.js.diff | 13 +- .../declarationEmitLateBoundAssignments2.js | 14 ++ ...clarationEmitLateBoundAssignments2.js.diff | 32 --- .../declarationEmitLateBoundJSAssignments.js | 5 + ...larationEmitLateBoundJSAssignments.js.diff | 8 +- .../compiler/expandoFunctionBlockShadowing.js | 3 + .../expandoFunctionBlockShadowing.js.diff | 4 +- .../expandoFunctionNestedAssigments.js | 27 +++ .../expandoFunctionNestedAssigments.js.diff | 35 --- ...xDeclarationsWithEsModuleInteropNoCrash.js | 25 ++- ...arationsWithEsModuleInteropNoCrash.js.diff | 26 ++- ...undFunctionMemberAssignmentDeclarations.js | 4 + ...nctionMemberAssignmentDeclarations.js.diff | 12 +- .../conformance/exportDefaultNamespace.js | 7 +- .../exportDefaultNamespace.js.diff | 14 +- .../conformance/jsDeclarationsClassMethod.js | 3 + .../jsDeclarationsClassMethod.js.diff | 8 +- .../jsDeclarationsFunctionKeywordProp.js | 13 ++ .../jsDeclarationsFunctionKeywordProp.js.diff | 22 +- ...clarationsFunctionKeywordPropExhaustive.js | 81 +++++++ ...tionsFunctionKeywordPropExhaustive.js.diff | 86 +++++++- .../jsDeclarationsFunctionLikeClasses2.js | 17 ++ ...jsDeclarationsFunctionLikeClasses2.js.diff | 19 +- .../conformance/jsDeclarationsFunctions.js | 11 + .../jsDeclarationsFunctions.js.diff | 20 +- .../jsDeclarationsReactComponents.js | 27 ++- .../jsDeclarationsReactComponents.js.diff | 29 ++- .../submodule/conformance/nullPropertyName.js | 81 +++++++ .../conformance/nullPropertyName.js.diff | 87 -------- .../typeFromPropertyAssignment29.js | 13 ++ .../typeFromPropertyAssignment29.js.diff | 34 +-- .../typeFromPrototypeAssignment4.js | 9 + .../typeFromPrototypeAssignment4.js.diff | 10 +- .../declarationEmitExpandoFunction.ts | 11 + 51 files changed, 1080 insertions(+), 334 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 delete mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff delete mode 100644 testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff delete mode 100644 testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff create mode 100644 testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 5c5fd2314d..2f9820a282 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -1348,7 +1348,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 { @@ -2817,10 +2817,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 @@ -2924,6 +2920,14 @@ func IsContextualKeyword(token Kind) bool { return KindFirstContextualKeyword <= token && token <= KindLastContextualKeyword } +func IsKeyword(token Kind) bool { + return KindFirstKeyword <= token && token <= KindLastKeyword +} + +func IsNonContextualKeyword(token Kind) bool { + return IsKeyword(token) && !IsContextualKeyword(token) +} + func IsThisInTypeQuery(node *Node) bool { if !IsThisIdentifier(node) { return false @@ -3633,3 +3637,79 @@ func GetSemanticJsxChildren(children []*JsxChild) []*JsxChild { } }) } + +func IsExpandoPropertyDeclaration(node *Node) bool { + if node == nil { + return false + } + return IsPropertyAccessExpression(node) || IsElementAccessExpression(node) || IsBinaryExpression(node) +} + +func GetExpandoInitializer(initializer *Node, isPrototypeAssignment bool) *Node { + if initializer.Kind == KindCallExpression { + expr := SkipParentheses(initializer.Expression()) + if expr.Kind == KindFunctionExpression || expr.Kind == KindArrowFunction { + return initializer + } + return nil + } + + if initializer.Kind == KindFunctionExpression || initializer.Kind == KindCallExpression || initializer.Kind == KindArrowFunction { + return initializer + } + + if initializer.Kind == KindObjectLiteralExpression && (len(initializer.Properties()) == 0 || isPrototypeAssignment) { + return initializer + } + + return nil +} + +func GetEffectiveInitializer(node *Node) *Expression { + if IsInJSFile(node) && node.Initializer() != nil && IsBinaryExpression(node.Initializer()) { + initializer := node.Initializer().AsBinaryExpression() + if initializer.OperatorToken.Kind == KindBarBarToken || initializer.OperatorToken.Kind == KindQuestionQuestionToken { + if node.Name() != nil && IsEntityNameExpressionEx(node.Name(), IsInJSFile(node)) && IsSameEntityName(node.Name(), initializer.Left) { + return initializer.Right + } + } + } + return node.Initializer() +} + +func GetDeclaredExpandoInitializer(node *Node) *Expression { + initializer := GetEffectiveInitializer(node) + if initializer == nil { + return nil + } + return GetExpandoInitializer(initializer, IsPrototypeAccess(node.Name())) +} + +func IsPrototypeAccess(node *Node) bool { + return IsBindableStaticAccessExpression(node, false /*excludeThisKeyword*/) +} + +func IsLiteralLikeAccess(node *Node) bool { + return IsPropertyAccessExpression(node) || IsLiteralLikeElementAccess(node) +} + +func GetNameOrArgument(node *Expression) *Expression { + if IsPropertyAccessExpression(node) { + return node.Name() + } + return node.AsElementAccessExpression().ArgumentExpression +} + +func IsSameEntityName(name *Expression, initializer *Expression) bool { + if IsPropertyNameLiteral(name) && IsPropertyNameLiteral(initializer) { + return name.Text() == initializer.Text() + } + if IsMemberName(name) && IsLiteralLikeAccess(initializer) && (initializer.Expression().Kind == KindThisKeyword || IsIdentifier(initializer.Expression()) && + (initializer.Expression().Text() == "window" || initializer.Expression().Text() == "self" || initializer.Expression().Text() == "global")) { + return IsSameEntityName(name, GetNameOrArgument(initializer)) + } + if IsLiteralLikeAccess(name) && IsLiteralLikeAccess(initializer) { + return GetElementOrPropertyAccessName(name) == GetElementOrPropertyAccessName(initializer) && IsSameEntityName(name.Expression(), initializer.Expression()) + } + return false +} diff --git a/internal/checker/emitresolver.go b/internal/checker/emitresolver.go index 38a7812f65..34f614e51d 100644 --- a/internal/checker/emitresolver.go +++ b/internal/checker/emitresolver.go @@ -605,8 +605,40 @@ func (r *emitResolver) IsLiteralConstDeclaration(node *ast.Node) bool { } func (r *emitResolver) IsExpandoFunctionDeclaration(node *ast.Node) bool { - // node = r.emitContext.ParseNode(node) - // !!! TODO: expando function support + if !ast.IsParseTreeNode(node) { + return false + } + + var symbol *ast.Symbol + if ast.IsVariableDeclaration(node) { + if node.Type() != nil || (!ast.IsInJSFile(node) && !ast.IsVarConstLike(node)) { + return false + } + initializer := ast.GetDeclaredExpandoInitializer(node) + if initializer == nil || !ast.CanHaveSymbol(initializer) { + return false + } + symbol = r.checker.getSymbolOfDeclaration(initializer) + } else if ast.IsFunctionDeclaration(node) { + symbol = r.checker.getSymbolOfDeclaration(node) + } + + if symbol == nil || (symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsVariable)) == 0 { + return false + } + + exports := r.checker.getExportsOfSymbol(symbol) + for _, p := range exports { + if p.Flags&ast.SymbolFlagsValue == 0 { + continue + } + if p.ValueDeclaration == nil { + continue + } + if ast.IsExpandoPropertyDeclaration(p.ValueDeclaration) { + return true + } + } return false } @@ -847,6 +879,23 @@ func (r *emitResolver) GetReferencedValueDeclarations(node *ast.IdentifierNode) return r.getReferenceResolver().GetReferencedValueDeclarations(node) } +func (r *emitResolver) GetPropertiesOfContainerFunction(node *ast.Node) []*ast.Symbol { + props := []*ast.Symbol{} + + if !ast.IsParseTreeNode(node) { + return props + } + + if ast.IsFunctionDeclaration(node) { + symbol := r.checker.getSymbolOfDeclaration(node) + if symbol == nil { + return props + } + props = r.checker.getPropertiesOfType(r.checker.getTypeOfSymbol(symbol)) + } + return props +} + // 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/parser/parser.go b/internal/parser/parser.go index 6cc354802a..ec4f2c9679 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -293,7 +293,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) } @@ -641,7 +641,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) @@ -659,7 +659,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) @@ -2376,7 +2376,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 @@ -6011,7 +6011,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 @@ -6411,10 +6411,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/printer/emitresolver.go b/internal/printer/emitresolver.go index f8a1f6c842..8acf810986 100644 --- a/internal/printer/emitresolver.go +++ b/internal/printer/emitresolver.go @@ -34,6 +34,7 @@ type EmitResolver interface { GetExternalModuleFileFromDeclaration(node *ast.Node) *ast.SourceFile GetEffectiveDeclarationFlags(node *ast.Node, flags ast.ModifierFlags) ast.ModifierFlags GetResolutionModeOverride(node *ast.Node) core.ResolutionMode + GetPropertiesOfContainerFunction(node *ast.Node) []*ast.Symbol // JSX Emit GetJsxFactoryEntity(location *ast.Node) *ast.Node diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 52b09dedcb..ae0bf07541 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -61,6 +61,11 @@ type DeclarationTransformer struct { rawLibReferenceDirectives []*ast.FileReference } +type ExportMapping struct { + PropertyName *ast.Identifier + Name string +} + func NewDeclarationTransformer(host DeclarationEmitHost, context *printer.EmitContext, compilerOptions *core.CompilerOptions, declarationFilePath string, declarationMapPath string) *DeclarationTransformer { resolver := host.GetEmitResolver() state := &SymbolTrackerSharedState{isolatedDeclarations: compilerOptions.IsolatedDeclarations.IsTrue(), resolver: resolver} @@ -1143,17 +1148,192 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi tx.ensureType(input.AsNode(), false), nil, ) - if updated == nil || !tx.resolver.IsExpandoFunctionDeclaration(input.AsNode()) || !shouldEmitFunctionProperties(input) { - return updated - } - // Add expando function properties to result + if updated != nil && tx.state.resolver.IsExpandoFunctionDeclaration(input.AsNode()) && shouldEmitFunctionProperties(input) { + props := tx.state.resolver.GetPropertiesOfContainerFunction(input.AsNode()) + if tx.state.isolatedDeclarations { + // TODO: reportExpandoFunctionErrors + return updated + } - // !!! TODO: expando function support - // props := tx.resolver.GetPropertiesOfContainerFunction(input) - // if tx.state.isolatedDeclarations { - // tx.state.reportExpandoFunctionErrors(input.AsNode()) - // } - return updated // !!! + synthesizedModuleDeclaration := tx.Factory().NewModuleDeclaration( + nil, /*modifiers*/ + ast.KindNamespaceKeyword, + core.IfElse(input.Name() == nil, tx.Factory().NewIdentifier("_default"), input.Name()), + nil, /*body*/ + ) + synthesizedModuleDeclaration.Parent = tx.enclosingDeclaration + declarationData := synthesizedModuleDeclaration.DeclarationData() + + parent := core.FirstOrNil(props) + if parent != nil { + declarationData.Symbol = &ast.Symbol{ + Name: parent.Name, + Flags: ast.SymbolFlagsNamespaceModule, + } + } + + symbolTable := make(ast.SymbolTable, len(props)) + for _, p := range props { + symbolTable[p.Name] = p + } + + containerData := synthesizedModuleDeclaration.LocalsContainerData() + containerData.Locals = symbolTable + + exportMappings := []ExportMapping{} + declarations := []*ast.Statement{} + + for _, p := range props { + if p.ValueDeclaration == nil { + continue + } + if !ast.IsExpandoPropertyDeclaration(p.ValueDeclaration) { + continue + } + if !scanner.IsIdentifierText(p.Name, core.LanguageVariantStandard) { + continue + } + + saveDiag := tx.state.getSymbolAccessibilityDiagnostic + tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p.ValueDeclaration) + + t := tx.resolver.CreateTypeOfDeclaration( + tx.EmitContext(), + p.ValueDeclaration, + synthesizedModuleDeclaration, + declarationEmitNodeBuilderFlags, + declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, + tx.tracker, + ) + + tx.state.getSymbolAccessibilityDiagnostic = saveDiag + + nameToken := scanner.StringToToken(p.Name) + isNonContextualKeywordName := ast.IsNonContextualKeyword(nameToken) + + name := core.IfElse( + isNonContextualKeywordName, + tx.Factory().NewGeneratedNameForNode(p.ValueDeclaration), + tx.Factory().NewIdentifier(p.Name), + ) + + if isNonContextualKeywordName { + exportMappings = append(exportMappings, ExportMapping{ + PropertyName: name.AsIdentifier(), + Name: p.Name, + }) + } + + variableDeclaration := tx.Factory().NewVariableDeclaration( + name, + nil, /*exclamationToken*/ + t, + nil, /*initializer*/ + ) + + declarations = append(declarations, + tx.Factory().NewVariableStatement( + core.IfElse( + isNonContextualKeywordName, + nil, + tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindExportKeyword)}), + ), + tx.Factory().NewVariableDeclarationList( + ast.NodeFlagsNone, + tx.Factory().NewNodeList([]*ast.Node{variableDeclaration}), + ), + ), + ) + } + + if len(exportMappings) == 0 { + for i, declaration := range declarations { + modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(ast.ModifierFlagsNone, tx.Factory().NewModifier)) + declarations[i] = ast.ReplaceModifiers(tx.Factory().AsNodeFactory(), declaration, modifiers) + } + } else { + exportSpecifiers := make([]*ast.Node, 0, len(exportMappings)) + for _, mapping := range exportMappings { + exportSpecifiers = append(exportSpecifiers, + tx.Factory().NewExportSpecifier( + false, /*isTypeOnly*/ + mapping.PropertyName.AsNode(), + tx.Factory().NewIdentifier(mapping.Name), + ), + ) + } + + exportDeclaration := tx.Factory().NewExportDeclaration( + nil, /*modifiers*/ + false, /*isTypeOnly*/ + tx.Factory().NewNamedExports(tx.Factory().NewNodeList(exportSpecifiers)), + nil, /*moduleSpecifier*/ + nil, /*attributes*/ + ) + + declarations = append(declarations, exportDeclaration) + } + + namespaceDeclaration := tx.Factory().NewModuleDeclaration( + tx.ensureModifiers(input.AsNode()), + ast.KindNamespaceKeyword, + input.Name(), + tx.Factory().NewModuleBlock(tx.Factory().NewNodeList(declarations)), + ) + + if tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsDefault) == 0 { + return tx.Factory().NewSyntaxList([]*ast.Node{ + updated, + namespaceDeclaration, + }) + } + + modifiers := tx.Factory().NewModifierList( + ast.CreateModifiersFromModifierFlags( + (updated.ModifierFlags()&^ast.ModifierFlagsExportDefault)|ast.ModifierFlagsAmbient, + tx.Factory().NewModifier, + ), + ) + + updatedFunctionDeclaration := tx.Factory().UpdateFunctionDeclaration( + updated.AsFunctionDeclaration(), + modifiers, + nil, /*asteriskToken*/ + updated.Name(), + updated.TypeParameterList(), + updated.ParameterList(), + updated.Type(), + nil, /*body*/ + ) + + updatedNamespaceDeclaration := tx.Factory().UpdateModuleDeclaration( + namespaceDeclaration.AsModuleDeclaration(), + modifiers, + namespaceDeclaration.Kind, + namespaceDeclaration.Name(), + namespaceDeclaration.Body(), + ) + + exportDefaultDeclaration := tx.Factory().NewExportAssignment( + nil, /*modifiers*/ + false, /*isExportEquals*/ + nil, /*typeNode*/ + namespaceDeclaration.Name(), + ) + + if ast.IsSourceFile(input.Parent) { + tx.resultHasExternalModuleIndicator = true + } + + tx.resultHasScopeMarker = false + + return tx.Factory().NewSyntaxList([]*ast.Node{ + updatedFunctionDeclaration, + updatedNamespaceDeclaration, + exportDefaultDeclaration, + }) + } + return updated } func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDeclaration) *ast.Node { diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js new file mode 100644 index 0000000000..f72463565d --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +//// [declarationEmitExpandoFunction.ts] +export function A() { + return 'A'; +} + +export enum B { + C +} + +A.B = B; + + +//// [declarationEmitExpandoFunction.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.B = void 0; +exports.A = A; +function A() { + return 'A'; +} +var B; +(function (B) { + B[B["C"] = 0] = "C"; +})(B || (exports.B = B = {})); +A.B = B; + + +//// [declarationEmitExpandoFunction.d.ts] +export declare function A(): string; +export declare namespace A { + var B: typeof import("./declarationEmitExpandoFunction").B; +} +export declare enum B { + C = 0 +} diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols new file mode 100644 index 0000000000..be4c55ce7b --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +=== declarationEmitExpandoFunction.ts === +export function A() { +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) + + return 'A'; +} + +export enum B { +>B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 2, 1)) + + C +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 4, 15)) +} + +A.B = B; +>A.B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 6, 1)) +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) +>B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 6, 1)) +>B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 2, 1)) + diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types new file mode 100644 index 0000000000..813600b90e --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +=== declarationEmitExpandoFunction.ts === +export function A() { +>A : { (): string; B: typeof B; } + + return 'A'; +>'A' : "A" +} + +export enum B { +>B : B + + C +>C : B.C +} + +A.B = B; +>A.B = B : typeof B +>A.B : typeof B +>A : { (): string; B: typeof B; } +>B : typeof B +>B : typeof B + diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index 345ebd102f..2cd7667fa1 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -82,14 +82,34 @@ C.B = B; export declare class Foo { } //// [index1.d.ts] -export default function Example(): void; +declare function Example(): void; +declare module Example { + var Foo: typeof import("./foo").Foo; +} +export default Example; +export {}; //// [index2.d.ts] import { Foo } from './foo'; export { Foo }; -export default function Example(): void; +declare function Example(): void; +declare module Example { + var Foo: typeof import("./foo").Foo; +} +export default Example; +export {}; //// [index3.d.ts] export declare class Bar { } -export default function Example(): void; +declare function Example(): void; +declare module Example { + var Bar: typeof import("./index3").Bar; +} +export default Example; +export {}; //// [index4.d.ts] export declare function C(): any; +export declare namespace C { + var A: () => void; + var B: () => void; +} +export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index ff4abd456f..808771678f 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -18,37 +18,40 @@ 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 function Example(): void; -declare namespace Example { -- var Foo: typeof import("./foo").Foo; --} --export default Example; -+export default function Example(): void; ++declare module Example { + var Foo: typeof import("./foo").Foo; + } + export default Example; ++export {}; //// [index2.d.ts] import { Foo } from './foo'; export { Foo }; --declare function Example(): void; + declare function Example(): void; -declare namespace Example { -- var Foo: typeof import("./foo").Foo; --} --export default Example; -+export default function Example(): void; ++declare module Example { + var Foo: typeof import("./foo").Foo; + } + export default Example; ++export {}; //// [index3.d.ts] export declare class Bar { } --declare function Example(): void; + declare function Example(): void; -declare namespace Example { -- var Bar: typeof import("./index3").Bar; --} --export default Example; -+export default function Example(): void; ++declare module Example { + var Bar: typeof import("./index3").Bar; + } + export default Example; ++export {}; //// [index4.d.ts] export declare function C(): any; --export declare namespace C { -- var A: () => void; -- var B: () => void; --} \ No newline at end of file + export declare namespace C { + var A: () => void; + var B: () => void; + } ++export {}; \ 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..bd91348197 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js @@ -31,3 +31,7 @@ export declare function f(): I; export {}; //// [b.d.ts] export declare function q(): void; +export declare namespace q { + var val: I; +} +export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff index e97c240744..5f99ced399 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff @@ -9,9 +9,14 @@ function q() { } q.val = (0, a_1.f)(); -@@= skipped -10, +10 lines =@@ +@@= skipped -9, +9 lines =@@ + interface I { } export declare function f(): I; - export {}; ++export {}; +//// [b.d.ts] -+export declare function q(): void; \ No newline at end of file ++export declare function q(): void; ++export declare namespace q { ++ var val: I; ++} + export {}; \ 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..8b715fb902 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js @@ -25,5 +25,18 @@ baz.normal = false; //// [declarationEmitFunctionKeywordProp.d.ts] declare function foo(): void; +declare namespace foo { + var _a: boolean; + export { _a as null }; +} declare function bar(): void; +declare namespace bar { + var async: boolean; + var normal: boolean; +} declare function baz(): void; +declare namespace baz { + var _b: boolean; + export var normal: boolean; + export { _b as class }; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff index 5628351b23..e5e1c06f43 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -1,21 +1,12 @@ --- old.declarationEmitFunctionKeywordProp.js +++ new.declarationEmitFunctionKeywordProp.js -@@= skipped -24, +24 lines =@@ - - //// [declarationEmitFunctionKeywordProp.d.ts] - declare function foo(): void; --declare namespace foo { -- var _a: boolean; -- export { _a as null }; --} - declare function bar(): void; --declare namespace bar { -- var async: boolean; -- var normal: boolean; --} +@@= skipped -35, +35 lines =@@ + } declare function baz(): void; --declare namespace baz { + declare namespace baz { - var _a: boolean; -- export var normal: boolean; ++ var _b: boolean; + export var normal: boolean; - export { _a as class }; --} \ No newline at end of file ++ export { _b as class }; + } \ 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..ad83eff151 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -36,3 +36,8 @@ const a = foo[dashStrMem]; //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; +export declare namespace foo { + var bar: number; + var strMemName: string; +} +export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 9b5edc4ae8..c6017e172f 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff @@ -1,10 +1,7 @@ --- old.declarationEmitLateBoundAssignments.js +++ new.declarationEmitLateBoundAssignments.js -@@= skipped -35, +35 lines =@@ - - //// [declarationEmitLateBoundAssignments.d.ts] - export declare function foo(): void; --export declare namespace foo { -- var bar: number; -- var strMemName: string; --} \ No newline at end of file +@@= skipped -39, +39 lines =@@ + var bar: number; + var strMemName: string; + } ++export {}; \ 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..1b15043502 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js @@ -121,15 +121,29 @@ arrow10[emoji] = 0; //// [declarationEmitLateBoundAssignments2.d.ts] export declare function decl(): void; +export declare namespace decl { + var B: string; +} export declare function decl2(): void; +export declare namespace decl2 { + var C: number; +} export declare function decl3(): void; +export declare namespace decl3 { } export declare function decl4(): void; +export declare namespace decl4 { } export declare function decl5(): void; +export declare namespace decl5 { } export declare function decl6(): void; +export declare namespace decl6 { } export declare function decl7(): void; +export declare namespace decl7 { } export declare function decl8(): void; +export declare namespace decl8 { } export declare function decl9(): void; +export declare namespace decl9 { } export declare function decl10(): void; +export declare namespace decl10 { } export declare const arrow: { (): void; B: string; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff deleted file mode 100644 index 7b63352120..0000000000 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff +++ /dev/null @@ -1,32 +0,0 @@ ---- old.declarationEmitLateBoundAssignments2.js -+++ new.declarationEmitLateBoundAssignments2.js -@@= skipped -120, +120 lines =@@ - - //// [declarationEmitLateBoundAssignments2.d.ts] - export declare function decl(): void; --export declare namespace decl { -- var B: string; --} - export declare function decl2(): void; --export declare namespace decl2 { -- var C: number; --} - export declare function decl3(): void; --export declare namespace decl3 { } - export declare function decl4(): void; --export declare namespace decl4 { } - export declare function decl5(): void; --export declare namespace decl5 { } - export declare function decl6(): void; --export declare namespace decl6 { } - export declare function decl7(): void; --export declare namespace decl7 { } - export declare function decl8(): void; --export declare namespace decl8 { } - export declare function decl9(): void; --export declare namespace decl9 { } - export declare function decl10(): void; --export declare namespace decl10 { } - export declare const arrow: { - (): void; - B: string; \ 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..b8d9c3d66d 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -26,3 +26,8 @@ const a = foo[dashStrMem]; //// [file.d.ts] export declare function foo(): void; +export declare namespace foo { + var bar: number; + var strMemName: string; +} +export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 62c383b58d..6300536c8f 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -8,5 +8,9 @@ -export namespace foo { - let bar: number; - let strMemName: string; --} -+export declare function foo(): void; \ No newline at end of file ++export declare function foo(): void; ++export declare namespace foo { ++ var bar: number; ++ var strMemName: string; + } ++export {}; \ 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 4f8252f128..25ae9b77be 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js @@ -46,3 +46,6 @@ if (Math.random()) { // https://github.com/microsoft/TypeScript/issues/56538 export declare function X(): void; export declare function Y(): void; +export declare namespace Y { + var test: string; +} diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index e1e3783a15..66e1ee0496 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff @@ -19,6 +19,4 @@ +// https://github.com/microsoft/TypeScript/issues/56538 export declare function X(): void; export declare function Y(): void; --export declare namespace Y { -- var test: string; --} \ No newline at end of file + export declare namespace Y { \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js b/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js index 68a2d47ca2..d36056c30d 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js @@ -97,5 +97,32 @@ for (let f in (Foo.forIn = [])) { //// [expandoFunctionNestedAssigments.d.ts] declare function Foo(): void; +declare namespace Foo { + var inVariableInit: number; + var bla: { + foo: number; + }; + var baz: number; + var bar: number; + var fromIf: number; + var inIf: number; + var fromWhileCondition: number; + var fromWhileBody: number; + var fromWhileBodyNested: number; + var fromDoBody: number; + var fromDoBodyNested: number; + var fromDoCondition: number; + var forInit: number; + var forCond: number; + var forIncr: number; + var fromForBody: number; + var fromForBodyNested: number; + var forOf: any[]; + var fromForOfBody: number; + var fromForOfBodyNested: number; + var forIn: any[]; + var fromForInBody: number; + var fromForInBodyNested: number; +} declare let d: number; declare function bar(p?: number): void; diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff deleted file mode 100644 index 458d8901f4..0000000000 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff +++ /dev/null @@ -1,35 +0,0 @@ ---- old.expandoFunctionNestedAssigments.js -+++ new.expandoFunctionNestedAssigments.js -@@= skipped -96, +96 lines =@@ - - //// [expandoFunctionNestedAssigments.d.ts] - declare function Foo(): void; --declare namespace Foo { -- var inVariableInit: number; -- var bla: { -- foo: number; -- }; -- var baz: number; -- var bar: number; -- var fromIf: number; -- var inIf: number; -- var fromWhileCondition: number; -- var fromWhileBody: number; -- var fromWhileBodyNested: number; -- var fromDoBody: number; -- var fromDoBodyNested: number; -- var fromDoCondition: number; -- var forInit: number; -- var forCond: number; -- var forIncr: number; -- var fromForBody: number; -- var fromForBodyNested: number; -- var forOf: any[]; -- var fromForOfBody: number; -- var fromForOfBodyNested: number; -- var forIn: any[]; -- var fromForInBody: number; -- var fromForInBodyNested: number; --} - declare let d: number; - declare function bar(p?: number): void; \ 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 b62c42e7db..1be352a5f7 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js @@ -25,23 +25,44 @@ export default Foo; //// [jsxDeclarationsWithEsModuleInteropNoCrash.d.ts] +import PropTypes from 'prop-types'; declare function Foo({ bar }: { bar: any; }): JSX.Element; +declare namespace Foo { + var propTypes: { + bar: PropTypes.Requireable; + }; + var defaultProps: { + bar: boolean; + }; +} export default Foo; //// [DtsFileErrors] -jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(3,5): error TS2503: Cannot find namespace 'JSX'. +jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. +jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. -==== jsxDeclarationsWithEsModuleInteropNoCrash.d.ts (1 errors) ==== +==== jsxDeclarationsWithEsModuleInteropNoCrash.d.ts (2 errors) ==== + import PropTypes from 'prop-types'; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. declare function Foo({ bar }: { bar: any; }): JSX.Element; ~~~ !!! error TS2503: Cannot find namespace 'JSX'. + declare namespace Foo { + var propTypes: { + bar: PropTypes.Requireable; + }; + var defaultProps: { + bar: boolean; + }; + } export default Foo; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff index 3c315b9637..762528d96c 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff @@ -6,10 +6,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 }; -} @@ -21,20 +22,39 @@ - export { bar_1 as bar }; -} -import PropTypes from 'prop-types'; ++ var propTypes: { ++ bar: PropTypes.Requireable; ++ }; ++ var defaultProps: { ++ bar: boolean; ++ }; ++} +export default Foo; + + +//// [DtsFileErrors] + + -+jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(3,5): error TS2503: Cannot find namespace 'JSX'. ++jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. ++jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. + + -+==== jsxDeclarationsWithEsModuleInteropNoCrash.d.ts (1 errors) ==== ++==== jsxDeclarationsWithEsModuleInteropNoCrash.d.ts (2 errors) ==== ++ import PropTypes from 'prop-types'; ++ ~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. + declare function Foo({ bar }: { + bar: any; + }): JSX.Element; + ~~~ +!!! error TS2503: Cannot find namespace 'JSX'. ++ declare namespace Foo { ++ var propTypes: { ++ bar: PropTypes.Requireable; ++ }; ++ var defaultProps: { ++ bar: boolean; ++ }; ++ } + export default Foo; + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js index 328d1a72ea..e4b46c3046 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js @@ -19,3 +19,7 @@ const x = foo[_private]; //// [index.d.ts] export declare function foo(): void; +export declare namespace foo { + var bar: number; +} +export {}; diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff index 9b1699fd25..1c35593bb7 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff @@ -1,9 +1,7 @@ --- old.lateBoundFunctionMemberAssignmentDeclarations.js +++ new.lateBoundFunctionMemberAssignmentDeclarations.js -@@= skipped -18, +18 lines =@@ - - //// [index.d.ts] - export declare function foo(): void; --export declare namespace foo { -- var bar: number; --} \ No newline at end of file +@@= skipped -21, +21 lines =@@ + export declare namespace foo { + var bar: number; + } ++export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index c438749f3f..69ad9a5c62 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -19,4 +19,9 @@ someFunc.someProp = 'yo'; //// [exportDefaultNamespace.d.ts] -export default function someFunc(): string; +declare function someFunc(): string; +declare module someFunc { + var someProp: string; +} +export default someFunc; +export {}; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff index c5f3a3a126..e25aa13e83 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 function someFunc(): string; -declare namespace someFunc { -- var someProp: string; --} --export default someFunc; -+export default function someFunc(): string; \ No newline at end of file ++declare module someFunc { + var someProp: string; + } + export default someFunc; ++export {}; \ 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..b2f09e37ec 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js @@ -129,6 +129,9 @@ C2.staticProp = function (x, y) { //// [jsDeclarationsClassMethod.d.ts] declare function C1(): void; +declare namespace C1 { + var staticProp: (x: any, y: any) => any; +} declare class C2 { /** * A comment method1 diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff index 1520c1ddf2..bed9dc480f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff @@ -20,7 +20,7 @@ - */ - method(x: number, y: number): number; -} --declare namespace C1 { + declare namespace C1 { - /** - * A comment staticProp - * @param {number} x @@ -28,11 +28,11 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; --} ++ var staticProp: (x: any, y: any) => any; + } declare class C2 { /** - * A comment method1 -@@= skipped -33, +8 lines =@@ +@@= skipped -33, +11 lines =@@ * @returns {number} */ method1(x: number, y: number): number; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js index 4b6e7dcc70..a6b96b0b08 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js @@ -25,5 +25,18 @@ baz.normal = false; //// [source.d.ts] declare function foo(): void; +declare namespace foo { + var _a: boolean; + export { _a as null }; +} declare function bar(): void; +declare namespace bar { + var async: boolean; + var normal: boolean; +} declare function baz(): void; +declare namespace baz { + var _b: boolean; + export var normal: boolean; + export { _b as class }; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff index d529325b10..be2842a198 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff @@ -1,22 +1,28 @@ --- old.jsDeclarationsFunctionKeywordProp.js +++ new.jsDeclarationsFunctionKeywordProp.js -@@= skipped -24, +24 lines =@@ - +@@= skipped -25, +25 lines =@@ //// [source.d.ts] declare function foo(): void; --declare namespace foo { + declare namespace foo { - let _null: boolean; - export { _null as null }; --} ++ var _a: boolean; ++ export { _a as null }; + } declare function bar(): void; --declare namespace bar { + declare namespace bar { - let async: boolean; - let normal: boolean; --} ++ var async: boolean; ++ var normal: boolean; + } declare function baz(): void; --declare namespace baz { + declare namespace baz { - let _class: boolean; - export { _class as class }; - let normal_1: boolean; - export { normal_1 as normal }; --} \ No newline at end of file ++ var _b: boolean; ++ export var normal: boolean; ++ export { _b as class }; + } \ 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..5b6b92828f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -170,3 +170,84 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; +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 }; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff index fa3f869313..83f1da1389 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,83 @@ - export let global: number; - export let bigint: number; - export let of: number; --} \ No newline at end of file ++ 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 }; + } \ 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 4a762961ba..be1ee27098 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js @@ -159,11 +159,28 @@ exports.origin = new source_1.Point2D(0, 0); * @param {number} len */ export declare function Vec(len: number): void; +export declare namespace Vec { + var prototype: { + /** + * @param {Vec} other + */ + dot(other: Vec): number; + magnitude(): number; + }; +} /** * @param {number} x * @param {number} y */ export declare function Point2D(x: number, y: number): any; +export declare namespace Point2D { + var prototype: { + __proto__: typeof Vec; + x: number; + y: number; + }; +} +export {}; //// [referencer.d.ts] export declare const origin: any; // export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff index d1b7e4a0ac..6c3862685d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff @@ -28,8 +28,16 @@ - */ - dot(other: Vec): number; - magnitude(): number; --} +export declare function Vec(len: number): void; ++export declare namespace Vec { ++ var prototype: { ++ /** ++ * @param {Vec} other ++ */ ++ dot(other: Vec): number; ++ magnitude(): number; ++ }; + } /** * @param {number} x * @param {number} y @@ -52,8 +60,15 @@ - set y(y: number); - get y(): number; - __proto__: typeof Vec; --} +export declare function Point2D(x: number, y: number): any; ++export declare namespace Point2D { ++ var prototype: { ++ __proto__: typeof Vec; ++ x: number; ++ y: number; ++ }; + } ++export {}; //// [referencer.d.ts] -export const origin: Point2D; -import { Point2D } from "./source"; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js index 7a1612bab4..8aa44cbc27 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -123,7 +123,15 @@ function j() { } //// [index.d.ts] export declare function a(): void; export declare function b(): void; +export declare namespace b { + var cat: string; +} export declare function c(): void; +export declare namespace c { + var Cls: { + new (): {}; + }; +} /** * @param {number} a * @param {number} b @@ -142,6 +150,9 @@ export declare function e(a: T, b: U): T & U; * @param {T} a */ export declare function f(a: T): T; +export declare namespace f { + var self: typeof f; +} /** * @param {{x: string}} a * @param {{y: typeof b}} b diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 75088fe6e6..8e2b016ad7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -25,14 +25,20 @@ -export function b(): void; -export namespace b { - let cat: string; --} ++export declare function a(): void; ++export declare function b(): void; ++export declare namespace b { ++ var cat: string; + } -export function c(): void; -export namespace c { - export { Cls }; --} -+export declare function a(): void; -+export declare function b(): void; +export declare function c(): void; ++export declare namespace c { ++ var Cls: { ++ new (): {}; ++ }; + } /** * @param {number} a * @param {number} b @@ -59,8 +65,10 @@ -export function i(): void; -export function j(): void; -declare class Cls { --} +export declare function f(a: T): T; ++export declare namespace f { ++ var self: typeof f; + } /** * @param {{x: string}} a * @param {{y: typeof b}} b @@ -77,7 +85,7 @@ /** * @param {{x: string}} a * @param {{y: typeof b}} b -@@= skipped -50, +38 lines =@@ +@@= skipped -50, +49 lines =@@ declare function hh(a: { x: string; }, b: { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index d7751ce4d7..2c542d8a64 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -223,9 +223,19 @@ declare const TabbedShowLayout: { }; export default TabbedShowLayout; //// [jsDeclarationsReactComponents5.d.ts] +import PropTypes from 'prop-types'; declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; +declare namespace Tree { + var propTypes: { + classes: PropTypes.Requireable; + }; + var defaultProps: { + classes: {}; + parentSource: string; + }; +} export default Tree; @@ -237,7 +247,8 @@ out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2503: Cannot find namespa out/jsDeclarationsReactComponents2.d.ts(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations. out/jsDeclarationsReactComponents3.d.ts(10,7): error TS2503: Cannot find namespace 'JSX'. out/jsDeclarationsReactComponents4.d.ts(2,18): error TS2503: Cannot find namespace 'JSX'. -out/jsDeclarationsReactComponents5.d.ts(3,5): error TS2503: Cannot find namespace 'JSX'. +out/jsDeclarationsReactComponents5.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. +out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. ==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== @@ -293,11 +304,23 @@ out/jsDeclarationsReactComponents5.d.ts(3,5): error TS2503: Cannot find namespac }; export default TabbedShowLayout; -==== out/jsDeclarationsReactComponents5.d.ts (1 errors) ==== +==== out/jsDeclarationsReactComponents5.d.ts (2 errors) ==== + import PropTypes from 'prop-types'; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; ~~~ !!! error TS2503: Cannot find namespace 'JSX'. + declare namespace Tree { + var propTypes: { + classes: PropTypes.Requireable; + }; + var 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 2fed74569e..0f5e2b3309 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -130,10 +130,11 @@ -} //// [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; - } @@ -142,7 +143,14 @@ - export { classes_1 as classes }; - export let parentSource: string; - } --} ++ var propTypes: { ++ classes: PropTypes.Requireable; ++ }; ++ var defaultProps: { ++ classes: {}; ++ parentSource: string; ++ }; + } -import PropTypes from 'prop-types'; +export default Tree; + @@ -155,7 +163,8 @@ +out/jsDeclarationsReactComponents2.d.ts(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations. +out/jsDeclarationsReactComponents3.d.ts(10,7): error TS2503: Cannot find namespace 'JSX'. +out/jsDeclarationsReactComponents4.d.ts(2,18): error TS2503: Cannot find namespace 'JSX'. -+out/jsDeclarationsReactComponents5.d.ts(3,5): error TS2503: Cannot find namespace 'JSX'. ++out/jsDeclarationsReactComponents5.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. ++out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. + + +==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== @@ -211,11 +220,23 @@ + }; + export default TabbedShowLayout; + -+==== out/jsDeclarationsReactComponents5.d.ts (1 errors) ==== ++==== out/jsDeclarationsReactComponents5.d.ts (2 errors) ==== ++ import PropTypes from 'prop-types'; ++ ~~~~~~~~~~~~ ++!!! error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. + declare function Tree({ allowDropOnRoot }: { + allowDropOnRoot: any; + }): JSX.Element; + ~~~ +!!! error TS2503: Cannot find namespace 'JSX'. ++ declare namespace Tree { ++ var propTypes: { ++ classes: PropTypes.Requireable; ++ }; ++ var defaultProps: { ++ classes: {}; ++ parentSource: string; ++ }; ++ } + export default Tree; + \ 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..088080daf9 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js @@ -171,3 +171,84 @@ foo.of = 1; //// [nullPropertyName.d.ts] declare function foo(): void; +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 }; +} diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff deleted file mode 100644 index 60cf26b0b5..0000000000 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff +++ /dev/null @@ -1,87 +0,0 @@ ---- old.nullPropertyName.js -+++ new.nullPropertyName.js -@@= skipped -170, +170 lines =@@ - - //// [nullPropertyName.d.ts] - declare function foo(): void; --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 }; --} \ 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 0939758bfb..baed70ee8a 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -170,6 +170,10 @@ var n = ExpandoExpr3.prop + ExpandoExpr3.m(13) + new ExpandoExpr3().n; //// [typeFromPropertyAssignment29.d.ts] declare function ExpandoDecl(n: number): string; +declare namespace ExpandoDecl { + var prop: number; + var m: (n: number) => number; +} declare var n: number; declare const ExpandoExpr: { (n: number): string; @@ -192,7 +196,13 @@ declare function ExpandoNested(n: number): { (m: number): number; total: number; }; +declare namespace ExpandoNested { + var also: number; +} declare function ExpandoMerge(n: number): number; +declare namespace ExpandoMerge { + var p1: number; +} declare namespace ExpandoMerge { var p2: number; } @@ -202,6 +212,9 @@ declare namespace ExpandoMerge { declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; + namespace ExpandoNamespace { + var p6: number; + } export function foo(): typeof ExpandoNamespace; export {}; } diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index 4f9133b0df..bea9405738 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -31,18 +31,7 @@ }; ExpandoExpr3.prop = 3; ExpandoExpr3.m = function (n) { -@@= skipped -13, +11 lines =@@ - - //// [typeFromPropertyAssignment29.d.ts] - declare function ExpandoDecl(n: number): string; --declare namespace ExpandoDecl { -- var prop: number; -- var m: (n: number) => number; --} - declare var n: number; - declare const ExpandoExpr: { - (n: number): string; -@@= skipped -14, +10 lines =@@ +@@= skipped -27, +25 lines =@@ x?: undefined; y: string; }; @@ -58,26 +47,7 @@ }; declare function ExpandoNested(n: number): { (m: number): number; - total: number; - }; --declare namespace ExpandoNested { -- var also: number; --} - declare function ExpandoMerge(n: number): number; - declare namespace ExpandoMerge { -- var p1: number; --} --declare namespace ExpandoMerge { - var p2: number; - } - declare namespace ExpandoMerge { -@@= skipped -28, +22 lines =@@ - declare var n: number; - declare namespace Ns { - function ExpandoNamespace(): void; -- namespace ExpandoNamespace { -- var p6: number; -- } +@@= skipped -34, +34 lines =@@ export function foo(): typeof ExpandoNamespace; export {}; } diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js index 05ea5715ce..c6a71ddc88 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js @@ -30,4 +30,13 @@ map4.__underscores__(); //// [a.d.ts] declare function Multimap4(): void; +declare namespace Multimap4 { + var prototype: { + /** + * @param {string} key + * @returns {number} the value ok + */ + get(key: string): number; + }; +} declare const map4: any; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff index d5ffe64194..1e1f280301 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff @@ -14,6 +14,14 @@ - "add-on"(): void; - addon(): void; - __underscores__(): void; --} ++declare namespace Multimap4 { ++ var prototype: { ++ /** ++ * @param {string} key ++ * @returns {number} the value ok ++ */ ++ get(key: string): number; ++ }; + } -declare const map4: Multimap4; +declare const map4: any; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts new file mode 100644 index 0000000000..78ab984b73 --- /dev/null +++ b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts @@ -0,0 +1,11 @@ +// @declaration: true + +export function A() { + return 'A'; +} + +export enum B { + C +} + +A.B = B; From 8e203e743cedec30b0aaff14e1ee3269b6890676 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 14 Jul 2025 13:41:38 +0300 Subject: [PATCH 2/9] add locking --- internal/checker/emitresolver.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/checker/emitresolver.go b/internal/checker/emitresolver.go index 34f614e51d..4069534455 100644 --- a/internal/checker/emitresolver.go +++ b/internal/checker/emitresolver.go @@ -609,6 +609,9 @@ func (r *emitResolver) IsExpandoFunctionDeclaration(node *ast.Node) bool { return false } + r.checkerMu.Lock() + defer r.checkerMu.Unlock() + var symbol *ast.Symbol if ast.IsVariableDeclaration(node) { if node.Type() != nil || (!ast.IsInJSFile(node) && !ast.IsVarConstLike(node)) { @@ -887,6 +890,9 @@ func (r *emitResolver) GetPropertiesOfContainerFunction(node *ast.Node) []*ast.S } if ast.IsFunctionDeclaration(node) { + r.checkerMu.Lock() + defer r.checkerMu.Unlock() + symbol := r.checker.getSymbolOfDeclaration(node) if symbol == nil { return props From 21c11bcbc6d01f7f5924646d4f432229b76b78c2 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 14 Jul 2025 14:58:45 +0300 Subject: [PATCH 3/9] emit namespace keyword --- internal/transformers/declarations/transform.go | 7 ++----- ...rationEmitDefaultExportWithStaticAssignment.js | 6 +++--- ...nEmitDefaultExportWithStaticAssignment.js.diff | 15 +++------------ .../conformance/exportDefaultNamespace.js | 2 +- .../conformance/exportDefaultNamespace.js.diff | 7 +------ 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index ae0bf07541..a143a5bdc6 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1166,10 +1166,7 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi parent := core.FirstOrNil(props) if parent != nil { - declarationData.Symbol = &ast.Symbol{ - Name: parent.Name, - Flags: ast.SymbolFlagsNamespaceModule, - } + declarationData.Symbol = parent } symbolTable := make(ast.SymbolTable, len(props)) @@ -1309,7 +1306,7 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi updatedNamespaceDeclaration := tx.Factory().UpdateModuleDeclaration( namespaceDeclaration.AsModuleDeclaration(), modifiers, - namespaceDeclaration.Kind, + namespaceDeclaration.AsModuleDeclaration().Keyword, namespaceDeclaration.Name(), namespaceDeclaration.Body(), ) diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index 2cd7667fa1..4671416e8a 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -83,7 +83,7 @@ export declare class Foo { } //// [index1.d.ts] declare function Example(): void; -declare module Example { +declare namespace Example { var Foo: typeof import("./foo").Foo; } export default Example; @@ -92,7 +92,7 @@ export {}; import { Foo } from './foo'; export { Foo }; declare function Example(): void; -declare module Example { +declare namespace Example { var Foo: typeof import("./foo").Foo; } export default Example; @@ -101,7 +101,7 @@ export {}; export declare class Bar { } declare function Example(): void; -declare module Example { +declare namespace Example { var Bar: typeof import("./index3").Bar; } export default Example; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index 808771678f..d304e38796 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -18,12 +18,7 @@ Object.defineProperty(exports, "Foo", { enumerable: true, get: function () { return foo_1.Foo; } }); function Example() { } Example.Foo = foo_1.Foo; -@@= skipped -32, +32 lines =@@ - } - //// [index1.d.ts] - declare function Example(): void; --declare namespace Example { -+declare module Example { +@@= skipped -36, +36 lines =@@ var Foo: typeof import("./foo").Foo; } export default Example; @@ -31,9 +26,7 @@ //// [index2.d.ts] import { Foo } from './foo'; export { Foo }; - declare function Example(): void; --declare namespace Example { -+declare module Example { +@@= skipped -8, +9 lines =@@ var Foo: typeof import("./foo").Foo; } export default Example; @@ -41,9 +34,7 @@ //// [index3.d.ts] export declare class Bar { } - declare function Example(): void; --declare namespace Example { -+declare module Example { +@@= skipped -8, +9 lines =@@ var Bar: typeof import("./index3").Bar; } export default Example; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index 69ad9a5c62..2e5f6ef901 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -20,7 +20,7 @@ someFunc.someProp = 'yo'; //// [exportDefaultNamespace.d.ts] declare function someFunc(): string; -declare module someFunc { +declare namespace someFunc { var someProp: string; } export default someFunc; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff index e25aa13e83..a89dded8b9 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -1,11 +1,6 @@ --- old.exportDefaultNamespace.js +++ new.exportDefaultNamespace.js -@@= skipped -19, +19 lines =@@ - - //// [exportDefaultNamespace.d.ts] - declare function someFunc(): string; --declare namespace someFunc { -+declare module someFunc { +@@= skipped -23, +23 lines =@@ var someProp: string; } export default someFunc; From 7e20f0903a3f3527245c7f11ee9c18c1f7f48fb7 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 14 Jul 2025 15:12:55 +0300 Subject: [PATCH 4/9] remove redundant empty export --- .../transformers/declarations/transform.go | 2 +- ...onEmitDefaultExportWithStaticAssignment.js | 3 --- ...tDefaultExportWithStaticAssignment.js.diff | 25 +------------------ .../conformance/exportDefaultNamespace.js | 1 - .../exportDefaultNamespace.js.diff | 7 ------ 5 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index a143a5bdc6..5f8197a0d0 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1322,7 +1322,7 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi tx.resultHasExternalModuleIndicator = true } - tx.resultHasScopeMarker = false + tx.resultHasScopeMarker = true return tx.Factory().NewSyntaxList([]*ast.Node{ updatedFunctionDeclaration, diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index 4671416e8a..84df5d5124 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -87,7 +87,6 @@ declare namespace Example { var Foo: typeof import("./foo").Foo; } export default Example; -export {}; //// [index2.d.ts] import { Foo } from './foo'; export { Foo }; @@ -96,7 +95,6 @@ declare namespace Example { var Foo: typeof import("./foo").Foo; } export default Example; -export {}; //// [index3.d.ts] export declare class Bar { } @@ -105,7 +103,6 @@ declare namespace Example { var Bar: typeof import("./index3").Bar; } export default Example; -export {}; //// [index4.d.ts] export declare function C(): any; export declare namespace C { diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index d304e38796..993aa69356 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -18,30 +18,7 @@ Object.defineProperty(exports, "Foo", { enumerable: true, get: function () { return foo_1.Foo; } }); function Example() { } Example.Foo = foo_1.Foo; -@@= skipped -36, +36 lines =@@ - var Foo: typeof import("./foo").Foo; - } - export default Example; -+export {}; - //// [index2.d.ts] - import { Foo } from './foo'; - export { Foo }; -@@= skipped -8, +9 lines =@@ - var Foo: typeof import("./foo").Foo; - } - export default Example; -+export {}; - //// [index3.d.ts] - export declare class Bar { - } -@@= skipped -8, +9 lines =@@ - var Bar: typeof import("./index3").Bar; - } - export default Example; -+export {}; - //// [index4.d.ts] - export declare function C(): any; - export declare namespace C { +@@= skipped -58, +58 lines =@@ var A: () => void; var B: () => void; } diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index 2e5f6ef901..1790aa837e 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -24,4 +24,3 @@ declare namespace someFunc { var someProp: string; } export default someFunc; -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff deleted file mode 100644 index a89dded8b9..0000000000 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ /dev/null @@ -1,7 +0,0 @@ ---- old.exportDefaultNamespace.js -+++ new.exportDefaultNamespace.js -@@= skipped -23, +23 lines =@@ - var someProp: string; - } - export default someFunc; -+export {}; \ No newline at end of file From 9eb36b81fc813cba4cf8959fd399d237a4fbcd39 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 14 Jul 2025 15:42:37 +0300 Subject: [PATCH 5/9] remove redundant empty export --- internal/transformers/declarations/transform.go | 2 +- .../declarationEmitDefaultExportWithStaticAssignment.js | 1 - ...clarationEmitDefaultExportWithStaticAssignment.js.diff | 7 +------ .../compiler/declarationEmitExpandoPropertyPrivateName.js | 1 - .../declarationEmitExpandoPropertyPrivateName.js.diff | 8 +++----- .../compiler/declarationEmitLateBoundAssignments.js | 1 - .../compiler/declarationEmitLateBoundAssignments.js.diff | 7 ------- .../compiler/declarationEmitLateBoundJSAssignments.js | 1 - .../declarationEmitLateBoundJSAssignments.js.diff | 3 +-- .../lateBoundFunctionMemberAssignmentDeclarations.js | 1 - .../lateBoundFunctionMemberAssignmentDeclarations.js.diff | 7 ------- .../conformance/jsDeclarationsFunctionLikeClasses2.js | 1 - .../jsDeclarationsFunctionLikeClasses2.js.diff | 1 - 13 files changed, 6 insertions(+), 35 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff 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 5f8197a0d0..5e8b80ef10 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -270,7 +270,7 @@ func (tx *DeclarationTransformer) transformAndReplaceLatePaintedStatements(state if needsScopeMarker(elem) { tx.needsScopeFixMarker = true } - if ast.IsSourceFile(statement.Parent) && ast.IsExternalModuleIndicator(replacement) { + if ast.IsSourceFile(statement.Parent) && ast.IsExternalModuleIndicator(elem) { tx.resultHasExternalModuleIndicator = true } } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index 84df5d5124..be5df399eb 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -109,4 +109,3 @@ export declare namespace C { var A: () => void; var B: () => void; } -export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index 993aa69356..81b1e1b978 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -17,9 +17,4 @@ +const foo_1 = require("./foo"); Object.defineProperty(exports, "Foo", { enumerable: true, get: function () { return foo_1.Foo; } }); function Example() { } - Example.Foo = foo_1.Foo; -@@= skipped -58, +58 lines =@@ - var A: () => void; - var B: () => void; - } -+export {}; \ No newline at end of file + Example.Foo = foo_1.Foo; \ 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 bd91348197..62611a4b50 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js @@ -34,4 +34,3 @@ export declare function q(): void; export declare namespace q { var val: I; } -export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff index 5f99ced399..1a0346d4ab 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff @@ -9,14 +9,12 @@ function q() { } q.val = (0, a_1.f)(); -@@= skipped -9, +9 lines =@@ - interface I { +@@= skipped -10, +10 lines =@@ } export declare function f(): I; -+export {}; + export {}; +//// [b.d.ts] +export declare function q(): void; +export declare namespace q { + var val: I; -+} - export {}; \ No newline at end of file ++} \ 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 ad83eff151..b76db45754 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -40,4 +40,3 @@ export declare namespace foo { var bar: number; var strMemName: string; } -export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff deleted file mode 100644 index c6017e172f..0000000000 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff +++ /dev/null @@ -1,7 +0,0 @@ ---- old.declarationEmitLateBoundAssignments.js -+++ new.declarationEmitLateBoundAssignments.js -@@= skipped -39, +39 lines =@@ - var bar: number; - var strMemName: string; - } -+export {}; \ 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 b8d9c3d66d..947fbc8245 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -30,4 +30,3 @@ export declare namespace foo { var bar: number; var strMemName: string; } -export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 6300536c8f..cd06e14a0e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -12,5 +12,4 @@ +export declare namespace foo { + var bar: number; + var strMemName: string; - } -+export {}; \ No newline at end of file + } \ 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 e4b46c3046..05ce6daa8c 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js @@ -22,4 +22,3 @@ export declare function foo(): void; export declare namespace foo { var bar: number; } -export {}; 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 1c35593bb7..0000000000 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff +++ /dev/null @@ -1,7 +0,0 @@ ---- old.lateBoundFunctionMemberAssignmentDeclarations.js -+++ new.lateBoundFunctionMemberAssignmentDeclarations.js -@@= skipped -21, +21 lines =@@ - export declare namespace foo { - var bar: number; - } -+export {}; \ 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 be1ee27098..7620ecc109 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js @@ -180,7 +180,6 @@ export declare namespace Point2D { y: number; }; } -export {}; //// [referencer.d.ts] export declare const origin: any; // export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff index 6c3862685d..34ba5b7cfa 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff @@ -68,7 +68,6 @@ + y: number; + }; } -+export {}; //// [referencer.d.ts] -export const origin: Point2D; -import { Point2D } from "./source"; From 37935cfffa5128d2eccbced7c39644fa7b89eef4 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Sat, 19 Jul 2025 12:28:43 +0300 Subject: [PATCH 6/9] delete obsolete helpers --- internal/ast/utilities.go | 75 ++----------------- internal/binder/binder.go | 16 +--- internal/checker/emitresolver.go | 30 ++++---- .../transformers/declarations/transform.go | 5 +- 4 files changed, 24 insertions(+), 102 deletions(-) diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index 2f9820a282..d7c07ddccb 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -3638,78 +3638,15 @@ func GetSemanticJsxChildren(children []*JsxChild) []*JsxChild { }) } -func IsExpandoPropertyDeclaration(node *Node) bool { - if node == nil { - return false - } - return IsPropertyAccessExpression(node) || IsElementAccessExpression(node) || IsBinaryExpression(node) -} - -func GetExpandoInitializer(initializer *Node, isPrototypeAssignment bool) *Node { - if initializer.Kind == KindCallExpression { - expr := SkipParentheses(initializer.Expression()) - if expr.Kind == KindFunctionExpression || expr.Kind == KindArrowFunction { - return initializer - } - return nil - } - - if initializer.Kind == KindFunctionExpression || initializer.Kind == KindCallExpression || initializer.Kind == KindArrowFunction { - return initializer - } - - if initializer.Kind == KindObjectLiteralExpression && (len(initializer.Properties()) == 0 || isPrototypeAssignment) { - return initializer - } - - return nil -} - -func GetEffectiveInitializer(node *Node) *Expression { - if IsInJSFile(node) && node.Initializer() != nil && IsBinaryExpression(node.Initializer()) { - initializer := node.Initializer().AsBinaryExpression() - if initializer.OperatorToken.Kind == KindBarBarToken || initializer.OperatorToken.Kind == KindQuestionQuestionToken { - if node.Name() != nil && IsEntityNameExpressionEx(node.Name(), IsInJSFile(node)) && IsSameEntityName(node.Name(), initializer.Left) { - return initializer.Right - } - } - } - return node.Initializer() -} - -func GetDeclaredExpandoInitializer(node *Node) *Expression { - initializer := GetEffectiveInitializer(node) +func IsExpandoInitializer(initializer *Node) bool { if initializer == nil { - return nil - } - return GetExpandoInitializer(initializer, IsPrototypeAccess(node.Name())) -} - -func IsPrototypeAccess(node *Node) bool { - return IsBindableStaticAccessExpression(node, false /*excludeThisKeyword*/) -} - -func IsLiteralLikeAccess(node *Node) bool { - return IsPropertyAccessExpression(node) || IsLiteralLikeElementAccess(node) -} - -func GetNameOrArgument(node *Expression) *Expression { - if IsPropertyAccessExpression(node) { - return node.Name() - } - return node.AsElementAccessExpression().ArgumentExpression -} - -func IsSameEntityName(name *Expression, initializer *Expression) bool { - if IsPropertyNameLiteral(name) && IsPropertyNameLiteral(initializer) { - return name.Text() == initializer.Text() + return false } - if IsMemberName(name) && IsLiteralLikeAccess(initializer) && (initializer.Expression().Kind == KindThisKeyword || IsIdentifier(initializer.Expression()) && - (initializer.Expression().Text() == "window" || initializer.Expression().Text() == "self" || initializer.Expression().Text() == "global")) { - return IsSameEntityName(name, GetNameOrArgument(initializer)) + if IsFunctionExpressionOrArrowFunction(initializer) { + return true } - if IsLiteralLikeAccess(name) && IsLiteralLikeAccess(initializer) { - return GetElementOrPropertyAccessName(name) == GetElementOrPropertyAccessName(initializer) && IsSameEntityName(name.Expression(), initializer.Expression()) + 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 05f8bc6382..d1adea8ab2 100644 --- a/internal/binder/binder.go +++ b/internal/binder/binder.go @@ -1019,30 +1019,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/emitresolver.go b/internal/checker/emitresolver.go index 4069534455..5a99985a77 100644 --- a/internal/checker/emitresolver.go +++ b/internal/checker/emitresolver.go @@ -612,33 +612,33 @@ func (r *emitResolver) IsExpandoFunctionDeclaration(node *ast.Node) bool { r.checkerMu.Lock() defer r.checkerMu.Unlock() - var symbol *ast.Symbol + var declaration *ast.Node if ast.IsVariableDeclaration(node) { - if node.Type() != nil || (!ast.IsInJSFile(node) && !ast.IsVarConstLike(node)) { - return false - } - initializer := ast.GetDeclaredExpandoInitializer(node) - if initializer == nil || !ast.CanHaveSymbol(initializer) { - return false + initializer := node.Initializer() + if node.Type() == nil && (ast.IsInJSFile(node) || ast.IsVarConstLike(node)) && ast.IsExpandoInitializer(initializer) { + declaration = initializer } - symbol = r.checker.getSymbolOfDeclaration(initializer) - } else if ast.IsFunctionDeclaration(node) { - symbol = r.checker.getSymbolOfDeclaration(node) } + if ast.IsFunctionDeclaration(node) { + declaration = node + } + + if declaration == nil { + return false + } + + symbol := r.checker.getSymbolOfDeclaration(declaration) if symbol == nil || (symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsVariable)) == 0 { return false } exports := r.checker.getExportsOfSymbol(symbol) for _, p := range exports { - if p.Flags&ast.SymbolFlagsValue == 0 { - continue - } - if p.ValueDeclaration == nil { + if p.ValueDeclaration == nil || p.Flags&ast.SymbolFlagsValue == 0 || p.Flags&ast.SymbolFlagsAssignment == 0 { continue } - if ast.IsExpandoPropertyDeclaration(p.ValueDeclaration) { + if p.ValueDeclaration.Flags&ast.NodeFlagsAmbient == 0 { return true } } diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 5e8b80ef10..722c49f84a 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1181,10 +1181,7 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi declarations := []*ast.Statement{} for _, p := range props { - if p.ValueDeclaration == nil { - continue - } - if !ast.IsExpandoPropertyDeclaration(p.ValueDeclaration) { + if p.ValueDeclaration == nil || p.Flags&ast.SymbolFlagsAssignment == 0 { continue } if !scanner.IsIdentifierText(p.Name, core.LanguageVariantStandard) { From c81d99f89d486d65c45e31da4c7758da6a73a65e Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 21 Jul 2025 20:23:54 +0300 Subject: [PATCH 7/9] update baseline --- .../jsDeclarationsReactComponents.js | 171 +++++++++--------- .../jsDeclarationsReactComponents.js.diff | 3 +- 2 files changed, 88 insertions(+), 86 deletions(-) diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js index 3a3a9c511d..5959f68704 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -1,98 +1,98 @@ //// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsReactComponents.ts] //// //// [jsDeclarationsReactComponents1.jsx] -/// -import React from "react"; -import PropTypes from "prop-types" - -const TabbedShowLayout = ({ -}) => { - return ( -
- ); -}; - -TabbedShowLayout.propTypes = { - version: PropTypes.number, - -}; - -TabbedShowLayout.defaultProps = { - tabs: undefined -}; - -export default TabbedShowLayout; +/// +import React from "react"; +import PropTypes from "prop-types" + +const TabbedShowLayout = ({ +}) => { + return ( +
+ ); +}; + +TabbedShowLayout.propTypes = { + version: PropTypes.number, + +}; + +TabbedShowLayout.defaultProps = { + tabs: undefined +}; + +export default TabbedShowLayout; //// [jsDeclarationsReactComponents2.jsx] -import React from "react"; -/** - * @type {React.SFC} - */ -const TabbedShowLayout = () => { - return ( -
- ok -
- ); -}; - -TabbedShowLayout.defaultProps = { - tabs: "default value" -}; - -export default TabbedShowLayout; +import React from "react"; +/** + * @type {React.SFC} + */ +const TabbedShowLayout = () => { + return ( +
+ ok +
+ ); +}; + +TabbedShowLayout.defaultProps = { + tabs: "default value" +}; + +export default TabbedShowLayout; //// [jsDeclarationsReactComponents3.jsx] -import React from "react"; -/** - * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} - */ -const TabbedShowLayout = () => { - return ( -
- ok -
- ); -}; - -TabbedShowLayout.defaultProps = { - tabs: "default value" -}; - -export default TabbedShowLayout; +import React from "react"; +/** + * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} + */ +const TabbedShowLayout = () => { + return ( +
+ ok +
+ ); +}; + +TabbedShowLayout.defaultProps = { + tabs: "default value" +}; + +export default TabbedShowLayout; //// [jsDeclarationsReactComponents4.jsx] -import React from "react"; -const TabbedShowLayout = (/** @type {{className: string}}*/prop) => { - return ( -
- ok -
- ); -}; - -TabbedShowLayout.defaultProps = { - tabs: "default value" -}; - +import React from "react"; +const TabbedShowLayout = (/** @type {{className: string}}*/prop) => { + return ( +
+ ok +
+ ); +}; + +TabbedShowLayout.defaultProps = { + tabs: "default value" +}; + export default TabbedShowLayout; //// [jsDeclarationsReactComponents5.jsx] -import React from 'react'; -import PropTypes from 'prop-types'; - -function Tree({ allowDropOnRoot }) { - return
-} - -Tree.propTypes = { - classes: PropTypes.object, -}; - -Tree.defaultProps = { - classes: {}, - parentSource: 'parent_id', -}; - +import React from 'react'; +import PropTypes from 'prop-types'; + +function Tree({ allowDropOnRoot }) { + return
+} + +Tree.propTypes = { + classes: PropTypes.object, +}; + +Tree.defaultProps = { + classes: {}, + parentSource: 'parent_id', +}; + export default Tree; //// [jsDeclarationsReactComponents1.js] @@ -249,7 +249,8 @@ out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2503: Cannot find namespa out/jsDeclarationsReactComponents2.d.ts(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations. out/jsDeclarationsReactComponents3.d.ts(10,7): error TS2503: Cannot find namespace 'JSX'. out/jsDeclarationsReactComponents4.d.ts(4,9): error TS2503: Cannot find namespace 'JSX'. -out/jsDeclarationsReactComponents5.d.ts(3,5): error TS2503: Cannot find namespace 'JSX'. +out/jsDeclarationsReactComponents5.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. +out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. ==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff index 095731439f..335599e1e2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -165,7 +165,8 @@ +out/jsDeclarationsReactComponents2.d.ts(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations. +out/jsDeclarationsReactComponents3.d.ts(10,7): error TS2503: Cannot find namespace 'JSX'. +out/jsDeclarationsReactComponents4.d.ts(4,9): error TS2503: Cannot find namespace 'JSX'. -+out/jsDeclarationsReactComponents5.d.ts(3,5): error TS2503: Cannot find namespace 'JSX'. ++out/jsDeclarationsReactComponents5.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. ++out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. + + +==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== From cf9bae513175f365be1d3fd31acf75bab9209084 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Sun, 27 Jul 2025 15:17:45 +0300 Subject: [PATCH 8/9] support expando assignments by collecting and emitting merged namespace declarations --- internal/checker/emitresolver.go | 59 +-- internal/printer/emitresolver.go | 1 - .../transformers/declarations/transform.go | 340 ++++++++---------- .../declarationEmitExpandoFunction.js | 40 ++- .../declarationEmitExpandoFunction.symbols | 28 +- .../declarationEmitExpandoFunction.types | 41 ++- .../compiler/declarationEmitDefaultExport3.js | 3 +- .../declarationEmitDefaultExport3.js.diff | 9 + ...onEmitDefaultExportWithStaticAssignment.js | 74 +++- ...tDefaultExportWithStaticAssignment.js.diff | 102 +++++- ...arationEmitExpandoWithGenericConstraint.js | 43 +++ ...onEmitExpandoWithGenericConstraint.js.diff | 45 ++- ...clarationEmitFunctionDuplicateNamespace.js | 3 + ...tionEmitFunctionDuplicateNamespace.js.diff | 8 +- .../declarationEmitFunctionKeywordProp.js | 46 ++- ...declarationEmitFunctionKeywordProp.js.diff | 59 ++- .../declarationEmitLateBoundAssignments.js | 3 +- ...eclarationEmitLateBoundAssignments.js.diff | 10 + .../declarationEmitLateBoundAssignments2.js | 14 - ...clarationEmitLateBoundAssignments2.js.diff | 32 ++ .../declarationEmitLateBoundJSAssignments.js | 3 +- ...larationEmitLateBoundJSAssignments.js.diff | 3 +- .../declarationEmitModuleWithScopeMarker.js | 25 +- ...clarationEmitModuleWithScopeMarker.js.diff | 34 ++ ...ionEmitUnnessesaryTypeReferenceNotAdded.js | 3 +- ...itUnnessesaryTypeReferenceNotAdded.js.diff | 9 +- .../es5ExportDefaultFunctionDeclaration.js | 3 +- ...s5ExportDefaultFunctionDeclaration.js.diff | 9 + .../es5ExportDefaultFunctionDeclaration3.js | 3 +- ...5ExportDefaultFunctionDeclaration3.js.diff | 9 + .../es5ExportDefaultFunctionDeclaration4.js | 27 +- ...5ExportDefaultFunctionDeclaration4.js.diff | 34 ++ .../es6ExportDefaultFunctionDeclaration.js | 3 +- ...s6ExportDefaultFunctionDeclaration.js.diff | 9 + .../compiler/expandoFunctionBlockShadowing.js | 2 +- .../expandoFunctionBlockShadowing.js.diff | 5 +- .../expandoFunctionNestedAssigments.js | 27 -- .../expandoFunctionNestedAssigments.js.diff | 35 ++ .../compiler/isolatedDeclarationErrors.js | 48 +++ .../isolatedDeclarationErrors.js.diff | 50 ++- ...olatedDeclarationErrorsExpandoFunctions.js | 9 + ...dDeclarationErrorsExpandoFunctions.js.diff | 11 +- .../jsDeclarationsGlobalFileConstFunction.js | 42 +++ ...eclarationsGlobalFileConstFunction.js.diff | 63 +++- ...eclarationsGlobalFileConstFunctionNamed.js | 31 ++ ...ationsGlobalFileConstFunctionNamed.js.diff | 59 ++- ...xDeclarationsWithEsModuleInteropNoCrash.js | 4 +- ...arationsWithEsModuleInteropNoCrash.js.diff | 4 +- ...undFunctionMemberAssignmentDeclarations.js | 2 +- ...nctionMemberAssignmentDeclarations.js.diff | 9 + .../uniqueSymbolPropertyDeclarationEmit.js | 3 +- ...niqueSymbolPropertyDeclarationEmit.js.diff | 12 +- .../conformance/assignmentToVoidZero2.js | 4 + .../conformance/assignmentToVoidZero2.js.diff | 4 + .../commonJSImportNestedClassTypeReference.js | 7 + ...onJSImportNestedClassTypeReference.js.diff | 10 +- .../conformance/exportDefaultNamespace.js | 2 +- .../exportDefaultNamespace.js.diff | 10 + .../conformance/jsDeclarationsClassMethod.js | 9 +- .../jsDeclarationsClassMethod.js.diff | 16 +- .../conformance/jsDeclarationsClassStatic.js | 3 + .../jsDeclarationsClassStatic.js.diff | 13 +- .../conformance/jsDeclarationsClassStatic2.js | 4 +- .../jsDeclarationsClassStatic2.js.diff | 12 +- .../conformance/jsDeclarationsDefault.js | 12 +- .../conformance/jsDeclarationsDefault.js.diff | 17 +- ...tionsFunctionClassesCjsExportAssignment.js | 10 + ...FunctionClassesCjsExportAssignment.js.diff | 12 +- .../jsDeclarationsFunctionKeywordProp.js | 22 +- .../jsDeclarationsFunctionKeywordProp.js.diff | 29 +- ...clarationsFunctionKeywordPropExhaustive.js | 202 +++++++---- ...tionsFunctionKeywordPropExhaustive.js.diff | 202 +++++++---- .../jsDeclarationsFunctionLikeClasses2.js | 10 +- ...jsDeclarationsFunctionLikeClasses2.js.diff | 19 +- .../jsDeclarationsFunctionPrototypeStatic.js | 4 + ...eclarationsFunctionPrototypeStatic.js.diff | 10 +- ...ationsFunctionWithDefaultAssignedMember.js | 18 +- ...sFunctionWithDefaultAssignedMember.js.diff | 24 +- .../conformance/jsDeclarationsFunctions.js | 22 +- .../jsDeclarationsFunctions.js.diff | 33 +- ...tionsParameterTagReusesInputNodeInEmit1.js | 6 + ...ParameterTagReusesInputNodeInEmit1.js.diff | 11 +- ...tionsParameterTagReusesInputNodeInEmit2.js | 6 + ...ParameterTagReusesInputNodeInEmit2.js.diff | 11 +- .../jsDeclarationsReactComponents.js | 82 ++++- .../jsDeclarationsReactComponents.js.diff | 86 ++++- .../conformance/jsdocImplements_class.js | 8 + .../conformance/jsdocImplements_class.js.diff | 9 +- .../submodule/conformance/nullPropertyName.js | 202 +++++++---- .../conformance/nullPropertyName.js.diff | 209 +++++++++++ .../typeFromPropertyAssignment29.js | 167 ++++++++- .../typeFromPropertyAssignment29.js.diff | 195 +++++++++- .../typeFromPrototypeAssignment4.js | 9 - .../typeFromPrototypeAssignment4.js.diff | 10 +- .../declarationEmitExpandoFunction.ts | 11 +- 95 files changed, 2510 insertions(+), 802 deletions(-) create mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExport3.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff create mode 100644 testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff create mode 100644 testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff create mode 100644 testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff diff --git a/internal/checker/emitresolver.go b/internal/checker/emitresolver.go index 5a99985a77..38a7812f65 100644 --- a/internal/checker/emitresolver.go +++ b/internal/checker/emitresolver.go @@ -605,43 +605,8 @@ func (r *emitResolver) IsLiteralConstDeclaration(node *ast.Node) bool { } func (r *emitResolver) IsExpandoFunctionDeclaration(node *ast.Node) bool { - if !ast.IsParseTreeNode(node) { - return false - } - - r.checkerMu.Lock() - defer r.checkerMu.Unlock() - - var declaration *ast.Node - if ast.IsVariableDeclaration(node) { - initializer := node.Initializer() - if node.Type() == nil && (ast.IsInJSFile(node) || ast.IsVarConstLike(node)) && ast.IsExpandoInitializer(initializer) { - declaration = initializer - } - } - - if ast.IsFunctionDeclaration(node) { - declaration = node - } - - if declaration == nil { - return false - } - - symbol := r.checker.getSymbolOfDeclaration(declaration) - if symbol == nil || (symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsVariable)) == 0 { - return false - } - - exports := r.checker.getExportsOfSymbol(symbol) - for _, p := range exports { - if p.ValueDeclaration == nil || p.Flags&ast.SymbolFlagsValue == 0 || p.Flags&ast.SymbolFlagsAssignment == 0 { - continue - } - if p.ValueDeclaration.Flags&ast.NodeFlagsAmbient == 0 { - return true - } - } + // node = r.emitContext.ParseNode(node) + // !!! TODO: expando function support return false } @@ -882,26 +847,6 @@ func (r *emitResolver) GetReferencedValueDeclarations(node *ast.IdentifierNode) return r.getReferenceResolver().GetReferencedValueDeclarations(node) } -func (r *emitResolver) GetPropertiesOfContainerFunction(node *ast.Node) []*ast.Symbol { - props := []*ast.Symbol{} - - if !ast.IsParseTreeNode(node) { - return props - } - - if ast.IsFunctionDeclaration(node) { - r.checkerMu.Lock() - defer r.checkerMu.Unlock() - - symbol := r.checker.getSymbolOfDeclaration(node) - if symbol == nil { - return props - } - props = r.checker.getPropertiesOfType(r.checker.getTypeOfSymbol(symbol)) - } - return props -} - // 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/printer/emitresolver.go b/internal/printer/emitresolver.go index 8acf810986..f8a1f6c842 100644 --- a/internal/printer/emitresolver.go +++ b/internal/printer/emitresolver.go @@ -34,7 +34,6 @@ type EmitResolver interface { GetExternalModuleFileFromDeclaration(node *ast.Node) *ast.SourceFile GetEffectiveDeclarationFlags(node *ast.Node, flags ast.ModifierFlags) ast.ModifierFlags GetResolutionModeOverride(node *ast.Node) core.ResolutionMode - GetPropertiesOfContainerFunction(node *ast.Node) []*ast.Symbol // JSX Emit GetJsxFactoryEntity(location *ast.Node) *ast.Node diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 722c49f84a..adfc5a2ad5 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -50,6 +50,7 @@ type DeclarationTransformer struct { isBundledEmit bool needsDeclare bool + needsDefaultExport bool needsScopeFixMarker bool resultHasScopeMarker bool enclosingDeclaration *ast.Node @@ -59,11 +60,8 @@ type DeclarationTransformer struct { rawReferencedFiles []ReferencedFilePair rawTypeReferenceDirectives []*ast.FileReference rawLibReferenceDirectives []*ast.FileReference -} - -type ExportMapping struct { - PropertyName *ast.Identifier - Name string + pendingExpando map[ast.SymbolId]*ast.Node + pendingDefaultExports []*ast.Node } func NewDeclarationTransformer(host DeclarationEmitHost, context *printer.EmitContext, compilerOptions *core.CompilerOptions, declarationFilePath string, declarationMapPath string) *DeclarationTransformer { @@ -128,7 +126,6 @@ func (tx *DeclarationTransformer) visit(node *ast.Node) *ast.Node { ast.KindContinueStatement, ast.KindDebuggerStatement, ast.KindDoStatement, - ast.KindExpressionStatement, ast.KindEmptyStatement, ast.KindForInStatement, ast.KindForOfStatement, @@ -145,6 +142,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) @@ -162,6 +161,7 @@ func (tx *DeclarationTransformer) visitSourceFile(node *ast.SourceFile) *ast.Nod tx.isBundledEmit = false tx.needsDeclare = true + tx.needsDefaultExport = true tx.needsScopeFixMarker = false tx.resultHasScopeMarker = false tx.enclosingDeclaration = node.AsNode() @@ -173,6 +173,8 @@ func (tx *DeclarationTransformer) visitSourceFile(node *ast.SourceFile) *ast.Nod tx.rawReferencedFiles = make([]ReferencedFilePair, 0) tx.rawTypeReferenceDirectives = make([]*ast.FileReference, 0) tx.rawLibReferenceDirectives = make([]*ast.FileReference, 0) + tx.pendingExpando = make(map[ast.SymbolId]*ast.Node) + tx.pendingDefaultExports = make([]*ast.Node, 0) tx.state.currentSourceFile = node tx.collectFileReferences(node) tx.resolver.PrecalculateDeclarationEmitVisibility(node) @@ -287,6 +289,14 @@ func (tx *DeclarationTransformer) transformAndReplaceLatePaintedStatements(state } } + for _, expandoAssignment := range tx.transformPendingExpandoAssignments() { + results = append(results, expandoAssignment) + } + + for _, defaultExport := range tx.transformPendingDefaultExports() { + results = append(results, defaultExport) + } + return tx.Factory().NewNodeList(results) } @@ -1138,6 +1148,11 @@ func (tx *DeclarationTransformer) transformInterfaceDeclaration(input *ast.Inter } func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.FunctionDeclaration) *ast.Node { + saveNeedsDefaultExport := tx.needsDefaultExport + if input.ModifierFlags()&ast.ModifierFlagsDefault != 0 && input.Name() != nil { + tx.needsDefaultExport = false + tx.pendingDefaultExports = append(tx.pendingDefaultExports, input.Name()) + } updated := tx.Factory().UpdateFunctionDeclaration( input, tx.ensureModifiers(input.AsNode()), @@ -1148,185 +1163,7 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi tx.ensureType(input.AsNode(), false), nil, ) - if updated != nil && tx.state.resolver.IsExpandoFunctionDeclaration(input.AsNode()) && shouldEmitFunctionProperties(input) { - props := tx.state.resolver.GetPropertiesOfContainerFunction(input.AsNode()) - if tx.state.isolatedDeclarations { - // TODO: reportExpandoFunctionErrors - return updated - } - - synthesizedModuleDeclaration := tx.Factory().NewModuleDeclaration( - nil, /*modifiers*/ - ast.KindNamespaceKeyword, - core.IfElse(input.Name() == nil, tx.Factory().NewIdentifier("_default"), input.Name()), - nil, /*body*/ - ) - synthesizedModuleDeclaration.Parent = tx.enclosingDeclaration - declarationData := synthesizedModuleDeclaration.DeclarationData() - - parent := core.FirstOrNil(props) - if parent != nil { - declarationData.Symbol = parent - } - - symbolTable := make(ast.SymbolTable, len(props)) - for _, p := range props { - symbolTable[p.Name] = p - } - - containerData := synthesizedModuleDeclaration.LocalsContainerData() - containerData.Locals = symbolTable - - exportMappings := []ExportMapping{} - declarations := []*ast.Statement{} - - for _, p := range props { - if p.ValueDeclaration == nil || p.Flags&ast.SymbolFlagsAssignment == 0 { - continue - } - if !scanner.IsIdentifierText(p.Name, core.LanguageVariantStandard) { - continue - } - - saveDiag := tx.state.getSymbolAccessibilityDiagnostic - tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p.ValueDeclaration) - - t := tx.resolver.CreateTypeOfDeclaration( - tx.EmitContext(), - p.ValueDeclaration, - synthesizedModuleDeclaration, - declarationEmitNodeBuilderFlags, - declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, - tx.tracker, - ) - - tx.state.getSymbolAccessibilityDiagnostic = saveDiag - - nameToken := scanner.StringToToken(p.Name) - isNonContextualKeywordName := ast.IsNonContextualKeyword(nameToken) - - name := core.IfElse( - isNonContextualKeywordName, - tx.Factory().NewGeneratedNameForNode(p.ValueDeclaration), - tx.Factory().NewIdentifier(p.Name), - ) - - if isNonContextualKeywordName { - exportMappings = append(exportMappings, ExportMapping{ - PropertyName: name.AsIdentifier(), - Name: p.Name, - }) - } - - variableDeclaration := tx.Factory().NewVariableDeclaration( - name, - nil, /*exclamationToken*/ - t, - nil, /*initializer*/ - ) - - declarations = append(declarations, - tx.Factory().NewVariableStatement( - core.IfElse( - isNonContextualKeywordName, - nil, - tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindExportKeyword)}), - ), - tx.Factory().NewVariableDeclarationList( - ast.NodeFlagsNone, - tx.Factory().NewNodeList([]*ast.Node{variableDeclaration}), - ), - ), - ) - } - - if len(exportMappings) == 0 { - for i, declaration := range declarations { - modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(ast.ModifierFlagsNone, tx.Factory().NewModifier)) - declarations[i] = ast.ReplaceModifiers(tx.Factory().AsNodeFactory(), declaration, modifiers) - } - } else { - exportSpecifiers := make([]*ast.Node, 0, len(exportMappings)) - for _, mapping := range exportMappings { - exportSpecifiers = append(exportSpecifiers, - tx.Factory().NewExportSpecifier( - false, /*isTypeOnly*/ - mapping.PropertyName.AsNode(), - tx.Factory().NewIdentifier(mapping.Name), - ), - ) - } - - exportDeclaration := tx.Factory().NewExportDeclaration( - nil, /*modifiers*/ - false, /*isTypeOnly*/ - tx.Factory().NewNamedExports(tx.Factory().NewNodeList(exportSpecifiers)), - nil, /*moduleSpecifier*/ - nil, /*attributes*/ - ) - - declarations = append(declarations, exportDeclaration) - } - - namespaceDeclaration := tx.Factory().NewModuleDeclaration( - tx.ensureModifiers(input.AsNode()), - ast.KindNamespaceKeyword, - input.Name(), - tx.Factory().NewModuleBlock(tx.Factory().NewNodeList(declarations)), - ) - - if tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsDefault) == 0 { - return tx.Factory().NewSyntaxList([]*ast.Node{ - updated, - namespaceDeclaration, - }) - } - - modifiers := tx.Factory().NewModifierList( - ast.CreateModifiersFromModifierFlags( - (updated.ModifierFlags()&^ast.ModifierFlagsExportDefault)|ast.ModifierFlagsAmbient, - tx.Factory().NewModifier, - ), - ) - - updatedFunctionDeclaration := tx.Factory().UpdateFunctionDeclaration( - updated.AsFunctionDeclaration(), - modifiers, - nil, /*asteriskToken*/ - updated.Name(), - updated.TypeParameterList(), - updated.ParameterList(), - updated.Type(), - nil, /*body*/ - ) - - updatedNamespaceDeclaration := tx.Factory().UpdateModuleDeclaration( - namespaceDeclaration.AsModuleDeclaration(), - modifiers, - namespaceDeclaration.AsModuleDeclaration().Keyword, - namespaceDeclaration.Name(), - namespaceDeclaration.Body(), - ) - - exportDefaultDeclaration := tx.Factory().NewExportAssignment( - nil, /*modifiers*/ - false, /*isExportEquals*/ - nil, /*typeNode*/ - namespaceDeclaration.Name(), - ) - - if ast.IsSourceFile(input.Parent) { - tx.resultHasExternalModuleIndicator = true - } - - tx.resultHasScopeMarker = true - - return tx.Factory().NewSyntaxList([]*ast.Node{ - updatedFunctionDeclaration, - updatedNamespaceDeclaration, - exportDefaultDeclaration, - }) - } + tx.needsDefaultExport = saveNeedsDefaultExport return updated } @@ -1668,6 +1505,10 @@ func (tx *DeclarationTransformer) ensureModifierFlags(node *ast.Node) ast.Modifi mask ^= ast.ModifierFlagsAmbient additions = ast.ModifierFlagsNone } + if !tx.needsDefaultExport { + mask ^= ast.ModifierFlagsDefault + mask ^= ast.ModifierFlagsExport + } return maskModifierFlags(tx.host, node, mask, additions) } @@ -1939,3 +1780,132 @@ 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 { + tx.collectExpandoAssignments(expression.AsBinaryExpression()) + } + + return nil +} + +func (tx *DeclarationTransformer) collectExpandoAssignments(node *ast.BinaryExpression) { + symbol := node.Symbol + if symbol == nil || symbol.Flags&ast.SymbolFlagsAssignment == 0 { + return + } + + host := symbol.Parent + if host == nil || host.ValueDeclaration == nil { + return + } + + left := node.Left + right := node.Right + + if ast.IsElementAccessExpression(left) { + return + } + + saveDiag := tx.state.getSymbolAccessibilityDiagnostic + tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node.AsNode()) + t := tx.resolver.CreateTypeOfExpression( + tx.EmitContext(), + right, + host.ValueDeclaration, + declarationEmitNodeBuilderFlags, + declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, + tx.tracker, + ) + tx.state.getSymbolAccessibilityDiagnostic = saveDiag + + nameToken := scanner.StringToToken(left.Name().Text()) + isNonContextualKeywordName := ast.IsNonContextualKeyword(nameToken) + + name := core.IfElse( + isNonContextualKeywordName, + tx.Factory().NewGeneratedNameForNode(left.Name()), + tx.Factory().NewIdentifier(left.Name().Text()), + ) + + variableDeclaration := tx.Factory().NewVariableDeclaration(name, nil /*exclamationToken*/, t, nil /*initializer*/) + variableStatement := tx.Factory().NewVariableStatement(nil /*modifiers*/, tx.Factory().NewVariableDeclarationList(ast.NodeFlagsConst, tx.Factory().NewNodeList([]*ast.Node{variableDeclaration}))) + statements := []*ast.Statement{variableStatement} + + if isNonContextualKeywordName { + namedExports := tx.Factory().NewNamedExports(tx.Factory().NewNodeList( + []*ast.Node{ + tx.Factory().NewExportSpecifier(false /*isTypeOnly*/, name, tx.Factory().NewIdentifier(left.Name().Text())), + }, + )) + statements = append( + statements, + tx.Factory().NewExportDeclaration(nil /*modifiers*/, false /*isTypeOnly*/, namedExports, nil /*moduleSpecifier*/, nil /*attributes*/), + ) + } + + id := ast.GetSymbolId(host) + if tx.pendingExpando[id] == nil { + modifierFlags := ast.ModifierFlagsAmbient + if host.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsExport != 0 && host.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsDefault == 0 { + modifierFlags |= ast.ModifierFlagsExport + } + modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)) + name := tx.Factory().NewIdentifier(ast.GetFirstIdentifier(left.AsPropertyAccessExpression().Expression).Text()) + tx.pendingExpando[id] = tx.Factory().NewModuleDeclaration( + modifiers, + ast.KindNamespaceKeyword, + name, + tx.Factory().NewModuleBlock(tx.Factory().NewNodeList(statements)), + ) + } else { + namespace := tx.pendingExpando[id].AsModuleDeclaration() + tx.pendingExpando[id] = tx.Factory().UpdateModuleDeclaration( + namespace, + namespace.Modifiers(), + namespace.Keyword, + namespace.Name(), + tx.Factory().UpdateModuleBlock( + namespace.Body.AsModuleBlock(), + tx.Factory().NewNodeList(append(namespace.Body.AsModuleBlock().Statements.Nodes, statements...)), + ), + ) + } +} + +func (tx *DeclarationTransformer) transformPendingExpandoAssignments() []*ast.Node { + results := make([]*ast.Node, 0) + if len(tx.pendingExpando) == 0 { + return results + } + + for _, replacement := range tx.pendingExpando { + results = append(results, replacement) + } + + tx.resultHasScopeMarker = true + tx.resultHasExternalModuleIndicator = true + + return results +} + +func (tx *DeclarationTransformer) transformPendingDefaultExports() []*ast.Node { + results := make([]*ast.Node, 0) + if len(tx.pendingDefaultExports) == 0 { + return results + } + + for _, reference := range tx.pendingDefaultExports { + results = append(results, tx.Factory().NewExportAssignment(nil /*modifiers*/, false /*isExportEquals*/, nil /*typeNode*/, reference)) + } + + tx.resultHasScopeMarker = true + tx.resultHasExternalModuleIndicator = true + + return results +} diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js index f72463565d..da6059b5a3 100644 --- a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js @@ -5,33 +5,51 @@ export function A() { return 'A'; } -export enum B { +export function B() { + return 'B'; +} + +export enum C { C } -A.B = B; +A.a = C; +A.b = C; + +B.c = C; //// [declarationEmitExpandoFunction.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.B = void 0; +exports.C = void 0; exports.A = A; +exports.B = B; function A() { return 'A'; } -var B; -(function (B) { - B[B["C"] = 0] = "C"; -})(B || (exports.B = B = {})); -A.B = B; +function B() { + return 'B'; +} +var C; +(function (C) { + C[C["C"] = 0] = "C"; +})(C || (exports.C = C = {})); +A.a = C; +A.b = C; +B.c = C; //// [declarationEmitExpandoFunction.d.ts] export declare function A(): string; +export declare function B(): string; +export declare enum C { + C = 0 +} export declare namespace A { - var B: typeof import("./declarationEmitExpandoFunction").B; + var a: typeof C; + var b: typeof C; } -export declare enum B { - C = 0 +export declare namespace B { + var c: typeof C; } diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols index be4c55ce7b..2ffe781977 100644 --- a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols @@ -7,16 +7,34 @@ export function A() { return 'A'; } -export enum B { +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, Decl(declarationEmitExpandoFunction.ts, 4, 15)) +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 8, 15)) } -A.B = B; ->A.B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 6, 1)) +A.a = C; +>A.a : Symbol(a, Decl(declarationEmitExpandoFunction.ts, 10, 1)) >A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) ->B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 6, 1)) +>a : Symbol(a, Decl(declarationEmitExpandoFunction.ts, 10, 1)) +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 6, 1)) + +A.b = C; +>A.b : Symbol(b, Decl(declarationEmitExpandoFunction.ts, 12, 8)) +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) +>b : Symbol(b, Decl(declarationEmitExpandoFunction.ts, 12, 8)) +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 6, 1)) + +B.c = C; +>B.c : Symbol(c, Decl(declarationEmitExpandoFunction.ts, 13, 8)) >B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 2, 1)) +>c : Symbol(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 index 813600b90e..0e7b87870c 100644 --- a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types @@ -2,23 +2,44 @@ === declarationEmitExpandoFunction.ts === export function A() { ->A : { (): string; B: typeof B; } +>A : { (): string; a: typeof C; b: typeof C; } return 'A'; >'A' : "A" } -export enum B { ->B : B +export function B() { +>B : { (): string; c: typeof C; } + + return 'B'; +>'B' : "B" +} + +export enum C { +>C : C C ->C : B.C +>C : C.C } -A.B = B; ->A.B = B : typeof B ->A.B : typeof B ->A : { (): string; B: typeof B; } ->B : typeof B ->B : typeof B +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/declarationEmitDefaultExport3.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExport3.js index 88308017aa..7459b484d0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExport3.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExport3.js @@ -12,4 +12,5 @@ export default function foo() { //// [declarationEmitDefaultExport3.d.ts] -export default function foo(): string; +declare function foo(): string; +export default foo; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExport3.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExport3.js.diff new file mode 100644 index 0000000000..834176055b --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExport3.js.diff @@ -0,0 +1,9 @@ +--- old.declarationEmitDefaultExport3.js ++++ new.declarationEmitDefaultExport3.js +@@= skipped -11, +11 lines =@@ + + + //// [declarationEmitDefaultExport3.d.ts] +-export default function foo(): string; ++declare function foo(): string; ++export default foo; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index be5df399eb..33111fbfc3 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -82,9 +82,10 @@ C.B = B; export declare class Foo { } //// [index1.d.ts] +import { Foo } from './foo'; declare function Example(): void; declare namespace Example { - var Foo: typeof import("./foo").Foo; + var Foo: typeof Foo; } export default Example; //// [index2.d.ts] @@ -92,7 +93,7 @@ import { Foo } from './foo'; export { Foo }; declare function Example(): void; declare namespace Example { - var Foo: typeof import("./foo").Foo; + var Foo: typeof Foo; } export default Example; //// [index3.d.ts] @@ -100,12 +101,75 @@ export declare class Bar { } declare function Example(): void; declare namespace Example { - var Bar: typeof import("./index3").Bar; + var Bar: typeof Bar; } export default Example; //// [index4.d.ts] +declare function A(): void; +declare function B(): void; export declare function C(): any; export declare namespace C { - var A: () => void; - var B: () => void; + var A: typeof A; + var B: typeof B; } + + +//// [DtsFileErrors] + + +index1.d.ts(4,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. +index2.d.ts(5,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. +index3.d.ts(5,9): error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. +index4.d.ts(5,9): error TS2502: 'A' is referenced directly or indirectly in its own type annotation. +index4.d.ts(6,9): error TS2502: 'B' is referenced directly or indirectly in its own type annotation. + + +==== foo.d.ts (0 errors) ==== + export declare class Foo { + } + +==== index1.d.ts (1 errors) ==== + import { Foo } from './foo'; + declare function Example(): void; + declare namespace Example { + var Foo: typeof Foo; + ~~~ +!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. + } + export default Example; + +==== index2.d.ts (1 errors) ==== + import { Foo } from './foo'; + export { Foo }; + declare function Example(): void; + declare namespace Example { + var Foo: typeof Foo; + ~~~ +!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. + } + export default Example; + +==== index3.d.ts (1 errors) ==== + export declare class Bar { + } + declare function Example(): void; + declare namespace Example { + var Bar: typeof Bar; + ~~~ +!!! error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. + } + export default Example; + +==== index4.d.ts (2 errors) ==== + declare function A(): void; + declare function B(): void; + export declare function C(): any; + export declare namespace C { + var A: typeof A; + ~ +!!! error TS2502: 'A' is referenced directly or indirectly in its own type annotation. + var B: typeof B; + ~ +!!! error TS2502: 'B' is referenced directly or indirectly in its own type annotation. + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index 81b1e1b978..427d749180 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -17,4 +17,104 @@ +const foo_1 = require("./foo"); Object.defineProperty(exports, "Foo", { enumerable: true, get: function () { return foo_1.Foo; } }); function Example() { } - Example.Foo = foo_1.Foo; \ No newline at end of file + Example.Foo = foo_1.Foo; +@@= skipped -31, +31 lines =@@ + export declare class Foo { + } + //// [index1.d.ts] ++import { Foo } from './foo'; + declare function Example(): void; + declare namespace Example { +- var Foo: typeof import("./foo").Foo; ++ var Foo: typeof Foo; + } + export default Example; + //// [index2.d.ts] +@@= skipped -10, +11 lines =@@ + export { Foo }; + declare function Example(): void; + declare namespace Example { +- var Foo: typeof import("./foo").Foo; ++ var Foo: typeof Foo; + } + export default Example; + //// [index3.d.ts] +@@= skipped -8, +8 lines =@@ + } + declare function Example(): void; + declare namespace Example { +- var Bar: typeof import("./index3").Bar; ++ var Bar: typeof Bar; + } + export default Example; + //// [index4.d.ts] ++declare function A(): void; ++declare function B(): void; + export declare function C(): any; + export declare namespace C { +- var A: () => void; +- var B: () => void; ++ var A: typeof A; ++ var B: typeof B; + } ++ ++ ++//// [DtsFileErrors] ++ ++ ++index1.d.ts(4,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. ++index2.d.ts(5,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. ++index3.d.ts(5,9): error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. ++index4.d.ts(5,9): error TS2502: 'A' is referenced directly or indirectly in its own type annotation. ++index4.d.ts(6,9): error TS2502: 'B' is referenced directly or indirectly in its own type annotation. ++ ++ ++==== foo.d.ts (0 errors) ==== ++ export declare class Foo { ++ } ++ ++==== index1.d.ts (1 errors) ==== ++ import { Foo } from './foo'; ++ declare function Example(): void; ++ declare namespace Example { ++ var Foo: typeof Foo; ++ ~~~ ++!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. ++ } ++ export default Example; ++ ++==== index2.d.ts (1 errors) ==== ++ import { Foo } from './foo'; ++ export { Foo }; ++ declare function Example(): void; ++ declare namespace Example { ++ var Foo: typeof Foo; ++ ~~~ ++!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. ++ } ++ export default Example; ++ ++==== index3.d.ts (1 errors) ==== ++ export declare class Bar { ++ } ++ declare function Example(): void; ++ declare namespace Example { ++ var Bar: typeof Bar; ++ ~~~ ++!!! error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. ++ } ++ export default Example; ++ ++==== index4.d.ts (2 errors) ==== ++ declare function A(): void; ++ declare function B(): void; ++ export declare function C(): any; ++ export declare namespace C { ++ var A: typeof A; ++ ~ ++!!! error TS2502: 'A' is referenced directly or indirectly in its own type annotation. ++ var B: typeof B; ++ ~ ++!!! error TS2502: 'B' is referenced directly or indirectly in its own type annotation. ++ } ++ \ 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..9a8f66e31d 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 { + var 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'. + var 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..bd9b32a806 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 { ++ var 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'. ++ var 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..67db7d7018 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 { + var x: 2; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff index c75018a359..429aa243ec 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 ++ var 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 8b715fb902..24bb7d39eb 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js @@ -25,18 +25,44 @@ baz.normal = false; //// [declarationEmitFunctionKeywordProp.d.ts] declare function foo(): void; -declare namespace foo { - var _a: boolean; - export { _a as null }; -} declare function bar(): void; +declare function baz(): void; declare namespace bar { - var async: boolean; - var normal: boolean; + var async: true; + var normal: false; } -declare function baz(): void; declare namespace baz { - var _b: boolean; - export var normal: boolean; - export { _b as class }; + var class_1: true; + export { class_1 as class }; + var normal: false; } +declare namespace foo { + var null_1: true; + export { null_1 as null }; +} + + +!!!! File declarationEmitFunctionKeywordProp.d.ts differs from original emit in noCheck emit +//// [declarationEmitFunctionKeywordProp.d.ts] +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -1,6 +1,10 @@ + declare function foo(): void; + declare function bar(): void; + declare function baz(): void; ++declare namespace foo { ++ var null_1: true; ++ export { null_1 as null }; ++} + declare namespace bar { + var async: true; + var normal: false; +@@ -9,8 +13,4 @@ + var class_1: true; + export { class_1 as class }; + var normal: false; +-} +-declare namespace foo { +- var null_1: true; +- export { null_1 as null }; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff index e5e1c06f43..183ada05ca 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -1,12 +1,59 @@ --- old.declarationEmitFunctionKeywordProp.js +++ new.declarationEmitFunctionKeywordProp.js -@@= skipped -35, +35 lines =@@ - } +@@= skipped -24, +24 lines =@@ + + //// [declarationEmitFunctionKeywordProp.d.ts] + declare function foo(): void; +-declare namespace foo { +- var _a: boolean; +- export { _a as null }; +-} + declare function bar(): void; +-declare namespace bar { +- var async: boolean; +- var normal: boolean; +-} declare function baz(): void; ++declare namespace bar { ++ var async: true; ++ var normal: false; ++} declare namespace baz { - var _a: boolean; -+ var _b: boolean; - export var normal: boolean; +- export var normal: boolean; - export { _a as class }; -+ export { _b as class }; - } \ No newline at end of file +-} ++ var class_1: true; ++ export { class_1 as class }; ++ var normal: false; ++} ++declare namespace foo { ++ var null_1: true; ++ export { null_1 as null }; ++} ++ ++ ++!!!! File declarationEmitFunctionKeywordProp.d.ts differs from original emit in noCheck emit ++//// [declarationEmitFunctionKeywordProp.d.ts] ++--- Expected The full check baseline +++++ Actual with noCheck set ++@@= skipped --24, +-24 lines =@@ ++ declare function foo(): void; ++ declare function bar(): void; ++ declare function baz(): void; +++declare namespace foo { +++ var null_1: true; +++ export { null_1 as null }; +++} ++ declare namespace bar { ++ var async: true; ++ var normal: false; ++@@= skipped -8, +12 lines =@@ ++ var class_1: true; ++ export { class_1 as class }; ++ var normal: false; ++-} ++-declare namespace foo { ++- var null_1: true; ++- export { null_1 as null }; ++ } \ 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 b76db45754..9be4e8519f 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -37,6 +37,5 @@ const a = foo[dashStrMem]; //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; export declare namespace foo { - var bar: number; - var strMemName: string; + var bar: 12; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff new file mode 100644 index 0000000000..5f78187456 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff @@ -0,0 +1,10 @@ +--- old.declarationEmitLateBoundAssignments.js ++++ new.declarationEmitLateBoundAssignments.js +@@= skipped -36, +36 lines =@@ + //// [declarationEmitLateBoundAssignments.d.ts] + export declare function foo(): void; + export declare namespace foo { +- var bar: number; +- var strMemName: string; ++ var bar: 12; + } \ 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 1b15043502..dbace19f24 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js @@ -121,29 +121,15 @@ arrow10[emoji] = 0; //// [declarationEmitLateBoundAssignments2.d.ts] export declare function decl(): void; -export declare namespace decl { - var B: string; -} export declare function decl2(): void; -export declare namespace decl2 { - var C: number; -} export declare function decl3(): void; -export declare namespace decl3 { } export declare function decl4(): void; -export declare namespace decl4 { } export declare function decl5(): void; -export declare namespace decl5 { } export declare function decl6(): void; -export declare namespace decl6 { } export declare function decl7(): void; -export declare namespace decl7 { } export declare function decl8(): void; -export declare namespace decl8 { } export declare function decl9(): void; -export declare namespace decl9 { } export declare function decl10(): void; -export declare namespace decl10 { } export declare const arrow: { (): void; B: string; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff new file mode 100644 index 0000000000..7b63352120 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments2.js.diff @@ -0,0 +1,32 @@ +--- old.declarationEmitLateBoundAssignments2.js ++++ new.declarationEmitLateBoundAssignments2.js +@@= skipped -120, +120 lines =@@ + + //// [declarationEmitLateBoundAssignments2.d.ts] + export declare function decl(): void; +-export declare namespace decl { +- var B: string; +-} + export declare function decl2(): void; +-export declare namespace decl2 { +- var C: number; +-} + export declare function decl3(): void; +-export declare namespace decl3 { } + export declare function decl4(): void; +-export declare namespace decl4 { } + export declare function decl5(): void; +-export declare namespace decl5 { } + export declare function decl6(): void; +-export declare namespace decl6 { } + export declare function decl7(): void; +-export declare namespace decl7 { } + export declare function decl8(): void; +-export declare namespace decl8 { } + export declare function decl9(): void; +-export declare namespace decl9 { } + export declare function decl10(): void; +-export declare namespace decl10 { } + export declare const arrow: { + (): void; + B: string; \ 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 947fbc8245..424969cc04 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -27,6 +27,5 @@ const a = foo[dashStrMem]; //// [file.d.ts] export declare function foo(): void; export declare namespace foo { - var bar: number; - var strMemName: string; + var bar: 12; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index cd06e14a0e..84fc68006e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -10,6 +10,5 @@ - let strMemName: string; +export declare function foo(): void; +export declare namespace foo { -+ var bar: number; -+ var strMemName: string; ++ var bar: 12; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js b/testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js index ca5eb29497..360cc78ec5 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js @@ -21,7 +21,30 @@ declare module "bar" { declare module "bar" { var before: typeof func; export function normal(): void; - export default function func(): typeof func; + function func(): typeof func; var after: typeof func; export {}; + export default func; } +export default func; + + +//// [DtsFileErrors] + + +declarationEmitModuleWithScopeMarker.d.ts(9,16): error TS2304: Cannot find name 'func'. + + +==== declarationEmitModuleWithScopeMarker.d.ts (1 errors) ==== + declare module "bar" { + var before: typeof func; + export function normal(): void; + function func(): typeof func; + var after: typeof func; + export {}; + export default func; + } + export default func; + ~~~~ +!!! error TS2304: Cannot find name 'func'. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js.diff new file mode 100644 index 0000000000..a28984913b --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitModuleWithScopeMarker.js.diff @@ -0,0 +1,34 @@ +--- old.declarationEmitModuleWithScopeMarker.js ++++ new.declarationEmitModuleWithScopeMarker.js +@@= skipped -20, +20 lines =@@ + declare module "bar" { + var before: typeof func; + export function normal(): void; +- export default function func(): typeof func; ++ function func(): typeof func; + var after: typeof func; + export {}; ++ export default func; + } ++export default func; ++ ++ ++//// [DtsFileErrors] ++ ++ ++declarationEmitModuleWithScopeMarker.d.ts(9,16): error TS2304: Cannot find name 'func'. ++ ++ ++==== declarationEmitModuleWithScopeMarker.d.ts (1 errors) ==== ++ declare module "bar" { ++ var before: typeof func; ++ export function normal(): void; ++ function func(): typeof func; ++ var after: typeof func; ++ export {}; ++ export default func; ++ } ++ export default func; ++ ~~~~ ++!!! error TS2304: Cannot find name 'func'. ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js b/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js index af06008a1b..f648b5bb4a 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js @@ -43,4 +43,5 @@ function parseArgs() { //// [index.d.ts] import minimist = require('minimist'); -export default function parseArgs(): minimist.ParsedArgs; +declare function parseArgs(): minimist.ParsedArgs; +export default parseArgs; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js.diff index 3aa75a2b79..f975f2d16a 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitUnnessesaryTypeReferenceNotAdded.js.diff @@ -10,4 +10,11 @@ +const process = require("process"); function parseArgs() { return minimist(process.argv.slice(2)); - } \ No newline at end of file + } +@@= skipped -9, +9 lines =@@ + + //// [index.d.ts] + import minimist = require('minimist'); +-export default function parseArgs(): minimist.ParsedArgs; ++declare function parseArgs(): minimist.ParsedArgs; ++export default parseArgs; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js index a6582c641f..8c5e8a6571 100644 --- a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js +++ b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js @@ -12,4 +12,5 @@ function f() { } //// [es5ExportDefaultFunctionDeclaration.d.ts] -export default function f(): void; +declare function f(): void; +export default f; diff --git a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js.diff b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js.diff new file mode 100644 index 0000000000..a02e2f0d90 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration.js.diff @@ -0,0 +1,9 @@ +--- old.es5ExportDefaultFunctionDeclaration.js ++++ new.es5ExportDefaultFunctionDeclaration.js +@@= skipped -11, +11 lines =@@ + + + //// [es5ExportDefaultFunctionDeclaration.d.ts] +-export default function f(): void; ++declare function f(): void; ++export default f; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js index c40155845e..6472ad043a 100644 --- a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js +++ b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js @@ -21,4 +21,5 @@ var after = func(); //// [es5ExportDefaultFunctionDeclaration3.d.ts] -export default function func(): typeof func; +declare function func(): typeof func; +export default func; diff --git a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js.diff b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js.diff new file mode 100644 index 0000000000..af6823a67b --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration3.js.diff @@ -0,0 +1,9 @@ +--- old.es5ExportDefaultFunctionDeclaration3.js ++++ new.es5ExportDefaultFunctionDeclaration3.js +@@= skipped -20, +20 lines =@@ + + + //// [es5ExportDefaultFunctionDeclaration3.d.ts] +-export default function func(): typeof func; ++declare function func(): typeof func; ++export default func; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js index 075581be5a..393dd9f0fe 100644 --- a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js +++ b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js @@ -14,7 +14,28 @@ declare module "bar" { //// [es5ExportDefaultFunctionDeclaration4.d.ts] declare module "bar" { - var before: typeof func; - export default function func(): typeof func; - var after: typeof func; + export var before: typeof func; + function func(): typeof func; + export var after: typeof func; + export default func; } +export default func; + + +//// [DtsFileErrors] + + +es5ExportDefaultFunctionDeclaration4.d.ts(7,16): error TS2304: Cannot find name 'func'. + + +==== es5ExportDefaultFunctionDeclaration4.d.ts (1 errors) ==== + declare module "bar" { + export var before: typeof func; + function func(): typeof func; + export var after: typeof func; + export default func; + } + export default func; + ~~~~ +!!! error TS2304: Cannot find name 'func'. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js.diff b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js.diff new file mode 100644 index 0000000000..3bf1fff654 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/es5ExportDefaultFunctionDeclaration4.js.diff @@ -0,0 +1,34 @@ +--- old.es5ExportDefaultFunctionDeclaration4.js ++++ new.es5ExportDefaultFunctionDeclaration4.js +@@= skipped -13, +13 lines =@@ + + //// [es5ExportDefaultFunctionDeclaration4.d.ts] + declare module "bar" { +- var before: typeof func; +- export default function func(): typeof func; +- var after: typeof func; ++ export var before: typeof func; ++ function func(): typeof func; ++ export var after: typeof func; ++ export default func; + } ++export default func; ++ ++ ++//// [DtsFileErrors] ++ ++ ++es5ExportDefaultFunctionDeclaration4.d.ts(7,16): error TS2304: Cannot find name 'func'. ++ ++ ++==== es5ExportDefaultFunctionDeclaration4.d.ts (1 errors) ==== ++ declare module "bar" { ++ export var before: typeof func; ++ function func(): typeof func; ++ export var after: typeof func; ++ export default func; ++ } ++ export default func; ++ ~~~~ ++!!! error TS2304: Cannot find name 'func'. ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js b/testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js index 8de0256544..a662dd0dfe 100644 --- a/testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js +++ b/testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js @@ -9,4 +9,5 @@ export default function f() { } //// [es6ExportDefaultFunctionDeclaration.d.ts] -export default function f(): void; +declare function f(): void; +export default f; diff --git a/testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js.diff b/testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js.diff new file mode 100644 index 0000000000..cfffb6b9bc --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/es6ExportDefaultFunctionDeclaration.js.diff @@ -0,0 +1,9 @@ +--- old.es6ExportDefaultFunctionDeclaration.js ++++ new.es6ExportDefaultFunctionDeclaration.js +@@= skipped -8, +8 lines =@@ + + + //// [es6ExportDefaultFunctionDeclaration.d.ts] +-export default function f(): void; ++declare function f(): void; ++export default f; \ 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 25ae9b77be..7b9c5c1bcd 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js @@ -47,5 +47,5 @@ if (Math.random()) { export declare function X(): void; export declare function Y(): void; export declare namespace Y { - var test: string; + var test: "foo"; } diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index 66e1ee0496..0a076d8989 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff @@ -19,4 +19,7 @@ +// https://github.com/microsoft/TypeScript/issues/56538 export declare function X(): void; export declare function Y(): void; - export declare namespace Y { \ No newline at end of file + export declare namespace Y { +- var test: string; ++ var test: "foo"; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js b/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js index d36056c30d..68a2d47ca2 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js @@ -97,32 +97,5 @@ for (let f in (Foo.forIn = [])) { //// [expandoFunctionNestedAssigments.d.ts] declare function Foo(): void; -declare namespace Foo { - var inVariableInit: number; - var bla: { - foo: number; - }; - var baz: number; - var bar: number; - var fromIf: number; - var inIf: number; - var fromWhileCondition: number; - var fromWhileBody: number; - var fromWhileBodyNested: number; - var fromDoBody: number; - var fromDoBodyNested: number; - var fromDoCondition: number; - var forInit: number; - var forCond: number; - var forIncr: number; - var fromForBody: number; - var fromForBodyNested: number; - var forOf: any[]; - var fromForOfBody: number; - var fromForOfBodyNested: number; - var forIn: any[]; - var fromForInBody: number; - var fromForInBodyNested: number; -} declare let d: number; declare function bar(p?: number): void; diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff new file mode 100644 index 0000000000..458d8901f4 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionNestedAssigments.js.diff @@ -0,0 +1,35 @@ +--- old.expandoFunctionNestedAssigments.js ++++ new.expandoFunctionNestedAssigments.js +@@= skipped -96, +96 lines =@@ + + //// [expandoFunctionNestedAssigments.d.ts] + declare function Foo(): void; +-declare namespace Foo { +- var inVariableInit: number; +- var bla: { +- foo: number; +- }; +- var baz: number; +- var bar: number; +- var fromIf: number; +- var inIf: number; +- var fromWhileCondition: number; +- var fromWhileBody: number; +- var fromWhileBodyNested: number; +- var fromDoBody: number; +- var fromDoBodyNested: number; +- var fromDoCondition: number; +- var forInit: number; +- var forCond: number; +- var forIncr: number; +- var fromForBody: number; +- var fromForBodyNested: number; +- var forOf: any[]; +- var fromForOfBody: number; +- var fromForOfBodyNested: number; +- var forIn: any[]; +- var fromForInBody: number; +- var fromForInBodyNested: number; +-} + declare let d: number; + declare function bar(p?: number): void; \ 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..b21642c23b 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -30,3 +30,51 @@ declare const errorOnMissingReturn: { (): void; a: string; }; +declare namespace errorOnAssignmentBelowDecl { + var a: ""; +} +declare namespace errorOnAssignmentBelow { + var a: ""; +} +declare namespace errorOnMissingReturn { + var a: ""; +} + + +//// [DtsFileErrors] + + +isolatedDeclarationErrors.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. +isolatedDeclarationErrors.d.ts(6,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. +isolatedDeclarationErrors.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. +isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. + + +==== isolatedDeclarationErrors.d.ts (4 errors) ==== + declare function errorOnAssignmentBelowDecl(): void; + declare const errorOnAssignmentBelow: { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. + (): void; + a: string; + }; + declare const errorOnMissingReturn: { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. + (): void; + a: string; + }; + declare namespace errorOnAssignmentBelowDecl { + var a: ""; + } + declare namespace errorOnAssignmentBelow { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. + var a: ""; + } + declare namespace errorOnMissingReturn { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. + var 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..eefa704de1 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -15,4 +15,52 @@ +declare const errorOnMissingReturn: { + (): void; + a: string; -+}; \ No newline at end of file ++}; ++declare namespace errorOnAssignmentBelowDecl { ++ var a: ""; ++} ++declare namespace errorOnAssignmentBelow { ++ var a: ""; ++} ++declare namespace errorOnMissingReturn { ++ var a: ""; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++isolatedDeclarationErrors.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++isolatedDeclarationErrors.d.ts(6,15): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++isolatedDeclarationErrors.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++ ++ ++==== isolatedDeclarationErrors.d.ts (4 errors) ==== ++ declare function errorOnAssignmentBelowDecl(): void; ++ declare const errorOnAssignmentBelow: { ++ ~~~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++ (): void; ++ a: string; ++ }; ++ declare const errorOnMissingReturn: { ++ ~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++ (): void; ++ a: string; ++ }; ++ declare namespace errorOnAssignmentBelowDecl { ++ var a: ""; ++ } ++ declare namespace errorOnAssignmentBelow { ++ ~~~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++ var a: ""; ++ } ++ declare namespace errorOnMissingReturn { ++ ~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++ var 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..2d31d9464f 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -25,3 +25,12 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] export declare function foo(): void; +export declare namespace foo { + var apply: () => void; + var call: () => void; + var bind: () => void; + var caller: () => void; + var toString: () => void; + var length: 10; + var length: 10; +} diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff index ea6e1338aa..30e20882be 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -7,4 +7,13 @@ + + +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] -+export declare function foo(): void; \ No newline at end of file ++export declare function foo(): void; ++export declare namespace foo { ++ var apply: () => void; ++ var call: () => void; ++ var bind: () => void; ++ var caller: () => void; ++ var toString: () => void; ++ var length: 10; ++ var length: 10; ++} \ 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..e049bbe719 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js @@ -27,3 +27,45 @@ declare const SomeConstructor3: { (): void; staticMember: string; }; +declare namespace SomeConstructor2 { + var staticMember: "str"; +} +declare namespace SomeConstructor3 { + var staticMember: "str"; +} + + +//// [DtsFileErrors] + + +file.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. +file.d.ts(6,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. +file.d.ts(10,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. +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 const SomeConstructor3: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. + (): void; + staticMember: string; + }; + declare namespace SomeConstructor2 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. + var staticMember: "str"; + } + declare namespace SomeConstructor3 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. + var 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..c6167c784a 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -9,17 +9,6 @@ - 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; @@ -28,4 +17,54 @@ +declare const SomeConstructor3: { + (): void; + staticMember: string; -+}; \ No newline at end of file ++}; + declare namespace SomeConstructor2 { +- let staticMember: string; ++ var staticMember: "str"; + } +-declare function SomeConstructor3(): void; + declare namespace SomeConstructor3 { +- let staticMember_1: string; +- export { staticMember_1 as staticMember }; +-} +-declare class SomeConstructor3 { +- x: number; +-} ++ var staticMember: "str"; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++file.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++file.d.ts(6,15): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++file.d.ts(10,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++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 const SomeConstructor3: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++ (): void; ++ staticMember: string; ++ }; ++ declare namespace SomeConstructor2 { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++ var staticMember: "str"; ++ } ++ declare namespace SomeConstructor3 { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++ var 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..941473f0d1 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -37,3 +37,34 @@ declare const SelfReference: { (): any; staticMember: string; }; +declare namespace SomeConstructor3 { + var staticMember: "str"; +} +declare namespace SelfReference { + var staticMember: "str"; +} +declare namespace SomeConstructor2 { + var staticMember: "str"; +} + + +!!!! File file.d.ts differs from original emit in noCheck emit +//// [file.d.ts] +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -11,12 +11,12 @@ + (): any; + staticMember: string; + }; ++declare namespace SomeConstructor2 { ++ var staticMember: "str"; ++} + declare namespace SomeConstructor3 { + var staticMember: "str"; + } + declare namespace SelfReference { +- var staticMember: "str"; +-} +-declare namespace SomeConstructor2 { + var staticMember: "str"; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 3b57bcf92d..b95d65fb32 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -13,7 +13,20 @@ - let staticMember: string; -} -declare function SomeConstructor3(): void; --declare namespace SomeConstructor3 { ++declare const SomeConstructor: () => void; ++declare const SomeConstructor2: { ++ (): void; ++ staticMember: string; ++}; ++declare const SomeConstructor3: { ++ (): void; ++ staticMember: string; ++}; ++declare const SelfReference: { ++ (): any; ++ staticMember: string; ++}; + declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} @@ -21,23 +34,39 @@ - x: number; -} -declare function SelfReference(): SelfReference; --declare namespace SelfReference { ++ var staticMember: "str"; ++} + declare namespace SelfReference { - let staticMember_2: string; - export { staticMember_2 as staticMember }; -} -declare class SelfReference { - x: number; -} -+declare const SomeConstructor: () => void; -+declare const SomeConstructor2: { -+ (): void; -+ staticMember: string; -+}; -+declare const SomeConstructor3: { -+ (): void; -+ staticMember: string; -+}; -+declare const SelfReference: { -+ (): any; -+ staticMember: string; -+}; \ No newline at end of file ++ var staticMember: "str"; ++} ++declare namespace SomeConstructor2 { ++ var staticMember: "str"; ++} ++ ++ ++!!!! File file.d.ts differs from original emit in noCheck emit ++//// [file.d.ts] ++--- Expected The full check baseline +++++ Actual with noCheck set ++@@= skipped --13, +-13 lines =@@ ++ (): any; ++ staticMember: string; ++ }; +++declare namespace SomeConstructor2 { +++ var staticMember: "str"; +++} ++ declare namespace SomeConstructor3 { ++ var staticMember: "str"; ++ } ++ declare namespace SelfReference { ++- var staticMember: "str"; ++-} ++-declare namespace SomeConstructor2 { ++ var 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 1be352a5f7..d9a58f4eee 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js @@ -29,6 +29,7 @@ import PropTypes from 'prop-types'; declare function Foo({ bar }: { bar: any; }): JSX.Element; +export default Foo; declare namespace Foo { var propTypes: { bar: PropTypes.Requireable; @@ -37,7 +38,6 @@ declare namespace Foo { bar: boolean; }; } -export default Foo; //// [DtsFileErrors] @@ -56,6 +56,7 @@ jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(4,5): error TS2503: Cannot find n }): JSX.Element; ~~~ !!! error TS2503: Cannot find namespace 'JSX'. + export default Foo; declare namespace Foo { var propTypes: { bar: PropTypes.Requireable; @@ -64,5 +65,4 @@ jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(4,5): error TS2503: Cannot find n bar: boolean; }; } - export default Foo; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff index 762528d96c..38ef8cd9c6 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff @@ -10,6 +10,7 @@ declare function Foo({ bar }: { bar: any; }): JSX.Element; ++export default Foo; declare namespace Foo { - export { propTypes }; - export { defaultProps }; @@ -29,7 +30,6 @@ + bar: boolean; + }; +} -+export default Foo; + + +//// [DtsFileErrors] @@ -48,6 +48,7 @@ + }): JSX.Element; + ~~~ +!!! error TS2503: Cannot find namespace 'JSX'. ++ export default Foo; + declare namespace Foo { + var propTypes: { + bar: PropTypes.Requireable; @@ -56,5 +57,4 @@ + 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 05ce6daa8c..d7b9198917 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 { - var bar: number; + var bar: 12; } diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff new file mode 100644 index 0000000000..2a4309da8e --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff @@ -0,0 +1,9 @@ +--- 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; ++ var bar: 12; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js b/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js index dd94b7a51d..75be562ce4 100644 --- a/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js +++ b/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js @@ -53,7 +53,8 @@ export default Op; //// [test.d.ts] import Op from './op'; import { Po } from './po'; -export default function foo(): { +declare function foo(): { [Op.or]: any[]; [Po.ro]: {}; }; +export default foo; diff --git a/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js.diff b/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js.diff index 6db89e813c..3df69ae50d 100644 --- a/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js.diff +++ b/testdata/baselines/reference/submodule/compiler/uniqueSymbolPropertyDeclarationEmit.js.diff @@ -10,4 +10,14 @@ +const po_1 = require("./po"); function foo() { return { - [op_1.default.or]: [], \ No newline at end of file + [op_1.default.or]: [], +@@= skipped -18, +18 lines =@@ + //// [test.d.ts] + import Op from './op'; + import { Po } from './po'; +-export default function foo(): { ++declare function foo(): { + [Op.or]: any[]; + [Po.ro]: {}; + }; ++export default foo; \ 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..1018e817c5 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js @@ -47,6 +47,10 @@ assignmentToVoidZero2_1.j + assignmentToVoidZero2_1.k; //// [assignmentToVoidZero2.d.ts] export var j = 1; export var k = void 0; +declare namespace o { + var x: 1; + var y: any; +} export {}; //// [importer.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff index 828b31c77b..b0d29fd3e4 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff @@ -25,6 +25,10 @@ -export const j: 1; +export var j = 1; +export var k = void 0; ++declare namespace o { ++ var x: 1; ++ var y: any; ++} +export {}; //// [importer.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js index 7334c82bde..789e2612a2 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js @@ -39,6 +39,13 @@ function f(k) { //// [mod1.d.ts] export var K = NS.K; +declare namespace NS { + var K: { + new (): { + values(): any; + }; + }; +} export {}; //// [main.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff index 7951efe1d6..e64d37fb8f 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff @@ -22,9 +22,15 @@ -export var K: { - new (): { - values(): /*elided*/ any; -- }; --}; +export var K = NS.K; ++declare namespace NS { ++ var K: { ++ new (): { ++ values(): any; ++ }; + }; +-}; ++} +export {}; //// [main.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index 1790aa837e..9cd435c121 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -21,6 +21,6 @@ someFunc.someProp = 'yo'; //// [exportDefaultNamespace.d.ts] declare function someFunc(): string; declare namespace someFunc { - var someProp: string; + var someProp: "yo"; } export default someFunc; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff new file mode 100644 index 0000000000..e9c0d39175 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -0,0 +1,10 @@ +--- old.exportDefaultNamespace.js ++++ new.exportDefaultNamespace.js +@@= skipped -20, +20 lines =@@ + //// [exportDefaultNamespace.d.ts] + declare function someFunc(): string; + declare namespace someFunc { +- var someProp: string; ++ var 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 b2f09e37ec..2a3bc6ca85 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 { - var staticProp: (x: any, y: any) => any; -} declare class C2 { /** * A comment method1 @@ -141,3 +138,9 @@ declare class C2 { */ method1(x: number, y: number): number; } +declare namespace C1 { + var staticProp: (x: any, y: any) => any; +} +declare namespace C2 { + var staticProp: (x: any, y: any) => any; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff index bed9dc480f..ba6c417e66 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff @@ -20,7 +20,7 @@ - */ - method(x: number, y: number): number; -} - declare namespace C1 { +-declare namespace C1 { - /** - * A comment staticProp - * @param {number} x @@ -28,11 +28,11 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; -+ var staticProp: (x: any, y: any) => any; - } +-} declare class C2 { /** -@@= skipped -33, +11 lines =@@ + * A comment method1 +@@= skipped -33, +8 lines =@@ * @returns {number} */ method1(x: number, y: number): number; @@ -43,8 +43,11 @@ - * @returns {number} - */ - method2(x: number, y: number): number; --} --declare namespace C2 { ++} ++declare namespace C1 { ++ var staticProp: (x: any, y: any) => any; + } + declare namespace C2 { - /** - * A comment staticProp - * @param {number} x @@ -52,4 +55,5 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; ++ var staticProp: (x: any, y: any) => any; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js index a0e2b92ee7..bfd3f35958 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -52,3 +52,6 @@ export var Strings = Strings; export type HandlerOptions = { name: String; }; +declare namespace Handler { + var statische: () => void; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff index f39f380c86..1791878375 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -30,7 +30,11 @@ - static get OPTIONS(): number; - process(): void; -} --declare namespace Handler { ++export var Strings = Strings; ++export type HandlerOptions = { ++ name: String; ++}; + declare namespace Handler { - export { statische, Strings, HandlerOptions }; -} -declare function statische(): void; @@ -43,7 +47,6 @@ - * Should be able to export a type alias at the same time. - */ - name: string; -+export var Strings = Strings; -+export type HandlerOptions = { -+ name: String; - }; \ No newline at end of file +-}; ++ var statische: () => void; ++} \ 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 96bb98ab89..72988c332d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js @@ -22,6 +22,8 @@ declare class Base { } export declare class Foo extends Base { } -export {}; +export declare namespace Foo { + var foo: "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..4778933c30 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff @@ -11,8 +11,12 @@ -} declare class Base { static foo: string; -+} -+export declare class Foo extends Base { } - export {}; - //// [Bar.d.ts] \ No newline at end of file +-export {}; ++export declare class Foo extends Base { ++} ++export declare namespace Foo { ++ var foo: "foo"; ++} + //// [Bar.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js index fabe4f7586..8122fd77b1 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js @@ -90,9 +90,10 @@ function func() { } declare const _default: number; export default _default; //// [index2.d.ts] -export default function foo(): typeof foo; +declare function foo(): typeof foo; export declare const x: typeof foo; export { foo as bar }; +export default foo; //// [index3.d.ts] export default class Foo { a: Foo; @@ -111,8 +112,9 @@ export default _default; export type default = string | number; //// [index6.d.ts] // merge type alias and function (OK) -export default function func(): void; +declare function func(): void; export type default = string | number; +export default func; //// [DtsFileErrors] @@ -137,9 +139,10 @@ out/index6.d.ts(3,32): error TS2693: 'number' only refers to a type, but is bein export default _default; ==== out/index2.d.ts (0 errors) ==== - export default function foo(): typeof foo; + declare function foo(): typeof foo; export declare const x: typeof foo; export { foo as bar }; + export default foo; ==== out/index3.d.ts (0 errors) ==== export default class Foo { @@ -174,7 +177,7 @@ out/index6.d.ts(3,32): error TS2693: 'number' only refers to a type, but is bein ==== out/index6.d.ts (6 errors) ==== // merge type alias and function (OK) - export default function func(): void; + declare function func(): void; export type default = string | number; ~~~~~~ !!! error TS1128: Declaration or statement expected. @@ -188,4 +191,5 @@ out/index6.d.ts(3,32): error TS2693: 'number' only refers to a type, but is bein !!! error TS2693: 'string' only refers to a type, but is being used as a value here. ~~~~~~ !!! error TS2693: 'number' only refers to a type, but is being used as a value here. + export default func; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff index 913922e847..c10773deb2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff @@ -50,10 +50,12 @@ +declare const _default: number; export default _default; //// [index2.d.ts] - export default function foo(): typeof foo; +-export default function foo(): typeof foo; -export function x(): typeof foo; ++declare function foo(): typeof foo; +export declare const x: typeof foo; export { foo as bar }; ++export default foo; //// [index3.d.ts] export default class Foo { a: Foo; @@ -76,12 +78,11 @@ export default _default; +export type default = string | number; //// [index6.d.ts] --declare function func(): void; --type func = string | number; --export default func; +// merge type alias and function (OK) -+export default function func(): void; + declare function func(): void; +-type func = string | number; +export type default = string | number; + export default func; + + +//// [DtsFileErrors] @@ -106,9 +107,10 @@ + export default _default; + +==== out/index2.d.ts (0 errors) ==== -+ export default function foo(): typeof foo; ++ declare function foo(): typeof foo; + export declare const x: typeof foo; + export { foo as bar }; ++ export default foo; + +==== out/index3.d.ts (0 errors) ==== + export default class Foo { @@ -143,7 +145,7 @@ + +==== out/index6.d.ts (6 errors) ==== + // merge type alias and function (OK) -+ export default function func(): void; ++ declare function func(): void; + export type default = string | number; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. @@ -157,4 +159,5 @@ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + ~~~~~~ +!!! error TS2693: 'number' only refers to a type, but is being used as a value here. ++ export default func; + \ 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..8f21b7eef3 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -159,6 +159,16 @@ export type State = { hook: Hook; }; export = Context; +declare namespace Context { + var prototype: { + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct(input: Input, handle?: any): State; + }; +} //// [hook.d.ts] export type HookHandler = (arg: import("./context")) => void; export = Hook; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff index 6f918307d3..2529803e97 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff @@ -123,9 +123,17 @@ - */ - construct(input: Input, handle?: HookHandler | undefined): State; -} --declare namespace Context { + declare namespace Context { - export { Timer, Hook, HookHandler, Input, State }; --} ++ var prototype: { ++ /** ++ * @param {Input} input ++ * @param {HookHandler=} handle ++ * @returns {State} ++ */ ++ construct(input: Input, handle?: any): State; ++ }; + } -/** - * Imports - */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js index a6b96b0b08..2be77b97e2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js @@ -25,18 +25,18 @@ baz.normal = false; //// [source.d.ts] declare function foo(): void; -declare namespace foo { - var _a: boolean; - export { _a as null }; -} declare function bar(): void; -declare namespace bar { - var async: boolean; - var normal: boolean; -} declare function baz(): void; declare namespace baz { - var _b: boolean; - export var normal: boolean; - export { _b as class }; + var class_1: true; + export { class_1 as class }; + var normal: false; +} +declare namespace foo { + var null_1: true; + export { null_1 as null }; +} +declare namespace bar { + var async: true; + var normal: false; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff index be2842a198..98f2c3cbd5 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff @@ -1,28 +1,33 @@ --- old.jsDeclarationsFunctionKeywordProp.js +++ new.jsDeclarationsFunctionKeywordProp.js -@@= skipped -25, +25 lines =@@ +@@= skipped -24, +24 lines =@@ + //// [source.d.ts] declare function foo(): void; - declare namespace foo { +-declare namespace foo { - let _null: boolean; - export { _null as null }; -+ var _a: boolean; -+ export { _a as null }; - } +-} declare function bar(): void; - declare namespace bar { +-declare namespace bar { - let async: boolean; - let normal: boolean; -+ var async: boolean; -+ var normal: boolean; - } +-} declare function baz(): void; declare namespace baz { - let _class: boolean; - export { _class as class }; - let normal_1: boolean; - export { normal_1 as normal }; -+ var _b: boolean; -+ export var normal: boolean; -+ export { _b as class }; ++ var class_1: true; ++ export { class_1 as class }; ++ var normal: false; ++} ++declare namespace foo { ++ var null_1: true; ++ export { null_1 as null }; ++} ++declare namespace bar { ++ var async: true; ++ var 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 5b6b92828f..9d207981a8 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -171,83 +171,127 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; 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 }; + var x: 1; + var y: 1; + var break_1: 1; + export { break_1 as break }; + var case_1: 1; + export { case_1 as case }; + var catch_1: 1; + export { catch_1 as catch }; + var class_1: 1; + export { class_1 as class }; + var const_1: 1; + export { const_1 as const }; + var continue_1: 1; + export { continue_1 as continue }; + var debugger_1: 1; + export { debugger_1 as debugger }; + var default_1: 1; + export { default_1 as default }; + var delete_1: 1; + export { delete_1 as delete }; + var do_1: 1; + export { do_1 as do }; + var else_1: 1; + export { else_1 as else }; + var enum_1: 1; + export { enum_1 as enum }; + var export_1: 1; + export { export_1 as export }; + var extends_1: 1; + export { extends_1 as extends }; + var false_1: 1; + export { false_1 as false }; + var finally_1: 1; + export { finally_1 as finally }; + var for_1: 1; + export { for_1 as for }; + var function_1: 1; + export { function_1 as function }; + var if_1: 1; + export { if_1 as if }; + var import_1: 1; + export { import_1 as import }; + var in_1: 1; + export { in_1 as in }; + var instanceof_1: 1; + export { instanceof_1 as instanceof }; + var new_1: 1; + export { new_1 as new }; + var null_1: 1; + export { null_1 as null }; + var return_1: 1; + export { return_1 as return }; + var super_1: 1; + export { super_1 as super }; + var switch_1: 1; + export { switch_1 as switch }; + var this_1: 1; + export { this_1 as this }; + var throw_1: 1; + export { throw_1 as throw }; + var true_1: 1; + export { true_1 as true }; + var try_1: 1; + export { try_1 as try }; + var typeof_1: 1; + export { typeof_1 as typeof }; + var var_1: 1; + export { var_1 as var }; + var void_1: 1; + export { void_1 as void }; + var while_1: 1; + export { while_1 as while }; + var with_1: 1; + export { with_1 as with }; + var implements_1: 1; + export { implements_1 as implements }; + var interface_1: 1; + export { interface_1 as interface }; + var let_1: 1; + export { let_1 as let }; + var package_1: 1; + export { package_1 as package }; + var private_1: 1; + export { private_1 as private }; + var protected_1: 1; + export { protected_1 as protected }; + var public_1: 1; + export { public_1 as public }; + var static_1: 1; + export { static_1 as static }; + var yield_1: 1; + export { yield_1 as yield }; + var abstract: 1; + var as: 1; + var asserts: 1; + var any: 1; + var async: 1; + var await: 1; + var boolean: 1; + var constructor: 1; + var declare: 1; + var get: 1; + var infer: 1; + var is: 1; + var keyof: 1; + var module: 1; + var namespace: 1; + var never: 1; + var readonly: 1; + var require: 1; + var number: 1; + var object: 1; + var set: 1; + var string: 1; + var symbol: 1; + var type: 1; + var undefined: 1; + var unique: 1; + var unknown: 1; + var from: 1; + var global: 1; + var bigint: 1; + var of: 1; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff index 83f1da1389..8547e9ddba 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff @@ -127,83 +127,127 @@ - export let global: number; - export let bigint: number; - export let of: number; -+ 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 }; ++ var x: 1; ++ var y: 1; ++ var break_1: 1; ++ export { break_1 as break }; ++ var case_1: 1; ++ export { case_1 as case }; ++ var catch_1: 1; ++ export { catch_1 as catch }; ++ var class_1: 1; ++ export { class_1 as class }; ++ var const_1: 1; ++ export { const_1 as const }; ++ var continue_1: 1; ++ export { continue_1 as continue }; ++ var debugger_1: 1; ++ export { debugger_1 as debugger }; ++ var default_1: 1; ++ export { default_1 as default }; ++ var delete_1: 1; ++ export { delete_1 as delete }; ++ var do_1: 1; ++ export { do_1 as do }; ++ var else_1: 1; ++ export { else_1 as else }; ++ var enum_1: 1; ++ export { enum_1 as enum }; ++ var export_1: 1; ++ export { export_1 as export }; ++ var extends_1: 1; ++ export { extends_1 as extends }; ++ var false_1: 1; ++ export { false_1 as false }; ++ var finally_1: 1; ++ export { finally_1 as finally }; ++ var for_1: 1; ++ export { for_1 as for }; ++ var function_1: 1; ++ export { function_1 as function }; ++ var if_1: 1; ++ export { if_1 as if }; ++ var import_1: 1; ++ export { import_1 as import }; ++ var in_1: 1; ++ export { in_1 as in }; ++ var instanceof_1: 1; ++ export { instanceof_1 as instanceof }; ++ var new_1: 1; ++ export { new_1 as new }; ++ var null_1: 1; ++ export { null_1 as null }; ++ var return_1: 1; ++ export { return_1 as return }; ++ var super_1: 1; ++ export { super_1 as super }; ++ var switch_1: 1; ++ export { switch_1 as switch }; ++ var this_1: 1; ++ export { this_1 as this }; ++ var throw_1: 1; ++ export { throw_1 as throw }; ++ var true_1: 1; ++ export { true_1 as true }; ++ var try_1: 1; ++ export { try_1 as try }; ++ var typeof_1: 1; ++ export { typeof_1 as typeof }; ++ var var_1: 1; ++ export { var_1 as var }; ++ var void_1: 1; ++ export { void_1 as void }; ++ var while_1: 1; ++ export { while_1 as while }; ++ var with_1: 1; ++ export { with_1 as with }; ++ var implements_1: 1; ++ export { implements_1 as implements }; ++ var interface_1: 1; ++ export { interface_1 as interface }; ++ var let_1: 1; ++ export { let_1 as let }; ++ var package_1: 1; ++ export { package_1 as package }; ++ var private_1: 1; ++ export { private_1 as private }; ++ var protected_1: 1; ++ export { protected_1 as protected }; ++ var public_1: 1; ++ export { public_1 as public }; ++ var static_1: 1; ++ export { static_1 as static }; ++ var yield_1: 1; ++ export { yield_1 as yield }; ++ var abstract: 1; ++ var as: 1; ++ var asserts: 1; ++ var any: 1; ++ var async: 1; ++ var await: 1; ++ var boolean: 1; ++ var constructor: 1; ++ var declare: 1; ++ var get: 1; ++ var infer: 1; ++ var is: 1; ++ var keyof: 1; ++ var module: 1; ++ var namespace: 1; ++ var never: 1; ++ var readonly: 1; ++ var require: 1; ++ var number: 1; ++ var object: 1; ++ var set: 1; ++ var string: 1; ++ var symbol: 1; ++ var type: 1; ++ var undefined: 1; ++ var unique: 1; ++ var unknown: 1; ++ var from: 1; ++ var global: 1; ++ var bigint: 1; ++ var 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 7620ecc109..87d29f52ad 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js @@ -159,6 +159,11 @@ exports.origin = new source_1.Point2D(0, 0); * @param {number} len */ export declare function Vec(len: number): void; +/** + * @param {number} x + * @param {number} y + */ +export declare function Point2D(x: number, y: number): any; export declare namespace Vec { var prototype: { /** @@ -168,11 +173,6 @@ export declare namespace Vec { magnitude(): number; }; } -/** - * @param {number} x - * @param {number} y - */ -export declare function Point2D(x: number, y: number): any; export declare namespace Point2D { var prototype: { __proto__: typeof Vec; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff index 34ba5b7cfa..bffe17438c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff @@ -28,16 +28,8 @@ - */ - dot(other: Vec): number; - magnitude(): number; +-} +export declare function Vec(len: number): void; -+export declare namespace Vec { -+ var prototype: { -+ /** -+ * @param {Vec} other -+ */ -+ dot(other: Vec): number; -+ magnitude(): number; -+ }; - } /** * @param {number} x * @param {number} y @@ -61,6 +53,15 @@ - get y(): number; - __proto__: typeof Vec; +export declare function Point2D(x: number, y: number): any; ++export declare namespace Vec { ++ var prototype: { ++ /** ++ * @param {Vec} other ++ */ ++ dot(other: Vec): number; ++ magnitude(): number; ++ }; ++} +export declare namespace Point2D { + var prototype: { + __proto__: typeof Vec; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index d637f33bc4..f090e2e254 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -29,3 +29,7 @@ MyClass.staticProperty = 123; //// [source.d.ts] export = MyClass; export type DoneCB = (failures: number) ; +declare namespace MyClass { + var staticMethod: () => void; + var staticProperty: 123; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 32b4e24364..7346c94309 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -26,13 +26,15 @@ -declare class MyClass { - method(): void; -} --declare namespace MyClass { ++export type DoneCB = (failures: number) ; + declare namespace MyClass { - export { staticMethod, staticProperty, DoneCB }; --} ++ var staticMethod: () => void; ++ var staticProperty: 123; + } -declare function staticMethod(): void; -declare var staticProperty: number; -/** - * Callback to be invoked when test execution is complete. - */ --type DoneCB = (failures: number) => any; -+export type DoneCB = (failures: number) ; \ No newline at end of file +-type DoneCB = (failures: number) => any; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js index d76ffef284..f939a3df17 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -16,17 +16,29 @@ module.exports = foo; //// [index.d.ts] +declare function foo(): void; export = foo; +declare namespace foo { + var foo: typeof foo; + var default_1: typeof foo; + export { default_1 as default }; +} //// [DtsFileErrors] -out/index.d.ts(1,10): error TS2304: Cannot find name 'foo'. +out/index.d.ts(4,9): error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. ==== out/index.d.ts (1 errors) ==== + declare function foo(): void; export = foo; - ~~~ -!!! error TS2304: Cannot find name 'foo'. + declare namespace foo { + var foo: typeof foo; + ~~~ +!!! error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. + var default_1: typeof foo; + export { default_1 as default }; + } \ 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..d5acb87385 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff @@ -9,22 +9,32 @@ //// [index.d.ts] - export = foo; --declare function foo(): void; --declare namespace foo { +-export = foo; + declare function foo(): void; ++export = foo; + declare namespace foo { - export { foo }; - export { foo as default }; --} ++ var foo: typeof foo; ++ var default_1: typeof foo; ++ export { default_1 as default }; + } + + +//// [DtsFileErrors] + + -+out/index.d.ts(1,10): error TS2304: Cannot find name 'foo'. ++out/index.d.ts(4,9): error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. + + +==== out/index.d.ts (1 errors) ==== ++ declare function foo(): void; + export = foo; -+ ~~~ -+!!! error TS2304: Cannot find name 'foo'. ++ declare namespace foo { ++ var foo: typeof foo; ++ ~~~ ++!!! error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. ++ var default_1: typeof foo; ++ export { default_1 as default }; ++ } + \ 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 8aa44cbc27..f350282d4c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -123,15 +123,7 @@ function j() { } //// [index.d.ts] export declare function a(): void; export declare function b(): void; -export declare namespace b { - var cat: string; -} export declare function c(): void; -export declare namespace c { - var Cls: { - new (): {}; - }; -} /** * @param {number} a * @param {number} b @@ -150,9 +142,6 @@ export declare function e(a: T, b: U): T & U; * @param {T} a */ export declare function f(a: T): T; -export declare namespace f { - var self: typeof f; -} /** * @param {{x: string}} a * @param {{y: typeof b}} b @@ -177,3 +166,14 @@ export declare function i(): void; export { i as ii }; export { j as jj }; export declare function j(): void; +export declare namespace b { + var cat: "cat"; +} +export declare namespace c { + var Cls: { + new (): {}; + }; +} +export declare namespace f { + var self: typeof f; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 8e2b016ad7..3ac3e833ca 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -25,20 +25,14 @@ -export function b(): void; -export namespace b { - let cat: string; -+export declare function a(): void; -+export declare function b(): void; -+export declare namespace b { -+ var cat: string; - } +-} -export function c(): void; -export namespace c { - export { Cls }; +-} ++export declare function a(): void; ++export declare function b(): void; +export declare function c(): void; -+export declare namespace c { -+ var Cls: { -+ new (): {}; -+ }; - } /** * @param {number} a * @param {number} b @@ -65,10 +59,8 @@ -export function i(): void; -export function j(): void; -declare class Cls { +-} +export declare function f(a: T): T; -+export declare namespace f { -+ var self: typeof f; - } /** * @param {{x: string}} a * @param {{y: typeof b}} b @@ -85,7 +77,7 @@ /** * @param {{x: string}} a * @param {{y: typeof b}} b -@@= skipped -50, +49 lines =@@ +@@= skipped -50, +38 lines =@@ declare function hh(a: { x: string; }, b: { @@ -98,4 +90,15 @@ +export declare function i(): void; +export { i as ii }; +export { j as jj }; -+export declare function j(): void; \ No newline at end of file ++export declare function j(): void; ++export declare namespace b { ++ var cat: "cat"; ++} ++export declare namespace c { ++ var Cls: { ++ new (): {}; ++ }; ++} ++export declare namespace f { ++ var self: typeof f; ++} \ 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 6be074102e..f9954e57e9 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -62,7 +62,13 @@ export {}; //// [base.d.ts] +declare class Base { + constructor(); +} export = BaseFactory; +declare namespace BaseFactory { + var Base: typeof Base; +} //// [file.d.ts] export type BaseFactory = import('./base'); export type BaseFactoryFactory = (factory: import('./base')) ; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff index f2dae38cd5..e66f3a065f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -16,13 +16,18 @@ //// [base.d.ts] - export = BaseFactory; +-export = BaseFactory; -declare function BaseFactory(): Base; -declare namespace BaseFactory { - export { Base }; -} --declare class Base { --} + declare class Base { ++ constructor(); ++} ++export = BaseFactory; ++declare namespace BaseFactory { ++ var Base: typeof Base; + } //// [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..9db54f9a8b 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(); +} export = BaseFactory; +declare namespace BaseFactory { + var Base: typeof Base; +} //// [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..e08e04b69a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff @@ -16,13 +16,18 @@ //// [base.d.ts] - export = BaseFactory; +-export = BaseFactory; -declare function BaseFactory(): Base; -declare namespace BaseFactory { - export { Base }; -} --declare class Base { --} + declare class Base { ++ constructor(); ++} ++export = BaseFactory; ++declare namespace BaseFactory { ++ var Base: typeof Base; + } //// [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 5959f68704..7c01defed7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -195,6 +195,14 @@ declare const TabbedShowLayout: { }; }; export default TabbedShowLayout; +declare namespace TabbedShowLayout { + var propTypes: { + version: PropTypes.Requireable; + }; + var defaultProps: { + tabs: undefined; + }; +} //// [jsDeclarationsReactComponents2.d.ts] import React from "react"; /** @@ -202,6 +210,11 @@ import React from "react"; */ declare const TabbedShowLayout: React.SFC; export default TabbedShowLayout; +declare namespace TabbedShowLayout { + var defaultProps: { + tabs: string; + }; +} //// [jsDeclarationsReactComponents3.d.ts] /** * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} @@ -214,6 +227,11 @@ declare const TabbedShowLayout: { elem: string; }) => JSX.Element); export default TabbedShowLayout; +declare namespace TabbedShowLayout { + var defaultProps: { + tabs: string; + }; +} //// [jsDeclarationsReactComponents4.d.ts] declare const TabbedShowLayout: { (prop: { @@ -224,11 +242,17 @@ declare const TabbedShowLayout: { }; }; export default TabbedShowLayout; +declare namespace TabbedShowLayout { + var defaultProps: { + tabs: string; + }; +} //// [jsDeclarationsReactComponents5.d.ts] import PropTypes from 'prop-types'; declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; +export default Tree; declare namespace Tree { var propTypes: { classes: PropTypes.Requireable; @@ -238,26 +262,35 @@ declare namespace Tree { parentSource: string; }; } -export default Tree; //// [DtsFileErrors] out/jsDeclarationsReactComponents1.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. +out/jsDeclarationsReactComponents1.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2503: Cannot find namespace 'JSX'. +out/jsDeclarationsReactComponents1.d.ts(12,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. out/jsDeclarationsReactComponents2.d.ts(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations. +out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents2.d.ts(7,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(10,7): error TS2503: Cannot find namespace 'JSX'. +out/jsDeclarationsReactComponents3.d.ts(12,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(4,9): error TS2503: Cannot find namespace 'JSX'. +out/jsDeclarationsReactComponents4.d.ts(10,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. out/jsDeclarationsReactComponents5.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. -==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== +==== out/jsDeclarationsReactComponents1.d.ts (4 errors) ==== import PropTypes from "prop-types"; ~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ({}: {}): JSX.Element; ~~~ !!! error TS2503: Cannot find namespace 'JSX'. @@ -269,8 +302,18 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac }; }; export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + var propTypes: { + version: PropTypes.Requireable; + }; + var defaultProps: { + tabs: undefined; + }; + } -==== out/jsDeclarationsReactComponents2.d.ts (1 errors) ==== +==== out/jsDeclarationsReactComponents2.d.ts (3 errors) ==== import React from "react"; ~~~~~~~ !!! error TS2307: Cannot find module 'react' or its corresponding type declarations. @@ -278,13 +321,24 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac * @type {React.SFC} */ declare const TabbedShowLayout: React.SFC; + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + var defaultProps: { + tabs: string; + }; + } -==== out/jsDeclarationsReactComponents3.d.ts (1 errors) ==== +==== out/jsDeclarationsReactComponents3.d.ts (3 errors) ==== /** * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} */ declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. defaultProps: { tabs: string; }; @@ -294,9 +348,18 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac ~~~ !!! error TS2503: Cannot find namespace 'JSX'. export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + var defaultProps: { + tabs: string; + }; + } -==== out/jsDeclarationsReactComponents4.d.ts (1 errors) ==== +==== out/jsDeclarationsReactComponents4.d.ts (3 errors) ==== declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. (prop: { className: string; }): JSX.Element; @@ -307,6 +370,13 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac }; }; export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + var defaultProps: { + tabs: string; + }; + } ==== out/jsDeclarationsReactComponents5.d.ts (2 errors) ==== import PropTypes from 'prop-types'; @@ -317,6 +387,7 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac }): JSX.Element; ~~~ !!! error TS2503: Cannot find namespace 'JSX'. + export default Tree; declare namespace Tree { var propTypes: { classes: PropTypes.Requireable; @@ -326,5 +397,4 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac 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 335599e1e2..6895527390 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -90,6 +90,14 @@ + }; +}; +export default TabbedShowLayout; ++declare namespace TabbedShowLayout { ++ var propTypes: { ++ version: PropTypes.Requireable; ++ }; ++ var defaultProps: { ++ tabs: undefined; ++ }; ++} //// [jsDeclarationsReactComponents2.d.ts] -export default TabbedShowLayout; -/** @@ -102,16 +110,26 @@ + */ +declare const TabbedShowLayout: React.SFC; +export default TabbedShowLayout; ++declare namespace TabbedShowLayout { ++ var defaultProps: { ++ tabs: string; ++ }; ++} //// [jsDeclarationsReactComponents3.d.ts] -export default TabbedShowLayout; /** * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} */ -@@= skipped -31, +29 lines =@@ +@@= skipped -31, +42 lines =@@ } & ((props?: { elem: string; }) => JSX.Element); +export default TabbedShowLayout; ++declare namespace TabbedShowLayout { ++ var defaultProps: { ++ tabs: string; ++ }; ++} //// [jsDeclarationsReactComponents4.d.ts] +declare const TabbedShowLayout: { + (prop: { @@ -125,17 +143,21 @@ -declare function TabbedShowLayout(prop: { - className: string; -}): JSX.Element; --declare namespace TabbedShowLayout { + declare namespace TabbedShowLayout { - namespace defaultProps { - let tabs: string; - } --} ++ var defaultProps: { ++ tabs: string; ++ }; + } //// [jsDeclarationsReactComponents5.d.ts] -export default Tree; +import PropTypes from 'prop-types'; declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; ++export default Tree; declare namespace Tree { - namespace propTypes { - let classes: PropTypes.Requireable; @@ -154,26 +176,35 @@ + }; } -import PropTypes from 'prop-types'; -+export default Tree; + + +//// [DtsFileErrors] + + +out/jsDeclarationsReactComponents1.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. ++out/jsDeclarationsReactComponents1.d.ts(2,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2503: Cannot find namespace 'JSX'. ++out/jsDeclarationsReactComponents1.d.ts(12,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents2.d.ts(1,19): error TS2307: Cannot find module 'react' or its corresponding type declarations. ++out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents2.d.ts(7,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(10,7): error TS2503: Cannot find namespace 'JSX'. ++out/jsDeclarationsReactComponents3.d.ts(12,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(4,9): error TS2503: Cannot find namespace 'JSX'. ++out/jsDeclarationsReactComponents4.d.ts(10,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents5.d.ts(1,23): error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. +out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespace 'JSX'. + + -+==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== ++==== out/jsDeclarationsReactComponents1.d.ts (4 errors) ==== + import PropTypes from "prop-types"; + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'prop-types' or its corresponding type declarations. + declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + ({}: {}): JSX.Element; + ~~~ +!!! error TS2503: Cannot find namespace 'JSX'. @@ -185,8 +216,18 @@ + }; + }; + export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ var propTypes: { ++ version: PropTypes.Requireable; ++ }; ++ var defaultProps: { ++ tabs: undefined; ++ }; ++ } + -+==== out/jsDeclarationsReactComponents2.d.ts (1 errors) ==== ++==== out/jsDeclarationsReactComponents2.d.ts (3 errors) ==== + import React from "react"; + ~~~~~~~ +!!! error TS2307: Cannot find module 'react' or its corresponding type declarations. @@ -194,13 +235,24 @@ + * @type {React.SFC} + */ + declare const TabbedShowLayout: React.SFC; ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ var defaultProps: { ++ tabs: string; ++ }; ++ } + -+==== out/jsDeclarationsReactComponents3.d.ts (1 errors) ==== ++==== out/jsDeclarationsReactComponents3.d.ts (3 errors) ==== + /** + * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} + */ + declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + defaultProps: { + tabs: string; + }; @@ -210,9 +262,18 @@ + ~~~ +!!! error TS2503: Cannot find namespace 'JSX'. + export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ var defaultProps: { ++ tabs: string; ++ }; ++ } + -+==== out/jsDeclarationsReactComponents4.d.ts (1 errors) ==== ++==== out/jsDeclarationsReactComponents4.d.ts (3 errors) ==== + declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + (prop: { + className: string; + }): JSX.Element; @@ -223,6 +284,13 @@ + }; + }; + export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ var defaultProps: { ++ tabs: string; ++ }; ++ } + +==== out/jsDeclarationsReactComponents5.d.ts (2 errors) ==== + import PropTypes from 'prop-types'; @@ -233,6 +301,7 @@ + }): JSX.Element; + ~~~ +!!! error TS2503: Cannot find namespace 'JSX'. ++ export default Tree; + declare namespace Tree { + var propTypes: { + classes: PropTypes.Requireable; @@ -242,5 +311,4 @@ + 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..aa17d9d8f9 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js @@ -106,3 +106,11 @@ declare class CC { }; } declare var C5: any; +declare namespace Ns { + var C1: { + new (): { + method(): number; + }; + }; + var C5: any; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff index 97a55138f3..846d4fc94d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff @@ -47,4 +47,11 @@ -} -declare class C3 implements A { - method(): number; --} \ No newline at end of file ++declare namespace Ns { ++ var C1: { ++ new (): { ++ method(): number; ++ }; ++ }; ++ 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 088080daf9..82a3d6981b 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js @@ -172,83 +172,127 @@ foo.of = 1; //// [nullPropertyName.d.ts] declare function foo(): void; 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 }; + var x: 1; + var y: 1; + var break_1: 1; + export { break_1 as break }; + var case_1: 1; + export { case_1 as case }; + var catch_1: 1; + export { catch_1 as catch }; + var class_1: 1; + export { class_1 as class }; + var const_1: 1; + export { const_1 as const }; + var continue_1: 1; + export { continue_1 as continue }; + var debugger_1: 1; + export { debugger_1 as debugger }; + var default_1: 1; + export { default_1 as default }; + var delete_1: 1; + export { delete_1 as delete }; + var do_1: 1; + export { do_1 as do }; + var else_1: 1; + export { else_1 as else }; + var enum_1: 1; + export { enum_1 as enum }; + var export_1: 1; + export { export_1 as export }; + var extends_1: 1; + export { extends_1 as extends }; + var false_1: 1; + export { false_1 as false }; + var finally_1: 1; + export { finally_1 as finally }; + var for_1: 1; + export { for_1 as for }; + var function_1: 1; + export { function_1 as function }; + var if_1: 1; + export { if_1 as if }; + var import_1: 1; + export { import_1 as import }; + var in_1: 1; + export { in_1 as in }; + var instanceof_1: 1; + export { instanceof_1 as instanceof }; + var new_1: 1; + export { new_1 as new }; + var null_1: 1; + export { null_1 as null }; + var return_1: 1; + export { return_1 as return }; + var super_1: 1; + export { super_1 as super }; + var switch_1: 1; + export { switch_1 as switch }; + var this_1: 1; + export { this_1 as this }; + var throw_1: 1; + export { throw_1 as throw }; + var true_1: 1; + export { true_1 as true }; + var try_1: 1; + export { try_1 as try }; + var typeof_1: 1; + export { typeof_1 as typeof }; + var var_1: 1; + export { var_1 as var }; + var void_1: 1; + export { void_1 as void }; + var while_1: 1; + export { while_1 as while }; + var with_1: 1; + export { with_1 as with }; + var implements_1: 1; + export { implements_1 as implements }; + var interface_1: 1; + export { interface_1 as interface }; + var let_1: 1; + export { let_1 as let }; + var package_1: 1; + export { package_1 as package }; + var private_1: 1; + export { private_1 as private }; + var protected_1: 1; + export { protected_1 as protected }; + var public_1: 1; + export { public_1 as public }; + var static_1: 1; + export { static_1 as static }; + var yield_1: 1; + export { yield_1 as yield }; + var abstract: 1; + var as: 1; + var asserts: 1; + var any: 1; + var async: 1; + var await: 1; + var boolean: 1; + var constructor: 1; + var declare: 1; + var get: 1; + var infer: 1; + var is: 1; + var keyof: 1; + var module: 1; + var namespace: 1; + var never: 1; + var readonly: 1; + var require: 1; + var number: 1; + var object: 1; + var set: 1; + var string: 1; + var symbol: 1; + var type: 1; + var undefined: 1; + var unique: 1; + var unknown: 1; + var from: 1; + var global: 1; + var bigint: 1; + var of: 1; } diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff new file mode 100644 index 0000000000..e61f85a8f9 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff @@ -0,0 +1,209 @@ +--- old.nullPropertyName.js ++++ new.nullPropertyName.js +@@= skipped -171, +171 lines =@@ + //// [nullPropertyName.d.ts] + declare function foo(): void; + 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 }; ++ var x: 1; ++ var y: 1; ++ var break_1: 1; ++ export { break_1 as break }; ++ var case_1: 1; ++ export { case_1 as case }; ++ var catch_1: 1; ++ export { catch_1 as catch }; ++ var class_1: 1; ++ export { class_1 as class }; ++ var const_1: 1; ++ export { const_1 as const }; ++ var continue_1: 1; ++ export { continue_1 as continue }; ++ var debugger_1: 1; ++ export { debugger_1 as debugger }; ++ var default_1: 1; ++ export { default_1 as default }; ++ var delete_1: 1; ++ export { delete_1 as delete }; ++ var do_1: 1; ++ export { do_1 as do }; ++ var else_1: 1; ++ export { else_1 as else }; ++ var enum_1: 1; ++ export { enum_1 as enum }; ++ var export_1: 1; ++ export { export_1 as export }; ++ var extends_1: 1; ++ export { extends_1 as extends }; ++ var false_1: 1; ++ export { false_1 as false }; ++ var finally_1: 1; ++ export { finally_1 as finally }; ++ var for_1: 1; ++ export { for_1 as for }; ++ var function_1: 1; ++ export { function_1 as function }; ++ var if_1: 1; ++ export { if_1 as if }; ++ var import_1: 1; ++ export { import_1 as import }; ++ var in_1: 1; ++ export { in_1 as in }; ++ var instanceof_1: 1; ++ export { instanceof_1 as instanceof }; ++ var new_1: 1; ++ export { new_1 as new }; ++ var null_1: 1; ++ export { null_1 as null }; ++ var return_1: 1; ++ export { return_1 as return }; ++ var super_1: 1; ++ export { super_1 as super }; ++ var switch_1: 1; ++ export { switch_1 as switch }; ++ var this_1: 1; ++ export { this_1 as this }; ++ var throw_1: 1; ++ export { throw_1 as throw }; ++ var true_1: 1; ++ export { true_1 as true }; ++ var try_1: 1; ++ export { try_1 as try }; ++ var typeof_1: 1; ++ export { typeof_1 as typeof }; ++ var var_1: 1; ++ export { var_1 as var }; ++ var void_1: 1; ++ export { void_1 as void }; ++ var while_1: 1; ++ export { while_1 as while }; ++ var with_1: 1; ++ export { with_1 as with }; ++ var implements_1: 1; ++ export { implements_1 as implements }; ++ var interface_1: 1; ++ export { interface_1 as interface }; ++ var let_1: 1; ++ export { let_1 as let }; ++ var package_1: 1; ++ export { package_1 as package }; ++ var private_1: 1; ++ export { private_1 as private }; ++ var protected_1: 1; ++ export { protected_1 as protected }; ++ var public_1: 1; ++ export { public_1 as public }; ++ var static_1: 1; ++ export { static_1 as static }; ++ var yield_1: 1; ++ export { yield_1 as yield }; ++ var abstract: 1; ++ var as: 1; ++ var asserts: 1; ++ var any: 1; ++ var async: 1; ++ var await: 1; ++ var boolean: 1; ++ var constructor: 1; ++ var declare: 1; ++ var get: 1; ++ var infer: 1; ++ var is: 1; ++ var keyof: 1; ++ var module: 1; ++ var namespace: 1; ++ var never: 1; ++ var readonly: 1; ++ var require: 1; ++ var number: 1; ++ var object: 1; ++ var set: 1; ++ var string: 1; ++ var symbol: 1; ++ var type: 1; ++ var undefined: 1; ++ var unique: 1; ++ var unknown: 1; ++ var from: 1; ++ var global: 1; ++ var bigint: 1; ++ var 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 baed70ee8a..a5574bc9fa 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -170,10 +170,6 @@ var n = ExpandoExpr3.prop + ExpandoExpr3.m(13) + new ExpandoExpr3().n; //// [typeFromPropertyAssignment29.d.ts] declare function ExpandoDecl(n: number): string; -declare namespace ExpandoDecl { - var prop: number; - var m: (n: number) => number; -} declare var n: number; declare const ExpandoExpr: { (n: number): string; @@ -196,27 +192,89 @@ declare function ExpandoNested(n: number): { (m: number): number; total: number; }; -declare namespace ExpandoNested { - var also: number; -} declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { - var p1: number; -} -declare namespace ExpandoMerge { - var p2: number; + export var p2: number; + declare namespace ExpandoNested { + var also: -1; + } + declare namespace ExpandoMerge { + var p1: 111; + } + declare namespace ExpandoDecl { + var prop: 2; + var m: (n: number) => number; + } + declare namespace ExpandoExpr { + var prop: { + x: number; + }; + var prop: { + y: string; + }; + var m: (n: number) => number; + } + declare namespace ExpandoArrow { + var prop: 2; + var m: (n: number) => number; + } } declare namespace ExpandoMerge { - var p3: number; + export var p3: number; + declare namespace ExpandoNested { + var also: -1; + } + declare namespace ExpandoMerge { + var p1: 111; + } + declare namespace ExpandoDecl { + var prop: 2; + var m: (n: number) => number; + } + declare namespace ExpandoExpr { + var prop: { + x: number; + }; + var prop: { + y: string; + }; + var m: (n: number) => number; + } + declare namespace ExpandoArrow { + var prop: 2; + var m: (n: number) => number; + } } declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; - namespace ExpandoNamespace { - var p6: number; - } export function foo(): typeof ExpandoNamespace; - export {}; + declare namespace ExpandoDecl { + var prop: 2; + var m: (n: number) => number; + } + declare namespace ExpandoExpr { + var prop: { + x: number; + }; + var prop: { + y: string; + }; + var m: (n: number) => number; + } + declare namespace ExpandoArrow { + var prop: 2; + var m: (n: number) => number; + } + declare namespace ExpandoNested { + var also: -1; + } + declare namespace ExpandoMerge { + var p1: 111; + } + declare namespace ExpandoNamespace { + var p6: 42; + } } // Should not work in Typescript -- must be const declare var ExpandoExpr2: (n: number) => string; @@ -233,3 +291,80 @@ declare var ExpandoExpr3: { }; }; declare var n: number; +declare namespace ExpandoDecl { + var prop: 2; + var m: (n: number) => number; +} +declare namespace ExpandoExpr { + var prop: { + x: number; + }; + var prop: { + y: string; + }; + var m: (n: number) => number; +} +declare namespace ExpandoArrow { + var prop: 2; + var m: (n: number) => number; +} +declare namespace ExpandoNested { + var also: -1; +} +declare namespace ExpandoMerge { + var p1: 111; +} +declare namespace ExpandoNamespace { + var p6: 42; +} + + +!!!! File typeFromPropertyAssignment29.d.ts differs from original emit in noCheck emit +//// [typeFromPropertyAssignment29.d.ts] +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -24,12 +24,6 @@ + declare function ExpandoMerge(n: number): number; + declare namespace ExpandoMerge { + export var p2: number; +- declare namespace ExpandoNested { +- var also: -1; +- } +- declare namespace ExpandoMerge { +- var p1: 111; +- } + declare namespace ExpandoDecl { + var prop: 2; + var m: (n: number) => number; +@@ -46,10 +40,20 @@ + declare namespace ExpandoArrow { + var prop: 2; + var m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ var also: -1; ++ } ++ declare namespace ExpandoMerge { ++ var p1: 111; + } + } + declare namespace ExpandoMerge { + export var p3: number; ++ declare namespace ExpandoArrow { ++ var prop: 2; ++ var m: (n: number) => number; ++ } + declare namespace ExpandoNested { + var also: -1; + } +@@ -67,10 +71,6 @@ + var prop: { + y: string; + }; +- var m: (n: number) => number; +- } +- declare namespace ExpandoArrow { +- var prop: 2; + var m: (n: number) => number; + } + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index bea9405738..bd53afbe7e 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -31,7 +31,18 @@ }; ExpandoExpr3.prop = 3; ExpandoExpr3.m = function (n) { -@@= skipped -27, +25 lines =@@ +@@= skipped -13, +11 lines =@@ + + //// [typeFromPropertyAssignment29.d.ts] + declare function ExpandoDecl(n: number): string; +-declare namespace ExpandoDecl { +- var prop: number; +- var m: (n: number) => number; +-} + declare var n: number; + declare const ExpandoExpr: { + (n: number): string; +@@= skipped -14, +10 lines =@@ x?: undefined; y: string; }; @@ -47,9 +58,105 @@ }; declare function ExpandoNested(n: number): { (m: number): number; -@@= skipped -34, +34 lines =@@ + total: number; + }; +-declare namespace ExpandoNested { +- var also: number; +-} + declare function ExpandoMerge(n: number): number; + declare namespace ExpandoMerge { +- var p1: number; +-} +-declare namespace ExpandoMerge { +- var p2: number; +-} +-declare namespace ExpandoMerge { +- var p3: number; ++ export var p2: number; ++ declare namespace ExpandoNested { ++ var also: -1; ++ } ++ declare namespace ExpandoMerge { ++ var p1: 111; ++ } ++ declare namespace ExpandoDecl { ++ var prop: 2; ++ var m: (n: number) => number; ++ } ++ declare namespace ExpandoExpr { ++ var prop: { ++ x: number; ++ }; ++ var prop: { ++ y: string; ++ }; ++ var m: (n: number) => number; ++ } ++ declare namespace ExpandoArrow { ++ var prop: 2; ++ var m: (n: number) => number; ++ } ++} ++declare namespace ExpandoMerge { ++ export var p3: number; ++ declare namespace ExpandoNested { ++ var also: -1; ++ } ++ declare namespace ExpandoMerge { ++ var p1: 111; ++ } ++ declare namespace ExpandoDecl { ++ var prop: 2; ++ var m: (n: number) => number; ++ } ++ declare namespace ExpandoExpr { ++ var prop: { ++ x: number; ++ }; ++ var prop: { ++ y: string; ++ }; ++ var m: (n: number) => number; ++ } ++ declare namespace ExpandoArrow { ++ var prop: 2; ++ var m: (n: number) => number; ++ } + } + declare var n: number; + declare namespace Ns { + function ExpandoNamespace(): void; +- namespace ExpandoNamespace { +- var p6: number; +- } export function foo(): typeof ExpandoNamespace; - export {}; +- export {}; ++ declare namespace ExpandoDecl { ++ var prop: 2; ++ var m: (n: number) => number; ++ } ++ declare namespace ExpandoExpr { ++ var prop: { ++ x: number; ++ }; ++ var prop: { ++ y: string; ++ }; ++ var m: (n: number) => number; ++ } ++ declare namespace ExpandoArrow { ++ var prop: 2; ++ var m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ var also: -1; ++ } ++ declare namespace ExpandoMerge { ++ var p1: 111; ++ } ++ declare namespace ExpandoNamespace { ++ var p6: 42; ++ } } +// Should not work in Typescript -- must be const declare var ExpandoExpr2: (n: number) => string; @@ -62,4 +169,84 @@ +// Class expressions shouldn't work in typescript either declare var ExpandoExpr3: { new (): { - n: number; \ No newline at end of file + n: number; + }; + }; + declare var n: number; ++declare namespace ExpandoDecl { ++ var prop: 2; ++ var m: (n: number) => number; ++} ++declare namespace ExpandoExpr { ++ var prop: { ++ x: number; ++ }; ++ var prop: { ++ y: string; ++ }; ++ var m: (n: number) => number; ++} ++declare namespace ExpandoArrow { ++ var prop: 2; ++ var m: (n: number) => number; ++} ++declare namespace ExpandoNested { ++ var also: -1; ++} ++declare namespace ExpandoMerge { ++ var p1: 111; ++} ++declare namespace ExpandoNamespace { ++ var p6: 42; ++} ++ ++ ++!!!! File typeFromPropertyAssignment29.d.ts differs from original emit in noCheck emit ++//// [typeFromPropertyAssignment29.d.ts] ++--- Expected The full check baseline +++++ Actual with noCheck set ++@@= skipped --164, +-156 lines =@@ ++ declare function ExpandoMerge(n: number): number; ++ declare namespace ExpandoMerge { ++ export var p2: number; ++- declare namespace ExpandoNested { ++- var also: -1; ++- } ++- declare namespace ExpandoMerge { ++- var p1: 111; ++- } ++ declare namespace ExpandoDecl { ++ var prop: 2; ++ var m: (n: number) => number; ++@@= skipped -22, +16 lines =@@ ++ declare namespace ExpandoArrow { ++ var prop: 2; ++ var m: (n: number) => number; +++ } +++ declare namespace ExpandoNested { +++ var also: -1; +++ } +++ declare namespace ExpandoMerge { +++ var p1: 111; ++ } ++ } ++ declare namespace ExpandoMerge { ++ export var p3: number; +++ declare namespace ExpandoArrow { +++ var prop: 2; +++ var m: (n: number) => number; +++ } ++ declare namespace ExpandoNested { ++ var also: -1; ++ } ++@@= skipped -21, +31 lines =@@ ++ var prop: { ++ y: string; ++ }; ++- var m: (n: number) => number; ++- } ++- declare namespace ExpandoArrow { ++- var prop: 2; ++ var m: (n: number) => 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 c6a71ddc88..05ea5715ce 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js @@ -30,13 +30,4 @@ map4.__underscores__(); //// [a.d.ts] declare function Multimap4(): void; -declare namespace Multimap4 { - var prototype: { - /** - * @param {string} key - * @returns {number} the value ok - */ - get(key: string): number; - }; -} declare const map4: any; diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff index 1e1f280301..d5ffe64194 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPrototypeAssignment4.js.diff @@ -14,14 +14,6 @@ - "add-on"(): void; - addon(): void; - __underscores__(): void; -+declare namespace Multimap4 { -+ var prototype: { -+ /** -+ * @param {string} key -+ * @returns {number} the value ok -+ */ -+ get(key: string): number; -+ }; - } +-} -declare const map4: Multimap4; +declare const map4: any; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts index 78ab984b73..607d116295 100644 --- a/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts +++ b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts @@ -4,8 +4,15 @@ export function A() { return 'A'; } -export enum B { +export function B() { + return 'B'; +} + +export enum C { C } -A.B = B; +A.a = C; +A.b = C; + +B.c = C; From d1c76ced4865cf731d5009ef3674e88063df3c25 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Sun, 27 Jul 2025 15:50:32 +0300 Subject: [PATCH 9/9] fix typeof enclosing declaration --- .../transformers/declarations/transform.go | 66 ++--- .../declarationEmitExpandoFunction.js | 6 +- ...onEmitDefaultExportWithStaticAssignment.js | 74 +----- ...tDefaultExportWithStaticAssignment.js.diff | 82 +----- ...clarationEmitExpandoPropertyPrivateName.js | 2 +- ...tionEmitExpandoPropertyPrivateName.js.diff | 2 +- ...arationEmitExpandoWithGenericConstraint.js | 4 +- ...onEmitExpandoWithGenericConstraint.js.diff | 4 +- ...clarationEmitFunctionDuplicateNamespace.js | 2 +- ...tionEmitFunctionDuplicateNamespace.js.diff | 2 +- .../declarationEmitFunctionKeywordProp.js | 22 +- ...declarationEmitFunctionKeywordProp.js.diff | 22 +- .../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 | 39 ++- ...dDeclarationErrorsExpandoFunctions.js.diff | 41 ++- .../jsDeclarationsGlobalFileConstFunction.js | 8 +- ...eclarationsGlobalFileConstFunction.js.diff | 8 +- ...eclarationsGlobalFileConstFunctionNamed.js | 30 +-- ...ationsGlobalFileConstFunctionNamed.js.diff | 44 ++-- ...xDeclarationsWithEsModuleInteropNoCrash.js | 8 +- ...arationsWithEsModuleInteropNoCrash.js.diff | 8 +- ...undFunctionMemberAssignmentDeclarations.js | 2 +- ...nctionMemberAssignmentDeclarations.js.diff | 2 +- .../conformance/assignmentToVoidZero2.js | 5 +- .../conformance/assignmentToVoidZero2.js.diff | 5 +- .../commonJSImportNestedClassTypeReference.js | 3 +- ...onJSImportNestedClassTypeReference.js.diff | 3 +- .../conformance/exportDefaultNamespace.js | 2 +- .../exportDefaultNamespace.js.diff | 2 +- .../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 | 40 ++- .../jsDeclarationsFunctionKeywordProp.js.diff | 41 ++- ...clarationsFunctionKeywordPropExhaustive.js | 156 ++++++------ ...tionsFunctionKeywordPropExhaustive.js.diff | 156 ++++++------ .../jsDeclarationsFunctionLikeClasses2.js | 4 +- ...jsDeclarationsFunctionLikeClasses2.js.diff | 4 +- .../jsDeclarationsFunctionPrototypeStatic.js | 4 +- ...eclarationsFunctionPrototypeStatic.js.diff | 4 +- ...ationsFunctionWithDefaultAssignedMember.js | 24 +- ...sFunctionWithDefaultAssignedMember.js.diff | 30 +-- .../conformance/jsDeclarationsFunctions.js | 30 ++- .../jsDeclarationsFunctions.js.diff | 32 ++- ...tionsParameterTagReusesInputNodeInEmit1.js | 4 +- ...ParameterTagReusesInputNodeInEmit1.js.diff | 4 +- ...tionsParameterTagReusesInputNodeInEmit2.js | 4 +- ...ParameterTagReusesInputNodeInEmit2.js.diff | 4 +- .../jsDeclarationsReactComponents.js | 28 +-- .../jsDeclarationsReactComponents.js.diff | 28 +-- .../conformance/jsdocImplements_class.js | 4 +- .../conformance/jsdocImplements_class.js.diff | 4 +- .../submodule/conformance/nullPropertyName.js | 156 ++++++------ .../conformance/nullPropertyName.js.diff | 156 ++++++------ .../typeFromPropertyAssignment29.js | 235 ++++++++++++------ .../typeFromPropertyAssignment29.js.diff | 233 +++++++++++------ 68 files changed, 1041 insertions(+), 898 deletions(-) diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index adfc5a2ad5..52156a3efd 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1812,12 +1812,39 @@ func (tx *DeclarationTransformer) collectExpandoAssignments(node *ast.BinaryExpr return } + namespaceName := ast.GetFirstIdentifier(left.AsPropertyAccessExpression().Expression).Text() + id := ast.GetSymbolId(host) + modifierFlags := ast.ModifierFlagsAmbient + if host.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsExport != 0 && host.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsDefault == 0 { + modifierFlags |= ast.ModifierFlagsExport + } + modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)) + + synthesizedModuleDeclaration := core.IfElse( + tx.pendingExpando[id] == nil, + tx.Factory().NewModuleDeclaration( + modifiers, + ast.KindNamespaceKeyword, + tx.Factory().NewIdentifier(namespaceName), + tx.Factory().NewModuleBlock(tx.Factory().NewNodeList([]*ast.Node{})), + ), + tx.pendingExpando[id], + ).AsModuleDeclaration() + + synthesizedModuleDeclaration.Parent = tx.enclosingDeclaration + + declarationData := synthesizedModuleDeclaration.DeclarationData() + declarationData.Symbol = host + + containerData := synthesizedModuleDeclaration.LocalsContainerData() + containerData.Locals = make(ast.SymbolTable, 0) + saveDiag := tx.state.getSymbolAccessibilityDiagnostic tx.state.getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node.AsNode()) t := tx.resolver.CreateTypeOfExpression( tx.EmitContext(), right, - host.ValueDeclaration, + synthesizedModuleDeclaration.AsNode(), declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags|nodebuilder.InternalFlagsNoSyntacticPrinter, tx.tracker, @@ -1849,33 +1876,16 @@ func (tx *DeclarationTransformer) collectExpandoAssignments(node *ast.BinaryExpr ) } - id := ast.GetSymbolId(host) - if tx.pendingExpando[id] == nil { - modifierFlags := ast.ModifierFlagsAmbient - if host.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsExport != 0 && host.ValueDeclaration.ModifierFlags()&ast.ModifierFlagsDefault == 0 { - modifierFlags |= ast.ModifierFlagsExport - } - modifiers := tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)) - name := tx.Factory().NewIdentifier(ast.GetFirstIdentifier(left.AsPropertyAccessExpression().Expression).Text()) - tx.pendingExpando[id] = tx.Factory().NewModuleDeclaration( - modifiers, - ast.KindNamespaceKeyword, - name, - tx.Factory().NewModuleBlock(tx.Factory().NewNodeList(statements)), - ) - } else { - namespace := tx.pendingExpando[id].AsModuleDeclaration() - tx.pendingExpando[id] = tx.Factory().UpdateModuleDeclaration( - namespace, - namespace.Modifiers(), - namespace.Keyword, - namespace.Name(), - tx.Factory().UpdateModuleBlock( - namespace.Body.AsModuleBlock(), - tx.Factory().NewNodeList(append(namespace.Body.AsModuleBlock().Statements.Nodes, statements...)), - ), - ) - } + tx.pendingExpando[id] = tx.Factory().UpdateModuleDeclaration( + synthesizedModuleDeclaration, + synthesizedModuleDeclaration.Modifiers(), + synthesizedModuleDeclaration.Keyword, + synthesizedModuleDeclaration.Name(), + tx.Factory().UpdateModuleBlock( + synthesizedModuleDeclaration.Body.AsModuleBlock(), + tx.Factory().NewNodeList(append(synthesizedModuleDeclaration.Body.AsModuleBlock().Statements.Nodes, statements...)), + ), + ) } func (tx *DeclarationTransformer) transformPendingExpandoAssignments() []*ast.Node { diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js index da6059b5a3..4a8d505537 100644 --- a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js @@ -47,9 +47,9 @@ export declare enum C { C = 0 } export declare namespace A { - var a: typeof C; - var b: typeof C; + const a: typeof C; + const b: typeof C; } export declare namespace B { - var c: typeof C; + const c: typeof C; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js index 33111fbfc3..9d878a4d46 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -82,10 +82,9 @@ C.B = B; export declare class Foo { } //// [index1.d.ts] -import { Foo } from './foo'; declare function Example(): void; declare namespace Example { - var Foo: typeof Foo; + const Foo: typeof import("./foo").Foo; } export default Example; //// [index2.d.ts] @@ -93,7 +92,7 @@ import { Foo } from './foo'; export { Foo }; declare function Example(): void; declare namespace Example { - var Foo: typeof Foo; + const Foo: typeof import("./foo").Foo; } export default Example; //// [index3.d.ts] @@ -101,75 +100,12 @@ export declare class Bar { } declare function Example(): void; declare namespace Example { - var Bar: typeof Bar; + const Bar: typeof import("./index3").Bar; } export default Example; //// [index4.d.ts] -declare function A(): void; -declare function B(): void; export declare function C(): any; export declare namespace C { - var A: typeof A; - var B: typeof B; + const A: () => void; + const B: () => void; } - - -//// [DtsFileErrors] - - -index1.d.ts(4,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. -index2.d.ts(5,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. -index3.d.ts(5,9): error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. -index4.d.ts(5,9): error TS2502: 'A' is referenced directly or indirectly in its own type annotation. -index4.d.ts(6,9): error TS2502: 'B' is referenced directly or indirectly in its own type annotation. - - -==== foo.d.ts (0 errors) ==== - export declare class Foo { - } - -==== index1.d.ts (1 errors) ==== - import { Foo } from './foo'; - declare function Example(): void; - declare namespace Example { - var Foo: typeof Foo; - ~~~ -!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. - } - export default Example; - -==== index2.d.ts (1 errors) ==== - import { Foo } from './foo'; - export { Foo }; - declare function Example(): void; - declare namespace Example { - var Foo: typeof Foo; - ~~~ -!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. - } - export default Example; - -==== index3.d.ts (1 errors) ==== - export declare class Bar { - } - declare function Example(): void; - declare namespace Example { - var Bar: typeof Bar; - ~~~ -!!! error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. - } - export default Example; - -==== index4.d.ts (2 errors) ==== - declare function A(): void; - declare function B(): void; - export declare function C(): any; - export declare namespace C { - var A: typeof A; - ~ -!!! error TS2502: 'A' is referenced directly or indirectly in its own type annotation. - var B: typeof B; - ~ -!!! error TS2502: 'B' is referenced directly or indirectly in its own type annotation. - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index 427d749180..501be0bbe8 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -18,24 +18,21 @@ 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 -33, +33 lines =@@ //// [index1.d.ts] -+import { Foo } from './foo'; declare function Example(): void; declare namespace Example { - var Foo: typeof import("./foo").Foo; -+ var Foo: typeof Foo; ++ const Foo: typeof import("./foo").Foo; } export default Example; //// [index2.d.ts] -@@= skipped -10, +11 lines =@@ +@@= skipped -8, +8 lines =@@ export { Foo }; declare function Example(): void; declare namespace Example { - var Foo: typeof import("./foo").Foo; -+ var Foo: typeof Foo; ++ const Foo: typeof import("./foo").Foo; } export default Example; //// [index3.d.ts] @@ -44,77 +41,14 @@ declare function Example(): void; declare namespace Example { - var Bar: typeof import("./index3").Bar; -+ var Bar: typeof Bar; ++ const Bar: typeof import("./index3").Bar; } export default Example; //// [index4.d.ts] -+declare function A(): void; -+declare function B(): void; export declare function C(): any; export declare namespace C { - var A: () => void; - var B: () => void; -+ var A: typeof A; -+ var B: typeof B; - } -+ -+ -+//// [DtsFileErrors] -+ -+ -+index1.d.ts(4,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. -+index2.d.ts(5,9): error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. -+index3.d.ts(5,9): error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. -+index4.d.ts(5,9): error TS2502: 'A' is referenced directly or indirectly in its own type annotation. -+index4.d.ts(6,9): error TS2502: 'B' is referenced directly or indirectly in its own type annotation. -+ -+ -+==== foo.d.ts (0 errors) ==== -+ export declare class Foo { -+ } -+ -+==== index1.d.ts (1 errors) ==== -+ import { Foo } from './foo'; -+ declare function Example(): void; -+ declare namespace Example { -+ var Foo: typeof Foo; -+ ~~~ -+!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. -+ } -+ export default Example; -+ -+==== index2.d.ts (1 errors) ==== -+ import { Foo } from './foo'; -+ export { Foo }; -+ declare function Example(): void; -+ declare namespace Example { -+ var Foo: typeof Foo; -+ ~~~ -+!!! error TS2502: 'Foo' is referenced directly or indirectly in its own type annotation. -+ } -+ export default Example; -+ -+==== index3.d.ts (1 errors) ==== -+ export declare class Bar { -+ } -+ declare function Example(): void; -+ declare namespace Example { -+ var Bar: typeof Bar; -+ ~~~ -+!!! error TS2502: 'Bar' is referenced directly or indirectly in its own type annotation. -+ } -+ export default Example; -+ -+==== index4.d.ts (2 errors) ==== -+ declare function A(): void; -+ declare function B(): void; -+ export declare function C(): any; -+ export declare namespace C { -+ var A: typeof A; -+ ~ -+!!! error TS2502: 'A' is referenced directly or indirectly in its own type annotation. -+ var B: typeof B; -+ ~ -+!!! error TS2502: 'B' is referenced directly or indirectly in its own type annotation. -+ } -+ \ No newline at end of file ++ const A: () => void; ++ const 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 62611a4b50..e018db2557 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 { - var val: I; + const val: I; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff index 1a0346d4ab..0886b8a890 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 { -+ var val: I; ++ 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 9a8f66e31d..9db3bade4d 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js @@ -42,7 +42,7 @@ export declare const Point: { }; export declare const Rect:

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

; declare namespace Point { - var zero: () => Point; + const zero: () => Point; } @@ -81,6 +81,6 @@ declarationEmitExpandoWithGenericConstraint.d.ts(14,19): error TS2451: Cannot re !!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. ~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'Point'. - var zero: () => 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 bd9b32a806..79768d419a 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js.diff @@ -9,7 +9,7 @@ }; export declare const Rect:

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

; +declare namespace Point { -+ var zero: () => Point; ++ const zero: () => Point; +} + + @@ -48,6 +48,6 @@ +!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. -+ var zero: () => 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 67db7d7018..2b62861091 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 { - var x: 2; + const x: 2; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff index 429aa243ec..fb005c3031 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; -+ var x: 2; ++ 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 24bb7d39eb..fac9d341c9 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js @@ -28,16 +28,16 @@ declare function foo(): void; declare function bar(): void; declare function baz(): void; declare namespace bar { - var async: true; - var normal: false; + const async: true; + const normal: false; } declare namespace baz { - var class_1: true; + const class_1: true; export { class_1 as class }; - var normal: false; + const normal: false; } declare namespace foo { - var null_1: true; + const null_1: true; export { null_1 as null }; } @@ -51,18 +51,18 @@ declare namespace foo { declare function bar(): void; declare function baz(): void; +declare namespace foo { -+ var null_1: true; ++ const null_1: true; + export { null_1 as null }; +} declare namespace bar { - var async: true; - var normal: false; + const async: true; + const normal: false; @@ -9,8 +13,4 @@ - var class_1: true; + const class_1: true; export { class_1 as class }; - var normal: false; + const normal: false; -} -declare namespace foo { -- var null_1: true; +- const null_1: true; - export { null_1 as null }; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff index 183ada05ca..1c9cd1b2e0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -15,20 +15,20 @@ -} declare function baz(): void; +declare namespace bar { -+ var async: true; -+ var normal: false; ++ const async: true; ++ const normal: false; +} declare namespace baz { - var _a: boolean; - export var normal: boolean; - export { _a as class }; -} -+ var class_1: true; ++ const class_1: true; + export { class_1 as class }; -+ var normal: false; ++ const normal: false; +} +declare namespace foo { -+ var null_1: true; ++ const null_1: true; + export { null_1 as null }; +} + @@ -42,18 +42,18 @@ + declare function bar(): void; + declare function baz(): void; ++declare namespace foo { -++ var null_1: true; +++ const null_1: true; ++ export { null_1 as null }; ++} + declare namespace bar { -+ var async: true; -+ var normal: false; ++ const async: true; ++ const normal: false; +@@= skipped -8, +12 lines =@@ -+ var class_1: true; ++ const class_1: true; + export { class_1 as class }; -+ var normal: false; ++ const normal: false; +-} +-declare namespace foo { -+- var null_1: true; ++- const null_1: true; +- export { null_1 as null }; + } \ 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 9be4e8519f..2b39f515ae 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 { - var bar: 12; + const bar: 12; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 5f78187456..11efae8688 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; -+ var bar: 12; ++ 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 424969cc04..12b20f7940 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 { - var bar: 12; + const bar: 12; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 84fc68006e..2688f0ab8e 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 { -+ var bar: 12; ++ 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 7b9c5c1bcd..508af594d3 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js @@ -47,5 +47,5 @@ if (Math.random()) { export declare function X(): void; export declare function Y(): void; export declare namespace Y { - var test: "foo"; + const test: "foo"; } diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index 0a076d8989..7d08bce082 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff @@ -21,5 +21,5 @@ export declare function Y(): void; export declare namespace Y { - var test: string; -+ var test: "foo"; ++ 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 b21642c23b..0630b19269 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -31,13 +31,13 @@ declare const errorOnMissingReturn: { a: string; }; declare namespace errorOnAssignmentBelowDecl { - var a: ""; + const a: ""; } declare namespace errorOnAssignmentBelow { - var a: ""; + const a: ""; } declare namespace errorOnMissingReturn { - var a: ""; + const a: ""; } @@ -65,16 +65,16 @@ isolatedDeclarationErrors.d.ts(16,19): error TS2451: Cannot redeclare block-scop a: string; }; declare namespace errorOnAssignmentBelowDecl { - var a: ""; + const a: ""; } declare namespace errorOnAssignmentBelow { ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. - var a: ""; + const a: ""; } declare namespace errorOnMissingReturn { ~~~~~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. - var a: ""; + 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 eefa704de1..01e4113a8d 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -17,13 +17,13 @@ + a: string; +}; +declare namespace errorOnAssignmentBelowDecl { -+ var a: ""; ++ const a: ""; +} +declare namespace errorOnAssignmentBelow { -+ var a: ""; ++ const a: ""; +} +declare namespace errorOnMissingReturn { -+ var a: ""; ++ const a: ""; +} + + @@ -51,16 +51,16 @@ + a: string; + }; + declare namespace errorOnAssignmentBelowDecl { -+ var a: ""; ++ const a: ""; + } + declare namespace errorOnAssignmentBelow { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. -+ var a: ""; ++ const a: ""; + } + declare namespace errorOnMissingReturn { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. -+ var a: ""; ++ 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 2d31d9464f..e25c8aad5b 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -26,11 +26,36 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] export declare function foo(): void; export declare namespace foo { - var apply: () => void; - var call: () => void; - var bind: () => void; - var caller: () => void; - var toString: () => void; - var length: 10; - var length: 10; + const apply: () => void; + const call: () => void; + const bind: () => void; + const caller: () => void; + const toString: () => void; + const length: 10; + const length: 10; } + + +//// [DtsFileErrors] + + +isolatedDeclarationErrorsExpandoFunctions.d.ts(8,11): error TS2451: Cannot redeclare block-scoped variable 'length'. +isolatedDeclarationErrorsExpandoFunctions.d.ts(9,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; + const call: () => void; + const bind: () => void; + const caller: () => void; + const toString: () => void; + const length: 10; + ~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'length'. + 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 30e20882be..90bb410ff9 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -9,11 +9,36 @@ +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] +export declare function foo(): void; +export declare namespace foo { -+ var apply: () => void; -+ var call: () => void; -+ var bind: () => void; -+ var caller: () => void; -+ var toString: () => void; -+ var length: 10; -+ var length: 10; -+} \ No newline at end of file ++ const apply: () => void; ++ const call: () => void; ++ const bind: () => void; ++ const caller: () => void; ++ const toString: () => void; ++ const length: 10; ++ const length: 10; ++} ++ ++ ++//// [DtsFileErrors] ++ ++ ++isolatedDeclarationErrorsExpandoFunctions.d.ts(8,11): error TS2451: Cannot redeclare block-scoped variable 'length'. ++isolatedDeclarationErrorsExpandoFunctions.d.ts(9,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; ++ const call: () => void; ++ const bind: () => void; ++ const caller: () => void; ++ const toString: () => void; ++ const length: 10; ++ ~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'length'. ++ 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 e049bbe719..eeb4d0f422 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js @@ -28,10 +28,10 @@ declare const SomeConstructor3: { staticMember: string; }; declare namespace SomeConstructor2 { - var staticMember: "str"; + const staticMember: "str"; } declare namespace SomeConstructor3 { - var staticMember: "str"; + const staticMember: "str"; } @@ -61,11 +61,11 @@ file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeCons declare namespace SomeConstructor2 { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. - var staticMember: "str"; + const staticMember: "str"; } declare namespace SomeConstructor3 { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. - var staticMember: "str"; + 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 c6167c784a..2b2613da30 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -20,7 +20,7 @@ +}; declare namespace SomeConstructor2 { - let staticMember: string; -+ var staticMember: "str"; ++ const staticMember: "str"; } -declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { @@ -30,7 +30,7 @@ -declare class SomeConstructor3 { - x: number; -} -+ var staticMember: "str"; ++ const staticMember: "str"; +} + + @@ -60,11 +60,11 @@ + declare namespace SomeConstructor2 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. -+ var staticMember: "str"; ++ const staticMember: "str"; + } + declare namespace SomeConstructor3 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. -+ var staticMember: "str"; ++ 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 941473f0d1..465d02ba81 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -37,14 +37,14 @@ declare const SelfReference: { (): any; staticMember: string; }; -declare namespace SomeConstructor3 { - var staticMember: "str"; -} declare namespace SelfReference { - var staticMember: "str"; + const staticMember: "str"; } declare namespace SomeConstructor2 { - var staticMember: "str"; + const staticMember: "str"; +} +declare namespace SomeConstructor3 { + const staticMember: "str"; } @@ -56,15 +56,15 @@ declare namespace SomeConstructor2 { (): any; staticMember: string; }; -+declare namespace SomeConstructor2 { -+ var staticMember: "str"; -+} - declare namespace SomeConstructor3 { - var staticMember: "str"; - } - declare namespace SelfReference { -- var staticMember: "str"; +-declare namespace SelfReference { +- const staticMember: "str"; -} --declare namespace SomeConstructor2 { - var staticMember: "str"; + declare namespace SomeConstructor2 { + const staticMember: "str"; + } + declare namespace SomeConstructor3 { ++ const staticMember: "str"; ++} ++declare namespace SelfReference { + const staticMember: "str"; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index b95d65fb32..6fd0ce57d3 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -7,12 +7,6 @@ -declare function SomeConstructor(): void; -declare class SomeConstructor { - x: number; --} --declare function SomeConstructor2(): void; --declare namespace SomeConstructor2 { -- let staticMember: string; --} --declare function SomeConstructor3(): void; +declare const SomeConstructor: () => void; +declare const SomeConstructor2: { + (): void; @@ -26,6 +20,15 @@ + (): any; + staticMember: string; +}; ++declare namespace SelfReference { ++ const staticMember: "str"; + } +-declare function SomeConstructor2(): void; + declare namespace SomeConstructor2 { +- let staticMember: string; ++ const staticMember: "str"; + } +-declare function SomeConstructor3(): void; declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; @@ -34,19 +37,14 @@ - x: number; -} -declare function SelfReference(): SelfReference; -+ var staticMember: "str"; -+} - declare namespace SelfReference { +-declare namespace SelfReference { - let staticMember_2: string; - export { staticMember_2 as staticMember }; -} -declare class SelfReference { - x: number; -} -+ var staticMember: "str"; -+} -+declare namespace SomeConstructor2 { -+ var staticMember: "str"; ++ const staticMember: "str"; +} + + @@ -58,15 +56,15 @@ + (): any; + staticMember: string; + }; -++declare namespace SomeConstructor2 { -++ var staticMember: "str"; -++} -+ declare namespace SomeConstructor3 { -+ var staticMember: "str"; -+ } -+ declare namespace SelfReference { -+- var staticMember: "str"; ++-declare namespace SelfReference { ++- const staticMember: "str"; +-} -+-declare namespace SomeConstructor2 { -+ var staticMember: "str"; ++ declare namespace SomeConstructor2 { ++ const staticMember: "str"; ++ } ++ declare namespace SomeConstructor3 { +++ const staticMember: "str"; +++} +++declare namespace SelfReference { ++ 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 d9a58f4eee..d008f7c100 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js @@ -31,10 +31,10 @@ declare function Foo({ bar }: { }): JSX.Element; export default Foo; declare namespace Foo { - var propTypes: { + const propTypes: { bar: PropTypes.Requireable; }; - var defaultProps: { + const defaultProps: { bar: boolean; }; } @@ -58,10 +58,10 @@ jsxDeclarationsWithEsModuleInteropNoCrash.d.ts(4,5): error TS2503: Cannot find n !!! error TS2503: Cannot find namespace 'JSX'. export default Foo; declare namespace Foo { - var propTypes: { + const propTypes: { bar: PropTypes.Requireable; }; - var defaultProps: { + const defaultProps: { bar: boolean; }; } diff --git a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff index 38ef8cd9c6..310f8477b1 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff @@ -23,10 +23,10 @@ - export { bar_1 as bar }; -} -import PropTypes from 'prop-types'; -+ var propTypes: { ++ const propTypes: { + bar: PropTypes.Requireable; + }; -+ var defaultProps: { ++ const defaultProps: { + bar: boolean; + }; +} @@ -50,10 +50,10 @@ +!!! error TS2503: Cannot find namespace 'JSX'. + export default Foo; + declare namespace Foo { -+ var propTypes: { ++ const propTypes: { + bar: PropTypes.Requireable; + }; -+ var defaultProps: { ++ const defaultProps: { + bar: boolean; + }; + } diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js index d7b9198917..f383ecb4bb 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 { - var bar: 12; + const bar: 12; } diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff index 2a4309da8e..c6663744d9 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; -+ var bar: 12; ++ 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 1018e817c5..9353d9f8c8 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js @@ -48,9 +48,8 @@ assignmentToVoidZero2_1.j + assignmentToVoidZero2_1.k; export var j = 1; export var k = void 0; declare namespace o { - var x: 1; - var y: any; + const x: 1; + 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 b0d29fd3e4..ae48533989 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff @@ -26,9 +26,8 @@ +export var j = 1; +export var k = void 0; +declare namespace o { -+ var x: 1; -+ var y: any; ++ const x: 1; ++ 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 789e2612a2..1e67dc8704 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js @@ -40,12 +40,11 @@ function f(k) { //// [mod1.d.ts] export var K = NS.K; declare namespace NS { - var K: { + const K: { new (): { values(): any; }; }; } -export {}; //// [main.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff index e64d37fb8f..97ea702c7a 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff @@ -24,13 +24,12 @@ - values(): /*elided*/ any; +export var K = NS.K; +declare namespace NS { -+ var K: { ++ const K: { + new (): { + values(): any; + }; }; -}; +} -+export {}; //// [main.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js index 9cd435c121..4bd1b54d90 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -21,6 +21,6 @@ someFunc.someProp = 'yo'; //// [exportDefaultNamespace.d.ts] declare function someFunc(): string; declare namespace someFunc { - var someProp: "yo"; + const someProp: "yo"; } export default someFunc; diff --git a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff index e9c0d39175..1cb1c90940 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -5,6 +5,6 @@ declare function someFunc(): string; declare namespace someFunc { - var someProp: string; -+ var someProp: "yo"; ++ 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 2a3bc6ca85..3c8648b108 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js @@ -139,8 +139,8 @@ declare class C2 { method1(x: number, y: number): number; } declare namespace C1 { - var staticProp: (x: any, y: any) => any; + const staticProp: (x: any, y: any) => any; } declare namespace C2 { - var staticProp: (x: any, y: any) => any; + 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 ba6c417e66..545dc12b4e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff @@ -45,7 +45,7 @@ - method2(x: number, y: number): number; +} +declare namespace C1 { -+ var staticProp: (x: any, y: any) => any; ++ const staticProp: (x: any, y: any) => any; } declare namespace C2 { - /** @@ -55,5 +55,5 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; -+ var staticProp: (x: any, y: any) => any; ++ 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 bfd3f35958..7e2e5b94f3 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -53,5 +53,5 @@ export type HandlerOptions = { name: String; }; declare namespace Handler { - var statische: () => void; + const statische: () => void; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff index 1791878375..ea8460c43d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -48,5 +48,5 @@ - */ - name: string; -}; -+ var statische: () => void; ++ const statische: () => void; +} \ 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 72988c332d..a2597762c2 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 { - var foo: "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 4778933c30..dabf27e3a4 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 { -+ var foo: "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 8f21b7eef3..a144219415 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -160,7 +160,7 @@ export type State = { }; export = Context; declare namespace Context { - var prototype: { + const 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 2529803e97..d5af4314c6 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js.diff @@ -125,7 +125,7 @@ -} declare namespace Context { - export { Timer, Hook, HookHandler, Input, State }; -+ var prototype: { ++ const 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 2be77b97e2..ca2adc7231 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js @@ -27,16 +27,42 @@ baz.normal = false; declare function foo(): void; declare function bar(): void; declare function baz(): void; +declare namespace bar { + const async: true; + const normal: false; +} declare namespace baz { - var class_1: true; + const class_1: true; export { class_1 as class }; - var normal: false; + const normal: false; } declare namespace foo { - var null_1: true; + const null_1: true; export { null_1 as null }; } -declare namespace bar { - var async: true; - var normal: false; -} + + +!!!! File out/source.d.ts differs from original emit in noCheck emit +//// [source.d.ts] +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -1,10 +1,6 @@ + declare function foo(): void; + declare function bar(): void; + declare function baz(): void; +-declare namespace bar { +- const async: true; +- const normal: false; +-} + declare namespace baz { + const class_1: true; + export { class_1 as class }; +@@ -13,4 +9,8 @@ + declare namespace foo { + const null_1: true; + export { null_1 as null }; ++} ++declare namespace bar { ++ const async: true; ++ const normal: false; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff index 98f2c3cbd5..eb988eafef 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff @@ -14,20 +14,47 @@ - let normal: boolean; -} declare function baz(): void; ++declare namespace bar { ++ const async: true; ++ const normal: false; ++} declare namespace baz { - let _class: boolean; - export { _class as class }; - let normal_1: boolean; - export { normal_1 as normal }; -+ var class_1: true; +-} ++ const class_1: true; + export { class_1 as class }; -+ var normal: false; ++ const normal: false; +} +declare namespace foo { -+ var null_1: true; ++ const null_1: true; + export { null_1 as null }; +} -+declare namespace bar { -+ var async: true; -+ var normal: false; - } \ No newline at end of file ++ ++ ++!!!! File out/source.d.ts differs from original emit in noCheck emit ++//// [source.d.ts] ++--- Expected The full check baseline +++++ Actual with noCheck set ++@@= skipped --24, +-24 lines =@@ ++ declare function foo(): void; ++ declare function bar(): void; ++ declare function baz(): void; ++-declare namespace bar { ++- const async: true; ++- const normal: false; ++-} ++ declare namespace baz { ++ const class_1: true; ++ export { class_1 as class }; ++@@= skipped -12, +8 lines =@@ ++ declare namespace foo { ++ const null_1: true; ++ export { null_1 as null }; +++} +++declare namespace bar { +++ const async: true; +++ 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 9d207981a8..b3dd426b5e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -171,127 +171,127 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; declare namespace foo { - var x: 1; - var y: 1; - var break_1: 1; + const x: 1; + const y: 1; + const break_1: 1; export { break_1 as break }; - var case_1: 1; + const case_1: 1; export { case_1 as case }; - var catch_1: 1; + const catch_1: 1; export { catch_1 as catch }; - var class_1: 1; + const class_1: 1; export { class_1 as class }; - var const_1: 1; + const const_1: 1; export { const_1 as const }; - var continue_1: 1; + const continue_1: 1; export { continue_1 as continue }; - var debugger_1: 1; + const debugger_1: 1; export { debugger_1 as debugger }; - var default_1: 1; + const default_1: 1; export { default_1 as default }; - var delete_1: 1; + const delete_1: 1; export { delete_1 as delete }; - var do_1: 1; + const do_1: 1; export { do_1 as do }; - var else_1: 1; + const else_1: 1; export { else_1 as else }; - var enum_1: 1; + const enum_1: 1; export { enum_1 as enum }; - var export_1: 1; + const export_1: 1; export { export_1 as export }; - var extends_1: 1; + const extends_1: 1; export { extends_1 as extends }; - var false_1: 1; + const false_1: 1; export { false_1 as false }; - var finally_1: 1; + const finally_1: 1; export { finally_1 as finally }; - var for_1: 1; + const for_1: 1; export { for_1 as for }; - var function_1: 1; + const function_1: 1; export { function_1 as function }; - var if_1: 1; + const if_1: 1; export { if_1 as if }; - var import_1: 1; + const import_1: 1; export { import_1 as import }; - var in_1: 1; + const in_1: 1; export { in_1 as in }; - var instanceof_1: 1; + const instanceof_1: 1; export { instanceof_1 as instanceof }; - var new_1: 1; + const new_1: 1; export { new_1 as new }; - var null_1: 1; + const null_1: 1; export { null_1 as null }; - var return_1: 1; + const return_1: 1; export { return_1 as return }; - var super_1: 1; + const super_1: 1; export { super_1 as super }; - var switch_1: 1; + const switch_1: 1; export { switch_1 as switch }; - var this_1: 1; + const this_1: 1; export { this_1 as this }; - var throw_1: 1; + const throw_1: 1; export { throw_1 as throw }; - var true_1: 1; + const true_1: 1; export { true_1 as true }; - var try_1: 1; + const try_1: 1; export { try_1 as try }; - var typeof_1: 1; + const typeof_1: 1; export { typeof_1 as typeof }; - var var_1: 1; + const var_1: 1; export { var_1 as var }; - var void_1: 1; + const void_1: 1; export { void_1 as void }; - var while_1: 1; + const while_1: 1; export { while_1 as while }; - var with_1: 1; + const with_1: 1; export { with_1 as with }; - var implements_1: 1; + const implements_1: 1; export { implements_1 as implements }; - var interface_1: 1; + const interface_1: 1; export { interface_1 as interface }; - var let_1: 1; + const let_1: 1; export { let_1 as let }; - var package_1: 1; + const package_1: 1; export { package_1 as package }; - var private_1: 1; + const private_1: 1; export { private_1 as private }; - var protected_1: 1; + const protected_1: 1; export { protected_1 as protected }; - var public_1: 1; + const public_1: 1; export { public_1 as public }; - var static_1: 1; + const static_1: 1; export { static_1 as static }; - var yield_1: 1; + const yield_1: 1; export { yield_1 as yield }; - var abstract: 1; - var as: 1; - var asserts: 1; - var any: 1; - var async: 1; - var await: 1; - var boolean: 1; - var constructor: 1; - var declare: 1; - var get: 1; - var infer: 1; - var is: 1; - var keyof: 1; - var module: 1; - var namespace: 1; - var never: 1; - var readonly: 1; - var require: 1; - var number: 1; - var object: 1; - var set: 1; - var string: 1; - var symbol: 1; - var type: 1; - var undefined: 1; - var unique: 1; - var unknown: 1; - var from: 1; - var global: 1; - var bigint: 1; - var of: 1; + const abstract: 1; + const as: 1; + const asserts: 1; + const any: 1; + const async: 1; + const await: 1; + const boolean: 1; + const constructor: 1; + const declare: 1; + const get: 1; + const infer: 1; + const is: 1; + const keyof: 1; + const module: 1; + const namespace: 1; + const never: 1; + const readonly: 1; + const require: 1; + const number: 1; + const object: 1; + const set: 1; + const string: 1; + const symbol: 1; + const type: 1; + const undefined: 1; + const unique: 1; + const unknown: 1; + const from: 1; + const global: 1; + const bigint: 1; + const of: 1; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff index 8547e9ddba..221622df6b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js.diff @@ -127,127 +127,127 @@ - export let global: number; - export let bigint: number; - export let of: number; -+ var x: 1; -+ var y: 1; -+ var break_1: 1; ++ const x: 1; ++ const y: 1; ++ const break_1: 1; + export { break_1 as break }; -+ var case_1: 1; ++ const case_1: 1; + export { case_1 as case }; -+ var catch_1: 1; ++ const catch_1: 1; + export { catch_1 as catch }; -+ var class_1: 1; ++ const class_1: 1; + export { class_1 as class }; -+ var const_1: 1; ++ const const_1: 1; + export { const_1 as const }; -+ var continue_1: 1; ++ const continue_1: 1; + export { continue_1 as continue }; -+ var debugger_1: 1; ++ const debugger_1: 1; + export { debugger_1 as debugger }; -+ var default_1: 1; ++ const default_1: 1; + export { default_1 as default }; -+ var delete_1: 1; ++ const delete_1: 1; + export { delete_1 as delete }; -+ var do_1: 1; ++ const do_1: 1; + export { do_1 as do }; -+ var else_1: 1; ++ const else_1: 1; + export { else_1 as else }; -+ var enum_1: 1; ++ const enum_1: 1; + export { enum_1 as enum }; -+ var export_1: 1; ++ const export_1: 1; + export { export_1 as export }; -+ var extends_1: 1; ++ const extends_1: 1; + export { extends_1 as extends }; -+ var false_1: 1; ++ const false_1: 1; + export { false_1 as false }; -+ var finally_1: 1; ++ const finally_1: 1; + export { finally_1 as finally }; -+ var for_1: 1; ++ const for_1: 1; + export { for_1 as for }; -+ var function_1: 1; ++ const function_1: 1; + export { function_1 as function }; -+ var if_1: 1; ++ const if_1: 1; + export { if_1 as if }; -+ var import_1: 1; ++ const import_1: 1; + export { import_1 as import }; -+ var in_1: 1; ++ const in_1: 1; + export { in_1 as in }; -+ var instanceof_1: 1; ++ const instanceof_1: 1; + export { instanceof_1 as instanceof }; -+ var new_1: 1; ++ const new_1: 1; + export { new_1 as new }; -+ var null_1: 1; ++ const null_1: 1; + export { null_1 as null }; -+ var return_1: 1; ++ const return_1: 1; + export { return_1 as return }; -+ var super_1: 1; ++ const super_1: 1; + export { super_1 as super }; -+ var switch_1: 1; ++ const switch_1: 1; + export { switch_1 as switch }; -+ var this_1: 1; ++ const this_1: 1; + export { this_1 as this }; -+ var throw_1: 1; ++ const throw_1: 1; + export { throw_1 as throw }; -+ var true_1: 1; ++ const true_1: 1; + export { true_1 as true }; -+ var try_1: 1; ++ const try_1: 1; + export { try_1 as try }; -+ var typeof_1: 1; ++ const typeof_1: 1; + export { typeof_1 as typeof }; -+ var var_1: 1; ++ const var_1: 1; + export { var_1 as var }; -+ var void_1: 1; ++ const void_1: 1; + export { void_1 as void }; -+ var while_1: 1; ++ const while_1: 1; + export { while_1 as while }; -+ var with_1: 1; ++ const with_1: 1; + export { with_1 as with }; -+ var implements_1: 1; ++ const implements_1: 1; + export { implements_1 as implements }; -+ var interface_1: 1; ++ const interface_1: 1; + export { interface_1 as interface }; -+ var let_1: 1; ++ const let_1: 1; + export { let_1 as let }; -+ var package_1: 1; ++ const package_1: 1; + export { package_1 as package }; -+ var private_1: 1; ++ const private_1: 1; + export { private_1 as private }; -+ var protected_1: 1; ++ const protected_1: 1; + export { protected_1 as protected }; -+ var public_1: 1; ++ const public_1: 1; + export { public_1 as public }; -+ var static_1: 1; ++ const static_1: 1; + export { static_1 as static }; -+ var yield_1: 1; ++ const yield_1: 1; + export { yield_1 as yield }; -+ var abstract: 1; -+ var as: 1; -+ var asserts: 1; -+ var any: 1; -+ var async: 1; -+ var await: 1; -+ var boolean: 1; -+ var constructor: 1; -+ var declare: 1; -+ var get: 1; -+ var infer: 1; -+ var is: 1; -+ var keyof: 1; -+ var module: 1; -+ var namespace: 1; -+ var never: 1; -+ var readonly: 1; -+ var require: 1; -+ var number: 1; -+ var object: 1; -+ var set: 1; -+ var string: 1; -+ var symbol: 1; -+ var type: 1; -+ var undefined: 1; -+ var unique: 1; -+ var unknown: 1; -+ var from: 1; -+ var global: 1; -+ var bigint: 1; -+ var of: 1; ++ const abstract: 1; ++ const as: 1; ++ const asserts: 1; ++ const any: 1; ++ const async: 1; ++ const await: 1; ++ const boolean: 1; ++ const constructor: 1; ++ const declare: 1; ++ const get: 1; ++ const infer: 1; ++ const is: 1; ++ const keyof: 1; ++ const module: 1; ++ const namespace: 1; ++ const never: 1; ++ const readonly: 1; ++ const require: 1; ++ const number: 1; ++ const object: 1; ++ const set: 1; ++ const string: 1; ++ const symbol: 1; ++ const type: 1; ++ const undefined: 1; ++ const unique: 1; ++ const unknown: 1; ++ const from: 1; ++ const global: 1; ++ const bigint: 1; ++ 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 87d29f52ad..0d76ad3126 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js @@ -165,7 +165,7 @@ export declare function Vec(len: number): void; */ export declare function Point2D(x: number, y: number): any; export declare namespace Vec { - var prototype: { + const prototype: { /** * @param {Vec} other */ @@ -174,7 +174,7 @@ export declare namespace Vec { }; } export declare namespace Point2D { - var prototype: { + const 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 bffe17438c..71f473896f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff @@ -54,7 +54,7 @@ - __proto__: typeof Vec; +export declare function Point2D(x: number, y: number): any; +export declare namespace Vec { -+ var prototype: { ++ const prototype: { + /** + * @param {Vec} other + */ @@ -63,7 +63,7 @@ + }; +} +export declare namespace Point2D { -+ var prototype: { ++ const 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 f090e2e254..9d759a2109 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -30,6 +30,6 @@ MyClass.staticProperty = 123; export = MyClass; export type DoneCB = (failures: number) ; declare namespace MyClass { - var staticMethod: () => void; - var staticProperty: 123; + const staticMethod: () => void; + const staticProperty: 123; } diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 7346c94309..4c6f90f51d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -29,8 +29,8 @@ +export type DoneCB = (failures: number) ; declare namespace MyClass { - export { staticMethod, staticProperty, DoneCB }; -+ var staticMethod: () => void; -+ var staticProperty: 123; ++ const staticMethod: () => void; ++ const staticProperty: 123; } -declare function staticMethod(): void; -declare var staticProperty: number; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js index f939a3df17..69bcc79603 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -16,29 +16,9 @@ module.exports = foo; //// [index.d.ts] -declare function foo(): void; export = foo; declare namespace foo { - var foo: typeof foo; - var default_1: typeof foo; + const foo: typeof import("."); + const default_1: typeof import("."); export { default_1 as default }; } - - -//// [DtsFileErrors] - - -out/index.d.ts(4,9): error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. - - -==== out/index.d.ts (1 errors) ==== - declare function foo(): void; - export = foo; - declare namespace foo { - var foo: typeof foo; - ~~~ -!!! error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. - var default_1: typeof foo; - export { default_1 as default }; - } - \ 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 d5acb87385..5b3e44d392 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff @@ -9,32 +9,12 @@ //// [index.d.ts] --export = foo; - declare function foo(): void; -+export = foo; + export = foo; +-declare function foo(): void; declare namespace foo { - export { foo }; - export { foo as default }; -+ var foo: typeof foo; -+ var default_1: typeof foo; ++ const foo: typeof import("."); ++ const default_1: typeof import("."); + export { default_1 as default }; - } -+ -+ -+//// [DtsFileErrors] -+ -+ -+out/index.d.ts(4,9): error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. -+ -+ -+==== out/index.d.ts (1 errors) ==== -+ declare function foo(): void; -+ export = foo; -+ declare namespace foo { -+ var foo: typeof foo; -+ ~~~ -+!!! error TS2502: 'foo' is referenced directly or indirectly in its own type annotation. -+ var default_1: typeof foo; -+ export { default_1 as default }; -+ } -+ \ 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 f350282d4c..db2e518640 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -167,13 +167,37 @@ export { i as ii }; export { j as jj }; export declare function j(): void; export declare namespace b { - var cat: "cat"; + const cat: "cat"; } export declare namespace c { - var Cls: { + const Cls: { new (): {}; }; } export declare namespace f { - var self: typeof f; + const self: typeof f; } + + +!!!! File out/index.d.ts differs from original emit in noCheck emit +//// [index.d.ts] +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -43,9 +43,6 @@ + export { i as ii }; + export { j as jj }; + export declare function j(): void; +-export declare namespace b { +- const cat: "cat"; +-} + export declare namespace c { + const Cls: { + new (): {}; +@@ -53,4 +50,7 @@ + } + export declare namespace f { + const self: typeof f; ++} ++export declare namespace b { ++ const cat: "cat"; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 3ac3e833ca..0ad6fcdbce 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -92,13 +92,37 @@ +export { j as jj }; +export declare function j(): void; +export declare namespace b { -+ var cat: "cat"; ++ const cat: "cat"; +} +export declare namespace c { -+ var Cls: { ++ const Cls: { + new (): {}; + }; +} +export declare namespace f { -+ var self: typeof f; -+} \ No newline at end of file ++ const self: typeof f; ++} ++ ++ ++!!!! File out/index.d.ts differs from original emit in noCheck emit ++//// [index.d.ts] ++--- Expected The full check baseline +++++ Actual with noCheck set ++@@= skipped --128, +-116 lines =@@ ++ export { i as ii }; ++ export { j as jj }; ++ export declare function j(): void; ++-export declare namespace b { ++- const cat: "cat"; ++-} ++ export declare namespace c { ++ const Cls: { ++ new (): {}; ++@@= skipped -10, +7 lines =@@ ++ } ++ export declare namespace f { ++ const self: typeof f; +++} +++export declare namespace b { +++ const cat: "cat"; ++ } \ 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 f9954e57e9..79e6104010 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -67,7 +67,9 @@ declare class Base { } export = BaseFactory; declare namespace BaseFactory { - var Base: typeof Base; + const Base: { + new (): Base; + }; } //// [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 e66f3a065f..b579634e63 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -26,7 +26,9 @@ +} +export = BaseFactory; +declare namespace BaseFactory { -+ var Base: typeof Base; ++ const Base: { ++ new (): Base; ++ }; } //// [file.d.ts] -type couldntThinkOfAny = { diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js index 9db54f9a8b..74990c5337 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js @@ -55,7 +55,9 @@ declare class Base { } export = BaseFactory; declare namespace BaseFactory { - var Base: typeof Base; + const Base: { + new (): Base; + }; } //// [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 e08e04b69a..401c14b400 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff @@ -26,7 +26,9 @@ +} +export = BaseFactory; +declare namespace BaseFactory { -+ var Base: typeof Base; ++ const Base: { ++ new (): Base; ++ }; } //// [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 7c01defed7..c876d3c8e5 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -196,10 +196,10 @@ declare const TabbedShowLayout: { }; export default TabbedShowLayout; declare namespace TabbedShowLayout { - var propTypes: { + const propTypes: { version: PropTypes.Requireable; }; - var defaultProps: { + const defaultProps: { tabs: undefined; }; } @@ -211,7 +211,7 @@ import React from "react"; declare const TabbedShowLayout: React.SFC; export default TabbedShowLayout; declare namespace TabbedShowLayout { - var defaultProps: { + const defaultProps: { tabs: string; }; } @@ -228,7 +228,7 @@ declare const TabbedShowLayout: { }) => JSX.Element); export default TabbedShowLayout; declare namespace TabbedShowLayout { - var defaultProps: { + const defaultProps: { tabs: string; }; } @@ -243,7 +243,7 @@ declare const TabbedShowLayout: { }; export default TabbedShowLayout; declare namespace TabbedShowLayout { - var defaultProps: { + const defaultProps: { tabs: string; }; } @@ -254,10 +254,10 @@ declare function Tree({ allowDropOnRoot }: { }): JSX.Element; export default Tree; declare namespace Tree { - var propTypes: { + const propTypes: { classes: PropTypes.Requireable; }; - var defaultProps: { + const defaultProps: { classes: {}; parentSource: string; }; @@ -305,10 +305,10 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac declare namespace TabbedShowLayout { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - var propTypes: { + const propTypes: { version: PropTypes.Requireable; }; - var defaultProps: { + const defaultProps: { tabs: undefined; }; } @@ -327,7 +327,7 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac declare namespace TabbedShowLayout { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - var defaultProps: { + const defaultProps: { tabs: string; }; } @@ -351,7 +351,7 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac declare namespace TabbedShowLayout { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - var defaultProps: { + const defaultProps: { tabs: string; }; } @@ -373,7 +373,7 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac declare namespace TabbedShowLayout { ~~~~~~~~~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. - var defaultProps: { + const defaultProps: { tabs: string; }; } @@ -389,10 +389,10 @@ out/jsDeclarationsReactComponents5.d.ts(4,5): error TS2503: Cannot find namespac !!! error TS2503: Cannot find namespace 'JSX'. export default Tree; declare namespace Tree { - var propTypes: { + const propTypes: { classes: PropTypes.Requireable; }; - var defaultProps: { + const 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 6895527390..7e27589e18 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -91,10 +91,10 @@ +}; +export default TabbedShowLayout; +declare namespace TabbedShowLayout { -+ var propTypes: { ++ const propTypes: { + version: PropTypes.Requireable; + }; -+ var defaultProps: { ++ const defaultProps: { + tabs: undefined; + }; +} @@ -111,7 +111,7 @@ +declare const TabbedShowLayout: React.SFC; +export default TabbedShowLayout; +declare namespace TabbedShowLayout { -+ var defaultProps: { ++ const defaultProps: { + tabs: string; + }; +} @@ -126,7 +126,7 @@ }) => JSX.Element); +export default TabbedShowLayout; +declare namespace TabbedShowLayout { -+ var defaultProps: { ++ const defaultProps: { + tabs: string; + }; +} @@ -147,7 +147,7 @@ - namespace defaultProps { - let tabs: string; - } -+ var defaultProps: { ++ const defaultProps: { + tabs: string; + }; } @@ -167,10 +167,10 @@ - export { classes_1 as classes }; - export let parentSource: string; - } -+ var propTypes: { ++ const propTypes: { + classes: PropTypes.Requireable; + }; -+ var defaultProps: { ++ const defaultProps: { + classes: {}; + parentSource: string; + }; @@ -219,10 +219,10 @@ + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ var propTypes: { ++ const propTypes: { + version: PropTypes.Requireable; + }; -+ var defaultProps: { ++ const defaultProps: { + tabs: undefined; + }; + } @@ -241,7 +241,7 @@ + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ var defaultProps: { ++ const defaultProps: { + tabs: string; + }; + } @@ -265,7 +265,7 @@ + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ var defaultProps: { ++ const defaultProps: { + tabs: string; + }; + } @@ -287,7 +287,7 @@ + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. -+ var defaultProps: { ++ const defaultProps: { + tabs: string; + }; + } @@ -303,10 +303,10 @@ +!!! error TS2503: Cannot find namespace 'JSX'. + export default Tree; + declare namespace Tree { -+ var propTypes: { ++ const propTypes: { + classes: PropTypes.Requireable; + }; -+ var defaultProps: { ++ const 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 aa17d9d8f9..2298a7a45e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js @@ -107,10 +107,10 @@ declare class CC { } declare var C5: any; declare namespace Ns { - var C1: { + const C1: { new (): { method(): number; }; }; - var C5: any; + 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 846d4fc94d..a4d71d6171 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff @@ -48,10 +48,10 @@ -declare class C3 implements A { - method(): number; +declare namespace Ns { -+ var C1: { ++ const C1: { + new (): { + method(): number; + }; + }; -+ var C5: any; ++ 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 82a3d6981b..7addf6a767 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js @@ -172,127 +172,127 @@ foo.of = 1; //// [nullPropertyName.d.ts] declare function foo(): void; declare namespace foo { - var x: 1; - var y: 1; - var break_1: 1; + const x: 1; + const y: 1; + const break_1: 1; export { break_1 as break }; - var case_1: 1; + const case_1: 1; export { case_1 as case }; - var catch_1: 1; + const catch_1: 1; export { catch_1 as catch }; - var class_1: 1; + const class_1: 1; export { class_1 as class }; - var const_1: 1; + const const_1: 1; export { const_1 as const }; - var continue_1: 1; + const continue_1: 1; export { continue_1 as continue }; - var debugger_1: 1; + const debugger_1: 1; export { debugger_1 as debugger }; - var default_1: 1; + const default_1: 1; export { default_1 as default }; - var delete_1: 1; + const delete_1: 1; export { delete_1 as delete }; - var do_1: 1; + const do_1: 1; export { do_1 as do }; - var else_1: 1; + const else_1: 1; export { else_1 as else }; - var enum_1: 1; + const enum_1: 1; export { enum_1 as enum }; - var export_1: 1; + const export_1: 1; export { export_1 as export }; - var extends_1: 1; + const extends_1: 1; export { extends_1 as extends }; - var false_1: 1; + const false_1: 1; export { false_1 as false }; - var finally_1: 1; + const finally_1: 1; export { finally_1 as finally }; - var for_1: 1; + const for_1: 1; export { for_1 as for }; - var function_1: 1; + const function_1: 1; export { function_1 as function }; - var if_1: 1; + const if_1: 1; export { if_1 as if }; - var import_1: 1; + const import_1: 1; export { import_1 as import }; - var in_1: 1; + const in_1: 1; export { in_1 as in }; - var instanceof_1: 1; + const instanceof_1: 1; export { instanceof_1 as instanceof }; - var new_1: 1; + const new_1: 1; export { new_1 as new }; - var null_1: 1; + const null_1: 1; export { null_1 as null }; - var return_1: 1; + const return_1: 1; export { return_1 as return }; - var super_1: 1; + const super_1: 1; export { super_1 as super }; - var switch_1: 1; + const switch_1: 1; export { switch_1 as switch }; - var this_1: 1; + const this_1: 1; export { this_1 as this }; - var throw_1: 1; + const throw_1: 1; export { throw_1 as throw }; - var true_1: 1; + const true_1: 1; export { true_1 as true }; - var try_1: 1; + const try_1: 1; export { try_1 as try }; - var typeof_1: 1; + const typeof_1: 1; export { typeof_1 as typeof }; - var var_1: 1; + const var_1: 1; export { var_1 as var }; - var void_1: 1; + const void_1: 1; export { void_1 as void }; - var while_1: 1; + const while_1: 1; export { while_1 as while }; - var with_1: 1; + const with_1: 1; export { with_1 as with }; - var implements_1: 1; + const implements_1: 1; export { implements_1 as implements }; - var interface_1: 1; + const interface_1: 1; export { interface_1 as interface }; - var let_1: 1; + const let_1: 1; export { let_1 as let }; - var package_1: 1; + const package_1: 1; export { package_1 as package }; - var private_1: 1; + const private_1: 1; export { private_1 as private }; - var protected_1: 1; + const protected_1: 1; export { protected_1 as protected }; - var public_1: 1; + const public_1: 1; export { public_1 as public }; - var static_1: 1; + const static_1: 1; export { static_1 as static }; - var yield_1: 1; + const yield_1: 1; export { yield_1 as yield }; - var abstract: 1; - var as: 1; - var asserts: 1; - var any: 1; - var async: 1; - var await: 1; - var boolean: 1; - var constructor: 1; - var declare: 1; - var get: 1; - var infer: 1; - var is: 1; - var keyof: 1; - var module: 1; - var namespace: 1; - var never: 1; - var readonly: 1; - var require: 1; - var number: 1; - var object: 1; - var set: 1; - var string: 1; - var symbol: 1; - var type: 1; - var undefined: 1; - var unique: 1; - var unknown: 1; - var from: 1; - var global: 1; - var bigint: 1; - var of: 1; + const abstract: 1; + const as: 1; + const asserts: 1; + const any: 1; + const async: 1; + const await: 1; + const boolean: 1; + const constructor: 1; + const declare: 1; + const get: 1; + const infer: 1; + const is: 1; + const keyof: 1; + const module: 1; + const namespace: 1; + const never: 1; + const readonly: 1; + const require: 1; + const number: 1; + const object: 1; + const set: 1; + const string: 1; + const symbol: 1; + const type: 1; + const undefined: 1; + const unique: 1; + const unknown: 1; + const from: 1; + const global: 1; + const bigint: 1; + const of: 1; } diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff index e61f85a8f9..992ca661a1 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff @@ -83,127 +83,127 @@ - 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 }; -+ var x: 1; -+ var y: 1; -+ var break_1: 1; ++ const x: 1; ++ const y: 1; ++ const break_1: 1; + export { break_1 as break }; -+ var case_1: 1; ++ const case_1: 1; + export { case_1 as case }; -+ var catch_1: 1; ++ const catch_1: 1; + export { catch_1 as catch }; -+ var class_1: 1; ++ const class_1: 1; + export { class_1 as class }; -+ var const_1: 1; ++ const const_1: 1; + export { const_1 as const }; -+ var continue_1: 1; ++ const continue_1: 1; + export { continue_1 as continue }; -+ var debugger_1: 1; ++ const debugger_1: 1; + export { debugger_1 as debugger }; -+ var default_1: 1; ++ const default_1: 1; + export { default_1 as default }; -+ var delete_1: 1; ++ const delete_1: 1; + export { delete_1 as delete }; -+ var do_1: 1; ++ const do_1: 1; + export { do_1 as do }; -+ var else_1: 1; ++ const else_1: 1; + export { else_1 as else }; -+ var enum_1: 1; ++ const enum_1: 1; + export { enum_1 as enum }; -+ var export_1: 1; ++ const export_1: 1; + export { export_1 as export }; -+ var extends_1: 1; ++ const extends_1: 1; + export { extends_1 as extends }; -+ var false_1: 1; ++ const false_1: 1; + export { false_1 as false }; -+ var finally_1: 1; ++ const finally_1: 1; + export { finally_1 as finally }; -+ var for_1: 1; ++ const for_1: 1; + export { for_1 as for }; -+ var function_1: 1; ++ const function_1: 1; + export { function_1 as function }; -+ var if_1: 1; ++ const if_1: 1; + export { if_1 as if }; -+ var import_1: 1; ++ const import_1: 1; + export { import_1 as import }; -+ var in_1: 1; ++ const in_1: 1; + export { in_1 as in }; -+ var instanceof_1: 1; ++ const instanceof_1: 1; + export { instanceof_1 as instanceof }; -+ var new_1: 1; ++ const new_1: 1; + export { new_1 as new }; -+ var null_1: 1; ++ const null_1: 1; + export { null_1 as null }; -+ var return_1: 1; ++ const return_1: 1; + export { return_1 as return }; -+ var super_1: 1; ++ const super_1: 1; + export { super_1 as super }; -+ var switch_1: 1; ++ const switch_1: 1; + export { switch_1 as switch }; -+ var this_1: 1; ++ const this_1: 1; + export { this_1 as this }; -+ var throw_1: 1; ++ const throw_1: 1; + export { throw_1 as throw }; -+ var true_1: 1; ++ const true_1: 1; + export { true_1 as true }; -+ var try_1: 1; ++ const try_1: 1; + export { try_1 as try }; -+ var typeof_1: 1; ++ const typeof_1: 1; + export { typeof_1 as typeof }; -+ var var_1: 1; ++ const var_1: 1; + export { var_1 as var }; -+ var void_1: 1; ++ const void_1: 1; + export { void_1 as void }; -+ var while_1: 1; ++ const while_1: 1; + export { while_1 as while }; -+ var with_1: 1; ++ const with_1: 1; + export { with_1 as with }; -+ var implements_1: 1; ++ const implements_1: 1; + export { implements_1 as implements }; -+ var interface_1: 1; ++ const interface_1: 1; + export { interface_1 as interface }; -+ var let_1: 1; ++ const let_1: 1; + export { let_1 as let }; -+ var package_1: 1; ++ const package_1: 1; + export { package_1 as package }; -+ var private_1: 1; ++ const private_1: 1; + export { private_1 as private }; -+ var protected_1: 1; ++ const protected_1: 1; + export { protected_1 as protected }; -+ var public_1: 1; ++ const public_1: 1; + export { public_1 as public }; -+ var static_1: 1; ++ const static_1: 1; + export { static_1 as static }; -+ var yield_1: 1; ++ const yield_1: 1; + export { yield_1 as yield }; -+ var abstract: 1; -+ var as: 1; -+ var asserts: 1; -+ var any: 1; -+ var async: 1; -+ var await: 1; -+ var boolean: 1; -+ var constructor: 1; -+ var declare: 1; -+ var get: 1; -+ var infer: 1; -+ var is: 1; -+ var keyof: 1; -+ var module: 1; -+ var namespace: 1; -+ var never: 1; -+ var readonly: 1; -+ var require: 1; -+ var number: 1; -+ var object: 1; -+ var set: 1; -+ var string: 1; -+ var symbol: 1; -+ var type: 1; -+ var undefined: 1; -+ var unique: 1; -+ var unknown: 1; -+ var from: 1; -+ var global: 1; -+ var bigint: 1; -+ var of: 1; ++ const abstract: 1; ++ const as: 1; ++ const asserts: 1; ++ const any: 1; ++ const async: 1; ++ const await: 1; ++ const boolean: 1; ++ const constructor: 1; ++ const declare: 1; ++ const get: 1; ++ const infer: 1; ++ const is: 1; ++ const keyof: 1; ++ const module: 1; ++ const namespace: 1; ++ const never: 1; ++ const readonly: 1; ++ const require: 1; ++ const number: 1; ++ const object: 1; ++ const set: 1; ++ const string: 1; ++ const symbol: 1; ++ const type: 1; ++ const undefined: 1; ++ const unique: 1; ++ const unknown: 1; ++ const from: 1; ++ const global: 1; ++ const bigint: 1; ++ 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 a5574bc9fa..e1a88a8be5 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -195,85 +195,85 @@ declare function ExpandoNested(n: number): { declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { export var p2: number; + declare namespace ExpandoArrow { + const prop: 2; + const m: (n: number) => number; + } declare namespace ExpandoNested { - var also: -1; + const also: -1; } declare namespace ExpandoMerge { - var p1: 111; + const p1: 111; } declare namespace ExpandoDecl { - var prop: 2; - var m: (n: number) => number; + const prop: 2; + const m: (n: number) => number; } declare namespace ExpandoExpr { - var prop: { + const prop: { x: number; }; - var prop: { + const prop: { y: string; }; - var m: (n: number) => number; - } - declare namespace ExpandoArrow { - var prop: 2; - var m: (n: number) => number; + const m: (n: number) => number; } } declare namespace ExpandoMerge { export var p3: number; - declare namespace ExpandoNested { - var also: -1; - } - declare namespace ExpandoMerge { - var p1: 111; - } declare namespace ExpandoDecl { - var prop: 2; - var m: (n: number) => number; + const prop: 2; + const m: (n: number) => number; } declare namespace ExpandoExpr { - var prop: { + const prop: { x: number; }; - var prop: { + const prop: { y: string; }; - var m: (n: number) => number; + const m: (n: number) => number; } declare namespace ExpandoArrow { - var prop: 2; - var m: (n: number) => number; + const prop: 2; + const m: (n: number) => number; + } + declare namespace ExpandoNested { + const also: -1; + } + declare namespace ExpandoMerge { + const p1: 111; } } declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; export function foo(): typeof ExpandoNamespace; + declare namespace ExpandoMerge { + const p1: 111; + } + declare namespace ExpandoNamespace { + const p6: 42; + } declare namespace ExpandoDecl { - var prop: 2; - var m: (n: number) => number; + const prop: 2; + const m: (n: number) => number; } declare namespace ExpandoExpr { - var prop: { + const prop: { x: number; }; - var prop: { + const prop: { y: string; }; - var m: (n: number) => number; + const m: (n: number) => number; } declare namespace ExpandoArrow { - var prop: 2; - var m: (n: number) => number; + const prop: 2; + const m: (n: number) => number; } declare namespace ExpandoNested { - var also: -1; - } - declare namespace ExpandoMerge { - var p1: 111; - } - declare namespace ExpandoNamespace { - var p6: 42; + const also: -1; } } // Should not work in Typescript -- must be const @@ -291,31 +291,31 @@ declare var ExpandoExpr3: { }; }; declare var n: number; +declare namespace ExpandoMerge { + const p1: 111; +} +declare namespace ExpandoNamespace { + const p6: 42; +} declare namespace ExpandoDecl { - var prop: 2; - var m: (n: number) => number; + const prop: 2; + const m: (n: number) => number; } declare namespace ExpandoExpr { - var prop: { + const prop: { x: number; }; - var prop: { + const prop: { y: string; }; - var m: (n: number) => number; + const m: (n: number) => number; } declare namespace ExpandoArrow { - var prop: 2; - var m: (n: number) => number; + const prop: 2; + const m: (n: number) => number; } declare namespace ExpandoNested { - var also: -1; -} -declare namespace ExpandoMerge { - var p1: 111; -} -declare namespace ExpandoNamespace { - var p6: 42; + const also: -1; } @@ -323,48 +323,123 @@ declare namespace ExpandoNamespace { //// [typeFromPropertyAssignment29.d.ts] --- Expected The full check baseline +++ Actual with noCheck set -@@ -24,12 +24,6 @@ +@@ -24,13 +24,6 @@ declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { export var p2: number; -- declare namespace ExpandoNested { -- var also: -1; +- declare namespace ExpandoArrow { +- const prop: 2; +- const m: (n: number) => number; - } -- declare namespace ExpandoMerge { -- var p1: 111; +- declare namespace ExpandoNested { +- const also: -1; - } - declare namespace ExpandoDecl { - var prop: 2; - var m: (n: number) => number; -@@ -46,10 +40,20 @@ - declare namespace ExpandoArrow { - var prop: 2; - var m: (n: number) => number; + declare namespace ExpandoMerge { + const p1: 111; + } +@@ -46,10 +39,23 @@ + y: string; + }; + const m: (n: number) => number; + } -+ declare namespace ExpandoNested { -+ var also: -1; ++ declare namespace ExpandoArrow { ++ const prop: 2; ++ const m: (n: number) => number; + } -+ declare namespace ExpandoMerge { -+ var p1: 111; ++ declare namespace ExpandoNested { ++ const also: -1; } } declare namespace ExpandoMerge { export var p3: number; ++ declare namespace ExpandoNested { ++ const also: -1; ++ } ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } + declare namespace ExpandoDecl { + const prop: 2; + const m: (n: number) => number; +@@ -66,18 +72,28 @@ + declare namespace ExpandoArrow { + const prop: 2; + const m: (n: number) => number; +- } +- declare namespace ExpandoNested { +- const also: -1; +- } +- declare namespace ExpandoMerge { +- const p1: 111; + } + } + declare var n: number; + declare namespace Ns { + function ExpandoNamespace(): void; + export function foo(): typeof ExpandoNamespace; ++ declare namespace ExpandoExpr { ++ const prop: { ++ x: number; ++ }; ++ const prop: { ++ y: string; ++ }; ++ const m: (n: number) => number; ++ } + declare namespace ExpandoArrow { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ const also: -1; + } - declare namespace ExpandoNested { - var also: -1; + declare namespace ExpandoMerge { + const p1: 111; } -@@ -67,10 +71,6 @@ - var prop: { - y: string; - }; -- var m: (n: number) => number; +@@ -88,22 +104,6 @@ + const prop: 2; + const m: (n: number) => number; + } +- declare namespace ExpandoExpr { +- const prop: { +- x: number; +- }; +- const prop: { +- y: string; +- }; +- const m: (n: number) => number; - } - declare namespace ExpandoArrow { -- var prop: 2; - var m: (n: number) => number; - } +- const prop: 2; +- const m: (n: number) => number; +- } +- declare namespace ExpandoNested { +- const also: -1; +- } + } + // Should not work in Typescript -- must be const + declare var ExpandoExpr2: (n: number) => string; +@@ -120,12 +120,6 @@ + }; + }; + declare var n: number; +-declare namespace ExpandoMerge { +- const p1: 111; +-} +-declare namespace ExpandoNamespace { +- const p6: 42; +-} + declare namespace ExpandoDecl { + const prop: 2; + const m: (n: number) => number; +@@ -145,4 +139,10 @@ + } + declare namespace ExpandoNested { + const also: -1; ++} ++declare namespace ExpandoMerge { ++ const p1: 111; ++} ++declare namespace ExpandoNamespace { ++ const p6: 42; } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff index bd53afbe7e..fdcae0e78a 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -73,54 +73,54 @@ -declare namespace ExpandoMerge { - var p3: number; + export var p2: number; ++ declare namespace ExpandoArrow { ++ const prop: 2; ++ const m: (n: number) => number; ++ } + declare namespace ExpandoNested { -+ var also: -1; ++ const also: -1; + } + declare namespace ExpandoMerge { -+ var p1: 111; ++ const p1: 111; + } + declare namespace ExpandoDecl { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; + } + declare namespace ExpandoExpr { -+ var prop: { ++ const prop: { + x: number; + }; -+ var prop: { ++ const prop: { + y: string; + }; -+ var m: (n: number) => number; -+ } -+ declare namespace ExpandoArrow { -+ var prop: 2; -+ var m: (n: number) => number; ++ const m: (n: number) => number; + } +} +declare namespace ExpandoMerge { + export var p3: number; -+ declare namespace ExpandoNested { -+ var also: -1; -+ } -+ declare namespace ExpandoMerge { -+ var p1: 111; -+ } + declare namespace ExpandoDecl { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; + } + declare namespace ExpandoExpr { -+ var prop: { ++ const prop: { + x: number; + }; -+ var prop: { ++ const prop: { + y: string; + }; -+ var m: (n: number) => number; ++ const m: (n: number) => number; + } + declare namespace ExpandoArrow { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ const also: -1; ++ } ++ declare namespace ExpandoMerge { ++ const p1: 111; + } } declare var n: number; @@ -131,31 +131,31 @@ - } export function foo(): typeof ExpandoNamespace; - export {}; ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } ++ declare namespace ExpandoNamespace { ++ const p6: 42; ++ } + declare namespace ExpandoDecl { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; + } + declare namespace ExpandoExpr { -+ var prop: { ++ const prop: { + x: number; + }; -+ var prop: { ++ const prop: { + y: string; + }; -+ var m: (n: number) => number; ++ const m: (n: number) => number; + } + declare namespace ExpandoArrow { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; + } + declare namespace ExpandoNested { -+ var also: -1; -+ } -+ declare namespace ExpandoMerge { -+ var p1: 111; -+ } -+ declare namespace ExpandoNamespace { -+ var p6: 42; ++ const also: -1; + } } +// Should not work in Typescript -- must be const @@ -173,31 +173,31 @@ }; }; declare var n: number; ++declare namespace ExpandoMerge { ++ const p1: 111; ++} ++declare namespace ExpandoNamespace { ++ const p6: 42; ++} +declare namespace ExpandoDecl { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; +} +declare namespace ExpandoExpr { -+ var prop: { ++ const prop: { + x: number; + }; -+ var prop: { ++ const prop: { + y: string; + }; -+ var m: (n: number) => number; ++ const m: (n: number) => number; +} +declare namespace ExpandoArrow { -+ var prop: 2; -+ var m: (n: number) => number; ++ const prop: 2; ++ const m: (n: number) => number; +} +declare namespace ExpandoNested { -+ var also: -1; -+} -+declare namespace ExpandoMerge { -+ var p1: 111; -+} -+declare namespace ExpandoNamespace { -+ var p6: 42; ++ const also: -1; +} + + @@ -209,44 +209,119 @@ + declare function ExpandoMerge(n: number): number; + declare namespace ExpandoMerge { + export var p2: number; -+- declare namespace ExpandoNested { -+- var also: -1; ++- declare namespace ExpandoArrow { ++- const prop: 2; ++- const m: (n: number) => number; +- } -+- declare namespace ExpandoMerge { -+- var p1: 111; ++- declare namespace ExpandoNested { ++- const also: -1; +- } -+ declare namespace ExpandoDecl { -+ var prop: 2; -+ var m: (n: number) => number; -+@@= skipped -22, +16 lines =@@ -+ declare namespace ExpandoArrow { -+ var prop: 2; -+ var m: (n: number) => number; ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } ++@@= skipped -22, +15 lines =@@ ++ y: string; ++ }; ++ const m: (n: number) => number; ++ } -++ declare namespace ExpandoNested { -++ var also: -1; +++ declare namespace ExpandoArrow { +++ const prop: 2; +++ const m: (n: number) => number; ++ } -++ declare namespace ExpandoMerge { -++ var p1: 111; +++ declare namespace ExpandoNested { +++ const also: -1; + } + } + declare namespace ExpandoMerge { + export var p3: number; +++ declare namespace ExpandoNested { +++ const also: -1; +++ } +++ declare namespace ExpandoMerge { +++ const p1: 111; +++ } ++ declare namespace ExpandoDecl { ++ const prop: 2; ++ const m: (n: number) => number; ++@@= skipped -20, +33 lines =@@ ++ declare namespace ExpandoArrow { ++ const prop: 2; ++ const m: (n: number) => number; ++- } ++- declare namespace ExpandoNested { ++- const also: -1; ++- } ++- declare namespace ExpandoMerge { ++- const p1: 111; ++ } ++ } ++ declare var n: number; ++ declare namespace Ns { ++ function ExpandoNamespace(): void; ++ export function foo(): typeof ExpandoNamespace; +++ declare namespace ExpandoExpr { +++ const prop: { +++ x: number; +++ }; +++ const prop: { +++ y: string; +++ }; +++ const m: (n: number) => number; +++ } ++ declare namespace ExpandoArrow { -++ var prop: 2; -++ var m: (n: number) => number; +++ const prop: 2; +++ const m: (n: number) => number; +++ } +++ declare namespace ExpandoNested { +++ const also: -1; ++ } -+ declare namespace ExpandoNested { -+ var also: -1; ++ declare namespace ExpandoMerge { ++ const p1: 111; + } -+@@= skipped -21, +31 lines =@@ -+ var prop: { -+ y: string; -+ }; -+- var m: (n: number) => number; ++@@= skipped -22, +32 lines =@@ ++ const prop: 2; ++ const m: (n: number) => number; ++ } ++- declare namespace ExpandoExpr { ++- const prop: { ++- x: number; ++- }; ++- const prop: { ++- y: string; ++- }; ++- const m: (n: number) => number; +- } +- declare namespace ExpandoArrow { -+- var prop: 2; -+ var m: (n: number) => number; -+ } ++- const prop: 2; ++- const m: (n: number) => number; ++- } ++- declare namespace ExpandoNested { ++- const also: -1; ++- } ++ } ++ // Should not work in Typescript -- must be const ++ declare var ExpandoExpr2: (n: number) => string; ++@@= skipped -32, +16 lines =@@ ++ }; ++ }; ++ declare var n: number; ++-declare namespace ExpandoMerge { ++- const p1: 111; ++-} ++-declare namespace ExpandoNamespace { ++- const p6: 42; ++-} ++ declare namespace ExpandoDecl { ++ const prop: 2; ++ const m: (n: number) => number; ++@@= skipped -25, +19 lines =@@ ++ } ++ declare namespace ExpandoNested { ++ const also: -1; +++} +++declare namespace ExpandoMerge { +++ const p1: 111; +++} +++declare namespace ExpandoNamespace { +++ const p6: 42; + } \ No newline at end of file