diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index b34fa3d51f..7af246bbd5 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -1337,7 +1337,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 { @@ -2812,10 +2812,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 @@ -2919,6 +2915,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 @@ -3635,3 +3639,16 @@ func GetSemanticJsxChildren(children []*JsxChild) []*JsxChild { } }) } + +func IsExpandoInitializer(initializer *Node) bool { + if initializer == nil { + return false + } + if IsFunctionExpressionOrArrowFunction(initializer) { + return true + } + if IsInJSFile(initializer) { + return IsClassExpression(initializer) || (IsObjectLiteralExpression(initializer) && len(initializer.AsObjectLiteralExpression().Properties.Nodes) == 0) + } + return false +} diff --git a/internal/binder/binder.go b/internal/binder/binder.go index a8265be291..d88e8b7690 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/parser/parser.go b/internal/parser/parser.go index 2fbaa224e8..cd6ff3730c 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) } @@ -640,7 +640,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) @@ -658,7 +658,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) @@ -2375,7 +2375,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/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index ad80436fb1..6f7f592435 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,6 +60,8 @@ type DeclarationTransformer struct { rawReferencedFiles []ReferencedFilePair rawTypeReferenceDirectives []*ast.FileReference rawLibReferenceDirectives []*ast.FileReference + pendingExpando map[ast.SymbolId]*ast.Node + pendingDefaultExports []*ast.Node } func NewDeclarationTransformer(host DeclarationEmitHost, context *printer.EmitContext, compilerOptions *core.CompilerOptions, declarationFilePath string, declarationMapPath string) *DeclarationTransformer { @@ -123,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, @@ -140,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) @@ -157,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() @@ -168,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) @@ -265,7 +272,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 } } @@ -282,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) } @@ -1137,6 +1152,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,17 +1168,8 @@ func (tx *DeclarationTransformer) transformFunctionDeclaration(input *ast.Functi nil, /*fullSignature*/ nil, ) - if updated == nil || !tx.resolver.IsExpandoFunctionDeclaration(input.AsNode()) || !shouldEmitFunctionProperties(input) { - return updated - } - // Add expando function properties to result - - // !!! TODO: expando function support - // props := tx.resolver.GetPropertiesOfContainerFunction(input) - // if tx.state.isolatedDeclarations { - // tx.state.reportExpandoFunctionErrors(input.AsNode()) - // } - return updated // !!! + tx.needsDefaultExport = saveNeedsDefaultExport + return updated } func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDeclaration) *ast.Node { @@ -1499,6 +1510,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) } @@ -1799,3 +1814,142 @@ 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 + } + + 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, + synthesizedModuleDeclaration.AsNode(), + 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*/), + ) + } + + 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 { + 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 new file mode 100644 index 0000000000..4a8d505537 --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +//// [declarationEmitExpandoFunction.ts] +export function A() { + return 'A'; +} + +export function B() { + return 'B'; +} + +export enum C { + C +} + +A.a = C; +A.b = C; + +B.c = C; + + +//// [declarationEmitExpandoFunction.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.C = void 0; +exports.A = A; +exports.B = B; +function A() { + return 'A'; +} +function B() { + return 'B'; +} +var C; +(function (C) { + C[C["C"] = 0] = "C"; +})(C || (exports.C = C = {})); +A.a = C; +A.b = C; +B.c = C; + + +//// [declarationEmitExpandoFunction.d.ts] +export declare function A(): string; +export declare function B(): string; +export declare enum C { + C = 0 +} +export declare namespace A { + const a: typeof C; + const b: typeof C; +} +export declare namespace B { + const c: typeof C; +} diff --git a/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols new file mode 100644 index 0000000000..2ffe781977 --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.symbols @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +=== declarationEmitExpandoFunction.ts === +export function A() { +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) + + return 'A'; +} + +export function B() { +>B : Symbol(B, Decl(declarationEmitExpandoFunction.ts, 2, 1)) + + return 'B'; +} + +export enum C { +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 6, 1)) + + C +>C : Symbol(C, Decl(declarationEmitExpandoFunction.ts, 8, 15)) +} + +A.a = C; +>A.a : Symbol(a, Decl(declarationEmitExpandoFunction.ts, 10, 1)) +>A : Symbol(A, Decl(declarationEmitExpandoFunction.ts, 0, 0)) +>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 new file mode 100644 index 0000000000..0e7b87870c --- /dev/null +++ b/testdata/baselines/reference/compiler/declarationEmitExpandoFunction.types @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/declarationEmitExpandoFunction.ts] //// + +=== declarationEmitExpandoFunction.ts === +export function A() { +>A : { (): string; a: typeof C; b: typeof C; } + + return 'A'; +>'A' : "A" +} + +export function B() { +>B : { (): string; c: typeof C; } + + return 'B'; +>'B' : "B" +} + +export enum C { +>C : C + + C +>C : C.C +} + +A.a = C; +>A.a = C : typeof C +>A.a : typeof C +>A : { (): string; a: typeof C; b: typeof C; } +>a : typeof C +>C : typeof C + +A.b = C; +>A.b = C : typeof C +>A.b : typeof C +>A : { (): string; a: typeof C; b: typeof C; } +>b : typeof C +>C : typeof C + +B.c = C; +>B.c = C : typeof C +>B.c : typeof C +>B : { (): string; c: typeof C; } +>c : typeof C +>C : typeof C + diff --git a/testdata/baselines/reference/submodule/compiler/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 345ebd102f..9d878a4d46 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js @@ -82,14 +82,30 @@ C.B = B; export declare class Foo { } //// [index1.d.ts] -export default function Example(): void; +declare function Example(): void; +declare namespace Example { + const Foo: typeof import("./foo").Foo; +} +export default Example; //// [index2.d.ts] import { Foo } from './foo'; export { Foo }; -export default function Example(): void; +declare function Example(): void; +declare namespace Example { + const Foo: typeof import("./foo").Foo; +} +export default Example; //// [index3.d.ts] export declare class Bar { } -export default function Example(): void; +declare function Example(): void; +declare namespace Example { + const Bar: typeof import("./index3").Bar; +} +export default Example; //// [index4.d.ts] export declare function C(): any; +export declare namespace C { + const A: () => void; + const B: () => void; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff index ff4abd456f..501be0bbe8 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitDefaultExportWithStaticAssignment.js.diff @@ -18,37 +18,37 @@ 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] --declare function Example(): void; --declare namespace Example { + declare function Example(): void; + declare namespace Example { - var Foo: typeof import("./foo").Foo; --} --export default Example; -+export default function Example(): void; ++ const Foo: typeof import("./foo").Foo; + } + export default Example; //// [index2.d.ts] - import { Foo } from './foo'; +@@= skipped -8, +8 lines =@@ export { Foo }; --declare function Example(): void; --declare namespace Example { + declare function Example(): void; + declare namespace Example { - var Foo: typeof import("./foo").Foo; --} --export default Example; -+export default function Example(): void; ++ const Foo: typeof import("./foo").Foo; + } + export default Example; //// [index3.d.ts] - export declare class Bar { +@@= skipped -8, +8 lines =@@ } --declare function Example(): void; --declare namespace Example { + declare function Example(): void; + declare namespace Example { - var Bar: typeof import("./index3").Bar; --} --export default Example; -+export default function Example(): void; ++ const Bar: typeof import("./index3").Bar; + } + export default Example; //// [index4.d.ts] export declare function C(): any; --export declare namespace C { + export declare namespace C { - var A: () => void; - var B: () => void; --} \ No newline at end of file ++ const A: () => void; ++ const B: () => void; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt new file mode 100644 index 0000000000..1ed386c351 --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt @@ -0,0 +1,14 @@ +b.ts(4,1): error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. + + +==== a.ts (0 errors) ==== + interface I {} + export function f(): I { return null as I; } +==== b.ts (1 errors) ==== + import {f} from "./a"; + + export function q() {} + q.val = f(); + ~~~~~~~~~~~ +!!! error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff index fc2ba7171a..e5704b00b0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.errors.txt.diff @@ -1,18 +1,10 @@ --- old.declarationEmitExpandoPropertyPrivateName.errors.txt +++ new.declarationEmitExpandoPropertyPrivateName.errors.txt -@@= skipped -0, +0 lines =@@ --b.ts(4,1): error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. -- -- --==== a.ts (0 errors) ==== -- interface I {} -- export function f(): I { return null as I; } --==== b.ts (1 errors) ==== -- import {f} from "./a"; -- -- export function q() {} -- q.val = f(); +@@= skipped -8, +8 lines =@@ + + export function q() {} + q.val = f(); - ~~~~~ --!!! error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. -- -+ \ No newline at end of file ++ ~~~~~~~~~~~ + !!! error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"a"'. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js index 4b994cff3c..e018db2557 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js @@ -31,3 +31,6 @@ export declare function f(): I; export {}; //// [b.d.ts] export declare function q(): void; +export declare namespace q { + const val: I; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff index e97c240744..0886b8a890 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoPropertyPrivateName.js.diff @@ -14,4 +14,7 @@ export declare function f(): I; export {}; +//// [b.d.ts] -+export declare function q(): void; \ No newline at end of file ++export declare function q(): void; ++export declare namespace q { ++ const val: I; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js index 02c1beb29a..9db3bade4d 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitExpandoWithGenericConstraint.js @@ -41,3 +41,46 @@ export declare const Point: { zero: () => Point; }; export declare const Rect:

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

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

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

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

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

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

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

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

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

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

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

; ++ declare namespace Point { ++ ~~~~~ ++!!! error TS2395: Individual declarations in merged declaration 'Point' must be all exported or all local. ++ ~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'Point'. ++ const zero: () => Point; ++ } ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js index 0fd62effd0..2b62861091 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js @@ -20,3 +20,6 @@ f.x = 2; //// [declarationEmitFunctionDuplicateNamespace.d.ts] declare function f(a: 0): 0; declare function f(a: 1): 1; +declare namespace f { + const x: 2; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff index c75018a359..fb005c3031 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionDuplicateNamespace.js.diff @@ -1,9 +1,9 @@ --- old.declarationEmitFunctionDuplicateNamespace.js +++ new.declarationEmitFunctionDuplicateNamespace.js -@@= skipped -19, +19 lines =@@ - //// [declarationEmitFunctionDuplicateNamespace.d.ts] +@@= skipped -20, +20 lines =@@ declare function f(a: 0): 0; declare function f(a: 1): 1; --declare namespace f { + declare namespace f { - var x: number; --} \ No newline at end of file ++ const x: 2; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js index f5ce29f90a..fac9d341c9 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js @@ -27,3 +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 { + const class_1: true; + export { class_1 as class }; + const normal: false; +} +declare namespace foo { + const 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 { ++ const null_1: true; ++ export { null_1 as null }; ++} + declare namespace bar { + const async: true; + const normal: false; +@@ -9,8 +13,4 @@ + const class_1: true; + export { class_1 as class }; + const normal: false; +-} +-declare namespace foo { +- 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 5628351b23..1c9cd1b2e0 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitFunctionKeywordProp.js.diff @@ -14,8 +14,46 @@ - var normal: boolean; -} declare function baz(): void; --declare namespace baz { ++declare namespace bar { ++ const async: true; ++ const normal: false; ++} + declare namespace baz { - var _a: boolean; - export var normal: boolean; - export { _a as class }; --} \ No newline at end of file +-} ++ const class_1: true; ++ export { class_1 as class }; ++ const normal: false; ++} ++declare namespace foo { ++ const 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 { +++ const null_1: true; +++ export { null_1 as null }; +++} ++ declare namespace bar { ++ const async: true; ++ const normal: false; ++@@= skipped -8, +12 lines =@@ ++ const class_1: true; ++ export { class_1 as class }; ++ const normal: false; ++-} ++-declare namespace foo { ++- 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 fc844a9af6..2b39f515ae 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js @@ -36,3 +36,6 @@ const a = foo[dashStrMem]; //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; +export declare namespace foo { + const bar: 12; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff index 9b5edc4ae8..11efae8688 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundAssignments.js.diff @@ -1,10 +1,10 @@ --- old.declarationEmitLateBoundAssignments.js +++ new.declarationEmitLateBoundAssignments.js -@@= skipped -35, +35 lines =@@ - +@@= skipped -36, +36 lines =@@ //// [declarationEmitLateBoundAssignments.d.ts] export declare function foo(): void; --export declare namespace foo { + export declare namespace foo { - var bar: number; - var strMemName: string; --} \ No newline at end of file ++ const bar: 12; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js index b3e5b3073c..12b20f7940 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js @@ -26,3 +26,6 @@ const a = foo[dashStrMem]; //// [file.d.ts] export declare function foo(): void; +export declare namespace foo { + const bar: 12; +} diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff index 62c383b58d..2688f0ab8e 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitLateBoundJSAssignments.js.diff @@ -8,5 +8,7 @@ -export namespace foo { - let bar: number; - let strMemName: string; --} -+export declare function foo(): void; \ No newline at end of file ++export declare function foo(): void; ++export declare namespace foo { ++ const bar: 12; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/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 4f8252f128..508af594d3 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 { + const test: "foo"; +} diff --git a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff index e1e3783a15..7d08bce082 100644 --- a/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff +++ b/testdata/baselines/reference/submodule/compiler/expandoFunctionBlockShadowing.js.diff @@ -19,6 +19,7 @@ +// https://github.com/microsoft/TypeScript/issues/56538 export declare function X(): void; export declare function Y(): void; --export declare namespace Y { + export declare namespace Y { - var test: string; --} \ No newline at end of file ++ const test: "foo"; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js index 8f211bd237..fb272b224c 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js @@ -30,3 +30,72 @@ declare const errorOnMissingReturn: { (): void; a: string; }; +declare namespace errorOnAssignmentBelowDecl { + const a: ""; +} +declare namespace errorOnAssignmentBelow { + const a: ""; +} +declare namespace errorOnMissingReturn { + const 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 { + const a: ""; + } + declare namespace errorOnAssignmentBelow { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. + const a: ""; + } + declare namespace errorOnMissingReturn { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. + const a: ""; + } + + +!!!! File isolatedDeclarationErrors.d.ts differs from original emit in noCheck emit +//// [isolatedDeclarationErrors.d.ts] +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -7,12 +7,12 @@ + (): void; + a: string; + }; +-declare namespace errorOnAssignmentBelowDecl { +- const a: ""; +-} + declare namespace errorOnAssignmentBelow { + const a: ""; + } + declare namespace errorOnMissingReturn { ++ const a: ""; ++} ++declare namespace errorOnAssignmentBelowDecl { + const a: ""; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff index a2e2b81506..9ac1b2ee8c 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrors.js.diff @@ -15,4 +15,73 @@ +declare const errorOnMissingReturn: { + (): void; + a: string; -+}; \ No newline at end of file ++}; ++declare namespace errorOnAssignmentBelowDecl { ++ const a: ""; ++} ++declare namespace errorOnAssignmentBelow { ++ const a: ""; ++} ++declare namespace errorOnMissingReturn { ++ const 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 { ++ const a: ""; ++ } ++ declare namespace errorOnAssignmentBelow { ++ ~~~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnAssignmentBelow'. ++ const a: ""; ++ } ++ declare namespace errorOnMissingReturn { ++ ~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'errorOnMissingReturn'. ++ const a: ""; ++ } ++ ++ ++!!!! File isolatedDeclarationErrors.d.ts differs from original emit in noCheck emit ++//// [isolatedDeclarationErrors.d.ts] ++--- Expected The full check baseline +++++ Actual with noCheck set ++@@= skipped --11, +-11 lines =@@ ++ (): void; ++ a: string; ++ }; ++-declare namespace errorOnAssignmentBelowDecl { ++- const a: ""; ++-} ++ declare namespace errorOnAssignmentBelow { ++ const a: ""; ++ } ++ declare namespace errorOnMissingReturn { +++ const a: ""; +++} +++declare namespace errorOnAssignmentBelowDecl { ++ const a: ""; ++ } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js index 52f0d4f7c5..e25c8aad5b 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js @@ -25,3 +25,37 @@ foo.length = 10; //// [isolatedDeclarationErrorsExpandoFunctions.d.ts] 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; + 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 ea6e1338aa..90bb410ff9 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpandoFunctions.js.diff @@ -7,4 +7,38 @@ + + +//// [isolatedDeclarationErrorsExpandoFunctions.d.ts] -+export declare function foo(): void; \ No newline at end of file ++export declare function foo(): void; ++export declare namespace foo { ++ const apply: () => void; ++ 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 9d4cfaead5..6dced0cc96 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 SomeConstructor3 { + const staticMember: "str"; +} +declare namespace SomeConstructor2 { + const 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 'SomeConstructor3'. +file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. + + +==== 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 SomeConstructor3 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. + const staticMember: "str"; + } + declare namespace SomeConstructor2 { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. + const staticMember: "str"; + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff index 171c3332a5..909a31d2b5 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunction.js.diff @@ -13,13 +13,6 @@ - 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 +21,52 @@ +declare const SomeConstructor3: { + (): void; + staticMember: string; -+}; \ No newline at end of file ++}; + declare namespace SomeConstructor3 { +- let staticMember_1: string; +- export { staticMember_1 as staticMember }; +-} +-declare class SomeConstructor3 { +- x: number; +-} ++ const staticMember: "str"; ++} ++declare namespace SomeConstructor2 { ++ const 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 'SomeConstructor3'. ++file.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++ ++ ++==== 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 SomeConstructor3 { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor3'. ++ const staticMember: "str"; ++ } ++ declare namespace SomeConstructor2 { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'SomeConstructor2'. ++ const staticMember: "str"; ++ } ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js index b4b7986cec..c7b7dfd89c 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -37,3 +37,12 @@ declare const SelfReference: { (): any; staticMember: string; }; +declare namespace SomeConstructor2 { + const staticMember: "str"; +} +declare namespace SomeConstructor3 { + const staticMember: "str"; +} +declare namespace SelfReference { + const staticMember: "str"; +} diff --git a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff index 3b57bcf92d..cd338c5a40 100644 --- a/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsDeclarationsGlobalFileConstFunctionNamed.js.diff @@ -9,11 +9,25 @@ - x: number; -} -declare function SomeConstructor2(): void; --declare namespace SomeConstructor2 { ++declare const SomeConstructor: () => void; ++declare const SomeConstructor2: { ++ (): void; ++ staticMember: string; ++}; ++declare const SomeConstructor3: { ++ (): void; ++ staticMember: string; ++}; ++declare const SelfReference: { ++ (): any; ++ staticMember: string; ++}; + declare namespace SomeConstructor2 { - let staticMember: string; --} ++ const staticMember: "str"; + } -declare function SomeConstructor3(): void; --declare namespace SomeConstructor3 { + declare namespace SomeConstructor3 { - let staticMember_1: string; - export { staticMember_1 as staticMember }; -} @@ -21,23 +35,13 @@ - x: number; -} -declare function SelfReference(): SelfReference; --declare namespace SelfReference { ++ const 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 ++ const staticMember: "str"; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js index d3a96f6c16..8b43635df8 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js @@ -26,7 +26,16 @@ export default Foo; //// [jsxDeclarationsWithEsModuleInteropNoCrash.d.ts] /// +import PropTypes from 'prop-types'; declare function Foo({ bar }: { bar: any; }): JSX.Element; export default Foo; +declare namespace Foo { + const propTypes: { + bar: PropTypes.Requireable; + }; + 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 1b8d5ca439..5a678e3302 100644 --- a/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsxDeclarationsWithEsModuleInteropNoCrash.js.diff @@ -5,10 +5,12 @@ //// [jsxDeclarationsWithEsModuleInteropNoCrash.d.ts] /// -export default Foo; ++import PropTypes from 'prop-types'; declare function Foo({ bar }: { bar: any; }): JSX.Element; --declare namespace Foo { ++export default Foo; + declare namespace Foo { - export { propTypes }; - export { defaultProps }; -} @@ -20,4 +22,10 @@ - export { bar_1 as bar }; -} -import PropTypes from 'prop-types'; -+export default Foo; \ No newline at end of file ++ const propTypes: { ++ bar: PropTypes.Requireable; ++ }; ++ const defaultProps: { ++ bar: boolean; ++ }; ++} \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js index 328d1a72ea..f383ecb4bb 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js @@ -19,3 +19,6 @@ const x = foo[_private]; //// [index.d.ts] export declare function foo(): void; +export declare namespace foo { + const bar: 12; +} diff --git a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff index 9b1699fd25..c6663744d9 100644 --- a/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff +++ b/testdata/baselines/reference/submodule/compiler/lateBoundFunctionMemberAssignmentDeclarations.js.diff @@ -1,9 +1,9 @@ --- old.lateBoundFunctionMemberAssignmentDeclarations.js +++ new.lateBoundFunctionMemberAssignmentDeclarations.js -@@= skipped -18, +18 lines =@@ - +@@= skipped -19, +19 lines =@@ //// [index.d.ts] export declare function foo(): void; --export declare namespace foo { + export declare namespace foo { - var bar: number; --} \ No newline at end of file ++ const bar: 12; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/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..9353d9f8c8 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js @@ -47,6 +47,9 @@ assignmentToVoidZero2_1.j + assignmentToVoidZero2_1.k; //// [assignmentToVoidZero2.d.ts] export var j = 1; export var k = void 0; -export {}; +declare namespace o { + const x: 1; + const y: any; +} //// [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..ae48533989 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff @@ -25,6 +25,9 @@ -export const j: 1; +export var j = 1; +export var k = void 0; -+export {}; ++declare namespace o { ++ const x: 1; ++ const y: any; ++} //// [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..1e67dc8704 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js @@ -39,6 +39,12 @@ function f(k) { //// [mod1.d.ts] export var K = NS.K; -export {}; +declare namespace NS { + const K: { + new (): { + values(): any; + }; + }; +} //// [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..97ea702c7a 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff @@ -22,9 +22,14 @@ -export var K: { - new (): { - values(): /*elided*/ any; -- }; --}; +export var K = NS.K; -+export {}; ++declare namespace NS { ++ const K: { ++ new (): { ++ values(): any; ++ }; + }; +-}; ++} //// [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 c438749f3f..4bd1b54d90 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js @@ -19,4 +19,8 @@ someFunc.someProp = 'yo'; //// [exportDefaultNamespace.d.ts] -export default function someFunc(): string; +declare function someFunc(): string; +declare namespace someFunc { + 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 c5f3a3a126..1cb1c90940 100644 --- a/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff +++ b/testdata/baselines/reference/submodule/conformance/exportDefaultNamespace.js.diff @@ -1,12 +1,10 @@ --- old.exportDefaultNamespace.js +++ new.exportDefaultNamespace.js -@@= skipped -18, +18 lines =@@ - - +@@= skipped -20, +20 lines =@@ //// [exportDefaultNamespace.d.ts] --declare function someFunc(): string; --declare namespace someFunc { + declare function someFunc(): string; + declare namespace someFunc { - var someProp: string; --} --export default someFunc; -+export default function someFunc(): string; \ No newline at end of file ++ const someProp: "yo"; + } + export default someFunc; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js index 291c26285d..1398e1ba82 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js @@ -138,3 +138,27 @@ declare class C2 { */ method1(x: number, y: number): number; } +declare namespace C2 { + const staticProp: (x: any, y: any) => any; +} +declare namespace C1 { + const staticProp: (x: any, y: any) => any; +} + + +!!!! File out/jsDeclarationsClassMethod.d.ts differs from original emit in noCheck emit +//// [jsDeclarationsClassMethod.d.ts] +--- Expected The full check baseline ++++ Actual with noCheck set +@@ -8,9 +8,9 @@ + */ + method1(x: number, y: number): number; + } +-declare namespace C2 { ++declare namespace C1 { + const staticProp: (x: any, y: any) => any; + } +-declare namespace C1 { ++declare namespace C2 { + const staticProp: (x: any, y: any) => any; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff index 1520c1ddf2..2c6cc3bb41 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassMethod.js.diff @@ -43,8 +43,8 @@ - * @returns {number} - */ - method2(x: number, y: number): number; --} --declare namespace C2 { + } + declare namespace C2 { - /** - * A comment staticProp - * @param {number} x @@ -52,4 +52,27 @@ - * @returns {number} - */ - function staticProp(x: number, y: number): number; - } \ No newline at end of file +-} ++ const staticProp: (x: any, y: any) => any; ++} ++declare namespace C1 { ++ const staticProp: (x: any, y: any) => any; ++} ++ ++ ++!!!! File out/jsDeclarationsClassMethod.d.ts differs from original emit in noCheck emit ++//// [jsDeclarationsClassMethod.d.ts] ++--- Expected The full check baseline +++++ Actual with noCheck set ++@@= skipped --154, +-129 lines =@@ ++ */ ++ method1(x: number, y: number): number; ++ } ++-declare namespace C2 { +++declare namespace C1 { ++ const staticProp: (x: any, y: any) => any; ++ } ++-declare namespace C1 { +++declare namespace C2 { ++ const staticProp: (x: any, y: any) => any; ++ } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js index 7b130e681b..f566a0683c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -57,6 +57,9 @@ export var Strings = Strings; export type HandlerOptions = { name: String; }; +declare namespace Handler { + const statische: () => void; +} /** * @typedef {Object} HandlerOptions * @property {String} name diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff index 7b335ba61e..f3b2e16a85 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -27,7 +27,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; @@ -40,10 +44,9 @@ - * Should be able to export a type alias at the same time. - */ - name: string; -+export var Strings = Strings; -+export type HandlerOptions = { -+ name: String; - }; +-}; ++ const statische: () => void; ++} +/** + * @typedef {Object} HandlerOptions + * @property {String} name diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js index 96bb98ab89..a2597762c2 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js @@ -22,6 +22,8 @@ declare class Base { } export declare class Foo extends Base { } -export {}; +export declare namespace Foo { + const foo: "foo"; +} //// [Bar.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff index f0e6cd5301..dabf27e3a4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic2.js.diff @@ -11,8 +11,12 @@ -} declare class Base { static foo: string; -+} -+export declare class Foo extends Base { } - export {}; - //// [Bar.d.ts] \ No newline at end of file +-export {}; ++export declare class Foo extends Base { ++} ++export declare namespace Foo { ++ const foo: "foo"; ++} + //// [Bar.d.ts] + export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js index 7a64753968..6ec8ef117b 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js @@ -96,9 +96,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; @@ -120,8 +121,9 @@ 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; /** * @typedef {string | number} default */ @@ -149,9 +151,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 { @@ -189,7 +192,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. @@ -203,6 +206,7 @@ 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; /** * @typedef {string | number} default */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff index 755a69eb8a..33f1081cd8 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff @@ -34,10 +34,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; @@ -63,12 +65,11 @@ + * @typedef {string | number} default + */ //// [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; +/** + * @typedef {string | number} default + */ @@ -96,9 +97,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 { @@ -136,7 +138,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. @@ -150,6 +152,7 @@ +!!! 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; + /** + * @typedef {string | number} default + */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment.js index 8038dc5993..a144219415 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 { + const 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..d5af4314c6 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 }; --} ++ const 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 4b6e7dcc70..4b1f124f15 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js @@ -27,3 +27,44 @@ baz.normal = false; declare function foo(): void; declare function bar(): void; declare function baz(): void; +declare namespace foo { + const null_1: true; + export { null_1 as null }; +} +declare namespace bar { + const async: true; + const normal: false; +} +declare namespace baz { + const class_1: true; + export { class_1 as class }; + const 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,16 +1,16 @@ + declare function foo(): void; + declare function bar(): void; + declare function baz(): void; ++declare namespace baz { ++ const class_1: true; ++ export { class_1 as class }; ++ const normal: false; ++} + declare namespace foo { + const null_1: true; + export { null_1 as null }; + } + declare namespace bar { + const async: true; +- const normal: false; +-} +-declare namespace baz { +- const class_1: true; +- export { class_1 as class }; + 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 d529325b10..b6cd215b6c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordProp.js.diff @@ -14,9 +14,48 @@ - let normal: boolean; -} declare function baz(): void; --declare namespace baz { ++declare namespace foo { ++ const null_1: true; ++ export { null_1 as null }; ++} ++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 }; --} \ No newline at end of file ++ const class_1: true; ++ export { class_1 as class }; ++ const 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 ++@@= skipped --24, +-24 lines =@@ ++ declare function foo(): void; ++ declare function bar(): void; ++ declare function baz(): void; +++declare namespace baz { +++ const class_1: true; +++ export { class_1 as class }; +++ const normal: false; +++} ++ declare namespace foo { ++ const null_1: true; ++ export { null_1 as null }; ++ } ++ declare namespace bar { ++ const async: true; ++- const normal: false; ++-} ++-declare namespace baz { ++- const class_1: true; ++- export { class_1 as class }; ++ const normal: false; ++ } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js index b7bc4713a4..b3dd426b5e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -170,3 +170,128 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; +declare namespace foo { + const x: 1; + const y: 1; + const break_1: 1; + export { break_1 as break }; + const case_1: 1; + export { case_1 as case }; + const catch_1: 1; + export { catch_1 as catch }; + const class_1: 1; + export { class_1 as class }; + const const_1: 1; + export { const_1 as const }; + const continue_1: 1; + export { continue_1 as continue }; + const debugger_1: 1; + export { debugger_1 as debugger }; + const default_1: 1; + export { default_1 as default }; + const delete_1: 1; + export { delete_1 as delete }; + const do_1: 1; + export { do_1 as do }; + const else_1: 1; + export { else_1 as else }; + const enum_1: 1; + export { enum_1 as enum }; + const export_1: 1; + export { export_1 as export }; + const extends_1: 1; + export { extends_1 as extends }; + const false_1: 1; + export { false_1 as false }; + const finally_1: 1; + export { finally_1 as finally }; + const for_1: 1; + export { for_1 as for }; + const function_1: 1; + export { function_1 as function }; + const if_1: 1; + export { if_1 as if }; + const import_1: 1; + export { import_1 as import }; + const in_1: 1; + export { in_1 as in }; + const instanceof_1: 1; + export { instanceof_1 as instanceof }; + const new_1: 1; + export { new_1 as new }; + const null_1: 1; + export { null_1 as null }; + const return_1: 1; + export { return_1 as return }; + const super_1: 1; + export { super_1 as super }; + const switch_1: 1; + export { switch_1 as switch }; + const this_1: 1; + export { this_1 as this }; + const throw_1: 1; + export { throw_1 as throw }; + const true_1: 1; + export { true_1 as true }; + const try_1: 1; + export { try_1 as try }; + const typeof_1: 1; + export { typeof_1 as typeof }; + const var_1: 1; + export { var_1 as var }; + const void_1: 1; + export { void_1 as void }; + const while_1: 1; + export { while_1 as while }; + const with_1: 1; + export { with_1 as with }; + const implements_1: 1; + export { implements_1 as implements }; + const interface_1: 1; + export { interface_1 as interface }; + const let_1: 1; + export { let_1 as let }; + const package_1: 1; + export { package_1 as package }; + const private_1: 1; + export { private_1 as private }; + const protected_1: 1; + export { protected_1 as protected }; + const public_1: 1; + export { public_1 as public }; + const static_1: 1; + export { static_1 as static }; + const yield_1: 1; + export { yield_1 as yield }; + 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 fa3f869313..221622df6b 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,127 @@ - export let global: number; - export let bigint: number; - export let of: number; --} \ No newline at end of file ++ const x: 1; ++ const y: 1; ++ const break_1: 1; ++ export { break_1 as break }; ++ const case_1: 1; ++ export { case_1 as case }; ++ const catch_1: 1; ++ export { catch_1 as catch }; ++ const class_1: 1; ++ export { class_1 as class }; ++ const const_1: 1; ++ export { const_1 as const }; ++ const continue_1: 1; ++ export { continue_1 as continue }; ++ const debugger_1: 1; ++ export { debugger_1 as debugger }; ++ const default_1: 1; ++ export { default_1 as default }; ++ const delete_1: 1; ++ export { delete_1 as delete }; ++ const do_1: 1; ++ export { do_1 as do }; ++ const else_1: 1; ++ export { else_1 as else }; ++ const enum_1: 1; ++ export { enum_1 as enum }; ++ const export_1: 1; ++ export { export_1 as export }; ++ const extends_1: 1; ++ export { extends_1 as extends }; ++ const false_1: 1; ++ export { false_1 as false }; ++ const finally_1: 1; ++ export { finally_1 as finally }; ++ const for_1: 1; ++ export { for_1 as for }; ++ const function_1: 1; ++ export { function_1 as function }; ++ const if_1: 1; ++ export { if_1 as if }; ++ const import_1: 1; ++ export { import_1 as import }; ++ const in_1: 1; ++ export { in_1 as in }; ++ const instanceof_1: 1; ++ export { instanceof_1 as instanceof }; ++ const new_1: 1; ++ export { new_1 as new }; ++ const null_1: 1; ++ export { null_1 as null }; ++ const return_1: 1; ++ export { return_1 as return }; ++ const super_1: 1; ++ export { super_1 as super }; ++ const switch_1: 1; ++ export { switch_1 as switch }; ++ const this_1: 1; ++ export { this_1 as this }; ++ const throw_1: 1; ++ export { throw_1 as throw }; ++ const true_1: 1; ++ export { true_1 as true }; ++ const try_1: 1; ++ export { try_1 as try }; ++ const typeof_1: 1; ++ export { typeof_1 as typeof }; ++ const var_1: 1; ++ export { var_1 as var }; ++ const void_1: 1; ++ export { void_1 as void }; ++ const while_1: 1; ++ export { while_1 as while }; ++ const with_1: 1; ++ export { with_1 as with }; ++ const implements_1: 1; ++ export { implements_1 as implements }; ++ const interface_1: 1; ++ export { interface_1 as interface }; ++ const let_1: 1; ++ export { let_1 as let }; ++ const package_1: 1; ++ export { package_1 as package }; ++ const private_1: 1; ++ export { private_1 as private }; ++ const protected_1: 1; ++ export { protected_1 as protected }; ++ const public_1: 1; ++ export { public_1 as public }; ++ const static_1: 1; ++ export { static_1 as static }; ++ const yield_1: 1; ++ export { yield_1 as yield }; ++ 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 4a762961ba..0d76ad3126 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js @@ -164,6 +164,22 @@ export declare function Vec(len: number): void; * @param {number} y */ export declare function Point2D(x: number, y: number): any; +export declare namespace Vec { + const prototype: { + /** + * @param {Vec} other + */ + dot(other: Vec): number; + magnitude(): number; + }; +} +export declare namespace Point2D { + const prototype: { + __proto__: typeof Vec; + x: number; + y: number; + }; +} //// [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..71f473896f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionLikeClasses2.js.diff @@ -52,8 +52,23 @@ - set y(y: number); - get y(): number; - __proto__: typeof Vec; --} +export declare function Point2D(x: number, y: number): any; ++export declare namespace Vec { ++ const prototype: { ++ /** ++ * @param {Vec} other ++ */ ++ dot(other: Vec): number; ++ magnitude(): number; ++ }; ++} ++export declare namespace Point2D { ++ const prototype: { ++ __proto__: typeof Vec; ++ x: number; ++ y: number; ++ }; + } //// [referencer.d.ts] -export const origin: Point2D; -import { Point2D } from "./source"; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index 25aba9ecba..89f6454af8 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -35,6 +35,10 @@ MyClass.staticProperty = 123; //// [source.d.ts] export = MyClass; export type DoneCB = (failures: number) ; +declare namespace MyClass { + const staticMethod: () => void; + const staticProperty: 123; +} /** * Callback to be invoked when test execution is complete. * diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index a39243d2a7..a104c2d06f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -18,12 +18,14 @@ -declare class MyClass { - method(): void; -} --declare namespace MyClass { ++export type DoneCB = (failures: number) ; + declare namespace MyClass { - export { staticMethod, staticProperty, DoneCB }; --} ++ const staticMethod: () => void; ++ const staticProperty: 123; + } -declare function staticMethod(): void; -declare var staticProperty: number; -+export type DoneCB = (failures: number) ; /** * Callback to be invoked when test execution is complete. - */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js index d76ffef284..69bcc79603 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js @@ -17,16 +17,8 @@ module.exports = foo; //// [index.d.ts] export = foo; - - -//// [DtsFileErrors] - - -out/index.d.ts(1,10): error TS2304: Cannot find name 'foo'. - - -==== out/index.d.ts (1 errors) ==== - export = foo; - ~~~ -!!! error TS2304: Cannot find name 'foo'. - \ No newline at end of file +declare namespace foo { + const foo: typeof import("."); + const default_1: typeof import("."); + export { default_1 as default }; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff index b57b340c63..5b3e44d392 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.js.diff @@ -11,20 +11,10 @@ //// [index.d.ts] export = foo; -declare function foo(): void; --declare namespace foo { + declare namespace foo { - export { foo }; - export { foo as default }; --} -+ -+ -+//// [DtsFileErrors] -+ -+ -+out/index.d.ts(1,10): error TS2304: Cannot find name 'foo'. -+ -+ -+==== out/index.d.ts (1 errors) ==== -+ export = foo; -+ ~~~ -+!!! error TS2304: Cannot find name 'foo'. -+ \ No newline at end of file ++ const foo: typeof import("."); ++ const default_1: typeof import("."); ++ 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 7a1612bab4..614ff447ff 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js @@ -166,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 { + const cat: "cat"; +} +export declare namespace c { + const Cls: { + new (): {}; + }; +} +export declare namespace f { + const self: typeof f; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff index 75088fe6e6..42eff85a3c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctions.js.diff @@ -90,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 { ++ const cat: "cat"; ++} ++export declare namespace c { ++ const Cls: { ++ new (): {}; ++ }; ++} ++export declare namespace f { ++ const 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..79e6104010 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -62,7 +62,15 @@ export {}; //// [base.d.ts] +declare class Base { + constructor(); +} export = BaseFactory; +declare namespace BaseFactory { + const Base: { + new (): 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..b579634e63 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -16,13 +16,20 @@ //// [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 { ++ 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 3c6498cabf..74990c5337 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js @@ -50,6 +50,14 @@ export {}; //// [base.d.ts] +declare class Base { + constructor(); +} export = BaseFactory; +declare namespace BaseFactory { + 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 4e00b4f79b..401c14b400 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff @@ -16,13 +16,20 @@ //// [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 { ++ 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 82575d2f0d..8278dadc8c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js @@ -196,6 +196,14 @@ declare const TabbedShowLayout: { }; }; export default TabbedShowLayout; +declare namespace TabbedShowLayout { + const propTypes: { + version: PropTypes.Requireable; + }; + const defaultProps: { + tabs: undefined; + }; +} //// [jsDeclarationsReactComponents2.d.ts] import React from "react"; /** @@ -203,6 +211,11 @@ import React from "react"; */ declare const TabbedShowLayout: React.SFC; export default TabbedShowLayout; +declare namespace TabbedShowLayout { + const defaultProps: { + tabs: string; + }; +} //// [jsDeclarationsReactComponents3.d.ts] /** * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} @@ -215,6 +228,11 @@ declare const TabbedShowLayout: { elem: string; }) => JSX.Element); export default TabbedShowLayout; +declare namespace TabbedShowLayout { + const defaultProps: { + tabs: string; + }; +} //// [jsDeclarationsReactComponents4.d.ts] declare const TabbedShowLayout: { (prop: { @@ -225,8 +243,139 @@ declare const TabbedShowLayout: { }; }; export default TabbedShowLayout; +declare namespace TabbedShowLayout { + const 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 { + const propTypes: { + classes: PropTypes.Requireable; + }; + const defaultProps: { + classes: {}; + parentSource: string; + }; +} + + +//// [DtsFileErrors] + + +out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents1.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. +out/jsDeclarationsReactComponents2.d.ts(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(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(10,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + + +==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== + /// + import PropTypes from "prop-types"; + declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + ({}: {}): JSX.Element; + propTypes: { + version: PropTypes.Requireable; + }; + defaultProps: { + tabs: undefined; + }; + }; + export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const propTypes: { + version: PropTypes.Requireable; + }; + const defaultProps: { + tabs: undefined; + }; + } + +==== out/jsDeclarationsReactComponents2.d.ts (2 errors) ==== + import React from "react"; + /** + * @type {React.SFC} + */ + declare const TabbedShowLayout: React.SFC; + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const defaultProps: { + tabs: string; + }; + } + +==== out/jsDeclarationsReactComponents3.d.ts (2 errors) ==== + /** + * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} + */ + declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + defaultProps: { + tabs: string; + }; + } & ((props?: { + elem: string; + }) => JSX.Element); + export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const defaultProps: { + tabs: string; + }; + } + +==== out/jsDeclarationsReactComponents4.d.ts (2 errors) ==== + declare const TabbedShowLayout: { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + (prop: { + className: string; + }): JSX.Element; + defaultProps: { + tabs: string; + }; + }; + export default TabbedShowLayout; + declare namespace TabbedShowLayout { + ~~~~~~~~~~~~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. + const defaultProps: { + tabs: string; + }; + } + +==== out/jsDeclarationsReactComponents5.d.ts (0 errors) ==== + import PropTypes from 'prop-types'; + declare function Tree({ allowDropOnRoot }: { + allowDropOnRoot: any; + }): JSX.Element; + export default Tree; + declare namespace Tree { + const propTypes: { + classes: PropTypes.Requireable; + }; + const defaultProps: { + classes: {}; + parentSource: string; + }; + } + \ 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 1cf9129430..79685b6fcd 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsReactComponents.js.diff @@ -89,6 +89,14 @@ + }; +}; +export default TabbedShowLayout; ++declare namespace TabbedShowLayout { ++ const propTypes: { ++ version: PropTypes.Requireable; ++ }; ++ const defaultProps: { ++ tabs: undefined; ++ }; ++} //// [jsDeclarationsReactComponents2.d.ts] -export default TabbedShowLayout; -/** @@ -101,16 +109,26 @@ + */ +declare const TabbedShowLayout: React.SFC; +export default TabbedShowLayout; ++declare namespace TabbedShowLayout { ++ const defaultProps: { ++ tabs: string; ++ }; ++} //// [jsDeclarationsReactComponents3.d.ts] -export default TabbedShowLayout; /** * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} */ -@@= skipped -30, +29 lines =@@ +@@= skipped -30, +42 lines =@@ } & ((props?: { elem: string; }) => JSX.Element); +export default TabbedShowLayout; ++declare namespace TabbedShowLayout { ++ const defaultProps: { ++ tabs: string; ++ }; ++} //// [jsDeclarationsReactComponents4.d.ts] +declare const TabbedShowLayout: { + (prop: { @@ -124,17 +142,22 @@ -declare function TabbedShowLayout(prop: { - className: string; -}): JSX.Element; --declare namespace TabbedShowLayout { + declare namespace TabbedShowLayout { - namespace defaultProps { - let tabs: string; - } --} ++ const defaultProps: { ++ tabs: string; ++ }; + } //// [jsDeclarationsReactComponents5.d.ts] -export default Tree; ++import PropTypes from 'prop-types'; declare function Tree({ allowDropOnRoot }: { allowDropOnRoot: any; }): JSX.Element; --declare namespace Tree { ++export default Tree; + declare namespace Tree { - namespace propTypes { - let classes: PropTypes.Requireable; - } @@ -143,6 +166,128 @@ - export { classes_1 as classes }; - export let parentSource: string; - } --} ++ const propTypes: { ++ classes: PropTypes.Requireable; ++ }; ++ const defaultProps: { ++ classes: {}; ++ parentSource: string; ++ }; + } -import PropTypes from 'prop-types'; -+export default Tree; \ No newline at end of file ++ ++ ++//// [DtsFileErrors] ++ ++ ++out/jsDeclarationsReactComponents1.d.ts(3,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents1.d.ts(13,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents2.d.ts(5,15): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++out/jsDeclarationsReactComponents2.d.ts(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(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(10,19): error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ ++ ++==== out/jsDeclarationsReactComponents1.d.ts (2 errors) ==== ++ /// ++ import PropTypes from "prop-types"; ++ declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ ({}: {}): JSX.Element; ++ propTypes: { ++ version: PropTypes.Requireable; ++ }; ++ defaultProps: { ++ tabs: undefined; ++ }; ++ }; ++ export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const propTypes: { ++ version: PropTypes.Requireable; ++ }; ++ const defaultProps: { ++ tabs: undefined; ++ }; ++ } ++ ++==== out/jsDeclarationsReactComponents2.d.ts (2 errors) ==== ++ import React from "react"; ++ /** ++ * @type {React.SFC} ++ */ ++ declare const TabbedShowLayout: React.SFC; ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const defaultProps: { ++ tabs: string; ++ }; ++ } ++ ++==== out/jsDeclarationsReactComponents3.d.ts (2 errors) ==== ++ /** ++ * @type {{defaultProps: {tabs: string}} & ((props?: {elem: string}) => JSX.Element)} ++ */ ++ declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ defaultProps: { ++ tabs: string; ++ }; ++ } & ((props?: { ++ elem: string; ++ }) => JSX.Element); ++ export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const defaultProps: { ++ tabs: string; ++ }; ++ } ++ ++==== out/jsDeclarationsReactComponents4.d.ts (2 errors) ==== ++ declare const TabbedShowLayout: { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ (prop: { ++ className: string; ++ }): JSX.Element; ++ defaultProps: { ++ tabs: string; ++ }; ++ }; ++ export default TabbedShowLayout; ++ declare namespace TabbedShowLayout { ++ ~~~~~~~~~~~~~~~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'TabbedShowLayout'. ++ const defaultProps: { ++ tabs: string; ++ }; ++ } ++ ++==== out/jsDeclarationsReactComponents5.d.ts (0 errors) ==== ++ import PropTypes from 'prop-types'; ++ declare function Tree({ allowDropOnRoot }: { ++ allowDropOnRoot: any; ++ }): JSX.Element; ++ export default Tree; ++ declare namespace Tree { ++ const propTypes: { ++ classes: PropTypes.Requireable; ++ }; ++ const defaultProps: { ++ classes: {}; ++ parentSource: string; ++ }; ++ } ++ \ 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..2298a7a45e 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 { + const C1: { + new (): { + method(): number; + }; + }; + const C5: any; +} diff --git a/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff b/testdata/baselines/reference/submodule/conformance/jsdocImplements_class.js.diff index 97a55138f3..a4d71d6171 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 { ++ const C1: { ++ new (): { ++ method(): number; ++ }; ++ }; ++ const C5: any; + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js index 687fcfe9e3..7addf6a767 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js @@ -171,3 +171,128 @@ foo.of = 1; //// [nullPropertyName.d.ts] declare function foo(): void; +declare namespace foo { + const x: 1; + const y: 1; + const break_1: 1; + export { break_1 as break }; + const case_1: 1; + export { case_1 as case }; + const catch_1: 1; + export { catch_1 as catch }; + const class_1: 1; + export { class_1 as class }; + const const_1: 1; + export { const_1 as const }; + const continue_1: 1; + export { continue_1 as continue }; + const debugger_1: 1; + export { debugger_1 as debugger }; + const default_1: 1; + export { default_1 as default }; + const delete_1: 1; + export { delete_1 as delete }; + const do_1: 1; + export { do_1 as do }; + const else_1: 1; + export { else_1 as else }; + const enum_1: 1; + export { enum_1 as enum }; + const export_1: 1; + export { export_1 as export }; + const extends_1: 1; + export { extends_1 as extends }; + const false_1: 1; + export { false_1 as false }; + const finally_1: 1; + export { finally_1 as finally }; + const for_1: 1; + export { for_1 as for }; + const function_1: 1; + export { function_1 as function }; + const if_1: 1; + export { if_1 as if }; + const import_1: 1; + export { import_1 as import }; + const in_1: 1; + export { in_1 as in }; + const instanceof_1: 1; + export { instanceof_1 as instanceof }; + const new_1: 1; + export { new_1 as new }; + const null_1: 1; + export { null_1 as null }; + const return_1: 1; + export { return_1 as return }; + const super_1: 1; + export { super_1 as super }; + const switch_1: 1; + export { switch_1 as switch }; + const this_1: 1; + export { this_1 as this }; + const throw_1: 1; + export { throw_1 as throw }; + const true_1: 1; + export { true_1 as true }; + const try_1: 1; + export { try_1 as try }; + const typeof_1: 1; + export { typeof_1 as typeof }; + const var_1: 1; + export { var_1 as var }; + const void_1: 1; + export { void_1 as void }; + const while_1: 1; + export { while_1 as while }; + const with_1: 1; + export { with_1 as with }; + const implements_1: 1; + export { implements_1 as implements }; + const interface_1: 1; + export { interface_1 as interface }; + const let_1: 1; + export { let_1 as let }; + const package_1: 1; + export { package_1 as package }; + const private_1: 1; + export { private_1 as private }; + const protected_1: 1; + export { protected_1 as protected }; + const public_1: 1; + export { public_1 as public }; + const static_1: 1; + export { static_1 as static }; + const yield_1: 1; + export { yield_1 as yield }; + 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 60cf26b0b5..992ca661a1 100644 --- a/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff +++ b/testdata/baselines/reference/submodule/conformance/nullPropertyName.js.diff @@ -1,10 +1,9 @@ --- old.nullPropertyName.js +++ new.nullPropertyName.js -@@= skipped -170, +170 lines =@@ - +@@= skipped -171, +171 lines =@@ //// [nullPropertyName.d.ts] declare function foo(): void; --declare namespace foo { + declare namespace foo { - export var x: number; - export var y: number; - var _a: number; @@ -84,4 +83,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 }; --} \ No newline at end of file ++ const x: 1; ++ const y: 1; ++ const break_1: 1; ++ export { break_1 as break }; ++ const case_1: 1; ++ export { case_1 as case }; ++ const catch_1: 1; ++ export { catch_1 as catch }; ++ const class_1: 1; ++ export { class_1 as class }; ++ const const_1: 1; ++ export { const_1 as const }; ++ const continue_1: 1; ++ export { continue_1 as continue }; ++ const debugger_1: 1; ++ export { debugger_1 as debugger }; ++ const default_1: 1; ++ export { default_1 as default }; ++ const delete_1: 1; ++ export { delete_1 as delete }; ++ const do_1: 1; ++ export { do_1 as do }; ++ const else_1: 1; ++ export { else_1 as else }; ++ const enum_1: 1; ++ export { enum_1 as enum }; ++ const export_1: 1; ++ export { export_1 as export }; ++ const extends_1: 1; ++ export { extends_1 as extends }; ++ const false_1: 1; ++ export { false_1 as false }; ++ const finally_1: 1; ++ export { finally_1 as finally }; ++ const for_1: 1; ++ export { for_1 as for }; ++ const function_1: 1; ++ export { function_1 as function }; ++ const if_1: 1; ++ export { if_1 as if }; ++ const import_1: 1; ++ export { import_1 as import }; ++ const in_1: 1; ++ export { in_1 as in }; ++ const instanceof_1: 1; ++ export { instanceof_1 as instanceof }; ++ const new_1: 1; ++ export { new_1 as new }; ++ const null_1: 1; ++ export { null_1 as null }; ++ const return_1: 1; ++ export { return_1 as return }; ++ const super_1: 1; ++ export { super_1 as super }; ++ const switch_1: 1; ++ export { switch_1 as switch }; ++ const this_1: 1; ++ export { this_1 as this }; ++ const throw_1: 1; ++ export { throw_1 as throw }; ++ const true_1: 1; ++ export { true_1 as true }; ++ const try_1: 1; ++ export { try_1 as try }; ++ const typeof_1: 1; ++ export { typeof_1 as typeof }; ++ const var_1: 1; ++ export { var_1 as var }; ++ const void_1: 1; ++ export { void_1 as void }; ++ const while_1: 1; ++ export { while_1 as while }; ++ const with_1: 1; ++ export { with_1 as with }; ++ const implements_1: 1; ++ export { implements_1 as implements }; ++ const interface_1: 1; ++ export { interface_1 as interface }; ++ const let_1: 1; ++ export { let_1 as let }; ++ const package_1: 1; ++ export { package_1 as package }; ++ const private_1: 1; ++ export { private_1 as private }; ++ const protected_1: 1; ++ export { protected_1 as protected }; ++ const public_1: 1; ++ export { public_1 as public }; ++ const static_1: 1; ++ export { static_1 as static }; ++ const yield_1: 1; ++ export { yield_1 as yield }; ++ 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 0939758bfb..08b717315a 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js @@ -194,16 +194,87 @@ declare function ExpandoNested(n: number): { }; declare function ExpandoMerge(n: number): number; declare namespace ExpandoMerge { - var p2: number; + export var p2: number; + declare namespace ExpandoNested { + const also: -1; + } + declare namespace ExpandoMerge { + const p1: 111; + } + declare namespace ExpandoDecl { + 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 { + const prop: 2; + const m: (n: number) => number; + } } declare namespace ExpandoMerge { - var p3: number; + export var p3: number; + declare namespace ExpandoMerge { + const p1: 111; + } + declare namespace ExpandoDecl { + 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 { + const prop: 2; + const m: (n: number) => number; + } + declare namespace ExpandoNested { + const also: -1; + } } declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; export function foo(): typeof ExpandoNamespace; - export {}; + declare namespace ExpandoExpr { + const prop: { + x: number; + }; + const prop: { + y: string; + }; + const m: (n: number) => number; + } + declare namespace ExpandoArrow { + const prop: 2; + const m: (n: number) => number; + } + declare namespace ExpandoNested { + const also: -1; + } + declare namespace ExpandoMerge { + const p1: 111; + } + declare namespace ExpandoNamespace { + const p6: 42; + } + declare namespace ExpandoDecl { + const prop: 2; + const m: (n: number) => number; + } } // Should not work in Typescript -- must be const declare var ExpandoExpr2: (n: number) => string; @@ -220,3 +291,117 @@ declare var ExpandoExpr3: { }; }; declare var n: number; +declare namespace ExpandoDecl { + 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 { + const prop: 2; + const m: (n: number) => number; +} +declare namespace ExpandoNested { + const also: -1; +} +declare namespace ExpandoMerge { + const p1: 111; +} +declare namespace ExpandoNamespace { + const 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,9 +24,6 @@ + declare function ExpandoMerge(n: number): number; + declare namespace ExpandoMerge { + export var p2: number; +- declare namespace ExpandoNested { +- const also: -1; +- } + declare namespace ExpandoMerge { + const p1: 111; + } +@@ -46,13 +43,13 @@ + declare namespace ExpandoArrow { + const prop: 2; + const m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ const also: -1; + } + } + declare namespace ExpandoMerge { + export var p3: number; +- declare namespace ExpandoMerge { +- const p1: 111; +- } + declare namespace ExpandoDecl { + const prop: 2; + const m: (n: number) => number; +@@ -72,28 +69,15 @@ + } + 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 { +- const prop: 2; +- const m: (n: number) => number; +- } +- declare namespace ExpandoNested { +- const also: -1; +- } + declare namespace ExpandoMerge { + const p1: 111; + } +@@ -103,6 +87,22 @@ + declare namespace ExpandoDecl { + 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 { ++ const prop: 2; ++ const m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ const also: -1; + } + } + // Should not work in Typescript -- must be const \ 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 4f9133b0df..62729ce0d7 100644 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff +++ b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment29.js.diff @@ -68,10 +68,61 @@ - var p1: number; -} -declare namespace ExpandoMerge { - var p2: number; +- var p2: number; +-} +-declare namespace ExpandoMerge { +- var p3: number; ++ export var p2: number; ++ declare namespace ExpandoNested { ++ const also: -1; ++ } ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } ++ declare namespace ExpandoDecl { ++ 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 { ++ const prop: 2; ++ const m: (n: number) => number; ++ } ++} ++declare namespace ExpandoMerge { ++ export var p3: number; ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } ++ declare namespace ExpandoDecl { ++ 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 { ++ const prop: 2; ++ const m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ const also: -1; ++ } } - declare namespace ExpandoMerge { -@@= skipped -28, +22 lines =@@ declare var n: number; declare namespace Ns { function ExpandoNamespace(): void; @@ -79,7 +130,33 @@ - var p6: number; - } export function foo(): typeof ExpandoNamespace; - export {}; +- export {}; ++ declare namespace ExpandoExpr { ++ const prop: { ++ x: number; ++ }; ++ const prop: { ++ y: string; ++ }; ++ const m: (n: number) => number; ++ } ++ declare namespace ExpandoArrow { ++ const prop: 2; ++ const m: (n: number) => number; ++ } ++ declare namespace ExpandoNested { ++ const also: -1; ++ } ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } ++ declare namespace ExpandoNamespace { ++ const p6: 42; ++ } ++ declare namespace ExpandoDecl { ++ const prop: 2; ++ const m: (n: number) => number; ++ } } +// Should not work in Typescript -- must be const declare var ExpandoExpr2: (n: number) => string; @@ -92,4 +169,121 @@ +// 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 { ++ 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 { ++ const prop: 2; ++ const m: (n: number) => number; ++} ++declare namespace ExpandoNested { ++ const also: -1; ++} ++declare namespace ExpandoMerge { ++ const p1: 111; ++} ++declare namespace ExpandoNamespace { ++ const 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 { ++- const also: -1; ++- } ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } ++@@= skipped -22, +19 lines =@@ ++ declare namespace ExpandoArrow { ++ const prop: 2; ++ const m: (n: number) => number; +++ } +++ declare namespace ExpandoNested { +++ const also: -1; ++ } ++ } ++ declare namespace ExpandoMerge { ++ export var p3: number; ++- declare namespace ExpandoMerge { ++- const p1: 111; ++- } ++ declare namespace ExpandoDecl { ++ const prop: 2; ++ const m: (n: number) => number; ++@@= skipped -26, +26 lines =@@ ++ } ++ 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 { ++- const prop: 2; ++- const m: (n: number) => number; ++- } ++- declare namespace ExpandoNested { ++- const also: -1; ++- } ++ declare namespace ExpandoMerge { ++ const p1: 111; ++ } ++@@= skipped -31, +18 lines =@@ ++ declare namespace ExpandoDecl { ++ 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 { +++ const prop: 2; +++ const m: (n: number) => number; +++ } +++ declare namespace ExpandoNested { +++ const also: -1; ++ } ++ } ++ // Should not work in Typescript -- must be const \ No newline at end of file diff --git a/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts new file mode 100644 index 0000000000..607d116295 --- /dev/null +++ b/testdata/tests/cases/compiler/declarationEmitExpandoFunction.ts @@ -0,0 +1,18 @@ +// @declaration: true + +export function A() { + return 'A'; +} + +export function B() { + return 'B'; +} + +export enum C { + C +} + +A.a = C; +A.b = C; + +B.c = C;