diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index e81bf4f602..5e7d92a011 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -120,7 +120,8 @@ func (tx *DeclarationTransformer) visit(node *ast.Node) *ast.Node { ast.KindJSImportDeclaration, ast.KindExportDeclaration, ast.KindJSExportAssignment, - ast.KindExportAssignment: + ast.KindExportAssignment, + ast.KindCommonJSExport: return tx.visitDeclarationStatements(node) // statements we elide case ast.KindBreakStatement, @@ -924,6 +925,80 @@ func (tx *DeclarationTransformer) visitDeclarationStatements(input *ast.Node) *a tx.rewriteModuleSpecifier(input, input.AsExportDeclaration().ModuleSpecifier), tx.tryGetResolutionModeOverride(input.AsExportDeclaration().Attributes), ) + case ast.KindCommonJSExport: + if ast.IsSourceFile(input.Parent) { + tx.resultHasExternalModuleIndicator = true + } + tx.resultHasScopeMarker = true + name := input.AsCommonJSExport().Name() + if ast.IsIdentifier(name) { + if name.AsIdentifier().Text == "default" { + // const _default: Type; export default _default; + newId := tx.Factory().NewUniqueNameEx("_default", printer.AutoGenerateOptions{Flags: printer.GeneratedIdentifierFlagsOptimistic}) + tx.state.getSymbolAccessibilityDiagnostic = func(_ printer.SymbolAccessibilityResult) *SymbolAccessibilityDiagnostic { + return &SymbolAccessibilityDiagnostic{ + diagnosticMessage: diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: input, + } + } + tx.tracker.PushErrorFallbackNode(input) + type_ := tx.ensureType(input, false) + varDecl := tx.Factory().NewVariableDeclaration(newId, nil, type_, nil) + tx.tracker.PopErrorFallbackNode() + var modList *ast.ModifierList + if tx.needsDeclare { + modList = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindDeclareKeyword)}) + } else { + modList = tx.Factory().NewModifierList([]*ast.Node{}) + } + statement := tx.Factory().NewVariableStatement(modList, tx.Factory().NewVariableDeclarationList(ast.NodeFlagsConst, tx.Factory().NewNodeList([]*ast.Node{varDecl}))) + + assignment := tx.Factory().NewExportAssignment(input.Modifiers(), false, nil, newId) + // Remove comments from the export declaration and copy them onto the synthetic _default declaration + tx.preserveJsDoc(statement, input) + tx.removeAllComments(assignment) + return tx.Factory().NewSyntaxList([]*ast.Node{statement, assignment}) + } else { + // export var name: Type + tx.tracker.PushErrorFallbackNode(input) + type_ := tx.ensureType(input, false) + varDecl := tx.Factory().NewVariableDeclaration(name, nil, type_, nil) + tx.tracker.PopErrorFallbackNode() + var modList *ast.ModifierList + if tx.needsDeclare { + modList = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindExportKeyword), tx.Factory().NewModifier(ast.KindDeclareKeyword)}) + } else { + modList = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindExportKeyword)}) + } + return tx.Factory().NewVariableStatement(modList, tx.Factory().NewVariableDeclarationList(ast.NodeFlagsNone, tx.Factory().NewNodeList([]*ast.Node{varDecl}))) + } + } else { + // const _exported: Type; export {_exported as "name"}; + newId := tx.Factory().NewUniqueNameEx("_exported", printer.AutoGenerateOptions{Flags: printer.GeneratedIdentifierFlagsOptimistic}) + tx.state.getSymbolAccessibilityDiagnostic = func(_ printer.SymbolAccessibilityResult) *SymbolAccessibilityDiagnostic { + return &SymbolAccessibilityDiagnostic{ + diagnosticMessage: diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: input, + } + } + tx.tracker.PushErrorFallbackNode(input) + type_ := tx.ensureType(input, false) + varDecl := tx.Factory().NewVariableDeclaration(newId, nil, type_, nil) + tx.tracker.PopErrorFallbackNode() + var modList *ast.ModifierList + if tx.needsDeclare { + modList = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindDeclareKeyword)}) + } else { + modList = tx.Factory().NewModifierList([]*ast.Node{}) + } + statement := tx.Factory().NewVariableStatement(modList, tx.Factory().NewVariableDeclarationList(ast.NodeFlagsConst, tx.Factory().NewNodeList([]*ast.Node{varDecl}))) + + assignment := tx.Factory().NewExportDeclaration(nil, false, tx.Factory().NewNamedExports(tx.Factory().NewNodeList([]*ast.Node{tx.Factory().NewExportSpecifier(false, newId, name)})), nil, nil) + // Remove comments from the export declaration and copy them onto the synthetic _default declaration + tx.preserveJsDoc(statement, input) + tx.removeAllComments(assignment) + return tx.Factory().NewSyntaxList([]*ast.Node{statement, assignment}) + } case ast.KindExportAssignment, ast.KindJSExportAssignment: if ast.IsSourceFile(input.Parent) { tx.resultHasExternalModuleIndicator = true diff --git a/internal/transformers/declarations/util.go b/internal/transformers/declarations/util.go index e6d71f5697..dfd28f98ab 100644 --- a/internal/transformers/declarations/util.go +++ b/internal/transformers/declarations/util.go @@ -64,7 +64,8 @@ func hasInferredType(node *ast.Node) bool { ast.KindPropertyAssignment, ast.KindShorthandPropertyAssignment, ast.KindJSDocParameterTag, - ast.KindJSDocPropertyTag: + ast.KindJSDocPropertyTag, + ast.KindCommonJSExport: return true default: // assertType(node); // !!! diff --git a/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.js b/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.js new file mode 100644 index 0000000000..0f64fde1de --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/jsDeclarationExportDefaultAssignmentCrash.ts] //// + +//// [index.js] +exports.default = () => { + return 1234; +} + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +export var default = () => { + return 1234; +}; +exports.default = () => { + return 1234; +}; + + +//// [index.d.ts] +declare const _default: () => number; +export default _default; diff --git a/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.symbols b/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.symbols new file mode 100644 index 0000000000..d6854289de --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.symbols @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/jsDeclarationExportDefaultAssignmentCrash.ts] //// + +=== index.js === +exports.default = () => { +>exports.default : Symbol(default, Decl(index.js, 0, 0)) +>exports : Symbol("index", Decl(index.js, 0, 0)) +>default : Symbol(default, Decl(index.js, 0, 0)) + + return 1234; +} + diff --git a/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.types b/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.types new file mode 100644 index 0000000000..91e2e5fc03 --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.types @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/jsDeclarationExportDefaultAssignmentCrash.ts] //// + +=== index.js === +exports.default = () => { +>exports.default = () => { return 1234;} : () => number +>exports.default : () => number +>exports : typeof import("index") +>default : () => number +>() => { return 1234;} : () => number + + return 1234; +>1234 : 1234 +} + diff --git a/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js b/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js index 635b4c6367..7b4d092edc 100644 --- a/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js +++ b/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js @@ -17,4 +17,4 @@ declare const _default: { customSymbol: symbol; }; export = _default; -export var customSymbol2 = Symbol("custom"); +export declare var customSymbol2: symbol; diff --git a/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js.diff b/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js.diff index 4094b52ae4..9d7a1df712 100644 --- a/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsExportAssignmentNonMutableLocation.js.diff @@ -10,4 +10,4 @@ + customSymbol: symbol; +}; +export = _default; -+export var customSymbol2 = Symbol("custom"); \ No newline at end of file ++export declare var customSymbol2: symbol; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/modulePreserve4.js b/testdata/baselines/reference/submodule/compiler/modulePreserve4.js index 1ec555552e..f9c42e3055 100644 --- a/testdata/baselines/reference/submodule/compiler/modulePreserve4.js +++ b/testdata/baselines/reference/submodule/compiler/modulePreserve4.js @@ -198,7 +198,7 @@ export {}; // Silly test harness //// [a.d.ts] export declare const x = 0; -export var y = 0; +export declare var y: number; //// [b.d.ts] declare const _default: number; export default _default; @@ -217,8 +217,8 @@ export = _default; declare const _default: number; export default _default; //// [g.d.ts] -export var default = 0; -export {}; +declare const _default: number; +export default _default; //// [main1.d.ts] export {}; //// [main2.d.mts] @@ -226,7 +226,6 @@ export {}; //// [main3.d.cts] export {}; //// [main4.d.cts] -export var x = require("./g"); -export {}; +export declare var x: typeof import("./g"); //// [dummy.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/compiler/modulePreserve4.js.diff b/testdata/baselines/reference/submodule/compiler/modulePreserve4.js.diff index 84267b6dd2..2d93a76726 100644 --- a/testdata/baselines/reference/submodule/compiler/modulePreserve4.js.diff +++ b/testdata/baselines/reference/submodule/compiler/modulePreserve4.js.diff @@ -30,7 +30,7 @@ //// [a.d.ts] -export const x: 0; +export declare const x = 0; -+export var y = 0; ++export declare var y: number; //// [b.d.ts] -declare const _default: 0; +declare const _default: number; @@ -50,18 +50,15 @@ export default _default; //// [g.d.ts] -declare const _default: 0; --export default _default; -+export var default = 0; -+export {}; ++declare const _default: number; + export default _default; //// [main1.d.ts] export {}; - //// [main2.d.mts] @@= skipped -15, +15 lines =@@ //// [main3.d.cts] export {}; //// [main4.d.cts] -export const x: typeof import("./g"); -+export var x = require("./g"); -+export {}; ++export declare var x: typeof import("./g"); //// [dummy.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js index 8a0b1128f3..54f30a42d6 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js @@ -21,7 +21,6 @@ exports.y = 2; //// [assignmentToVoidZero1.d.ts] -export var y = exports.x = void 0; -export var x = 1; -export var y = 2; -export {}; +export declare var y: undefined; +export declare var x: number; +export declare var y: undefined; diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js.diff b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js.diff index 18d553cbdf..714b31fe2a 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero1.js.diff @@ -19,7 +19,6 @@ //// [assignmentToVoidZero1.d.ts] -export const x: 1; -export const y: 2; -+export var y = exports.x = void 0; -+export var x = 1; -+export var y = 2; -+export {}; \ No newline at end of file ++export declare var y: undefined; ++export declare var x: number; ++export declare var y: undefined; \ 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 e79804a05e..9b3221fcfd 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js @@ -45,14 +45,13 @@ assignmentToVoidZero2_1.j + assignmentToVoidZero2_1.k; //// [assignmentToVoidZero2.d.ts] -export var j = 1; -export var k = void 0; +export declare var j: number; +export declare var k: undefined; declare namespace o { var x: number; } declare namespace o { var y: any; } -export {}; //// [importer.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff index a08ceb9494..25462c35e7 100644 --- a/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/assignmentToVoidZero2.js.diff @@ -23,14 +23,13 @@ //// [assignmentToVoidZero2.d.ts] -export const j: 1; -+export var j = 1; -+export var k = void 0; ++export declare var j: number; ++export declare var k: undefined; +declare namespace o { + var x: number; +} +declare namespace o { + var y: any; +} -+export {}; //// [importer.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js b/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js index 239db68d84..e612aa9e18 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js @@ -36,7 +36,8 @@ var diddy = funky(1); //// [commonJSAliasedExport.d.ts] +declare function funky(declaration: any): boolean; export = donkey; -export var funky = funky; +export declare var funky: typeof funky; //// [bug43713.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js.diff b/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js.diff index 3d91b41bc0..f658a2e9e7 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.js.diff @@ -16,15 +16,17 @@ module.exports.funky = funky; //// [bug43713.js] const { funky } = require('./commonJSAliasedExport'); -@@= skipped -15, +19 lines =@@ +@@= skipped -14, +18 lines =@@ + //// [commonJSAliasedExport.d.ts] - export = donkey; +-export = donkey; -declare function donkey(ast: any): any; -declare namespace donkey { - export { funky }; -} --declare function funky(declaration: any): boolean; -+export var funky = funky; + declare function funky(declaration: any): boolean; ++export = donkey; ++export declare var funky: typeof funky; //// [bug43713.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js b/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js index eb041a90a1..6d25b48359 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js @@ -36,7 +36,9 @@ function f(k) { //// [mod1.d.ts] -export var K = K; -export {}; +declare class K { + values(): K; +} +export declare var K: typeof K; //// [main.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js.diff b/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js.diff index 9c2c311535..b8983fb6eb 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportClassTypeReference.js.diff @@ -19,9 +19,9 @@ //// [mod1.d.ts] -export class K { -- values(): K; --} -+export var K = K; -+export {}; ++declare class K { + values(): K; + } ++export declare var K: typeof K; //// [main.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js b/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js index da4ecfbfd1..60789d061e 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js @@ -35,9 +35,10 @@ function f(k) { //// [mod1.d.ts] -export var K = class K { - values(): void; +export declare var K: { + new (): { + values(): void; + }; }; -export {}; //// [main.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js.diff b/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js.diff index 259e8b473a..eedc85ac50 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportExportedClassExpression.js.diff @@ -17,10 +17,12 @@ //// [mod1.d.ts] -export class K { -+export var K = class K { - values(): void; +- values(): void; -} ++export declare var K: { ++ new (): { ++ values(): void; ++ }; +}; -+export {}; //// [main.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 39c2df78a4..bd6dfdc330 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js @@ -45,7 +45,10 @@ declare namespace NS { }; }; } -export var K = NS.K; -export {}; +export declare var K: { + new (): { + values(): /*elided*/ 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 7dcf48b386..263c8c011e 100644 --- a/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff +++ b/testdata/baselines/reference/submodule/conformance/commonJSImportNestedClassTypeReference.js.diff @@ -20,17 +20,14 @@ //// [mod1.d.ts] -export var K: { -- new (): { -- values(): /*elided*/ any; +declare namespace NS { + var K: { + new (): { + values(): /*elided*/ any; + }; - }; --}; ++ }; +} -+export var K = NS.K; -+export {}; - //// [main.d.ts] - export {}; \ No newline at end of file ++export declare var K: { + new (): { + values(): /*elided*/ any; + }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js index 873919cc36..b8868c1a18 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js @@ -38,4 +38,7 @@ module.exports.Strings = Strings; export = Bar; //// [cls.d.ts] export = Foo; -export var Strings = Strings; +export declare var Strings: { + a: string; + b: string; +}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js.diff index 8d3685964a..bb250feeab 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility.js.diff @@ -38,4 +38,7 @@ - let a: string; - let b: string; -} -+export var Strings = Strings; \ No newline at end of file ++export declare var Strings: { ++ a: string; ++ b: string; ++}; \ 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 72c30e4c2a..22db15c153 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -56,7 +56,10 @@ declare namespace Handler { var statische: () => void; } export = Handler; -export var Strings = Strings; +export declare var Strings: { + a: string; + b: string; +}; export type HandlerOptions = { name: String; }; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff index 17b3390c8f..38da037666 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -41,13 +41,17 @@ - * Should be able to export a type alias at the same time. - */ - name: string; +-}; + var statische: () => void; +} +export = Handler; -+export var Strings = Strings; ++export declare var Strings: { ++ a: string; ++ b: string; ++}; +export type HandlerOptions = { + name: String; - }; ++}; +/** + * @typedef {Object} HandlerOptions + * @property {String} name diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js index 43d7d8a23b..c7dda4b311 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js @@ -34,4 +34,4 @@ export default validate; declare const m: typeof m; declare const _default: typeof m.default; export = _default; -export var memberName = "thing"; +export declare var memberName: string; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js.diff index 3c0477cb71..909afdba18 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsCrossfileMerge.js.diff @@ -28,4 +28,4 @@ +declare const m: typeof m; +declare const _default: typeof m.default; +export = _default; -+export var memberName = "thing"; \ No newline at end of file ++export declare var memberName: string; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js index feff514416..3a002970dd 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js @@ -46,6 +46,10 @@ declare const _default: { }; }; export = _default; -export var Sub = class { - constructor(); +export declare var Sub: { + new (): { + instance: { + t: number; + }; + }; }; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js.diff index b8d1314888..635641bdd8 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js.diff @@ -45,6 +45,10 @@ + }; +}; +export = _default; -+export var Sub = class { -+ constructor(); ++export declare var Sub: { ++ new (): { ++ instance: { ++ t: number; ++ }; ++ }; +}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js index 0d111728d1..0e6b5aa563 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js @@ -51,4 +51,4 @@ declare const _default: { }; }; export = _default; -export var Another = Q; +export declare var Another: typeof Q; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js.diff index 79b32ca0bf..426129727c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing.js.diff @@ -52,4 +52,4 @@ + }; +}; +export = _default; -+export var Another = Q; \ No newline at end of file ++export declare var Another: typeof Q; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js index b0cf369223..0d20499ae7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js @@ -30,4 +30,4 @@ declare class Foo { } declare const _default: Foo; export = _default; -export var additional = 20; +export declare var additional: number; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js.diff index b674f89330..f60203ee9d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3.js.diff @@ -34,4 +34,4 @@ +} +declare const _default: Foo; +export = _default; -+export var additional = 20; \ No newline at end of file ++export declare var additional: number; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js index f73905bca5..50c7df5365 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js @@ -29,21 +29,4 @@ module.exports.MyClass.prototype = { //// [jsDeclarationsExportAssignedConstructorFunction.d.ts] -/** @constructor */ -export var MyClass = function ();; -export {}; - - -//// [DtsFileErrors] - - -out/jsDeclarationsExportAssignedConstructorFunction.d.ts(2,33): error TS1005: '{' expected. - - -==== out/jsDeclarationsExportAssignedConstructorFunction.d.ts (1 errors) ==== - /** @constructor */ - export var MyClass = function ();; - ~ -!!! error TS1005: '{' expected. - export {}; - \ No newline at end of file +export declare var MyClass: () => void; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js.diff index 089c0e854d..a1e3ca15d5 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunction.js.diff @@ -20,21 +20,4 @@ -export class MyClass { - a: () => void; -} -+/** @constructor */ -+export var MyClass = function ();; -+export {}; -+ -+ -+//// [DtsFileErrors] -+ -+ -+out/jsDeclarationsExportAssignedConstructorFunction.d.ts(2,33): error TS1005: '{' expected. -+ -+ -+==== out/jsDeclarationsExportAssignedConstructorFunction.d.ts (1 errors) ==== -+ /** @constructor */ -+ export var MyClass = function ();; -+ ~ -+!!! error TS1005: '{' expected. -+ export {}; -+ \ No newline at end of file ++export declare var MyClass: () => void; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js index f1fcca9856..329fb95300 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js @@ -40,4 +40,4 @@ module.exports.Sub.prototype = {}; //// [jsDeclarationsExportAssignedConstructorFunctionWithSub.d.ts] declare const _default: (p: any) => void; export = _default; -export var Sub = function ();; +export declare var Sub: () => void; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js.diff index 8724348065..552b990ef4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedConstructorFunctionWithSub.js.diff @@ -30,4 +30,4 @@ +//// [jsDeclarationsExportAssignedConstructorFunctionWithSub.d.ts] +declare const _default: (p: any) => void; +export = _default; -+export var Sub = function ();; \ No newline at end of file ++export declare var Sub: () => void; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js index 1fafdc93b4..d364596b63 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js @@ -49,4 +49,7 @@ declare const _default: { }; }; export = _default; -export var Strings = Strings; +export declare var Strings: { + a: string; + b: string; +}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js.diff index 65c013a360..b1e559719e 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary.js.diff @@ -46,4 +46,7 @@ + }; +}; +export = _default; -+export var Strings = Strings; \ No newline at end of file ++export declare var Strings: { ++ a: string; ++ b: string; ++}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js index 58e1e4b0ff..93fb7301b1 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js @@ -195,11 +195,11 @@ export = _default; //// [cjs2.d.ts] export = ns; //// [cjs3.d.ts] -export var ns = ns; -export {}; +declare const ns: typeof ns; +export declare var ns: typeof ns; //// [cjs4.d.ts] -export var names = ns; -export {}; +declare const ns: typeof ns; +export declare var names: typeof ns; //// [includeAll.d.ts] import "./cjs4"; import "./cjs3"; @@ -218,9 +218,12 @@ import "./bar2"; out/cjs.d.ts(1,15): error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. out/cjs2.d.ts(1,10): error TS2304: Cannot find name 'ns'. -out/cjs3.d.ts(1,17): error TS1039: Initializers are not allowed in ambient contexts. -out/cjs4.d.ts(1,20): error TS1039: Initializers are not allowed in ambient contexts. -out/cjs4.d.ts(1,20): error TS2304: Cannot find name 'ns'. +out/cjs3.d.ts(1,15): error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. +out/cjs3.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'ns'. +out/cjs3.d.ts(2,20): error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. +out/cjs3.d.ts(2,20): error TS2451: Cannot redeclare block-scoped variable 'ns'. +out/cjs3.d.ts(2,20): error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. +out/cjs4.d.ts(1,15): error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. ==== out/cls.d.ts (0 errors) ==== @@ -267,19 +270,25 @@ out/cjs4.d.ts(1,20): error TS2304: Cannot find name 'ns'. ~~ !!! error TS2304: Cannot find name 'ns'. -==== out/cjs3.d.ts (1 errors) ==== - export var ns = ns; - ~~ -!!! error TS1039: Initializers are not allowed in ambient contexts. - export {}; - -==== out/cjs4.d.ts (2 errors) ==== - export var names = ns; +==== out/cjs3.d.ts (5 errors) ==== + declare const ns: typeof ns; + ~~ +!!! error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. + ~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'ns'. + export declare var ns: typeof ns; ~~ -!!! error TS1039: Initializers are not allowed in ambient contexts. +!!! error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. ~~ -!!! error TS2304: Cannot find name 'ns'. - export {}; +!!! error TS2451: Cannot redeclare block-scoped variable 'ns'. + ~~ +!!! error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. + +==== out/cjs4.d.ts (1 errors) ==== + declare const ns: typeof ns; + ~~ +!!! error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. + export declare var names: typeof ns; ==== out/includeAll.d.ts (0 errors) ==== import "./cjs4"; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js.diff index 0d7c673b3d..b1bcde6b98 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportForms.js.diff @@ -93,13 +93,13 @@ //// [cjs3.d.ts] -export { ns }; -import ns = require("./cls"); -+export var ns = ns; -+export {}; ++declare const ns: typeof ns; ++export declare var ns: typeof ns; //// [cjs4.d.ts] -export { ns as names }; -import ns = require("./cls"); -+export var names = ns; -+export {}; ++declare const ns: typeof ns; ++export declare var names: typeof ns; //// [includeAll.d.ts] -export {}; +import "./cjs4"; @@ -119,9 +119,12 @@ + +out/cjs.d.ts(1,15): error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. +out/cjs2.d.ts(1,10): error TS2304: Cannot find name 'ns'. -+out/cjs3.d.ts(1,17): error TS1039: Initializers are not allowed in ambient contexts. -+out/cjs4.d.ts(1,20): error TS1039: Initializers are not allowed in ambient contexts. -+out/cjs4.d.ts(1,20): error TS2304: Cannot find name 'ns'. ++out/cjs3.d.ts(1,15): error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. ++out/cjs3.d.ts(1,15): error TS2451: Cannot redeclare block-scoped variable 'ns'. ++out/cjs3.d.ts(2,20): error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. ++out/cjs3.d.ts(2,20): error TS2451: Cannot redeclare block-scoped variable 'ns'. ++out/cjs3.d.ts(2,20): error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. ++out/cjs4.d.ts(1,15): error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. + + +==== out/cls.d.ts (0 errors) ==== @@ -168,19 +171,25 @@ + ~~ +!!! error TS2304: Cannot find name 'ns'. + -+==== out/cjs3.d.ts (1 errors) ==== -+ export var ns = ns; -+ ~~ -+!!! error TS1039: Initializers are not allowed in ambient contexts. -+ export {}; -+ -+==== out/cjs4.d.ts (2 errors) ==== -+ export var names = ns; ++==== out/cjs3.d.ts (5 errors) ==== ++ declare const ns: typeof ns; ++ ~~ ++!!! error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. ++ ~~ ++!!! error TS2451: Cannot redeclare block-scoped variable 'ns'. ++ export declare var ns: typeof ns; + ~~ -+!!! error TS1039: Initializers are not allowed in ambient contexts. ++!!! error TS2395: Individual declarations in merged declaration 'ns' must be all exported or all local. + ~~ -+!!! error TS2304: Cannot find name 'ns'. -+ export {}; ++!!! error TS2451: Cannot redeclare block-scoped variable 'ns'. ++ ~~ ++!!! error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. ++ ++==== out/cjs4.d.ts (1 errors) ==== ++ declare const ns: typeof ns; ++ ~~ ++!!! error TS2502: 'ns' is referenced directly or indirectly in its own type annotation. ++ export declare var names: typeof ns; + +==== out/includeAll.d.ts (0 errors) ==== + import "./cjs4"; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js index 0dd0b9d043..eded4b1dac 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js @@ -26,4 +26,7 @@ module.exports.Strings = Strings; //// [cls.d.ts] export = Foo; -export var Strings = Strings; +export declare var Strings: { + a: string; + b: string; +}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js.diff index 94c7fd4dbd..169cc9bb8a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments.js.diff @@ -29,4 +29,7 @@ - let a: string; - let b: string; -} -+export var Strings = Strings; \ No newline at end of file ++export declare var Strings: { ++ a: string; ++ b: string; ++}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js index ae049969e2..e8f0949e96 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js @@ -145,31 +145,33 @@ module.exports.j = function j() { }; //// [index.d.ts] -export var a = function a();; -export var b = function b();; -export var c = function c();; +export declare var a: () => void; +export declare var b: () => void; +export declare var c: () => void; +export declare var d: (a: any, b: any) => any; +export declare var e: (a: any, b: any) => any; +export declare var f: (a: any) => any; /** - * @param {number} a - * @param {number} b - * @return {string} - */ -export var d = function d(a, b);; -/** - * @template T,U - * @param {T} a - * @param {U} b - * @return {T & U} + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b */ -export var e = function e(a, b);; +declare function g(a: { + x: string; +}, b: { + y: typeof module.exports.b; +}): any; +export declare var g: typeof g; /** - * @template T - * @param {T} a + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b */ -export var f = function f(a);; -export var g = g; -export var h = hh; -export var i = function i();; -export var ii = module.exports.i; -export var jj = module.exports.j; -export var j = function j();; -export {}; +declare function hh(a: { + x: string; +}, b: { + y: typeof module.exports.b; +}): any; +export declare var h: typeof hh; +export declare var i: () => void; +export declare var ii: () => void; +export declare var jj: () => void; +export declare var j: () => void; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js.diff index 6c5287fed0..014da86514 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionsCjs.js.diff @@ -105,56 +105,45 @@ -export function j(): void; -declare class Cls { -} --/** -- * @param {{x: string}} a -- * @param {{y: typeof module.exports.b}} b -- */ ++export declare var a: () => void; ++export declare var b: () => void; ++export declare var c: () => void; ++export declare var d: (a: any, b: any) => any; ++export declare var e: (a: any, b: any) => any; ++export declare var f: (a: any) => any; + /** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ -export function g(a: { -- x: string; --}, b: { ++declare function g(a: { + x: string; + }, b: { - y: { - (): void; - cat: string; - }; -}): void; --/** -- * @param {{x: string}} a -- * @param {{y: typeof module.exports.b}} b -- */ --declare function hh(a: { -- x: string; --}, b: { ++ y: typeof module.exports.b; ++}): any; ++export declare var g: typeof g; + /** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b +@@= skipped -48, +38 lines =@@ + declare function hh(a: { + x: string; + }, b: { - y: { - (): void; - cat: string; - }; -}): void; -export { hh as h, i as ii, j as jj }; -+export var a = function a();; -+export var b = function b();; -+export var c = function c();; -+/** -+ * @param {number} a -+ * @param {number} b -+ * @return {string} -+ */ -+export var d = function d(a, b);; -+/** -+ * @template T,U -+ * @param {T} a -+ * @param {U} b -+ * @return {T & U} -+ */ -+export var e = function e(a, b);; -+/** -+ * @template T -+ * @param {T} a -+ */ -+export var f = function f(a);; -+export var g = g; -+export var h = hh; -+export var i = function i();; -+export var ii = module.exports.i; -+export var jj = module.exports.j; -+export var j = function j();; -+export {}; \ No newline at end of file ++ y: typeof module.exports.b; ++}): any; ++export declare var h: typeof hh; ++export declare var i: () => void; ++export declare var ii: () => void; ++export declare var jj: () => void; ++export declare var j: () => void; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js index 55d6a0df23..ba40b630ab 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js @@ -60,14 +60,7 @@ export type myTypes = { prop2: string; }; export type myTypes = myTypes.typeB | Function; -/** @typedef {string|RegExp|Array} myTypes.typeA */ -/** - * @typedef myTypes.typeB - * @property {myTypes.typeA} prop1 - Prop 1. - * @property {string} prop2 - Prop 2. - */ -/** @typedef {myTypes.typeB|Function} myTypes.typeC */ -export var myTypes = myTypes; +export declare var myTypes: any; //// [file2.d.ts] export type testFnTypes = boolean | myTypes.typeC; /** @typedef {boolean|myTypes.typeC} testFnTypes.input */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js.diff index ff18b56816..bf77c50f99 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js.diff @@ -4,24 +4,18 @@ //// [file.d.ts] -+export type myTypes = string | RegExp | Array; -+export type myTypes = { -+ prop1: myTypes.typeA; -+ prop2: string; -+}; -+export type myTypes = myTypes.typeB | Function; -+/** @typedef {string|RegExp|Array} myTypes.typeA */ - /** +-/** - * @namespace myTypes - * @global - * @type {Object} -+ * @typedef myTypes.typeB -+ * @property {myTypes.typeA} prop1 - Prop 1. -+ * @property {string} prop2 - Prop 2. - */ +- */ -export const myTypes: { - [x: string]: any; --}; ++export type myTypes = string | RegExp | Array; ++export type myTypes = { ++ prop1: myTypes.typeA; ++ prop2: string; + }; -export namespace myTypes { - type typeA = string | RegExp | Array; - type typeB = { @@ -36,14 +30,14 @@ - }; - type typeC = myTypes.typeB | Function; -} -+/** @typedef {myTypes.typeB|Function} myTypes.typeC */ -+export var myTypes = myTypes; ++export type myTypes = myTypes.typeB | Function; ++export declare var myTypes: any; //// [file2.d.ts] +export type testFnTypes = boolean | myTypes.typeC; /** @typedef {boolean|myTypes.typeC} testFnTypes.input */ /** * @function testFn -@@= skipped -30, +23 lines =@@ +@@= skipped -30, +16 lines =@@ * @param {testFnTypes.input} input - Input. * @returns {number|null} Result. */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js index c92bd9bc18..0469b5358c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js @@ -27,5 +27,4 @@ module.exports.A.B = { //// [index.d.ts] -export var A = {}; -export {}; +export declare var A: {}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js.diff index 2a594e8114..afd05f2739 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences3.js.diff @@ -23,5 +23,4 @@ -} -import Something_1 = require("fs"); -import Something = Something_1.Something; -+export var A = {}; -+export {}; \ No newline at end of file ++export declare var A: {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js b/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js index 184cf4cb72..65b2dbedb4 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js +++ b/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js @@ -20,27 +20,8 @@ exports["Does not work yet"] = D; //// [moduleExportAliasElementAccessExpression.d.ts] -export var D = D; -export var Does not work yet = D; -export {}; - - -//// [DtsFileErrors] - - -out/moduleExportAliasElementAccessExpression.d.ts(2,17): error TS1005: ',' expected. -out/moduleExportAliasElementAccessExpression.d.ts(2,21): error TS1005: ',' expected. -out/moduleExportAliasElementAccessExpression.d.ts(2,26): error TS1005: ',' expected. - - -==== out/moduleExportAliasElementAccessExpression.d.ts (3 errors) ==== - export var D = D; - export var Does not work yet = D; - ~~~ -!!! error TS1005: ',' expected. - ~~~~ -!!! error TS1005: ',' expected. - ~~~ -!!! error TS1005: ',' expected. - export {}; - \ No newline at end of file +declare function D(): void; +declare const _exported: typeof D; +export { _exported as "D" }; +declare const _exported_1: typeof D; +export { _exported_1 as "Does not work yet" }; diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js.diff b/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js.diff index 7783a7eb3e..5d2f55b2a9 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js.diff +++ b/testdata/baselines/reference/submodule/conformance/moduleExportAliasElementAccessExpression.js.diff @@ -18,27 +18,8 @@ //// [moduleExportAliasElementAccessExpression.d.ts] -export function D(): void; -export { D as _Does_not_work_yet }; -+export var D = D; -+export var Does not work yet = D; -+export {}; -+ -+ -+//// [DtsFileErrors] -+ -+ -+out/moduleExportAliasElementAccessExpression.d.ts(2,17): error TS1005: ',' expected. -+out/moduleExportAliasElementAccessExpression.d.ts(2,21): error TS1005: ',' expected. -+out/moduleExportAliasElementAccessExpression.d.ts(2,26): error TS1005: ',' expected. -+ -+ -+==== out/moduleExportAliasElementAccessExpression.d.ts (3 errors) ==== -+ export var D = D; -+ export var Does not work yet = D; -+ ~~~ -+!!! error TS1005: ',' expected. -+ ~~~~ -+!!! error TS1005: ',' expected. -+ ~~~ -+!!! error TS1005: ',' expected. -+ export {}; -+ \ No newline at end of file ++declare function D(): void; ++declare const _exported: typeof D; ++export { _exported as "D" }; ++declare const _exported_1: typeof D; ++export { _exported_1 as "Does not work yet" }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js index 5efb46cf66..4ee7030d20 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js +++ b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js @@ -29,8 +29,7 @@ apply(); //// [moduleExportAliasDuplicateAlias.d.ts] -export var apply = undefined; -export var apply = a; -export {}; +export declare var apply: undefined; +export declare var apply: undefined; //// [test.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js.diff b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js.diff index 1f6798aa2b..da8d0fc2d2 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js.diff +++ b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias.js.diff @@ -19,8 +19,7 @@ //// [moduleExportAliasDuplicateAlias.d.ts] -export { a as apply }; -declare function a(): void; -+export var apply = undefined; -+export var apply = a; -+export {}; ++export declare var apply: undefined; ++export declare var apply: undefined; //// [test.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js index 32cd447fba..464a441258 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js +++ b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js @@ -30,9 +30,8 @@ apply(); //// [moduleExportAliasDuplicateAlias.d.ts] -export var apply = undefined; -export var apply = a; -export var apply = a; -export {}; +export declare var apply: undefined; +export declare var apply: undefined; +export declare var apply: undefined; //// [test.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js.diff b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js.diff index 547d966ad9..51dfb3c53a 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js.diff +++ b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias2.js.diff @@ -20,9 +20,8 @@ //// [moduleExportAliasDuplicateAlias.d.ts] -export { a as apply }; -declare function a(): void; -+export var apply = undefined; -+export var apply = a; -+export var apply = a; -+export {}; ++export declare var apply: undefined; ++export declare var apply: undefined; ++export declare var apply: undefined; //// [test.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js index ca8ba75bb5..1826f857f2 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js +++ b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js @@ -38,11 +38,10 @@ const result = apply.toFixed(); //// [moduleExportAliasDuplicateAlias.d.ts] -export var apply = undefined; -export var apply = undefined; -export var apply = a; -export var apply = 'ok'; -export var apply = 1; -export {}; +export declare var apply: undefined; +export declare var apply: undefined; +export declare var apply: undefined; +export declare var apply: undefined; +export declare var apply: undefined; //// [test.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js.diff b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js.diff index 031199c202..e091ce0595 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js.diff +++ b/testdata/baselines/reference/submodule/conformance/moduleExportDuplicateAlias3.js.diff @@ -27,11 +27,10 @@ -export const apply: "ok" | 1 | typeof a | undefined; -export { a as apply }; -declare function a(): void; -+export var apply = undefined; -+export var apply = undefined; -+export var apply = a; -+export var apply = 'ok'; -+export var apply = 1; -+export {}; ++export declare var apply: undefined; ++export declare var apply: undefined; ++export declare var apply: undefined; ++export declare var apply: undefined; ++export declare var apply: undefined; //// [test.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js b/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js index 5e70503425..fd6eb83ea9 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js +++ b/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js @@ -20,11 +20,22 @@ mod1.default; //// [mod1.d.ts] -export var a = { x: "x" }; -export var b = { x: "x" }; -export var default = { x: "x" }; -export var c = { x: "x" }; -export var d = {}; -export {}; +export declare var a: { + x: string; +}; +declare const _exported: { + x: string; +}; +export { _exported as "b" }; +declare const _exported_1: { + x: string; +}; +export { _exported_1 as "default" }; +declare const _exported_2: { + x: string; +}; +export { _exported_2 as "c" }; +declare const _exported_3: {}; +export { _exported_3 as "d" }; //// [mod2.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js.diff b/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js.diff index 5c413072ad..68d3a6f598 100644 --- a/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js.diff +++ b/testdata/baselines/reference/submodule/conformance/moduleExportsElementAccessAssignment.js.diff @@ -23,11 +23,22 @@ -export namespace d { - let e: number; -} -+export var a = { x: "x" }; -+export var b = { x: "x" }; -+export var default = { x: "x" }; -+export var c = { x: "x" }; -+export var d = {}; -+export {}; ++export declare var a: { ++ x: string; ++}; ++declare const _exported: { ++ x: string; ++}; ++export { _exported as "b" }; ++declare const _exported_1: { ++ x: string; ++}; ++export { _exported_1 as "default" }; ++declare const _exported_2: { ++ x: string; ++}; ++export { _exported_2 as "c" }; ++declare const _exported_3: {}; ++export { _exported_3 as "d" }; //// [mod2.d.ts] export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js b/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js index 2d323ea43f..ea7a565f31 100644 --- a/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js +++ b/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js @@ -29,7 +29,8 @@ chalk; //// [mod1.d.ts] -export var chalk = chalk; -export {}; +export declare var chalk: { + grey: {}; +}; //// [main.d.ts] export {}; diff --git a/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js.diff b/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js.diff index 4fdb156b6f..09d98a3c3a 100644 --- a/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js.diff +++ b/testdata/baselines/reference/submodule/conformance/nestedDestructuringOfRequire.js.diff @@ -20,7 +20,8 @@ -export namespace chalk { - let grey: {}; -} -+export var chalk = chalk; -+export {}; ++export declare var chalk: { ++ grey: {}; ++}; //// [main.d.ts] export {}; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/jsDeclarationExportDefaultAssignmentCrash.ts b/testdata/tests/cases/compiler/jsDeclarationExportDefaultAssignmentCrash.ts new file mode 100644 index 0000000000..9ffac97175 --- /dev/null +++ b/testdata/tests/cases/compiler/jsDeclarationExportDefaultAssignmentCrash.ts @@ -0,0 +1,9 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: index.js + +exports.default = () => { + return 1234; +}