From 4a50671092cffdae086170f3b4b5859e1cf8cca9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 18 Jan 2018 15:05:20 -0800 Subject: [PATCH 01/41] Nested excess property checks:discriminated unions Previously, unions and intersections would never do nested excess property checks. When the unions have a discriminant, nested checks are fine because only constituents matching the discriminant will be checked. --- src/compiler/checker.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 79430adf777..8a1b9015150 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9217,7 +9217,8 @@ namespace ts { isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True; if (isObjectLiteralType(source) && source.flags & TypeFlags.FreshLiteral) { - if (hasExcessProperties(source, target, reportErrors)) { + const discriminantType = target.flags & TypeFlags.Union ? findMatchingDiscriminantType(source, target as UnionType) : undefined; + if (hasExcessProperties(source, target, discriminantType, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } @@ -9227,7 +9228,7 @@ namespace ts { // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. - if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { + if (isUnionOrIntersectionTypeWithoutNullableConstituents(target) && !discriminantType) { source = getRegularTypeOfObjectLiteral(source); } } @@ -9328,19 +9329,16 @@ namespace ts { return Ternary.False; } - function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean { + function hasExcessProperties(source: FreshObjectLiteralType, target: Type, discriminant: Type | undefined, reportErrors: boolean): boolean { if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) { const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes); if ((relation === assignableRelation || relation === comparableRelation) && (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } - if (target.flags & TypeFlags.Union) { - const discriminantType = findMatchingDiscriminantType(source, target as UnionType); - if (discriminantType) { - // check excess properties against discriminant type only, not the entire union - return hasExcessProperties(source, discriminantType, reportErrors); - } + if (discriminant) { + // check excess properties against discriminant type only, not the entire union + return hasExcessProperties(source, discriminant, undefined, reportErrors); } for (const prop of getPropertiesOfObjectType(source)) { if (!isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) { From 6ccf9bce8ff23160ade099cc9c3e9dd3322373f1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 18 Jan 2018 15:11:29 -0800 Subject: [PATCH 02/41] Test:Nested excess property checking w/discriminated unions --- .../excessPropertyCheckWithUnions.errors.txt | 32 +++++++++- .../excessPropertyCheckWithUnions.js | 33 ++++++++++ .../excessPropertyCheckWithUnions.symbols | 54 ++++++++++++++++ .../excessPropertyCheckWithUnions.types | 64 +++++++++++++++++++ .../compiler/excessPropertyCheckWithUnions.ts | 19 ++++++ 5 files changed, 201 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt index 24940d173d0..f5e0550033d 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt @@ -21,9 +21,14 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(49,35): error TS2322: Type Object literal may only specify known properties, and 'second' does not exist in type '{ a: 1; b: 1; first: string; }'. tests/cases/compiler/excessPropertyCheckWithUnions.ts(50,35): error TS2322: Type '{ a: 1; b: 1; first: string; third: string; }' is not assignable to type 'Overlapping'. Object literal may only specify known properties, and 'third' does not exist in type '{ a: 1; b: 1; first: string; }'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(66,9): error TS2322: Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type 'AB'. + Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type '{ kind: "A"; n: AN; }'. + Types of property 'n' are incompatible. + Type '{ a: string; b: string; }' is not assignable to type 'AN'. + Object literal may only specify known properties, and 'b' does not exist in type 'AN'. -==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (9 errors) ==== +==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (10 errors) ==== type ADT = { tag: "A", a1: string @@ -112,4 +117,29 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(50,35): error TS2322: Type declare let t1: { a: any, b: any, c: any } | { c: any, d: any, e: any } let t2 = { ...t1 } t0 = t2 + + // Nested excess property checks work with discriminated unions + type AN = { a: string } | { c: string } + type BN = { b: string } + type AB = { kind: "A", n: AN } | { kind: "B", n: BN } + const abab: AB = { + kind: "A", + n: { + a: "a", + b: "b", // excess -- kind: "A" + ~~~~~~ +!!! error TS2322: Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type 'AB'. +!!! error TS2322: Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type '{ kind: "A"; n: AN; }'. +!!! error TS2322: Types of property 'n' are incompatible. +!!! error TS2322: Type '{ a: string; b: string; }' is not assignable to type 'AN'. +!!! error TS2322: Object literal may only specify known properties, and 'b' does not exist in type 'AN'. + } + } + const abac: AB = { + kind: "A", + n: { + a: "a", + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.js b/tests/baselines/reference/excessPropertyCheckWithUnions.js index a20983e4b08..1ac4d7477d6 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.js +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.js @@ -55,6 +55,25 @@ declare let t0: { a: any, b: any } | { d: any, e: any } declare let t1: { a: any, b: any, c: any } | { c: any, d: any, e: any } let t2 = { ...t1 } t0 = t2 + +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +type BN = { b: string } +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +const abab: AB = { + kind: "A", + n: { + a: "a", + b: "b", // excess -- kind: "A" + } +} +const abac: AB = { + kind: "A", + n: { + a: "a", + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } + } +} //// [excessPropertyCheckWithUnions.js] @@ -89,3 +108,17 @@ over = { a: 1, b: 1, first: "ok", second: "error" }; over = { a: 1, b: 1, first: "ok", third: "error" }; var t2 = __assign({}, t1); t0 = t2; +var abab = { + kind: "A", + n: { + a: "a", + b: "b" + } +}; +var abac = { + kind: "A", + n: { + a: "a", + c: "c" + } +}; diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.symbols b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols index 381681de384..beee933a2f1 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.symbols +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols @@ -167,3 +167,57 @@ t0 = t2 >t0 : Symbol(t0, Decl(excessPropertyCheckWithUnions.ts, 52, 11)) >t2 : Symbol(t2, Decl(excessPropertyCheckWithUnions.ts, 54, 3)) +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +>AN : Symbol(AN, Decl(excessPropertyCheckWithUnions.ts, 55, 7)) +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 58, 11)) +>c : Symbol(c, Decl(excessPropertyCheckWithUnions.ts, 58, 27)) + +type BN = { b: string } +>BN : Symbol(BN, Decl(excessPropertyCheckWithUnions.ts, 58, 39)) +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 59, 11)) + +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +>AB : Symbol(AB, Decl(excessPropertyCheckWithUnions.ts, 59, 23)) +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 60, 11)) +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 60, 22)) +>AN : Symbol(AN, Decl(excessPropertyCheckWithUnions.ts, 55, 7)) +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 60, 34)) +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 60, 45)) +>BN : Symbol(BN, Decl(excessPropertyCheckWithUnions.ts, 58, 39)) + +const abab: AB = { +>abab : Symbol(abab, Decl(excessPropertyCheckWithUnions.ts, 61, 5)) +>AB : Symbol(AB, Decl(excessPropertyCheckWithUnions.ts, 59, 23)) + + kind: "A", +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 61, 18)) + + n: { +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 62, 14)) + + a: "a", +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 63, 8)) + + b: "b", // excess -- kind: "A" +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 64, 15)) + } +} +const abac: AB = { +>abac : Symbol(abac, Decl(excessPropertyCheckWithUnions.ts, 68, 5)) +>AB : Symbol(AB, Decl(excessPropertyCheckWithUnions.ts, 59, 23)) + + kind: "A", +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 68, 18)) + + n: { +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 69, 14)) + + a: "a", +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 70, 8)) + + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } +>c : Symbol(c, Decl(excessPropertyCheckWithUnions.ts, 71, 15)) + } +} + diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.types b/tests/baselines/reference/excessPropertyCheckWithUnions.types index 4ef53e35ecc..41a8bb67a03 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.types +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.types @@ -221,3 +221,67 @@ t0 = t2 >t0 : { a: any; b: any; } | { d: any; e: any; } >t2 : { a: any; b: any; c: any; } | { c: any; d: any; e: any; } +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +>AN : AN +>a : string +>c : string + +type BN = { b: string } +>BN : BN +>b : string + +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +>AB : AB +>kind : "A" +>n : AN +>AN : AN +>kind : "B" +>n : BN +>BN : BN + +const abab: AB = { +>abab : AB +>AB : AB +>{ kind: "A", n: { a: "a", b: "b", // excess -- kind: "A" }} : { kind: "A"; n: { a: string; b: string; }; } + + kind: "A", +>kind : "A" +>"A" : "A" + + n: { +>n : { a: string; b: string; } +>{ a: "a", b: "b", // excess -- kind: "A" } : { a: string; b: string; } + + a: "a", +>a : string +>"a" : "a" + + b: "b", // excess -- kind: "A" +>b : string +>"b" : "b" + } +} +const abac: AB = { +>abac : AB +>AB : AB +>{ kind: "A", n: { a: "a", c: "c", // ok -- kind: "A", an: { a: string } | { c: string } }} : { kind: "A"; n: { a: string; c: string; }; } + + kind: "A", +>kind : "A" +>"A" : "A" + + n: { +>n : { a: string; c: string; } +>{ a: "a", c: "c", // ok -- kind: "A", an: { a: string } | { c: string } } : { a: string; c: string; } + + a: "a", +>a : string +>"a" : "a" + + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } +>c : string +>"c" : "c" + } +} + diff --git a/tests/cases/compiler/excessPropertyCheckWithUnions.ts b/tests/cases/compiler/excessPropertyCheckWithUnions.ts index 240af391cf5..027e67e4ec9 100644 --- a/tests/cases/compiler/excessPropertyCheckWithUnions.ts +++ b/tests/cases/compiler/excessPropertyCheckWithUnions.ts @@ -55,3 +55,22 @@ declare let t0: { a: any, b: any } | { d: any, e: any } declare let t1: { a: any, b: any, c: any } | { c: any, d: any, e: any } let t2 = { ...t1 } t0 = t2 + +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +type BN = { b: string } +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +const abab: AB = { + kind: "A", + n: { + a: "a", + b: "b", // excess -- kind: "A" + } +} +const abac: AB = { + kind: "A", + n: { + a: "a", + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } + } +} From cadd7679a2e3bf819f58e575a650fcf6118a9c96 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 19 Jan 2018 13:08:22 -0800 Subject: [PATCH 03/41] DT runner:Fix $ExpectError handling Indices into lines of the file are zero-based, but the errors reporting by Typescript are one-based. Also, the regex ignored $ExpectError in tsx files. --- src/harness/externalCompileRunner.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/harness/externalCompileRunner.ts b/src/harness/externalCompileRunner.ts index c829a6490bb..1f945cfcc9c 100644 --- a/src/harness/externalCompileRunner.ts +++ b/src/harness/externalCompileRunner.ts @@ -131,13 +131,13 @@ function removeExpectedErrors(errors: string, cwd: string): string { function isUnexpectedError(cwd: string) { return (error: string[]) => { ts.Debug.assertGreaterThanOrEqual(error.length, 1); - const match = error[0].match(/(.+\.ts)\((\d+),\d+\): error TS/); + const match = error[0].match(/(.+\.tsx?)\((\d+),\d+\): error TS/); if (!match) { return true; } const [, errorFile, lineNumberString] = match; const lines = fs.readFileSync(path.join(cwd, errorFile), { encoding: "utf8" }).split("\n"); - const lineNumber = parseInt(lineNumberString); + const lineNumber = parseInt(lineNumberString) - 1; ts.Debug.assertGreaterThanOrEqual(lineNumber, 0); ts.Debug.assertLessThan(lineNumber, lines.length); const previousLine = lineNumber - 1 > 0 ? lines[lineNumber - 1] : ""; From 184835b5cd5764d1db433333c3b804cc5b50fcf8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 19 Jan 2018 13:36:01 -0800 Subject: [PATCH 04/41] Lint:document parameter name --- 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 8a1b9015150..3e8d5b86af7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9338,7 +9338,7 @@ namespace ts { } if (discriminant) { // check excess properties against discriminant type only, not the entire union - return hasExcessProperties(source, discriminant, undefined, reportErrors); + return hasExcessProperties(source, discriminant, /*discriminant*/ undefined, reportErrors); } for (const prop of getPropertiesOfObjectType(source)) { if (!isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) { From 92bde084c1e5ce42ac9491273dec3e846fc61c7e Mon Sep 17 00:00:00 2001 From: Esakki Raj Date: Sun, 21 Jan 2018 23:15:58 +0530 Subject: [PATCH 05/41] Fix formatting between for and await (#21254) * Fix issue 21084 * Removed unwanted rules. --- src/services/formatting/rules.ts | 3 +++ tests/cases/fourslash/formattingAwait.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/cases/fourslash/formattingAwait.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 16270eda479..f6a9dee4cfe 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -321,6 +321,9 @@ namespace ts.formatting { rule("NoSpaceAfterCloseBracket", SyntaxKind.CloseBracketToken, anyToken, [isNonJsxSameLineTokenContext, isNotBeforeBlockInFunctionDeclarationContext], RuleAction.Delete), rule("SpaceAfterSemicolon", SyntaxKind.SemicolonToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Space), + // Remove extra space between for and await + rule("SpaceBetweenForAndAwaitKeyword", SyntaxKind.ForKeyword, SyntaxKind.AwaitKeyword, [isNonJsxSameLineTokenContext], RuleAction.Space), + // Add a space between statements. All keywords except (do,else,case) has open/close parens after them. // So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any] rule( diff --git a/tests/cases/fourslash/formattingAwait.ts b/tests/cases/fourslash/formattingAwait.ts new file mode 100644 index 00000000000..e6a86f92d08 --- /dev/null +++ b/tests/cases/fourslash/formattingAwait.ts @@ -0,0 +1,18 @@ +/// + +////async function f() { +//// for await (const x of g()) { +//// console.log(x); +//// } +////} + + +format.document(); + +verify.currentFileContentIs( +`async function f() { + for await (const x of g()) { + console.log(x); + } +}` +); \ No newline at end of file From 18e1ac030613bd15a55156bd95e16b5002e99ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 09:52:58 +0100 Subject: [PATCH 06/41] Fixes #17080 Changes are in src/compiler.checker.ts only The second arguments to the function "removeOptionalityFromDeclaredType" has been changed from "getRootDeclaration(declaration)" to "declaration". --- pull_request_template.md | 9 +- src/compiler/checker.ts | 2 +- ...rInDestructuringWithInitializer.errors.txt | 62 ++++++ ...ParameterInDestructuringWithInitializer.js | 80 +++++++ ...eterInDestructuringWithInitializer.symbols | 154 ++++++++++++++ ...ameterInDestructuringWithInitializer.types | 198 ++++++++++++++++++ ...ParameterInDestructuringWithInitializer.ts | 39 ++++ 7 files changed, 539 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types create mode 100644 tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts diff --git a/pull_request_template.md b/pull_request_template.md index 2c49c84641b..faa484054be 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -2,15 +2,16 @@ Thank you for submitting a pull request! Here's a checklist you might find useful. -[ ] There is an associated issue that is labelled +[X] There is an associated issue that is labelled 'Bug' or 'help wanted' or is in the Community milestone -[ ] Code is up-to-date with the `master` branch -[ ] You've successfully run `jake runtests` locally +[X] Code is up-to-date with the `master` branch +[X] You've successfully run `jake runtests` locally [ ] You've signed the CLA -[ ] There are new or updated unit tests validating the change +[X] There are new or updated unit tests validating the change Refer to CONTRIBUTING.MD for more details. https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md --> Fixes # +#17080 diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 405fd11f138..74c60bcdb62 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13046,7 +13046,7 @@ namespace ts { node.parent.kind === SyntaxKind.NonNullExpression || declaration.kind === SyntaxKind.VariableDeclaration && (declaration).exclamationToken || declaration.flags & NodeFlags.Ambient; - const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) : + const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration as VariableLikeDeclaration) : type) : type === autoType || type === autoArrayType ? undefinedType : getOptionalType(type); const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer, !assumeInitialized); diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt new file mode 100644 index 00000000000..14bc3ea8e6c --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt @@ -0,0 +1,62 @@ +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(6,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(16,7): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(21,7): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. + + +==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (4 errors) ==== + // https://github.com/Microsoft/TypeScript/issues/17080 + function f(a:number,b:number) { + } + + function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error + } + + function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error + } + + function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error + } + \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js new file mode 100644 index 00000000000..8c297088f14 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js @@ -0,0 +1,80 @@ +//// [optionalParameterInDestructuringWithInitializer.ts] +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error +} + + +//// [optionalParameterInDestructuringWithInitializer.js] +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a, b) { +} +function func1(_a) { + var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, b = _b.b; + f(a, b); + // error +} +function func2(_a) { + var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, _c = _b.b, b = _c === void 0 ? 3 : _c; + f(a, b); + // no error +} +function func3(_a) { + var _b = _a === void 0 ? { a: 1 } : _a, a = _b.a, b = _b.b; + f(a, b); + // error +} +function func4(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, c = _c.c, d = _b.d; + f(b, c); + // error +} +function func5(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, _d = _c.c, c = _d === void 0 ? 4 : _d, d = _b.d; + f(b, c); + // no error +} +function func6(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, c = _d.c, d = _b.d; + f(b, c); + // error +} +function func7(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, _e = _d.c, c = _e === void 0 ? 6 : _e, d = _b.d; + f(b, c); + // no error +} diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols new file mode 100644 index 00000000000..fc068a0babb --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols @@ -0,0 +1,154 @@ +=== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 11)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 20)) +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { +>func1 : Symbol(func1, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 25)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 35)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 51)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 56)) + + f(a, b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) + + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { +>func2 : Symbol(func2, Decl(optionalParameterInDestructuringWithInitializer.ts, 7, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 29)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 39)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 54)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 59)) + + f(a, b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 19)) + + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { +>func3 : Symbol(func3, Decl(optionalParameterInDestructuringWithInitializer.ts, 12, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 25)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 35)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 51)) + + f(a,b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 19)) + + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func4 : Symbol(func4, Decl(optionalParameterInDestructuringWithInitializer.ts, 17, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 33)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 23)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 27)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 33)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 37)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 47)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 59)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 73)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 77)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 82)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 88)) + + f(b,c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 23)) + + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func5 : Symbol(func5, Decl(optionalParameterInDestructuringWithInitializer.ts, 22, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 36)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 20)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 22)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 30)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 36)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 40)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 50)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 62)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 76)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 80)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 85)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 91)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 20)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 22)) + + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { +>func6 : Symbol(func6, Decl(optionalParameterInDestructuringWithInitializer.ts, 27, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 48)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 23)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 30)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 35)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 42)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 48)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 52)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 62)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 75)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 90)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 94)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 99)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 105)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 23)) + + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { +>func7 : Symbol(func7, Decl(optionalParameterInDestructuringWithInitializer.ts, 32, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 52)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 23)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 34)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 39)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 46)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 52)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 56)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 66)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 79)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 94)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 98)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 103)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 110)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 23)) + + // no error +} + diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types new file mode 100644 index 00000000000..8def19dde20 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types @@ -0,0 +1,198 @@ +=== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +>f : (a: number, b: number) => void +>a : number +>b : number +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { +>func1 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number | undefined +>a : number +>b : number | undefined +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + + f(a, b) +>f(a, b) : void +>f : (a: number, b: number) => void +>a : number +>b : number | undefined + + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { +>func2 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number +>3 : 3 +>a : number +>b : number | undefined +>{a: 1,b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + + f(a, b) +>f(a, b) : void +>f : (a: number, b: number) => void +>a : number +>b : number + + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { +>func3 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number | undefined +>a : number +>b : number | undefined +>{a: 1} : { a: number; } +>a : number +>1 : 1 + + f(a,b) +>f(a,b) : void +>f : (a: number, b: number) => void +>a : number +>b : number | undefined + + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func4 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number | undefined +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2},d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b,c) +>f(b,c) : void +>f : (a: number, b: number) => void +>b : number +>c : number | undefined + + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func5 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number +>4 : 4 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2},d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number + + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { +>func6 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number | undefined +>{b: 4, c: 5} : { b: number; c: number; } +>b : number +>4 : 4 +>c : number +>5 : 5 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2}, d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number | undefined + + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { +>func7 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number +>6 : 6 +>{b: 4, c: 5} : { b: number; c?: number; } +>b : number +>4 : 4 +>c : number +>5 : 5 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1, c: 2}, d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1, c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number + + // no error +} + diff --git a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts new file mode 100644 index 00000000000..3666ee2d954 --- /dev/null +++ b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts @@ -0,0 +1,39 @@ +// @strictNullChecks: true +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error +} From 5a87a94c59a7ea137113a873b163c98e7322fa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 13:40:57 +0100 Subject: [PATCH 07/41] Fixes #17080 https://github.com/Microsoft/TypeScript/issues/17080 Added testcases from the Github bugreport (all working as intended now). Signed CLA. --- pull_request_template.md | 2 +- ...rInDestructuringWithInitializer.errors.txt | 38 ++++++++++- ...ParameterInDestructuringWithInitializer.js | 44 +++++++++++++ ...eterInDestructuringWithInitializer.symbols | 55 ++++++++++++++++ ...ameterInDestructuringWithInitializer.types | 66 +++++++++++++++++++ ...ParameterInDestructuringWithInitializer.ts | 26 ++++++++ 6 files changed, 229 insertions(+), 2 deletions(-) diff --git a/pull_request_template.md b/pull_request_template.md index faa484054be..4243c2f671f 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -6,7 +6,7 @@ Here's a checklist you might find useful. 'Bug' or 'help wanted' or is in the Community milestone [X] Code is up-to-date with the `master` branch [X] You've successfully run `jake runtests` locally -[ ] You've signed the CLA +[X] You've signed the CLA [X] There are new or updated unit tests validating the change Refer to CONTRIBUTING.MD for more details. diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt index 14bc3ea8e6c..8965d7172e8 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt @@ -6,9 +6,13 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(21,7): e Type 'undefined' is not assignable to type 'number'. tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(45,10): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. + Type 'null' is not assignable to type 'number | undefined'. -==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (4 errors) ==== +==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (6 errors) ==== // https://github.com/Microsoft/TypeScript/issues/17080 function f(a:number,b:number) { } @@ -59,4 +63,36 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): e f(b, c) // no error } + + interface Foo { + readonly bar?: number; + } + + function performFoo({ bar }: Foo = {}) { + useBar(bar); + ~~~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + } + + function useBar(bar: number) { + f(bar, 1) + } + + performFoo(); + + function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); + ~~~ +!!! error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. +!!! error TS2345: Type 'null' is not assignable to type 'number | undefined'. + } + + function useBar2(bar: number | undefined) { + if (bar) { + f(bar, 1) + } + } + + performFoo2(); \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js index 8c297088f14..cb929d89112 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js @@ -37,6 +37,32 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, f(b, c) // no error } + +interface Foo { + readonly bar?: number; +} + +function performFoo({ bar }: Foo = {}) { + useBar(bar); +} + +function useBar(bar: number) { + f(bar, 1) +} + +performFoo(); + +function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); +} + +function useBar2(bar: number | undefined) { + if (bar) { + f(bar, 1) + } +} + +performFoo2(); //// [optionalParameterInDestructuringWithInitializer.js] @@ -78,3 +104,21 @@ function func7(_a) { f(b, c); // no error } +function performFoo(_a) { + var bar = (_a === void 0 ? {} : _a).bar; + useBar(bar); +} +function useBar(bar) { + f(bar, 1); +} +performFoo(); +function performFoo2(_a) { + var _b = (_a === void 0 ? {} : _a).bar, bar = _b === void 0 ? null : _b; + useBar2(bar); +} +function useBar2(bar) { + if (bar) { + f(bar, 1); + } +} +performFoo2(); diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols index fc068a0babb..399956476c8 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols @@ -152,3 +152,58 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, // no error } +interface Foo { +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + readonly bar?: number; +>bar : Symbol(Foo.bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 39, 15)) +} + +function performFoo({ bar }: Foo = {}) { +>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + useBar(bar); +>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) +} + +function useBar(bar: number) { +>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) + + f(bar, 1) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) +} + +performFoo(); +>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) + +function performFoo2({ bar = null }: Foo = {}) { +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + useBar2(bar); +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +} + +function useBar2(bar: number | undefined) { +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) + + if (bar) { +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) + + f(bar, 1) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) + } +} + +performFoo2(); +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) + diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types index 8def19dde20..1d1618e12e3 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types @@ -196,3 +196,69 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, // no error } +interface Foo { +>Foo : Foo + + readonly bar?: number; +>bar : number | undefined +} + +function performFoo({ bar }: Foo = {}) { +>performFoo : ({ bar }?: Foo) => void +>bar : number | undefined +>Foo : Foo +>{} : {} + + useBar(bar); +>useBar(bar) : void +>useBar : (bar: number) => void +>bar : number | undefined +} + +function useBar(bar: number) { +>useBar : (bar: number) => void +>bar : number + + f(bar, 1) +>f(bar, 1) : void +>f : (a: number, b: number) => void +>bar : number +>1 : 1 +} + +performFoo(); +>performFoo() : void +>performFoo : ({ bar }?: Foo) => void + +function performFoo2({ bar = null }: Foo = {}) { +>performFoo2 : ({ bar }?: Foo) => void +>bar : number | null +>null : null +>Foo : Foo +>{} : {} + + useBar2(bar); +>useBar2(bar) : void +>useBar2 : (bar: number | undefined) => void +>bar : number | null +} + +function useBar2(bar: number | undefined) { +>useBar2 : (bar: number | undefined) => void +>bar : number | undefined + + if (bar) { +>bar : number | undefined + + f(bar, 1) +>f(bar, 1) : void +>f : (a: number, b: number) => void +>bar : number +>1 : 1 + } +} + +performFoo2(); +>performFoo2() : void +>performFoo2 : ({ bar }?: Foo) => void + diff --git a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts index 3666ee2d954..1f1847a19a7 100644 --- a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts +++ b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts @@ -37,3 +37,29 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, f(b, c) // no error } + +interface Foo { + readonly bar?: number; +} + +function performFoo({ bar }: Foo = {}) { + useBar(bar); +} + +function useBar(bar: number) { + f(bar, 1) +} + +performFoo(); + +function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); +} + +function useBar2(bar: number | undefined) { + if (bar) { + f(bar, 1) + } +} + +performFoo2(); From 588716926dcaa063aecb4d64232e2f3cfd8e23b2 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 22 Jan 2018 10:15:57 -0800 Subject: [PATCH 08/41] Fix bug: result of createUnionOrIntersectionProperty may be undefined (#21332) --- src/compiler/checker.ts | 6 ++++-- tests/cases/fourslash/completionsUnion.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 405fd11f138..14631fa69cb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5995,7 +5995,9 @@ namespace ts { for (const memberType of types) { for (const { escapedName } of getAugmentedPropertiesOfType(memberType)) { if (!props.has(escapedName)) { - props.set(escapedName, createUnionOrIntersectionProperty(unionType as UnionType, escapedName)); + const prop = createUnionOrIntersectionProperty(unionType as UnionType, escapedName); + // May be undefined if the property is private + if (prop) props.set(escapedName, prop); } } } @@ -6177,7 +6179,7 @@ namespace ts { t; } - function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol { + function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined { let props: Symbol[]; const isUnion = containingType.flags & TypeFlags.Union; const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0; diff --git a/tests/cases/fourslash/completionsUnion.ts b/tests/cases/fourslash/completionsUnion.ts index ed449936680..d9d1d3c792f 100644 --- a/tests/cases/fourslash/completionsUnion.ts +++ b/tests/cases/fourslash/completionsUnion.ts @@ -2,7 +2,9 @@ ////interface I { x: number; } ////interface Many extends ReadonlyArray { extra: number; } -////const x: I | I[] | Many = { /**/ }; +////class C { private priv: number; } +////const x: I | I[] | Many | C = { /**/ }; // We specifically filter out any array-like types. +// Private members will be excluded by `createUnionOrIntersectionProperty`. verify.completionsAt("", ["x"]); From 146256b7dc2590f067ea8ccd916d1192ef169429 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 17 Jan 2018 15:35:17 -0800 Subject: [PATCH 09/41] Allow dynamic files without external project and also use file names starting with ^ as dynamic file Fixes #21204 --- .../unittests/tsserverProjectSystem.ts | 39 +++++++++++++++++++ src/server/editorServices.ts | 4 +- src/server/scriptInfo.ts | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index af69e35ec18..fee21fcdb2d 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2846,6 +2846,45 @@ namespace ts.projectSystem { const options = project.getCompilerOptions(); assert.equal(options.outDir, "C:/a/b", ""); }); + + it("dynamic file without external project", () => { + const file: FileOrFolder = { + path: "^walkThroughSnippet:/Users/UserName/projects/someProject/out/someFile#1.js", + content: "var x = 10;" + }; + const host = createServerHost([libFile], { useCaseSensitiveFileNames: true }); + const projectService = createProjectService(host); + projectService.setCompilerOptionsForInferredProjects({ + module: ModuleKind.CommonJS, + allowJs: true, + allowSyntheticDefaultImports: true, + allowNonTsExtensions: true + }); + projectService.openClientFile(file.path, "var x = 10;"); + + projectService.checkNumberOfProjects({ inferredProjects: 1 }); + const project = projectService.inferredProjects[0]; + checkProjectRootFiles(project, [file.path]); + checkProjectActualFiles(project, [file.path, libFile.path]); + + assert.strictEqual(projectService.getDefaultProjectForFile(server.toNormalizedPath(file.path), /*ensureProject*/ true), project); + const indexOfX = file.content.indexOf("x"); + assert.deepEqual(project.getLanguageService(/*ensureSynchronized*/ true).getQuickInfoAtPosition(file.path, indexOfX), { + kind: ScriptElementKind.variableElement, + kindModifiers: "", + textSpan: { start: indexOfX, length: 1 }, + displayParts: [ + { text: "var", kind: "keyword" }, + { text: " ", kind: "space" }, + { text: "x", kind: "localName" }, + { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "number", kind: "keyword" } + ], + documentation: [], + tags: [] + }); + }); }); describe("tsserverProjectSystem Proper errors", () => { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 575e00c5b0e..5d71ff4c2d3 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -898,7 +898,7 @@ namespace ts.server { const project = this.getOrCreateInferredProjectForProjectRootPathIfEnabled(info, projectRootPath) || this.getOrCreateSingleInferredProjectIfEnabled() || - this.createInferredProject(getDirectoryPath(info.path)); + this.createInferredProject(info.isDynamic ? this.currentDirectory : getDirectoryPath(info.path)); project.addRoot(info); project.updateGraph(); @@ -1655,7 +1655,7 @@ namespace ts.server { } private getOrCreateInferredProjectForProjectRootPathIfEnabled(info: ScriptInfo, projectRootPath: NormalizedPath | undefined): InferredProject | undefined { - if (!this.useInferredProjectPerProjectRoot) { + if (info.isDynamic || !this.useInferredProjectPerProjectRoot) { return undefined; } diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index dbadf5c88e7..6fc4f241f65 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -196,7 +196,7 @@ namespace ts.server { /*@internal*/ export function isDynamicFileName(fileName: NormalizedPath) { - return getBaseFileName(fileName)[0] === "^"; + return fileName[0] === "^" || getBaseFileName(fileName)[0] === "^"; } export class ScriptInfo { From d11341820e3aa3d99c918700a113f2819d8c381e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 21:45:37 +0100 Subject: [PATCH 10/41] Fixes #17080 Fixed the two requested changes. 1) Deleting the file "pull_request_template.md" 2) Declaring functions in tests, instead of defining --- pull_request_template.md | 17 ------- ...rInDestructuringWithInitializer.errors.txt | 16 +++---- ...ParameterInDestructuringWithInitializer.js | 24 ++-------- ...eterInDestructuringWithInitializer.symbols | 44 +++++++------------ ...ameterInDestructuringWithInitializer.types | 26 ++--------- ...ParameterInDestructuringWithInitializer.ts | 14 ++---- 6 files changed, 32 insertions(+), 109 deletions(-) delete mode 100644 pull_request_template.md diff --git a/pull_request_template.md b/pull_request_template.md deleted file mode 100644 index 4243c2f671f..00000000000 --- a/pull_request_template.md +++ /dev/null @@ -1,17 +0,0 @@ - - -Fixes # -#17080 diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt index 8965d7172e8..b2fea589cb1 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt @@ -8,14 +8,14 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): e Type 'undefined' is not assignable to type 'number'. tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(45,10): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'. -tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(53,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. Type 'null' is not assignable to type 'number | undefined'. ==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (6 errors) ==== // https://github.com/Microsoft/TypeScript/issues/17080 - function f(a:number,b:number) { - } + + declare function f(a:number,b:number): void; function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { f(a, b) @@ -75,9 +75,7 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): !!! error TS2345: Type 'undefined' is not assignable to type 'number'. } - function useBar(bar: number) { - f(bar, 1) - } + declare function useBar(bar: number): void; performFoo(); @@ -88,11 +86,7 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): !!! error TS2345: Type 'null' is not assignable to type 'number | undefined'. } - function useBar2(bar: number | undefined) { - if (bar) { - f(bar, 1) - } - } + declare function useBar2(bar: number | undefined): void; performFoo2(); \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js index cb929d89112..642f00a4f50 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js @@ -1,7 +1,7 @@ //// [optionalParameterInDestructuringWithInitializer.ts] // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { -} + +declare function f(a:number,b:number): void; function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { f(a, b) @@ -46,9 +46,7 @@ function performFoo({ bar }: Foo = {}) { useBar(bar); } -function useBar(bar: number) { - f(bar, 1) -} +declare function useBar(bar: number): void; performFoo(); @@ -56,19 +54,13 @@ function performFoo2({ bar = null }: Foo = {}) { useBar2(bar); } -function useBar2(bar: number | undefined) { - if (bar) { - f(bar, 1) - } -} +declare function useBar2(bar: number | undefined): void; performFoo2(); //// [optionalParameterInDestructuringWithInitializer.js] // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a, b) { -} function func1(_a) { var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, b = _b.b; f(a, b); @@ -108,17 +100,9 @@ function performFoo(_a) { var bar = (_a === void 0 ? {} : _a).bar; useBar(bar); } -function useBar(bar) { - f(bar, 1); -} performFoo(); function performFoo2(_a) { var _b = (_a === void 0 ? {} : _a).bar, bar = _b === void 0 ? null : _b; useBar2(bar); } -function useBar2(bar) { - if (bar) { - f(bar, 1); - } -} performFoo2(); diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols index 399956476c8..6d4cf484d92 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols @@ -1,13 +1,13 @@ === tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { + +declare function f(a:number,b:number): void; >f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) ->a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 11)) ->b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 20)) -} +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 19)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 28)) function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { ->func1 : Symbol(func1, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 1)) +>func1 : Symbol(func1, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 44)) >a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) >b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) >a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 25)) @@ -169,41 +169,27 @@ function performFoo({ bar }: Foo = {}) { >bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) } -function useBar(bar: number) { +declare function useBar(bar: number): void; >useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) - - f(bar, 1) ->f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) -} +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 24)) performFoo(); >performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) function performFoo2({ bar = null }: Foo = {}) { ->performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 49, 13)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 22)) >Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) useBar2(bar); ->useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 22)) } -function useBar2(bar: number | undefined) { ->useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) - - if (bar) { ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) - - f(bar, 1) ->f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) - } -} +declare function useBar2(bar: number | undefined): void; +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 25)) performFoo2(); ->performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 49, 13)) diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types index 1d1618e12e3..26110e71051 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types @@ -1,10 +1,10 @@ === tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { + +declare function f(a:number,b:number): void; >f : (a: number, b: number) => void >a : number >b : number -} function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { >func1 : ({ a, b }?: { a: number; b?: number | undefined; }) => void @@ -215,17 +215,10 @@ function performFoo({ bar }: Foo = {}) { >bar : number | undefined } -function useBar(bar: number) { +declare function useBar(bar: number): void; >useBar : (bar: number) => void >bar : number - f(bar, 1) ->f(bar, 1) : void ->f : (a: number, b: number) => void ->bar : number ->1 : 1 -} - performFoo(); >performFoo() : void >performFoo : ({ bar }?: Foo) => void @@ -243,21 +236,10 @@ function performFoo2({ bar = null }: Foo = {}) { >bar : number | null } -function useBar2(bar: number | undefined) { +declare function useBar2(bar: number | undefined): void; >useBar2 : (bar: number | undefined) => void >bar : number | undefined - if (bar) { ->bar : number | undefined - - f(bar, 1) ->f(bar, 1) : void ->f : (a: number, b: number) => void ->bar : number ->1 : 1 - } -} - performFoo2(); >performFoo2() : void >performFoo2 : ({ bar }?: Foo) => void diff --git a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts index 1f1847a19a7..d3ebd99efa1 100644 --- a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts +++ b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts @@ -1,7 +1,7 @@ // @strictNullChecks: true // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { -} + +declare function f(a:number,b:number): void; function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { f(a, b) @@ -46,9 +46,7 @@ function performFoo({ bar }: Foo = {}) { useBar(bar); } -function useBar(bar: number) { - f(bar, 1) -} +declare function useBar(bar: number): void; performFoo(); @@ -56,10 +54,6 @@ function performFoo2({ bar = null }: Foo = {}) { useBar2(bar); } -function useBar2(bar: number | undefined) { - if (bar) { - f(bar, 1) - } -} +declare function useBar2(bar: number | undefined): void; performFoo2(); From 97fb0fd55f28d9c599f14ad8487b85367bdf7da2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 22 Jan 2018 12:59:53 -0800 Subject: [PATCH 11/41] Add semicolon to unused class member list Turns out SemicolonClassElement is a specific kind for semicolons inside a class. Having one of them with --noUnusedLocals on would crash the compiler after the assert added in #21013. --- src/compiler/checker.ts | 1 + tests/baselines/reference/unusedSemicolonInClass.js | 13 +++++++++++++ .../reference/unusedSemicolonInClass.symbols | 7 +++++++ .../reference/unusedSemicolonInClass.types | 7 +++++++ tests/cases/compiler/unusedSemicolonInClass.ts | 4 ++++ 5 files changed, 32 insertions(+) create mode 100644 tests/baselines/reference/unusedSemicolonInClass.js create mode 100644 tests/baselines/reference/unusedSemicolonInClass.symbols create mode 100644 tests/baselines/reference/unusedSemicolonInClass.types create mode 100644 tests/cases/compiler/unusedSemicolonInClass.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 14631fa69cb..f418dbabcb8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21030,6 +21030,7 @@ namespace ts { } break; case SyntaxKind.IndexSignature: + case SyntaxKind.SemicolonClassElement: // Can't be private break; default: diff --git a/tests/baselines/reference/unusedSemicolonInClass.js b/tests/baselines/reference/unusedSemicolonInClass.js new file mode 100644 index 00000000000..c33f799fec4 --- /dev/null +++ b/tests/baselines/reference/unusedSemicolonInClass.js @@ -0,0 +1,13 @@ +//// [unusedSemicolonInClass.ts] +class Unused { + ; +} + + +//// [unusedSemicolonInClass.js] +var Unused = /** @class */ (function () { + function Unused() { + } + ; + return Unused; +}()); diff --git a/tests/baselines/reference/unusedSemicolonInClass.symbols b/tests/baselines/reference/unusedSemicolonInClass.symbols new file mode 100644 index 00000000000..0e1832d1f3a --- /dev/null +++ b/tests/baselines/reference/unusedSemicolonInClass.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/unusedSemicolonInClass.ts === +class Unused { +>Unused : Symbol(Unused, Decl(unusedSemicolonInClass.ts, 0, 0)) + + ; +} + diff --git a/tests/baselines/reference/unusedSemicolonInClass.types b/tests/baselines/reference/unusedSemicolonInClass.types new file mode 100644 index 00000000000..118259662f4 --- /dev/null +++ b/tests/baselines/reference/unusedSemicolonInClass.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/unusedSemicolonInClass.ts === +class Unused { +>Unused : Unused + + ; +} + diff --git a/tests/cases/compiler/unusedSemicolonInClass.ts b/tests/cases/compiler/unusedSemicolonInClass.ts new file mode 100644 index 00000000000..5cd62690ba9 --- /dev/null +++ b/tests/cases/compiler/unusedSemicolonInClass.ts @@ -0,0 +1,4 @@ +// @noUnusedLocals: true +class Unused { + ; +} From 7b449a5e6230b5ec9445902a87148a698719baa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 22:09:35 +0100 Subject: [PATCH 12/41] Fixes #17080 Readded untouched pull_request_template.md --- pull_request_template.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 pull_request_template.md diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 00000000000..2c49c84641b --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,16 @@ + + +Fixes # From ae652404cdcf9821e7a397d7c16995ef2111baed Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 22 Jan 2018 13:34:12 -0800 Subject: [PATCH 13/41] Fix JSX attribute checking when spreading unions Previously, the code didn't account for the fact that spreading a union creates a union. In fact, before Decemeber, spreading a union in JSX didn't create a union. Now the check for properties of the spread type uses `getPropertiesOfType`, which works with unions, instead of accessing the `properties` property directly. --- src/compiler/checker.ts | 2 +- .../tsxSpreadAttributesResolution17.js | 47 +++++++++++++++++++ .../tsxSpreadAttributesResolution17.symbols | 41 ++++++++++++++++ .../tsxSpreadAttributesResolution17.types | 45 ++++++++++++++++++ .../jsx/tsxSpreadAttributesResolution17.tsx | 25 ++++++++++ 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/tsxSpreadAttributesResolution17.js create mode 100644 tests/baselines/reference/tsxSpreadAttributesResolution17.symbols create mode 100644 tests/baselines/reference/tsxSpreadAttributesResolution17.types create mode 100644 tests/cases/conformance/jsx/tsxSpreadAttributesResolution17.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f418dbabcb8..f4d8c99c471 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15310,7 +15310,7 @@ namespace ts { // If the targetAttributesType is an emptyObjectType, indicating that there is no property named 'props' on this instance type. // but there exists a sourceAttributesType, we need to explicitly give an error as normal assignability check allow excess properties and will pass. - if (targetAttributesType === emptyObjectType && (isTypeAny(sourceAttributesType) || (sourceAttributesType).properties.length > 0)) { + if (targetAttributesType === emptyObjectType && (isTypeAny(sourceAttributesType) || getPropertiesOfType(sourceAttributesType).length > 0)) { error(openingLikeElement, Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, unescapeLeadingUnderscores(getJsxElementPropertiesName())); } else { diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution17.js b/tests/baselines/reference/tsxSpreadAttributesResolution17.js new file mode 100644 index 00000000000..81b1f073514 --- /dev/null +++ b/tests/baselines/reference/tsxSpreadAttributesResolution17.js @@ -0,0 +1,47 @@ +//// [file.tsx] +declare global { + namespace JSX { + interface Element {} + interface ElementAttributesProperty { props: {} } + } +} +declare var React: any; + +export class Empty extends React.Component<{}, {}> { + render() { + return
Hello
; + } +} + +declare const obj: { a: number | undefined } | undefined; + +// OK +let unionedSpread = ; + + +//// [file.jsx] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var Empty = /** @class */ (function (_super) { + __extends(Empty, _super); + function Empty() { + return _super !== null && _super.apply(this, arguments) || this; + } + Empty.prototype.render = function () { + return
Hello
; + }; + return Empty; +}(React.Component)); +exports.Empty = Empty; +// OK +var unionedSpread = ; diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution17.symbols b/tests/baselines/reference/tsxSpreadAttributesResolution17.symbols new file mode 100644 index 00000000000..6f346ccdcb1 --- /dev/null +++ b/tests/baselines/reference/tsxSpreadAttributesResolution17.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/jsx/file.tsx === +declare global { +>global : Symbol(global, Decl(file.tsx, 0, 0)) + + namespace JSX { +>JSX : Symbol(JSX, Decl(file.tsx, 0, 16)) + + interface Element {} +>Element : Symbol(Element, Decl(file.tsx, 1, 19)) + + interface ElementAttributesProperty { props: {} } +>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(file.tsx, 2, 28)) +>props : Symbol(ElementAttributesProperty.props, Decl(file.tsx, 3, 45)) + } +} +declare var React: any; +>React : Symbol(React, Decl(file.tsx, 6, 11)) + +export class Empty extends React.Component<{}, {}> { +>Empty : Symbol(Empty, Decl(file.tsx, 6, 23)) +>React : Symbol(React, Decl(file.tsx, 6, 11)) + + render() { +>render : Symbol(Empty.render, Decl(file.tsx, 8, 52)) + + return
Hello
; +>div : Symbol(unknown) +>div : Symbol(unknown) + } +} + +declare const obj: { a: number | undefined } | undefined; +>obj : Symbol(obj, Decl(file.tsx, 14, 13)) +>a : Symbol(a, Decl(file.tsx, 14, 20)) + +// OK +let unionedSpread = ; +>unionedSpread : Symbol(unionedSpread, Decl(file.tsx, 17, 3)) +>Empty : Symbol(Empty, Decl(file.tsx, 6, 23)) +>obj : Symbol(obj, Decl(file.tsx, 14, 13)) + diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution17.types b/tests/baselines/reference/tsxSpreadAttributesResolution17.types new file mode 100644 index 00000000000..9477e7366ee --- /dev/null +++ b/tests/baselines/reference/tsxSpreadAttributesResolution17.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/jsx/file.tsx === +declare global { +>global : any + + namespace JSX { +>JSX : any + + interface Element {} +>Element : Element + + interface ElementAttributesProperty { props: {} } +>ElementAttributesProperty : ElementAttributesProperty +>props : {} + } +} +declare var React: any; +>React : any + +export class Empty extends React.Component<{}, {}> { +>Empty : Empty +>React.Component : any +>React : any +>Component : any + + render() { +>render : () => JSX.Element + + return
Hello
; +>
Hello
: JSX.Element +>div : any +>div : any + } +} + +declare const obj: { a: number | undefined } | undefined; +>obj : { a: number | undefined; } | undefined +>a : number | undefined + +// OK +let unionedSpread = ; +>unionedSpread : JSX.Element +> : JSX.Element +>Empty : typeof Empty +>obj : { a: number | undefined; } | undefined + diff --git a/tests/cases/conformance/jsx/tsxSpreadAttributesResolution17.tsx b/tests/cases/conformance/jsx/tsxSpreadAttributesResolution17.tsx new file mode 100644 index 00000000000..da5638d3e2a --- /dev/null +++ b/tests/cases/conformance/jsx/tsxSpreadAttributesResolution17.tsx @@ -0,0 +1,25 @@ +// @strictNullChecks: true +// @filename: file.tsx +// @jsx: preserve +// @noLib: true +// @skipLibCheck: true +// @libFiles: lib.d.ts + +declare global { + namespace JSX { + interface Element {} + interface ElementAttributesProperty { props: {} } + } +} +declare var React: any; + +export class Empty extends React.Component<{}, {}> { + render() { + return
Hello
; + } +} + +declare const obj: { a: number | undefined } | undefined; + +// OK +let unionedSpread = ; From a05f669f43d4e52b2fe4e349d9968b61d3090ae4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 22 Jan 2018 16:40:29 -0800 Subject: [PATCH 14/41] Expose sort and deduplicate diagnostics in Public API Fixes #20876 --- src/compiler/core.ts | 8 ++++---- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ae506fd616a..e927bd35382 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -16,6 +16,10 @@ namespace ts { // Update: We also consider a path like `C:\foo.ts` "relative" because we do not search for it in `node_modules` or treat it as an ambient module. return pathIsRelative(moduleName) || isRootedDiskPath(moduleName); } + + export function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[] { + return sortAndDeduplicate(diagnostics, compareDiagnostics); + } } /* @internal */ @@ -1897,10 +1901,6 @@ namespace ts { return text1 ? Comparison.GreaterThan : Comparison.LessThan; } - export function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[] { - return sortAndDeduplicate(diagnostics, compareDiagnostics); - } - export function normalizeSlashes(path: string): string { return path.replace(/\\/g, "/"); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index cd1b577b711..8c244f3d4e0 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2814,6 +2814,7 @@ declare namespace ts { } declare namespace ts { function isExternalModuleNameRelative(moduleName: string): boolean; + function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[]; } declare function setTimeout(handler: (...args: any[]) => void, timeout: number): any; declare function clearTimeout(handle: any): void; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3cbca96f8fa..2933d11e5cb 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2814,6 +2814,7 @@ declare namespace ts { } declare namespace ts { function isExternalModuleNameRelative(moduleName: string): boolean; + function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[]; } declare function setTimeout(handler: (...args: any[]) => void, timeout: number): any; declare function clearTimeout(handle: any): void; From 6cc17f1cd9169ec02eb1d5a0573f3691ab561465 Mon Sep 17 00:00:00 2001 From: csigs Date: Tue, 23 Jan 2018 10:10:51 +0000 Subject: [PATCH 15/41] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl index b6b35ec094b..7ef4d27d021 100644 --- a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -582,6 +582,15 @@ + + + + + + + + + @@ -3378,15 +3387,6 @@ - - - - - - - - - @@ -3573,6 +3573,15 @@ + + + + + + + + + @@ -6603,11 +6612,11 @@ - + - + - + From 0e46086e7e7323461306bbb1ff4261e2800a283a Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 23 Jan 2018 08:09:15 -0800 Subject: [PATCH 16/41] In getSpecialPropertyExport, add debug failure when symbol parent is not a module (#21347) * In getSpecialPropertyExport, add debug failure when symbol parent is not a module * Fix lint --- src/services/importTracker.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index d2ce802f177..a8f724cb4be 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -510,11 +510,32 @@ namespace ts.FindAllReferences { return undefined; } - const sym = useLhsSymbol ? checker.getSymbolAtLocation((node.left as ts.PropertyAccessExpression).name) : symbol; + const sym = useLhsSymbol ? checker.getSymbolAtLocation(cast(node.left, isPropertyAccessExpression).name) : symbol; + // Better detection for GH#20803 + if (sym && !(checker.getMergedSymbol(sym.parent).flags & SymbolFlags.Module)) { + Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${showSymbol(sym)}, parent is ${showSymbol(sym.parent)}`); + } return sym && exportInfo(sym, kind); } } + function showSymbol(s: Symbol): string { + const decls = s.declarations.map(d => (ts as any).SyntaxKind[d.kind]).join(","); + const flags = showFlags(s.flags, (ts as any).SymbolFlags); + return `{ declarations: ${decls}, flags: ${flags} }`; + } + + function showFlags(f: number, flags: any) { + const out = []; + for (let pow = 0; pow <= 30; pow++) { + const n = 1 << pow; + if (f & n) { + out.push(flags[n]); + } + } + return out.join("|"); + } + function getImport(): ImportedSymbol | undefined { const isImport = isNodeImport(node); if (!isImport) return undefined; From 9dc01bf8bdd4a5c98c14fd1d21c302bc0df47173 Mon Sep 17 00:00:00 2001 From: csigs Date: Tue, 23 Jan 2018 17:10:12 +0000 Subject: [PATCH 17/41] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- 5 files changed, 105 insertions(+), 60 deletions(-) diff --git a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl index a678f69e80e..7ae7fab1b3b 100644 --- a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl index a58de23e3ff..7cc0cf16633 100644 --- a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl index d111d8f84b5..1262a3743cf 100644 --- a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -582,6 +582,15 @@ + + + + + + + + + @@ -3378,15 +3387,6 @@ - - - - - - - - - @@ -3573,6 +3573,15 @@ + + + + + + + + + @@ -6603,11 +6612,11 @@ - + - + - + diff --git a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 1f62aefc8ab..551a0e28806 100644 --- a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl index 2481a1b8752..d9b0532182c 100644 --- a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + From d4b3bd16c4deaec427fbfdc304cdd1b23a36de2a Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 23 Jan 2018 10:57:35 -0800 Subject: [PATCH 18/41] Add KeywordCompletionFilters.TypeKeywords (#21364) --- src/services/completions.ts | 86 ++++++++----------- src/services/utilities.ts | 4 + .../fourslash/completionsTypeKeywords.ts | 7 ++ 3 files changed, 46 insertions(+), 51 deletions(-) create mode 100644 tests/cases/fourslash/completionsTypeKeywords.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 80fdf6c280e..8b7f564ff08 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -20,7 +20,8 @@ namespace ts.Completions { None, ClassElementKeywords, // Keywords at class keyword ConstructorParameterKeywords, // Keywords at constructor parameter - FunctionLikeBodyKeywords // Keywords at function like body + FunctionLikeBodyKeywords, // Keywords at function like body + TypeKeywords, } export function getCompletionsAtPosition( @@ -565,7 +566,7 @@ namespace ts.Completions { } case "none": { // Didn't find a symbol with this name. See if we can find a keyword instead. - if (some(getKeywordCompletions(KeywordCompletionFilters.None), c => c.name === name)) { + if (allKeywordsCompletions().some(c => c.name === name)) { return { name, kind: ScriptElementKind.keyword, @@ -1163,6 +1164,9 @@ namespace ts.Completions { } function filterGlobalCompletion(symbols: Symbol[]): void { + const isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); + if (isTypeCompletion) keywordFilters = KeywordCompletionFilters.TypeKeywords; + filterMutate(symbols, symbol => { if (!isSourceFile(location)) { // export = /**/ here we want to get all meanings, so any symbol is ok @@ -1170,19 +1174,14 @@ namespace ts.Completions { return true; } - // This is an alias, follow what it aliases - if (symbol && symbol.flags & SymbolFlags.Alias) { - symbol = typeChecker.getAliasedSymbol(symbol); - } + symbol = skipAlias(symbol, typeChecker); // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace) if (isInRightSideOfInternalImportEqualsDeclaration(location)) { return !!(symbol.flags & SymbolFlags.Namespace); } - if (insideJsDocTagTypeExpression || - (!isContextTokenValueLocation(contextToken) && - (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)))) { + if (isTypeCompletion) { // Its a type, but you can reach it by namespace.type as well return symbolCanBeReferencedAtTypeLocation(symbol); } @@ -1199,7 +1198,7 @@ namespace ts.Completions { contextToken.parent.kind === SyntaxKind.TypeQuery; } - function isContextTokenTypeLocation(contextToken: Node) { + function isContextTokenTypeLocation(contextToken: Node): boolean { if (contextToken) { const parentKind = contextToken.parent.kind; switch (contextToken.kind) { @@ -1217,6 +1216,7 @@ namespace ts.Completions { return parentKind === SyntaxKind.AsExpression; } } + return false; } function symbolCanBeReferencedAtTypeLocation(symbol: Symbol): boolean { @@ -2130,51 +2130,38 @@ namespace ts.Completions { } // A cache of completion entries for keywords, these do not change between sessions - const _keywordCompletions: CompletionEntry[][] = []; - function getKeywordCompletions(keywordFilter: KeywordCompletionFilters): CompletionEntry[] { - const completions = _keywordCompletions[keywordFilter]; - if (completions) { - return completions; + const _keywordCompletions: ReadonlyArray[] = []; + const allKeywordsCompletions: () => ReadonlyArray = ts.memoize(() => { + const res: CompletionEntry[] = []; + for (let i = SyntaxKind.FirstKeyword; i <= SyntaxKind.LastKeyword; i++) { + res.push({ + name: tokenToString(i), + kind: ScriptElementKind.keyword, + kindModifiers: ScriptElementKindModifier.none, + sortText: "0" + }); } - return _keywordCompletions[keywordFilter] = generateKeywordCompletions(keywordFilter); - - type FilterKeywordCompletions = (entryName: string) => boolean; - function generateKeywordCompletions(keywordFilter: KeywordCompletionFilters): CompletionEntry[] { + return res; + }); + function getKeywordCompletions(keywordFilter: KeywordCompletionFilters): ReadonlyArray { + return _keywordCompletions[keywordFilter] || (_keywordCompletions[keywordFilter] = allKeywordsCompletions().filter(entry => { + const kind = stringToToken(entry.name); switch (keywordFilter) { case KeywordCompletionFilters.None: - return getAllKeywordCompletions(); + // "undefined" is a global variable, so don't need a keyword completion for it. + return kind !== SyntaxKind.UndefinedKeyword; case KeywordCompletionFilters.ClassElementKeywords: - return getFilteredKeywordCompletions(isClassMemberCompletionKeywordText); + return isClassMemberCompletionKeyword(kind); case KeywordCompletionFilters.ConstructorParameterKeywords: - return getFilteredKeywordCompletions(isConstructorParameterCompletionKeywordText); + return isConstructorParameterCompletionKeyword(kind); case KeywordCompletionFilters.FunctionLikeBodyKeywords: - return getFilteredKeywordCompletions(isFunctionLikeBodyCompletionKeywordText); + return isFunctionLikeBodyCompletionKeyword(kind); + case KeywordCompletionFilters.TypeKeywords: + return isTypeKeyword(kind); default: - Debug.assertNever(keywordFilter); + return Debug.assertNever(keywordFilter); } - } - - function getAllKeywordCompletions() { - const allKeywordsCompletions: CompletionEntry[] = []; - for (let i = SyntaxKind.FirstKeyword; i <= SyntaxKind.LastKeyword; i++) { - // "undefined" is a global variable, so don't need a keyword completion for it. - if (i === SyntaxKind.UndefinedKeyword) continue; - allKeywordsCompletions.push({ - name: tokenToString(i), - kind: ScriptElementKind.keyword, - kindModifiers: ScriptElementKindModifier.none, - sortText: "0" - }); - } - return allKeywordsCompletions; - } - - function getFilteredKeywordCompletions(filterFn: FilterKeywordCompletions) { - return filter( - getKeywordCompletions(KeywordCompletionFilters.None), - entry => filterFn(entry.name) - ); - } + })); } function isClassMemberCompletionKeyword(kind: SyntaxKind) { @@ -2222,15 +2209,12 @@ namespace ts.Completions { case SyntaxKind.AbstractKeyword: case SyntaxKind.GetKeyword: case SyntaxKind.SetKeyword: + case SyntaxKind.UndefinedKeyword: return false; } return true; } - function isFunctionLikeBodyCompletionKeywordText(text: string) { - return isFunctionLikeBodyCompletionKeyword(stringToToken(text)); - } - function isEqualityOperatorKind(kind: ts.SyntaxKind): kind is EqualityOperator { switch (kind) { case ts.SyntaxKind.EqualsEqualsEqualsToken: diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 9bb35359523..c724fa5643d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1070,12 +1070,16 @@ namespace ts { export const typeKeywords: ReadonlyArray = [ SyntaxKind.AnyKeyword, SyntaxKind.BooleanKeyword, + SyntaxKind.KeyOfKeyword, SyntaxKind.NeverKeyword, + SyntaxKind.NullKeyword, SyntaxKind.NumberKeyword, SyntaxKind.ObjectKeyword, SyntaxKind.StringKeyword, SyntaxKind.SymbolKeyword, SyntaxKind.VoidKeyword, + SyntaxKind.UndefinedKeyword, + SyntaxKind.UniqueKeyword, ]; export function isTypeKeyword(kind: SyntaxKind): boolean { diff --git a/tests/cases/fourslash/completionsTypeKeywords.ts b/tests/cases/fourslash/completionsTypeKeywords.ts new file mode 100644 index 00000000000..198d6dddab4 --- /dev/null +++ b/tests/cases/fourslash/completionsTypeKeywords.ts @@ -0,0 +1,7 @@ +/// + +////type T = /**/ + +goTo.marker(); +verify.completionListContains("undefined", "undefined", undefined, "keyword"); +verify.not.completionListContains("await"); From 4f11dd68abf969b6ad0f7f08185e68e291cd54d5 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Tue, 23 Jan 2018 10:39:26 -0800 Subject: [PATCH 19/41] Handle extracting case clause expression as constant --- src/harness/unittests/extractConstants.ts | 7 +++++++ src/services/refactors/extractSymbol.ts | 7 +++++++ .../extractConstant_CaseClauseExpression.js | 13 +++++++++++++ .../extractConstant_CaseClauseExpression.ts | 13 +++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.js create mode 100644 tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.ts diff --git a/src/harness/unittests/extractConstants.ts b/src/harness/unittests/extractConstants.ts index 71b550cba8f..9dfb1264a70 100644 --- a/src/harness/unittests/extractConstants.ts +++ b/src/harness/unittests/extractConstants.ts @@ -273,6 +273,13 @@ let i: I = [#|{ a: 1 }|]; const myObj: { member(x: number, y: string): void } = { member: [#|(x, y) => x + y|], } +`); + + testExtractConstant("extractConstant_CaseClauseExpression", ` +switch (1) { + case [#|1|]: + break; +} `); }); diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 479c387fc65..f9a46f04914 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -1321,6 +1321,13 @@ namespace ts.refactor.extractSymbol { } prevStatement = statement; } + + if (!prevStatement && isCaseClause(curr)) { + // We must have been in the expression of the case clause. + Debug.assert(isSwitchStatement(curr.parent.parent)); + return curr.parent.parent; + } + // There must be at least one statement since we started in one. Debug.assert(prevStatement !== undefined); return prevStatement; diff --git a/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.js b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.js new file mode 100644 index 00000000000..0031ecdf0f9 --- /dev/null +++ b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.js @@ -0,0 +1,13 @@ +// ==ORIGINAL== + +switch (1) { + case /*[#|*/1/*|]*/: + break; +} + +// ==SCOPE::Extract to constant in enclosing scope== +const newLocal = 1; +switch (1) { + case /*RENAME*/newLocal: + break; +} diff --git a/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.ts b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.ts new file mode 100644 index 00000000000..0031ecdf0f9 --- /dev/null +++ b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.ts @@ -0,0 +1,13 @@ +// ==ORIGINAL== + +switch (1) { + case /*[#|*/1/*|]*/: + break; +} + +// ==SCOPE::Extract to constant in enclosing scope== +const newLocal = 1; +switch (1) { + case /*RENAME*/newLocal: + break; +} From 2f3b06a3cd5ca8c394828fee9c0c96f85f54f903 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Tue, 23 Jan 2018 11:07:59 -0800 Subject: [PATCH 20/41] Handle extraction ranges including case clause expressions (mostly by rejecting them) Fixes #20559 --- src/harness/unittests/extractRanges.ts | 46 +++++++++++++++++++++++++ src/services/refactors/extractSymbol.ts | 11 ++++++ 2 files changed, 57 insertions(+) diff --git a/src/harness/unittests/extractRanges.ts b/src/harness/unittests/extractRanges.ts index 493c9639c3d..2810f323abf 100644 --- a/src/harness/unittests/extractRanges.ts +++ b/src/harness/unittests/extractRanges.ts @@ -365,6 +365,52 @@ switch (x) { refactor.extractSymbol.Messages.cannotExtractRange.message ]); + testExtractRangeFailed("extractRangeFailed14", + ` + switch(1) { + case [#|1: + break;|] + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + + testExtractRangeFailed("extractRangeFailed15", + ` + switch(1) { + case [#|1: + break|]; + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + + // Documentation only - it would be nice if the result were [$|1|] + testExtractRangeFailed("extractRangeFailed16", + ` + switch(1) { + [#|case 1|]: + break; + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + + // Documentation only - it would be nice if the result were [$|1|] + testExtractRangeFailed("extractRangeFailed17", + ` + switch(1) { + [#|case 1:|] + break; + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, [refactor.extractSymbol.Messages.cannotExtractIdentifier.message]); }); } \ No newline at end of file diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index f9a46f04914..e8a2186aa8b 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -235,6 +235,17 @@ namespace ts.refactor.extractSymbol { break; } } + + if (!statements.length) { + // https://github.com/Microsoft/TypeScript/issues/20559 + // Ranges like [|case 1: break;|] will fail to populate `statements` because + // they will never find `start` in `start.parent.statements`. + // Consider: We could support ranges like [|case 1:|] by refining them to just + // the expression. + Debug.assert(isCaseClause(start.parent) && span.start < start.parent.expression.end); + return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] }; + } + return { targetRange: { range: statements, facts: rangeFacts, declarations } }; } From cd833890778c01260accd0198ea8e7240e00e4df Mon Sep 17 00:00:00 2001 From: csigs Date: Tue, 23 Jan 2018 23:11:17 +0000 Subject: [PATCH 21/41] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- 4 files changed, 84 insertions(+), 48 deletions(-) diff --git a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl index 63f0270005a..7579d5ce794 100644 --- a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 74cf056e95a..400187f844a 100644 --- a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -566,6 +566,15 @@ + + + + + + + + + @@ -3359,15 +3368,6 @@ - - - - - - - - - @@ -3554,6 +3554,15 @@ + + + + + + + + + @@ -6578,11 +6587,11 @@ - + - + - + diff --git a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl index ced875a6581..46dce16bc93 100644 --- a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -572,6 +572,15 @@ + + + + + + + + + @@ -3368,15 +3377,6 @@ - - - - - - - - - @@ -3563,6 +3563,15 @@ + + + + + + + + + @@ -6593,11 +6602,11 @@ - + - + - + diff --git a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 3b9a3824b9f..c1894d0db09 100644 --- a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -566,6 +566,15 @@ + + + + + + + + + @@ -3362,15 +3371,6 @@ - - - - - - - - - @@ -3557,6 +3557,15 @@ + + + + + + + + + @@ -6587,11 +6596,11 @@ - + - + - + From d7ed6402a53c1aa432119273e6bb69a5a896c512 Mon Sep 17 00:00:00 2001 From: csigs Date: Wed, 24 Jan 2018 05:10:14 +0000 Subject: [PATCH 22/41] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 5d1bc276ee8..3ad2bbf63b2 100644 --- a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -582,6 +582,15 @@ + + + + + + + + + @@ -3378,15 +3387,6 @@ - - - - - - - - - @@ -3573,6 +3573,15 @@ + + + + + + + + + @@ -6603,11 +6612,11 @@ - + - + - + diff --git a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl index 4be92ea0534..b6290bed3fb 100644 --- a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -566,6 +566,15 @@ + + + + + + + + + @@ -3359,15 +3368,6 @@ - - - - - - - - - @@ -3554,6 +3554,15 @@ + + + + + + + + + @@ -6578,11 +6587,11 @@ - + - + - + From 5df27c1cd69b54dc3218d0c9e681940966bebc70 Mon Sep 17 00:00:00 2001 From: csigs Date: Wed, 24 Jan 2018 11:10:38 +0000 Subject: [PATCH 23/41] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl index afee7120010..7fe309d50f8 100644 --- a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3366,15 +3375,6 @@ - - - - - - - - - @@ -3561,6 +3561,15 @@ + + + + + + + + + @@ -6585,11 +6594,11 @@ - + - + - + From 77c5529e93ae1d5e4d21bc2bc3e8d573c7d69fa1 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 24 Jan 2018 10:58:41 -0800 Subject: [PATCH 24/41] Make error span for wrong type arguments be just `<...>`,d not `f<...>(...)` (#21390) --- src/compiler/checker.ts | 4 +- src/compiler/utilities.ts | 5 ++ ...signingFromObjectToAnythingElse.errors.txt | 8 +-- ...hIncorrectNumberOfTypeArguments.errors.txt | 56 +++++++++---------- ...enericFunctionWithTypeArguments.errors.txt | 28 +++++----- ...lWithWrongNumberOfTypeArguments.errors.txt | 8 +-- ...torInvocationWithTooFewTypeArgs.errors.txt | 4 +- .../emptyTypeArgumentList.errors.txt | 8 +-- .../emptyTypeArgumentListWithNew.errors.txt | 8 +-- ...kedInsideItsContainingFunction1.errors.txt | 24 ++++---- .../genericDefaultsErrors.errors.txt | 8 +-- .../genericWithOpenTypeParameters1.errors.txt | 8 +-- ...sWithWrongNumberOfTypeArguments.errors.txt | 8 +-- ...NonGenericTypeWithTypeArguments.errors.txt | 12 ++-- ...citTypeParameterAndArgumentType.errors.txt | 4 +- .../reference/overloadResolution.errors.txt | 4 +- ...loadResolutionClassConstructors.errors.txt | 12 ++-- .../overloadResolutionConstructors.errors.txt | 4 +- ...loadsAndTypeArgumentArityErrors.errors.txt | 8 +-- .../parserConstructorAmbiguity3.errors.txt | 6 +- ...CallExpressionWithTypeArguments.errors.txt | 4 +- .../tooManyTypeParameters1.errors.txt | 12 ++-- ...OnFunctionsWithNoTypeParameters.errors.txt | 8 +-- .../reference/typeAssertions.errors.txt | 4 +- ...unctionCallsWithTypeParameters1.errors.txt | 16 +++--- 25 files changed, 138 insertions(+), 133 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 01b3a047d1d..bb1fbbdd526 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16717,7 +16717,7 @@ namespace ts { const isDecorator = node.kind === SyntaxKind.Decorator; const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node); - let typeArguments: ReadonlyArray; + let typeArguments: NodeArray; if (!isTaggedTemplate && !isDecorator && !isJsxOpeningOrSelfClosingElement) { typeArguments = (node).typeArguments; @@ -16846,7 +16846,7 @@ namespace ts { max = Math.max(max, length(sig.typeParameters)); } const paramCount = min < max ? min + "-" + max : min; - diagnostics.add(createDiagnosticForNode(node, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length)); + diagnostics.add(createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length)); } else if (args) { let min = Number.POSITIVE_INFINITY; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bf6a086967c..f4ddf1d8319 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -599,6 +599,11 @@ namespace ts { return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2, arg3); } + export function createDiagnosticForNodeArray(sourceFile: SourceFile, nodes: NodeArray, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): Diagnostic { + const start = skipTrivia(sourceFile.text, nodes.pos); + return createFileDiagnostic(sourceFile, start, nodes.end - start, message, arg0, arg1, arg2, arg3); + } + export function createDiagnosticForNodeInSourceFile(sourceFile: SourceFile, node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): Diagnostic { const span = getErrorSpanForNode(sourceFile, node); return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2, arg3); diff --git a/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt index c8fb57e3616..bc92c376c7c 100644 --- a/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt +++ b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/assigningFromObjectToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Property 'exec' is missing in type 'Object'. -tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,17): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,17): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,31): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,31): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Property 'name' is missing in type 'Object'. @@ -18,10 +18,10 @@ tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Ty !!! error TS2322: Property 'exec' is missing in type 'Object'. var a: String = Object.create(""); - ~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var c: String = Object.create(1); - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var w: Error = new Object(); diff --git a/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt b/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt index 6d95b588ebf..d5809d677e4 100644 --- a/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt @@ -1,17 +1,17 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(5,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(6,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(9,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(10,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(13,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(14,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(21,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(22,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(28,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(29,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(36,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(37,11): error TS2558: Expected 0 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(43,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(44,11): error TS2558: Expected 0 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(5,12): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(6,13): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(9,13): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(10,14): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(13,13): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(14,14): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(21,22): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(22,23): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(28,14): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(29,15): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(36,23): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(37,24): error TS2558: Expected 0 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(43,15): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(44,16): error TS2558: Expected 0 type arguments, but got 3. ==== tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts (14 errors) ==== @@ -20,26 +20,26 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti function f(x: T, y: U): T { return null; } var r1 = f(1, ''); - ~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r1b = f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. var f2 = (x: T, y: U): T => { return null; } var r2 = f2(1, ''); - ~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r2b = f2(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. var f3: { (x: T, y: U): T; } var r3 = f3(1, ''); - ~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r3b = f3(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. class C { @@ -48,10 +48,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } } var r4 = (new C()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r4b = (new C()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. interface I { @@ -59,10 +59,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } var i: I; var r5 = i.f(1, ''); - ~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r5b = i.f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. class C2 { @@ -71,10 +71,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } } var r6 = (new C2()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r6b = (new C2()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 3. interface I2 { @@ -82,8 +82,8 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } var i2: I2; var r7 = i2.f(1, ''); - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r7b = i2.f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 3. \ No newline at end of file diff --git a/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt b/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt index b014eae0fd8..6bfb0c1113e 100644 --- a/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt +++ b/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(5,9): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(8,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(11,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(18,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(24,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(31,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(37,10): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(5,11): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(8,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(11,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(18,22): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(24,14): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(31,23): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(37,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(40,10): error TS2347: Untyped function calls may not accept type arguments. tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(43,10): error TS2347: Untyped function calls may not accept type arguments. @@ -15,17 +15,17 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun function f(x: number) { return null; } var r = f(1); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f2 = (x: number) => { return null; } var r2 = f2(1); - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f3: { (x: number): any; } var r3 = f3(1); - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. class C { @@ -34,7 +34,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } } var r4 = (new C()).f(1); - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface I { @@ -42,7 +42,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } var i: I; var r5 = i.f(1); - ~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. class C2 { @@ -51,7 +51,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } } var r6 = (new C2()).f(1); - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface I2 { @@ -59,7 +59,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } var i2: I2; var r7 = i2.f(1); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var a; diff --git a/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt b/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt index e3fca9dff9c..c8553e8fc0d 100644 --- a/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(3,1): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(5,1): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(3,3): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(5,3): error TS2558: Expected 2 type arguments, but got 3. ==== tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts (2 errors) ==== function f() { } f(); - ~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. f(); f(); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. \ No newline at end of file diff --git a/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt b/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt index 265ce4686db..10dd4ad82fb 100644 --- a/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt +++ b/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts(9,9): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts(9,15): error TS2558: Expected 2 type arguments, but got 1. ==== tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts(9,9): error TS25 } var d = new D(); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentList.errors.txt b/tests/baselines/reference/emptyTypeArgumentList.errors.txt index 036f307447b..395c990a3d9 100644 --- a/tests/baselines/reference/emptyTypeArgumentList.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentList.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/emptyTypeArgumentList.ts(2,1): error TS2558: Expected 1 type arguments, but got 0. tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty. +tests/cases/compiler/emptyTypeArgumentList.ts(2,5): error TS2558: Expected 1 type arguments, but got 0. ==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ==== function foo() { } foo<>(); - ~~~~~~~ -!!! error TS2558: Expected 1 type arguments, but got 0. ~~ -!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file +!!! error TS1099: Type argument list cannot be empty. + +!!! error TS2558: Expected 1 type arguments, but got 0. \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt index 648aa7c6c50..92eb250291a 100644 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,1): error TS2558: Expected 1 type arguments, but got 0. tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty. +tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,9): error TS2558: Expected 1 type arguments, but got 0. ==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ==== class foo { } new foo<>(); - ~~~~~~~~~~~ -!!! error TS2558: Expected 1 type arguments, but got 0. ~~ -!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file +!!! error TS1099: Type argument list cannot be empty. + +!!! error TS2558: Expected 1 type arguments, but got 0. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt b/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt index 7ff051bd63e..ff4c2235b49 100644 --- a/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt +++ b/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt @@ -1,32 +1,32 @@ -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(2,14): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(2,16): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(3,16): error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(4,14): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(8,15): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(9,15): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(4,16): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(8,17): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(9,17): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(12,17): error TS2345: Argument of type 'U' is not assignable to parameter of type 'T'. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(13,15): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(14,15): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(13,17): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(14,17): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts (8 errors) ==== function foo(x:T, y:U, f: (v: T) => U) { var r1 = f(1); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r2 = f(1); ~ !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. var r3 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r4 = f(null); var r11 = f(x); var r21 = f(x); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r31 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r41 = f(null); @@ -34,10 +34,10 @@ tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(14,15 ~ !!! error TS2345: Argument of type 'U' is not assignable to parameter of type 'T'. var r22 = f(y); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r32 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r42 = f(null); } \ No newline at end of file diff --git a/tests/baselines/reference/genericDefaultsErrors.errors.txt b/tests/baselines/reference/genericDefaultsErrors.errors.txt index b1afd6f173b..e1dca77d958 100644 --- a/tests/baselines/reference/genericDefaultsErrors.errors.txt +++ b/tests/baselines/reference/genericDefaultsErrors.errors.txt @@ -3,8 +3,8 @@ tests/cases/compiler/genericDefaultsErrors.ts(4,59): error TS2344: Type 'T' does Type 'string' is not assignable to type 'number'. tests/cases/compiler/genericDefaultsErrors.ts(5,44): error TS2344: Type 'T' does not satisfy the constraint 'number'. tests/cases/compiler/genericDefaultsErrors.ts(6,39): error TS2344: Type 'number' does not satisfy the constraint 'T'. -tests/cases/compiler/genericDefaultsErrors.ts(10,1): error TS2558: Expected 2-3 type arguments, but got 1. -tests/cases/compiler/genericDefaultsErrors.ts(13,1): error TS2558: Expected 2-3 type arguments, but got 4. +tests/cases/compiler/genericDefaultsErrors.ts(10,5): error TS2558: Expected 2-3 type arguments, but got 1. +tests/cases/compiler/genericDefaultsErrors.ts(13,5): error TS2558: Expected 2-3 type arguments, but got 4. tests/cases/compiler/genericDefaultsErrors.ts(17,13): error TS2345: Argument of type '"a"' is not assignable to parameter of type 'number'. tests/cases/compiler/genericDefaultsErrors.ts(19,11): error TS2428: All declarations of 'i00' must have identical type parameters. tests/cases/compiler/genericDefaultsErrors.ts(20,11): error TS2428: All declarations of 'i00' must have identical type parameters. @@ -44,12 +44,12 @@ tests/cases/compiler/genericDefaultsErrors.ts(42,29): error TS2716: Type paramet declare function f11(): void; f11(); // ok f11<1>(); // error - ~~~~~~~~ + ~ !!! error TS2558: Expected 2-3 type arguments, but got 1. f11<1, 2>(); // ok f11<1, 2, 3>(); // ok f11<1, 2, 3, 4>(); // error - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~ !!! error TS2558: Expected 2-3 type arguments, but got 4. declare function f12(a?: U): void; diff --git a/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt b/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt index 9f8694d2fca..6a243650b1e 100644 --- a/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt +++ b/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/genericWithOpenTypeParameters1.ts(7,40): error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. -tests/cases/compiler/genericWithOpenTypeParameters1.ts(8,35): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericWithOpenTypeParameters1.ts(9,35): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericWithOpenTypeParameters1.ts(8,41): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericWithOpenTypeParameters1.ts(9,41): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/genericWithOpenTypeParameters1.ts (3 errors) ==== @@ -14,10 +14,10 @@ tests/cases/compiler/genericWithOpenTypeParameters1.ts(9,35): error TS2558: Expe ~ !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. var f2 = (x: B) => { return x.foo(1); } // error - ~~~~~~~~~~~ + ~ !!! error TS2558: Expected 0 type arguments, but got 1. var f3 = (x: B) => { return x.foo(1); } // error - ~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f4 = (x: B) => { return x.foo(1); } // no error \ No newline at end of file diff --git a/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt b/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt index 05cc1ee1cd0..a09b424b8e1 100644 --- a/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(8,9): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(16,9): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(8,15): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(16,15): error TS2558: Expected 2 type arguments, but got 1. ==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts (2 errors) ==== @@ -11,7 +11,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGeneri } var c = new C(); - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. class D { @@ -21,5 +21,5 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGeneri // BUG 794238 var d = new D(); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. \ No newline at end of file diff --git a/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt b/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt index 196af18aa9a..5e70aa31249 100644 --- a/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt +++ b/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(8,9): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(8,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(11,9): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(11,9): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(11,17): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(14,10): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(14,10): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(14,16): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(18,10): error TS2347: Untyped function calls may not accept type arguments. @@ -15,21 +15,21 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGen } var c = new C(); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. function Foo(): void { } var r = new Foo(); ~~~~~~~~~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. - ~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f: { (): void }; var r2 = new f(); ~~~~~~~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var a: any; diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index 9b95b143d64..f96dc69ee33 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,15): error TS2558: Expected 2 type arguments, but got 1. ==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (2 errors) ==== @@ -20,6 +20,6 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e !!! error TS2345: Type 'string | number' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r8 = map([1, ""], (x) => x.toString()); \ No newline at end of file diff --git a/tests/baselines/reference/overloadResolution.errors.txt b/tests/baselines/reference/overloadResolution.errors.txt index 37cea935e66..6710f697b3c 100644 --- a/tests/baselines/reference/overloadResolution.errors.txt +++ b/tests/baselines/reference/overloadResolution.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(27,5): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(41,11): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(63,1): error TS2558: Expected 1-3 type arguments, but got 4. +tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(63,5): error TS2558: Expected 1-3 type arguments, but got 4. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(70,21): error TS2345: Argument of type '3' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(71,21): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(81,5): error TS2344: Type 'boolean' does not satisfy the constraint 'number'. @@ -78,7 +78,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(91,22): // Generic overloads with differing arity called with type argument count that doesn't match any overload fn3(); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 1-3 type arguments, but got 4. // Generic overloads with constraints called with type arguments that satisfy the constraints diff --git a/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt b/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt index 92f3a7cfa90..cfbc2605559 100644 --- a/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt +++ b/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(27,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(60,1): error TS2558: Expected 3 type arguments, but got 1. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(61,1): error TS2558: Expected 3 type arguments, but got 2. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(65,1): error TS2558: Expected 3 type arguments, but got 4. +tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(60,9): error TS2558: Expected 3 type arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(61,9): error TS2558: Expected 3 type arguments, but got 2. +tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(65,9): error TS2558: Expected 3 type arguments, but got 4. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(73,25): error TS2345: Argument of type '3' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(74,9): error TS2344: Type 'number' does not satisfy the constraint 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(75,9): error TS2344: Type 'number' does not satisfy the constraint 'string'. @@ -77,16 +77,16 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstru // Generic overloads with differing arity called with type arguments matching each overload type parameter count new fn3(4); // Error - ~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 3 type arguments, but got 1. new fn3('', '', ''); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2558: Expected 3 type arguments, but got 2. new fn3('', '', 3); // Generic overloads with differing arity called with type argument count that doesn't match any overload new fn3(); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 3 type arguments, but got 4. // Generic overloads with constraints called with type arguments that satisfy the constraints diff --git a/tests/baselines/reference/overloadResolutionConstructors.errors.txt b/tests/baselines/reference/overloadResolutionConstructors.errors.txt index 9b09992228e..fe1c955651b 100644 --- a/tests/baselines/reference/overloadResolutionConstructors.errors.txt +++ b/tests/baselines/reference/overloadResolutionConstructors.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(27,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(43,15): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(67,1): error TS2558: Expected 1-3 type arguments, but got 4. +tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(67,9): error TS2558: Expected 1-3 type arguments, but got 4. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(77,25): error TS2345: Argument of type '3' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(78,25): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(88,9): error TS2344: Type 'boolean' does not satisfy the constraint 'number'. @@ -82,7 +82,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors // Generic overloads with differing arity called with type argument count that doesn't match any overload new fn3(); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 1-3 type arguments, but got 4. // Generic overloads with constraints called with type arguments that satisfy the constraints diff --git a/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt b/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt index 52bcaaf790b..45a5616d188 100644 --- a/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt +++ b/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(5,1): error TS2558: Expected 0-2 type arguments, but got 3. +tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(5,11): error TS2558: Expected 0-2 type arguments, but got 3. tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,1): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,1): error TS2558: Expected 0-2 type arguments, but got 3. +tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,15): error TS2558: Expected 0-2 type arguments, but got 3. ==== tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts (3 errors) ==== @@ -9,10 +9,10 @@ tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,1): error TS2558: declare function Callbacks(flags?: string): void; Callbacks('s'); // wrong number of type arguments - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0-2 type arguments, but got 3. new Callbacks('s'); // wrong number of type arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0-2 type arguments, but got 3. \ No newline at end of file diff --git a/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt b/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt index c13916fa39d..cd58ed117f6 100644 --- a/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt +++ b/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,1): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,10): error TS2304: Cannot find name 'A'. +tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,10): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,12): error TS1005: '(' expected. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts (3 errors) ==== new Date - ~~~~~~~~~~~ -!!! error TS2558: Expected 0 type arguments, but got 1. ~ !!! error TS2304: Cannot find name 'A'. + ~ +!!! error TS2558: Expected 0 type arguments, but got 1. !!! error TS1005: '(' expected. \ No newline at end of file diff --git a/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt b/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt index 1dac3478c63..22f4632cef8 100644 --- a/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt +++ b/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/thisExpressionInCallExpressionWithTypeArguments.ts(2,20): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/thisExpressionInCallExpressionWithTypeArguments.ts(2,32): error TS2558: Expected 1 type arguments, but got 2. ==== tests/cases/compiler/thisExpressionInCallExpressionWithTypeArguments.ts (1 errors) ==== class C { public foo() { [1,2,3].map((x) => { return this; })} - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. } \ No newline at end of file diff --git a/tests/baselines/reference/tooManyTypeParameters1.errors.txt b/tests/baselines/reference/tooManyTypeParameters1.errors.txt index 7997e68b575..b966225bef5 100644 --- a/tests/baselines/reference/tooManyTypeParameters1.errors.txt +++ b/tests/baselines/reference/tooManyTypeParameters1.errors.txt @@ -1,23 +1,23 @@ -tests/cases/compiler/tooManyTypeParameters1.ts(2,1): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/compiler/tooManyTypeParameters1.ts(5,1): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/compiler/tooManyTypeParameters1.ts(8,9): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/tooManyTypeParameters1.ts(2,3): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/tooManyTypeParameters1.ts(5,3): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/tooManyTypeParameters1.ts(8,15): error TS2558: Expected 1 type arguments, but got 2. tests/cases/compiler/tooManyTypeParameters1.ts(11,8): error TS2314: Generic type 'I' requires 1 type argument(s). ==== tests/cases/compiler/tooManyTypeParameters1.ts (4 errors) ==== function f() { } f(); - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. var x = () => {}; x(); - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. class C {} var c = new C(); - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. interface I {} diff --git a/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt b/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt index 5c916331950..a162b997c0f 100644 --- a/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt +++ b/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt @@ -1,18 +1,18 @@ -tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(2,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(2,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(3,15): error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. -tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(4,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(4,15): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts (3 errors) ==== function foo(f: (v: T) => U) { var r1 = f(1); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r2 = f(1); ~ !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. var r3 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r4 = f(null); } diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index 45f20437860..cefc15b8e23 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,5): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,9): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'. Property 'p' is missing in type 'SomeOther'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'. @@ -29,7 +29,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): err function fn2(t: any) { } fn1(fn2(4)); // Error - ~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var a: any; diff --git a/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt b/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt index 6b6594fc1ed..d1a1b0f08f9 100644 --- a/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt +++ b/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt @@ -1,20 +1,20 @@ -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(3,10): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(3,12): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(5,10): error TS2347: Untyped function calls may not accept type arguments. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(8,10): error TS2347: Untyped function calls may not accept type arguments. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(10,7): error TS2420: Class 'C' incorrectly implements interface 'Function'. Property 'apply' is missing in type 'C'. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(18,10): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'C' has no compatible call signatures. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(22,10): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(28,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(35,1): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(28,12): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(35,4): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,4): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts (9 errors) ==== // none of these function calls should be allowed var x = function () { return; }; var r1 = x(); - ~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var y: any = x; var r2 = y(); @@ -52,7 +52,7 @@ tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2 } var z: I; var r6 = z(1); // error - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface callable2 { @@ -61,7 +61,7 @@ tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2 var c4: callable2; c4(1); - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface callable3 { (a: T): T; @@ -69,7 +69,7 @@ tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2 var c5: callable3; c5(1); // error - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. \ No newline at end of file From 1cc164b330929860f520cbad27e190cda621e00d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 24 Jan 2018 12:05:44 -0800 Subject: [PATCH 25/41] Update version (#21319) --- package.json | 2 +- src/compiler/core.ts | 2 +- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fb089b64918..d0ec2d70ce2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "2.7.0", + "version": "2.8.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ae506fd616a..cefa9367b48 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -4,7 +4,7 @@ namespace ts { // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. // If changing the text in this section, be sure to test `configureNightly` too. - export const versionMajorMinor = "2.7"; + export const versionMajorMinor = "2.8"; /** The version of the TypeScript compiler release */ export const version = `${versionMajorMinor}.0`; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index cd1b577b711..a2ded98383e 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2808,7 +2808,7 @@ declare namespace ts { } } declare namespace ts { - const versionMajorMinor = "2.7"; + const versionMajorMinor = "2.8"; /** The version of the TypeScript compiler release */ const version: string; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3cbca96f8fa..2cf666b1cf3 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2808,7 +2808,7 @@ declare namespace ts { } } declare namespace ts { - const versionMajorMinor = "2.7"; + const versionMajorMinor = "2.8"; /** The version of the TypeScript compiler release */ const version: string; } From ba797f2c50bd6bf211950bef932cb8fb64ec7cb2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 24 Jan 2018 12:37:45 -0800 Subject: [PATCH 26/41] Add flag to skip qualification check when symbol is already in the process of being qualified (#21337) --- src/compiler/checker.ts | 19 +++--- ...tionExportStarShadowingGlobalIsNameable.js | 60 +++++++++++++++++++ ...xportStarShadowingGlobalIsNameable.symbols | 49 +++++++++++++++ ...nExportStarShadowingGlobalIsNameable.types | 50 ++++++++++++++++ ...tionExportStarShadowingGlobalIsNameable.ts | 24 ++++++++ 5 files changed, 194 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js create mode 100644 tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.symbols create mode 100644 tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.types create mode 100644 tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bb1fbbdd526..f3658c645db 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2424,12 +2424,15 @@ namespace ts { const visitedSymbolTables: SymbolTable[] = []; return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable); - function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] | undefined { + /** + * @param {ignoreQualification} boolean Set when a symbol is being looked for through the exports of another symbol (meaning we have a route to qualify it already) + */ + function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean): Symbol[] | undefined { if (!pushIfUnique(visitedSymbolTables, symbols)) { return undefined; } - const result = trySymbolTable(symbols); + const result = trySymbolTable(symbols, ignoreQualification); visitedSymbolTables.pop(); return result; } @@ -2441,22 +2444,22 @@ namespace ts { !!getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing); } - function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol) { + function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol, ignoreQualification?: boolean) { return symbol === (resolvedAliasSymbol || symbolFromSymbolTable) && // if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table) // and if symbolFromSymbolTable or alias resolution matches the symbol, // check the symbol can be qualified, it is only then this symbol is accessible !some(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) && - canQualifySymbol(symbolFromSymbolTable, meaning); + (ignoreQualification || canQualifySymbol(symbolFromSymbolTable, meaning)); } function isUMDExportSymbol(symbol: Symbol) { return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]); } - function trySymbolTable(symbols: SymbolTable) { + function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined) { // If symbol is directly available by its name in the symbol table - if (isAccessible(symbols.get(symbol.escapedName))) { + if (isAccessible(symbols.get(symbol.escapedName), /*resolvedAliasSymbol*/ undefined, ignoreQualification)) { return [symbol]; } @@ -2469,14 +2472,14 @@ namespace ts { && (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))) { const resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolvedImportedSymbol)) { + if (isAccessible(symbolFromSymbolTable, resolvedImportedSymbol, ignoreQualification)) { return [symbolFromSymbolTable]; } // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain // but only if the symbolFromSymbolTable can be qualified const candidateTable = getExportsOfSymbol(resolvedImportedSymbol); - const accessibleSymbolsFromExports = candidateTable && getAccessibleSymbolChainFromSymbolTable(candidateTable); + const accessibleSymbolsFromExports = candidateTable && getAccessibleSymbolChainFromSymbolTable(candidateTable, /*ignoreQualification*/ true); if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); } diff --git a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js new file mode 100644 index 00000000000..77b1b5f8ff4 --- /dev/null +++ b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js @@ -0,0 +1,60 @@ +//// [tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts] //// + +//// [index.ts] +export * from "./account"; + +//// [account.ts] +export interface Account { + myAccNum: number; +} +interface Account2 { + myAccNum: number; +} +export { Account2 as Acc }; + +//// [index.ts] +declare global { + interface Account { + someProp: number; + } + interface Acc { + someProp: number; + } +} +import * as model from "./model"; +export const func = (account: model.Account, acc2: model.Acc) => {}; + + +//// [account.js] +"use strict"; +exports.__esModule = true; +//// [index.js] +"use strict"; +exports.__esModule = true; +//// [index.js] +"use strict"; +exports.__esModule = true; +exports.func = function (account, acc2) { }; + + +//// [account.d.ts] +export interface Account { + myAccNum: number; +} +interface Account2 { + myAccNum: number; +} +export { Account2 as Acc }; +//// [index.d.ts] +export * from "./account"; +//// [index.d.ts] +declare global { + interface Account { + someProp: number; + } + interface Acc { + someProp: number; + } +} +import * as model from "./model"; +export declare const func: (account: model.Account, acc2: model.Acc) => void; diff --git a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.symbols b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.symbols new file mode 100644 index 00000000000..add5fce7476 --- /dev/null +++ b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.symbols @@ -0,0 +1,49 @@ +=== tests/cases/compiler/model/index.ts === +export * from "./account"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/model/account.ts === +export interface Account { +>Account : Symbol(Account, Decl(account.ts, 0, 0)) + + myAccNum: number; +>myAccNum : Symbol(Account.myAccNum, Decl(account.ts, 0, 26)) +} +interface Account2 { +>Account2 : Symbol(Account2, Decl(account.ts, 2, 1)) + + myAccNum: number; +>myAccNum : Symbol(Account2.myAccNum, Decl(account.ts, 3, 20)) +} +export { Account2 as Acc }; +>Account2 : Symbol(Acc, Decl(account.ts, 6, 8)) +>Acc : Symbol(Acc, Decl(account.ts, 6, 8)) + +=== tests/cases/compiler/index.ts === +declare global { +>global : Symbol(global, Decl(index.ts, 0, 0)) + + interface Account { +>Account : Symbol(Account, Decl(index.ts, 0, 16)) + + someProp: number; +>someProp : Symbol(Account.someProp, Decl(index.ts, 1, 23)) + } + interface Acc { +>Acc : Symbol(Acc, Decl(index.ts, 3, 5)) + + someProp: number; +>someProp : Symbol(Acc.someProp, Decl(index.ts, 4, 19)) + } +} +import * as model from "./model"; +>model : Symbol(model, Decl(index.ts, 8, 6)) + +export const func = (account: model.Account, acc2: model.Acc) => {}; +>func : Symbol(func, Decl(index.ts, 9, 12)) +>account : Symbol(account, Decl(index.ts, 9, 21)) +>model : Symbol(model, Decl(index.ts, 8, 6)) +>Account : Symbol(model.Account, Decl(account.ts, 0, 0)) +>acc2 : Symbol(acc2, Decl(index.ts, 9, 44)) +>model : Symbol(model, Decl(index.ts, 8, 6)) +>Acc : Symbol(model.Acc, Decl(account.ts, 6, 8)) + diff --git a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.types b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.types new file mode 100644 index 00000000000..af27f7e3678 --- /dev/null +++ b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.types @@ -0,0 +1,50 @@ +=== tests/cases/compiler/model/index.ts === +export * from "./account"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/model/account.ts === +export interface Account { +>Account : Account + + myAccNum: number; +>myAccNum : number +} +interface Account2 { +>Account2 : Account2 + + myAccNum: number; +>myAccNum : number +} +export { Account2 as Acc }; +>Account2 : any +>Acc : any + +=== tests/cases/compiler/index.ts === +declare global { +>global : any + + interface Account { +>Account : Account + + someProp: number; +>someProp : number + } + interface Acc { +>Acc : Acc + + someProp: number; +>someProp : number + } +} +import * as model from "./model"; +>model : typeof model + +export const func = (account: model.Account, acc2: model.Acc) => {}; +>func : (account: model.Account, acc2: model.Acc) => void +>(account: model.Account, acc2: model.Acc) => {} : (account: model.Account, acc2: model.Acc) => void +>account : model.Account +>model : any +>Account : model.Account +>acc2 : model.Acc +>model : any +>Acc : model.Acc + diff --git a/tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts b/tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts new file mode 100644 index 00000000000..9113e6e329b --- /dev/null +++ b/tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts @@ -0,0 +1,24 @@ +// @declaration: true +// @filename: model/index.ts +export * from "./account"; + +// @filename: model/account.ts +export interface Account { + myAccNum: number; +} +interface Account2 { + myAccNum: number; +} +export { Account2 as Acc }; + +// @filename: index.ts +declare global { + interface Account { + someProp: number; + } + interface Acc { + someProp: number; + } +} +import * as model from "./model"; +export const func = (account: model.Account, acc2: model.Acc) => {}; From 08aa2653dd4609561c9ffe94e8aa5c349a4d12c5 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 24 Jan 2018 12:46:13 -0800 Subject: [PATCH 27/41] Remove incorrect assert --- src/harness/unittests/extractRanges.ts | 6 ++++++ src/services/refactors/extractSymbol.ts | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/harness/unittests/extractRanges.ts b/src/harness/unittests/extractRanges.ts index 2810f323abf..00fbf334b38 100644 --- a/src/harness/unittests/extractRanges.ts +++ b/src/harness/unittests/extractRanges.ts @@ -411,6 +411,12 @@ switch (x) { refactor.extractSymbol.Messages.cannotExtractRange.message ]); + testExtractRangeFailed("extractRangeFailed18", + `[#|{ 1;|] }`, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, [refactor.extractSymbol.Messages.cannotExtractIdentifier.message]); }); } \ No newline at end of file diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index e8a2186aa8b..e3a2763b783 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -242,7 +242,6 @@ namespace ts.refactor.extractSymbol { // they will never find `start` in `start.parent.statements`. // Consider: We could support ranges like [|case 1:|] by refining them to just // the expression. - Debug.assert(isCaseClause(start.parent) && span.start < start.parent.expression.end); return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] }; } From e58391d9c53c22a1207c5cb2fe7ec21b5399887e Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 24 Jan 2018 15:06:00 -0800 Subject: [PATCH 28/41] In fourslash.ts, remove unused exports and use '{}' instead of 'any' (#21377) --- src/harness/fourslash.ts | 43 +++++++++++++--------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index bf5f46de248..75476669b59 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -23,7 +23,7 @@ namespace FourSlash { ts.disableIncrementalParsing = false; // Represents a parsed source file with metadata - export interface FourSlashFile { + interface FourSlashFile { // The contents of the file (with markers, etc stripped out) content: string; fileName: string; @@ -34,7 +34,7 @@ namespace FourSlash { } // Represents a set of parsed source files and options - export interface FourSlashData { + interface FourSlashData { // Global options (name/value pairs) globalOptions: Harness.TestCaseParser.CompilerSettings; @@ -59,7 +59,7 @@ namespace FourSlash { export interface Marker { fileName: string; position: number; - data?: any; + data?: {}; } export interface Range { @@ -89,21 +89,6 @@ namespace FourSlash { end: number; } - export import IndentStyle = ts.IndentStyle; - - const entityMap = ts.createMapFromTemplate({ - "&": "&", - "\"": """, - "'": "'", - "/": "/", - "<": "<", - ">": ">" - }); - - export function escapeXmlAttributeValue(s: string) { - return s.replace(/[&<>"'\/]/g, ch => entityMap.get(ch)); - } - // Name of testcase metadata including ts.CompilerOptions properties that will be used by globalOptions // To add additional option, add property into the testOptMetadataNames, refer the property in either globalMetadataNames or fileMetadataNames // Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data @@ -1079,7 +1064,7 @@ namespace FourSlash { for (const reference of expectedReferences) { const { fileName, start, end } = reference; if (reference.marker && reference.marker.data) { - const { isWriteAccess, isDefinition } = reference.marker.data; + const { isWriteAccess, isDefinition } = reference.marker.data as { isWriteAccess?: boolean, isDefinition?: boolean }; this.verifyReferencesWorker(actualReferences, fileName, start, end, isWriteAccess, isDefinition); } else { @@ -1108,7 +1093,16 @@ namespace FourSlash { } const fullExpected = ts.map(parts, ({ definition, ranges }) => ({ definition: typeof definition === "string" ? definition : { ...definition, range: textSpanFromRange(definition.range) }, - references: ranges.map(rangeToReferenceEntry), + references: ranges.map(r => { + const { isWriteAccess = false, isDefinition = false, isInString } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true }; + return { + isWriteAccess, + isDefinition, + fileName: r.fileName, + textSpan: textSpanFromRange(r), + ...(isInString ? { isInString: true } : undefined), + }; + }), })); for (const startRange of toArray(startRanges)) { @@ -1122,15 +1116,6 @@ namespace FourSlash { }); this.assertObjectsEqual(fullActual, fullExpected); } - - function rangeToReferenceEntry(r: Range): ts.ReferenceEntry { - const { isWriteAccess, isDefinition, isInString } = (r.marker && r.marker.data) || { isWriteAccess: false, isDefinition: false, isInString: undefined }; - const result: ts.ReferenceEntry = { fileName: r.fileName, textSpan: textSpanFromRange(r), isWriteAccess: !!isWriteAccess, isDefinition: !!isDefinition }; - if (isInString !== undefined) { - result.isInString = isInString; - } - return result; - } } public verifyNoReferences(markerNameOrRange?: string | Range) { From d333d889c1d42a98deceb81545ac5a9a57448abe Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 24 Jan 2018 15:06:52 -0800 Subject: [PATCH 29/41] Test for (and fix) order of import fixes (#21398) --- src/harness/fourslash.ts | 8 +++---- src/services/codefixes/importFixes.ts | 2 +- .../fourslash/completionsImportBaseUrl.ts | 21 +++++++++++++++++++ .../importNameCodeFixExistingImport2.ts | 4 ++-- .../importNameCodeFixNewImportBaseUrl0.ts | 6 +++--- .../importNameCodeFixOptionalImport0.ts | 6 +++--- .../importNameCodeFixOptionalImport1.ts | 10 ++++----- 7 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 tests/cases/fourslash/completionsImportBaseUrl.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 75476669b59..98e8e61eef5 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2572,12 +2572,10 @@ Actual: ${stringify(fullActual)}`); actualTextArray.push(text); scriptInfo.updateContent(originalContent); } - const sortedExpectedArray = expectedTextArray.sort(); - const sortedActualArray = actualTextArray.sort(); - if (sortedExpectedArray.length !== sortedActualArray.length) { - this.raiseError(`Expected ${sortedExpectedArray.length} import fixes, got ${sortedActualArray.length}`); + if (expectedTextArray.length !== actualTextArray.length) { + this.raiseError(`Expected ${expectedTextArray.length} import fixes, got ${actualTextArray.length}`); } - ts.zipWith(sortedExpectedArray, sortedActualArray, (expected, actual, index) => { + ts.zipWith(expectedTextArray, actualTextArray, (expected, actual, index) => { if (expected !== actual) { this.raiseError(`Import fix at index ${index} doesn't match.\n${showTextDiff(expected, actual)}`); } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 4c536ce3fd2..ac88d98eba5 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -390,7 +390,7 @@ namespace ts.codefix { In this case we should prefer using the relative path "../a" instead of the baseUrl path "foo/a". */ const pathFromSourceToBaseUrl = getRelativePath(baseUrl, sourceDirectory, getCanonicalFileName); - const relativeFirst = getRelativePathNParents(pathFromSourceToBaseUrl) < getRelativePathNParents(relativePath); + const relativeFirst = getRelativePathNParents(relativePath) < getRelativePathNParents(pathFromSourceToBaseUrl); return relativeFirst ? [relativePath, importRelativeToBaseUrl] : [importRelativeToBaseUrl, relativePath]; })); // Only return results for the re-export with the shortest possible path (and also give the other path even if that's long.) diff --git a/tests/cases/fourslash/completionsImportBaseUrl.ts b/tests/cases/fourslash/completionsImportBaseUrl.ts new file mode 100644 index 00000000000..e5f5b07b9f4 --- /dev/null +++ b/tests/cases/fourslash/completionsImportBaseUrl.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: /tsconfig.json +////{ +//// "compilerOptions": { +//// "baseUrl": "." +//// } +////} + +// @Filename: /src/a.ts +////export const foo = 0; + +// @Filename: /src/b.ts +////fo/**/ + +// Test that it prefers a relative import (see sourceDisplay). +goTo.marker(""); +verify.completionListContains({ name: "foo", source: "/src/a" }, "const foo: 0", "", "const", undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport2.ts b/tests/cases/fourslash/importNameCodeFixExistingImport2.ts index 1146f24aeae..dbf34f4389e 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport2.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport2.ts @@ -9,8 +9,8 @@ verify.importFixAtPosition([ `import * as ns from "./module"; +ns.f1();`, +`import * as ns from "./module"; import { f1 } from "./module"; f1();`, -`import * as ns from "./module"; -ns.f1();`, ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts b/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts index bc852b5c47c..fba8875a610 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts @@ -13,10 +13,10 @@ //// export function f1() { }; verify.importFixAtPosition([ +`import { f1 } from "b"; + +f1();`, `import { f1 } from "./a/b"; f1();`, -`import { f1 } from "b"; - -f1();` ]); diff --git a/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts b/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts index 218ec4fabb7..3fbae01fab0 100644 --- a/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts +++ b/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts @@ -12,9 +12,9 @@ verify.importFixAtPosition([ `import * as ns from "./foo"; -import { foo } from "./foo"; -foo();`, +ns.foo();`, `import * as ns from "./foo"; -ns.foo();`, +import { foo } from "./foo"; +foo();`, ]); diff --git a/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts b/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts index 7a3d19e1532..11204b3c4d2 100644 --- a/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts +++ b/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts @@ -7,14 +7,14 @@ //// export function foo() {}; // @Filename: a/foo.ts -//// export { foo } from "bar"; +//// export { foo } from "bar"; verify.importFixAtPosition([ -`import { foo } from "./foo"; - -foo();`, - `import { foo } from "bar"; +foo();`, + +`import { foo } from "./foo"; + foo();`, ]); From fe0c461d9139c01372e6b6816f85c38cfd20ada2 Mon Sep 17 00:00:00 2001 From: csigs Date: Wed, 24 Jan 2018 23:10:36 +0000 Subject: [PATCH 30/41] LEGO: check in for master to temporary branch. --- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- .../diagnosticMessages/diagnosticMessages.generated.json.lcl | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl index 7ae7fab1b3b..5d67c5c6cdc 100644 --- a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + diff --git a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl index 7cc0cf16633..c7e02a6c2cc 100644 --- a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + diff --git a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl index 7ef4d27d021..3747e00c1f9 100644 --- a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -19,7 +19,7 @@ - + diff --git a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl index 7fe309d50f8..4d8f2721a08 100644 --- a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + diff --git a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 3ad2bbf63b2..517b05df202 100644 --- a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -19,7 +19,7 @@ - + diff --git a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl index 1262a3743cf..99776a461cc 100644 --- a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -19,7 +19,7 @@ - + diff --git a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl index 7579d5ce794..e13e8191eb2 100644 --- a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + diff --git a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 551a0e28806..1a892b757cb 100644 --- a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + diff --git a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl index d9b0532182c..b534bf56365 100644 --- a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + diff --git a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 400187f844a..c5473f41421 100644 --- a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -7,7 +7,7 @@ - + diff --git a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl index b6290bed3fb..080b2e11402 100644 --- a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -7,7 +7,7 @@ - + diff --git a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl index 46dce16bc93..bb0b07794a3 100644 --- a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -13,7 +13,7 @@ - + diff --git a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl index c1894d0db09..44a9f695fca 100644 --- a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -7,7 +7,7 @@ - + From 5698a6ab52d50f25f912bebe012ea8e99c28cc0e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 25 Jan 2018 02:11:01 -0800 Subject: [PATCH 31/41] Fix loop labels for for..await --- src/compiler/transformers/esnext.ts | 2 +- .../reference/emitter.forAwait.es2015.js | 88 +++++++++ .../reference/emitter.forAwait.es2015.symbols | 30 +++ .../reference/emitter.forAwait.es2015.types | 34 ++++ .../reference/emitter.forAwait.es2017.js | 78 ++++++++ .../reference/emitter.forAwait.es2017.symbols | 30 +++ .../reference/emitter.forAwait.es2017.types | 34 ++++ .../reference/emitter.forAwait.es5.js | 182 ++++++++++++++++++ .../reference/emitter.forAwait.es5.symbols | 30 +++ .../reference/emitter.forAwait.es5.types | 34 ++++ .../reference/emitter.forAwait.esnext.js | 32 +++ .../reference/emitter.forAwait.esnext.symbols | 30 +++ .../reference/emitter.forAwait.esnext.types | 34 ++++ .../forAwait/emitter.forAwait.es2015.ts | 16 ++ .../forAwait/emitter.forAwait.es2017.ts | 16 ++ .../es5/forAwait/emitter.forAwait.es5.ts | 16 ++ .../forAwait/emitter.forAwait.esnext.ts | 16 ++ 17 files changed, 701 insertions(+), 1 deletion(-) diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 5d46c8430d2..424371ad311 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -148,7 +148,7 @@ namespace ts { } function visitLabeledStatement(node: LabeledStatement) { - if (enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator) { + if (enclosingFunctionFlags & FunctionFlags.Async) { const statement = unwrapInnermostStatementOfLabel(node); if (statement.kind === SyntaxKind.ForOfStatement && (statement).awaitModifier) { return visitForOfStatement(statement, node); diff --git a/tests/baselines/reference/emitter.forAwait.es2015.js b/tests/baselines/reference/emitter.forAwait.es2015.js index 323d62f0ac8..6b6bdd739fd 100644 --- a/tests/baselines/reference/emitter.forAwait.es2015.js +++ b/tests/baselines/reference/emitter.forAwait.es2015.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { @@ -161,3 +177,75 @@ function f4() { var e_1, _a; }); } +//// [file5.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f5() { + return __awaiter(this, void 0, void 0, function* () { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield y_1.next(), !y_1_1.done;) { + const x = yield y_1_1.value; + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield _a.call(y_1); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} +//// [file6.js] +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f6() { + return __asyncGenerator(this, arguments, function* f6_1() { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield __await(y_1.next()), !y_1_1.done;) { + const x = yield __await(y_1_1.value); + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield __await(_a.call(y_1)); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} diff --git a/tests/baselines/reference/emitter.forAwait.es2015.symbols b/tests/baselines/reference/emitter.forAwait.es2015.symbols index 6c4ed3b10e9..bc75908f601 100644 --- a/tests/baselines/reference/emitter.forAwait.es2015.symbols +++ b/tests/baselines/reference/emitter.forAwait.es2015.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/es2015/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/es2015/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es2015.types b/tests/baselines/reference/emitter.forAwait.es2015.types index ac7321e43b4..e7d1c77f346 100644 --- a/tests/baselines/reference/emitter.forAwait.es2015.types +++ b/tests/baselines/reference/emitter.forAwait.es2015.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/es2015/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/es2015/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.js b/tests/baselines/reference/emitter.forAwait.es2017.js index 4b3770f02af..8eb21442558 100644 --- a/tests/baselines/reference/emitter.forAwait.es2017.js +++ b/tests/baselines/reference/emitter.forAwait.es2017.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] var __asyncValues = (this && this.__asyncValues) || function (o) { @@ -141,3 +157,65 @@ function f4() { var e_1, _a; }); } +//// [file5.js] +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = await y_1.next(), !y_1_1.done;) { + const x = await y_1_1.value; + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) await _a.call(y_1); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; +} +//// [file6.js] +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f6() { + return __asyncGenerator(this, arguments, function* f6_1() { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield __await(y_1.next()), !y_1_1.done;) { + const x = yield __await(y_1_1.value); + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield __await(_a.call(y_1)); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.symbols b/tests/baselines/reference/emitter.forAwait.es2017.symbols index a08e31f5553..184d26c1266 100644 --- a/tests/baselines/reference/emitter.forAwait.es2017.symbols +++ b/tests/baselines/reference/emitter.forAwait.es2017.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/es2017/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.types b/tests/baselines/reference/emitter.forAwait.es2017.types index 0d886cca4cc..f1dffdd280a 100644 --- a/tests/baselines/reference/emitter.forAwait.es2017.types +++ b/tests/baselines/reference/emitter.forAwait.es2017.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/es2017/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es5.js b/tests/baselines/reference/emitter.forAwait.es5.js index 2b073a3f43a..b4ea4ddcf54 100644 --- a/tests/baselines/reference/emitter.forAwait.es5.js +++ b/tests/baselines/reference/emitter.forAwait.es5.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { @@ -353,3 +369,169 @@ function f4() { }); }); } +//// [file5.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f5() { + return __awaiter(this, void 0, void 0, function () { + var y, y_1, y_1_1, x, e_1_1, e_1, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 6, 7, 12]); + y_1 = __asyncValues(y); + _b.label = 1; + case 1: return [4 /*yield*/, y_1.next()]; + case 2: + if (!(y_1_1 = _b.sent(), !y_1_1.done)) return [3 /*break*/, 5]; + return [4 /*yield*/, y_1_1.value]; + case 3: + x = _b.sent(); + return [3 /*break*/, 4]; + case 4: return [3 /*break*/, 1]; + case 5: return [3 /*break*/, 12]; + case 6: + e_1_1 = _b.sent(); + e_1 = { error: e_1_1 }; + return [3 /*break*/, 12]; + case 7: + _b.trys.push([7, , 10, 11]); + if (!(y_1_1 && !y_1_1.done && (_a = y_1.return))) return [3 /*break*/, 9]; + return [4 /*yield*/, _a.call(y_1)]; + case 8: + _b.sent(); + _b.label = 9; + case 9: return [3 /*break*/, 11]; + case 10: + if (e_1) throw e_1.error; + return [7 /*endfinally*/]; + case 11: return [7 /*endfinally*/]; + case 12: return [2 /*return*/]; + } + }); + }); +} +//// [file6.js] +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f6() { + return __asyncGenerator(this, arguments, function f6_1() { + var y, y_1, y_1_1, x, e_1_1, e_1, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 6, 7, 12]); + y_1 = __asyncValues(y); + _b.label = 1; + case 1: return [4 /*yield*/, __await(y_1.next())]; + case 2: + if (!(y_1_1 = _b.sent(), !y_1_1.done)) return [3 /*break*/, 5]; + return [4 /*yield*/, __await(y_1_1.value)]; + case 3: + x = _b.sent(); + return [3 /*break*/, 4]; + case 4: return [3 /*break*/, 1]; + case 5: return [3 /*break*/, 12]; + case 6: + e_1_1 = _b.sent(); + e_1 = { error: e_1_1 }; + return [3 /*break*/, 12]; + case 7: + _b.trys.push([7, , 10, 11]); + if (!(y_1_1 && !y_1_1.done && (_a = y_1.return))) return [3 /*break*/, 9]; + return [4 /*yield*/, __await(_a.call(y_1))]; + case 8: + _b.sent(); + _b.label = 9; + case 9: return [3 /*break*/, 11]; + case 10: + if (e_1) throw e_1.error; + return [7 /*endfinally*/]; + case 11: return [7 /*endfinally*/]; + case 12: return [2 /*return*/]; + } + }); + }); +} diff --git a/tests/baselines/reference/emitter.forAwait.es5.symbols b/tests/baselines/reference/emitter.forAwait.es5.symbols index 40c5562453c..05fb915c0fc 100644 --- a/tests/baselines/reference/emitter.forAwait.es5.symbols +++ b/tests/baselines/reference/emitter.forAwait.es5.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/es5/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/es5/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es5.types b/tests/baselines/reference/emitter.forAwait.es5.types index 8c8f6dec723..fe0a49a9016 100644 --- a/tests/baselines/reference/emitter.forAwait.es5.types +++ b/tests/baselines/reference/emitter.forAwait.es5.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/es5/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/es5/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/baselines/reference/emitter.forAwait.esnext.js b/tests/baselines/reference/emitter.forAwait.esnext.js index 7a6c6837c9a..0042ae38fbd 100644 --- a/tests/baselines/reference/emitter.forAwait.esnext.js +++ b/tests/baselines/reference/emitter.forAwait.esnext.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] async function f1() { @@ -49,3 +65,19 @@ async function* f4() { for await (x of y) { } } +//// [file5.js] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.js] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y; + outer: for await (const x of y) { + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.esnext.symbols b/tests/baselines/reference/emitter.forAwait.esnext.symbols index 137ebed0802..2910738102b 100644 --- a/tests/baselines/reference/emitter.forAwait.esnext.symbols +++ b/tests/baselines/reference/emitter.forAwait.esnext.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/esnext/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/esnext/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.esnext.types b/tests/baselines/reference/emitter.forAwait.esnext.types index ae52bd1080d..6339aeebeff 100644 --- a/tests/baselines/reference/emitter.forAwait.esnext.types +++ b/tests/baselines/reference/emitter.forAwait.esnext.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/esnext/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/esnext/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts b/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts index 2069f08af30..64b44e901e2 100644 --- a/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts +++ b/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file diff --git a/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts b/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts index f2d1f46873d..f9d9fc3d4d9 100644 --- a/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts +++ b/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file diff --git a/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts b/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts index beb9ac9c2ca..a441b0da2bd 100644 --- a/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts +++ b/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file diff --git a/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts b/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts index 2f532f55ed5..ea1b030599e 100644 --- a/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts +++ b/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file From 058e3ad75e5ad5239f3b89c83d3a2dba6933fa24 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 25 Jan 2018 07:36:38 -0800 Subject: [PATCH 32/41] Improve assertion in computePositionOfLineAndCharacter (#21361) --- src/compiler/core.ts | 4 ++++ src/compiler/scanner.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index cefa9367b48..06f8b24a4c6 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -340,6 +340,10 @@ namespace ts { return false; } + export function arraysEqual(a: ReadonlyArray, b: ReadonlyArray, equalityComparer: EqualityComparer = equateValues): boolean { + return a.length === b.length && a.every((x, i) => equalityComparer(x, b[i])); + } + export function indexOfAnyCharCode(text: string, charCodes: ReadonlyArray, start?: number): number { for (let i = start || 0; i < text.length; i++) { if (contains(charCodes, text.charCodeAt(i))) { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 5001ea58336..6b0d10223fd 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -335,7 +335,10 @@ namespace ts { /* @internal */ export function computePositionOfLineAndCharacter(lineStarts: ReadonlyArray, line: number, character: number, debugText?: string): number { - Debug.assert(line >= 0 && line < lineStarts.length); + if (line < 0 || line >= lineStarts.length) { + Debug.fail(`Bad line number. Line: ${line}, lineStarts.length: ${lineStarts.length} , line map is correct? ${debugText !== undefined ? arraysEqual(lineStarts, computeLineStarts(debugText)) : "unknown"}`); + } + const res = lineStarts[line] + character; if (line < lineStarts.length - 1) { Debug.assert(res < lineStarts[line + 1]); From 0b7f6d5911fae749d9dd8e67a0f86dbc2ba8421e Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 25 Jan 2018 07:42:01 -0800 Subject: [PATCH 33/41] Fix bug: Support `this.` completions even when isGlobalCompletion is false (#21330) --- src/services/completions.ts | 5 +++-- tests/cases/fourslash/completionsThisType.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index 8b7f564ff08..492aca5b26c 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -180,7 +180,7 @@ namespace ts.Completions { let insertText: string | undefined; let replacementSpan: TextSpan | undefined; - if (kind === CompletionKind.Global && origin && origin.type === "this-type") { + if (origin && origin.type === "this-type") { insertText = needsConvertPropertyAccess ? `this["${name}"]` : `this.${name}`; } else if (needsConvertPropertyAccess) { @@ -683,6 +683,7 @@ namespace ts.Completions { const enum CompletionKind { ObjectPropertyDeclaration, + /** Note that sometimes we access completions from global scope, but use "None" instead of this. See isGlobalCompletionScope. */ Global, PropertyAccess, MemberLike, @@ -2112,13 +2113,13 @@ namespace ts.Completions { const validIdentiferResult: CompletionEntryDisplayNameForSymbol = { name, needsConvertPropertyAccess: false }; if (isIdentifierText(name, target)) return validIdentiferResult; switch (kind) { - case CompletionKind.None: case CompletionKind.MemberLike: return undefined; case CompletionKind.ObjectPropertyDeclaration: // TODO: GH#18169 return { name: JSON.stringify(name), needsConvertPropertyAccess: false }; case CompletionKind.PropertyAccess: + case CompletionKind.None: case CompletionKind.Global: // Don't add a completion for a name starting with a space. See https://github.com/Microsoft/TypeScript/pull/20547 return name.charCodeAt(0) === CharacterCodes.space ? undefined : { name, needsConvertPropertyAccess: true }; diff --git a/tests/cases/fourslash/completionsThisType.ts b/tests/cases/fourslash/completionsThisType.ts index 58325182a22..471251d2134 100644 --- a/tests/cases/fourslash/completionsThisType.ts +++ b/tests/cases/fourslash/completionsThisType.ts @@ -3,7 +3,7 @@ ////class C { //// "foo bar": number; //// xyz() { -//// /**/ +//// return (/**/) //// } ////} //// @@ -11,7 +11,7 @@ goTo.marker(""); -verify.completionListContains("xyz", "(method) C.xyz(): void", "", "method", undefined, undefined, { +verify.completionListContains("xyz", "(method) C.xyz(): any", "", "method", undefined, undefined, { includeInsertTextCompletions: true, insertText: "this.xyz", }); From dcd3b5e1f7582fba9dc4a6c0ac924e836c19444b Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 25 Jan 2018 09:02:20 -0800 Subject: [PATCH 34/41] At `
{ @@ -246,7 +256,7 @@ namespace ts.Completions { const uniques = createMap(); for (const symbol of symbols) { const origin = symbolToOriginInfoMap ? symbolToOriginInfoMap[getSymbolId(symbol)] : undefined; - const entry = createCompletionEntry(symbol, location, sourceFile, typeChecker, target, kind, origin, recommendedCompletion, propertyAccessToConvert, includeInsertTextCompletions); + const entry = createCompletionEntry(symbol, location, sourceFile, typeChecker, target, kind, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, includeInsertTextCompletions); if (!entry) { continue; } @@ -483,6 +493,7 @@ namespace ts.Completions { location: Node; symbolToOriginInfoMap: SymbolOriginInfoMap; previousToken: Node; + readonly isJsxInitializer: boolean; } function getSymbolCompletionFromEntryId( typeChecker: TypeChecker, @@ -501,7 +512,7 @@ namespace ts.Completions { return { type: "request", request: completionData }; } - const { symbols, location, completionKind, symbolToOriginInfoMap, previousToken } = completionData; + const { symbols, location, completionKind, symbolToOriginInfoMap, previousToken, isJsxInitializer } = completionData; // Find the symbol with the matching entry name. // We don't need to perform character checks here because we're only comparing the @@ -510,7 +521,7 @@ namespace ts.Completions { return firstDefined(symbols, (symbol): SymbolCompletion => { // TODO: Shouldn't need return type annotation (GH#12632) const origin = symbolToOriginInfoMap[getSymbolId(symbol)]; const info = getCompletionEntryDisplayNameForSymbol(symbol, compilerOptions.target, origin, completionKind); - return info && info.name === name && getSourceFromOrigin(origin) === source ? { type: "symbol" as "symbol", symbol, location, symbolToOriginInfoMap, previousToken } : undefined; + return info && info.name === name && getSourceFromOrigin(origin) === source ? { type: "symbol" as "symbol", symbol, location, symbolToOriginInfoMap, previousToken, isJsxInitializer } : undefined; }) || { type: "none" }; } @@ -678,6 +689,7 @@ namespace ts.Completions { readonly symbolToOriginInfoMap: SymbolOriginInfoMap; readonly recommendedCompletion: Symbol | undefined; readonly previousToken: Node | undefined; + readonly isJsxInitializer: boolean; } type Request = { readonly kind: CompletionDataKind.JsDocTagName | CompletionDataKind.JsDocTag } | { readonly kind: CompletionDataKind.JsDocParameterName, tag: JSDocParameterTag }; @@ -859,6 +871,7 @@ namespace ts.Completions { let isRightOfDot = false; let isRightOfOpenTag = false; let isStartingCloseTag = false; + let isJsxInitializer = false; let location = getTouchingPropertyName(sourceFile, position, insideJsDocTagTypeExpression); // TODO: GH#15853 if (contextToken) { @@ -917,6 +930,10 @@ namespace ts.Completions { location = contextToken; } break; + + case SyntaxKind.JsxAttribute: + isJsxInitializer = previousToken.kind === SyntaxKind.EqualsToken; + break; } } } @@ -962,7 +979,7 @@ namespace ts.Completions { log("getCompletionData: Semantic work: " + (timestamp() - semanticStart)); const recommendedCompletion = previousToken && getRecommendedCompletion(previousToken, typeChecker); - return { kind: CompletionDataKind.Data, symbols, completionKind, propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, previousToken }; + return { kind: CompletionDataKind.Data, symbols, completionKind, propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, previousToken, isJsxInitializer }; type JSDocTagWithTypeExpression = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag; diff --git a/tests/cases/fourslash/completionsJsxAttributeInitializer.ts b/tests/cases/fourslash/completionsJsxAttributeInitializer.ts new file mode 100644 index 00000000000..510e0630de9 --- /dev/null +++ b/tests/cases/fourslash/completionsJsxAttributeInitializer.ts @@ -0,0 +1,23 @@ +/// + +// @Filename: /a.tsx +////function f(this: { p: number; "a b": number }, x: number): void { +////
; +////} + +goTo.marker(); + +verify.completionListContains("x", "(parameter) x: number", "", "parameter", undefined, undefined, { + includeInsertTextCompletions: true, + insertText: "{x}", +}); + +verify.completionListContains("p", "(property) p: number", "", "property", undefined, undefined, { + includeInsertTextCompletions: true, + insertText: "{this.p}", +}); + +verify.completionListContains("a b", '(property) "a b": number', "", "property", undefined, undefined, { + includeInsertTextCompletions: true, + insertText: '{this["a b"]}', +}); From 8e8a02f8f13dfd0d0da5da703711633b09f2570e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 25 Jan 2018 10:06:59 -0800 Subject: [PATCH 35/41] Rename parseConfigFile to getParsedCommandLineOfConfigFile --- src/compiler/watch.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index beccb65f7b8..790295c2254 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -68,7 +68,7 @@ namespace ts { const host: ParseConfigFileHost = system; host.onConfigFileDiagnostic = reportDiagnostic; host.onUnRecoverableConfigFileDiagnostic = diagnostic => reportUnrecoverableDiagnostic(sys, reportDiagnostic, diagnostic); - const result = parseConfigFile(configFileName, optionsToExtend, host); + const result = getParsedCommandLineOfConfigFile(configFileName, optionsToExtend, host); host.onConfigFileDiagnostic = undefined; host.onUnRecoverableConfigFileDiagnostic = undefined; return result; @@ -77,7 +77,7 @@ namespace ts { /** * Reads the config file, reports errors if any and exits if the config file cannot be found */ - export function parseConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined { + export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined { let configFileText: string; try { configFileText = host.readFile(configFileName); @@ -791,7 +791,7 @@ namespace ts { } function parseConfigFile() { - const configParseResult = ts.parseConfigFile(configFileName, optionsToExtendForConfigFile, parseConfigFileHost); + const configParseResult = ts.getParsedCommandLineOfConfigFile(configFileName, optionsToExtendForConfigFile, parseConfigFileHost); rootFileNames = configParseResult.fileNames; compilerOptions = configParseResult.options; configFileSpecs = configParseResult.configFileSpecs; From 7c4e755effa696419e39d7f0eeb3bcb51f831e57 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 25 Jan 2018 13:53:08 -0800 Subject: [PATCH 36/41] When applying `// @ts-ignore` fix as a group, apply to a line only once. (#21413) * When applying `// @ts-ignore` fix as a group, apply to a line only once. * Rename line to lineNumber --- .../codefixes/disableJsDiagnostics.ts | 48 ++++++++++--------- .../codeFixDisableJsDiagnosticsInFile_all.ts | 8 ++-- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/services/codefixes/disableJsDiagnostics.ts b/src/services/codefixes/disableJsDiagnostics.ts index a887878bac6..3bcbf886df8 100644 --- a/src/services/codefixes/disableJsDiagnostics.ts +++ b/src/services/codefixes/disableJsDiagnostics.ts @@ -1,8 +1,8 @@ /* @internal */ namespace ts.codefix { const fixId = "disableJsDiagnostics"; - const errorCodes = mapDefined(Object.keys(Diagnostics), key => { - const diag = (Diagnostics as MapLike)[key]; + const errorCodes = mapDefined(Object.keys(Diagnostics) as ReadonlyArray, key => { + const diag = Diagnostics[key]; return diag.category === DiagnosticCategory.Error ? diag.code : undefined; }); @@ -19,7 +19,7 @@ namespace ts.codefix { return [{ description: getLocaleSpecificMessage(Diagnostics.Ignore_this_error_message), - changes: [createFileTextChanges(sourceFile.fileName, [getIgnoreCommentLocationForLocation(sourceFile, span.start, newLineCharacter)])], + changes: [createFileTextChanges(sourceFile.fileName, [getIgnoreCommentLocationForLocation(sourceFile, span.start, newLineCharacter).change])], fixId, }, { @@ -35,17 +35,23 @@ namespace ts.codefix { fixId: undefined, }]; }, - fixIds: [fixId], // No point applying as a group, doing it once will fix all errors - getAllCodeActions: context => codeFixAllWithTextChanges(context, errorCodes, (changes, err) => { - if (err.start !== undefined) { - changes.push(getIgnoreCommentLocationForLocation(err.file!, err.start, getNewLineOrDefaultFromHost(context.host, context.formatContext.options))); - } - }), + fixIds: [fixId], + getAllCodeActions: context => { + const seenLines = createMap(); // Only need to add `// @ts-ignore` for a line once. + return codeFixAllWithTextChanges(context, errorCodes, (changes, err) => { + if (err.start !== undefined) { + const { lineNumber, change } = getIgnoreCommentLocationForLocation(err.file!, err.start, getNewLineOrDefaultFromHost(context.host, context.formatContext.options)); + if (addToSeen(seenLines, lineNumber)) { + changes.push(change); + } + } + }); + }, }); - function getIgnoreCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string): TextChange { - const { line } = getLineAndCharacterOfPosition(sourceFile, position); - const lineStartPosition = getStartPositionOfLine(line, sourceFile); + function getIgnoreCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string): { lineNumber: number, change: TextChange } { + const { line: lineNumber } = getLineAndCharacterOfPosition(sourceFile, position); + const lineStartPosition = getStartPositionOfLine(lineNumber, sourceFile); const startPosition = getFirstNonSpaceCharacterPosition(sourceFile.text, lineStartPosition); // First try to see if we can put the '// @ts-ignore' on the previous line. @@ -54,19 +60,17 @@ namespace ts.codefix { // if so, we do not want to separate the node from its comment if we can. if (!isInComment(sourceFile, startPosition) && !isInString(sourceFile, startPosition) && !isInTemplateString(sourceFile, startPosition)) { const token = getTouchingToken(sourceFile, startPosition, /*includeJsDocComment*/ false); - const tokenLeadingCommnets = getLeadingCommentRangesOfNode(token, sourceFile); - if (!tokenLeadingCommnets || !tokenLeadingCommnets.length || tokenLeadingCommnets[0].pos >= startPosition) { - return { - span: { start: startPosition, length: 0 }, - newText: `// @ts-ignore${newLineCharacter}` - }; + const tokenLeadingComments = getLeadingCommentRangesOfNode(token, sourceFile); + if (!tokenLeadingComments || !tokenLeadingComments.length || tokenLeadingComments[0].pos >= startPosition) { + return { lineNumber, change: createTextChange(startPosition, 0, `// @ts-ignore${newLineCharacter}`) }; } } // If all fails, add an extra new line immediately before the error span. - return { - span: { start: position, length: 0 }, - newText: `${position === startPosition ? "" : newLineCharacter}// @ts-ignore${newLineCharacter}` - }; + return { lineNumber, change: createTextChange(position, 0, `${position === startPosition ? "" : newLineCharacter}// @ts-ignore${newLineCharacter}`) }; + } + + function createTextChange(start: number, length: number, newText: string): TextChange { + return { span: { start, length }, newText }; } } diff --git a/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts b/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts index 9c3785cf2ae..89f94520374 100644 --- a/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts +++ b/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts @@ -6,15 +6,15 @@ // @Filename: a.js ////let x = ""; -////x = 1; -////x = true; +////x = 1; x = true; +////x = []; verify.codeFixAll({ fixId: "disableJsDiagnostics", newFileContent: `let x = ""; // @ts-ignore -x = 1; +x = 1; x = true; // @ts-ignore -x = true;`, +x = [];`, }); From afc588eb9e6322faf55bc28f26994712e3f02261 Mon Sep 17 00:00:00 2001 From: Manoj Patel Date: Thu, 25 Jan 2018 15:35:18 -0800 Subject: [PATCH 37/41] --emitDeclarationsOnly flag to enable declarations only output (#20735) * Add emitOnlyDeclarations flag * Fix name * verifyOptions checking logic * Passing tests * doJsEmitBaseline * Tests !!! --- src/compiler/commandLineParser.ts | 6 ++++ src/compiler/diagnosticMessages.json | 4 +++ src/compiler/emitter.ts | 2 +- src/compiler/program.ts | 14 +++++++- src/compiler/types.ts | 1 + src/harness/harness.ts | 16 ++++++++-- .../reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + .../reference/declFileEmitDeclarationsOnly.js | 26 +++++++++++++++ .../declFileEmitDeclarationsOnly.symbols | 29 +++++++++++++++++ .../declFileEmitDeclarationsOnly.types | 32 +++++++++++++++++++ ...lFileEmitDeclarationsOnlyError1.errors.txt | 7 ++++ ...declFileEmitDeclarationsOnlyError1.symbols | 4 +++ .../declFileEmitDeclarationsOnlyError1.types | 5 +++ ...lFileEmitDeclarationsOnlyError2.errors.txt | 9 ++++++ ...declFileEmitDeclarationsOnlyError2.symbols | 4 +++ .../declFileEmitDeclarationsOnlyError2.types | 5 +++ .../compiler/declFileEmitDeclarationsOnly.ts | 16 ++++++++++ .../declFileEmitDeclarationsOnlyError1.ts | 4 +++ .../declFileEmitDeclarationsOnlyError2.ts | 5 +++ 20 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnly.js create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnly.symbols create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnly.types create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnlyError1.errors.txt create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnlyError1.symbols create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnlyError1.types create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnlyError2.errors.txt create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnlyError2.symbols create mode 100644 tests/baselines/reference/declFileEmitDeclarationsOnlyError2.types create mode 100644 tests/cases/compiler/declFileEmitDeclarationsOnly.ts create mode 100644 tests/cases/compiler/declFileEmitDeclarationsOnlyError1.ts create mode 100644 tests/cases/compiler/declFileEmitDeclarationsOnlyError2.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index eb9f1e3cf34..9c30cb87a4d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -186,6 +186,12 @@ namespace ts { category: Diagnostics.Basic_Options, description: Diagnostics.Generates_corresponding_d_ts_file, }, + { + name: "emitDeclarationsOnly", + type: "boolean", + category: Diagnostics.Advanced_Options, + description: Diagnostics.Only_emit_d_ts_declaration_files, + }, { name: "sourceMap", type: "boolean", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7a62d6d5aa4..6fffd576e7c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2807,6 +2807,10 @@ "category": "Message", "code": 6013 }, + "Only emit '.d.ts' declaration files.": { + "category": "Message", + "code": 6014 + }, "Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'.": { "category": "Message", "code": 6015 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6f3041666ba..03ff63a4211 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -135,7 +135,7 @@ namespace ts { function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) { // Make sure not to write js file and source map file if any of them cannot be written - if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit) { + if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit && !compilerOptions.emitDeclarationsOnly) { if (!emitOnlyDtsFiles) { printSourceFileOrBundle(jsFilePath, sourceMapFilePath, sourceFileOrBundle); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index bd45857fc51..23f9b08aa79 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2201,6 +2201,16 @@ namespace ts { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs")); } + if (options.emitDeclarationsOnly) { + if (!options.declaration) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationsOnly", "declarations"); + } + + if (options.noEmit) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationsOnly", "noEmit"); + } + } + if (options.emitDecoratorMetadata && !options.experimentalDecorators) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"); @@ -2223,7 +2233,9 @@ namespace ts { const emitHost = getEmitHost(); const emitFilesSeen = createMap(); forEachEmittedFile(emitHost, (emitFileNames) => { - verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen); + if (!options.emitDeclarationsOnly) { + verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen); + } verifyEmitFilePath(emitFileNames.declarationFilePath, emitFilesSeen); }); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f6ca2f45d34..481b91c9276 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3967,6 +3967,7 @@ namespace ts { /** configFile is set as non enumerable property so as to avoid checking of json source files */ /* @internal */ readonly configFile?: JsonSourceFile; declaration?: boolean; + emitDeclarationsOnly?: boolean; declarationDir?: string; /* @internal */ diagnostics?: boolean; /* @internal */ extendedDiagnostics?: boolean; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index f2f8587d834..3e6f4cfa163 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1252,8 +1252,18 @@ namespace Harness { options: ts.CompilerOptions, // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file currentDirectory: string): DeclarationCompilationContext | undefined { - if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) { - throw new Error("There were no errors and declFiles generated did not match number of js files generated"); + + if (result.errors.length === 0) { + if (options.declaration) { + if (options.emitDeclarationsOnly) { + if (result.files.length > 0 || result.declFilesCode.length === 0) { + throw new Error("Only declaration files should be generated when emitDeclarationsOnly:true"); + } + } + else if (result.declFilesCode.length !== result.files.length) { + throw new Error("There were no errors and declFiles generated did not match number of js files generated"); + } + } } const declInputFiles: TestFile[] = []; @@ -1654,7 +1664,7 @@ namespace Harness { } export function doJsEmitBaseline(baselinePath: string, header: string, options: ts.CompilerOptions, result: CompilerResult, tsConfigFiles: Harness.Compiler.TestFile[], toBeCompiled: Harness.Compiler.TestFile[], otherFiles: Harness.Compiler.TestFile[], harnessSettings: Harness.TestCaseParser.CompilerSettings) { - if (!options.noEmit && result.files.length === 0 && result.errors.length === 0) { + if (!options.noEmit && !options.emitDeclarationsOnly && result.files.length === 0 && result.errors.length === 0) { throw new Error("Expected at least one js file to be emitted or at least one error to be created."); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c1af8fc036f..78f68a80c50 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2266,6 +2266,7 @@ declare namespace ts { charset?: string; checkJs?: boolean; declaration?: boolean; + emitDeclarationsOnly?: boolean; declarationDir?: string; disableSizeLimit?: boolean; downlevelIteration?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 4f84f50e3bb..bdcc29af76e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2266,6 +2266,7 @@ declare namespace ts { charset?: string; checkJs?: boolean; declaration?: boolean; + emitDeclarationsOnly?: boolean; declarationDir?: string; disableSizeLimit?: boolean; downlevelIteration?: boolean; diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnly.js b/tests/baselines/reference/declFileEmitDeclarationsOnly.js new file mode 100644 index 00000000000..78d9842fe88 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnly.js @@ -0,0 +1,26 @@ +//// [helloworld.ts] +const Log = { + info(msg: string) {} +} + +class HelloWorld { + constructor(private name: string) { + } + + public hello() { + Log.info(`Hello ${this.name}`); + } +} + + + + +//// [helloworld.d.ts] +declare const Log: { + info(msg: string): void; +}; +declare class HelloWorld { + private name; + constructor(name: string); + hello(): void; +} diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnly.symbols b/tests/baselines/reference/declFileEmitDeclarationsOnly.symbols new file mode 100644 index 00000000000..e2a277fb603 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnly.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/helloworld.ts === +const Log = { +>Log : Symbol(Log, Decl(helloworld.ts, 0, 5)) + + info(msg: string) {} +>info : Symbol(info, Decl(helloworld.ts, 0, 13)) +>msg : Symbol(msg, Decl(helloworld.ts, 1, 7)) +} + +class HelloWorld { +>HelloWorld : Symbol(HelloWorld, Decl(helloworld.ts, 2, 1)) + + constructor(private name: string) { +>name : Symbol(HelloWorld.name, Decl(helloworld.ts, 5, 14)) + } + + public hello() { +>hello : Symbol(HelloWorld.hello, Decl(helloworld.ts, 6, 3)) + + Log.info(`Hello ${this.name}`); +>Log.info : Symbol(info, Decl(helloworld.ts, 0, 13)) +>Log : Symbol(Log, Decl(helloworld.ts, 0, 5)) +>info : Symbol(info, Decl(helloworld.ts, 0, 13)) +>this.name : Symbol(HelloWorld.name, Decl(helloworld.ts, 5, 14)) +>this : Symbol(HelloWorld, Decl(helloworld.ts, 2, 1)) +>name : Symbol(HelloWorld.name, Decl(helloworld.ts, 5, 14)) + } +} + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnly.types b/tests/baselines/reference/declFileEmitDeclarationsOnly.types new file mode 100644 index 00000000000..9a3cf8cfc70 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnly.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/helloworld.ts === +const Log = { +>Log : { info(msg: string): void; } +>{ info(msg: string) {}} : { info(msg: string): void; } + + info(msg: string) {} +>info : (msg: string) => void +>msg : string +} + +class HelloWorld { +>HelloWorld : HelloWorld + + constructor(private name: string) { +>name : string + } + + public hello() { +>hello : () => void + + Log.info(`Hello ${this.name}`); +>Log.info(`Hello ${this.name}`) : void +>Log.info : (msg: string) => void +>Log : { info(msg: string): void; } +>info : (msg: string) => void +>`Hello ${this.name}` : string +>this.name : string +>this : this +>name : string + } +} + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.errors.txt b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.errors.txt new file mode 100644 index 00000000000..88a154cc508 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.errors.txt @@ -0,0 +1,7 @@ +error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. + + +!!! error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. +==== tests/cases/compiler/hello.ts (0 errors) ==== + var hello = "yo!"; + \ No newline at end of file diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.symbols b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.symbols new file mode 100644 index 00000000000..52b2f9bbe64 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : Symbol(hello, Decl(hello.ts, 0, 3)) + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.types b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.types new file mode 100644 index 00000000000..e1603394d7c --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : string +>"yo!" : "yo!" + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.errors.txt b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.errors.txt new file mode 100644 index 00000000000..7c067d83ba2 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.errors.txt @@ -0,0 +1,9 @@ +error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. +error TS5053: Option 'emitDeclarationsOnly' cannot be specified with option 'noEmit'. + + +!!! error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. +!!! error TS5053: Option 'emitDeclarationsOnly' cannot be specified with option 'noEmit'. +==== tests/cases/compiler/hello.ts (0 errors) ==== + var hello = "yo!"; + \ No newline at end of file diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.symbols b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.symbols new file mode 100644 index 00000000000..52b2f9bbe64 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : Symbol(hello, Decl(hello.ts, 0, 3)) + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.types b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.types new file mode 100644 index 00000000000..e1603394d7c --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : string +>"yo!" : "yo!" + diff --git a/tests/cases/compiler/declFileEmitDeclarationsOnly.ts b/tests/cases/compiler/declFileEmitDeclarationsOnly.ts new file mode 100644 index 00000000000..e55496e4ca3 --- /dev/null +++ b/tests/cases/compiler/declFileEmitDeclarationsOnly.ts @@ -0,0 +1,16 @@ +// @declaration: true +// @emitDeclarationsOnly: true + +// @filename: helloworld.ts +const Log = { + info(msg: string) {} +} + +class HelloWorld { + constructor(private name: string) { + } + + public hello() { + Log.info(`Hello ${this.name}`); + } +} diff --git a/tests/cases/compiler/declFileEmitDeclarationsOnlyError1.ts b/tests/cases/compiler/declFileEmitDeclarationsOnlyError1.ts new file mode 100644 index 00000000000..477934a7b2a --- /dev/null +++ b/tests/cases/compiler/declFileEmitDeclarationsOnlyError1.ts @@ -0,0 +1,4 @@ +// @emitDeclarationsOnly: true + +// @filename: hello.ts +var hello = "yo!"; diff --git a/tests/cases/compiler/declFileEmitDeclarationsOnlyError2.ts b/tests/cases/compiler/declFileEmitDeclarationsOnlyError2.ts new file mode 100644 index 00000000000..994a6a5dbd8 --- /dev/null +++ b/tests/cases/compiler/declFileEmitDeclarationsOnlyError2.ts @@ -0,0 +1,5 @@ +// @noEmit: true +// @emitDeclarationsOnly: true + +// @filename: hello.ts +var hello = "yo!"; From 9677b0641cc5ba7d8b701b4f892ed7e54ceaee9a Mon Sep 17 00:00:00 2001 From: Adnan Chowdhury Date: Thu, 25 Jan 2018 16:17:58 -0800 Subject: [PATCH 38/41] Implement fallback hashing algorithm when crypto module is not available (#19941) * Implement fallback hashing algorithm when crypto module is not available * Fix lint errors * Expose method internally and use in watch.ts * Simplify syntax; Remove fallback from watch.ts --- src/compiler/sys.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 3256eef4dc2..ef1a3f8fd49 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -126,10 +126,32 @@ namespace ts { const _fs = require("fs"); const _path = require("path"); const _os = require("os"); - const _crypto = require("crypto"); + // crypto can be absent on reduced node installations + let _crypto: any; + try { + _crypto = require("crypto"); + } + catch { + _crypto = undefined; + } const useNonPollingWatchers = process.env.TSC_NONPOLLING_WATCHER; + /** + * djb2 hashing algorithm + * http://www.cse.yorku.ca/~oz/hash.html + */ + function generateDjb2Hash(data: string): string { + const chars = data.split("").map(str => str.charCodeAt(0)); + return `${chars.reduce((prev, curr) => ((prev << 5) + prev) + curr, 5381)}`; + } + + function createMD5HashUsingNativeCrypto(data: string) { + const hash = _crypto.createHash("md5"); + hash.update(data); + return hash.digest("hex"); + } + function createWatchedFileSet() { const dirWatchers = createMap(); // One file can have multiple watchers @@ -493,11 +515,7 @@ namespace ts { return undefined; } }, - createHash(data) { - const hash = _crypto.createHash("md5"); - hash.update(data); - return hash.digest("hex"); - }, + createHash: _crypto ? createMD5HashUsingNativeCrypto : generateDjb2Hash, getMemoryUsage() { if (global.gc) { global.gc(); From f0ba16c9a558bf11a82b517fd789d7d41f88c0da Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Thu, 25 Jan 2018 19:18:35 -0500 Subject: [PATCH 39/41] Unused type parameters should be checked by --noUnusedParameters, not (#21167) --noUnusedLocals. Fixes #20568. --- src/compiler/checker.ts | 4 +-- ...tersCheckedByNoUnusedParameters.errors.txt | 33 +++++++++++++++++++ ...peParametersCheckedByNoUnusedParameters.js | 25 ++++++++++++++ ...ametersCheckedByNoUnusedParameters.symbols | 27 +++++++++++++++ ...arametersCheckedByNoUnusedParameters.types | 28 ++++++++++++++++ ...ypeParametersNotCheckedByNoUnusedLocals.js | 25 ++++++++++++++ ...rametersNotCheckedByNoUnusedLocals.symbols | 27 +++++++++++++++ ...ParametersNotCheckedByNoUnusedLocals.types | 28 ++++++++++++++++ ...sedTypeParametersWithUnderscore.errors.txt | 14 ++++++-- .../unusedTypeParametersWithUnderscore.js | 8 ++++- ...unusedTypeParametersWithUnderscore.symbols | 14 +++++++- .../unusedTypeParametersWithUnderscore.types | 15 ++++++++- ...peParametersCheckedByNoUnusedParameters.ts | 13 ++++++++ ...ypeParametersNotCheckedByNoUnusedLocals.ts | 13 ++++++++ .../unusedTypeParametersWithUnderscore.ts | 8 +++-- .../fourslash/unusedTypeParametersInClass1.ts | 2 +- .../fourslash/unusedTypeParametersInClass2.ts | 2 +- .../fourslash/unusedTypeParametersInClass3.ts | 2 +- .../unusedTypeParametersInFunction1.ts | 2 +- .../unusedTypeParametersInFunction2.ts | 2 +- .../unusedTypeParametersInFunction3.ts | 2 +- .../unusedTypeParametersInLambda4.ts | 2 +- .../unusedTypeParametersInMethod1.ts | 2 +- .../unusedTypeParametersInMethod2.ts | 2 +- .../unusedTypeParametersInMethods1.ts | 2 +- 25 files changed, 283 insertions(+), 19 deletions(-) create mode 100644 tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.errors.txt create mode 100644 tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.js create mode 100644 tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.symbols create mode 100644 tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.types create mode 100644 tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.js create mode 100644 tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.symbols create mode 100644 tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.types create mode 100644 tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts create mode 100644 tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 26f0baec5ec..ba3c3e6b83c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20967,7 +20967,7 @@ namespace ts { error(name, Diagnostics._0_is_declared_but_its_value_is_never_read, symbolName(local)); } } - else if (compilerOptions.noUnusedLocals) { + else if (local.flags & SymbolFlags.TypeParameter ? compilerOptions.noUnusedParameters : compilerOptions.noUnusedLocals) { forEach(local.declarations, d => errorUnusedLocal(d, symbolName(local))); } } @@ -21042,7 +21042,7 @@ namespace ts { } function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration | TypeAliasDeclaration) { - if (compilerOptions.noUnusedLocals && !(node.flags & NodeFlags.Ambient)) { + if (compilerOptions.noUnusedParameters && !(node.flags & NodeFlags.Ambient)) { if (node.typeParameters) { // Only report errors on the last declaration for the type parameter container; // this ensures that all uses have been accounted for. diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.errors.txt b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.errors.txt new file mode 100644 index 00000000000..e5bc774b706 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(1,12): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(3,8): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(5,13): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(7,9): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(8,14): error TS6133: 'V' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(11,10): error TS6133: 'T' is declared but its value is never read. + + +==== tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts (6 errors) ==== + function f() { } + ~ +!!! error TS6133: 'T' is declared but its value is never read. + + type T = { }; + ~ +!!! error TS6133: 'T' is declared but its value is never read. + + interface I { }; + ~ +!!! error TS6133: 'T' is declared but its value is never read. + + class C { + ~ +!!! error TS6133: 'T' is declared but its value is never read. + public m() { } + ~ +!!! error TS6133: 'V' is declared but its value is never read. + }; + + let l = () => { }; + ~ +!!! error TS6133: 'T' is declared but its value is never read. + \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.js b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.js new file mode 100644 index 00000000000..50a7dfcfeac --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.js @@ -0,0 +1,25 @@ +//// [unusedTypeParametersCheckedByNoUnusedParameters.ts] +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; + + +//// [unusedTypeParametersCheckedByNoUnusedParameters.js] +function f() { } +; +var C = /** @class */ (function () { + function C() { + } + C.prototype.m = function () { }; + return C; +}()); +; +var l = function () { }; diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.symbols b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.symbols new file mode 100644 index 00000000000..916329800ef --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts === +function f() { } +>f : Symbol(f, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 0, 0)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 0, 11)) + +type T = { }; +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 0, 19)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 2, 7)) + +interface I { }; +>I : Symbol(I, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 2, 16)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 4, 12)) + +class C { +>C : Symbol(C, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 4, 19)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 6, 8)) + + public m() { } +>m : Symbol(C.m, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 6, 12)) +>V : Symbol(V, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 7, 13)) + +}; + +let l = () => { }; +>l : Symbol(l, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 10, 3)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 10, 9)) + diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.types b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.types new file mode 100644 index 00000000000..eb49d0a731f --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts === +function f() { } +>f : () => void +>T : T + +type T = { }; +>T : {} +>T : T + +interface I { }; +>I : I +>T : T + +class C { +>C : C +>T : T + + public m() { } +>m : () => void +>V : V + +}; + +let l = () => { }; +>l : () => void +>() => { } : () => void +>T : T + diff --git a/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.js b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.js new file mode 100644 index 00000000000..2b215504bda --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.js @@ -0,0 +1,25 @@ +//// [unusedTypeParametersNotCheckedByNoUnusedLocals.ts] +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; + + +//// [unusedTypeParametersNotCheckedByNoUnusedLocals.js] +function f() { } +; +var C = /** @class */ (function () { + function C() { + } + C.prototype.m = function () { }; + return C; +}()); +; +var l = function () { }; diff --git a/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.symbols b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.symbols new file mode 100644 index 00000000000..27bc52564d5 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts === +function f() { } +>f : Symbol(f, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 0, 0)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 0, 11)) + +type T = { }; +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 0, 19)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 2, 7)) + +interface I { }; +>I : Symbol(I, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 2, 16)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 4, 12)) + +class C { +>C : Symbol(C, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 4, 19)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 6, 8)) + + public m() { } +>m : Symbol(C.m, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 6, 12)) +>V : Symbol(V, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 7, 13)) + +}; + +let l = () => { }; +>l : Symbol(l, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 10, 3)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 10, 9)) + diff --git a/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.types b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.types new file mode 100644 index 00000000000..bed3e964d2c --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts === +function f() { } +>f : () => void +>T : T + +type T = { }; +>T : {} +>T : T + +interface I { }; +>I : I +>T : T + +class C { +>C : C +>T : T + + public m() { } +>m : () => void +>V : V + +}; + +let l = () => { }; +>l : () => void +>() => { } : () => void +>T : T + diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt b/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt index cd44a68b78c..b41b62694f8 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt @@ -2,9 +2,11 @@ tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(1,16): error TS6133: tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(3,12): error TS6133: 'U' is declared but its value is never read. tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(5,17): error TS6133: 'U' is declared but its value is never read. tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(7,13): error TS6133: 'U' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(8,18): error TS6133: 'W' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(11,14): error TS6133: 'U' is declared but its value is never read. -==== tests/cases/compiler/unusedTypeParametersWithUnderscore.ts (4 errors) ==== +==== tests/cases/compiler/unusedTypeParametersWithUnderscore.ts (6 errors) ==== function f<_T, U>() { } ~ !!! error TS6133: 'U' is declared but its value is never read. @@ -17,7 +19,15 @@ tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(7,13): error TS6133: ~ !!! error TS6133: 'U' is declared but its value is never read. - class C<_T, U> { }; + class C<_T, U> { ~ !!! error TS6133: 'U' is declared but its value is never read. + public m<_V, W>() { } + ~ +!!! error TS6133: 'W' is declared but its value is never read. + }; + + let l = <_T, U>() => { }; + ~ +!!! error TS6133: 'U' is declared but its value is never read. \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.js b/tests/baselines/reference/unusedTypeParametersWithUnderscore.js index 095cf2da85f..bade5f6f95f 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.js +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.js @@ -5,7 +5,11 @@ type T<_T, U> = { }; interface I<_T, U> { }; -class C<_T, U> { }; +class C<_T, U> { + public m<_V, W>() { } +}; + +let l = <_T, U>() => { }; //// [unusedTypeParametersWithUnderscore.js] @@ -14,6 +18,8 @@ function f() { } var C = /** @class */ (function () { function C() { } + C.prototype.m = function () { }; return C; }()); ; +var l = function () { }; diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols b/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols index 4429bc1bd25..3f8444d7069 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols @@ -14,8 +14,20 @@ interface I<_T, U> { }; >_T : Symbol(_T, Decl(unusedTypeParametersWithUnderscore.ts, 4, 12)) >U : Symbol(U, Decl(unusedTypeParametersWithUnderscore.ts, 4, 15)) -class C<_T, U> { }; +class C<_T, U> { >C : Symbol(C, Decl(unusedTypeParametersWithUnderscore.ts, 4, 23)) >_T : Symbol(_T, Decl(unusedTypeParametersWithUnderscore.ts, 6, 8)) >U : Symbol(U, Decl(unusedTypeParametersWithUnderscore.ts, 6, 11)) + public m<_V, W>() { } +>m : Symbol(C.m, Decl(unusedTypeParametersWithUnderscore.ts, 6, 16)) +>_V : Symbol(_V, Decl(unusedTypeParametersWithUnderscore.ts, 7, 13)) +>W : Symbol(W, Decl(unusedTypeParametersWithUnderscore.ts, 7, 16)) + +}; + +let l = <_T, U>() => { }; +>l : Symbol(l, Decl(unusedTypeParametersWithUnderscore.ts, 10, 3)) +>_T : Symbol(_T, Decl(unusedTypeParametersWithUnderscore.ts, 10, 9)) +>U : Symbol(U, Decl(unusedTypeParametersWithUnderscore.ts, 10, 12)) + diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.types b/tests/baselines/reference/unusedTypeParametersWithUnderscore.types index bfafa3c9b38..9fbb3b974df 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.types +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.types @@ -14,8 +14,21 @@ interface I<_T, U> { }; >_T : _T >U : U -class C<_T, U> { }; +class C<_T, U> { >C : C<_T, U> >_T : _T +>U : U + + public m<_V, W>() { } +>m : <_V, W>() => void +>_V : _V +>W : W + +}; + +let l = <_T, U>() => { }; +>l : <_T, U>() => void +><_T, U>() => { } : <_T, U>() => void +>_T : _T >U : U diff --git a/tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts b/tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts new file mode 100644 index 00000000000..b2c132a399e --- /dev/null +++ b/tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts @@ -0,0 +1,13 @@ +//@noUnusedParameters:true + +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; diff --git a/tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts b/tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts new file mode 100644 index 00000000000..b305f7a8d72 --- /dev/null +++ b/tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts @@ -0,0 +1,13 @@ +//@noUnusedLocals:true + +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; diff --git a/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts b/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts index dc66534118f..ed4c23411db 100644 --- a/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts +++ b/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts @@ -1,4 +1,4 @@ -//@noUnusedLocals:true +//@noUnusedParameters:true function f<_T, U>() { } @@ -6,4 +6,8 @@ type T<_T, U> = { }; interface I<_T, U> { }; -class C<_T, U> { }; +class C<_T, U> { + public m<_V, W>() { } +}; + +let l = <_T, U>() => { }; diff --git a/tests/cases/fourslash/unusedTypeParametersInClass1.ts b/tests/cases/fourslash/unusedTypeParametersInClass1.ts index 327558922e7..86beb10a445 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true ////[|class greeter |] { ////} diff --git a/tests/cases/fourslash/unusedTypeParametersInClass2.ts b/tests/cases/fourslash/unusedTypeParametersInClass2.ts index 4f78aa3fbe9..23a4c39602d 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass2.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true ////[|class greeter |] { //// public a: X; ////} diff --git a/tests/cases/fourslash/unusedTypeParametersInClass3.ts b/tests/cases/fourslash/unusedTypeParametersInClass3.ts index f0b12f868f1..8312830407b 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass3.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass3.ts @@ -1,7 +1,7 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true ////[|class greeter |] { //// public a: X; //// public b: Z; diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction1.ts b/tests/cases/fourslash/unusedTypeParametersInFunction1.ts index a33ecf60ea6..686ced26503 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// [|function f1() {}|] verify.codeFix({ diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction2.ts b/tests/cases/fourslash/unusedTypeParametersInFunction2.ts index 9c0d9e7b098..87d7e90207b 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction2.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// [|function f1(a: X) {a}|] verify.codeFix({ diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction3.ts b/tests/cases/fourslash/unusedTypeParametersInFunction3.ts index 0c8ea449731..0a3bc6bb79b 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction3.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction3.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// [|function f1(a: X) {a;var b:Z;b}|] verify.codeFix({ diff --git a/tests/cases/fourslash/unusedTypeParametersInLambda4.ts b/tests/cases/fourslash/unusedTypeParametersInLambda4.ts index b3e3f4b11f3..b9a258bac3d 100644 --- a/tests/cases/fourslash/unusedTypeParametersInLambda4.ts +++ b/tests/cases/fourslash/unusedTypeParametersInLambda4.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class A { //// public x: T; //// } diff --git a/tests/cases/fourslash/unusedTypeParametersInMethod1.ts b/tests/cases/fourslash/unusedTypeParametersInMethod1.ts index 260a9399650..a3afd76251d 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethod1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethod1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class C1 { //// [|f1()|] {} //// } diff --git a/tests/cases/fourslash/unusedTypeParametersInMethod2.ts b/tests/cases/fourslash/unusedTypeParametersInMethod2.ts index 377642c5bd5..3ca7a0f8a87 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethod2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethod2.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class C1 { //// [|f1(a: U)|] {a;} //// } diff --git a/tests/cases/fourslash/unusedTypeParametersInMethods1.ts b/tests/cases/fourslash/unusedTypeParametersInMethods1.ts index 4a538fb4b39..d394d9af772 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethods1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethods1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class A { //// [|public f1(a: X)|] { a; var b: Z; b } //// } From cae4bc5e83b38e724a13a3f8d86920b7c167a757 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 25 Jan 2018 17:48:22 -0800 Subject: [PATCH 40/41] Move createTextChange to services/utilities.ts (#21416) * Move createTextChange to services/utilities.ts * Use separate functions instead of overloads --- src/services/codefixes/disableJsDiagnostics.ts | 18 +++++------------- src/services/codefixes/fixJSDocTypes.ts | 2 +- src/services/codefixes/inferFromUsage.ts | 2 +- src/services/formatting/formatting.ts | 8 ++------ src/services/textChanges.ts | 5 +---- src/services/utilities.ts | 8 ++++++++ 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/services/codefixes/disableJsDiagnostics.ts b/src/services/codefixes/disableJsDiagnostics.ts index 3bcbf886df8..091ee07a9cc 100644 --- a/src/services/codefixes/disableJsDiagnostics.ts +++ b/src/services/codefixes/disableJsDiagnostics.ts @@ -24,13 +24,9 @@ namespace ts.codefix { }, { description: getLocaleSpecificMessage(Diagnostics.Disable_checking_for_this_file), - changes: [createFileTextChanges(sourceFile.fileName, [{ - span: { - start: sourceFile.checkJsDirective ? sourceFile.checkJsDirective.pos : 0, - length: sourceFile.checkJsDirective ? sourceFile.checkJsDirective.end - sourceFile.checkJsDirective.pos : 0 - }, - newText: `// @ts-nocheck${newLineCharacter}` - }])], + changes: [createFileTextChanges(sourceFile.fileName, [ + createTextChange(sourceFile.checkJsDirective ? createTextSpanFromBounds(sourceFile.checkJsDirective.pos, sourceFile.checkJsDirective.end) : createTextSpan(0, 0), `// @ts-nocheck${newLineCharacter}`), + ])], // fixId unnecessary because adding `// @ts-nocheck` even once will ignore every error in the file. fixId: undefined, }]; @@ -62,15 +58,11 @@ namespace ts.codefix { const token = getTouchingToken(sourceFile, startPosition, /*includeJsDocComment*/ false); const tokenLeadingComments = getLeadingCommentRangesOfNode(token, sourceFile); if (!tokenLeadingComments || !tokenLeadingComments.length || tokenLeadingComments[0].pos >= startPosition) { - return { lineNumber, change: createTextChange(startPosition, 0, `// @ts-ignore${newLineCharacter}`) }; + return { lineNumber, change: createTextChangeFromStartLength(startPosition, 0, `// @ts-ignore${newLineCharacter}`) }; } } // If all fails, add an extra new line immediately before the error span. - return { lineNumber, change: createTextChange(position, 0, `${position === startPosition ? "" : newLineCharacter}// @ts-ignore${newLineCharacter}`) }; - } - - function createTextChange(start: number, length: number, newText: string): TextChange { - return { span: { start, length }, newText }; + return { lineNumber, change: createTextChangeFromStartLength(position, 0, `${position === startPosition ? "" : newLineCharacter}// @ts-ignore${newLineCharacter}`) }; } } diff --git a/src/services/codefixes/fixJSDocTypes.ts b/src/services/codefixes/fixJSDocTypes.ts index 8c43ed0cc7f..3158e90ce96 100644 --- a/src/services/codefixes/fixJSDocTypes.ts +++ b/src/services/codefixes/fixJSDocTypes.ts @@ -50,7 +50,7 @@ namespace ts.codefix { } function createChange(declaration: TypeNode, sourceFile: SourceFile, newText: string): TextChange { - return { span: createTextSpanFromBounds(declaration.getStart(sourceFile), declaration.getEnd()), newText }; + return createTextChange(createTextSpanFromNode(declaration, sourceFile), newText); } function typeString(type: Type, checker: TypeChecker): string { diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index 6f6b2f3c61e..2f3dae01acf 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -191,7 +191,7 @@ namespace ts.codefix { function makeChange(declaration: Declaration, start: number, type: Type | undefined, program: Program): TextChange | undefined { const typeString = type && typeToString(type, declaration, program.getTypeChecker()); - return typeString === undefined ? undefined : { span: createTextSpan(start, 0), newText: `: ${typeString}` }; + return typeString === undefined ? undefined : createTextChangeFromStartLength(start, 0, `: ${typeString}`); } function getReferences(token: PropertyName | Token, sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): Identifier[] { diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 818e2815944..22446a98ce2 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -1078,19 +1078,15 @@ namespace ts.formatting { trimTrailingWhitespacesForLines(startLine, endLine + 1, previousRange); } - function newTextChange(start: number, len: number, newText: string): TextChange { - return { span: createTextSpan(start, len), newText }; - } - function recordDelete(start: number, len: number) { if (len) { - edits.push(newTextChange(start, len, "")); + edits.push(createTextChangeFromStartLength(start, len, "")); } } function recordReplace(start: number, len: number, newText: string) { if (len || newText) { - edits.push(newTextChange(start, len, newText)); + edits.push(createTextChangeFromStartLength(start, len, newText)); } } diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 3674cd31b97..83b434aac7d 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -620,10 +620,7 @@ namespace ts.textChanges { const sourceFile = changesInFile[0].sourceFile; const fileTextChanges: FileTextChanges = { fileName: sourceFile.fileName, textChanges: [] }; for (const c of ChangeTracker.normalize(changesInFile)) { - fileTextChanges.textChanges.push({ - span: this.computeSpan(c, sourceFile), - newText: this.computeNewText(c, sourceFile) - }); + fileTextChanges.textChanges.push(createTextChange(this.computeSpan(c, sourceFile), this.computeNewText(c, sourceFile))); } fileChangesList.push(fileTextChanges); }); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index c724fa5643d..e30fd8cfe2d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1067,6 +1067,14 @@ namespace ts { return createTextSpanFromBounds(range.pos, range.end); } + export function createTextChangeFromStartLength(start: number, length: number, newText: string): TextChange { + return createTextChange(createTextSpan(start, length), newText); + } + + export function createTextChange(span: TextSpan, newText: string): TextChange { + return { span, newText }; + } + export const typeKeywords: ReadonlyArray = [ SyntaxKind.AnyKeyword, SyntaxKind.BooleanKeyword, From 7b855d8f67bfafbf4f481f5a8abe0b50a8993553 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 26 Jan 2018 17:11:10 -0800 Subject: [PATCH 41/41] Fix dependency for 'publish-nightly'. --- Jakefile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jakefile.js b/Jakefile.js index 9bef7946722..87fca36a841 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -594,7 +594,7 @@ task("configure-insiders", [configurePrereleaseJs], function () { }, { async: true }); desc("Configure, build, test, and publish the insiders release."); -task("publish-insiders", ["configure-nightly", "LKG", "clean", "setDebugMode", "runtests-parallel"], function () { +task("publish-insiders", ["configure-insiders", "LKG", "clean", "setDebugMode", "runtests-parallel"], function () { var cmd = "npm publish --tag insiders"; console.log(cmd); exec(cmd);