From 0eeb9cbd0c9d89f0bc5d72ea7ad9248f0302cd37 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 2 Aug 2016 12:34:23 -0700 Subject: [PATCH 01/10] Fix #10083 - allowSyntheticDefaultImports alters getExternalModuleMember (#10096) --- src/compiler/checker.ts | 4 +++ .../allowSyntheticDefaultImports10.errors.txt | 17 +++++++++++ .../allowSyntheticDefaultImports10.js | 17 +++++++++++ .../allowSyntheticDefaultImports7.js | 28 +++++++++++++++++++ .../allowSyntheticDefaultImports7.symbols | 22 +++++++++++++++ .../allowSyntheticDefaultImports7.types | 24 ++++++++++++++++ .../allowSyntheticDefaultImports8.errors.txt | 14 ++++++++++ .../allowSyntheticDefaultImports8.js | 28 +++++++++++++++++++ .../allowSyntheticDefaultImports9.js | 17 +++++++++++ .../allowSyntheticDefaultImports9.symbols | 22 +++++++++++++++ .../allowSyntheticDefaultImports9.types | 24 ++++++++++++++++ .../allowSyntheticDefaultImports10.ts | 11 ++++++++ .../compiler/allowSyntheticDefaultImports7.ts | 10 +++++++ .../compiler/allowSyntheticDefaultImports8.ts | 11 ++++++++ .../compiler/allowSyntheticDefaultImports9.ts | 11 ++++++++ 15 files changed, 260 insertions(+) create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports10.errors.txt create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports10.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports7.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports7.symbols create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports7.types create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports8.errors.txt create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports8.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports9.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports9.symbols create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports9.types create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports10.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports7.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports8.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports9.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a45b61660a1f..c1626ff0b7584 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1135,6 +1135,10 @@ namespace ts { else { symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text); } + // If the export member we're looking for is default, and there is no real default but allowSyntheticDefaultImports is on, return the entire module as the default + if (!symbolFromVariable && allowSyntheticDefaultImports && name.text === "default") { + symbolFromVariable = resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol); + } // if symbolFromVariable is export - get its final target symbolFromVariable = resolveSymbol(symbolFromVariable); const symbolFromModule = getExportOfModule(targetSymbol, name.text); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports10.errors.txt b/tests/baselines/reference/allowSyntheticDefaultImports10.errors.txt new file mode 100644 index 0000000000000..981f89214e2ca --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports10.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/a.ts(2,5): error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'. +tests/cases/compiler/a.ts(3,5): error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'. + + +==== tests/cases/compiler/a.ts (2 errors) ==== + import Foo = require("./b"); + Foo.default.bar(); + ~~~~~~~ +!!! error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'. + Foo.default.default.foo(); + ~~~~~~~ +!!! error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'. +==== tests/cases/compiler/b.d.ts (0 errors) ==== + export function foo(); + + export function bar(); + \ No newline at end of file diff --git a/tests/baselines/reference/allowSyntheticDefaultImports10.js b/tests/baselines/reference/allowSyntheticDefaultImports10.js new file mode 100644 index 0000000000000..746997c4c8941 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports10.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports10.ts] //// + +//// [b.d.ts] +export function foo(); + +export function bar(); + +//// [a.ts] +import Foo = require("./b"); +Foo.default.bar(); +Foo.default.default.foo(); + +//// [a.js] +"use strict"; +var Foo = require("./b"); +Foo.default.bar(); +Foo.default.default.foo(); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports7.js b/tests/baselines/reference/allowSyntheticDefaultImports7.js new file mode 100644 index 0000000000000..51cc63e6e11e7 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports7.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports7.ts] //// + +//// [b.d.ts] +export function foo(); + +export function bar(); + +//// [a.ts] +import { default as Foo } from "./b"; +Foo.bar(); +Foo.foo(); + +//// [a.js] +System.register(["./b"], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var b_1; + return { + setters:[ + function (b_1_1) { + b_1 = b_1_1; + }], + execute: function() { + b_1["default"].bar(); + b_1["default"].foo(); + } + } +}); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports7.symbols b/tests/baselines/reference/allowSyntheticDefaultImports7.symbols new file mode 100644 index 0000000000000..51155dd69dfd8 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports7.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/b.d.ts === +export function foo(); +>foo : Symbol(foo, Decl(b.d.ts, 0, 0)) + +export function bar(); +>bar : Symbol(bar, Decl(b.d.ts, 0, 22)) + +=== tests/cases/compiler/a.ts === +import { default as Foo } from "./b"; +>default : Symbol(Foo, Decl(a.ts, 0, 8)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 8)) + +Foo.bar(); +>Foo.bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 8)) +>bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22)) + +Foo.foo(); +>Foo.foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 8)) +>foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports7.types b/tests/baselines/reference/allowSyntheticDefaultImports7.types new file mode 100644 index 0000000000000..69ce39e6dc6e6 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports7.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/b.d.ts === +export function foo(); +>foo : () => any + +export function bar(); +>bar : () => any + +=== tests/cases/compiler/a.ts === +import { default as Foo } from "./b"; +>default : typeof Foo +>Foo : typeof Foo + +Foo.bar(); +>Foo.bar() : any +>Foo.bar : () => any +>Foo : typeof Foo +>bar : () => any + +Foo.foo(); +>Foo.foo() : any +>Foo.foo : () => any +>Foo : typeof Foo +>foo : () => any + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports8.errors.txt b/tests/baselines/reference/allowSyntheticDefaultImports8.errors.txt new file mode 100644 index 0000000000000..acb584f8fd9e0 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports8.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/a.ts(1,10): error TS2305: Module '"tests/cases/compiler/b"' has no exported member 'default'. + + +==== tests/cases/compiler/b.d.ts (0 errors) ==== + export function foo(); + + export function bar(); + +==== tests/cases/compiler/a.ts (1 errors) ==== + import { default as Foo } from "./b"; + ~~~~~~~ +!!! error TS2305: Module '"tests/cases/compiler/b"' has no exported member 'default'. + Foo.bar(); + Foo.foo(); \ No newline at end of file diff --git a/tests/baselines/reference/allowSyntheticDefaultImports8.js b/tests/baselines/reference/allowSyntheticDefaultImports8.js new file mode 100644 index 0000000000000..3c3c5fa8d28c7 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports8.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports8.ts] //// + +//// [b.d.ts] +export function foo(); + +export function bar(); + +//// [a.ts] +import { default as Foo } from "./b"; +Foo.bar(); +Foo.foo(); + +//// [a.js] +System.register(["./b"], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var b_1; + return { + setters:[ + function (b_1_1) { + b_1 = b_1_1; + }], + execute: function() { + b_1["default"].bar(); + b_1["default"].foo(); + } + } +}); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports9.js b/tests/baselines/reference/allowSyntheticDefaultImports9.js new file mode 100644 index 0000000000000..15810ccaaf703 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports9.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports9.ts] //// + +//// [b.d.ts] +export function foo(); + +export function bar(); + +//// [a.ts] +import { default as Foo } from "./b"; +Foo.bar(); +Foo.foo(); + +//// [a.js] +"use strict"; +var b_1 = require("./b"); +b_1["default"].bar(); +b_1["default"].foo(); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports9.symbols b/tests/baselines/reference/allowSyntheticDefaultImports9.symbols new file mode 100644 index 0000000000000..51155dd69dfd8 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports9.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/b.d.ts === +export function foo(); +>foo : Symbol(foo, Decl(b.d.ts, 0, 0)) + +export function bar(); +>bar : Symbol(bar, Decl(b.d.ts, 0, 22)) + +=== tests/cases/compiler/a.ts === +import { default as Foo } from "./b"; +>default : Symbol(Foo, Decl(a.ts, 0, 8)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 8)) + +Foo.bar(); +>Foo.bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 8)) +>bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22)) + +Foo.foo(); +>Foo.foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 8)) +>foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports9.types b/tests/baselines/reference/allowSyntheticDefaultImports9.types new file mode 100644 index 0000000000000..69ce39e6dc6e6 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports9.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/b.d.ts === +export function foo(); +>foo : () => any + +export function bar(); +>bar : () => any + +=== tests/cases/compiler/a.ts === +import { default as Foo } from "./b"; +>default : typeof Foo +>Foo : typeof Foo + +Foo.bar(); +>Foo.bar() : any +>Foo.bar : () => any +>Foo : typeof Foo +>bar : () => any + +Foo.foo(); +>Foo.foo() : any +>Foo.foo : () => any +>Foo : typeof Foo +>foo : () => any + diff --git a/tests/cases/compiler/allowSyntheticDefaultImports10.ts b/tests/cases/compiler/allowSyntheticDefaultImports10.ts new file mode 100644 index 0000000000000..6b50bae96d8fe --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports10.ts @@ -0,0 +1,11 @@ +// @allowSyntheticDefaultImports: true +// @module: commonjs +// @Filename: b.d.ts +export function foo(); + +export function bar(); + +// @Filename: a.ts +import Foo = require("./b"); +Foo.default.bar(); +Foo.default.default.foo(); \ No newline at end of file diff --git a/tests/cases/compiler/allowSyntheticDefaultImports7.ts b/tests/cases/compiler/allowSyntheticDefaultImports7.ts new file mode 100644 index 0000000000000..2da05e4678c7f --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports7.ts @@ -0,0 +1,10 @@ +// @module: system +// @Filename: b.d.ts +export function foo(); + +export function bar(); + +// @Filename: a.ts +import { default as Foo } from "./b"; +Foo.bar(); +Foo.foo(); \ No newline at end of file diff --git a/tests/cases/compiler/allowSyntheticDefaultImports8.ts b/tests/cases/compiler/allowSyntheticDefaultImports8.ts new file mode 100644 index 0000000000000..3a213ad80235f --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports8.ts @@ -0,0 +1,11 @@ +// @allowSyntheticDefaultImports: false +// @module: system +// @Filename: b.d.ts +export function foo(); + +export function bar(); + +// @Filename: a.ts +import { default as Foo } from "./b"; +Foo.bar(); +Foo.foo(); \ No newline at end of file diff --git a/tests/cases/compiler/allowSyntheticDefaultImports9.ts b/tests/cases/compiler/allowSyntheticDefaultImports9.ts new file mode 100644 index 0000000000000..8da66f33adf56 --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports9.ts @@ -0,0 +1,11 @@ +// @allowSyntheticDefaultImports: true +// @module: commonjs +// @Filename: b.d.ts +export function foo(); + +export function bar(); + +// @Filename: a.ts +import { default as Foo } from "./b"; +Foo.bar(); +Foo.foo(); \ No newline at end of file From 204f2c16c0d6ff851e4798c03a9646b625ac2bd7 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 3 Aug 2016 08:55:55 -0700 Subject: [PATCH 02/10] Add a helper function `getOrUpdateProperty` to prevent unprotected access to Maps. --- src/compiler/core.ts | 10 +++++++--- src/compiler/emitter.ts | 2 +- tests/baselines/reference/exportToString.js | 9 +++++++++ tests/baselines/reference/exportToString.symbols | 7 +++++++ tests/baselines/reference/exportToString.types | 8 ++++++++ tests/cases/compiler/exportToString.ts | 2 ++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/exportToString.js create mode 100644 tests/baselines/reference/exportToString.symbols create mode 100644 tests/baselines/reference/exportToString.types create mode 100644 tests/cases/compiler/exportToString.ts diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 709a331e02281..6c87ad82955c3 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -323,8 +323,12 @@ namespace ts { return keys; } - export function getProperty(map: Map, key: string): T { - return hasOwnProperty.call(map, key) ? map[key] : undefined; + export function getProperty(map: Map, key: string): T | undefined { + return hasProperty(map, key) ? map[key] : undefined; + } + + export function getOrUpdateProperty(map: Map, key: string, makeValue: () => T): T { + return hasProperty(map, key) ? map[key] : map[key] = makeValue(); } export function isEmpty(map: Map) { @@ -941,7 +945,7 @@ namespace ts { * [^./] # matches everything up to the first . character (excluding directory seperators) * (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension */ - const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*"; + const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*"; const singleAsteriskRegexFragmentOther = "[^/]*"; export function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5fe5027978c78..c8bd8072b2400 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6842,7 +6842,7 @@ const _super = (function (geti, seti) { // export { x, y } for (const specifier of (node).exportClause.elements) { const name = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); + getOrUpdateProperty(exportSpecifiers, name, () => []).push(specifier); } } break; diff --git a/tests/baselines/reference/exportToString.js b/tests/baselines/reference/exportToString.js new file mode 100644 index 0000000000000..190d1693c248c --- /dev/null +++ b/tests/baselines/reference/exportToString.js @@ -0,0 +1,9 @@ +//// [exportToString.ts] +const toString = 0; +export { toString }; + + +//// [exportToString.js] +"use strict"; +var toString = 0; +exports.toString = toString; diff --git a/tests/baselines/reference/exportToString.symbols b/tests/baselines/reference/exportToString.symbols new file mode 100644 index 0000000000000..ce5446317a4d5 --- /dev/null +++ b/tests/baselines/reference/exportToString.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/exportToString.ts === +const toString = 0; +>toString : Symbol(toString, Decl(exportToString.ts, 0, 5)) + +export { toString }; +>toString : Symbol(toString, Decl(exportToString.ts, 1, 8)) + diff --git a/tests/baselines/reference/exportToString.types b/tests/baselines/reference/exportToString.types new file mode 100644 index 0000000000000..17037852f3b13 --- /dev/null +++ b/tests/baselines/reference/exportToString.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/exportToString.ts === +const toString = 0; +>toString : number +>0 : number + +export { toString }; +>toString : number + diff --git a/tests/cases/compiler/exportToString.ts b/tests/cases/compiler/exportToString.ts new file mode 100644 index 0000000000000..248df036bfde9 --- /dev/null +++ b/tests/cases/compiler/exportToString.ts @@ -0,0 +1,2 @@ +const toString = 0; +export { toString }; From 7ab6e11aaf5a3c98592555889e34ec4301cd0339 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 3 Aug 2016 10:00:37 -0700 Subject: [PATCH 03/10] Limit type guards as assertions to incomplete types in loops --- src/compiler/checker.ts | 74 +++++++++++++++++++++++++---------------- src/compiler/types.ts | 10 ++++++ 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a45b61660a1f..69c93a75323a3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -215,7 +215,7 @@ namespace ts { const flowLoopKeys: string[] = []; const flowLoopTypes: Type[][] = []; const visitedFlowNodes: FlowNode[] = []; - const visitedFlowTypes: Type[] = []; + const visitedFlowTypes: FlowType[] = []; const potentialThisCollisions: Node[] = []; const awaitedTypeStack: number[] = []; @@ -8086,6 +8086,18 @@ namespace ts { f(type) ? type : neverType; } + function isIncomplete(flowType: FlowType) { + return flowType.flags === 0; + } + + function getTypeFromFlowType(flowType: FlowType) { + return flowType.flags === 0 ? (flowType).type : flowType; + } + + function createFlowType(type: Type, incomplete: boolean): FlowType { + return incomplete ? { flags: 0, type } : type; + } + function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, includeOuterFunctions: boolean) { let key: string; if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) { @@ -8093,14 +8105,14 @@ namespace ts { } const initialType = assumeInitialized ? declaredType : includeFalsyTypes(declaredType, TypeFlags.Undefined); const visitedFlowStart = visitedFlowCount; - const result = getTypeAtFlowNode(reference.flowNode); + const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode)); visitedFlowCount = visitedFlowStart; if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull) === neverType) { return declaredType; } return result; - function getTypeAtFlowNode(flow: FlowNode): Type { + function getTypeAtFlowNode(flow: FlowNode): FlowType { while (true) { if (flow.flags & FlowFlags.Shared) { // We cache results of flow type resolution for shared nodes that were previously visited in @@ -8112,7 +8124,7 @@ namespace ts { } } } - let type: Type; + let type: FlowType; if (flow.flags & FlowFlags.Assignment) { type = getTypeAtFlowAssignment(flow); if (!type) { @@ -8180,41 +8192,44 @@ namespace ts { return undefined; } - function getTypeAtFlowCondition(flow: FlowCondition) { - let type = getTypeAtFlowNode(flow.antecedent); + function getTypeAtFlowCondition(flow: FlowCondition): FlowType { + const flowType = getTypeAtFlowNode(flow.antecedent); + let type = getTypeFromFlowType(flowType); if (type !== neverType) { // If we have an antecedent type (meaning we're reachable in some way), we first - // attempt to narrow the antecedent type. If that produces the nothing type, then - // we take the type guard as an indication that control could reach here in a - // manner not understood by the control flow analyzer (e.g. a function argument - // has an invalid type, or a nested function has possibly made an assignment to a - // captured variable). We proceed by reverting to the declared type and then + // attempt to narrow the antecedent type. If that produces the never type, and if + // the antecedent type is incomplete (i.e. a transient type in a loop), then we + // take the type guard as an indication that control *could* reach here once we + // have the complete type. We proceed by reverting to the declared type and then // narrow that. const assumeTrue = (flow.flags & FlowFlags.TrueCondition) !== 0; type = narrowType(type, flow.expression, assumeTrue); - if (type === neverType) { + if (type === neverType && isIncomplete(flowType)) { type = narrowType(declaredType, flow.expression, assumeTrue); } } - return type; + return createFlowType(type, isIncomplete(flowType)); } - function getTypeAtSwitchClause(flow: FlowSwitchClause) { - const type = getTypeAtFlowNode(flow.antecedent); + function getTypeAtSwitchClause(flow: FlowSwitchClause): FlowType { + const flowType = getTypeAtFlowNode(flow.antecedent); + let type = getTypeFromFlowType(flowType); const expr = flow.switchStatement.expression; if (isMatchingReference(reference, expr)) { - return narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); + type = narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); } - if (isMatchingPropertyAccess(expr)) { - return narrowTypeByDiscriminant(type, expr, t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd)); + else if (isMatchingPropertyAccess(expr)) { + type = narrowTypeByDiscriminant(type, expr, t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd)); } - return type; + return createFlowType(type, isIncomplete(flowType)); } - function getTypeAtFlowBranchLabel(flow: FlowLabel) { + function getTypeAtFlowBranchLabel(flow: FlowLabel): FlowType { const antecedentTypes: Type[] = []; + let seenIncomplete = false; for (const antecedent of flow.antecedents) { - const type = getTypeAtFlowNode(antecedent); + const flowType = getTypeAtFlowNode(antecedent); + const type = getTypeFromFlowType(flowType); // If the type at a particular antecedent path is the declared type and the // reference is known to always be assigned (i.e. when declared and initial types // are the same), there is no reason to process more antecedents since the only @@ -8225,11 +8240,14 @@ namespace ts { if (!contains(antecedentTypes, type)) { antecedentTypes.push(type); } + if (isIncomplete(flowType)) { + seenIncomplete = true; + } } - return getUnionType(antecedentTypes); + return createFlowType(getUnionType(antecedentTypes), seenIncomplete); } - function getTypeAtFlowLoopLabel(flow: FlowLabel) { + function getTypeAtFlowLoopLabel(flow: FlowLabel): FlowType { // If we have previously computed the control flow type for the reference at // this flow loop junction, return the cached type. const id = getFlowNodeId(flow); @@ -8241,12 +8259,12 @@ namespace ts { return cache[key]; } // If this flow loop junction and reference are already being processed, return - // the union of the types computed for each branch so far. We should never see - // an empty array here because the first antecedent of a loop junction is always - // the non-looping control flow path that leads to the top. + // the union of the types computed for each branch so far, marked as incomplete. + // We should never see an empty array here because the first antecedent of a loop + // junction is always the non-looping control flow path that leads to the top. for (let i = flowLoopStart; i < flowLoopCount; i++) { if (flowLoopNodes[i] === flow && flowLoopKeys[i] === key) { - return getUnionType(flowLoopTypes[i]); + return createFlowType(getUnionType(flowLoopTypes[i]), true); } } // Add the flow loop junction and reference to the in-process stack and analyze @@ -8257,7 +8275,7 @@ namespace ts { flowLoopTypes[flowLoopCount] = antecedentTypes; for (const antecedent of flow.antecedents) { flowLoopCount++; - const type = getTypeAtFlowNode(antecedent); + const type = getTypeFromFlowType(getTypeAtFlowNode(antecedent)); flowLoopCount--; // If we see a value appear in the cache it is a sign that control flow analysis // was restarted and completed by checkExpressionCached. We can simply pick up diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 072209aa49640..b9de9ce1635ff 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1606,6 +1606,16 @@ namespace ts { antecedent: FlowNode; } + export type FlowType = Type | IncompleteType; + + // Incomplete types occur during control flow analysis of loops. An IncompleteType + // is distinguished from a regular type by a flags value of zero. Incomplete type + // objects are internal to the getFlowTypeOfRefecence function and never escape it. + export interface IncompleteType { + flags: TypeFlags; // No flags set + type: Type; // The type marked incomplete + } + export interface AmdDependency { path: string; name: string; From 917d18a1ca1b490f1d022aba0a736d23d0e0e07b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 3 Aug 2016 10:05:49 -0700 Subject: [PATCH 04/10] Accept new baselines --- .../reference/stringLiteralTypesAndTuples01.types | 2 +- .../typeGuardTautologicalConsistiency.types | 4 ++-- .../reference/typeGuardTypeOfUndefined.types | 6 +++--- .../baselines/reference/typeGuardsAsAssertions.types | 12 ++++++------ .../reference/typeGuardsInIfStatement.errors.txt | 5 ++++- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/baselines/reference/stringLiteralTypesAndTuples01.types b/tests/baselines/reference/stringLiteralTypesAndTuples01.types index 0900d9fc745af..10a30a6d75c94 100644 --- a/tests/baselines/reference/stringLiteralTypesAndTuples01.types +++ b/tests/baselines/reference/stringLiteralTypesAndTuples01.types @@ -55,5 +55,5 @@ function rawr(dino: RexOrRaptor) { throw "Unexpected " + dino; >"Unexpected " + dino : string >"Unexpected " : string ->dino : "t-rex" +>dino : never } diff --git a/tests/baselines/reference/typeGuardTautologicalConsistiency.types b/tests/baselines/reference/typeGuardTautologicalConsistiency.types index f86a9e66fa285..0a6524dd26f23 100644 --- a/tests/baselines/reference/typeGuardTautologicalConsistiency.types +++ b/tests/baselines/reference/typeGuardTautologicalConsistiency.types @@ -15,7 +15,7 @@ if (typeof stringOrNumber === "number") { >"number" : "number" stringOrNumber; ->stringOrNumber : string +>stringOrNumber : never } } @@ -31,6 +31,6 @@ if (typeof stringOrNumber === "number" && typeof stringOrNumber !== "number") { >"number" : "number" stringOrNumber; ->stringOrNumber : string +>stringOrNumber : never } diff --git a/tests/baselines/reference/typeGuardTypeOfUndefined.types b/tests/baselines/reference/typeGuardTypeOfUndefined.types index 8e9928896a19d..520d045d9e0d1 100644 --- a/tests/baselines/reference/typeGuardTypeOfUndefined.types +++ b/tests/baselines/reference/typeGuardTypeOfUndefined.types @@ -47,7 +47,7 @@ function test2(a: any) { >"boolean" : "boolean" a; ->a : boolean +>a : never } else { a; @@ -129,7 +129,7 @@ function test5(a: boolean | void) { } else { a; ->a : void +>a : never } } else { @@ -188,7 +188,7 @@ function test7(a: boolean | void) { } else { a; ->a : void +>a : never } } diff --git a/tests/baselines/reference/typeGuardsAsAssertions.types b/tests/baselines/reference/typeGuardsAsAssertions.types index 34d3b296a48db..661ce9fbc55b1 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.types +++ b/tests/baselines/reference/typeGuardsAsAssertions.types @@ -193,10 +193,10 @@ function f1() { >x : undefined x; // string | number (guard as assertion) ->x : string | number +>x : never } x; // string | number | undefined ->x : string | number | undefined +>x : undefined } function f2() { @@ -216,10 +216,10 @@ function f2() { >"string" : "string" x; // string (guard as assertion) ->x : string +>x : never } x; // string | undefined ->x : string | undefined +>x : undefined } function f3() { @@ -239,7 +239,7 @@ function f3() { return; } x; // string | number (guard as assertion) ->x : string | number +>x : never } function f4() { @@ -281,7 +281,7 @@ function f5(x: string | number) { >"number" : "number" x; // number (guard as assertion) ->x : number +>x : never } else { x; // string | number diff --git a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt index 984ca454e76af..cd9ae40932ac9 100644 --- a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt +++ b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt @@ -1,9 +1,10 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(22,10): error TS2354: No best common type exists among return expressions. tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(31,10): error TS2354: No best common type exists among return expressions. tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(49,10): error TS2354: No best common type exists among return expressions. +tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(139,17): error TS2339: Property 'toString' does not exist on type 'never'. -==== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts (3 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts (4 errors) ==== // In the true branch statement of an 'if' statement, // the type of a variable or parameter is narrowed by any type guard in the 'if' condition when true. // In the false branch statement of an 'if' statement, @@ -149,5 +150,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(49,10) return typeof x === "number" ? x.toString() // number : x.toString(); // boolean | string + ~~~~~~~~ +!!! error TS2339: Property 'toString' does not exist on type 'never'. } } \ No newline at end of file From 12eb57c4d0d9b1082e8f4e7b459685e5829bac78 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 3 Aug 2016 10:15:00 -0700 Subject: [PATCH 05/10] Fix linting error --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 69c93a75323a3..4e5da63af2f2f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8264,7 +8264,7 @@ namespace ts { // junction is always the non-looping control flow path that leads to the top. for (let i = flowLoopStart; i < flowLoopCount; i++) { if (flowLoopNodes[i] === flow && flowLoopKeys[i] === key) { - return createFlowType(getUnionType(flowLoopTypes[i]), true); + return createFlowType(getUnionType(flowLoopTypes[i]), /*incomplete*/ true); } } // Add the flow loop junction and reference to the in-process stack and analyze From 10b36abc8f85c8a2610fd56f04c81836bcf393a4 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 4 Aug 2016 07:43:54 -0700 Subject: [PATCH 06/10] [Release-2.0] Fix 9662: Visual Studio 2015 with TS2.0 gives incorrect @types path resolution errors (#9867) * Change the shape of the shim layer to support getAutomaticTypeDirectives * Change the key for looking up automatic type-directives * Update baselines from change look-up name of type-directives * Add @currentDirectory into the test * Update baselines * Fix linting error * Address PR: fix spelling mistake * Instead of return path of the type directive names just return type directive names --- src/compiler/program.ts | 19 +++++----- src/compiler/types.ts | 1 + src/services/services.ts | 2 +- src/services/shims.ts | 35 ++++++++++++++++--- .../reference/library-reference-13.trace.json | 2 +- .../reference/library-reference-14.trace.json | 2 +- .../reference/library-reference-15.trace.json | 2 +- .../reference/library-reference-2.trace.json | 2 +- .../reference/library-reference-6.trace.json | 2 +- .../reference/typeReferenceDirectives1.js | 1 - .../typeReferenceDirectives1.symbols | 3 +- .../reference/typeReferenceDirectives1.types | 1 - .../compiler/typeReferenceDirectives1.ts | 2 +- .../compiler/typeReferenceDirectives10.ts | 1 + .../compiler/typeReferenceDirectives11.ts | 1 + .../compiler/typeReferenceDirectives12.ts | 1 + .../compiler/typeReferenceDirectives13.ts | 1 + .../compiler/typeReferenceDirectives2.ts | 1 + .../compiler/typeReferenceDirectives3.ts | 1 + .../compiler/typeReferenceDirectives4.ts | 1 + .../compiler/typeReferenceDirectives5.ts | 1 + .../compiler/typeReferenceDirectives6.ts | 1 + .../compiler/typeReferenceDirectives7.ts | 1 + .../compiler/typeReferenceDirectives8.ts | 1 + .../compiler/typeReferenceDirectives9.ts | 1 + .../references/library-reference-13.ts | 1 + .../conformance/typings/typingsLookup1.ts | 1 + 27 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4b9948c3ba0b4..7d40b2f3219fc 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1055,19 +1055,15 @@ namespace ts { return resolutions; } - function getInferredTypesRoot(options: CompilerOptions, rootFiles: string[], host: CompilerHost) { - return computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), f => host.getCanonicalFileName(f)); - } - /** - * Given a set of options and a set of root files, returns the set of type directive names + * Given a set of options, returns the set of type directive names * that should be included for this program automatically. * This list could either come from the config file, * or from enumerating the types root + initial secondary types lookup location. * More type directives might appear in the program later as a result of loading actual source files; * this list is only the set of defaults that are implicitly included. */ - export function getAutomaticTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[] { + export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[] { // Use explicit type list from tsconfig.json if (options.types) { return options.types; @@ -1080,7 +1076,10 @@ namespace ts { if (typeRoots) { for (const root of typeRoots) { if (host.directoryExists(root)) { - result = result.concat(host.getDirectories(root)); + for (const typeDirectivePath of host.getDirectories(root)) { + // Return just the type directive names + result = result.concat(getBaseFileName(normalizePath(typeDirectivePath))); + } } } } @@ -1155,11 +1154,11 @@ namespace ts { forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false)); // load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders - const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, rootNames, host); + const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, host); if (typeReferences) { - const inferredRoot = getInferredTypesRoot(options, rootNames, host); - const containingFilename = combinePaths(inferredRoot, "__inferred type names__.ts"); + // This containingFilename needs to match with the one used in managed-side + const containingFilename = combinePaths(host.getCurrentDirectory(), "__inferred type names__.ts"); const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename); for (let i = 0; i < typeReferences.length; i++) { processTypeReferenceDirective(typeReferences[i], resolutions[i]); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b9de9ce1635ff..28ededebb0de1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2910,6 +2910,7 @@ namespace ts { directoryExists?(directoryName: string): boolean; realpath?(path: string): string; getCurrentDirectory?(): string; + getDirectories?(path: string): string[]; } export interface ResolvedModule { diff --git a/src/services/services.ts b/src/services/services.ts index 6ec95343e330d..ab1e30a44a607 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1886,7 +1886,7 @@ namespace ts { }; } - // Cache host information about scrip Should be refreshed + // Cache host information about script should be refreshed // at each language service public entry point, since we don't know when // set of scripts handled by the host changes. class HostCache { diff --git a/src/services/shims.ts b/src/services/shims.ts index 271d6f2d6e205..45c4b284ae744 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -72,8 +72,13 @@ namespace ts { directoryExists(directoryName: string): boolean; } - /** Public interface of the the of a config service shim instance.*/ - export interface CoreServicesShimHost extends Logger, ModuleResolutionHost { + /** Public interface of the core-services host instance used in managed side */ + export interface CoreServicesShimHost extends Logger { + directoryExists(directoryName: string): boolean; + fileExists(fileName: string): boolean; + getCurrentDirectory(): string; + getDirectories(path: string): string; + /** * Returns a JSON-encoded value of the type: string[] * @@ -81,9 +86,14 @@ namespace ts { * when enumerating the directory. */ readDirectory(rootDir: string, extension: string, basePaths?: string, excludeEx?: string, includeFileEx?: string, includeDirEx?: string, depth?: number): string; - useCaseSensitiveFileNames?(): boolean; - getCurrentDirectory(): string; + + /** + * Read arbitary text files on disk, i.e. when resolution procedure needs the content of 'package.json' to determine location of bundled typings for node modules + */ + readFile(fileName: string): string; + realpath?(path: string): string; trace(s: string): void; + useCaseSensitiveFileNames?(): boolean; } /// @@ -240,6 +250,7 @@ namespace ts { } export interface CoreServicesShim extends Shim { + getAutomaticTypeDirectiveNames(compilerOptionsJson: string): string; getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string; getTSConfigFileInfo(fileName: string, sourceText: IScriptSnapshot): string; getDefaultCompilationSettings(): string; @@ -492,6 +503,10 @@ namespace ts { private readDirectoryFallback(rootDir: string, extension: string, exclude: string[]) { return JSON.parse(this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude))); } + + public getDirectories(path: string): string[] { + return JSON.parse(this.shimHost.getDirectories(path)); + } } function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): any { @@ -1003,7 +1018,7 @@ namespace ts { public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string { return this.forwardJSONCall( - "getPreProcessedFileInfo('" + fileName + "')", + `getPreProcessedFileInfo('${fileName}')`, () => { // for now treat files as JavaScript const result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()), /* readImportFiles */ true, /* detectJavaScriptImports */ true); @@ -1017,6 +1032,16 @@ namespace ts { }); } + public getAutomaticTypeDirectiveNames(compilerOptionsJson: string): string { + return this.forwardJSONCall( + `getAutomaticTypeDirectiveNames('${compilerOptionsJson}')`, + () => { + const compilerOptions = JSON.parse(compilerOptionsJson); + return getAutomaticTypeDirectiveNames(compilerOptions, this.host); + } + ); + } + private convertFileReferences(refs: FileReference[]): IFileReference[] { if (!refs) { return undefined; diff --git a/tests/baselines/reference/library-reference-13.trace.json b/tests/baselines/reference/library-reference-13.trace.json index d8dfb57c2a66f..a23f0ef0ca56e 100644 --- a/tests/baselines/reference/library-reference-13.trace.json +++ b/tests/baselines/reference/library-reference-13.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/__inferred type names__.ts', root directory '/a/types'. ========", + "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/a/types'. ========", "Resolving with primary search path '/a/types'", "File '/a/types/jquery/package.json' does not exist.", "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-14.trace.json b/tests/baselines/reference/library-reference-14.trace.json index d8dfb57c2a66f..fb3a2bb7da48d 100644 --- a/tests/baselines/reference/library-reference-14.trace.json +++ b/tests/baselines/reference/library-reference-14.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/__inferred type names__.ts', root directory '/a/types'. ========", + "======== Resolving type reference directive 'jquery', containing file '/a/__inferred type names__.ts', root directory '/a/types'. ========", "Resolving with primary search path '/a/types'", "File '/a/types/jquery/package.json' does not exist.", "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-15.trace.json b/tests/baselines/reference/library-reference-15.trace.json index 3e9d7dba1d21d..e23517976b0e4 100644 --- a/tests/baselines/reference/library-reference-15.trace.json +++ b/tests/baselines/reference/library-reference-15.trace.json @@ -1,5 +1,5 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/__inferred type names__.ts', root directory 'types'. ========", + "======== Resolving type reference directive 'jquery', containing file '/a/__inferred type names__.ts', root directory 'types'. ========", "Resolving with primary search path 'types'", "File 'types/jquery/package.json' does not exist.", "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-2.trace.json b/tests/baselines/reference/library-reference-2.trace.json index c26f7d2763d7f..64cdd8091832f 100644 --- a/tests/baselines/reference/library-reference-2.trace.json +++ b/tests/baselines/reference/library-reference-2.trace.json @@ -5,7 +5,7 @@ "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", "File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/jquery.d.ts', primary: true. ========", - "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "======== Resolving type reference directive 'jquery', containing file 'test/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", "Found 'package.json' at '/types/jquery/package.json'.", "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index 48fb49e6c7fb9..fd83c1431b438 100644 --- a/tests/baselines/reference/library-reference-6.trace.json +++ b/tests/baselines/reference/library-reference-6.trace.json @@ -4,7 +4,7 @@ "File '/node_modules/@types/alpha/package.json' does not exist.", "File '/node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/@types/alpha/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'alpha', containing file '/src/__inferred type names__.ts', root directory '/node_modules/@types'. ========", + "======== Resolving type reference directive 'alpha', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/alpha/package.json' does not exist.", "File '/node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/typeReferenceDirectives1.js b/tests/baselines/reference/typeReferenceDirectives1.js index 775af9c5283f3..a621081993126 100644 --- a/tests/baselines/reference/typeReferenceDirectives1.js +++ b/tests/baselines/reference/typeReferenceDirectives1.js @@ -2,7 +2,6 @@ //// [index.d.ts] - interface $ { x } //// [app.ts] diff --git a/tests/baselines/reference/typeReferenceDirectives1.symbols b/tests/baselines/reference/typeReferenceDirectives1.symbols index 55c17b219ecaa..a33a2aba4082d 100644 --- a/tests/baselines/reference/typeReferenceDirectives1.symbols +++ b/tests/baselines/reference/typeReferenceDirectives1.symbols @@ -9,8 +9,7 @@ interface A { } === /types/lib/index.d.ts === - interface $ { x } >$ : Symbol($, Decl(index.d.ts, 0, 0)) ->x : Symbol($.x, Decl(index.d.ts, 2, 13)) +>x : Symbol($.x, Decl(index.d.ts, 1, 13)) diff --git a/tests/baselines/reference/typeReferenceDirectives1.types b/tests/baselines/reference/typeReferenceDirectives1.types index 05080e05651dd..be789a08ddc5c 100644 --- a/tests/baselines/reference/typeReferenceDirectives1.types +++ b/tests/baselines/reference/typeReferenceDirectives1.types @@ -9,7 +9,6 @@ interface A { } === /types/lib/index.d.ts === - interface $ { x } >$ : $ >x : any diff --git a/tests/cases/compiler/typeReferenceDirectives1.ts b/tests/cases/compiler/typeReferenceDirectives1.ts index e17e498b9784d..13c84c7ae5e9b 100644 --- a/tests/cases/compiler/typeReferenceDirectives1.ts +++ b/tests/cases/compiler/typeReferenceDirectives1.ts @@ -2,7 +2,7 @@ // @traceResolution: true // @declaration: true // @typeRoots: /types - +// @currentDirectory: / // @filename: /types/lib/index.d.ts interface $ { x } diff --git a/tests/cases/compiler/typeReferenceDirectives10.ts b/tests/cases/compiler/typeReferenceDirectives10.ts index 61971ba44b2ad..1eb796d03fd25 100644 --- a/tests/cases/compiler/typeReferenceDirectives10.ts +++ b/tests/cases/compiler/typeReferenceDirectives10.ts @@ -2,6 +2,7 @@ // @declaration: true // @typeRoots: /types // @traceResolution: true +// @currentDirectory: / // @filename: /ref.d.ts export interface $ { x } diff --git a/tests/cases/compiler/typeReferenceDirectives11.ts b/tests/cases/compiler/typeReferenceDirectives11.ts index 2d93e22bdcf23..8b56459cd697f 100644 --- a/tests/cases/compiler/typeReferenceDirectives11.ts +++ b/tests/cases/compiler/typeReferenceDirectives11.ts @@ -4,6 +4,7 @@ // @traceResolution: true // @types: lib // @out: output.js +// @currentDirectory: / // @filename: /types/lib/index.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives12.ts b/tests/cases/compiler/typeReferenceDirectives12.ts index efdb1e8312b6f..f1abe27f05f36 100644 --- a/tests/cases/compiler/typeReferenceDirectives12.ts +++ b/tests/cases/compiler/typeReferenceDirectives12.ts @@ -3,6 +3,7 @@ // @typeRoots: /types // @traceResolution: true // @out: output.js +// @currentDirectory: / // @filename: /types/lib/index.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives13.ts b/tests/cases/compiler/typeReferenceDirectives13.ts index 124c31274ace4..f9dede73267bd 100644 --- a/tests/cases/compiler/typeReferenceDirectives13.ts +++ b/tests/cases/compiler/typeReferenceDirectives13.ts @@ -2,6 +2,7 @@ // @declaration: true // @typeRoots: /types // @traceResolution: true +// @currentDirectory: / // @filename: /ref.d.ts export interface $ { x } diff --git a/tests/cases/compiler/typeReferenceDirectives2.ts b/tests/cases/compiler/typeReferenceDirectives2.ts index 31a01a0b8e4bc..44218683a5a99 100644 --- a/tests/cases/compiler/typeReferenceDirectives2.ts +++ b/tests/cases/compiler/typeReferenceDirectives2.ts @@ -3,6 +3,7 @@ // @declaration: true // @typeRoots: /types // @types: lib +// @currentDirectory: / // @filename: /types/lib/index.d.ts interface $ { x } diff --git a/tests/cases/compiler/typeReferenceDirectives3.ts b/tests/cases/compiler/typeReferenceDirectives3.ts index 4c2729ab389b3..1baf0bdac9d28 100644 --- a/tests/cases/compiler/typeReferenceDirectives3.ts +++ b/tests/cases/compiler/typeReferenceDirectives3.ts @@ -2,6 +2,7 @@ // @declaration: true // @typeRoots: /types // @traceResolution: true +// @currentDirectory: / // $ comes from d.ts file - no need to add type reference directive diff --git a/tests/cases/compiler/typeReferenceDirectives4.ts b/tests/cases/compiler/typeReferenceDirectives4.ts index ac7346895ef7d..dfa87b651387b 100644 --- a/tests/cases/compiler/typeReferenceDirectives4.ts +++ b/tests/cases/compiler/typeReferenceDirectives4.ts @@ -2,6 +2,7 @@ // @traceResolution: true // @declaration: true // @typeRoots: /types +// @currentDirectory: / // $ comes from d.ts file - no need to add type reference directive diff --git a/tests/cases/compiler/typeReferenceDirectives5.ts b/tests/cases/compiler/typeReferenceDirectives5.ts index bb24b82b32466..e81ae663e24f6 100644 --- a/tests/cases/compiler/typeReferenceDirectives5.ts +++ b/tests/cases/compiler/typeReferenceDirectives5.ts @@ -2,6 +2,7 @@ // @traceResolution: true // @declaration: true // @typeRoots: /types +// @currentDirectory: / // @filename: /ref.d.ts export interface $ { x } diff --git a/tests/cases/compiler/typeReferenceDirectives6.ts b/tests/cases/compiler/typeReferenceDirectives6.ts index 7154963f1efa3..edf2ece7e06dc 100644 --- a/tests/cases/compiler/typeReferenceDirectives6.ts +++ b/tests/cases/compiler/typeReferenceDirectives6.ts @@ -2,6 +2,7 @@ // @traceResolution: true // @declaration: true // @typeRoots: /types +// @currentDirectory: / // $ comes from type declaration file - type reference directive should be added diff --git a/tests/cases/compiler/typeReferenceDirectives7.ts b/tests/cases/compiler/typeReferenceDirectives7.ts index 79d42fa701853..e9335b0708209 100644 --- a/tests/cases/compiler/typeReferenceDirectives7.ts +++ b/tests/cases/compiler/typeReferenceDirectives7.ts @@ -2,6 +2,7 @@ // @traceResolution: true // @declaration: true // @typeRoots: /types +// @currentDirectory: / // local value shadows global - no need to add type reference directive diff --git a/tests/cases/compiler/typeReferenceDirectives8.ts b/tests/cases/compiler/typeReferenceDirectives8.ts index c7725a3aab1ab..bed69cbf35739 100644 --- a/tests/cases/compiler/typeReferenceDirectives8.ts +++ b/tests/cases/compiler/typeReferenceDirectives8.ts @@ -3,6 +3,7 @@ // @typeRoots: /types // @traceResolution: true // @types: lib +// @currentDirectory: / // @filename: /types/lib/index.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives9.ts b/tests/cases/compiler/typeReferenceDirectives9.ts index 610c7173c898b..1ad1aa522885b 100644 --- a/tests/cases/compiler/typeReferenceDirectives9.ts +++ b/tests/cases/compiler/typeReferenceDirectives9.ts @@ -2,6 +2,7 @@ // @declaration: true // @typeRoots: /types // @traceResolution: true +// @currentDirectory: / // @filename: /types/lib/index.d.ts diff --git a/tests/cases/conformance/references/library-reference-13.ts b/tests/cases/conformance/references/library-reference-13.ts index 92b4b259ba4a9..419643d9d0d90 100644 --- a/tests/cases/conformance/references/library-reference-13.ts +++ b/tests/cases/conformance/references/library-reference-13.ts @@ -1,5 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true +// @currentDirectory: / // load type declarations from types section of tsconfig diff --git a/tests/cases/conformance/typings/typingsLookup1.ts b/tests/cases/conformance/typings/typingsLookup1.ts index 555d4569af34d..150deef992ac1 100644 --- a/tests/cases/conformance/typings/typingsLookup1.ts +++ b/tests/cases/conformance/typings/typingsLookup1.ts @@ -1,5 +1,6 @@ // @traceResolution: true // @noImplicitReferences: true +// @currentDirectory: / // @filename: /tsconfig.json { "files": "a.ts" } From 18fb33d36fbac6d296b4e7d9a94beb29b57de607 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 4 Aug 2016 08:11:42 -0700 Subject: [PATCH 07/10] Remove unused reference files: these tests produce erros so they will not produce these files (#9233) From 9947ac2ecefcd343b6ebc40b9614c1dfcf76b666 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 4 Aug 2016 14:13:07 -0700 Subject: [PATCH 08/10] Don't allow properties inherited from Object to be automatically included in TSX attributes --- src/compiler/checker.ts | 4 ++-- .../baselines/reference/tsxAttributeResolution5.errors.txt | 7 +++++-- tests/baselines/reference/tsxAttributeResolution5.js | 4 ++-- tests/cases/conformance/jsx/tsxAttributeResolution5.tsx | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0599eb4bbbc60..84d5cd08a2bb1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10060,7 +10060,7 @@ namespace ts { for (const prop of props) { // Is there a corresponding property in the element attributes type? Skip checking of properties // that have already been assigned to, as these are not actually pushed into the resulting type - if (!nameTable[prop.name]) { + if (!hasProperty(nameTable, prop.name)) { const targetPropSym = getPropertyOfType(elementAttributesType, prop.name); if (targetPropSym) { const msg = chainDiagnosticMessages(undefined, Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property, prop.name); @@ -10406,7 +10406,7 @@ namespace ts { const targetProperties = getPropertiesOfType(targetAttributesType); for (let i = 0; i < targetProperties.length; i++) { if (!(targetProperties[i].flags & SymbolFlags.Optional) && - nameTable[targetProperties[i].name] === undefined) { + !hasProperty(nameTable, targetProperties[i].name)) { error(node, Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType)); } diff --git a/tests/baselines/reference/tsxAttributeResolution5.errors.txt b/tests/baselines/reference/tsxAttributeResolution5.errors.txt index d7aa46bc05ace..42dabc741ab92 100644 --- a/tests/baselines/reference/tsxAttributeResolution5.errors.txt +++ b/tests/baselines/reference/tsxAttributeResolution5.errors.txt @@ -2,9 +2,10 @@ tests/cases/conformance/jsx/file.tsx(21,16): error TS2606: Property 'x' of JSX s Type 'number' is not assignable to type 'string'. tests/cases/conformance/jsx/file.tsx(25,9): error TS2324: Property 'x' is missing in type 'Attribs1'. tests/cases/conformance/jsx/file.tsx(29,1): error TS2324: Property 'x' is missing in type 'Attribs1'. +tests/cases/conformance/jsx/file.tsx(30,1): error TS2324: Property 'toString' is missing in type 'Attribs2'. -==== tests/cases/conformance/jsx/file.tsx (3 errors) ==== +==== tests/cases/conformance/jsx/file.tsx (4 errors) ==== declare module JSX { interface Element { } interface IntrinsicElements { @@ -41,5 +42,7 @@ tests/cases/conformance/jsx/file.tsx(29,1): error TS2324: Property 'x' is missin ; // Error, missing x ~~~~~~~~~~~~~~~~~ !!! error TS2324: Property 'x' is missing in type 'Attribs1'. - ; // OK + ; // Error, missing toString + ~~~~~~~~~~~~~~~~~ +!!! error TS2324: Property 'toString' is missing in type 'Attribs2'. \ No newline at end of file diff --git a/tests/baselines/reference/tsxAttributeResolution5.js b/tests/baselines/reference/tsxAttributeResolution5.js index abfb54e000c7e..4bde09074b552 100644 --- a/tests/baselines/reference/tsxAttributeResolution5.js +++ b/tests/baselines/reference/tsxAttributeResolution5.js @@ -28,7 +28,7 @@ function make3 (obj: T) { ; // Error, missing x -; // OK +; // Error, missing toString //// [file.jsx] @@ -42,4 +42,4 @@ function make3(obj) { return ; // Error, missing x } ; // Error, missing x -; // OK +; // Error, missing toString diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution5.tsx b/tests/cases/conformance/jsx/tsxAttributeResolution5.tsx index dd16ade10e31e..83fb7b32f5620 100644 --- a/tests/cases/conformance/jsx/tsxAttributeResolution5.tsx +++ b/tests/cases/conformance/jsx/tsxAttributeResolution5.tsx @@ -29,4 +29,4 @@ function make3 (obj: T) { ; // Error, missing x -; // OK +; // Error, missing toString From ceab31cf0db3eb0b5e96559c1f5e77c9328e58aa Mon Sep 17 00:00:00 2001 From: Yui Date: Fri, 5 Aug 2016 10:12:01 -0700 Subject: [PATCH 09/10] Port PR #10016 to Master (#10100) * Treat namespaceExportDeclaration as declaration * Update baselines * wip - add tests * Add tests * Show "export namespace" for quick-info --- src/compiler/checker.ts | 3 ++- src/compiler/utilities.ts | 1 + src/services/services.ts | 9 ++++++++- .../reference/umd-augmentation-1.symbols | 1 + .../reference/umd-augmentation-1.types | 2 +- .../reference/umd-augmentation-2.symbols | 1 + .../reference/umd-augmentation-2.types | 2 +- .../reference/umd-augmentation-3.symbols | 1 + .../reference/umd-augmentation-3.types | 2 +- .../reference/umd-augmentation-4.symbols | 1 + .../reference/umd-augmentation-4.types | 2 +- tests/baselines/reference/umd1.symbols | 1 + tests/baselines/reference/umd1.types | 2 +- tests/baselines/reference/umd3.symbols | 1 + tests/baselines/reference/umd3.types | 2 +- tests/baselines/reference/umd4.symbols | 1 + tests/baselines/reference/umd4.types | 2 +- tests/baselines/reference/umd6.symbols | 1 + tests/baselines/reference/umd6.types | 2 +- tests/baselines/reference/umd7.symbols | 1 + tests/baselines/reference/umd7.types | 2 +- tests/baselines/reference/umd8.symbols | 1 + tests/baselines/reference/umd8.types | 2 +- .../fourslash/findAllRefsForUMDModuleAlias1.ts | 13 +++++++++++++ .../fourslash/quickInfoForUMDModuleAlias.ts | 17 +++++++++++++++++ tests/cases/fourslash/renameAlias.ts | 8 ++++---- tests/cases/fourslash/renameUMDModuleAlias1.ts | 17 +++++++++++++++++ tests/cases/fourslash/renameUMDModuleAlias2.ts | 14 ++++++++++++++ 28 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts create mode 100644 tests/cases/fourslash/quickInfoForUMDModuleAlias.ts create mode 100644 tests/cases/fourslash/renameUMDModuleAlias1.ts create mode 100644 tests/cases/fourslash/renameUMDModuleAlias2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 84d5cd08a2bb1..9583fadba6230 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19691,7 +19691,7 @@ namespace ts { } function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean { - // A declare modifier is required for any top level .d.ts declaration except export=, export default, + // A declare modifier is required for any top level .d.ts declaration except export=, export default, export as namespace // interfaces and imports categories: // // DeclarationElement: @@ -19709,6 +19709,7 @@ namespace ts { node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration || node.kind === SyntaxKind.ExportAssignment || + node.kind === SyntaxKind.NamespaceExportDeclaration || (node.flags & NodeFlags.Ambient) || (node.flags & (NodeFlags.Export | NodeFlags.Default))) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4ae0005e9c5e7..2cfaf1f5cfbc4 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1569,6 +1569,7 @@ namespace ts { case SyntaxKind.MethodSignature: case SyntaxKind.ModuleDeclaration: case SyntaxKind.NamespaceImport: + case SyntaxKind.NamespaceExportDeclaration: case SyntaxKind.Parameter: case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index ab1e30a44a607..aea4d5f872e03 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4830,7 +4830,14 @@ namespace ts { } if (symbolFlags & SymbolFlags.Alias) { addNewLineIfDisplayPartsExist(); - displayParts.push(keywordPart(SyntaxKind.ImportKeyword)); + if (symbol.declarations[0].kind === SyntaxKind.NamespaceExportDeclaration) { + displayParts.push(keywordPart(SyntaxKind.ExportKeyword)); + displayParts.push(spacePart()); + displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword)); + } + else { + displayParts.push(keywordPart(SyntaxKind.ImportKeyword)); + } displayParts.push(spacePart()); addFullSymbolName(symbol); ts.forEach(symbol.declarations, declaration => { diff --git a/tests/baselines/reference/umd-augmentation-1.symbols b/tests/baselines/reference/umd-augmentation-1.symbols index 645511350a91c..70715649894c1 100644 --- a/tests/baselines/reference/umd-augmentation-1.symbols +++ b/tests/baselines/reference/umd-augmentation-1.symbols @@ -39,6 +39,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; +>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0)) export interface Point { >Point : Symbol(Point, Decl(index.d.ts, 1, 27)) diff --git a/tests/baselines/reference/umd-augmentation-1.types b/tests/baselines/reference/umd-augmentation-1.types index 31ac43fe85557..59b577141e055 100644 --- a/tests/baselines/reference/umd-augmentation-1.types +++ b/tests/baselines/reference/umd-augmentation-1.types @@ -48,7 +48,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; ->Math2d : any +>Math2d : typeof Math2d export interface Point { >Point : Point diff --git a/tests/baselines/reference/umd-augmentation-2.symbols b/tests/baselines/reference/umd-augmentation-2.symbols index bd6584d3d7473..a31ed61d531e9 100644 --- a/tests/baselines/reference/umd-augmentation-2.symbols +++ b/tests/baselines/reference/umd-augmentation-2.symbols @@ -37,6 +37,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; +>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0)) export interface Point { >Point : Symbol(Point, Decl(index.d.ts, 1, 27)) diff --git a/tests/baselines/reference/umd-augmentation-2.types b/tests/baselines/reference/umd-augmentation-2.types index 20bba09190314..24fe6df3c3cc5 100644 --- a/tests/baselines/reference/umd-augmentation-2.types +++ b/tests/baselines/reference/umd-augmentation-2.types @@ -46,7 +46,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; ->Math2d : any +>Math2d : typeof Math2d export interface Point { >Point : Point diff --git a/tests/baselines/reference/umd-augmentation-3.symbols b/tests/baselines/reference/umd-augmentation-3.symbols index 3193e83cd1979..3e2df7c8a89ac 100644 --- a/tests/baselines/reference/umd-augmentation-3.symbols +++ b/tests/baselines/reference/umd-augmentation-3.symbols @@ -39,6 +39,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; +>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0)) export = M2D; >M2D : Symbol(M2D, Decl(index.d.ts, 3, 13)) diff --git a/tests/baselines/reference/umd-augmentation-3.types b/tests/baselines/reference/umd-augmentation-3.types index 854ebceff379c..39bc28cbd2451 100644 --- a/tests/baselines/reference/umd-augmentation-3.types +++ b/tests/baselines/reference/umd-augmentation-3.types @@ -48,7 +48,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; ->Math2d : any +>Math2d : typeof Math2d export = M2D; >M2D : typeof M2D diff --git a/tests/baselines/reference/umd-augmentation-4.symbols b/tests/baselines/reference/umd-augmentation-4.symbols index 3f2cc913d8610..7be5d278bf26d 100644 --- a/tests/baselines/reference/umd-augmentation-4.symbols +++ b/tests/baselines/reference/umd-augmentation-4.symbols @@ -37,6 +37,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; +>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0)) export = M2D; >M2D : Symbol(M2D, Decl(index.d.ts, 3, 13)) diff --git a/tests/baselines/reference/umd-augmentation-4.types b/tests/baselines/reference/umd-augmentation-4.types index 71783d0301260..246270aa5a60f 100644 --- a/tests/baselines/reference/umd-augmentation-4.types +++ b/tests/baselines/reference/umd-augmentation-4.types @@ -46,7 +46,7 @@ var t = p.x; === tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts === export as namespace Math2d; ->Math2d : any +>Math2d : typeof Math2d export = M2D; >M2D : typeof M2D diff --git a/tests/baselines/reference/umd1.symbols b/tests/baselines/reference/umd1.symbols index 9b964456bcf02..0307a9b78d375 100644 --- a/tests/baselines/reference/umd1.symbols +++ b/tests/baselines/reference/umd1.symbols @@ -30,4 +30,5 @@ export interface Thing { n: typeof x } >x : Symbol(x, Decl(foo.d.ts, 1, 10)) export as namespace Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38)) diff --git a/tests/baselines/reference/umd1.types b/tests/baselines/reference/umd1.types index 1767f3b5a899d..1379bba8d5d1c 100644 --- a/tests/baselines/reference/umd1.types +++ b/tests/baselines/reference/umd1.types @@ -31,5 +31,5 @@ export interface Thing { n: typeof x } >x : number export as namespace Foo; ->Foo : any +>Foo : typeof Foo diff --git a/tests/baselines/reference/umd3.symbols b/tests/baselines/reference/umd3.symbols index 165fd81597aba..c1fd3d6d74fbc 100644 --- a/tests/baselines/reference/umd3.symbols +++ b/tests/baselines/reference/umd3.symbols @@ -32,4 +32,5 @@ export interface Thing { n: typeof x } >x : Symbol(x, Decl(foo.d.ts, 1, 10)) export as namespace Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38)) diff --git a/tests/baselines/reference/umd3.types b/tests/baselines/reference/umd3.types index 85ee6bafe5ec1..23149e58d76cc 100644 --- a/tests/baselines/reference/umd3.types +++ b/tests/baselines/reference/umd3.types @@ -33,5 +33,5 @@ export interface Thing { n: typeof x } >x : number export as namespace Foo; ->Foo : any +>Foo : typeof Foo diff --git a/tests/baselines/reference/umd4.symbols b/tests/baselines/reference/umd4.symbols index 8403187198bf3..d266997770bd3 100644 --- a/tests/baselines/reference/umd4.symbols +++ b/tests/baselines/reference/umd4.symbols @@ -32,4 +32,5 @@ export interface Thing { n: typeof x } >x : Symbol(x, Decl(foo.d.ts, 1, 10)) export as namespace Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38)) diff --git a/tests/baselines/reference/umd4.types b/tests/baselines/reference/umd4.types index 579599f56619b..18794258517d3 100644 --- a/tests/baselines/reference/umd4.types +++ b/tests/baselines/reference/umd4.types @@ -33,5 +33,5 @@ export interface Thing { n: typeof x } >x : number export as namespace Foo; ->Foo : any +>Foo : typeof Foo diff --git a/tests/baselines/reference/umd6.symbols b/tests/baselines/reference/umd6.symbols index d08507f1ea2e7..958875b79ebd3 100644 --- a/tests/baselines/reference/umd6.symbols +++ b/tests/baselines/reference/umd6.symbols @@ -18,4 +18,5 @@ export = Thing; >Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0)) export as namespace Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 4, 15)) diff --git a/tests/baselines/reference/umd6.types b/tests/baselines/reference/umd6.types index 7318a43057a4e..5b1469cbd6c3c 100644 --- a/tests/baselines/reference/umd6.types +++ b/tests/baselines/reference/umd6.types @@ -19,5 +19,5 @@ export = Thing; >Thing : typeof Thing export as namespace Foo; ->Foo : any +>Foo : typeof Thing diff --git a/tests/baselines/reference/umd7.symbols b/tests/baselines/reference/umd7.symbols index 0b3ef17fb7b72..19b56ed30f3ba 100644 --- a/tests/baselines/reference/umd7.symbols +++ b/tests/baselines/reference/umd7.symbols @@ -13,4 +13,5 @@ export = Thing; >Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0)) export as namespace Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 2, 15)) diff --git a/tests/baselines/reference/umd7.types b/tests/baselines/reference/umd7.types index 60782543710bc..d83e039b674e1 100644 --- a/tests/baselines/reference/umd7.types +++ b/tests/baselines/reference/umd7.types @@ -14,5 +14,5 @@ export = Thing; >Thing : () => number export as namespace Foo; ->Foo : any +>Foo : () => number diff --git a/tests/baselines/reference/umd8.symbols b/tests/baselines/reference/umd8.symbols index 8c38f267a2ae9..97da693b38f12 100644 --- a/tests/baselines/reference/umd8.symbols +++ b/tests/baselines/reference/umd8.symbols @@ -22,4 +22,5 @@ export = Thing; >Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0)) export as namespace Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 4, 15)) diff --git a/tests/baselines/reference/umd8.types b/tests/baselines/reference/umd8.types index 0e66a49b9630e..ae3bdfd5fc89e 100644 --- a/tests/baselines/reference/umd8.types +++ b/tests/baselines/reference/umd8.types @@ -23,5 +23,5 @@ export = Thing; >Thing : Thing export as namespace Foo; ->Foo : any +>Foo : typeof Thing diff --git a/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts b/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts new file mode 100644 index 0000000000000..4177e154532b8 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts @@ -0,0 +1,13 @@ +/// + +// @Filename: 0.d.ts +//// export function doThing(): string; +//// export function doTheOtherThing(): void; + +//// export as namespace [|myLib|]; + +// @Filename: 1.ts +//// /// +//// [|myLib|].doThing(); + +verify.rangesReferenceEachOther(); diff --git a/tests/cases/fourslash/quickInfoForUMDModuleAlias.ts b/tests/cases/fourslash/quickInfoForUMDModuleAlias.ts new file mode 100644 index 0000000000000..085ea33b87446 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForUMDModuleAlias.ts @@ -0,0 +1,17 @@ +/// + +// @Filename: 0.d.ts +//// export function doThing(): string; +//// export function doTheOtherThing(): void; + +//// export as namespace /*0*/myLib; + +// @Filename: 1.ts +//// /// +//// /*1*/myLib.doThing(); + +goTo.marker("0"); +verify.quickInfoIs("export namespace myLib"); + +goTo.marker("1"); +verify.quickInfoIs("export namespace myLib"); diff --git a/tests/cases/fourslash/renameAlias.ts b/tests/cases/fourslash/renameAlias.ts index e3f57ac7b4182..e0408af656fc3 100644 --- a/tests/cases/fourslash/renameAlias.ts +++ b/tests/cases/fourslash/renameAlias.ts @@ -4,8 +4,8 @@ ////import [|M|] = SomeModule; ////import C = [|M|].SomeClass; -let ranges = test.ranges() -for (let range of ranges) { - goTo.position(range.start); - verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); } \ No newline at end of file diff --git a/tests/cases/fourslash/renameUMDModuleAlias1.ts b/tests/cases/fourslash/renameUMDModuleAlias1.ts new file mode 100644 index 0000000000000..94aabcdbde522 --- /dev/null +++ b/tests/cases/fourslash/renameUMDModuleAlias1.ts @@ -0,0 +1,17 @@ +/// + +// @Filename: 0.d.ts +//// export function doThing(): string; +//// export function doTheOtherThing(): void; + +//// export as namespace [|myLib|]; + +// @Filename: 1.ts +//// /// +//// [|myLib|].doThing(); + +const ranges = test.ranges() +for (const range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameUMDModuleAlias2.ts b/tests/cases/fourslash/renameUMDModuleAlias2.ts new file mode 100644 index 0000000000000..0daa4087b0d61 --- /dev/null +++ b/tests/cases/fourslash/renameUMDModuleAlias2.ts @@ -0,0 +1,14 @@ +/// + +// @Filename: 0.d.ts +//// export function doThing(): string; +//// export function doTheOtherThing(): void; + +//// export as namespace /**/[|myLib|]; + +// @Filename: 1.ts +//// /// +//// myLib.doThing(); + +goTo.marker(); +verify.renameInfoSucceeded("myLib"); \ No newline at end of file From 578a666d11afc079960e78c2bad5e19830618dbb Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 5 Aug 2016 15:09:38 -0700 Subject: [PATCH 10/10] Update baselines from merging --- .../allowSyntheticDefaultImports7.js | 11 +- .../allowSyntheticDefaultImports8.js | 11 +- .../discriminatedUnionTypes1.symbols | 402 --------------- .../reference/discriminatedUnionTypes1.types | 465 ------------------ 4 files changed, 12 insertions(+), 877 deletions(-) delete mode 100644 tests/baselines/reference/discriminatedUnionTypes1.symbols delete mode 100644 tests/baselines/reference/discriminatedUnionTypes1.types diff --git a/tests/baselines/reference/allowSyntheticDefaultImports7.js b/tests/baselines/reference/allowSyntheticDefaultImports7.js index 51cc63e6e11e7..6d0ea5b3be07a 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports7.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports7.js @@ -11,18 +11,19 @@ Foo.bar(); Foo.foo(); //// [a.js] -System.register(["./b"], function(exports_1, context_1) { +System.register(["./b"], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var b_1; return { - setters:[ + setters: [ function (b_1_1) { b_1 = b_1_1; - }], - execute: function() { + } + ], + execute: function () { b_1["default"].bar(); b_1["default"].foo(); } - } + }; }); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports8.js b/tests/baselines/reference/allowSyntheticDefaultImports8.js index 3c3c5fa8d28c7..5a77e51e6a241 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports8.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports8.js @@ -11,18 +11,19 @@ Foo.bar(); Foo.foo(); //// [a.js] -System.register(["./b"], function(exports_1, context_1) { +System.register(["./b"], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var b_1; return { - setters:[ + setters: [ function (b_1_1) { b_1 = b_1_1; - }], - execute: function() { + } + ], + execute: function () { b_1["default"].bar(); b_1["default"].foo(); } - } + }; }); diff --git a/tests/baselines/reference/discriminatedUnionTypes1.symbols b/tests/baselines/reference/discriminatedUnionTypes1.symbols deleted file mode 100644 index 380694474239a..0000000000000 --- a/tests/baselines/reference/discriminatedUnionTypes1.symbols +++ /dev/null @@ -1,402 +0,0 @@ -=== tests/cases/conformance/types/union/discriminatedUnionTypes1.ts === -interface Square { ->Square : Symbol(Square, Decl(discriminatedUnionTypes1.ts, 0, 0)) - - kind: "square"; ->kind : Symbol(Square.kind, Decl(discriminatedUnionTypes1.ts, 0, 18)) - - size: number; ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) -} - -interface Rectangle { ->Rectangle : Symbol(Rectangle, Decl(discriminatedUnionTypes1.ts, 3, 1)) - - kind: "rectangle"; ->kind : Symbol(Rectangle.kind, Decl(discriminatedUnionTypes1.ts, 5, 21)) - - width: number; ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) - - height: number; ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) -} - -interface Circle { ->Circle : Symbol(Circle, Decl(discriminatedUnionTypes1.ts, 9, 1)) - - kind: "circle"; ->kind : Symbol(Circle.kind, Decl(discriminatedUnionTypes1.ts, 11, 18)) - - radius: number; ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) -} - -type Shape = Square | Rectangle | Circle; ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) ->Square : Symbol(Square, Decl(discriminatedUnionTypes1.ts, 0, 0)) ->Rectangle : Symbol(Rectangle, Decl(discriminatedUnionTypes1.ts, 3, 1)) ->Circle : Symbol(Circle, Decl(discriminatedUnionTypes1.ts, 9, 1)) - -function area1(s: Shape) { ->area1 : Symbol(area1, Decl(discriminatedUnionTypes1.ts, 16, 41)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - if (s.kind === "square") { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - } - else if (s.kind === "circle") { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - } - else if (s.kind === "rectangle") { ->s.kind : Symbol(Rectangle.kind, Decl(discriminatedUnionTypes1.ts, 5, 21)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->kind : Symbol(Rectangle.kind, Decl(discriminatedUnionTypes1.ts, 5, 21)) - - return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - } - else { - return 0; - } -} - -function area2(s: Shape) { ->area2 : Symbol(area2, Decl(discriminatedUnionTypes1.ts, 31, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - switch (s.kind) { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - case "square": return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - - case "rectangle": return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - - case "circle": return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - } -} - -function assertNever(x: never): never { ->assertNever : Symbol(assertNever, Decl(discriminatedUnionTypes1.ts, 39, 1)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 41, 21)) - - throw new Error("Unexpected object: " + x); ->Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 41, 21)) -} - -function area3(s: Shape) { ->area3 : Symbol(area3, Decl(discriminatedUnionTypes1.ts, 43, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - switch (s.kind) { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - case "square": return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - - case "rectangle": return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - - case "circle": return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - - default: return assertNever(s); ->assertNever : Symbol(assertNever, Decl(discriminatedUnionTypes1.ts, 39, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) - } -} - -function area4(s: Shape) { ->area4 : Symbol(area4, Decl(discriminatedUnionTypes1.ts, 52, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - switch (s.kind) { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - case "square": return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - - case "rectangle": return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - - case "circle": return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - } - return assertNever(s); ->assertNever : Symbol(assertNever, Decl(discriminatedUnionTypes1.ts, 39, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) -} - -type Message = ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - { kind: "A", x: string } | ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 64, 16)) - - { kind: "B" | "C", y: number } | ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 65, 5)) ->y : Symbol(y, Decl(discriminatedUnionTypes1.ts, 65, 22)) - - { kind: "D" }; ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 66, 5)) - -function f1(m: Message) { ->f1 : Symbol(f1, Decl(discriminatedUnionTypes1.ts, 66, 18)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - if (m.kind === "A") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - m; // { kind: "A", x: string } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) - } - else if (m.kind === "D") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - m; // { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) - } - else { - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) - } -} - -function f2(m: Message) { ->f2 : Symbol(f2, Decl(discriminatedUnionTypes1.ts, 78, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 80, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - if (m.kind === "A") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 80, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 80, 12)) -} - -function f3(m: Message) { ->f3 : Symbol(f3, Decl(discriminatedUnionTypes1.ts, 85, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 87, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - if (m.kind === "X") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 87, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - m; // never ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 87, 12)) - } -} - -function f4(m: Message, x: "A" | "D") { ->f4 : Symbol(f4, Decl(discriminatedUnionTypes1.ts, 91, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 93, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 93, 23)) - - if (m.kind == x) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 93, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 93, 23)) - - m; // { kind: "A", x: string } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 93, 12)) - } -} - -function f5(m: Message) { ->f5 : Symbol(f5, Decl(discriminatedUnionTypes1.ts, 97, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - m; // { kind: "A", x: string } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) - - break; - case "D": - m; // { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) - } -} - -function f6(m: Message) { ->f6 : Symbol(f6, Decl(discriminatedUnionTypes1.ts, 110, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - m; // { kind: "A", x: string } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) - - case "D": - m; // { kind: "A", x: string } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) - } -} - -function f7(m: Message) { ->f7 : Symbol(f7, Decl(discriminatedUnionTypes1.ts, 122, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 124, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 124, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - case "B": - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 124, 12)) -} - -function f8(m: Message) { ->f8 : Symbol(f8, Decl(discriminatedUnionTypes1.ts, 131, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 133, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 133, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - return; - case "D": - throw new Error(); ->Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) - } - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 133, 12)) -} diff --git a/tests/baselines/reference/discriminatedUnionTypes1.types b/tests/baselines/reference/discriminatedUnionTypes1.types deleted file mode 100644 index 234de28eabae5..0000000000000 --- a/tests/baselines/reference/discriminatedUnionTypes1.types +++ /dev/null @@ -1,465 +0,0 @@ -=== tests/cases/conformance/types/union/discriminatedUnionTypes1.ts === -interface Square { ->Square : Square - - kind: "square"; ->kind : "square" - - size: number; ->size : number -} - -interface Rectangle { ->Rectangle : Rectangle - - kind: "rectangle"; ->kind : "rectangle" - - width: number; ->width : number - - height: number; ->height : number -} - -interface Circle { ->Circle : Circle - - kind: "circle"; ->kind : "circle" - - radius: number; ->radius : number -} - -type Shape = Square | Rectangle | Circle; ->Shape : Square | Rectangle | Circle ->Square : Square ->Rectangle : Rectangle ->Circle : Circle - -function area1(s: Shape) { ->area1 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - if (s.kind === "square") { ->s.kind === "square" : boolean ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" ->"square" : string - - return s.size * s.size; ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - } - else if (s.kind === "circle") { ->s.kind === "circle" : boolean ->s.kind : "rectangle" | "circle" ->s : Rectangle | Circle ->kind : "rectangle" | "circle" ->"circle" : string - - return Math.PI * s.radius * s.radius; ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - } - else if (s.kind === "rectangle") { ->s.kind === "rectangle" : boolean ->s.kind : "rectangle" ->s : Rectangle ->kind : "rectangle" ->"rectangle" : string - - return s.width * s.height; ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - } - else { - return 0; ->0 : number - } -} - -function area2(s: Shape) { ->area2 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - switch (s.kind) { ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" - - case "square": return s.size * s.size; ->"square" : string ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - - case "rectangle": return s.width * s.height; ->"rectangle" : string ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - - case "circle": return Math.PI * s.radius * s.radius; ->"circle" : string ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - } -} - -function assertNever(x: never): never { ->assertNever : (x: never) => never ->x : never - - throw new Error("Unexpected object: " + x); ->new Error("Unexpected object: " + x) : Error ->Error : ErrorConstructor ->"Unexpected object: " + x : string ->"Unexpected object: " : string ->x : never -} - -function area3(s: Shape) { ->area3 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - switch (s.kind) { ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" - - case "square": return s.size * s.size; ->"square" : string ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - - case "rectangle": return s.width * s.height; ->"rectangle" : string ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - - case "circle": return Math.PI * s.radius * s.radius; ->"circle" : string ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - - default: return assertNever(s); ->assertNever(s) : never ->assertNever : (x: never) => never ->s : never - } -} - -function area4(s: Shape) { ->area4 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - switch (s.kind) { ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" - - case "square": return s.size * s.size; ->"square" : string ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - - case "rectangle": return s.width * s.height; ->"rectangle" : string ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - - case "circle": return Math.PI * s.radius * s.radius; ->"circle" : string ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - } - return assertNever(s); ->assertNever(s) : never ->assertNever : (x: never) => never ->s : never -} - -type Message = ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - { kind: "A", x: string } | ->kind : "A" ->x : string - - { kind: "B" | "C", y: number } | ->kind : "B" | "C" ->y : number - - { kind: "D" }; ->kind : "D" - -function f1(m: Message) { ->f1 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - if (m.kind === "A") { ->m.kind === "A" : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->"A" : string - - m; // { kind: "A", x: string } ->m : { kind: "A"; x: string; } - } - else if (m.kind === "D") { ->m.kind === "D" : boolean ->m.kind : "B" | "C" | "D" ->m : { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "B" | "C" | "D" ->"D" : string - - m; // { kind: "D" } ->m : { kind: "D"; } - } - else { - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } - } -} - -function f2(m: Message) { ->f2 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - if (m.kind === "A") { ->m.kind === "A" : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->"A" : string - - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : { kind: "B" | "C"; y: number; } | { kind: "D"; } -} - -function f3(m: Message) { ->f3 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - if (m.kind === "X") { ->m.kind === "X" : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->"X" : string - - m; // never ->m : never - } -} - -function f4(m: Message, x: "A" | "D") { ->f4 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }, x: "A" | "D") => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->x : "A" | "D" - - if (m.kind == x) { ->m.kind == x : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->x : "A" | "D" - - m; // { kind: "A", x: string } | { kind: "D" } ->m : { kind: "A"; x: string; } | { kind: "D"; } - } -} - -function f5(m: Message) { ->f5 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - m; // { kind: "A", x: string } ->m : { kind: "A"; x: string; } - - break; - case "D": ->"D" : string - - m; // { kind: "D" } ->m : { kind: "D"; } - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } - } -} - -function f6(m: Message) { ->f6 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - m; // { kind: "A", x: string } ->m : { kind: "A"; x: string; } - - case "D": ->"D" : string - - m; // { kind: "A", x: string } | { kind: "D" } ->m : { kind: "D"; } | { kind: "A"; x: string; } - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } - } -} - -function f7(m: Message) { ->f7 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - case "B": ->"B" : string - - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : { kind: "B" | "C"; y: number; } | { kind: "D"; } -} - -function f8(m: Message) { ->f8 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - return; - case "D": ->"D" : string - - throw new Error(); ->new Error() : Error ->Error : ErrorConstructor - } - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } -}