diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 228afea1813ef..544a1e2d4b0a6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4368,11 +4368,11 @@ namespace ts { return getInferredType(context, i); } } - return t; + return t; }; mapper.context = context; - return mapper; + return mapper; } function identityMapper(type: Type): Type { @@ -7334,10 +7334,9 @@ namespace ts { * For example, in the element , the element instance type is `MyClass` (not `typeof MyClass`). */ function getJsxElementInstanceType(node: JsxOpeningLikeElement) { - if (!(getNodeLinks(node).jsxFlags & JsxFlags.ClassElement)) { - // There is no such thing as an instance type for a non-class element - return undefined; - } + // There is no such thing as an instance type for a non-class element. This + // line shouldn't be hit. + Debug.assert(!!(getNodeLinks(node).jsxFlags & JsxFlags.ClassElement), 'Should not call getJsxElementInstanceType on non-class Element'); let classSymbol = getJsxElementTagSymbol(node); if (classSymbol === unknownSymbol) { @@ -7360,16 +7359,11 @@ namespace ts { if (signatures.length === 0) { // We found no signatures at all, which is an error error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName)); - return undefined; + return unknownType; } } - // Check that the constructor/factory returns an object type - let returnType = getUnionType(signatures.map(s => getReturnTypeOfSignature(s))); - if (!isTypeAny(returnType) && !(returnType.flags & TypeFlags.ObjectType)) { - error(node.tagName, Diagnostics.The_return_type_of_a_JSX_element_constructor_must_return_an_object_type); - return undefined; - } + let returnType = getUnionType(signatures.map(getReturnTypeOfSignature)); // Issue an error if this return type isn't assignable to JSX.ElementClass let elemClassType = getJsxGlobalElementClassType(); @@ -7430,7 +7424,7 @@ namespace ts { let elemInstanceType = getJsxElementInstanceType(node); if (isTypeAny(elemInstanceType)) { - return links.resolvedJsxType = anyType; + return links.resolvedJsxType = elemInstanceType; } let propsName = getJsxElementPropertiesName(); @@ -10873,9 +10867,6 @@ namespace ts { return; } - // Exports should be checked only if enclosing module contains both exported and non exported declarations. - // In case if all declarations are non-exported check is unnecessary. - // if localSymbol is defined on node then node itself is exported - check is required let symbol = node.localSymbol; if (!symbol) { @@ -10895,27 +10886,45 @@ namespace ts { // we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace // to denote disjoint declarationSpaces (without making new enum type). - let exportedDeclarationSpaces: SymbolFlags = 0; - let nonExportedDeclarationSpaces: SymbolFlags = 0; - forEach(symbol.declarations, d => { + let exportedDeclarationSpaces = SymbolFlags.None; + let nonExportedDeclarationSpaces = SymbolFlags.None; + let defaultExportedDeclarationSpaces = SymbolFlags.None; + for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); - if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) { - exportedDeclarationSpaces |= declarationSpaces; + let effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, NodeFlags.Export | NodeFlags.Default); + + if (effectiveDeclarationFlags & NodeFlags.Export) { + if (effectiveDeclarationFlags & NodeFlags.Default) { + defaultExportedDeclarationSpaces |= declarationSpaces; + } + else { + exportedDeclarationSpaces |= declarationSpaces; + } } else { nonExportedDeclarationSpaces |= declarationSpaces; } - }); + } - let commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + // Spaces for anyting not declared a 'default export'. + let nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces; + + let commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + let commonDeclarationSpacesForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces; - if (commonDeclarationSpace) { + if (commonDeclarationSpacesForExportsAndLocals || commonDeclarationSpacesForDefaultAndNonDefault) { // declaration spaces for exported and non-exported declarations intersect - forEach(symbol.declarations, d => { - if (getDeclarationSpaces(d) & commonDeclarationSpace) { + for (let d of symbol.declarations) { + let declarationSpaces = getDeclarationSpaces(d); + + // Only error on the declarations that conributed to the intersecting spaces. + if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) { + error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead, declarationNameToString(d.name)); + } + else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); } - }); + } } function getDeclarationSpaces(d: Declaration): SymbolFlags { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ecea3a766730c..854d214fb7460 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -294,7 +294,7 @@ namespace ts { Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." }, Duplicate_function_implementation: { code: 2393, category: DiagnosticCategory.Error, key: "Duplicate function implementation." }, Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." }, - Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." }, + Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration '{0}' must be all exported or all local." }, Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." }, Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." }, Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." }, @@ -425,6 +425,7 @@ namespace ts { JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" }, The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" }, Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, + Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2651, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2765d04f4003e..fd235a9d38ac4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1165,7 +1165,7 @@ "category": "Error", "code": 2394 }, - "Individual declarations in merged declaration {0} must be all exported or all local.": { + "Individual declarations in merged declaration '{0}' must be all exported or all local.": { "category": "Error", "code": 2395 }, @@ -1689,6 +1689,10 @@ "category": "Error", "code": 2650 }, + "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead.": { + "category": "Error", + "code": 2651 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e97ece5bf0022..7b3b51c3f2766 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6841,6 +6841,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } + /** + * Removes all but the pinned or triple slash comments. + * @param ranges The array to be filtered + * @param onlyPinnedOrTripleSlashComments whether the filtering should be performed. + */ function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { // If we're removing comments, then we want to strip out all but the pinned or // triple slash comments. diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index a657cc8c314b9..6872c4c876ee3 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -3,7 +3,7 @@ namespace ts { export interface SourceFile { - fileWatcher: FileWatcher; + fileWatcher?: FileWatcher; } /** diff --git a/src/services/services.ts b/src/services/services.ts index 60796669d6552..8e670268498df 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -261,26 +261,25 @@ namespace ts { } public getFirstToken(sourceFile?: SourceFile): Node { - let children = this.getChildren(); - for (let child of children) { - if (child.kind < SyntaxKind.FirstNode) { - return child; - } - - return child.getFirstToken(sourceFile); + let children = this.getChildren(sourceFile); + if (!children.length) { + return undefined; } + + let child = children[0]; + + return child.kind < SyntaxKind.FirstNode ? child : child.getFirstToken(sourceFile); } public getLastToken(sourceFile?: SourceFile): Node { let children = this.getChildren(sourceFile); - for (let i = children.length - 1; i >= 0; i--) { - let child = children[i]; - if (child.kind < SyntaxKind.FirstNode) { - return child; - } - return child.getLastToken(sourceFile); + let child = lastOrUndefined(children); + if (!child) { + return undefined; } + + return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); } } diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt new file mode 100644 index 0000000000000..6e3955b4ef86a --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt @@ -0,0 +1,49 @@ +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(11,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m2.ts(5,8): error TS2304: Cannot find name 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,8): error TS2339: Property 'x' does not exist on type '() => number'. +tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does not exist on type '() => number'. + + +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== + + export default function Decl() { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + return 0; + } + + export interface Decl { + p1: number; + p2: number; + } + + export namespace Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + export var x = 10; + export var y = 20; + + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + + var x: Entity; + ~~~~~~ +!!! error TS2304: Cannot find name 'Entity'. + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + + Entity.x; + ~ +!!! error TS2339: Property 'x' does not exist on type '() => number'. + Entity.y; + ~ +!!! error TS2339: Property 'y' does not exist on type '() => number'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.js b/tests/baselines/reference/defaultExportsCannotMerge01.js new file mode 100644 index 0000000000000..99b8ecab1d325 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge01.js @@ -0,0 +1,50 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts] //// + +//// [m1.ts] + +export default function Decl() { + return 0; +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + export var x = 10; + export var y = 20; + + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; + +Entity.x; +Entity.y; + +//// [m1.js] +function Decl() { + return 0; +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Decl; +var Decl; +(function (Decl) { + Decl.x = 10; + Decl.y = 20; +})(Decl = exports.Decl || (exports.Decl = {})); +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +m1_1.default.x; +m1_1.default.y; diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt new file mode 100644 index 0000000000000..ef4ecdccfc31d --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(5,18): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. +tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' does not exist on type 'Decl'. + + +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== + + export default class Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + } + + export interface Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + p1: number; + p2: number; + } + + export namespace Decl { + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? + + var x: Entity; + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + var z = new Entity(); + var sum = z.p1 + z.p2 + ~~ +!!! error TS2339: Property 'p1' does not exist on type 'Decl'. + ~~ +!!! error TS2339: Property 'p2' does not exist on type 'Decl'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.js b/tests/baselines/reference/defaultExportsCannotMerge02.js new file mode 100644 index 0000000000000..e3897395c74fd --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts] //// + +//// [m1.ts] + +export default class Decl { +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 + +//// [m1.js] +var Decl = (function () { + function Decl() { + } + return Decl; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Decl; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +var z = new m1_1.default(); +var sum = z.p1 + z.p2; diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt new file mode 100644 index 0000000000000..219b59a56336c --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt @@ -0,0 +1,47 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2518: Only an ambient class can be merged with an interface. +tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. +tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' does not exist on type 'Decl'. + + +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== + + export default class Decl { + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + } + + interface Decl { + ~~~~ +!!! error TS2518: Only an ambient class can be merged with an interface. + ~~~~ +!!! error TS2651: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + p1: number; + p2: number; + } + + namespace Decl { + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? + + var x: Entity; + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + var z = new Entity(); + var sum = z.p1 + z.p2 + ~~ +!!! error TS2339: Property 'p1' does not exist on type 'Decl'. + ~~ +!!! error TS2339: Property 'p2' does not exist on type 'Decl'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.js b/tests/baselines/reference/defaultExportsCannotMerge03.js new file mode 100644 index 0000000000000..05e7de9412087 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts] //// + +//// [m1.ts] + +export default class Decl { +} + +interface Decl { + p1: number; + p2: number; +} + +namespace Decl { + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 + +//// [m1.js] +var Decl = (function () { + function Decl() { + } + return Decl; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Decl; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +var z = new m1_1.default(); +var sum = z.p1 + z.p2; diff --git a/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt new file mode 100644 index 0000000000000..ee36491e0c767 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(2,25): error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(5,11): error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(9,11): error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(12,18): error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + + +==== tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts (4 errors) ==== + + export default function Foo() { + ~~~ +!!! error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. + } + + namespace Foo { + ~~~ +!!! error TS2651: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. + export var x; + } + + interface Foo { + ~~~ +!!! error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + } + + export interface Foo { + ~~~ +!!! error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + } \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge04.js b/tests/baselines/reference/defaultExportsCannotMerge04.js new file mode 100644 index 0000000000000..eb1122a819743 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge04.js @@ -0,0 +1,23 @@ +//// [defaultExportsCannotMerge04.ts] + +export default function Foo() { +} + +namespace Foo { + export var x; +} + +interface Foo { +} + +export interface Foo { +} + +//// [defaultExportsCannotMerge04.js] +function Foo() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Foo; +var Foo; +(function (Foo) { +})(Foo || (Foo = {})); diff --git a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt index df4f8f13c31d8..85dd29b78a3d6 100644 --- a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt +++ b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/duplicateSymbolsExportMatching.ts(24,15): error TS2395: Individual declarations in merged declaration I must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(25,22): error TS2395: Individual declarations in merged declaration I must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(26,22): error TS2395: Individual declarations in merged declaration E must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(27,15): error TS2395: Individual declarations in merged declaration E must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(32,12): error TS2395: Individual declarations in merged declaration inst must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(35,19): error TS2395: Individual declarations in merged declaration inst must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(42,9): error TS2395: Individual declarations in merged declaration v must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(43,16): error TS2395: Individual declarations in merged declaration v must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(44,9): error TS2395: Individual declarations in merged declaration w must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(45,16): error TS2395: Individual declarations in merged declaration w must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2395: Individual declarations in merged declaration F must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(24,15): error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(25,22): error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(26,22): error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(27,15): error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(32,12): error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(35,19): error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(42,9): error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(43,16): error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(44,9): error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(45,16): error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2434: A namespace declaration cannot be located prior to a class or function with which it is merged -tests/cases/compiler/duplicateSymbolsExportMatching.ts(52,21): error TS2395: Individual declarations in merged declaration F must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(56,11): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(57,12): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(58,19): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(64,11): error TS2395: Individual declarations in merged declaration D must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Individual declarations in merged declaration D must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(52,21): error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(56,11): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(57,12): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(58,19): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(64,11): error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. ==== tests/cases/compiler/duplicateSymbolsExportMatching.ts (18 errors) ==== @@ -44,28 +44,28 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind module N2 { interface I { } ~ -!!! error TS2395: Individual declarations in merged declaration I must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. export interface I { } // error ~ -!!! error TS2395: Individual declarations in merged declaration I must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. export interface E { } ~ -!!! error TS2395: Individual declarations in merged declaration E must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. interface E { } // error ~ -!!! error TS2395: Individual declarations in merged declaration E must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. } // Should report error only once for instantiated module module M { module inst { ~~~~ -!!! error TS2395: Individual declarations in merged declaration inst must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. var t; } export module inst { // one error ~~~~ -!!! error TS2395: Individual declarations in merged declaration inst must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. var t; } } @@ -74,41 +74,41 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind module M2 { var v: string; ~ -!!! error TS2395: Individual declarations in merged declaration v must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. export var v: string; // one error (visibility) ~ -!!! error TS2395: Individual declarations in merged declaration v must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. var w: number; ~ -!!! error TS2395: Individual declarations in merged declaration w must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. export var w: string; // two errors (visibility and type mismatch) ~ -!!! error TS2395: Individual declarations in merged declaration w must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. } module M { module F { ~ -!!! error TS2395: Individual declarations in merged declaration F must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. ~ !!! error TS2434: A namespace declaration cannot be located prior to a class or function with which it is merged var t; } export function F() { } // Only one error for duplicate identifier (don't consider visibility) ~ -!!! error TS2395: Individual declarations in merged declaration F must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. } module M { class C { } ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. module C { } ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. export module C { // Two visibility errors (one for the clodule symbol, and one for the merged container symbol) ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. var t; } } @@ -116,7 +116,7 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind // Top level interface D { } ~ -!!! error TS2395: Individual declarations in merged declaration D must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. export interface D { } ~ -!!! error TS2395: Individual declarations in merged declaration D must be all exported or all local. \ No newline at end of file +!!! error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. \ No newline at end of file diff --git a/tests/baselines/reference/innerModExport2.errors.txt b/tests/baselines/reference/innerModExport2.errors.txt index 52a9d01c99739..f9568bb45a4e1 100644 --- a/tests/baselines/reference/innerModExport2.errors.txt +++ b/tests/baselines/reference/innerModExport2.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/innerModExport2.ts(5,5): error TS2304: Cannot find name 'module'. tests/cases/compiler/innerModExport2.ts(5,12): error TS1005: ';' expected. -tests/cases/compiler/innerModExport2.ts(7,20): error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. -tests/cases/compiler/innerModExport2.ts(13,9): error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +tests/cases/compiler/innerModExport2.ts(7,20): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. +tests/cases/compiler/innerModExport2.ts(13,9): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExportFunc' does not exist on type 'typeof Outer'. @@ -18,7 +18,7 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport var non_export_var = 0; export var export_var = 1; ~~~~~~~~~~ -!!! error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. function NonExportFunc() { return 0; } @@ -26,7 +26,7 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport } var export_var: number; ~~~~~~~~~~ -!!! error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. export var outer_var_export = 0; export function outerFuncExport() { return 0; } diff --git a/tests/baselines/reference/jsxViaImport.errors.txt b/tests/baselines/reference/jsxViaImport.errors.txt new file mode 100644 index 0000000000000..8fa22809a44e8 --- /dev/null +++ b/tests/baselines/reference/jsxViaImport.errors.txt @@ -0,0 +1,27 @@ +tests/cases/compiler/consumer.tsx(5,17): error TS2604: JSX element type 'BaseComponent' does not have any construct or call signatures. + + +==== tests/cases/compiler/consumer.tsx (1 errors) ==== + /// + import BaseComponent = require('BaseComponent'); + class TestComponent extends React.Component { + render() { + return ; + ~~~~~~~~~~~~~ +!!! error TS2604: JSX element type 'BaseComponent' does not have any construct or call signatures. + } + } + +==== tests/cases/compiler/component.d.ts (0 errors) ==== + + declare module JSX { + interface ElementAttributesProperty { props; } + } + declare module React { + class Component { } + } + declare module "BaseComponent" { + var base: React.Component; + export = base; + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsxViaImport.js b/tests/baselines/reference/jsxViaImport.js new file mode 100644 index 0000000000000..6bf61af67f5fb --- /dev/null +++ b/tests/baselines/reference/jsxViaImport.js @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/jsxViaImport.tsx] //// + +//// [component.d.ts] + +declare module JSX { + interface ElementAttributesProperty { props; } +} +declare module React { + class Component { } +} +declare module "BaseComponent" { + var base: React.Component; + export = base; +} + +//// [consumer.tsx] +/// +import BaseComponent = require('BaseComponent'); +class TestComponent extends React.Component { + render() { + return ; + } +} + + +//// [consumer.jsx] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +/// +var BaseComponent = require('BaseComponent'); +var TestComponent = (function (_super) { + __extends(TestComponent, _super); + function TestComponent() { + _super.apply(this, arguments); + } + TestComponent.prototype.render = function () { + return ; + }; + return TestComponent; +})(React.Component); diff --git a/tests/baselines/reference/multipleDefaultExports01.errors.txt b/tests/baselines/reference/multipleDefaultExports01.errors.txt new file mode 100644 index 0000000000000..7b49afe1a4e35 --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports01.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2300: Duplicate identifier 'foo'. +tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2300: Duplicate identifier 'bar'. +tests/cases/conformance/es6/modules/m1.ts(11,1): error TS2300: Duplicate identifier 'default'. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? + + +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== + + export default class foo { + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. + + } + + export default function bar() { + ~~~ +!!! error TS2300: Duplicate identifier 'bar'. + + } + + var x = 10; + export default x; + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. + +==== tests/cases/conformance/es6/modules/m2.ts (1 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? \ No newline at end of file diff --git a/tests/baselines/reference/multipleDefaultExports01.js b/tests/baselines/reference/multipleDefaultExports01.js new file mode 100644 index 0000000000000..e633cf69f550d --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports01.js @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/es6/modules/multipleDefaultExports01.ts] //// + +//// [m1.ts] + +export default class foo { + +} + +export default function bar() { + +} + +var x = 10; +export default x; + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +//// [m1.js] +var foo = (function () { + function foo() { + } + return foo; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = foo; +function bar() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = bar; +var x = 10; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = x; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); diff --git a/tests/baselines/reference/multipleDefaultExports02.errors.txt b/tests/baselines/reference/multipleDefaultExports02.errors.txt new file mode 100644 index 0000000000000..51220ecfae262 --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports02.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2393: Duplicate function implementation. + + +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== + + export default function foo() { + ~~~ +!!! error TS2393: Duplicate function implementation. + + } + + export default function bar() { + ~~~ +!!! error TS2393: Duplicate function implementation. + + } + +==== tests/cases/conformance/es6/modules/m2.ts (0 errors) ==== + import Entity from "m1" + + Entity(); \ No newline at end of file diff --git a/tests/baselines/reference/multipleDefaultExports02.js b/tests/baselines/reference/multipleDefaultExports02.js new file mode 100644 index 0000000000000..3d1b84ff6a630 --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports02.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/es6/modules/multipleDefaultExports02.ts] //// + +//// [m1.ts] + +export default function foo() { + +} + +export default function bar() { + +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +//// [m1.js] +function foo() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = foo; +function bar() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = bar; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); diff --git a/tests/baselines/reference/multivar.errors.txt b/tests/baselines/reference/multivar.errors.txt index 931e61de5aef7..44061b9d74c77 100644 --- a/tests/baselines/reference/multivar.errors.txt +++ b/tests/baselines/reference/multivar.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/multivar.ts(6,19): error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. -tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +tests/cases/compiler/multivar.ts(6,19): error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. +tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. ==== tests/cases/compiler/multivar.ts (2 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in export var a, b2: number = 10, b; ~~ -!!! error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. var m1; var a2, b22: number = 10, b222; var m3; @@ -28,7 +28,7 @@ tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in declare var d1, d2; var b2; ~~ -!!! error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. declare var v1; } diff --git a/tests/baselines/reference/tsxElementResolution8.errors.txt b/tests/baselines/reference/tsxElementResolution8.errors.txt index 5710c4e177d35..92ff05d1aedb7 100644 --- a/tests/baselines/reference/tsxElementResolution8.errors.txt +++ b/tests/baselines/reference/tsxElementResolution8.errors.txt @@ -1,10 +1,8 @@ tests/cases/conformance/jsx/tsxElementResolution8.tsx(8,2): error TS2604: JSX element type 'Div' does not have any construct or call signatures. -tests/cases/conformance/jsx/tsxElementResolution8.tsx(16,2): error TS2601: The return type of a JSX element constructor must return an object type. -tests/cases/conformance/jsx/tsxElementResolution8.tsx(29,2): error TS2601: The return type of a JSX element constructor must return an object type. tests/cases/conformance/jsx/tsxElementResolution8.tsx(34,2): error TS2604: JSX element type 'Obj3' does not have any construct or call signatures. -==== tests/cases/conformance/jsx/tsxElementResolution8.tsx (4 errors) ==== +==== tests/cases/conformance/jsx/tsxElementResolution8.tsx (2 errors) ==== declare module JSX { interface Element { } interface IntrinsicElements { } @@ -23,8 +21,6 @@ tests/cases/conformance/jsx/tsxElementResolution8.tsx(34,2): error TS2604: JSX e // Error function Fnum(): number{ return 42; } - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. interface Obj1 { new(): {}; @@ -38,8 +34,6 @@ tests/cases/conformance/jsx/tsxElementResolution8.tsx(34,2): error TS2604: JSX e } var Obj2: Obj2; ; // Error - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. interface Obj3 { } diff --git a/tests/baselines/reference/tsxElementResolution9.errors.txt b/tests/baselines/reference/tsxElementResolution9.errors.txt deleted file mode 100644 index 64514eebc005f..0000000000000 --- a/tests/baselines/reference/tsxElementResolution9.errors.txt +++ /dev/null @@ -1,38 +0,0 @@ -tests/cases/conformance/jsx/tsxElementResolution9.tsx(11,2): error TS2601: The return type of a JSX element constructor must return an object type. -tests/cases/conformance/jsx/tsxElementResolution9.tsx(18,2): error TS2601: The return type of a JSX element constructor must return an object type. -tests/cases/conformance/jsx/tsxElementResolution9.tsx(25,2): error TS2601: The return type of a JSX element constructor must return an object type. - - -==== tests/cases/conformance/jsx/tsxElementResolution9.tsx (3 errors) ==== - declare module JSX { - interface Element { } - interface IntrinsicElements { } - } - - interface Obj1 { - new(n: string): { x: number }; - new(n: number): { y: string }; - } - var Obj1: Obj1; - ; // Error, return type is not an object type - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. - - interface Obj2 { - (n: string): { x: number }; - (n: number): { y: string }; - } - var Obj2: Obj2; - ; // Error, return type is not an object type - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. - - interface Obj3 { - (n: string): { x: number }; - (n: number): { x: number; y: string }; - } - var Obj3: Obj3; - ; // OK - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. - \ No newline at end of file diff --git a/tests/baselines/reference/tsxElementResolution9.symbols b/tests/baselines/reference/tsxElementResolution9.symbols new file mode 100644 index 0000000000000..bfa04219ef990 --- /dev/null +++ b/tests/baselines/reference/tsxElementResolution9.symbols @@ -0,0 +1,67 @@ +=== tests/cases/conformance/jsx/tsxElementResolution9.tsx === +declare module JSX { +>JSX : Symbol(JSX, Decl(tsxElementResolution9.tsx, 0, 0)) + + interface Element { } +>Element : Symbol(Element, Decl(tsxElementResolution9.tsx, 0, 20)) + + interface IntrinsicElements { } +>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxElementResolution9.tsx, 1, 22)) +} + +interface Obj1 { +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) + + new(n: string): { x: number }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 6, 5)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 6, 18)) + + new(n: number): { y: string }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 7, 5)) +>y : Symbol(y, Decl(tsxElementResolution9.tsx, 7, 18)) +} +var Obj1: Obj1; +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) + +; // Error, return type is not an object type +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) + +interface Obj2 { +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) + + (n: string): { x: number }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 13, 2)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 13, 15)) + + (n: number): { y: string }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 14, 2)) +>y : Symbol(y, Decl(tsxElementResolution9.tsx, 14, 15)) +} +var Obj2: Obj2; +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) + +; // Error, return type is not an object type +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) + +interface Obj3 { +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) + + (n: string): { x: number }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 20, 2)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 20, 15)) + + (n: number): { x: number; y: string }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 21, 2)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 21, 15)) +>y : Symbol(y, Decl(tsxElementResolution9.tsx, 21, 26)) +} +var Obj3: Obj3; +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) + +; // OK +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) +>x : Symbol(unknown) + diff --git a/tests/baselines/reference/tsxElementResolution9.types b/tests/baselines/reference/tsxElementResolution9.types new file mode 100644 index 0000000000000..525e4600b2ee8 --- /dev/null +++ b/tests/baselines/reference/tsxElementResolution9.types @@ -0,0 +1,70 @@ +=== tests/cases/conformance/jsx/tsxElementResolution9.tsx === +declare module JSX { +>JSX : any + + interface Element { } +>Element : Element + + interface IntrinsicElements { } +>IntrinsicElements : IntrinsicElements +} + +interface Obj1 { +>Obj1 : Obj1 + + new(n: string): { x: number }; +>n : string +>x : number + + new(n: number): { y: string }; +>n : number +>y : string +} +var Obj1: Obj1; +>Obj1 : Obj1 +>Obj1 : Obj1 + +; // Error, return type is not an object type +> : JSX.Element +>Obj1 : Obj1 + +interface Obj2 { +>Obj2 : Obj2 + + (n: string): { x: number }; +>n : string +>x : number + + (n: number): { y: string }; +>n : number +>y : string +} +var Obj2: Obj2; +>Obj2 : Obj2 +>Obj2 : Obj2 + +; // Error, return type is not an object type +> : JSX.Element +>Obj2 : Obj2 + +interface Obj3 { +>Obj3 : Obj3 + + (n: string): { x: number }; +>n : string +>x : number + + (n: number): { x: number; y: string }; +>n : number +>x : number +>y : string +} +var Obj3: Obj3; +>Obj3 : Obj3 +>Obj3 : Obj3 + +; // OK +> : JSX.Element +>Obj3 : Obj3 +>x : any + diff --git a/tests/cases/compiler/jsxViaImport.tsx b/tests/cases/compiler/jsxViaImport.tsx new file mode 100644 index 0000000000000..5b3b7e11d83a4 --- /dev/null +++ b/tests/cases/compiler/jsxViaImport.tsx @@ -0,0 +1,23 @@ +//@jsx: preserve +//@module: commonjs + +//@filename: component.d.ts +declare module JSX { + interface ElementAttributesProperty { props; } +} +declare module React { + class Component { } +} +declare module "BaseComponent" { + var base: React.Component; + export = base; +} + +//@filename: consumer.tsx +/// +import BaseComponent = require('BaseComponent'); +class TestComponent extends React.Component { + render() { + return ; + } +} diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts new file mode 100644 index 0000000000000..7caa9caf57412 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts @@ -0,0 +1,31 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default function Decl() { + return 0; +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + export var x = 10; + export var y = 20; + + interface I { + } +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; + +Entity.x; +Entity.y; \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts new file mode 100644 index 0000000000000..f7312ec2e6615 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts @@ -0,0 +1,26 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default class Decl { +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + interface I { + } +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts new file mode 100644 index 0000000000000..dad8431812b03 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts @@ -0,0 +1,26 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default class Decl { +} + +interface Decl { + p1: number; + p2: number; +} + +namespace Decl { + interface I { + } +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts new file mode 100644 index 0000000000000..ab72d10504a12 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts @@ -0,0 +1,15 @@ +// @module: commonjs +// @target: ES5 + +export default function Foo() { +} + +namespace Foo { + export var x; +} + +interface Foo { +} + +export interface Foo { +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/multipleDefaultExports01.ts b/tests/cases/conformance/es6/modules/multipleDefaultExports01.ts new file mode 100644 index 0000000000000..84172248e9384 --- /dev/null +++ b/tests/cases/conformance/es6/modules/multipleDefaultExports01.ts @@ -0,0 +1,19 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default class foo { + +} + +export default function bar() { + +} + +var x = 10; +export default x; + +// @filename: m2.ts +import Entity from "m1" + +Entity(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/multipleDefaultExports02.ts b/tests/cases/conformance/es6/modules/multipleDefaultExports02.ts new file mode 100644 index 0000000000000..1e9c8dabc1373 --- /dev/null +++ b/tests/cases/conformance/es6/modules/multipleDefaultExports02.ts @@ -0,0 +1,16 @@ +// @module: commonjs +// @target: ES5 + +// @filename: m1.ts +export default function foo() { + +} + +export default function bar() { + +} + +// @filename: m2.ts +import Entity from "m1" + +Entity(); \ No newline at end of file