From 7acca501b6d7ab1ec29c784546ff83741d579613 Mon Sep 17 00:00:00 2001 From: gb714us Date: Fri, 7 Jun 2019 03:48:19 -0700 Subject: [PATCH 01/23] create outlining span for JsxFragment --- src/services/outliningElementsCollector.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 650a107f4a5..6e3a5dc6ecd 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -198,6 +198,8 @@ namespace ts.OutliningElementsCollector { return spanForObjectOrArrayLiteral(n, SyntaxKind.OpenBracketToken); case SyntaxKind.JsxElement: return spanForJSXElement(n); + case SyntaxKind.JsxFragment: + return spanForJSXFragment(n); case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxOpeningElement: return spanForJSXAttributes((n).attributes); @@ -210,6 +212,12 @@ namespace ts.OutliningElementsCollector { return createOutliningSpan(textSpan, OutliningSpanKind.Code, textSpan, /*autoCollapse*/ false, bannerText); } + function spanForJSXFragment(node: JsxFragment): OutliningSpan | undefined { + const textSpan = createTextSpanFromBounds(node.openingFragment.getStart(sourceFile), node.closingFragment.getEnd()); + const bannerText = "<>..."; + return createOutliningSpan(textSpan, OutliningSpanKind.Code, textSpan, /*autoCollapse*/ false, bannerText); + } + function spanForJSXAttributes(node: JsxAttributes): OutliningSpan | undefined { if (node.properties.length === 0) { return undefined; From 29f995829b6037273effd2838eae97ade82e31ee Mon Sep 17 00:00:00 2001 From: gb714us Date: Sat, 8 Jun 2019 15:23:50 -0700 Subject: [PATCH 02/23] Added test cases for JSXFragment span --- tests/cases/fourslash/getJSXOutliningSpans.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/cases/fourslash/getJSXOutliningSpans.tsx b/tests/cases/fourslash/getJSXOutliningSpans.tsx index fa4f541b193..f00eac19d5c 100644 --- a/tests/cases/fourslash/getJSXOutliningSpans.tsx +++ b/tests/cases/fourslash/getJSXOutliningSpans.tsx @@ -25,9 +25,12 @@ //// md: 5 //// }|]}|] //// /> +//// [|<> +//// text +//// |] //// |] //// ); //// }|] ////}|] -verify.outliningSpansInCurrentFile(test.ranges(), "code"); +verify.outliningSpansInCurrentFile(test.ranges(), "code"); \ No newline at end of file From 6e9d098d4134f865c9e352e46182ec6a2417dd41 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Wed, 3 Jul 2019 17:59:35 -0400 Subject: [PATCH 03/23] Adds support for completions after ASI inserted expressions Signed-off-by: Andrew Branch --- src/services/completions.ts | 18 +++++++++++++--- src/services/types.ts | 2 +- ...ompletionEntryAfterASIExpressionInClass.ts | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/completionEntryAfterASIExpressionInClass.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 6d1d48b22b8..ce8fec3f04f 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1538,7 +1538,7 @@ namespace ts.Completions { * Relevant symbols are stored in the captured 'symbols' variable. */ function tryGetClassLikeCompletionSymbols(): GlobalsSearch { - const decl = tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location); + const decl = tryGetObjectTypeDeclarationCompletionContainer(sourceFile, contextToken, location, position); if (!decl) return GlobalsSearch.Continue; // We're looking up possible property names from parent type. @@ -2155,7 +2155,7 @@ namespace ts.Completions { * Returns the immediate owning class declaration of a context token, * on the condition that one exists and that the context implies completion should be given. */ - function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile, contextToken: Node | undefined, location: Node): ObjectTypeDeclaration | undefined { + function tryGetObjectTypeDeclarationCompletionContainer(sourceFile: SourceFile, contextToken: Node | undefined, location: Node, position: number): ObjectTypeDeclaration | undefined { // class c { method() { } | method2() { } } switch (location.kind) { case SyntaxKind.SyntaxList: @@ -2165,9 +2165,15 @@ namespace ts.Completions { if (cls && !findChildOfKind(cls, SyntaxKind.CloseBraceToken, sourceFile)) { return cls; } + break; + case SyntaxKind.Identifier: // class c extends React.Component { a: () => 1\n compon| } + if (isFromObjectTypeDeclaration(location)) { + return findAncestor(location, isObjectTypeDeclaration); + } } if (!contextToken) return undefined; + switch (contextToken.kind) { case SyntaxKind.SemicolonToken: // class c {getValue(): number; | } case SyntaxKind.CloseBraceToken: // class c { method() { } | } @@ -2179,7 +2185,13 @@ namespace ts.Completions { case SyntaxKind.CommaToken: // class c {getValue(): number, | } return tryCast(contextToken.parent, isObjectTypeDeclaration); default: - if (!isFromObjectTypeDeclaration(contextToken)) return undefined; + if (!isFromObjectTypeDeclaration(contextToken)) { + // class c extends React.Component { a: () => 1\n| } + if (getLineAndCharacterOfPosition(sourceFile, contextToken.getEnd()).line !== getLineAndCharacterOfPosition(sourceFile, position).line && isObjectTypeDeclaration(location)) { + return location; + } + return undefined; + } const isValidKeyword = isClassLike(contextToken.parent.parent) ? isClassMemberCompletionKeyword : isInterfaceOrTypeLiteralCompletionKeyword; return (isValidKeyword(contextToken.kind) || contextToken.kind === SyntaxKind.AsteriskToken || isIdentifier(contextToken) && isValidKeyword(stringToToken(contextToken.text)!)) // TODO: GH#18217 ? contextToken.parent.parent as ObjectTypeDeclaration : undefined; diff --git a/src/services/types.ts b/src/services/types.ts index b97125734f7..099263063a8 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -892,7 +892,7 @@ namespace ts { } export interface CompletionInfo { - /** Not true for all glboal completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ + /** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ isGlobalCompletion: boolean; isMemberCompletion: boolean; diff --git a/tests/cases/fourslash/completionEntryAfterASIExpressionInClass.ts b/tests/cases/fourslash/completionEntryAfterASIExpressionInClass.ts new file mode 100644 index 00000000000..61271140ad0 --- /dev/null +++ b/tests/cases/fourslash/completionEntryAfterASIExpressionInClass.ts @@ -0,0 +1,21 @@ +/// + +//// class Parent { +//// protected shouldWork() { +//// console.log(); +//// } +//// } +//// +//// class Child extends Parent { +//// // this assumes ASI, but on next line wants to +//// x = () => 1 +//// shoul/*insideid*/ +//// } +//// +//// class ChildTwo extends Parent { +//// // this assumes ASI, but on next line wants to +//// x = () => 1 +//// /*root*/ //nothing +//// } + +verify.completions({ marker: ["insideid", "root"], includes: "shouldWork", isNewIdentifierLocation: true }); From e55f97ec282d720f9bf58792ece0acc048202f93 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 8 Jul 2019 14:43:06 -0400 Subject: [PATCH 04/23] Updates the baselines for the typo fixes --- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 944092e13d0..7853a4855ef 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5398,7 +5398,7 @@ declare namespace ts { argumentCount: number; } interface CompletionInfo { - /** Not true for all glboal completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ + /** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ isGlobalCompletion: boolean; isMemberCompletion: boolean; /** diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index be8eea8062b..142ed88a111 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5398,7 +5398,7 @@ declare namespace ts { argumentCount: number; } interface CompletionInfo { - /** Not true for all glboal completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ + /** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */ isGlobalCompletion: boolean; isMemberCompletion: boolean; /** From dfc97db32325ed86ff86e51f6091714aa21dda65 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 11 Jul 2019 14:26:03 -0400 Subject: [PATCH 05/23] Don't add extra indentation for objects inside function parameters --- src/services/formatting/smartIndenter.ts | 3 ++- ...dentionsOfObjectsInAListAfterFormatting.ts | 2 +- .../formatMultipleFunctionArguments.ts | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/formatMultipleFunctionArguments.ts diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 0c9e7b186f7..62f4c3c556c 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -482,7 +482,6 @@ namespace ts.formatting { case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.Block: case SyntaxKind.ModuleBlock: - case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TypeLiteral: case SyntaxKind.MappedType: case SyntaxKind.TupleType: @@ -524,6 +523,8 @@ namespace ts.formatting { return rangeIsOnOneLine(sourceFile, child!); } return true; + case SyntaxKind.CallExpression: + return childKind !== SyntaxKind.ObjectLiteralExpression case SyntaxKind.DoStatement: case SyntaxKind.WhileStatement: case SyntaxKind.ForInStatement: diff --git a/tests/cases/fourslash/consistenceOnIndentionsOfObjectsInAListAfterFormatting.ts b/tests/cases/fourslash/consistenceOnIndentionsOfObjectsInAListAfterFormatting.ts index 14ada206026..bbcdaec9cad 100644 --- a/tests/cases/fourslash/consistenceOnIndentionsOfObjectsInAListAfterFormatting.ts +++ b/tests/cases/fourslash/consistenceOnIndentionsOfObjectsInAListAfterFormatting.ts @@ -8,4 +8,4 @@ format.document(); goTo.marker("1"); verify.currentLineContentIs("}, {"); goTo.marker("2"); -verify.currentLineContentIs(" });"); \ No newline at end of file +verify.currentLineContentIs("});"); diff --git a/tests/cases/fourslash/formatMultipleFunctionArguments.ts b/tests/cases/fourslash/formatMultipleFunctionArguments.ts new file mode 100644 index 00000000000..1e3909305a6 --- /dev/null +++ b/tests/cases/fourslash/formatMultipleFunctionArguments.ts @@ -0,0 +1,26 @@ +/// + +//// +//// someRandomFunction({ +//// prop1: 1, +//// prop2: 2 +//// }, { +//// prop3: 3, +//// prop4: 4 +//// }, { +//// prop5: 5, +//// prop6: 6 +//// }); + +format.document(); +verify.currentFileContentIs(` +someRandomFunction({ + prop1: 1, + prop2: 2 +}, { + prop3: 3, + prop4: 4 +}, { + prop5: 5, + prop6: 6 +});`); From 0e273c3e07666d201bb434a6c822a2efbaec5a77 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 11 Jul 2019 10:45:19 -1000 Subject: [PATCH 06/23] Fix type parameter inference cache invalidation --- src/compiler/checker.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5d5d99f62c6..b840417db3b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15229,8 +15229,8 @@ namespace ts { const inference = inferences[i]; if (t === inference.typeParameter) { if (fix && !inference.isFixed) { + clearCachedInferences(inferences); inference.isFixed = true; - inference.inferredType = undefined; } return getInferredType(context, i); } @@ -15238,6 +15238,14 @@ namespace ts { return t; } + function clearCachedInferences(inferences: InferenceInfo[]) { + for (const inference of inferences) { + if (!inference.isFixed) { + inference.inferredType = undefined; + } + } + } + function createInferenceInfo(typeParameter: TypeParameter): InferenceInfo { return { typeParameter, @@ -15517,17 +15525,17 @@ namespace ts { if (contravariant && !bivariant) { if (!contains(inference.contraCandidates, candidate)) { inference.contraCandidates = append(inference.contraCandidates, candidate); - inference.inferredType = undefined; + clearCachedInferences(inferences); } } else if (!contains(inference.candidates, candidate)) { inference.candidates = append(inference.candidates, candidate); - inference.inferredType = undefined; + clearCachedInferences(inferences); } } if (!(priority & InferencePriority.ReturnType) && target.flags & TypeFlags.TypeParameter && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) { inference.topLevel = false; - inference.inferredType = undefined; + clearCachedInferences(inferences); } } return; From c53246fa35bb0e8f931042240e0fe28d5c34f31a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 11 Jul 2019 10:47:27 -1000 Subject: [PATCH 07/23] Add regression test --- .../typeInferenceCacheInvalidation.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/cases/compiler/typeInferenceCacheInvalidation.ts diff --git a/tests/cases/compiler/typeInferenceCacheInvalidation.ts b/tests/cases/compiler/typeInferenceCacheInvalidation.ts new file mode 100644 index 00000000000..d037f139ec5 --- /dev/null +++ b/tests/cases/compiler/typeInferenceCacheInvalidation.ts @@ -0,0 +1,23 @@ +// @strict: true + +// Repro from #32230 + +type Callback = (foo: TFoo, bar: TBar) => any + +declare function example>( + foo: TFoo, + callback: TCallback, + bar: TBar, +): TCallback + +example(42, (foo, bar) => ({ + t: () => { + let s: string = bar; + } +}), '42'); + +example(42, (foo, bar) => ({ + t() { + let s: string = bar; + } +}), '42'); From 4b9ca33e1d532b33da2331420b5353bb9a5ae576 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 11 Jul 2019 10:47:34 -1000 Subject: [PATCH 08/23] Accept new baselines --- .../typeInferenceCacheInvalidation.js | 37 +++++++++++ .../typeInferenceCacheInvalidation.symbols | 64 +++++++++++++++++++ .../typeInferenceCacheInvalidation.types | 63 ++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 tests/baselines/reference/typeInferenceCacheInvalidation.js create mode 100644 tests/baselines/reference/typeInferenceCacheInvalidation.symbols create mode 100644 tests/baselines/reference/typeInferenceCacheInvalidation.types diff --git a/tests/baselines/reference/typeInferenceCacheInvalidation.js b/tests/baselines/reference/typeInferenceCacheInvalidation.js new file mode 100644 index 00000000000..bda29ad8b70 --- /dev/null +++ b/tests/baselines/reference/typeInferenceCacheInvalidation.js @@ -0,0 +1,37 @@ +//// [typeInferenceCacheInvalidation.ts] +// Repro from #32230 + +type Callback = (foo: TFoo, bar: TBar) => any + +declare function example>( + foo: TFoo, + callback: TCallback, + bar: TBar, +): TCallback + +example(42, (foo, bar) => ({ + t: () => { + let s: string = bar; + } +}), '42'); + +example(42, (foo, bar) => ({ + t() { + let s: string = bar; + } +}), '42'); + + +//// [typeInferenceCacheInvalidation.js] +"use strict"; +// Repro from #32230 +example(42, function (foo, bar) { return ({ + t: function () { + var s = bar; + } +}); }, '42'); +example(42, function (foo, bar) { return ({ + t: function () { + var s = bar; + } +}); }, '42'); diff --git a/tests/baselines/reference/typeInferenceCacheInvalidation.symbols b/tests/baselines/reference/typeInferenceCacheInvalidation.symbols new file mode 100644 index 00000000000..e9e1949dc91 --- /dev/null +++ b/tests/baselines/reference/typeInferenceCacheInvalidation.symbols @@ -0,0 +1,64 @@ +=== tests/cases/compiler/typeInferenceCacheInvalidation.ts === +// Repro from #32230 + +type Callback = (foo: TFoo, bar: TBar) => any +>Callback : Symbol(Callback, Decl(typeInferenceCacheInvalidation.ts, 0, 0)) +>TFoo : Symbol(TFoo, Decl(typeInferenceCacheInvalidation.ts, 2, 14)) +>TBar : Symbol(TBar, Decl(typeInferenceCacheInvalidation.ts, 2, 19)) +>foo : Symbol(foo, Decl(typeInferenceCacheInvalidation.ts, 2, 29)) +>TFoo : Symbol(TFoo, Decl(typeInferenceCacheInvalidation.ts, 2, 14)) +>bar : Symbol(bar, Decl(typeInferenceCacheInvalidation.ts, 2, 39)) +>TBar : Symbol(TBar, Decl(typeInferenceCacheInvalidation.ts, 2, 19)) + +declare function example>( +>example : Symbol(example, Decl(typeInferenceCacheInvalidation.ts, 2, 57)) +>TFoo : Symbol(TFoo, Decl(typeInferenceCacheInvalidation.ts, 4, 25)) +>TBar : Symbol(TBar, Decl(typeInferenceCacheInvalidation.ts, 4, 30)) +>TCallback : Symbol(TCallback, Decl(typeInferenceCacheInvalidation.ts, 4, 36)) +>Callback : Symbol(Callback, Decl(typeInferenceCacheInvalidation.ts, 0, 0)) +>TFoo : Symbol(TFoo, Decl(typeInferenceCacheInvalidation.ts, 4, 25)) +>TBar : Symbol(TBar, Decl(typeInferenceCacheInvalidation.ts, 4, 30)) + + foo: TFoo, +>foo : Symbol(foo, Decl(typeInferenceCacheInvalidation.ts, 4, 77)) +>TFoo : Symbol(TFoo, Decl(typeInferenceCacheInvalidation.ts, 4, 25)) + + callback: TCallback, +>callback : Symbol(callback, Decl(typeInferenceCacheInvalidation.ts, 5, 14)) +>TCallback : Symbol(TCallback, Decl(typeInferenceCacheInvalidation.ts, 4, 36)) + + bar: TBar, +>bar : Symbol(bar, Decl(typeInferenceCacheInvalidation.ts, 6, 24)) +>TBar : Symbol(TBar, Decl(typeInferenceCacheInvalidation.ts, 4, 30)) + +): TCallback +>TCallback : Symbol(TCallback, Decl(typeInferenceCacheInvalidation.ts, 4, 36)) + +example(42, (foo, bar) => ({ +>example : Symbol(example, Decl(typeInferenceCacheInvalidation.ts, 2, 57)) +>foo : Symbol(foo, Decl(typeInferenceCacheInvalidation.ts, 10, 13)) +>bar : Symbol(bar, Decl(typeInferenceCacheInvalidation.ts, 10, 17)) + + t: () => { +>t : Symbol(t, Decl(typeInferenceCacheInvalidation.ts, 10, 28)) + + let s: string = bar; +>s : Symbol(s, Decl(typeInferenceCacheInvalidation.ts, 12, 11)) +>bar : Symbol(bar, Decl(typeInferenceCacheInvalidation.ts, 10, 17)) + } +}), '42'); + +example(42, (foo, bar) => ({ +>example : Symbol(example, Decl(typeInferenceCacheInvalidation.ts, 2, 57)) +>foo : Symbol(foo, Decl(typeInferenceCacheInvalidation.ts, 16, 13)) +>bar : Symbol(bar, Decl(typeInferenceCacheInvalidation.ts, 16, 17)) + + t() { +>t : Symbol(t, Decl(typeInferenceCacheInvalidation.ts, 16, 28)) + + let s: string = bar; +>s : Symbol(s, Decl(typeInferenceCacheInvalidation.ts, 18, 11)) +>bar : Symbol(bar, Decl(typeInferenceCacheInvalidation.ts, 16, 17)) + } +}), '42'); + diff --git a/tests/baselines/reference/typeInferenceCacheInvalidation.types b/tests/baselines/reference/typeInferenceCacheInvalidation.types new file mode 100644 index 00000000000..35911fafb39 --- /dev/null +++ b/tests/baselines/reference/typeInferenceCacheInvalidation.types @@ -0,0 +1,63 @@ +=== tests/cases/compiler/typeInferenceCacheInvalidation.ts === +// Repro from #32230 + +type Callback = (foo: TFoo, bar: TBar) => any +>Callback : Callback +>foo : TFoo +>bar : TBar + +declare function example>( +>example : >(foo: TFoo, callback: TCallback, bar: TBar) => TCallback + + foo: TFoo, +>foo : TFoo + + callback: TCallback, +>callback : TCallback + + bar: TBar, +>bar : TBar + +): TCallback + +example(42, (foo, bar) => ({ +>example(42, (foo, bar) => ({ t: () => { let s: string = bar; }}), '42') : (foo: number, bar: string) => { t: () => void; } +>example : >(foo: TFoo, callback: TCallback, bar: TBar) => TCallback +>42 : 42 +>(foo, bar) => ({ t: () => { let s: string = bar; }}) : (foo: number, bar: string) => { t: () => void; } +>foo : number +>bar : string +>({ t: () => { let s: string = bar; }}) : { t: () => void; } +>{ t: () => { let s: string = bar; }} : { t: () => void; } + + t: () => { +>t : () => void +>() => { let s: string = bar; } : () => void + + let s: string = bar; +>s : string +>bar : string + } +}), '42'); +>'42' : "42" + +example(42, (foo, bar) => ({ +>example(42, (foo, bar) => ({ t() { let s: string = bar; }}), '42') : (foo: number, bar: string) => { t(): void; } +>example : >(foo: TFoo, callback: TCallback, bar: TBar) => TCallback +>42 : 42 +>(foo, bar) => ({ t() { let s: string = bar; }}) : (foo: number, bar: string) => { t(): void; } +>foo : number +>bar : string +>({ t() { let s: string = bar; }}) : { t(): void; } +>{ t() { let s: string = bar; }} : { t(): void; } + + t() { +>t : () => void + + let s: string = bar; +>s : string +>bar : string + } +}), '42'); +>'42' : "42" + From 84f4acdb89e3d2cd202c7e43933d661cfa8da29d Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 11 Jul 2019 20:34:41 -0400 Subject: [PATCH 09/23] Add kind to JsxAttributes. --- src/compiler/types.ts | 1 + tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a88580f9b12..439dfb5f98e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1882,6 +1882,7 @@ namespace ts { } export interface JsxAttributes extends ObjectLiteralExpressionBase { + kind: SyntaxKind.JsxAttributes; parent: JsxOpeningLikeElement; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b4a089f63b9..fb39db1d3e0 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1155,6 +1155,7 @@ declare namespace ts { expression: JsxTagNameExpression; } interface JsxAttributes extends ObjectLiteralExpressionBase { + kind: SyntaxKind.JsxAttributes; parent: JsxOpeningLikeElement; } interface JsxOpeningElement extends Expression { diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 46f1c31e6e3..c9d6a220e6f 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1155,6 +1155,7 @@ declare namespace ts { expression: JsxTagNameExpression; } interface JsxAttributes extends ObjectLiteralExpressionBase { + kind: SyntaxKind.JsxAttributes; parent: JsxOpeningLikeElement; } interface JsxOpeningElement extends Expression { From 8516127a05995b5f8329629e5def8efc461715f8 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 12 Jul 2019 07:57:55 -0700 Subject: [PATCH 10/23] Fix regression of generic T assignability to Partial (#32354) --- src/compiler/checker.ts | 3 ++- .../reference/mappedTypeRelationships.errors.txt | 4 ++++ tests/baselines/reference/mappedTypeRelationships.js | 10 ++++++++++ .../reference/mappedTypeRelationships.symbols | 12 ++++++++++++ .../reference/mappedTypeRelationships.types | 10 ++++++++++ .../types/mapped/mappedTypeRelationships.ts | 4 ++++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 978f841a292..06350fba335 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13450,7 +13450,8 @@ namespace ts { if (includeOptional ? !(filteredByApplicability!.flags & TypeFlags.Never) : isRelatedTo(targetConstraint, sourceKeys)) { - const indexingType = filteredByApplicability || getTypeParameterFromMappedType(target); + const typeParameter = getTypeParameterFromMappedType(target); + const indexingType = filteredByApplicability ? getIntersectionType([filteredByApplicability, typeParameter]) : typeParameter; const indexedAccessType = getIndexedAccessType(source, indexingType); const templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index 8f33c7414b1..b43effeb998 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -392,4 +392,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS function f90() { const n: Numeric = { x: 1 }; } + + function f(): Partial { + return undefined! as T; + } \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeRelationships.js b/tests/baselines/reference/mappedTypeRelationships.js index ea448f5fb92..deb240454c3 100644 --- a/tests/baselines/reference/mappedTypeRelationships.js +++ b/tests/baselines/reference/mappedTypeRelationships.js @@ -186,6 +186,10 @@ type Numeric = { [K in keyof T]?: number }; function f90() { const n: Numeric = { x: 1 }; } + +function f(): Partial { + return undefined! as T; +} //// [mappedTypeRelationships.js] @@ -319,6 +323,9 @@ function f82(t, k1, k2) { function f90() { var n = { x: 1 }; } +function f() { + return undefined; +} //// [mappedTypeRelationships.d.ts] @@ -408,3 +415,6 @@ declare type Numeric = { declare function f90(): void; +declare function f(): Partial; diff --git a/tests/baselines/reference/mappedTypeRelationships.symbols b/tests/baselines/reference/mappedTypeRelationships.symbols index c70cf1c07a0..f50d49cde3a 100644 --- a/tests/baselines/reference/mappedTypeRelationships.symbols +++ b/tests/baselines/reference/mappedTypeRelationships.symbols @@ -824,3 +824,15 @@ function f90() { >x : Symbol(x, Decl(mappedTypeRelationships.ts, 185, 27)) } +function f(): Partial { +>f : Symbol(f, Decl(mappedTypeRelationships.ts, 186, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 188, 11)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 188, 22)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 188, 11)) + + return undefined! as T; +>undefined : Symbol(undefined) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 188, 11)) +} + diff --git a/tests/baselines/reference/mappedTypeRelationships.types b/tests/baselines/reference/mappedTypeRelationships.types index b130e05bfa5..f138f86e521 100644 --- a/tests/baselines/reference/mappedTypeRelationships.types +++ b/tests/baselines/reference/mappedTypeRelationships.types @@ -668,3 +668,13 @@ function f90() { >1 : 1 } +function f(): Partial { +>f : () => Partial +>x : {} + + return undefined! as T; +>undefined! as T : T +>undefined! : never +>undefined : undefined +} + diff --git a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts index f140d84687a..9bec21145b2 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts @@ -188,3 +188,7 @@ type Numeric = { [K in keyof T]?: number }; function f90() { const n: Numeric = { x: 1 }; } + +function f(): Partial { + return undefined! as T; +} From 4e49706c72b88f5ecbd517eaa7708e30316f5cd3 Mon Sep 17 00:00:00 2001 From: csigs Date: Fri, 12 Jul 2019 16:10:19 +0000 Subject: [PATCH 11/23] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl index c368422da3d..4a7941396b4 100644 --- a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -1,4 +1,4 @@ - + @@ -3301,7 +3301,7 @@ - + @@ -4123,7 +4123,7 @@ - + From 71bec5b69872569842b7e40bc3cce3d8d5e7d724 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 12 Jul 2019 10:07:55 -0700 Subject: [PATCH 12/23] Add quick fix to add missing 'await' (#32356) * Start prototyping addMissingAwait codefix * Filter by diagnostics that have missing-await related info * Start writing tests and checking precedence * Implement codeFixAll, add test for binary expressions * Add test for iterables * Add test for passing argument * Add test for call/construct signatures * Add test for awaiting initializer * Improve assertion error * Replace specific property access error with general one and add await related info * Add test for property access * Require code to be inside a function body to offer await * Accept suggestion Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> * Add explicit test for code fix being not available unless something is a Promise * Skip looking for function body if already in AwaitContext flags * Inline getCodeActions function for symmetry --- src/compiler/checker.ts | 3 +- src/compiler/diagnosticMessages.json | 17 +- src/harness/fourslash.ts | 25 ++- src/services/codefixes/addMissingAwait.ts | 173 ++++++++++++++++++ src/services/textChanges.ts | 4 + src/services/tsconfig.json | 1 + ...erationsAvailableOnPromisedType.errors.txt | 5 +- .../codeFixAddMissingAwait_argument.ts | 13 ++ ...odeFixAddMissingAwait_binaryExpressions.ts | 50 +++++ .../codeFixAddMissingAwait_initializer.ts | 28 +++ .../codeFixAddMissingAwait_iterables.ts | 50 +++++ ...MissingAwait_notAvailableWithoutPromise.ts | 6 + .../codeFixAddMissingAwait_propertyAccess.ts | 13 ++ .../codeFixAddMissingAwait_signatures.ts | 50 +++++ .../codeFixAddMissingAwait_topLevel.ts | 10 + tests/cases/fourslash/fourslash.ts | 2 +- 16 files changed, 438 insertions(+), 12 deletions(-) create mode 100644 src/services/codefixes/addMissingAwait.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_argument.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_binaryExpressions.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_initializer.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_iterables.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_notAvailableWithoutPromise.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_propertyAccess.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_signatures.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingAwait_topLevel.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 06350fba335..b761606fcb3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20715,7 +20715,8 @@ namespace ts { else { const promisedType = getPromisedTypeOfPromise(containingType); if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) { - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType)); + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType)); + relatedInfo = createDiagnosticForNode(propNode, Diagnostics.Did_you_forget_to_use_await); } else { const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 16b16732694..7fc2fdd4237 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2076,10 +2076,6 @@ "category": "Error", "code": 2569 }, - "Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?": { - "category": "Error", - "code": 2570 - }, "Object is of type 'unknown'.": { "category": "Error", "code": 2571 @@ -5087,6 +5083,19 @@ "category": "Message", "code": 95082 }, + "Add 'await'": { + "category": "Message", + "code": 95083 + }, + "Add 'await' to initializer for '{0}'": { + "category": "Message", + "code": 95084 + }, + "Fix all expressions possibly missing 'await'": { + "category": "Message", + "code": 95085 + }, + "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", "code": 18004 diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ffc0759e92e..5d5338db1f4 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2828,11 +2828,28 @@ Actual: ${stringify(fullActual)}`); } } - public verifyCodeFixAvailable(negative: boolean, expected: FourSlashInterface.VerifyCodeFixAvailableOptions[] | undefined): void { - assert(!negative || !expected); + public verifyCodeFixAvailable(negative: boolean, expected: FourSlashInterface.VerifyCodeFixAvailableOptions[] | string | undefined): void { const codeFixes = this.getCodeFixes(this.activeFile.fileName); - const actuals = codeFixes.map((fix): FourSlashInterface.VerifyCodeFixAvailableOptions => ({ description: fix.description, commands: fix.commands })); - this.assertObjectsEqual(actuals, negative ? ts.emptyArray : expected); + if (negative) { + if (typeof expected === "undefined") { + this.assertObjectsEqual(codeFixes, ts.emptyArray); + } + else if (typeof expected === "string") { + if (codeFixes.some(fix => fix.fixName === expected)) { + this.raiseError(`Expected not to find a fix with the name '${expected}', but one exists.`); + } + } + else { + assert(typeof expected === "undefined" || typeof expected === "string", "With a negated assertion, 'expected' must be undefined or a string value of a codefix name."); + } + } + else if (typeof expected === "string") { + this.assertObjectsEqual(codeFixes.map(fix => fix.fixName), [expected]); + } + else { + const actuals = codeFixes.map((fix): FourSlashInterface.VerifyCodeFixAvailableOptions => ({ description: fix.description, commands: fix.commands })); + this.assertObjectsEqual(actuals, negative ? ts.emptyArray : expected); + } } public verifyApplicableRefactorAvailableAtMarker(negative: boolean, markerName: string) { diff --git a/src/services/codefixes/addMissingAwait.ts b/src/services/codefixes/addMissingAwait.ts new file mode 100644 index 00000000000..3545c65faf9 --- /dev/null +++ b/src/services/codefixes/addMissingAwait.ts @@ -0,0 +1,173 @@ +/* @internal */ +namespace ts.codefix { + type ContextualTrackChangesFunction = (cb: (changeTracker: textChanges.ChangeTracker) => void) => FileTextChanges[]; + const fixId = "addMissingAwait"; + const propertyAccessCode = Diagnostics.Property_0_does_not_exist_on_type_1.code; + const callableConstructableErrorCodes = [ + Diagnostics.This_expression_is_not_callable.code, + Diagnostics.This_expression_is_not_constructable.code, + ]; + const errorCodes = [ + Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type.code, + Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code, + Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code, + Diagnostics.Operator_0_cannot_be_applied_to_type_1.code, + Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2.code, + Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code, + Diagnostics.Type_0_is_not_an_array_type.code, + Diagnostics.Type_0_is_not_an_array_type_or_a_string_type.code, + Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators.code, + Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator.code, + Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator.code, + Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator.code, + Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator.code, + Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code, + propertyAccessCode, + ...callableConstructableErrorCodes, + ]; + + registerCodeFix({ + fixIds: [fixId], + errorCodes, + getCodeActions: context => { + const { sourceFile, errorCode, span, cancellationToken, program } = context; + const expression = getAwaitableExpression(sourceFile, errorCode, span, cancellationToken, program); + if (!expression) { + return; + } + + const checker = context.program.getTypeChecker(); + const trackChanges: ContextualTrackChangesFunction = cb => textChanges.ChangeTracker.with(context, cb); + return compact([ + getDeclarationSiteFix(context, expression, errorCode, checker, trackChanges), + getUseSiteFix(context, expression, errorCode, checker, trackChanges)]); + }, + getAllCodeActions: context => { + const { sourceFile, program, cancellationToken } = context; + const checker = context.program.getTypeChecker(); + return codeFixAll(context, errorCodes, (t, diagnostic) => { + const expression = getAwaitableExpression(sourceFile, diagnostic.code, diagnostic, cancellationToken, program); + if (!expression) { + return; + } + const trackChanges: ContextualTrackChangesFunction = cb => (cb(t), []); + return getDeclarationSiteFix(context, expression, diagnostic.code, checker, trackChanges) + || getUseSiteFix(context, expression, diagnostic.code, checker, trackChanges); + }); + }, + }); + + function getDeclarationSiteFix(context: CodeFixContext | CodeFixAllContext, expression: Expression, errorCode: number, checker: TypeChecker, trackChanges: ContextualTrackChangesFunction) { + const { sourceFile } = context; + const awaitableInitializer = findAwaitableInitializer(expression, sourceFile, checker); + if (awaitableInitializer) { + const initializerChanges = trackChanges(t => makeChange(t, errorCode, sourceFile, checker, awaitableInitializer)); + return createCodeFixActionNoFixId( + "addMissingAwaitToInitializer", + initializerChanges, + [Diagnostics.Add_await_to_initializer_for_0, expression.getText(sourceFile)]); + } + } + + function getUseSiteFix(context: CodeFixContext | CodeFixAllContext, expression: Expression, errorCode: number, checker: TypeChecker, trackChanges: ContextualTrackChangesFunction) { + const changes = trackChanges(t => makeChange(t, errorCode, context.sourceFile, checker, expression)); + return createCodeFixAction(fixId, changes, Diagnostics.Add_await, fixId, Diagnostics.Fix_all_expressions_possibly_missing_await); + } + + function isMissingAwaitError(sourceFile: SourceFile, errorCode: number, span: TextSpan, cancellationToken: CancellationToken, program: Program) { + const checker = program.getDiagnosticsProducingTypeChecker(); + const diagnostics = checker.getDiagnostics(sourceFile, cancellationToken); + return some(diagnostics, ({ start, length, relatedInformation, code }) => + isNumber(start) && isNumber(length) && textSpansEqual({ start, length }, span) && + code === errorCode && + !!relatedInformation && + some(relatedInformation, related => related.code === Diagnostics.Did_you_forget_to_use_await.code)); + } + + function getAwaitableExpression(sourceFile: SourceFile, errorCode: number, span: TextSpan, cancellationToken: CancellationToken, program: Program): Expression | undefined { + const token = getTokenAtPosition(sourceFile, span.start); + // Checker has already done work to determine that await might be possible, and has attached + // related info to the node, so start by finding the expression that exactly matches up + // with the diagnostic range. + const expression = findAncestor(token, node => { + if (node.getStart(sourceFile) < span.start || node.getEnd() > textSpanEnd(span)) { + return "quit"; + } + return isExpression(node) && textSpansEqual(span, createTextSpanFromNode(node, sourceFile)); + }) as Expression | undefined; + + return expression + && isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program) + && isInsideAwaitableBody(expression) + ? expression + : undefined; + } + + function findAwaitableInitializer(expression: Node, sourceFile: SourceFile, checker: TypeChecker): Expression | undefined { + if (!isIdentifier(expression)) { + return; + } + + const symbol = checker.getSymbolAtLocation(expression); + if (!symbol) { + return; + } + + const declaration = tryCast(symbol.valueDeclaration, isVariableDeclaration); + const variableName = tryCast(declaration && declaration.name, isIdentifier); + const variableStatement = getAncestor(declaration, SyntaxKind.VariableStatement); + if (!declaration || !variableStatement || + declaration.type || + !declaration.initializer || + variableStatement.getSourceFile() !== sourceFile || + hasModifier(variableStatement, ModifierFlags.Export) || + !variableName || + !isInsideAwaitableBody(declaration.initializer)) { + return; + } + + const isUsedElsewhere = FindAllReferences.Core.eachSymbolReferenceInFile(variableName, checker, sourceFile, identifier => { + return identifier !== expression; + }); + + if (isUsedElsewhere) { + return; + } + + return declaration.initializer; + } + + function isInsideAwaitableBody(node: Node) { + return node.kind & NodeFlags.AwaitContext || !!findAncestor(node, ancestor => + ancestor.parent && isArrowFunction(ancestor.parent) && ancestor.parent.body === ancestor || + isBlock(ancestor) && ( + ancestor.parent.kind === SyntaxKind.FunctionDeclaration || + ancestor.parent.kind === SyntaxKind.FunctionExpression || + ancestor.parent.kind === SyntaxKind.ArrowFunction || + ancestor.parent.kind === SyntaxKind.MethodDeclaration)); + } + + function makeChange(changeTracker: textChanges.ChangeTracker, errorCode: number, sourceFile: SourceFile, checker: TypeChecker, insertionSite: Expression) { + if (isBinaryExpression(insertionSite)) { + const { left, right } = insertionSite; + const leftType = checker.getTypeAtLocation(left); + const rightType = checker.getTypeAtLocation(right); + const newLeft = checker.getPromisedTypeOfPromise(leftType) ? createAwait(left) : left; + const newRight = checker.getPromisedTypeOfPromise(rightType) ? createAwait(right) : right; + changeTracker.replaceNode(sourceFile, left, newLeft); + changeTracker.replaceNode(sourceFile, right, newRight); + } + else if (errorCode === propertyAccessCode && isPropertyAccessExpression(insertionSite.parent)) { + changeTracker.replaceNode( + sourceFile, + insertionSite.parent.expression, + createParen(createAwait(insertionSite.parent.expression))); + } + else if (contains(callableConstructableErrorCodes, errorCode) && isCallOrNewExpression(insertionSite.parent)) { + changeTracker.replaceNode(sourceFile, insertionSite, createParen(createAwait(insertionSite))); + } + else { + changeTracker.replaceNode(sourceFile, insertionSite, createAwait(insertionSite)); + } + } +} diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index f6af03aa2c5..f3e5bf9bfb5 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -704,6 +704,10 @@ namespace ts.textChanges { } } + public parenthesizeExpression(sourceFile: SourceFile, expression: Expression) { + this.replaceRange(sourceFile, rangeOfNode(expression), createParen(expression)); + } + private finishClassesWithNodesInsertedAtStart(): void { this.classesWithNodesInsertedAtStart.forEach(({ node, sourceFile }) => { const [openBraceEnd, closeBraceEnd] = getClassOrObjectBraceEnds(node, sourceFile); diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 5e6de0f15ca..05c1b0b482e 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -45,6 +45,7 @@ "codeFixProvider.ts", "refactorProvider.ts", "codefixes/addConvertToUnknownForNonOverlappingTypes.ts", + "codefixes/addMissingAwait.ts", "codefixes/addMissingConst.ts", "codefixes/addMissingInvocationForDecorator.ts", "codefixes/addNameToNamelessParameter.ts", diff --git a/tests/baselines/reference/operationsAvailableOnPromisedType.errors.txt b/tests/baselines/reference/operationsAvailableOnPromisedType.errors.txt index 23782741215..ffa16497ad2 100644 --- a/tests/baselines/reference/operationsAvailableOnPromisedType.errors.txt +++ b/tests/baselines/reference/operationsAvailableOnPromisedType.errors.txt @@ -8,7 +8,7 @@ tests/cases/compiler/operationsAvailableOnPromisedType.ts(17,5): error TS2367: T tests/cases/compiler/operationsAvailableOnPromisedType.ts(18,9): error TS2461: Type 'Promise' is not an array type. tests/cases/compiler/operationsAvailableOnPromisedType.ts(19,21): error TS2495: Type 'Promise' is not an array type or a string type. tests/cases/compiler/operationsAvailableOnPromisedType.ts(20,12): error TS2345: Argument of type 'Promise' is not assignable to parameter of type 'number'. -tests/cases/compiler/operationsAvailableOnPromisedType.ts(21,11): error TS2570: Property 'prop' does not exist on type 'Promise<{ prop: string; }>'. Did you forget to use 'await'? +tests/cases/compiler/operationsAvailableOnPromisedType.ts(21,11): error TS2339: Property 'prop' does not exist on type 'Promise<{ prop: string; }>'. tests/cases/compiler/operationsAvailableOnPromisedType.ts(23,27): error TS2495: Type 'Promise' is not an array type or a string type. tests/cases/compiler/operationsAvailableOnPromisedType.ts(24,5): error TS2349: This expression is not callable. Type 'Promise<() => void>' has no call signatures. @@ -72,7 +72,8 @@ tests/cases/compiler/operationsAvailableOnPromisedType.ts(27,5): error TS2349: T !!! related TS2773 tests/cases/compiler/operationsAvailableOnPromisedType.ts:20:12: Did you forget to use 'await'? d.prop; ~~~~ -!!! error TS2570: Property 'prop' does not exist on type 'Promise<{ prop: string; }>'. Did you forget to use 'await'? +!!! error TS2339: Property 'prop' does not exist on type 'Promise<{ prop: string; }>'. +!!! related TS2773 tests/cases/compiler/operationsAvailableOnPromisedType.ts:21:11: Did you forget to use 'await'? } for await (const s of c) {} ~ diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_argument.ts b/tests/cases/fourslash/codeFixAddMissingAwait_argument.ts new file mode 100644 index 00000000000..600e1338080 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_argument.ts @@ -0,0 +1,13 @@ +/// +////async function fn(a: Promise, b: string) { +//// fn(a, a); +////} + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 0, + newFileContent: +`async function fn(a: Promise, b: string) { + fn(a, await a); +}` +}); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_binaryExpressions.ts b/tests/cases/fourslash/codeFixAddMissingAwait_binaryExpressions.ts new file mode 100644 index 00000000000..eae2b0bdf36 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_binaryExpressions.ts @@ -0,0 +1,50 @@ +/// +////async function fn(a: Promise, b: number) { +//// a | b; +//// b + a; +//// a + a; +////} + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 0, + newFileContent: +`async function fn(a: Promise, b: number) { + await a | b; + b + a; + a + a; +}` +}); + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 1, + newFileContent: +`async function fn(a: Promise, b: number) { + a | b; + b + await a; + a + a; +}` +}); + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 2, + newFileContent: +`async function fn(a: Promise, b: number) { + a | b; + b + a; + await a + await a; +}` +}); + +verify.codeFixAll({ + fixAllDescription: ts.Diagnostics.Fix_all_expressions_possibly_missing_await.message, + fixId: "addMissingAwait", + newFileContent: +`async function fn(a: Promise, b: number) { + await a | b; + b + await a; + await a + await a; +}` +}); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_initializer.ts b/tests/cases/fourslash/codeFixAddMissingAwait_initializer.ts new file mode 100644 index 00000000000..7c86b140eda --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_initializer.ts @@ -0,0 +1,28 @@ +/// +////async function fn(a: string, b: Promise) { +//// const x = b; +//// fn(x, b); +//// fn(b, b); +////} + +verify.codeFix({ + description: "Add 'await' to initializer for 'x'", + index: 0, + newFileContent: +`async function fn(a: string, b: Promise) { + const x = await b; + fn(x, b); + fn(b, b); +}` +}); + +verify.codeFixAll({ + fixAllDescription: ts.Diagnostics.Fix_all_expressions_possibly_missing_await.message, + fixId: "addMissingAwait", + newFileContent: +`async function fn(a: string, b: Promise) { + const x = await b; + fn(x, b); + fn(await b, b); +}` +}); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_iterables.ts b/tests/cases/fourslash/codeFixAddMissingAwait_iterables.ts new file mode 100644 index 00000000000..80ca234e815 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_iterables.ts @@ -0,0 +1,50 @@ +/// +////async function fn(a: Promise) { +//// [...a]; +//// for (const c of a) { c; } +//// for await (const c of a) { c; } +////} + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 0, + newFileContent: +`async function fn(a: Promise) { + [...await a]; + for (const c of a) { c; } + for await (const c of a) { c; } +}` +}); + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 1, + newFileContent: +`async function fn(a: Promise) { + [...a]; + for (const c of await a) { c; } + for await (const c of a) { c; } +}` +}); + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 2, + newFileContent: +`async function fn(a: Promise) { + [...a]; + for (const c of a) { c; } + for await (const c of await a) { c; } +}` +}); + +verify.codeFixAll({ + fixAllDescription: ts.Diagnostics.Fix_all_expressions_possibly_missing_await.message, + fixId: "addMissingAwait", + newFileContent: +`async function fn(a: Promise) { + [...await a]; + for (const c of await a) { c; } + for await (const c of await a) { c; } +}` +}); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_notAvailableWithoutPromise.ts b/tests/cases/fourslash/codeFixAddMissingAwait_notAvailableWithoutPromise.ts new file mode 100644 index 00000000000..c2ae62fcab0 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_notAvailableWithoutPromise.ts @@ -0,0 +1,6 @@ +/// +////async function fn(a: {}, b: number) { +//// a + b; +////} + +verify.not.codeFixAvailable("addMissingAwait"); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_propertyAccess.ts b/tests/cases/fourslash/codeFixAddMissingAwait_propertyAccess.ts new file mode 100644 index 00000000000..fd1b7d65779 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_propertyAccess.ts @@ -0,0 +1,13 @@ +/// +////async function fn(a: Promise<{ x: string }>) { +//// a.x; +////} + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 0, + newFileContent: +`async function fn(a: Promise<{ x: string }>) { + (await a).x; +}` +}); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_signatures.ts b/tests/cases/fourslash/codeFixAddMissingAwait_signatures.ts new file mode 100644 index 00000000000..f4cfda84807 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_signatures.ts @@ -0,0 +1,50 @@ +/// +////async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { +//// a(); +//// b(); +//// new C(); +////} + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 0, + newFileContent: +`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { + (await a)(); + b(); + new C(); +}` +}); + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 1, + newFileContent: +`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { + a(); + (await b)(); + new C(); +}` +}); + +verify.codeFix({ + description: ts.Diagnostics.Add_await.message, + index: 2, + newFileContent: +`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { + a(); + b(); + new (await C)(); +}` +}); + +verify.codeFixAll({ + fixAllDescription: ts.Diagnostics.Fix_all_expressions_possibly_missing_await.message, + fixId: "addMissingAwait", + newFileContent: +`async function fn(a: Promise<() => void>, b: Promise<() => void> | (() => void), C: Promise<{ new(): any }>) { + (await a)(); + (await b)(); + new (await C)(); +}` +}); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_topLevel.ts b/tests/cases/fourslash/codeFixAddMissingAwait_topLevel.ts new file mode 100644 index 00000000000..9f524b90d7c --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingAwait_topLevel.ts @@ -0,0 +1,10 @@ +/// +////declare function getPromise(): Promise; +////const p = getPromise(); +////while (true) { +//// p/*0*/.toLowerCase(); +//// getPromise()/*1*/.toLowerCase(); +////} + +verify.not.codeFixAvailable("addMissingAwait"); +verify.not.codeFixAvailable("addMissingAwaitToInitializer"); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 05799a15642..d74523ea7fd 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -185,7 +185,7 @@ declare namespace FourSlashInterface { applyChanges?: boolean, commands?: {}[], }); - codeFixAvailable(options?: ReadonlyArray): void; + codeFixAvailable(options?: ReadonlyArray | string): void; applicableRefactorAvailableAtMarker(markerName: string): void; codeFixDiagnosticsAvailableAtMarkers(markerNames: string[], diagnosticCode?: number): void; applicableRefactorAvailableForRange(): void; From 60a1b1dc1a93ca792cf12bb0432cf7bc134c3ad1 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 12 Jul 2019 10:08:55 -0700 Subject: [PATCH 13/23] =?UTF-8?q?Proposal:=20If=20there=E2=80=99s=20a=20pa?= =?UTF-8?q?ckage.json,=20only=20auto-import=20things=20in=20it,=20more=20o?= =?UTF-8?q?r=20less=20(#31893)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move package.json related utils to utilities * Add failing test * Make first test pass * Don’t filter when there’s no package.json, fix scoped package imports * Use type acquisition as a heuristic for whether a JS project is using node core * Make same fix in getCompletionDetails * Fix re-exporting * Change JS node core module heuristic to same-file utilization * Remove unused method * Remove other unused method * Remove unused triple-slash ref * Update comment * Refactor findAlias to forEachAlias to reduce iterations * Really fix re-exporting * Use getModuleSpecifier instead of custom hack * Fix offering auto imports to paths within node modules * Rename things and make comments better * Add another reexport test * Inline `symbolHasBeenSeen` * Simplify forEachAlias to findAlias * Add note that symbols is mutated * Symbol order doesn’t matter here * Style nits * Add test with nested package.jsons * Fix and add tests for export * re-exports --- src/compiler/utilities.ts | 2 +- src/harness/fourslash.ts | 2 +- src/services/codefixes/importFixes.ts | 124 ++++++++++++++- src/services/completions.ts | 150 ++++++++++++++---- src/services/services.ts | 2 +- src/services/stringCompletions.ts | 49 ------ src/services/utilities.ts | 49 ++++++ ...rt_filteredByPackageJson_@typesImplicit.ts | 44 +++++ ...Import_filteredByPackageJson_@typesOnly.ts | 44 +++++ ...onsImport_filteredByPackageJson_ambient.ts | 30 ++++ ...ionsImport_filteredByPackageJson_direct.ts | 46 ++++++ ...ionsImport_filteredByPackageJson_nested.ts | 66 ++++++++ ...nsImport_filteredByPackageJson_reexport.ts | 58 +++++++ ...sImport_filteredByPackageJson_reexport2.ts | 58 +++++++ ...sImport_filteredByPackageJson_reexport3.ts | 48 ++++++ ...sImport_filteredByPackageJson_reexport4.ts | 57 +++++++ .../fourslash/completionsImport_ofAlias.ts | 17 +- .../importNameCodeFixNewImportNodeModules8.ts | 2 +- 18 files changed, 751 insertions(+), 97 deletions(-) create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesImplicit.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesOnly.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_ambient.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_direct.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_nested.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport2.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport3.ts create mode 100644 tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport4.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3203e10f370..0d3bad879de 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7468,7 +7468,7 @@ namespace ts { export function getDirectoryPath(path: Path): Path; /** * Returns the path except for its basename. Semantics align with NodeJS's `path.dirname` - * except that we support URL's as well. + * except that we support URLs as well. * * ```ts * getDirectoryPath("/path/to/file.ext") === "/path/to" diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 5d5338db1f4..56cc2b65508 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -798,7 +798,7 @@ namespace FourSlash { const name = typeof include === "string" ? include : include.name; const found = nameToEntries.get(name); if (!found) throw this.raiseError(`No completion ${name} found`); - assert(found.length === 1); // Must use 'exact' for multiple completions with same name + assert(found.length === 1, `Must use 'exact' for multiple completions with same name: '${name}'`); this.verifyCompletionEntry(ts.first(found), include); } } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 8006d1a0cfd..2fcc8cf5ccb 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -283,13 +283,25 @@ namespace ts.codefix { preferences: UserPreferences, ): ReadonlyArray { const isJs = isSourceFileJS(sourceFile); + const { allowsImporting } = createLazyPackageJsonDependencyReader(sourceFile, host); const choicesForEachExportingModule = flatMap(moduleSymbols, ({ moduleSymbol, importKind, exportedSymbolIsTypeOnly }) => moduleSpecifiers.getModuleSpecifiers(moduleSymbol, program.getCompilerOptions(), sourceFile, host, program.getSourceFiles(), preferences, program.redirectTargetsMap) .map((moduleSpecifier): FixAddNewImport | FixUseImportType => // `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types. exportedSymbolIsTypeOnly && isJs ? { kind: ImportFixKind.ImportType, moduleSpecifier, position: Debug.assertDefined(position) } : { kind: ImportFixKind.AddNew, moduleSpecifier, importKind })); - // Sort to keep the shortest paths first - return sort(choicesForEachExportingModule, (a, b) => a.moduleSpecifier.length - b.moduleSpecifier.length); + + // Sort by presence in package.json, then shortest paths first + return sort(choicesForEachExportingModule, (a, b) => { + const allowsImportingA = allowsImporting(a.moduleSpecifier); + const allowsImportingB = allowsImporting(b.moduleSpecifier); + if (allowsImportingA && !allowsImportingB) { + return -1; + } + if (allowsImportingB && !allowsImportingA) { + return 1; + } + return a.moduleSpecifier.length - b.moduleSpecifier.length; + }); } function getFixesForAddImport( @@ -380,7 +392,8 @@ namespace ts.codefix { // "default" is a keyword and not a legal identifier for the import, so we don't expect it here Debug.assert(symbolName !== InternalSymbolName.Default); - const fixes = arrayFrom(flatMapIterator(getExportInfos(symbolName, getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, checker, program).entries(), ([_, exportInfos]) => + const exportInfos = getExportInfos(symbolName, getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, checker, program, preferences, host); + const fixes = arrayFrom(flatMapIterator(exportInfos.entries(), ([_, exportInfos]) => getFixForImport(exportInfos, symbolName, symbolToken.getStart(sourceFile), program, sourceFile, host, preferences))); return { fixes, symbolName }; } @@ -393,6 +406,8 @@ namespace ts.codefix { sourceFile: SourceFile, checker: TypeChecker, program: Program, + preferences: UserPreferences, + host: LanguageServiceHost ): ReadonlyMap> { // For each original symbol, keep all re-exports of that symbol together so we can call `getCodeActionsForImport` on the whole group at once. // Maps symbol id to info for modules providing that symbol (original export + re-exports). @@ -400,7 +415,7 @@ namespace ts.codefix { function addSymbol(moduleSymbol: Symbol, exportedSymbol: Symbol, importKind: ImportKind): void { originalSymbolToExportInfos.add(getUniqueSymbolId(exportedSymbol, checker).toString(), { moduleSymbol, importKind, exportedSymbolIsTypeOnly: isTypeOnlySymbol(exportedSymbol, checker) }); } - forEachExternalModuleToImportFrom(checker, sourceFile, program.getSourceFiles(), moduleSymbol => { + forEachExternalModuleToImportFrom(checker, host, preferences, program.redirectTargetsMap, sourceFile, program.getSourceFiles(), moduleSymbol => { cancellationToken.throwIfCancellationRequested(); const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, program.getCompilerOptions()); @@ -561,12 +576,44 @@ namespace ts.codefix { return some(declarations, decl => !!(getMeaningFromDeclaration(decl) & meaning)); } - export function forEachExternalModuleToImportFrom(checker: TypeChecker, from: SourceFile, allSourceFiles: ReadonlyArray, cb: (module: Symbol) => void) { + export function forEachExternalModuleToImportFrom(checker: TypeChecker, host: LanguageServiceHost, preferences: UserPreferences, redirectTargetsMap: RedirectTargetsMap, from: SourceFile, allSourceFiles: ReadonlyArray, cb: (module: Symbol) => void) { + const { allowsImporting } = createLazyPackageJsonDependencyReader(from, host); + const compilerOptions = host.getCompilationSettings(); + const getCanonicalFileName = hostGetCanonicalFileName(host); forEachExternalModule(checker, allSourceFiles, (module, sourceFile) => { - if (sourceFile === undefined || sourceFile !== from && isImportablePath(from.fileName, sourceFile.fileName)) { + if (sourceFile === undefined && allowsImporting(stripQuotes(module.getName()))) { cb(module); } + else if (sourceFile && sourceFile !== from && isImportablePath(from.fileName, sourceFile.fileName)) { + const moduleSpecifier = getNodeModulesPackageNameFromFileName(sourceFile.fileName); + if (!moduleSpecifier || allowsImporting(moduleSpecifier)) { + cb(module); + } + } }); + + function getNodeModulesPackageNameFromFileName(importedFileName: string): string | undefined { + const specifier = moduleSpecifiers.getModuleSpecifier( + compilerOptions, + from, + toPath(from.fileName, /*basePath*/ undefined, getCanonicalFileName), + importedFileName, + host, + allSourceFiles, + preferences, + redirectTargetsMap); + + // Paths here are not node_modules, so we don’t care about them; + // returning anything will trigger a lookup in package.json. + if (!pathIsRelative(specifier) && !isRootedDiskPath(specifier)) { + const components = getPathComponents(getPackageNameFromTypesPackageName(specifier)).slice(1); + // Scoped packages + if (startsWith(components[0], "@")) { + return `${components[0]}/${components[1]}`; + } + return components[0]; + } + } } function forEachExternalModule(checker: TypeChecker, allSourceFiles: ReadonlyArray, cb: (module: Symbol, sourceFile: SourceFile | undefined) => void) { @@ -620,4 +667,69 @@ namespace ts.codefix { // Need `|| "_"` to ensure result isn't empty. return !isStringANonContextualKeyword(res) ? res || "_" : `_${res}`; } + + function createLazyPackageJsonDependencyReader(fromFile: SourceFile, host: LanguageServiceHost) { + const packageJsonPaths = findPackageJsons(getDirectoryPath(fromFile.fileName), host); + const dependencyIterator = readPackageJsonDependencies(host, packageJsonPaths); + let seenDeps: Map | undefined; + let usesNodeCoreModules: boolean | undefined; + return { allowsImporting }; + + function containsDependency(dependency: string) { + if ((seenDeps || (seenDeps = createMap())).has(dependency)) { + return true; + } + let packageName: string | void; + while (packageName = dependencyIterator.next().value) { + seenDeps.set(packageName, true); + if (packageName === dependency) { + return true; + } + } + return false; + } + + function allowsImporting(moduleSpecifier: string): boolean { + if (!packageJsonPaths.length) { + return true; + } + + // If we’re in JavaScript, it can be difficult to tell whether the user wants to import + // from Node core modules or not. We can start by seeing if the user is actually using + // any node core modules, as opposed to simply having @types/node accidentally as a + // dependency of a dependency. + if (isSourceFileJS(fromFile) && JsTyping.nodeCoreModules.has(moduleSpecifier)) { + if (usesNodeCoreModules === undefined) { + usesNodeCoreModules = consumesNodeCoreModules(fromFile); + } + if (usesNodeCoreModules) { + return true; + } + } + + return containsDependency(moduleSpecifier) + || containsDependency(getTypesPackageName(moduleSpecifier)); + } + } + + function *readPackageJsonDependencies(host: LanguageServiceHost, packageJsonPaths: string[]) { + type PackageJson = Record | undefined>; + const dependencyKeys = ["dependencies", "devDependencies", "optionalDependencies"] as const; + for (const fileName of packageJsonPaths) { + const content = readJson(fileName, { readFile: host.readFile ? host.readFile.bind(host) : sys.readFile }) as PackageJson; + for (const key of dependencyKeys) { + const dependencies = content[key]; + if (!dependencies) { + continue; + } + for (const packageName in dependencies) { + yield packageName; + } + } + } + } + + function consumesNodeCoreModules(sourceFile: SourceFile): boolean { + return some(sourceFile.imports, ({ text }) => JsTyping.nodeCoreModules.has(text)); + } } diff --git a/src/services/completions.ts b/src/services/completions.ts index 6d1d48b22b8..cf707c642ed 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -63,7 +63,7 @@ namespace ts.Completions { return getLabelCompletionAtPosition(contextToken.parent); } - const completionData = getCompletionData(program, log, sourceFile, isUncheckedFile(sourceFile, compilerOptions), position, preferences, /*detailsEntryId*/ undefined); + const completionData = getCompletionData(program, log, sourceFile, isUncheckedFile(sourceFile, compilerOptions), position, preferences, /*detailsEntryId*/ undefined, host); if (!completionData) { return undefined; } @@ -406,10 +406,10 @@ namespace ts.Completions { previousToken: Node | undefined; readonly isJsxInitializer: IsJsxInitializer; } - function getSymbolCompletionFromEntryId(program: Program, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier, + function getSymbolCompletionFromEntryId(program: Program, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier, host: LanguageServiceHost ): SymbolCompletion | { type: "request", request: Request } | { type: "literal", literal: string | number | PseudoBigInt } | { type: "none" } { const compilerOptions = program.getCompilerOptions(); - const completionData = getCompletionData(program, log, sourceFile, isUncheckedFile(sourceFile, compilerOptions), position, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true }, entryId); + const completionData = getCompletionData(program, log, sourceFile, isUncheckedFile(sourceFile, compilerOptions), position, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true }, entryId, host); if (!completionData) { return { type: "none" }; } @@ -471,7 +471,7 @@ namespace ts.Completions { } // Compute all the completion symbols again. - const symbolCompletion = getSymbolCompletionFromEntryId(program, log, sourceFile, position, entryId); + const symbolCompletion = getSymbolCompletionFromEntryId(program, log, sourceFile, position, entryId, host); switch (symbolCompletion.type) { case "request": { const { request } = symbolCompletion; @@ -556,8 +556,8 @@ namespace ts.Completions { return { sourceDisplay: [textPart(moduleSpecifier)], codeActions: [codeAction] }; } - export function getCompletionEntrySymbol(program: Program, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier): Symbol | undefined { - const completion = getSymbolCompletionFromEntryId(program, log, sourceFile, position, entryId); + export function getCompletionEntrySymbol(program: Program, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier, host: LanguageServiceHost): Symbol | undefined { + const completion = getSymbolCompletionFromEntryId(program, log, sourceFile, position, entryId, host); return completion.type === "symbol" ? completion.symbol : undefined; } @@ -656,6 +656,7 @@ namespace ts.Completions { position: number, preferences: Pick, detailsEntryId: CompletionEntryIdentifier | undefined, + host: LanguageServiceHost ): CompletionData | Request | undefined { const typeChecker = program.getTypeChecker(); @@ -1148,7 +1149,7 @@ namespace ts.Completions { } if (shouldOfferImportCompletions()) { - getSymbolsFromOtherSourceFileExports(symbols, previousToken && isIdentifier(previousToken) ? previousToken.text : "", program.getCompilerOptions().target!); + getSymbolsFromOtherSourceFileExports(symbols, previousToken && isIdentifier(previousToken) ? previousToken.text : "", program.getCompilerOptions().target!, host); } filterGlobalCompletion(symbols); } @@ -1254,12 +1255,64 @@ namespace ts.Completions { typeChecker.getExportsOfModule(sym).some(e => symbolCanBeReferencedAtTypeLocation(e, seenModules)); } - function getSymbolsFromOtherSourceFileExports(symbols: Symbol[], tokenText: string, target: ScriptTarget): void { + /** + * Gathers symbols that can be imported from other files, deduplicating along the way. Symbols can be “duplicates” + * if re-exported from another module, e.g. `export { foo } from "./a"`. That syntax creates a fresh symbol, but + * it’s just an alias to the first, and both have the same name, so we generally want to filter those aliases out, + * if and only if the the first can be imported (it may be excluded due to package.json filtering in + * `codefix.forEachExternalModuleToImportFrom`). + * + * Example. Imagine a chain of node_modules re-exporting one original symbol: + * + * ```js + * node_modules/x/index.js node_modules/y/index.js node_modules/z/index.js + * +-----------------------+ +--------------------------+ +--------------------------+ + * | | | | | | + * | export const foo = 0; | <--- | export { foo } from 'x'; | <--- | export { foo } from 'y'; | + * | | | | | | + * +-----------------------+ +--------------------------+ +--------------------------+ + * ``` + * + * Also imagine three buckets, which we’ll reference soon: + * + * ```md + * | | | | | | + * | **Bucket A** | | **Bucket B** | | **Bucket C** | + * | Symbols to | | Aliases to symbols | | Symbols to return | + * | definitely | | in Buckets A or C | | if nothing better | + * | return | | (don’t return these) | | comes along | + * |__________________| |______________________| |___________________| + * ``` + * + * We _probably_ want to show `foo` from 'x', but not from 'y' or 'z'. However, if 'x' is not in a package.json, it + * will not appear in a `forEachExternalModuleToImportFrom` iteration. Furthermore, the order of iterations is not + * guaranteed, as it is host-dependent. Therefore, when presented with the symbol `foo` from module 'y' alone, we + * may not be sure whether or not it should go in the list. So, we’ll take the following steps: + * + * 1. Resolve alias `foo` from 'y' to the export declaration in 'x', get the symbol there, and see if that symbol is + * already in Bucket A (symbols we already know will be returned). If it is, put `foo` from 'y' in Bucket B + * (symbols that are aliases to symbols in Bucket A). If it’s not, put it in Bucket C. + * 2. Next, imagine we see `foo` from module 'z'. Again, we resolve the alias to the nearest export, which is in 'y'. + * At this point, if that nearest export from 'y' is in _any_ of the three buckets, we know the symbol in 'z' + * should never be returned in the final list, so put it in Bucket B. + * 3. Next, imagine we see `foo` from module 'x', the original. Syntactically, it doesn’t look like a re-export, so + * we can just check Bucket C to see if we put any aliases to the original in there. If they exist, throw them out. + * Put this symbol in Bucket A. + * 4. After we’ve iterated through every symbol of every module, any symbol left in Bucket C means that step 3 didn’t + * occur for that symbol---that is, the original symbol is not in Bucket A, so we should include the alias. Move + * everything from Bucket C to Bucket A. + * + * Note: Bucket A is passed in as the parameter `symbols` and mutated. + */ + function getSymbolsFromOtherSourceFileExports(/** Bucket A */ symbols: Symbol[], tokenText: string, target: ScriptTarget, host: LanguageServiceHost): void { const tokenTextLowerCase = tokenText.toLowerCase(); - const seenResolvedModules = createMap(); + /** Bucket B */ + const aliasesToAlreadyIncludedSymbols = createMap(); + /** Bucket C */ + const aliasesToReturnIfOriginalsAreMissing = createMap<{ alias: Symbol, moduleSymbol: Symbol }>(); - codefix.forEachExternalModuleToImportFrom(typeChecker, sourceFile, program.getSourceFiles(), moduleSymbol => { + codefix.forEachExternalModuleToImportFrom(typeChecker, host, preferences, program.redirectTargetsMap, sourceFile, program.getSourceFiles(), moduleSymbol => { // Perf -- ignore other modules if this is a request for details if (detailsEntryId && detailsEntryId.source && stripQuotes(moduleSymbol.name) !== detailsEntryId.source) { return; @@ -1280,33 +1333,59 @@ namespace ts.Completions { symbolToOriginInfoMap[getSymbolId(resolvedModuleSymbol)] = { kind: SymbolOriginInfoKind.Export, moduleSymbol, isDefaultExport: false }; } - for (let symbol of typeChecker.getExportsOfModule(moduleSymbol)) { - // Don't add a completion for a re-export, only for the original. - // The actual import fix might end up coming from a re-export -- we don't compute that until getting completion details. - // This is just to avoid adding duplicate completion entries. - // - // If `symbol.parent !== ...`, this is an `export * from "foo"` re-export. Those don't create new symbols. - if (typeChecker.getMergedSymbol(symbol.parent!) !== resolvedModuleSymbol - || some(symbol.declarations, d => - // If `!!d.name.originalKeywordKind`, this is `export { _break as break };` -- skip this and prefer the keyword completion. - // If `!!d.parent.parent.moduleSpecifier`, this is `export { foo } from "foo"` re-export, which creates a new symbol (thus isn't caught by the first check). - isExportSpecifier(d) && (d.propertyName ? isIdentifierANonContextualKeyword(d.name) : !!d.parent.parent.moduleSpecifier))) { + for (const symbol of typeChecker.getExportsOfModule(moduleSymbol)) { + // If this is `export { _break as break };` (a keyword) -- skip this and prefer the keyword completion. + if (some(symbol.declarations, d => isExportSpecifier(d) && !!d.propertyName && isIdentifierANonContextualKeyword(d.name))) { continue; } - - const isDefaultExport = symbol.escapedName === InternalSymbolName.Default; - if (isDefaultExport) { - symbol = getLocalSymbolForExportDefault(symbol) || symbol; + // If `symbol.parent !== moduleSymbol`, this is an `export * from "foo"` re-export. Those don't create new symbols. + const isExportStarFromReExport = typeChecker.getMergedSymbol(symbol.parent!) !== resolvedModuleSymbol; + // If `!!d.parent.parent.moduleSpecifier`, this is `export { foo } from "foo"` re-export, which creates a new symbol (thus isn't caught by the first check). + if (isExportStarFromReExport || some(symbol.declarations, d => isExportSpecifier(d) && !d.propertyName && !!d.parent.parent.moduleSpecifier)) { + // Walk the export chain back one module (step 1 or 2 in diagrammed example). + // Or, in the case of `export * from "foo"`, `symbol` already points to the original export, so just use that. + const nearestExportSymbolId = getSymbolId(isExportStarFromReExport ? symbol : Debug.assertDefined(getNearestExportSymbol(symbol))); + const symbolHasBeenSeen = !!symbolToOriginInfoMap[nearestExportSymbolId] || aliasesToAlreadyIncludedSymbols.has(nearestExportSymbolId.toString()); + if (!symbolHasBeenSeen) { + aliasesToReturnIfOriginalsAreMissing.set(nearestExportSymbolId.toString(), { alias: symbol, moduleSymbol }); + aliasesToAlreadyIncludedSymbols.set(getSymbolId(symbol).toString(), true); + } + else { + // Perf - we know this symbol is an alias to one that’s already covered in `symbols`, so store it here + // in case another symbol re-exports this one; that way we can short-circuit as soon as we see this symbol id. + addToSeen(aliasesToAlreadyIncludedSymbols, getSymbolId(symbol)); + } } - - const origin: SymbolOriginInfoExport = { kind: SymbolOriginInfoKind.Export, moduleSymbol, isDefaultExport }; - if (detailsEntryId || stringContainsCharactersInOrder(getSymbolName(symbol, origin, target).toLowerCase(), tokenTextLowerCase)) { - symbols.push(symbol); - symbolToSortTextMap[getSymbolId(symbol)] = SortText.AutoImportSuggestions; - symbolToOriginInfoMap[getSymbolId(symbol)] = origin; + else { + // This is not a re-export, so see if we have any aliases pending and remove them (step 3 in diagrammed example) + aliasesToReturnIfOriginalsAreMissing.delete(getSymbolId(symbol).toString()); + pushSymbol(symbol, moduleSymbol); } } }); + + // By this point, any potential duplicates that were actually duplicates have been + // removed, so the rest need to be added. (Step 4 in diagrammed example) + aliasesToReturnIfOriginalsAreMissing.forEach(({ alias, moduleSymbol }) => pushSymbol(alias, moduleSymbol)); + + function pushSymbol(symbol: Symbol, moduleSymbol: Symbol) { + const isDefaultExport = symbol.escapedName === InternalSymbolName.Default; + if (isDefaultExport) { + symbol = getLocalSymbolForExportDefault(symbol) || symbol; + } + const origin: SymbolOriginInfoExport = { kind: SymbolOriginInfoKind.Export, moduleSymbol, isDefaultExport }; + if (detailsEntryId || stringContainsCharactersInOrder(getSymbolName(symbol, origin, target).toLowerCase(), tokenTextLowerCase)) { + symbols.push(symbol); + symbolToSortTextMap[getSymbolId(symbol)] = SortText.AutoImportSuggestions; + symbolToOriginInfoMap[getSymbolId(symbol)] = origin; + } + } + } + + function getNearestExportSymbol(fromSymbol: Symbol) { + return findAlias(typeChecker, fromSymbol, alias => { + return some(alias.declarations, d => isExportSpecifier(d) || !!d.localSymbol); + }); } /** @@ -2216,4 +2295,13 @@ namespace ts.Completions { function binaryExpressionMayBeOpenTag({ left }: BinaryExpression): boolean { return nodeIsMissing(left); } + + function findAlias(typeChecker: TypeChecker, symbol: Symbol, predicate: (symbol: Symbol) => boolean): Symbol | undefined { + let currentAlias: Symbol | undefined = symbol; + while (currentAlias.flags & SymbolFlags.Alias && (currentAlias = typeChecker.getImmediateAliasedSymbol(currentAlias))) { + if (predicate(currentAlias)) { + return currentAlias; + } + } + } } diff --git a/src/services/services.ts b/src/services/services.ts index fab6f88b779..2f000bc0f2e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1453,7 +1453,7 @@ namespace ts { function getCompletionEntrySymbol(fileName: string, position: number, name: string, source?: string): Symbol | undefined { synchronizeHostData(); - return Completions.getCompletionEntrySymbol(program, log, getValidSourceFile(fileName), position, { name, source }); + return Completions.getCompletionEntrySymbol(program, log, getValidSourceFile(fileName), position, { name, source }, host); } function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined { diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index b287ebdb406..58195b5cb3c 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -627,30 +627,6 @@ namespace ts.Completions.StringCompletions { } } - function findPackageJsons(directory: string, host: LanguageServiceHost): string[] { - const paths: string[] = []; - forEachAncestorDirectory(directory, ancestor => { - const currentConfigPath = findConfigFile(ancestor, (f) => tryFileExists(host, f), "package.json"); - if (!currentConfigPath) { - return true; // break out - } - paths.push(currentConfigPath); - }); - return paths; - } - - function findPackageJson(directory: string, host: LanguageServiceHost): string | undefined { - let packageJson: string | undefined; - forEachAncestorDirectory(directory, ancestor => { - if (ancestor === "node_modules") return true; - packageJson = findConfigFile(ancestor, (f) => tryFileExists(host, f), "package.json"); - if (packageJson) { - return true; // break out - } - }); - return packageJson; - } - function enumerateNodeModulesVisibleToScript(host: LanguageServiceHost, scriptPath: string): ReadonlyArray { if (!host.readFile || !host.fileExists) return emptyArray; @@ -706,31 +682,6 @@ namespace ts.Completions.StringCompletions { const nodeModulesDependencyKeys: ReadonlyArray = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]; - function tryGetDirectories(host: LanguageServiceHost, directoryName: string): string[] { - return tryIOAndConsumeErrors(host, host.getDirectories, directoryName) || []; - } - - function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray): ReadonlyArray { - return tryIOAndConsumeErrors(host, host.readDirectory, path, extensions, exclude, include) || emptyArray; - } - - function tryFileExists(host: LanguageServiceHost, path: string): boolean { - return tryIOAndConsumeErrors(host, host.fileExists, path); - } - - function tryDirectoryExists(host: LanguageServiceHost, path: string): boolean { - return tryAndIgnoreErrors(() => directoryProbablyExists(path, host)) || false; - } - - function tryIOAndConsumeErrors(host: LanguageServiceHost, toApply: ((...a: any[]) => T) | undefined, ...args: any[]) { - return tryAndIgnoreErrors(() => toApply && toApply.apply(host, args)); - } - - function tryAndIgnoreErrors(cb: () => T): T | undefined { - try { return cb(); } - catch { return undefined; } - } - function containsSlash(fragment: string) { return stringContains(fragment, directorySeparator); } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 44125fea6d0..cbadfbc9b53 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2038,4 +2038,53 @@ namespace ts { // If even 2/5 places have a semicolon, the user probably wants semicolons return withSemicolon / withoutSemicolon > 1 / nStatementsToObserve; } + + export function tryGetDirectories(host: LanguageServiceHost, directoryName: string): string[] { + return tryIOAndConsumeErrors(host, host.getDirectories, directoryName) || []; + } + + export function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray): ReadonlyArray { + return tryIOAndConsumeErrors(host, host.readDirectory, path, extensions, exclude, include) || emptyArray; + } + + export function tryFileExists(host: LanguageServiceHost, path: string): boolean { + return tryIOAndConsumeErrors(host, host.fileExists, path); + } + + export function tryDirectoryExists(host: LanguageServiceHost, path: string): boolean { + return tryAndIgnoreErrors(() => directoryProbablyExists(path, host)) || false; + } + + export function tryAndIgnoreErrors(cb: () => T): T | undefined { + try { return cb(); } + catch { return undefined; } + } + + export function tryIOAndConsumeErrors(host: LanguageServiceHost, toApply: ((...a: any[]) => T) | undefined, ...args: any[]) { + return tryAndIgnoreErrors(() => toApply && toApply.apply(host, args)); + } + + export function findPackageJsons(directory: string, host: LanguageServiceHost): string[] { + const paths: string[] = []; + forEachAncestorDirectory(directory, ancestor => { + const currentConfigPath = findConfigFile(ancestor, (f) => tryFileExists(host, f), "package.json"); + if (!currentConfigPath) { + return true; // break out + } + paths.push(currentConfigPath); + }); + return paths; + } + + export function findPackageJson(directory: string, host: LanguageServiceHost): string | undefined { + let packageJson: string | undefined; + forEachAncestorDirectory(directory, ancestor => { + if (ancestor === "node_modules") return true; + packageJson = findConfigFile(ancestor, (f) => tryFileExists(host, f), "package.json"); + if (packageJson) { + return true; // break out + } + }); + return packageJson; + } } diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesImplicit.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesImplicit.ts new file mode 100644 index 00000000000..539a9cc8ff6 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesImplicit.ts @@ -0,0 +1,44 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// "react": "*" +//// } +////} + +//@Filename: /node_modules/@types/react/index.d.ts +////export declare var React: any; + +//@Filename: /node_modules/@types/react/package.json +////{ +//// "name": "@types/react" +////} + +//@Filename: /node_modules/@types/fake-react/index.d.ts +////export declare var ReactFake: any; + +//@Filename: /node_modules/@types/fake-react/package.json +////{ +//// "name": "@types/fake-react" +////} + +//@Filename: /src/index.ts +////const x = Re/**/ + +verify.completions({ + marker: test.marker(""), + isNewIdentifierLocation: true, + includes: { + name: "React", + hasAction: true, + source: "/node_modules/@types/react/index", + sortText: completion.SortText.AutoImportSuggestions + }, + excludes: "ReactFake", + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesOnly.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesOnly.ts new file mode 100644 index 00000000000..b0d2c01e3db --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_@typesOnly.ts @@ -0,0 +1,44 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "devDependencies": { +//// "@types/react": "*" +//// } +////} + +//@Filename: /node_modules/@types/react/index.d.ts +////export declare var React: any; + +//@Filename: /node_modules/@types/react/package.json +////{ +//// "name": "@types/react" +////} + +//@Filename: /node_modules/@types/fake-react/index.d.ts +////export declare var ReactFake: any; + +//@Filename: /node_modules/@types/fake-react/package.json +////{ +//// "name": "@types/fake-react" +////} + +//@Filename: /src/index.ts +////const x = Re/**/ + +verify.completions({ + marker: test.marker(""), + isNewIdentifierLocation: true, + includes: { + name: "React", + hasAction: true, + source: "/node_modules/@types/react/index", + sortText: completion.SortText.AutoImportSuggestions + }, + excludes: "ReactFake", + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_ambient.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_ambient.ts new file mode 100644 index 00000000000..3dcb9eb6690 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_ambient.ts @@ -0,0 +1,30 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// } +////} + +//@Filename: /node_modules/@types/node/timers.d.ts +////declare module "timers" { +//// function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timeout; +////} + +//@Filename: /node_modules/@types/node/package.json +////{ +//// "name": "@types/node", +////} + +//@Filename: /src/index.ts +////setTimeo/**/ + +verify.completions({ + marker: test.marker(""), + exact: completion.globals, + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_direct.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_direct.ts new file mode 100644 index 00000000000..aa7845daed3 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_direct.ts @@ -0,0 +1,46 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// "react": "*" +//// } +////} + +//@Filename: /node_modules/react/index.d.ts +////export declare var React: any; + +//@Filename: /node_modules/react/package.json +////{ +//// "name": "react", +//// "types": "./index.d.ts" +////} + +//@Filename: /node_modules/fake-react/index.d.ts +////export declare var ReactFake: any; + +//@Filename: /node_modules/fake-react/package.json +////{ +//// "name": "fake-react", +//// "types": "./index.d.ts" +////} + +//@Filename: /src/index.ts +////const x = Re/**/ + +verify.completions({ + marker: test.marker(""), + isNewIdentifierLocation: true, + includes: { + name: "React", + hasAction: true, + source: "/node_modules/react/index", + sortText: completion.SortText.AutoImportSuggestions + }, + excludes: "ReactFake", + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_nested.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_nested.ts new file mode 100644 index 00000000000..e940c43e32c --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_nested.ts @@ -0,0 +1,66 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// "react": "*" +//// } +////} + +//@Filename: /node_modules/react/index.d.ts +////export declare var React: any; + +//@Filename: /node_modules/react/package.json +////{ +//// "name": "react", +//// "types": "./index.d.ts" +////} + +//@Filename: /dir/package.json +////{ +//// "dependencies": { +//// "redux": "*" +//// } +////} + +//@Filename: /dir/node_modules/redux/package.json +////{ +//// "name": "redux", +//// "types": "./index.d.ts" +////} + +//@Filename: /dir/node_modules/redux/index.d.ts +////export declare var Redux: any; + +//@Filename: /dir/index.ts +////const x = Re/**/ + +verify.completions({ + marker: test.marker(""), + isNewIdentifierLocation: true, + includes: { + name: "React", + hasAction: true, + source: "/node_modules/react/index", + sortText: completion.SortText.AutoImportSuggestions + }, + preferences: { + includeCompletionsForModuleExports: true + } +}); + +verify.completions({ + marker: test.marker(""), + isNewIdentifierLocation: true, + includes: { + name: "Redux", + hasAction: true, + source: "/dir/node_modules/redux/index", + sortText: completion.SortText.AutoImportSuggestions + }, + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport.ts new file mode 100644 index 00000000000..8e17a3c3a44 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport.ts @@ -0,0 +1,58 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// "@emotion/core": "*" +//// } +////} + +//@Filename: /node_modules/@emotion/css/index.d.ts +////export declare const css: any; +////const css2: any; +////export { css2 }; + +//@Filename: /node_modules/@emotion/css/package.json +////{ +//// "name": "@emotion/css", +//// "types": "./index.d.ts" +////} + +//@Filename: /node_modules/@emotion/core/index.d.ts +////import { css2 } from "@emotion/css"; +////export { css } from "@emotion/css"; +////export { css2 }; + +//@Filename: /node_modules/@emotion/core/package.json +////{ +//// "name": "@emotion/core", +//// "types": "./index.d.ts" +////} + +//@Filename: /src/index.ts +////cs/**/ + +verify.completions({ + marker: test.marker(""), + includes: [ + completion.undefinedVarEntry, + { + name: "css", + source: "/node_modules/@emotion/core/index", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, + { + name: "css2", + source: "/node_modules/@emotion/core/index", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, + ...completion.statementKeywordsWithTypes + ], + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport2.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport2.ts new file mode 100644 index 00000000000..eb946ce17b4 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport2.ts @@ -0,0 +1,58 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// "b_": "*", +//// "_c": "*" +//// } +////} + +//@Filename: /node_modules/a/index.d.ts +////export const foo = 0; + +//@Filename: /node_modules/a/package.json +////{ +//// "name": "a", +//// "types": "./index.d.ts" +////} + +//@Filename: /node_modules/b_/index.d.ts +////export { foo } from "a"; + +//@Filename: /node_modules/b_/package.json +////{ +//// "name": "b_", +//// "types": "./index.d.ts" +////} + +//@Filename: /node_modules/_c/index.d.ts +////export { foo } from "b_"; + +//@Filename: /node_modules/_c/package.json +////{ +//// "name": "_c", +//// "types": "./index.d.ts" +////} + +//@Filename: /src/index.ts +////fo/**/ + +verify.completions({ + marker: test.marker(""), + includes: [ + completion.undefinedVarEntry, + { + name: "foo", + source: "/node_modules/b_/index", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, + ...completion.statementKeywordsWithTypes + ], + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport3.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport3.ts new file mode 100644 index 00000000000..8533461e0b8 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport3.ts @@ -0,0 +1,48 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// "b": "*", +//// } +////} + +//@Filename: /node_modules/a/index.d.ts +////export const foo = 0; + +//@Filename: /node_modules/a/package.json +////{ +//// "name": "a", +//// "types": "./index.d.ts" +////} + +//@Filename: /node_modules/b/index.d.ts +////export * from "a"; + +//@Filename: /node_modules/b/package.json +////{ +//// "name": "b", +//// "types": "./index.d.ts" +////} + +//@Filename: /src/index.ts +////fo/**/ + +verify.completions({ + marker: test.marker(""), + includes: [ + completion.undefinedVarEntry, + { + name: "foo", + source: "/node_modules/b/index", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, + ...completion.statementKeywordsWithTypes + ], + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport4.ts b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport4.ts new file mode 100644 index 00000000000..83ac6526b25 --- /dev/null +++ b/tests/cases/fourslash/completionsImport_filteredByPackageJson_reexport4.ts @@ -0,0 +1,57 @@ +/// + +//@noEmit: true + +//@Filename: /package.json +////{ +//// "dependencies": { +//// "c": "*", +//// } +////} + +//@Filename: /node_modules/a/index.d.ts +////export const foo = 0; + +//@Filename: /node_modules/a/package.json +////{ +//// "name": "a", +//// "types": "./index.d.ts" +////} + +//@Filename: /node_modules/b/index.d.ts +////export * from "a"; + +//@Filename: /node_modules/b/package.json +////{ +//// "name": "b", +//// "types": "./index.d.ts" +////} + +//@Filename: /node_modules/c/index.d.ts +////export * from "a"; + +//@Filename: /node_modules/c/package.json +////{ +//// "name": "c", +//// "types": "./index.d.ts" +////} + +//@Filename: /src/index.ts +////fo/**/ + +verify.completions({ + marker: test.marker(""), + includes: [ + completion.undefinedVarEntry, + { + name: "foo", + source: "/node_modules/c/index", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, + ...completion.statementKeywordsWithTypes + ], + preferences: { + includeCompletionsForModuleExports: true + } +}); diff --git a/tests/cases/fourslash/completionsImport_ofAlias.ts b/tests/cases/fourslash/completionsImport_ofAlias.ts index 9a9cb4a2b18..1319391eb0b 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias.ts @@ -16,6 +16,9 @@ // @Filename: /a_reexport_2.ts ////export * from "./a"; +// @Filename: /a_reexport_3.ts +////export { foo } from "./a_reexport"; + // @Filename: /b.ts ////fo/**/ @@ -24,13 +27,13 @@ verify.completions({ includes: [ completion.undefinedVarEntry, { - name: "foo", - source: "/a", - sourceDisplay: "./a", - text: "(alias) const foo: 0\nexport foo", - kind: "alias", - hasAction: true, - sortText: completion.SortText.AutoImportSuggestions + name: "foo", + source: "/a", + sourceDisplay: "./a", + text: "(alias) const foo: 0\nexport foo", + kind: "alias", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, ...completion.statementKeywordsWithTypes, ], diff --git a/tests/cases/fourslash/importNameCodeFixNewImportNodeModules8.ts b/tests/cases/fourslash/importNameCodeFixNewImportNodeModules8.ts index f048f0d30d2..acfddd587f7 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportNodeModules8.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportNodeModules8.ts @@ -3,7 +3,7 @@ //// [|f1/*0*/('');|] // @Filename: package.json -//// { "dependencies": { "package-name": "latest" } } +//// { "dependencies": { "@scope/package-name": "latest" } } // @Filename: node_modules/@scope/package-name/bin/lib/index.d.ts //// export function f1(text: string): string; From 89badcc9d57213ee3b04f420877310edc8b840f9 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 12 Jul 2019 11:03:20 -0700 Subject: [PATCH 14/23] Add 'Remove unnecessary await' suggestion and fix (#32363) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add remove unnecessary await fix * Add test for removing unnecessary parens after await is gone * Fix handling of numbers in property access expressions * Don’t offer suggestion when awaited type is any/unknown * Fix random other test * Fix new expression edge cases * Only remove parens for identifiers and call expressions --- src/compiler/checker.ts | 6 ++- src/compiler/diagnosticMessages.json | 13 ++++++ .../codefixes/removeUnnecessaryAwait.ts | 33 +++++++++++++++ src/services/tsconfig.json | 1 + .../codeFixRemoveUnnecessaryAwait.ts | 40 +++++++++++++++++++ .../convertFunctionToEs6Class_asyncMethods.ts | 9 +++-- 6 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 src/services/codefixes/removeUnnecessaryAwait.ts create mode 100644 tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b761606fcb3..a79a02cba07 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26403,7 +26403,11 @@ namespace ts { * The runtime behavior of the `await` keyword. */ function checkAwaitedType(type: Type, errorNode: Node, diagnosticMessage: DiagnosticMessage, arg0?: string | number): Type { - return getAwaitedType(type, errorNode, diagnosticMessage, arg0) || errorType; + const awaitedType = getAwaitedType(type, errorNode, diagnosticMessage, arg0); + if (awaitedType === type && !(type.flags & TypeFlags.AnyOrUnknown)) { + addErrorOrSuggestion(/*isError*/ false, createDiagnosticForNode(errorNode, Diagnostics.await_has_no_effect_on_the_type_of_this_expression)); + } + return awaitedType || errorType; } function getAwaitedType(type: Type, errorNode?: Node, diagnosticMessage?: DiagnosticMessage, arg0?: string | number): Type | undefined { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7fc2fdd4237..7a6b798e2ae 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4635,6 +4635,11 @@ "category": "Suggestion", "code": 80006 }, + "'await' has no effect on the type of this expression.": { + "category": "Suggestion", + "code": 80007 + }, + "Add missing 'super()' call": { "category": "Message", "code": 90001 @@ -5095,6 +5100,14 @@ "category": "Message", "code": 95085 }, + "Remove unnecessary 'await'": { + "category": "Message", + "code": 95086 + }, + "Remove all unnecessary uses of 'await'": { + "category": "Message", + "code": 95087 + }, "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", diff --git a/src/services/codefixes/removeUnnecessaryAwait.ts b/src/services/codefixes/removeUnnecessaryAwait.ts new file mode 100644 index 00000000000..c235d028efb --- /dev/null +++ b/src/services/codefixes/removeUnnecessaryAwait.ts @@ -0,0 +1,33 @@ +/* @internal */ +namespace ts.codefix { + const fixId = "removeUnnecessaryAwait"; + const errorCodes = [ + Diagnostics.await_has_no_effect_on_the_type_of_this_expression.code, + ]; + + registerCodeFix({ + errorCodes, + getCodeActions: (context) => { + const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span)); + if (changes.length > 0) { + return [createCodeFixAction(fixId, changes, Diagnostics.Remove_unnecessary_await, fixId, Diagnostics.Remove_all_unnecessary_uses_of_await)]; + } + }, + fixIds: [fixId], + getAllCodeActions: context => { + return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag)); + }, + }); + + function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, span: TextSpan) { + const awaitKeyword = tryCast(getTokenAtPosition(sourceFile, span.start), (node): node is AwaitKeywordToken => node.kind === SyntaxKind.AwaitKeyword); + const awaitExpression = awaitKeyword && tryCast(awaitKeyword.parent, isAwaitExpression); + if (!awaitExpression) { + return; + } + + const parenthesizedExpression = tryCast(awaitExpression.parent, isParenthesizedExpression); + const removeParens = parenthesizedExpression && (isIdentifier(awaitExpression.expression) || isCallExpression(awaitExpression.expression)); + changeTracker.replaceNode(sourceFile, removeParens ? parenthesizedExpression || awaitExpression : awaitExpression, awaitExpression.expression); + } +} diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 05c1b0b482e..c2a6946b5ed 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -80,6 +80,7 @@ "codefixes/useDefaultImport.ts", "codefixes/fixAddModuleReferTypeMissingTypeof.ts", "codefixes/convertToMappedObjectType.ts", + "codefixes/removeUnnecessaryAwait.ts", "refactors/convertExport.ts", "refactors/convertImport.ts", "refactors/extractSymbol.ts", diff --git a/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts b/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts new file mode 100644 index 00000000000..b8e1de4605e --- /dev/null +++ b/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts @@ -0,0 +1,40 @@ +/// +////declare class C { foo(): void } +////declare function foo(): string; +////async function f() { +//// await ""; +//// await 0; +//// (await foo()).toLowerCase(); +//// (await 0).toFixed(); +//// (await new C).foo(); +////} + +verify.codeFix({ + description: ts.Diagnostics.Remove_unnecessary_await.message, + index: 0, + newFileContent: +`declare class C { foo(): void } +declare function foo(): string; +async function f() { + ""; + await 0; + (await foo()).toLowerCase(); + (await 0).toFixed(); + (await new C).foo(); +}` +}); + +verify.codeFixAll({ + fixAllDescription: ts.Diagnostics.Remove_all_unnecessary_uses_of_await.message, + fixId: "removeUnnecessaryAwait", + newFileContent: +`declare class C { foo(): void } +declare function foo(): string; +async function f() { + ""; + 0; + foo().toLowerCase(); + (0).toFixed(); + (new C).foo(); +}` +}); diff --git a/tests/cases/fourslash/convertFunctionToEs6Class_asyncMethods.ts b/tests/cases/fourslash/convertFunctionToEs6Class_asyncMethods.ts index fb3b46763c8..bb8f8c22962 100644 --- a/tests/cases/fourslash/convertFunctionToEs6Class_asyncMethods.ts +++ b/tests/cases/fourslash/convertFunctionToEs6Class_asyncMethods.ts @@ -2,13 +2,14 @@ // @allowNonTsExtensions: true // @Filename: test123.js +// @lib: es5 ////export function /**/MyClass() { ////} ////MyClass.prototype.foo = async function() { -//// await 2; +//// await Promise.resolve(); ////} ////MyClass.bar = async function() { -//// await 3; +//// await Promise.resolve(); ////} verify.codeFix({ @@ -18,10 +19,10 @@ verify.codeFix({ constructor() { } async foo() { - await 2; + await Promise.resolve(); } static async bar() { - await 3; + await Promise.resolve(); } } `, From 59d5585814afee67d162228c9b5f702ab1caf8ab Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 12 Jul 2019 15:21:57 -0400 Subject: [PATCH 15/23] Don't indent properties if an object literal follows directly from another object on the same line --- src/services/formatting/formatting.ts | 3 +++ src/services/formatting/smartIndenter.ts | 23 +++++++++++++++++-- .../formatMultipleFunctionArguments.ts | 20 +++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 01c09a4989c..e4b6459a31e 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -490,6 +490,9 @@ namespace ts.formatting { else if (SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile)) { return { indentation: parentDynamicIndentation.getIndentation(), delta }; } + else if (SmartIndenter.childStartsInlineWithPreviousObject(parent, node, startLine, sourceFile)) { + return { indentation: parentDynamicIndentation.getIndentation(), delta }; + } else { return { indentation: parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(node), delta }; } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 62f4c3c556c..766228c1f09 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -322,6 +322,26 @@ namespace ts.formatting { return false; } + export function childStartsInlineWithPreviousObject(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean { + if (parent.kind === SyntaxKind.CallExpression) { + const parentCallExpression = parent; + const currentNode = find(parentCallExpression.arguments, arg => arg.pos === child.pos); + if (!currentNode) return false; // Shouldn't happen + + const currentIndex = parentCallExpression.arguments.indexOf(currentNode); + if (currentIndex === 0) return false; // Can't look at previous node if first + + const previousNode = parentCallExpression.arguments[currentIndex - 1]; + const lineOfPreviousNode = getLineAndCharacterOfPosition(sourceFile, previousNode.getEnd()).line; + + if (childStartLine === lineOfPreviousNode) { + return true; + } + } + + return false; + } + export function getContainingList(node: Node, sourceFile: SourceFile): NodeArray | undefined { return node.parent && getListByRange(node.getStart(sourceFile), node.getEnd(), node.parent, sourceFile); } @@ -482,6 +502,7 @@ namespace ts.formatting { case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.Block: case SyntaxKind.ModuleBlock: + case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TypeLiteral: case SyntaxKind.MappedType: case SyntaxKind.TupleType: @@ -523,8 +544,6 @@ namespace ts.formatting { return rangeIsOnOneLine(sourceFile, child!); } return true; - case SyntaxKind.CallExpression: - return childKind !== SyntaxKind.ObjectLiteralExpression case SyntaxKind.DoStatement: case SyntaxKind.WhileStatement: case SyntaxKind.ForInStatement: diff --git a/tests/cases/fourslash/formatMultipleFunctionArguments.ts b/tests/cases/fourslash/formatMultipleFunctionArguments.ts index 1e3909305a6..32e6d0eea89 100644 --- a/tests/cases/fourslash/formatMultipleFunctionArguments.ts +++ b/tests/cases/fourslash/formatMultipleFunctionArguments.ts @@ -11,6 +11,15 @@ //// prop5: 5, //// prop6: 6 //// }); +//// +//// someRandomFunction( +//// { prop7: 1, prop8: 2 }, +//// { prop9: 3, prop10: 4 }, +//// { +//// prop11: 5, +//// prop2: 6 +//// } +//// ); format.document(); verify.currentFileContentIs(` @@ -23,4 +32,13 @@ someRandomFunction({ }, { prop5: 5, prop6: 6 -});`); +}); + +someRandomFunction( + { prop7: 1, prop8: 2 }, + { prop9: 3, prop10: 4 }, + { + prop11: 5, + prop2: 6 + } +);`); From 37f2e5972f36515a79c67c2cb95547955b6a8a62 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 12 Jul 2019 12:49:34 -0700 Subject: [PATCH 16/23] Cache & widen assigned js prototype type (#32381) --- src/compiler/checker.ts | 2 +- ...ototypeNoErrorTruncationNoCrash.errors.txt | 48 +++++++++++ ...onWithPrototypeNoErrorTruncationNoCrash.js | 34 ++++++++ ...hPrototypeNoErrorTruncationNoCrash.symbols | 52 ++++++++++++ ...ithPrototypeNoErrorTruncationNoCrash.types | 81 +++++++++++++++++++ ...onWithPrototypeNoErrorTruncationNoCrash.ts | 21 +++++ 6 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.errors.txt create mode 100644 tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.js create mode 100644 tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.symbols create mode 100644 tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.types create mode 100644 tests/cases/compiler/jsFunctionWithPrototypeNoErrorTruncationNoCrash.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a79a02cba07..3dd9f9ef6f0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22750,7 +22750,7 @@ namespace ts { isVariableDeclaration(decl.parent) && getSymbolOfNode(decl.parent)); const prototype = assignmentSymbol && assignmentSymbol.exports && assignmentSymbol.exports.get("prototype" as __String); const init = prototype && prototype.valueDeclaration && getAssignedJSPrototype(prototype.valueDeclaration); - return init ? checkExpression(init) : undefined; + return init ? getWidenedType(checkExpressionCached(init)) : undefined; } function getAssignedJSPrototype(node: Node) { diff --git a/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.errors.txt b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.errors.txt new file mode 100644 index 00000000000..f4f41b4e231 --- /dev/null +++ b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.errors.txt @@ -0,0 +1,48 @@ +tests/cases/compiler/index.js(1,16): error TS7006: Parameter 'obj' implicitly has an 'any' type. +tests/cases/compiler/index.js(6,21): error TS7006: Parameter 'ratio' implicitly has an 'any' type. +tests/cases/compiler/index.js(7,20): error TS7006: Parameter 'ratio' implicitly has an 'any' type. +tests/cases/compiler/index.js(8,22): error TS7006: Parameter 'ratio' implicitly has an 'any' type. +tests/cases/compiler/index.js(9,24): error TS7006: Parameter 'ratio' implicitly has an 'any' type. +tests/cases/compiler/index.js(10,20): error TS7006: Parameter 'ratio' implicitly has an 'any' type. +tests/cases/compiler/index.js(11,21): error TS7006: Parameter 'ratio' implicitly has an 'any' type. +tests/cases/compiler/index.js(13,21): error TS7006: Parameter 'ratio' implicitly has an 'any' type. +tests/cases/compiler/index.js(14,2): error TS7023: 'toJSON' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. +tests/cases/compiler/index.js(14,35): error TS2339: Property 'rgb' does not exist on type 'Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }'. + + +==== tests/cases/compiler/index.js (10 errors) ==== + function Color(obj) { + ~~~ +!!! error TS7006: Parameter 'obj' implicitly has an 'any' type. + this.example = true + }; + Color.prototype = { + negate: function () {return this;}, + lighten: function (ratio) {return this;}, + ~~~~~ +!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type. + darken: function (ratio) {return this;}, + ~~~~~ +!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type. + saturate: function (ratio) {return this;}, + ~~~~~ +!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type. + desaturate: function (ratio) {return this;}, + ~~~~~ +!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type. + whiten: function (ratio) {return this;}, + ~~~~~ +!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type. + blacken: function (ratio) {return this;}, + ~~~~~ +!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type. + greyscale: function () {return this;}, + clearer: function (ratio) {return this;}, + ~~~~~ +!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type. + toJSON: function () {return this.rgb();}, + ~~~~~~ +!!! error TS7023: 'toJSON' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. + ~~~ +!!! error TS2339: Property 'rgb' does not exist on type 'Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }'. + }; \ No newline at end of file diff --git a/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.js b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.js new file mode 100644 index 00000000000..49d05b77cc9 --- /dev/null +++ b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.js @@ -0,0 +1,34 @@ +//// [index.js] +function Color(obj) { + this.example = true +}; +Color.prototype = { + negate: function () {return this;}, + lighten: function (ratio) {return this;}, + darken: function (ratio) {return this;}, + saturate: function (ratio) {return this;}, + desaturate: function (ratio) {return this;}, + whiten: function (ratio) {return this;}, + blacken: function (ratio) {return this;}, + greyscale: function () {return this;}, + clearer: function (ratio) {return this;}, + toJSON: function () {return this.rgb();}, +}; + +//// [index.js] +function Color(obj) { + this.example = true; +} +; +Color.prototype = { + negate: function () { return this; }, + lighten: function (ratio) { return this; }, + darken: function (ratio) { return this; }, + saturate: function (ratio) { return this; }, + desaturate: function (ratio) { return this; }, + whiten: function (ratio) { return this; }, + blacken: function (ratio) { return this; }, + greyscale: function () { return this; }, + clearer: function (ratio) { return this; }, + toJSON: function () { return this.rgb(); } +}; diff --git a/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.symbols b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.symbols new file mode 100644 index 00000000000..992df4b7886 --- /dev/null +++ b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.symbols @@ -0,0 +1,52 @@ +=== tests/cases/compiler/index.js === +function Color(obj) { +>Color : Symbol(Color, Decl(index.js, 0, 0), Decl(index.js, 2, 2)) +>obj : Symbol(obj, Decl(index.js, 0, 15)) + + this.example = true +>example : Symbol(Color.example, Decl(index.js, 0, 21)) + +}; +Color.prototype = { +>Color.prototype : Symbol(Color.prototype, Decl(index.js, 2, 2)) +>Color : Symbol(Color, Decl(index.js, 0, 0), Decl(index.js, 2, 2)) +>prototype : Symbol(Color.prototype, Decl(index.js, 2, 2)) + + negate: function () {return this;}, +>negate : Symbol(negate, Decl(index.js, 3, 19)) + + lighten: function (ratio) {return this;}, +>lighten : Symbol(lighten, Decl(index.js, 4, 36)) +>ratio : Symbol(ratio, Decl(index.js, 5, 20)) + + darken: function (ratio) {return this;}, +>darken : Symbol(darken, Decl(index.js, 5, 42)) +>ratio : Symbol(ratio, Decl(index.js, 6, 19)) + + saturate: function (ratio) {return this;}, +>saturate : Symbol(saturate, Decl(index.js, 6, 41)) +>ratio : Symbol(ratio, Decl(index.js, 7, 21)) + + desaturate: function (ratio) {return this;}, +>desaturate : Symbol(desaturate, Decl(index.js, 7, 43)) +>ratio : Symbol(ratio, Decl(index.js, 8, 23)) + + whiten: function (ratio) {return this;}, +>whiten : Symbol(whiten, Decl(index.js, 8, 45)) +>ratio : Symbol(ratio, Decl(index.js, 9, 19)) + + blacken: function (ratio) {return this;}, +>blacken : Symbol(blacken, Decl(index.js, 9, 41)) +>ratio : Symbol(ratio, Decl(index.js, 10, 20)) + + greyscale: function () {return this;}, +>greyscale : Symbol(greyscale, Decl(index.js, 10, 42)) + + clearer: function (ratio) {return this;}, +>clearer : Symbol(clearer, Decl(index.js, 11, 39)) +>ratio : Symbol(ratio, Decl(index.js, 12, 20)) + + toJSON: function () {return this.rgb();}, +>toJSON : Symbol(toJSON, Decl(index.js, 12, 42)) + +}; diff --git a/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.types b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.types new file mode 100644 index 00000000000..e7d10c54453 --- /dev/null +++ b/tests/baselines/reference/jsFunctionWithPrototypeNoErrorTruncationNoCrash.types @@ -0,0 +1,81 @@ +=== tests/cases/compiler/index.js === +function Color(obj) { +>Color : typeof Color +>obj : any + + this.example = true +>this.example = true : true +>this.example : any +>this : any +>example : any +>true : true + +}; +Color.prototype = { +>Color.prototype = { negate: function () {return this;}, lighten: function (ratio) {return this;}, darken: function (ratio) {return this;}, saturate: function (ratio) {return this;}, desaturate: function (ratio) {return this;}, whiten: function (ratio) {return this;}, blacken: function (ratio) {return this;}, greyscale: function () {return this;}, clearer: function (ratio) {return this;}, toJSON: function () {return this.rgb();},} : { negate: () => Color & { negate: any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; lighten: (ratio: any) => Color & { negate: () => Color & any; lighten: any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; darken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; saturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; desaturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; whiten: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; blacken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; greyscale: () => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; clearer: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: any; toJSON: () => any; }; toJSON: () => any; } +>Color.prototype : { negate: () => Color & { negate: any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; lighten: (ratio: any) => Color & { negate: () => Color & any; lighten: any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; darken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; saturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; desaturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; whiten: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; blacken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; greyscale: () => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; clearer: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: any; toJSON: () => any; }; toJSON: () => any; } +>Color : typeof Color +>prototype : { negate: () => Color & { negate: any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; lighten: (ratio: any) => Color & { negate: () => Color & any; lighten: any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; darken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; saturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; desaturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; whiten: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; blacken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; greyscale: () => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; clearer: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: any; toJSON: () => any; }; toJSON: () => any; } +>{ negate: function () {return this;}, lighten: function (ratio) {return this;}, darken: function (ratio) {return this;}, saturate: function (ratio) {return this;}, desaturate: function (ratio) {return this;}, whiten: function (ratio) {return this;}, blacken: function (ratio) {return this;}, greyscale: function () {return this;}, clearer: function (ratio) {return this;}, toJSON: function () {return this.rgb();},} : { negate: () => Color & { negate: any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; lighten: (ratio: any) => Color & { negate: () => Color & any; lighten: any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; darken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; saturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; desaturate: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; whiten: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; blacken: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; greyscale: () => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: any; clearer: (ratio: any) => Color & any; toJSON: () => any; }; clearer: (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: any; toJSON: () => any; }; toJSON: () => any; } + + negate: function () {return this;}, +>negate : () => Color & { negate: any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function () {return this;} : () => Color & { negate: any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + lighten: function (ratio) {return this;}, +>lighten : (ratio: any) => Color & { negate: () => Color & any; lighten: any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function (ratio) {return this;} : (ratio: any) => Color & { negate: () => Color & any; lighten: any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>ratio : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + darken: function (ratio) {return this;}, +>darken : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function (ratio) {return this;} : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>ratio : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + saturate: function (ratio) {return this;}, +>saturate : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function (ratio) {return this;} : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>ratio : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + desaturate: function (ratio) {return this;}, +>desaturate : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function (ratio) {return this;} : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>ratio : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + whiten: function (ratio) {return this;}, +>whiten : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function (ratio) {return this;} : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>ratio : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + blacken: function (ratio) {return this;}, +>blacken : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function (ratio) {return this;} : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>ratio : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + greyscale: function () {return this;}, +>greyscale : () => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>function () {return this;} : () => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + clearer: function (ratio) {return this;}, +>clearer : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: any; toJSON: () => any; } +>function (ratio) {return this;} : (ratio: any) => Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: any; toJSON: () => any; } +>ratio : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } + + toJSON: function () {return this.rgb();}, +>toJSON : () => any +>function () {return this.rgb();} : () => any +>this.rgb() : any +>this.rgb : any +>this : Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; } +>rgb : any + +}; diff --git a/tests/cases/compiler/jsFunctionWithPrototypeNoErrorTruncationNoCrash.ts b/tests/cases/compiler/jsFunctionWithPrototypeNoErrorTruncationNoCrash.ts new file mode 100644 index 00000000000..6f925aef687 --- /dev/null +++ b/tests/cases/compiler/jsFunctionWithPrototypeNoErrorTruncationNoCrash.ts @@ -0,0 +1,21 @@ +// @noErrorTruncation: true +// @noImplicitAny: true +// @allowJs: true +// @checkJs: true +// @outDir: built +// @filename: index.js +function Color(obj) { + this.example = true +}; +Color.prototype = { + negate: function () {return this;}, + lighten: function (ratio) {return this;}, + darken: function (ratio) {return this;}, + saturate: function (ratio) {return this;}, + desaturate: function (ratio) {return this;}, + whiten: function (ratio) {return this;}, + blacken: function (ratio) {return this;}, + greyscale: function () {return this;}, + clearer: function (ratio) {return this;}, + toJSON: function () {return this.rgb();}, +}; \ No newline at end of file From ba79b5ffacec89ee79219eb6de5e35b90a0bf537 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 12 Jul 2019 23:14:42 +0300 Subject: [PATCH 17/23] Fixed auto completion after a < token to return types not values. --- src/services/completions.ts | 3 +++ .../cases/fourslash/completionsAfterLessThanToken.ts | 12 ++++++++++++ .../completionsIsPossiblyTypeArgumentPosition.ts | 9 ++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/completionsAfterLessThanToken.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index cf707c642ed..29ce51bd47a 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1239,6 +1239,9 @@ namespace ts.Completions { case SyntaxKind.AsKeyword: return parentKind === SyntaxKind.AsExpression; + case SyntaxKind.LessThanToken: + return parentKind === SyntaxKind.TypeReference; + case SyntaxKind.ExtendsKeyword: return parentKind === SyntaxKind.TypeParameter; } diff --git a/tests/cases/fourslash/completionsAfterLessThanToken.ts b/tests/cases/fourslash/completionsAfterLessThanToken.ts new file mode 100644 index 00000000000..c236f85e1fe --- /dev/null +++ b/tests/cases/fourslash/completionsAfterLessThanToken.ts @@ -0,0 +1,12 @@ +/// + +//// function f() { +//// const k: Record Date: Fri, 12 Jul 2019 14:01:57 -0700 Subject: [PATCH 18/23] Parse quoted constructors as constructors, not methods (#31949) * Parse quoted constructors as constructors, not methods * Update baselines * Fix disambiguation between quoted constructor and property named constructor * Clean up parsing a bit * Support escapes in constructor name * Update baselines --- src/compiler/checker.ts | 3 - src/compiler/diagnosticMessages.json | 4 -- src/compiler/parser.ts | 34 ++++++++--- src/compiler/utilities.ts | 17 ++++++ src/services/utilities.ts | 17 ------ .../reference/quotedConstructors.errors.txt | 30 --------- .../baselines/reference/quotedConstructors.js | 38 +++++++++--- .../reference/quotedConstructors.symbols | 61 ++++++++++++++----- .../reference/quotedConstructors.types | 58 +++++++++++++++--- .../quotedConstructors.ts | 22 +++++-- 10 files changed, 186 insertions(+), 98 deletions(-) delete mode 100644 tests/baselines/reference/quotedConstructors.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3dd9f9ef6f0..610c1c38de0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33017,9 +33017,6 @@ namespace ts { return grammarErrorAtPos(node, node.end - 1, ";".length, Diagnostics._0_expected, "{"); } } - else if (isClassLike(node.parent) && isStringLiteral(node.name) && node.name.text === "constructor" && (!compilerOptions.target || compilerOptions.target < ScriptTarget.ES5)) { - return grammarErrorOnNode(node.name, Diagnostics.Quoted_constructors_have_previously_been_interpreted_as_methods_which_is_incorrect_In_TypeScript_3_6_they_will_be_correctly_parsed_as_constructors_In_the_meantime_consider_using_constructor_to_write_a_constructor_or_constructor_to_write_a_method); - } if (checkGrammarForGenerator(node)) { return true; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7a6b798e2ae..4528d504d0d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5113,10 +5113,6 @@ "category": "Error", "code": 18004 }, - "Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '[\"constructor\"]()' to write a method.": { - "category": "Error", - "code": 18005 - }, "Classes may not have a field named 'constructor'.": { "category": "Error", "code": 18006 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f115d66951a..254be93000b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5656,12 +5656,27 @@ namespace ts { return finishNode(node); } - function parseConstructorDeclaration(node: ConstructorDeclaration): ConstructorDeclaration { - node.kind = SyntaxKind.Constructor; - parseExpected(SyntaxKind.ConstructorKeyword); - fillSignature(SyntaxKind.ColonToken, SignatureFlags.None, node); - node.body = parseFunctionBlockOrSemicolon(SignatureFlags.None, Diagnostics.or_expected); - return finishNode(node); + function parseConstructorName() { + if (token() === SyntaxKind.ConstructorKeyword) { + return parseExpected(SyntaxKind.ConstructorKeyword); + } + if (token() === SyntaxKind.StringLiteral && lookAhead(nextToken) === SyntaxKind.OpenParenToken) { + return tryParse(() => { + const literalNode = parseLiteralNode(); + return literalNode.text === "constructor" ? literalNode : undefined; + }); + } + } + + function tryParseConstructorDeclaration(node: ConstructorDeclaration): ConstructorDeclaration | undefined { + return tryParse(() => { + if (parseConstructorName()) { + node.kind = SyntaxKind.Constructor; + fillSignature(SyntaxKind.ColonToken, SignatureFlags.None, node); + node.body = parseFunctionBlockOrSemicolon(SignatureFlags.None, Diagnostics.or_expected); + return finishNode(node); + } + }); } function parseMethodDeclaration(node: MethodDeclaration, asteriskToken: AsteriskToken, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { @@ -5867,8 +5882,11 @@ namespace ts { return parseAccessorDeclaration(node, SyntaxKind.SetAccessor); } - if (token() === SyntaxKind.ConstructorKeyword) { - return parseConstructorDeclaration(node); + if (token() === SyntaxKind.ConstructorKeyword || token() === SyntaxKind.StringLiteral) { + const constructorDeclaration = tryParseConstructorDeclaration(node); + if (constructorDeclaration) { + return constructorDeclaration; + } } if (isIndexSignature()) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 0d3bad879de..fb5c69c6375 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3150,6 +3150,23 @@ namespace ts { return s.replace(escapedCharsRegExp, getReplacement); } + /** + * Strip off existed single quotes or double quotes from a given string + * + * @return non-quoted string + */ + export function stripQuotes(name: string) { + const length = name.length; + if (length >= 2 && name.charCodeAt(0) === name.charCodeAt(length - 1) && startsWithQuote(name)) { + return name.substring(1, length - 1); + } + return name; + } + + export function startsWithQuote(name: string): boolean { + return isSingleOrDoubleQuote(name.charCodeAt(0)); + } + function getReplacement(c: string, offset: number, input: string) { if (c.charCodeAt(0) === CharacterCodes.nullCharacter) { const lookAhead = input.charCodeAt(offset + c.length); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index cbadfbc9b53..6b224df4d4d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1636,23 +1636,6 @@ namespace ts { return !!location.parent && isImportOrExportSpecifier(location.parent) && location.parent.propertyName === location; } - /** - * Strip off existed single quotes or double quotes from a given string - * - * @return non-quoted string - */ - export function stripQuotes(name: string) { - const length = name.length; - if (length >= 2 && name.charCodeAt(0) === name.charCodeAt(length - 1) && startsWithQuote(name)) { - return name.substring(1, length - 1); - } - return name; - } - - export function startsWithQuote(name: string): boolean { - return isSingleOrDoubleQuote(name.charCodeAt(0)); - } - export function scriptKindIs(fileName: string, host: LanguageServiceHost, ...scriptKinds: ScriptKind[]): boolean { const scriptKind = getScriptKind(fileName, host); return some(scriptKinds, k => k === scriptKind); diff --git a/tests/baselines/reference/quotedConstructors.errors.txt b/tests/baselines/reference/quotedConstructors.errors.txt deleted file mode 100644 index 9e70452ff40..00000000000 --- a/tests/baselines/reference/quotedConstructors.errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts(2,5): error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. -tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts(6,5): error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. -tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts(14,5): error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. - - -==== tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts (3 errors) ==== - class C { - "constructor"() {} // Error in 3.5 - ~~~~~~~~~~~~~ -!!! error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. - } - - class D { - 'constructor'() {} // Error in 3.5 - ~~~~~~~~~~~~~ -!!! error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. - } - - class E { - ['constructor']() {} - } - - new class { - "constructor"() {} // Error in 3.5 - ~~~~~~~~~~~~~ -!!! error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. - }; - - var o = { "constructor"() {} }; - \ No newline at end of file diff --git a/tests/baselines/reference/quotedConstructors.js b/tests/baselines/reference/quotedConstructors.js index c9a662e6af5..36b57718f0a 100644 --- a/tests/baselines/reference/quotedConstructors.js +++ b/tests/baselines/reference/quotedConstructors.js @@ -1,46 +1,68 @@ //// [quotedConstructors.ts] class C { - "constructor"() {} // Error in 3.5 + "constructor"() { + console.log(this); + } } class D { - 'constructor'() {} // Error in 3.5 + 'constructor'() { + console.log(this); + } } class E { - ['constructor']() {} + ['constructor']() { + console.log(this); + } } new class { - "constructor"() {} // Error in 3.5 + "constructor"() { + console.log(this); + } }; var o = { "constructor"() {} }; + +class F { + "\x63onstructor"() { + console.log(this); + } +} //// [quotedConstructors.js] var C = /** @class */ (function () { function C() { + console.log(this); } - C.prototype["constructor"] = function () { }; // Error in 3.5 return C; }()); var D = /** @class */ (function () { function D() { + console.log(this); } - D.prototype['constructor'] = function () { }; // Error in 3.5 return D; }()); var E = /** @class */ (function () { function E() { } - E.prototype['constructor'] = function () { }; + E.prototype['constructor'] = function () { + console.log(this); + }; return E; }()); new /** @class */ (function () { function class_1() { + console.log(this); } - class_1.prototype["constructor"] = function () { }; // Error in 3.5 return class_1; }()); var o = { "constructor": function () { } }; +var F = /** @class */ (function () { + function F() { + console.log(this); + } + return F; +}()); diff --git a/tests/baselines/reference/quotedConstructors.symbols b/tests/baselines/reference/quotedConstructors.symbols index be68e484847..a4476a25ae5 100644 --- a/tests/baselines/reference/quotedConstructors.symbols +++ b/tests/baselines/reference/quotedConstructors.symbols @@ -2,32 +2,65 @@ class C { >C : Symbol(C, Decl(quotedConstructors.ts, 0, 0)) - "constructor"() {} // Error in 3.5 ->"constructor" : Symbol(C["constructor"], Decl(quotedConstructors.ts, 0, 9)) + "constructor"() { + console.log(this); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(C, Decl(quotedConstructors.ts, 0, 0)) + } } class D { ->D : Symbol(D, Decl(quotedConstructors.ts, 2, 1)) +>D : Symbol(D, Decl(quotedConstructors.ts, 4, 1)) - 'constructor'() {} // Error in 3.5 ->'constructor' : Symbol(D['constructor'], Decl(quotedConstructors.ts, 4, 9)) + 'constructor'() { + console.log(this); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(D, Decl(quotedConstructors.ts, 4, 1)) + } } class E { ->E : Symbol(E, Decl(quotedConstructors.ts, 6, 1)) +>E : Symbol(E, Decl(quotedConstructors.ts, 10, 1)) - ['constructor']() {} ->['constructor'] : Symbol(E['constructor'], Decl(quotedConstructors.ts, 8, 9)) ->'constructor' : Symbol(E['constructor'], Decl(quotedConstructors.ts, 8, 9)) + ['constructor']() { +>['constructor'] : Symbol(E['constructor'], Decl(quotedConstructors.ts, 12, 9)) +>'constructor' : Symbol(E['constructor'], Decl(quotedConstructors.ts, 12, 9)) + + console.log(this); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(E, Decl(quotedConstructors.ts, 10, 1)) + } } new class { - "constructor"() {} // Error in 3.5 ->"constructor" : Symbol((Anonymous class)["constructor"], Decl(quotedConstructors.ts, 12, 11)) - + "constructor"() { + console.log(this); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this : Symbol((Anonymous class), Decl(quotedConstructors.ts, 18, 3)) + } }; var o = { "constructor"() {} }; ->o : Symbol(o, Decl(quotedConstructors.ts, 16, 3)) ->"constructor" : Symbol("constructor", Decl(quotedConstructors.ts, 16, 9)) +>o : Symbol(o, Decl(quotedConstructors.ts, 24, 3)) +>"constructor" : Symbol("constructor", Decl(quotedConstructors.ts, 24, 9)) + +class F { +>F : Symbol(F, Decl(quotedConstructors.ts, 24, 31)) + + "\x63onstructor"() { + console.log(this); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(F, Decl(quotedConstructors.ts, 24, 31)) + } +} diff --git a/tests/baselines/reference/quotedConstructors.types b/tests/baselines/reference/quotedConstructors.types index 907a2152a80..65be89ff815 100644 --- a/tests/baselines/reference/quotedConstructors.types +++ b/tests/baselines/reference/quotedConstructors.types @@ -2,32 +2,57 @@ class C { >C : C - "constructor"() {} // Error in 3.5 ->"constructor" : () => void + "constructor"() { + console.log(this); +>console.log(this) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>this : this + } } class D { >D : D - 'constructor'() {} // Error in 3.5 ->'constructor' : () => void + 'constructor'() { + console.log(this); +>console.log(this) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>this : this + } } class E { >E : E - ['constructor']() {} + ['constructor']() { >['constructor'] : () => void >'constructor' : "constructor" + + console.log(this); +>console.log(this) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>this : this + } } new class { ->new class { "constructor"() {} // Error in 3.5} : (Anonymous class) ->class { "constructor"() {} // Error in 3.5} : typeof (Anonymous class) - - "constructor"() {} // Error in 3.5 ->"constructor" : () => void +>new class { "constructor"() { console.log(this); }} : (Anonymous class) +>class { "constructor"() { console.log(this); }} : typeof (Anonymous class) + "constructor"() { + console.log(this); +>console.log(this) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>this : this + } }; var o = { "constructor"() {} }; @@ -35,3 +60,16 @@ var o = { "constructor"() {} }; >{ "constructor"() {} } : { "constructor"(): void; } >"constructor" : () => void +class F { +>F : F + + "\x63onstructor"() { + console.log(this); +>console.log(this) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>this : this + } +} + diff --git a/tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts b/tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts index 3ab45c72810..c03ce26cc2f 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts @@ -1,17 +1,31 @@ class C { - "constructor"() {} // Error in 3.5 + "constructor"() { + console.log(this); + } } class D { - 'constructor'() {} // Error in 3.5 + 'constructor'() { + console.log(this); + } } class E { - ['constructor']() {} + ['constructor']() { + console.log(this); + } } new class { - "constructor"() {} // Error in 3.5 + "constructor"() { + console.log(this); + } }; var o = { "constructor"() {} }; + +class F { + "\x63onstructor"() { + console.log(this); + } +} From 1d78218053332e0a7de3cadcea53a64f3b0beff1 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 15 Jul 2019 10:48:10 -0400 Subject: [PATCH 19/23] Handle feedback from #32359 --- src/services/formatting/formatting.ts | 2 +- src/services/formatting/smartIndenter.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index e4b6459a31e..ed6b71efb75 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -490,7 +490,7 @@ namespace ts.formatting { else if (SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile)) { return { indentation: parentDynamicIndentation.getIndentation(), delta }; } - else if (SmartIndenter.childStartsInlineWithPreviousObject(parent, node, startLine, sourceFile)) { + else if (SmartIndenter.argumentStartsOnSameLineAsPreviousArgument(parent, node, startLine, sourceFile)) { return { indentation: parentDynamicIndentation.getIndentation(), delta }; } else { diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 766228c1f09..7a8bfb5f5d5 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -322,16 +322,15 @@ namespace ts.formatting { return false; } - export function childStartsInlineWithPreviousObject(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean { - if (parent.kind === SyntaxKind.CallExpression) { - const parentCallExpression = parent; - const currentNode = find(parentCallExpression.arguments, arg => arg.pos === child.pos); - if (!currentNode) return false; // Shouldn't happen + export function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean { + if (isCallOrNewExpression(parent)) { + if (!parent.arguments) return false; - const currentIndex = parentCallExpression.arguments.indexOf(currentNode); + const currentNode = Debug.assertDefined(find(parent.arguments, arg => arg.pos === child.pos)); + const currentIndex = parent.arguments.indexOf(currentNode); if (currentIndex === 0) return false; // Can't look at previous node if first - const previousNode = parentCallExpression.arguments[currentIndex - 1]; + const previousNode = parent.arguments[currentIndex - 1]; const lineOfPreviousNode = getLineAndCharacterOfPosition(sourceFile, previousNode.getEnd()).line; if (childStartLine === lineOfPreviousNode) { From 79201c909d1889f0436c5ddefc74c39f99ed1262 Mon Sep 17 00:00:00 2001 From: csigs Date: Mon, 15 Jul 2019 16:10:11 +0000 Subject: [PATCH 20/23] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 20276 ++++++++-------- 1 file changed, 10138 insertions(+), 10138 deletions(-) diff --git a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl index 1a288195844..56bd64e882e 100644 --- a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -1,10139 +1,10139 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - or -. For example '{0}' or '{1}'.]]> - - 或 <语言>-<区域> 形式。例如“{0}”或“{1}”。]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - type.]]> - - 类型。]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ()' instead.]]> - - ()"。]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + or -. For example '{0}' or '{1}'.]]> + + 或 <语言>-<区域> 形式。例如“{0}”或“{1}”。]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + type.]]> + + 类型。]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ()' instead.]]> + + ()"。]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1397dc93873feb2005b5a9a09062d7fd36978765 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Mon, 15 Jul 2019 10:17:29 -0700 Subject: [PATCH 21/23] Update user baselines (#32403) --- .../baselines/reference/docker/azure-sdk.log | 14 +-- .../reference/docker/office-ui-fabric.log | 38 +++++-- .../user/chrome-devtools-frontend.log | 106 ------------------ tests/baselines/reference/user/uglify-js.log | 2 +- 4 files changed, 38 insertions(+), 122 deletions(-) diff --git a/tests/baselines/reference/docker/azure-sdk.log b/tests/baselines/reference/docker/azure-sdk.log index 5991387679e..a1e33524e6e 100644 --- a/tests/baselines/reference/docker/azure-sdk.log +++ b/tests/baselines/reference/docker/azure-sdk.log @@ -1,7 +1,7 @@ Exit Code: 1 Standard output: -Rush Multi-Project Build Tool 5.7.3 - https://rushjs.io +Rush Multi-Project Build Tool 5.10.1 - https://rushjs.io Starting "rush rebuild" Executing a maximum of 1 simultaneous processes... [@azure/cosmos] started @@ -13,7 +13,7 @@ npm ERR! npm ERR! Failed at the @azure/cosmos@X.X.X compile script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-11T13_39_53_628Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-15T13_35_10_789Z-debug.log [@azure/service-bus] started [@azure/storage-blob] started XX of XX: [@azure/storage-blob] completed successfully in ? seconds @@ -38,7 +38,7 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:tsc script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-11T13_41_08_804Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_862Z-debug.log ERROR: "build:tsc" exited with 2. npm ERR! code ELIFECYCLE npm ERR! errno 1 @@ -48,7 +48,7 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:lib script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-11T13_41_08_852Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_938Z-debug.log ERROR: "build:lib" exited with 1. [@azure/core-paging] started XX of XX: [@azure/core-paging] completed successfully in ? seconds @@ -90,7 +90,7 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:tsc script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-11T13_41_08_804Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_862Z-debug.log ERROR: "build:tsc" exited with 2. npm ERR! code ELIFECYCLE npm ERR! errno 1 @@ -100,7 +100,7 @@ npm ERR! npm ERR! Failed at the @azure/core-http@X.X.X-preview.1 build:lib script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-11T13_41_08_852Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-15T13_36_24_938Z-debug.log ERROR: "build:lib" exited with 1. @azure/cosmos ( ? seconds) npm ERR! code ELIFECYCLE @@ -111,7 +111,7 @@ npm ERR! npm ERR! Failed at the @azure/cosmos@X.X.X compile script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: -npm ERR! /root/.npm/_logs/2019-07-11T13_39_53_628Z-debug.log +npm ERR! /root/.npm/_logs/2019-07-15T13_35_10_789Z-debug.log @azure/service-bus ( ? seconds) >>> @azure/service-bus tsc -p . && rollup -c 2>&1 && npm run extract-api diff --git a/tests/baselines/reference/docker/office-ui-fabric.log b/tests/baselines/reference/docker/office-ui-fabric.log index 70e9ab2cc7b..c3a55fc3f6b 100644 --- a/tests/baselines/reference/docker/office-ui-fabric.log +++ b/tests/baselines/reference/docker/office-ui-fabric.log @@ -10,12 +10,24 @@ XX of XX: [@uifabric/prettier-rules] completed successfully in ? seconds XX of XX: [@uifabric/tslint-rules] completed successfully in ? seconds [@uifabric/codepen-loader] started ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. + PASS src/__tests__/codepenTransform.test.ts + codepen transform + ✓ handles examples with function components (225ms) + ✓ handles examples with class components (38ms) + ✓ handles examples importing exampleData (115ms) + ✓ handles examples importing TestImages (45ms) + ✓ handles examples importing PeopleExampleData (288ms) +Test Suites: 1 passed, 1 total +Tests: 5 passed, 5 total +Snapshots: 4 passed, 4 total +Time: ?s +Ran all test suites. [@uifabric/build] started XX of XX: [@uifabric/build] completed successfully in ? seconds [@uifabric/migration] started XX of XX: [@uifabric/migration] completed successfully in ? seconds [@uifabric/set-version] started -ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. +XX of XX: [@uifabric/set-version] completed successfully in ? seconds [@uifabric/merge-styles] started ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. [@uifabric/jest-serializer-merge-styles] started @@ -204,7 +216,7 @@ ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed [XX:XX:XX XM] x Error detected while running 'jest' [XX:XX:XX XM] x ------------------------------------ [XX:XX:XX XM] x Error: Command failed: /usr/local/bin/node /office-ui-fabric-react/common/temp/node_modules/jest/bin/jest.js --config /office-ui-fabric-react/packages/foundation/jest.config.js --passWithNoTests --colors - at ChildProcess. (/office-ui-fabric-react/common/temp/node_modules/.registry.npmjs.org/just-scripts-utils/0.8.1/node_modules/just-scripts-utils/lib/exec.js:70:31) + at ChildProcess. (/office-ui-fabric-react/common/temp/node_modules/.registry.npmjs.org/just-scripts-utils/0.8.2/node_modules/just-scripts-utils/lib/exec.js:70:31) at ChildProcess.emit (events.js:203:13) at ChildProcess.EventEmitter.emit (domain.js:494:23) at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) @@ -216,27 +228,38 @@ ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed XX of XX: [@uifabric/icons] completed successfully in ? seconds [@uifabric/webpack-utils] started XX of XX: [@uifabric/webpack-utils] completed successfully in ? seconds -SUCCESS (8) +SUCCESS (9) ================================ @uifabric/build (? seconds) @uifabric/file-type-icons (? seconds) @uifabric/icons (? seconds) @uifabric/migration (? seconds) @uifabric/prettier-rules (? seconds) +@uifabric/set-version (? seconds) @uifabric/test-utilities (? seconds) @uifabric/tslint-rules (? seconds) @uifabric/webpack-utils (? seconds) ================================ -SUCCESS WITH WARNINGS (6) +SUCCESS WITH WARNINGS (5) ================================ @uifabric/codepen-loader (? seconds) ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. + PASS src/__tests__/codepenTransform.test.ts + codepen transform + ✓ handles examples with function components (225ms) + ✓ handles examples with class components (38ms) + ✓ handles examples importing exampleData (115ms) + ✓ handles examples importing TestImages (45ms) + ✓ handles examples importing PeopleExampleData (288ms) +Test Suites: 1 passed, 1 total +Tests: 5 passed, 5 total +Snapshots: 4 passed, 4 total +Time: ?s +Ran all test suites. @uifabric/jest-serializer-merge-styles (? seconds) ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. @uifabric/merge-styles (? seconds) ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. -@uifabric/set-version (? seconds) -ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. @uifabric/styling (? seconds) ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. @uifabric/utilities (? seconds) @@ -296,7 +319,7 @@ ts-jest[versions] (WARN) Version X.X.X-insiders.xxxxxxxx of typescript installed [XX:XX:XX XM] x Error detected while running 'jest' [XX:XX:XX XM] x ------------------------------------ [XX:XX:XX XM] x Error: Command failed: /usr/local/bin/node /office-ui-fabric-react/common/temp/node_modules/jest/bin/jest.js --config /office-ui-fabric-react/packages/foundation/jest.config.js --passWithNoTests --colors - at ChildProcess. (/office-ui-fabric-react/common/temp/node_modules/.registry.npmjs.org/just-scripts-utils/0.8.1/node_modules/just-scripts-utils/lib/exec.js:70:31) + at ChildProcess. (/office-ui-fabric-react/common/temp/node_modules/.registry.npmjs.org/just-scripts-utils/0.8.2/node_modules/just-scripts-utils/lib/exec.js:70:31) at ChildProcess.emit (events.js:203:13) at ChildProcess.EventEmitter.emit (domain.js:494:23) at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) @@ -313,7 +336,6 @@ rush rebuild - Errors! ( ? seconds) Standard error: Your version of Node.js (X.X.X) has not been tested with this release of Rush. The Rush team will not accept issue reports for it. Please consider upgrading Rush or downgrading Node.js. XX of XX: [@uifabric/codepen-loader] completed with warnings in ? seconds -XX of XX: [@uifabric/set-version] completed with warnings in ? seconds XX of XX: [@uifabric/merge-styles] completed with warnings in ? seconds XX of XX: [@uifabric/jest-serializer-merge-styles] completed with warnings in ? seconds XX of XX: [@uifabric/utilities] completed with warnings in ? seconds diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index 87a3cd23c38..3f4fa8d5b95 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -3178,8 +3178,6 @@ node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBindin node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBinding.js(51,31): error TS2339: Property 'remove' does not exist on type 'Map'. node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBinding.js(65,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBinding.js(76,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. -node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBinding.js(85,5): error TS2322: Type 'StackTraceTopFrameLocation' is not assignable to type '{ update(): void; uiLocation(): UILocation; dispose(): void; isBlackboxed(): boolean; }'. - Property '_updateScheduled' does not exist on type '{ update(): void; uiLocation(): UILocation; dispose(): void; isBlackboxed(): boolean; }'. node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBinding.js(90,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBinding.js(195,22): error TS2694: Namespace 'Common' has no exported member 'Event'. node_modules/chrome-devtools-frontend/front_end/bindings/DebuggerWorkspaceBinding.js(207,34): error TS2339: Property 'valuesArray' does not exist on type 'Set'. @@ -3287,12 +3285,6 @@ node_modules/chrome-devtools-frontend/front_end/bindings_test_runner/IsolatedFil node_modules/chrome-devtools-frontend/front_end/bindings_test_runner/IsolatedFilesystemTestRunner.js(275,8): error TS2551: Property '_entry' does not exist on type 'typeof TestFileSystem'. Did you mean 'Entry'? node_modules/chrome-devtools-frontend/front_end/bindings_test_runner/IsolatedFilesystemTestRunner.js(276,8): error TS2339: Property '_modificationTimesDelta' does not exist on type 'typeof TestFileSystem'. node_modules/chrome-devtools-frontend/front_end/bindings_test_runner/OverridesTestRunner.js(7,13): error TS1064: The return type of an async function or method must be the global Promise type. -node_modules/chrome-devtools-frontend/front_end/bindings_test_runner/PersistenceTestRunner.js(45,46): error TS2345: Argument of type '(bindingCreated: (arg0: PersistenceBinding) => any, bindingRemoved: (arg0: PersistenceBinding) => any) => DefaultMapping' is not assignable to parameter of type '(arg0: (arg0: PersistenceBinding) => any, arg1: (arg0: PersistenceBinding) => any) => { dispose: () => void; }'. - Type 'DefaultMapping' is not assignable to type '{ dispose: () => void; }'. - Property '_workspace' does not exist on type '{ dispose: () => void; }'. -node_modules/chrome-devtools-frontend/front_end/bindings_test_runner/PersistenceTestRunner.js(54,46): error TS2345: Argument of type '(bindingCreated: (arg0: PersistenceBinding) => any, bindingRemoved: (arg0: PersistenceBinding) => any) => TestMapping' is not assignable to parameter of type '(arg0: (arg0: PersistenceBinding) => any, arg1: (arg0: PersistenceBinding) => any) => { dispose: () => void; }'. - Type 'TestMapping' is not assignable to type '{ dispose: () => void; }'. - Property '_onBindingAdded' does not exist on type '{ dispose: () => void; }'. node_modules/chrome-devtools-frontend/front_end/changes/ChangesHighlighter.js(7,51): error TS2694: Namespace 'Changes.ChangesView' has no exported member 'Row'. node_modules/chrome-devtools-frontend/front_end/changes/ChangesHighlighter.js(9,56): error TS2694: Namespace 'Changes.ChangesHighlighter' has no exported member 'DiffState'. node_modules/chrome-devtools-frontend/front_end/changes/ChangesHighlighter.js(10,75): error TS2694: Namespace 'Changes.ChangesHighlighter' has no exported member 'DiffState'. @@ -4029,8 +4021,6 @@ node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(232,15): node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(232,51): error TS2339: Property 'ConsoleView' does not exist on type '{ new (): Console; prototype: Console; }'. node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(233,20): error TS2339: Property 'ConsoleView' does not exist on type '{ new (): Console; prototype: Console; }'. node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(241,76): error TS2339: Property 'ConsoleFilter' does not exist on type '{ new (): Console; prototype: Console; }'. -node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(287,5): error TS2322: Type 'ConsoleViewMessage' is not assignable to type '{ willHide(): void; wasShown(): void; element(): Element; }'. - Property '_message' does not exist on type '{ willHide(): void; wasShown(): void; element(): Element; }'. node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(312,24): error TS2694: Namespace 'Common' has no exported member 'Event'. node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(411,7): error TS2322: Type 'Promise' is not assignable to type 'Promise'. node_modules/chrome-devtools-frontend/front_end/console/ConsoleView.js(419,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. @@ -4460,8 +4450,6 @@ node_modules/chrome-devtools-frontend/front_end/coverage/CoverageListView.js(285 node_modules/chrome-devtools-frontend/front_end/coverage/CoverageListView.js(286,45): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageListView.js(290,33): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(34,42): error TS2694: Namespace 'Protocol' has no exported member 'Profiler'. -node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(103,46): error TS2345: Argument of type 'CSSStyleSheetHeader' is not assignable to parameter of type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. - Property '_cssModel' does not exist on type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(131,31): error TS2694: Namespace 'Protocol' has no exported member 'Profiler'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(170,31): error TS2694: Namespace 'Protocol' has no exported member 'CSS'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(175,64): error TS2694: Namespace 'Coverage' has no exported member 'RangeUseCount'. @@ -5850,8 +5838,6 @@ node_modules/chrome-devtools-frontend/front_end/emulation/AdvancedApp.js(124,22) node_modules/chrome-devtools-frontend/front_end/emulation/AdvancedApp.js(142,44): error TS2339: Property 'style' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/emulation/AdvancedApp.js(169,22): error TS2694: Namespace 'Common' has no exported member 'Event'. node_modules/chrome-devtools-frontend/front_end/emulation/AdvancedApp.js(174,57): error TS2339: Property 'window' does not exist on type 'Element'. -node_modules/chrome-devtools-frontend/front_end/emulation/AdvancedApp.js(199,5): error TS2322: Type 'AdvancedApp' is not assignable to type '{ presentUI(document: Document): void; }'. - Property '_rootSplitWidget' does not exist on type '{ presentUI(document: Document): void; }'. node_modules/chrome-devtools-frontend/front_end/emulation/DeviceModeModel.js(9,1): error TS8022: JSDoc '@extends' is not attached to a class. node_modules/chrome-devtools-frontend/front_end/emulation/DeviceModeModel.js(56,42): error TS2694: Namespace 'Emulation.EmulatedDevice' has no exported member 'Mode'. node_modules/chrome-devtools-frontend/front_end/emulation/DeviceModeModel.js(65,17): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. @@ -6584,36 +6570,15 @@ node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapsho node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(1974,10): error TS2339: Property 'countDelta' does not exist on type 'Diff'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(1975,10): error TS2339: Property 'sizeDelta' does not exist on type 'Diff'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2021,80): error TS2339: Property 'edges' does not exist on type 'void'. -node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2021,89): error TS2345: Argument of type 'HeapSnapshotEdgeIndexProvider' is not assignable to parameter of type '{ itemForIndex(newIndex: number): { itemIndex(): number; serialize(): any; }; }'. - Types of property 'itemForIndex' are incompatible. - Type '(index: number) => HeapSnapshotEdge' is not assignable to type '(newIndex: number) => { itemIndex(): number; serialize(): any; }'. - Type 'HeapSnapshotEdge' is not assignable to type '{ itemIndex(): number; serialize(): any; }'. - Property '_snapshot' does not exist on type '{ itemIndex(): number; serialize(): any; }'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2032,80): error TS2339: Property 'edges' does not exist on type 'void'. -node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2032,89): error TS2345: Argument of type 'HeapSnapshotEdgeIndexProvider' is not assignable to parameter of type '{ itemForIndex(newIndex: number): { itemIndex(): number; serialize(): any; }; }'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2057,80): error TS2339: Property 'retainers' does not exist on type 'void'. -node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2057,93): error TS2345: Argument of type 'HeapSnapshotRetainerEdgeIndexProvider' is not assignable to parameter of type '{ itemForIndex(newIndex: number): { itemIndex(): number; serialize(): any; }; }'. - Types of property 'itemForIndex' are incompatible. - Type '(index: number) => HeapSnapshotRetainerEdge' is not assignable to type '(newIndex: number) => { itemIndex(): number; serialize(): any; }'. - Type 'HeapSnapshotRetainerEdge' is not assignable to type '{ itemIndex(): number; serialize(): any; }'. - Property '_snapshot' does not exist on type '{ itemIndex(): number; serialize(): any; }'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2126,33): error TS2339: Property 'AggregatedInfo' does not exist on type 'typeof HeapSnapshot'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2205,12): error TS2339: Property 'sort' does not exist on type 'HeapSnapshotItemProvider'. -node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2244,13): error TS2345: Argument of type 'HeapSnapshotEdgeIterator' is not assignable to parameter of type '{ hasNext(): boolean; item(): { itemIndex(): number; serialize(): any; }; next(): void; }'. - Types of property 'item' are incompatible. - Type '() => HeapSnapshotEdge' is not assignable to type '() => { itemIndex(): number; serialize(): any; }'. - Type 'HeapSnapshotEdge' is not assignable to type '{ itemIndex(): number; serialize(): any; }'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2283,13): error TS2339: Property 'nodeIndex' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2287,13): error TS2339: Property 'nodeIndex' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2322,28): error TS2339: Property 'sortRange' does not exist on type 'number[]'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2324,28): error TS2339: Property 'sortRange' does not exist on type 'number[]'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2326,28): error TS2339: Property 'sortRange' does not exist on type 'number[]'. -node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2340,68): error TS2345: Argument of type 'HeapSnapshotNodeIndexProvider' is not assignable to parameter of type '{ itemForIndex(newIndex: number): { itemIndex(): number; serialize(): any; }; }'. - Types of property 'itemForIndex' are incompatible. - Type '(index: number) => HeapSnapshotNode' is not assignable to type '(newIndex: number) => { itemIndex(): number; serialize(): any; }'. - Type 'HeapSnapshotNode' is not assignable to type '{ itemIndex(): number; serialize(): any; }'. - Property '_snapshot' does not exist on type '{ itemIndex(): number; serialize(): any; }'. -node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2341,15): error TS2345: Argument of type 'HeapSnapshotNodeIndexProvider' is not assignable to parameter of type '{ itemForIndex(newIndex: number): { itemIndex(): number; serialize(): any; }; }'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2353,12): error TS2339: Property 'nodeIndex' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2354,16): error TS2339: Property 'id' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/heap_snapshot_worker/HeapSnapshot.js(2397,13): error TS2339: Property 'nodeIndex' does not exist on type 'void'. @@ -7332,8 +7297,6 @@ node_modules/chrome-devtools-frontend/front_end/network/NetworkItemView.js(62,40 node_modules/chrome-devtools-frontend/front_end/network/NetworkItemView.js(65,37): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/network/NetworkLogView.js(86,48): error TS2694: Namespace 'Network.NetworkLogView' has no exported member 'Filter'. node_modules/chrome-devtools-frontend/front_end/network/NetworkLogView.js(88,40): error TS2694: Namespace 'Network.NetworkLogView' has no exported member 'Filter'. -node_modules/chrome-devtools-frontend/front_end/network/NetworkLogView.js(114,37): error TS2345: Argument of type 'NetworkFrameGrouper' is not assignable to parameter of type '{ groupNodeForRequest: (request: NetworkRequest) => NetworkGroupNode; reset: () => void; }'. - Property '_parentView' does not exist on type '{ groupNodeForRequest: (request: NetworkRequest) => NetworkGroupNode; reset: () => void; }'. node_modules/chrome-devtools-frontend/front_end/network/NetworkLogView.js(124,33): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/network/NetworkLogView.js(144,44): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/network/NetworkLogView.js(147,57): error TS2555: Expected at least 2 arguments, but got 1. @@ -7671,8 +7634,6 @@ node_modules/chrome-devtools-frontend/front_end/network/ResourceWebSocketFrameVi node_modules/chrome-devtools-frontend/front_end/network/ResourceWebSocketFrameView.js(241,34): error TS2694: Namespace 'SDK.NetworkRequest' has no exported member 'WebSocketFrame'. node_modules/chrome-devtools-frontend/front_end/network/ResourceWebSocketFrameView.js(250,14): error TS2339: Property 'createTextChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/network/ResourceWebSocketFrameView.js(251,14): error TS2339: Property 'title' does not exist on type 'Element'. -node_modules/chrome-devtools-frontend/front_end/network/ResourceWebSocketFrameView.js(292,5): error TS2322: Type 'StaticContentProvider' is not assignable to type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. - Property '_contentURL' does not exist on type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/network_log/HAREntry.js(130,29): error TS2339: Property 'localizedFailDescription' does not exist on type 'NetworkRequest'. node_modules/chrome-devtools-frontend/front_end/network_log/HAREntry.js(150,36): error TS2694: Namespace 'NetworkLog.HAREntry' has no exported member 'Timing'. node_modules/chrome-devtools-frontend/front_end/network_log/HAREntry.js(319,21): error TS2339: Property 'Timing' does not exist on type 'typeof HAREntry'. @@ -8585,8 +8546,6 @@ node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileFlameChart.js node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileFlameChart.js(481,40): error TS2339: Property 'window' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(61,23): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(63,23): error TS2555: Expected at least 2 arguments, but got 1. -node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(73,5): error TS2322: Type 'CPUFlameChartDataProvider' is not assignable to type '{ minimumBoundary(): number; totalTime(): number; formatValue(value: number, precision?: number): string; maxStackDepth(): number; timelineData(): TimelineData; prepareHighlightedEntryInfo(entryIndex: number): Element; ... 6 more ...; textColor(entryIndex: number): string; }'. - Property '_cpuProfile' does not exist on type '{ minimumBoundary(): number; totalTime(): number; formatValue(value: number, precision?: number): string; maxStackDepth(): number; timelineData(): TimelineData; prepareHighlightedEntryInfo(entryIndex: number): Element; ... 6 more ...; textColor(entryIndex: number): string; }'. node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(82,50): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(85,29): error TS2339: Property 'instance' does not exist on type 'typeof CPUProfileType'. node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(115,37): error TS2555: Expected at least 2 arguments, but got 1. @@ -8611,8 +8570,6 @@ node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(405,7 node_modules/chrome-devtools-frontend/front_end/profiler/CPUProfileView.js(407,31): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/HeapProfileView.js(31,23): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/HeapProfileView.js(33,23): error TS2555: Expected at least 2 arguments, but got 1. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapProfileView.js(43,5): error TS2322: Type 'HeapFlameChartDataProvider' is not assignable to type '{ minimumBoundary(): number; totalTime(): number; formatValue(value: number, precision?: number): string; maxStackDepth(): number; timelineData(): TimelineData; prepareHighlightedEntryInfo(entryIndex: number): Element; ... 6 more ...; textColor(entryIndex: number): string; }'. - Property '_profile' does not exist on type '{ minimumBoundary(): number; totalTime(): number; formatValue(value: number, precision?: number): string; maxStackDepth(): number; timelineData(): TimelineData; prepareHighlightedEntryInfo(entryIndex: number): Element; ... 6 more ...; textColor(entryIndex: number): string; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapProfileView.js(52,59): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/HeapProfileView.js(54,38): error TS2339: Property 'instance' does not exist on type 'typeof SamplingHeapProfileType'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapProfileView.js(82,37): error TS2555: Expected at least 2 arguments, but got 1. @@ -8688,10 +8645,6 @@ node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.j node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(700,24): error TS2694: Namespace 'Protocol' has no exported member 'HeapProfiler'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(713,67): error TS2339: Property '_name' does not exist on type 'HeapSnapshotGridNode'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(717,30): error TS2339: Property 'populateNodeBySnapshotObjectId' does not exist on type 'HeapSnapshotGridNode'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(776,11): error TS2345: Argument of type 'HeapSnapshotConstructorNode' is not assignable to parameter of type 'HeapSnapshotGridNode'. - Types of property 'createProvider' are incompatible. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Type 'HeapSnapshotProviderProxy' is not assignable to type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(822,56): error TS2694: Namespace 'DataGrid.DataGrid' has no exported member 'ColumnDescriptor'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(823,36): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(824,40): error TS2555: Expected at least 2 arguments, but got 1. @@ -8700,10 +8653,6 @@ node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.j node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(828,23): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(834,41): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(835,39): error TS2555: Expected at least 2 arguments, but got 1. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(887,40): error TS2345: Argument of type 'HeapSnapshotDiffNode' is not assignable to parameter of type 'HeapSnapshotGridNode'. - Types of property 'createProvider' are incompatible. - Type '() => HeapSnapshotDiffNodesProvider' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Type 'HeapSnapshotDiffNodesProvider' is not assignable to type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(902,56): error TS2694: Namespace 'DataGrid.DataGrid' has no exported member 'ColumnDescriptor'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(903,39): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotDataGrids.js(904,35): error TS2555: Expected at least 2 arguments, but got 1. @@ -8739,36 +8688,13 @@ node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.j node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(580,12): error TS2339: Property 'style' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(581,10): error TS2339: Property 'heapSnapshotNode' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(602,82): error TS2555: Expected at least 2 arguments, but got 1. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(682,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotObjectNode' is not assignable to the same property in base type 'HeapSnapshotGenericObjectNode'. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(682,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotObjectNode' is not assignable to the same property in base type 'HeapSnapshotGenericObjectNode'. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Type 'HeapSnapshotProviderProxy' is not assignable to type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Property '_worker' does not exist on type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(804,15): error TS2577: Return type annotation circularly references itself. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(871,36): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(874,34): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(892,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotInstanceNode' is not assignable to the same property in base type 'HeapSnapshotGenericObjectNode'. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(892,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotInstanceNode' is not assignable to the same property in base type 'HeapSnapshotGenericObjectNode'. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Type 'HeapSnapshotProviderProxy' is not assignable to type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(966,23): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(968,29): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(969,30): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(980,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotConstructorNode' is not assignable to the same property in base type 'HeapSnapshotGridNode'. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(980,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotConstructorNode' is not assignable to the same property in base type 'HeapSnapshotGridNode'. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Type 'HeapSnapshotProviderProxy' is not assignable to type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(981,27): error TS2339: Property 'snapshot' does not exist on type 'HeapSnapshotSortableDataGrid'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1001,5): error TS2322: Type '(HeapSnapshotGridNode | this)[]' is not assignable to type 'HeapSnapshotGridNode[]'. - Type 'HeapSnapshotGridNode | this' is not assignable to type 'HeapSnapshotGridNode'. - Type 'this' is not assignable to type 'HeapSnapshotGridNode'. - Type 'HeapSnapshotConstructorNode' is not assignable to type 'HeapSnapshotGridNode'. - Types of property 'createProvider' are incompatible. - Type '() => HeapSnapshotProviderProxy' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Type 'HeapSnapshotProviderProxy' is not assignable to type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1019,14): error TS2339: Property '_searchMatched' does not exist on type 'HeapSnapshotConstructorNode'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1029,81): error TS2339: Property 'snapshot' does not exist on type 'HeapSnapshotSortableDataGrid'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1140,22): error TS2339: Property 'pushAll' does not exist on type 'any[]'. @@ -8778,12 +8704,6 @@ node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.j node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1181,27): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1182,29): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1183,65): error TS2339: Property 'withThousandsSeparator' does not exist on type 'NumberConstructor'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1191,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotDiffNode' is not assignable to the same property in base type 'HeapSnapshotGridNode'. - Type '() => HeapSnapshotDiffNodesProvider' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. -node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1191,3): error TS2416: Property 'createProvider' in type 'HeapSnapshotDiffNode' is not assignable to the same property in base type 'HeapSnapshotGridNode'. - Type '() => HeapSnapshotDiffNodesProvider' is not assignable to type '() => { dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Type 'HeapSnapshotDiffNodesProvider' is not assignable to type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. - Property '_addedNodesProvider' does not exist on type '{ dispose(): void; nodePosition(snapshotObjectId: number): Promise; isEmpty(): Promise; serializeItemsRange(startPosition: number, endPosition: number): Promise<...>; sortAndRewind(comparator: ComparatorConfig): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1194,14): error TS2339: Property 'snapshot' does not exist on type 'HeapSnapshotSortableDataGrid'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1194,53): error TS2339: Property 'baseSnapshot' does not exist on type 'HeapSnapshotSortableDataGrid'. node_modules/chrome-devtools-frontend/front_end/profiler/HeapSnapshotGridNodes.js(1195,14): error TS2339: Property 'baseSnapshot' does not exist on type 'HeapSnapshotSortableDataGrid'. @@ -9497,8 +9417,6 @@ node_modules/chrome-devtools-frontend/front_end/screencast/ScreencastApp.js(16,6 Types of parameters 'screenCaptureModel' and 'model' are incompatible. Type 'T' is not assignable to type 'ScreenCaptureModel'. node_modules/chrome-devtools-frontend/front_end/screencast/ScreencastApp.js(85,35): error TS2345: Argument of type 'ScreencastView' is not assignable to parameter of type 'boolean'. -node_modules/chrome-devtools-frontend/front_end/screencast/ScreencastApp.js(121,5): error TS2322: Type 'ScreencastApp' is not assignable to type '{ presentUI(document: Document): void; }'. - Property '_enabledSetting' does not exist on type '{ presentUI(document: Document): void; }'. node_modules/chrome-devtools-frontend/front_end/screencast/ScreencastView.js(56,42): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/screencast/ScreencastView.js(152,24): error TS2694: Namespace 'Protocol' has no exported member 'Page'. node_modules/chrome-devtools-frontend/front_end/screencast/ScreencastView.js(193,22): error TS2694: Namespace 'Common' has no exported member 'Event'. @@ -9672,7 +9590,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/CSSStyleDeclaration.js(8,24) node_modules/chrome-devtools-frontend/front_end/sdk/CSSStyleDeclaration.js(41,47): error TS2694: Namespace 'Protocol' has no exported member 'CSS'. node_modules/chrome-devtools-frontend/front_end/sdk/CSSStyleDeclaration.js(50,24): error TS2694: Namespace 'Protocol' has no exported member 'CSS'. node_modules/chrome-devtools-frontend/front_end/sdk/CSSStyleSheetHeader.js(11,24): error TS2694: Namespace 'Protocol' has no exported member 'CSS'. -node_modules/chrome-devtools-frontend/front_end/sdk/CSSStyleSheetHeader.js(40,5): error TS2322: Type 'StaticContentProvider' is not assignable to type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/sdk/Connections.js(10,52): error TS2694: Namespace 'Protocol.InspectorBackend.Connection' has no exported member 'Params'. node_modules/chrome-devtools-frontend/front_end/sdk/Connections.js(34,22): error TS2694: Namespace 'Common' has no exported member 'Event'. node_modules/chrome-devtools-frontend/front_end/sdk/Connections.js(41,22): error TS2694: Namespace 'Common' has no exported member 'Event'. @@ -10410,7 +10327,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/ScreenCaptureModel.js(152,24 node_modules/chrome-devtools-frontend/front_end/sdk/ScreenCaptureModel.js(160,24): error TS2694: Namespace 'Protocol' has no exported member 'Page'. node_modules/chrome-devtools-frontend/front_end/sdk/Script.js(39,24): error TS2694: Namespace 'Protocol' has no exported member 'Runtime'. node_modules/chrome-devtools-frontend/front_end/sdk/Script.js(143,52): error TS2339: Property 'debuggerAgent' does not exist on type 'Target'. -node_modules/chrome-devtools-frontend/front_end/sdk/Script.js(159,5): error TS2322: Type 'StaticContentProvider' is not assignable to type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/sdk/Script.js(174,43): error TS2339: Property 'debuggerAgent' does not exist on type 'Target'. node_modules/chrome-devtools-frontend/front_end/sdk/Script.js(190,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/sdk/Script.js(190,50): error TS2694: Namespace 'Protocol' has no exported member 'Runtime'. @@ -10475,9 +10391,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(196,28): error node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(198,25): error TS2339: Property '_base64Map' does not exist on type 'typeof TextSourceMap'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(200,27): error TS2339: Property '_base64Map' does not exist on type 'typeof TextSourceMap'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(272,30): error TS2339: Property 'keysArray' does not exist on type 'Map'. -node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(284,7): error TS2322: Type 'StaticContentProvider' is not assignable to type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. -node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(285,5): error TS2322: Type 'CompilerSourceMappingContentProvider' is not assignable to type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. - Property '_sourceURL' does not exist on type '{ contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise; requestContent(): Promise; searchInContent(query: string, caseSensitive: boolean, isRegex: boolean): Promise<...>; }'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(325,26): error TS2339: Property 'upperBound' does not exist on type 'SourceMapEntry[]'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(338,26): error TS2339: Property 'lowerBound' does not exist on type 'SourceMapEntry[]'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js(339,25): error TS2339: Property 'upperBound' does not exist on type 'SourceMapEntry[]'. @@ -10502,9 +10415,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/SourceMapManager.js(141,49): 'string' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint '{}'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMapManager.js(146,44): error TS2345: Argument of type 'string' is not assignable to parameter of type 'K'. 'string' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint '{}'. -node_modules/chrome-devtools-frontend/front_end/sdk/SourceMapManager.js(159,36): error TS2352: Conversion of type 'TextSourceMap' to type '{ compiledURL(): string; url(): string; sourceURLs(): string[]; sourceContentProvider(sourceURL: string, contentType: ResourceType): { contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise<...>; requestContent(): Promise<...>; searchInContent(query: string, caseSensitive: boolean, isRegex: boo...' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. -node_modules/chrome-devtools-frontend/front_end/sdk/SourceMapManager.js(159,36): error TS2352: Conversion of type 'TextSourceMap' to type '{ compiledURL(): string; url(): string; sourceURLs(): string[]; sourceContentProvider(sourceURL: string, contentType: ResourceType): { contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise<...>; requestContent(): Promise<...>; searchInContent(query: string, caseSensitive: boolean, isRegex: boo...' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. - Property '_json' does not exist on type '{ compiledURL(): string; url(): string; sourceURLs(): string[]; sourceContentProvider(sourceURL: string, contentType: ResourceType): { contentURL(): string; contentType(): ResourceType; contentEncoded(): Promise<...>; requestContent(): Promise<...>; searchInContent(query: string, caseSensitive: boolean, isRegex: boo...'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMapManager.js(163,12): error TS2339: Property 'catchException' does not exist on type 'Promise'. node_modules/chrome-devtools-frontend/front_end/sdk/SourceMapManager.js(173,60): error TS2345: Argument of type 'string' is not assignable to parameter of type 'K'. 'string' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint '{}'. @@ -10563,12 +10473,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(329,32): er node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(351,42): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(352,12): error TS2339: Property 'runtimeAgent' does not exist on type 'Target'. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(356,52): error TS2694: Namespace 'Protocol.InspectorBackend.Connection' has no exported member 'Params'. -node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(364,7): error TS2322: Type 'WebSocketConnection' is not assignable to type '{ sendMessage(message: string): void; disconnect(): Promise; }'. - Property '_socket' does not exist on type '{ sendMessage(message: string): void; disconnect(): Promise; }'. -node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(366,7): error TS2322: Type 'StubConnection' is not assignable to type '{ sendMessage(message: string): void; disconnect(): Promise; }'. - Property '_onMessage' does not exist on type '{ sendMessage(message: string): void; disconnect(): Promise; }'. -node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(368,7): error TS2322: Type 'MainConnection' is not assignable to type '{ sendMessage(message: string): void; disconnect(): Promise; }'. - Property '_onMessage' does not exist on type '{ sendMessage(message: string): void; disconnect(): Promise; }'. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(381,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(401,38): error TS2339: Property 'targetAgent' does not exist on type 'Target'. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(406,18): error TS2339: Property 'registerTargetDispatcher' does not exist on type 'Target'. @@ -10580,8 +10484,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(530,24): er node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(552,12): error TS2339: Property 'runtimeAgent' does not exist on type 'Target'. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(581,24): error TS2694: Namespace 'Protocol' has no exported member 'TargetAgent'. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(583,52): error TS2694: Namespace 'Protocol.InspectorBackend.Connection' has no exported member 'Params'. -node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(589,5): error TS2322: Type 'ChildConnection' is not assignable to type '{ sendMessage(message: string): void; disconnect(): Promise; }'. - Property '_agent' does not exist on type '{ sendMessage(message: string): void; disconnect(): Promise; }'. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(598,24): error TS2694: Namespace 'Protocol' has no exported member 'TargetAgent'. node_modules/chrome-devtools-frontend/front_end/sdk/TargetManager.js(600,52): error TS2694: Namespace 'Protocol.InspectorBackend.Connection' has no exported member 'Params'. node_modules/chrome-devtools-frontend/front_end/sdk/TracingManager.js(13,42): error TS2694: Namespace 'SDK.TracingManager' has no exported member 'EventPayload'. @@ -10822,8 +10724,6 @@ node_modules/chrome-devtools-frontend/front_end/snippets/ScriptSnippetModel.js(5 Types of parameters 'debuggerModel' and 'model' are incompatible. Type 'T' is not assignable to type 'DebuggerModel'. node_modules/chrome-devtools-frontend/front_end/snippets/ScriptSnippetModel.js(70,35): error TS2339: Property 'remove' does not exist on type 'Map'. -node_modules/chrome-devtools-frontend/front_end/snippets/ScriptSnippetModel.js(113,5): error TS2322: Type 'SnippetsProject' is not assignable to type '{ workspace(): Workspace; id(): string; type(): string; isServiceProject(): boolean; displayName(): string; requestMetadata(uiSourceCode: UISourceCode): Promise; ... 17 more ...; uiSourceCodes(): UISourceCode[]; }'. - Property '_model' does not exist on type '{ workspace(): Workspace; id(): string; type(): string; isServiceProject(): boolean; displayName(): string; requestMetadata(uiSourceCode: UISourceCode): Promise; ... 17 more ...; uiSourceCodes(): UISourceCode[]; }'. node_modules/chrome-devtools-frontend/front_end/snippets/ScriptSnippetModel.js(146,22): error TS2694: Namespace 'Common' has no exported member 'Event'. node_modules/chrome-devtools-frontend/front_end/snippets/ScriptSnippetModel.js(165,36): error TS2339: Property 'remove' does not exist on type 'Map'. node_modules/chrome-devtools-frontend/front_end/snippets/ScriptSnippetModel.js(172,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. @@ -13496,14 +13396,8 @@ node_modules/chrome-devtools-frontend/front_end/ui/View.js(254,15): error TS2355 node_modules/chrome-devtools-frontend/front_end/ui/View.js(263,1): error TS8022: JSDoc '@extends' is not attached to a class. node_modules/chrome-devtools-frontend/front_end/ui/View.js(267,15): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. node_modules/chrome-devtools-frontend/front_end/ui/View.js(282,15): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. -node_modules/chrome-devtools-frontend/front_end/ui/View.js(299,41): error TS2345: Argument of type 'ProvidedView' is not assignable to parameter of type '{ viewId(): string; title(): string; isCloseable(): boolean; isTransient(): boolean; toolbarItems(): Promise; widget(): Promise; disposeView(): void; }'. - Property '_extension' does not exist on type '{ viewId(): string; title(): string; isCloseable(): boolean; isTransient(): boolean; toolbarItems(): Promise; widget(): Promise; disposeView(): void; }'. node_modules/chrome-devtools-frontend/front_end/ui/View.js(326,21): error TS2339: Property 'showView' does not exist on type '_Location'. node_modules/chrome-devtools-frontend/front_end/ui/View.js(371,23): error TS2339: Property 'showView' does not exist on type '_Location'. -node_modules/chrome-devtools-frontend/front_end/ui/View.js(401,5): error TS2322: Type '_TabbedLocation' is not assignable to type '{ tabbedPane(): TabbedPane; enableMoreTabsButton(): void; }'. - Property '_tabbedPane' does not exist on type '{ tabbedPane(): TabbedPane; enableMoreTabsButton(): void; }'. -node_modules/chrome-devtools-frontend/front_end/ui/View.js(411,5): error TS2322: Type '_StackLocation' is not assignable to type '{ appendApplicableItems(locationName: string): void; appendView(view: { viewId(): string; title(): string; isCloseable(): boolean; isTransient(): boolean; toolbarItems(): Promise; widget(): Promise<...>; disposeView(): void; }, insertBefore?: { ...; }): void; showView(view: { ...; }, insertBefore?: { ...'. - Property '_vbox' does not exist on type '{ appendApplicableItems(locationName: string): void; appendView(view: { viewId(): string; title(): string; isCloseable(): boolean; isTransient(): boolean; toolbarItems(): Promise; widget(): Promise<...>; disposeView(): void; }, insertBefore?: { ...; }): void; showView(view: { ...; }, insertBefore?: { ...'. node_modules/chrome-devtools-frontend/front_end/ui/View.js(440,18): error TS2339: Property 'tabIndex' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/View.js(454,38): error TS2339: Property 'hasFocus' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/View.js(461,44): error TS2769: No overload matches this call. diff --git a/tests/baselines/reference/user/uglify-js.log b/tests/baselines/reference/user/uglify-js.log index a01073ce3a2..78c15c035b5 100644 --- a/tests/baselines/reference/user/uglify-js.log +++ b/tests/baselines/reference/user/uglify-js.log @@ -41,7 +41,7 @@ node_modules/uglify-js/lib/compress.js(3839,12): error TS2339: Property 'push' d node_modules/uglify-js/lib/compress.js(3914,38): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/compress.js(3935,24): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. node_modules/uglify-js/lib/compress.js(3945,28): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(4114,21): error TS2403: Subsequent variable declarations must have the same type. Variable 'defs' must be of type 'Dictionary & { set: (key: any, val: any) => Dictionary & { set: ...; add: (key: any, val: any) => Dictionary & { set: ...; add: ...; get: (key: any) => any; del: (key: any) => Dictionary & { set: ...; ... 8 more ...; toObject: () => any; }; ... 5 more ...; toObject: () => any; }; ... 7 more ...; toObject: () => any;...', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(4114,21): error TS2403: Subsequent variable declarations must have the same type. Variable 'defs' must be of type 'Dictionary & { set: (key: any, val: any) => Dictionary & ...; add: (key: any, val: any) => Dictionary & ...; get: (key: any) => any; del: (key: any) => Dictionary & ...; has: (key: any) => boolean; ... 4 more ...; toObject: () => any; }', but here has type 'any'. node_modules/uglify-js/lib/compress.js(4166,17): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. node_modules/uglify-js/lib/compress.js(4229,45): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/compress.js(4340,33): error TS2554: Expected 0 arguments, but got 1. From 17762c480df52ab4ea49e0a832ba29fbaf57e92c Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 15 Jul 2019 13:41:17 -0700 Subject: [PATCH 22/23] Fall back to (Async)IterableIterator if (Async)Generator not found (#32303) --- src/compiler/checker.ts | 67 ++++++++++++------- .../reference/castOfYield.errors.txt | 4 +- .../generatorReturnTypeFallback.1.symbols | 7 ++ .../generatorReturnTypeFallback.1.types | 9 +++ .../generatorReturnTypeFallback.2.errors.txt | 10 +++ .../generatorReturnTypeFallback.2.symbols | 8 +++ .../generatorReturnTypeFallback.2.types | 10 +++ .../generatorReturnTypeFallback.3.errors.txt | 10 +++ .../generatorReturnTypeFallback.3.symbols | 9 +++ .../generatorReturnTypeFallback.3.types | 11 +++ .../generatorReturnTypeFallback.4.symbols | 9 +++ .../generatorReturnTypeFallback.4.types | 11 +++ .../generatorReturnTypeFallback.5.symbols | 8 +++ .../generatorReturnTypeFallback.5.types | 9 +++ ...romGeneratorMakesRequiredParams.errors.txt | 4 +- ...eStringWithEmbeddedYieldKeyword.errors.txt | 4 +- .../types.forAwait.es2018.3.errors.txt | 4 +- .../generatorReturnTypeFallback.1.ts | 9 +++ .../generatorReturnTypeFallback.2.ts | 10 +++ .../generatorReturnTypeFallback.3.ts | 10 +++ .../generatorReturnTypeFallback.4.ts | 10 +++ .../generatorReturnTypeFallback.5.ts | 9 +++ 22 files changed, 209 insertions(+), 33 deletions(-) create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.1.symbols create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.1.types create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.2.errors.txt create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.2.symbols create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.2.types create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.3.errors.txt create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.3.symbols create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.3.types create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.4.symbols create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.4.types create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.5.symbols create mode 100644 tests/baselines/reference/generatorReturnTypeFallback.5.types create mode 100644 tests/cases/conformance/generators/generatorReturnTypeFallback.1.ts create mode 100644 tests/cases/conformance/generators/generatorReturnTypeFallback.2.ts create mode 100644 tests/cases/conformance/generators/generatorReturnTypeFallback.3.ts create mode 100644 tests/cases/conformance/generators/generatorReturnTypeFallback.4.ts create mode 100644 tests/cases/conformance/generators/generatorReturnTypeFallback.5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5b5ae6b4b24..c31732cc24a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -42,10 +42,10 @@ namespace ts { iterableCacheKey: "iterationTypesOfAsyncIterable" | "iterationTypesOfIterable"; iteratorCacheKey: "iterationTypesOfAsyncIterator" | "iterationTypesOfIterator"; iteratorSymbolName: "asyncIterator" | "iterator"; - getGlobalIteratorType: (reportErrors: boolean) => Type; - getGlobalIterableType: (reportErrors: boolean) => Type; - getGlobalIterableIteratorType: (reportErrors: boolean) => Type; - getGlobalGeneratorType: (reportErrors: boolean) => Type; + getGlobalIteratorType: (reportErrors: boolean) => GenericType; + getGlobalIterableType: (reportErrors: boolean) => GenericType; + getGlobalIterableIteratorType: (reportErrors: boolean) => GenericType; + getGlobalGeneratorType: (reportErrors: boolean) => GenericType; resolveIterationType: (type: Type, errorNode: Node | undefined) => Type | undefined; mustHaveANextMethodDiagnostic: DiagnosticMessage; mustBeAMethodDiagnostic: DiagnosticMessage; @@ -9531,24 +9531,10 @@ namespace ts { return createTypeFromGenericGlobalType(getGlobalTypedPropertyDescriptorType(), [propertyType]); } - function createAsyncGeneratorType(yieldType: Type, returnType: Type, nextType: Type) { - const globalAsyncGeneratorType = getGlobalAsyncGeneratorType(/*reportErrors*/ true); - if (globalAsyncGeneratorType !== emptyGenericType) { - yieldType = getAwaitedType(yieldType) || unknownType; - returnType = getAwaitedType(returnType) || unknownType; - nextType = getAwaitedType(nextType) || unknownType; - } - return createTypeFromGenericGlobalType(globalAsyncGeneratorType, [yieldType, returnType, nextType]); - } - function createIterableType(iteratedType: Type): Type { return createTypeFromGenericGlobalType(getGlobalIterableType(/*reportErrors*/ true), [iteratedType]); } - function createGeneratorType(yieldType: Type, returnType: Type, nextType: Type) { - return createTypeFromGenericGlobalType(getGlobalGeneratorType(/*reportErrors*/ true), [yieldType, returnType, nextType]); - } - function createArrayType(elementType: Type, readonly?: boolean): ObjectType { return createTypeFromGenericGlobalType(readonly ? globalReadonlyArrayType : globalArrayType, [elementType]); } @@ -23401,9 +23387,36 @@ namespace ts { } function createGeneratorReturnType(yieldType: Type, returnType: Type, nextType: Type, isAsyncGenerator: boolean) { - return isAsyncGenerator - ? createAsyncGeneratorType(yieldType, returnType, nextType) - : createGeneratorType(yieldType, returnType, nextType); + const resolver = isAsyncGenerator ? asyncIterationTypesResolver : syncIterationTypesResolver; + const globalGeneratorType = resolver.getGlobalGeneratorType(/*reportErrors*/ false); + yieldType = resolver.resolveIterationType(yieldType, /*errorNode*/ undefined) || unknownType; + returnType = resolver.resolveIterationType(returnType, /*errorNode*/ undefined) || unknownType; + nextType = resolver.resolveIterationType(nextType, /*errorNode*/ undefined) || unknownType; + if (globalGeneratorType === emptyGenericType) { + // Fall back to the global IterableIterator if returnType is assignable to the expected return iteration + // type of IterableIterator, and the expected next iteration type of IterableIterator is assignable to + // nextType. + const globalType = resolver.getGlobalIterableIteratorType(/*reportErrors*/ false); + const iterationTypes = globalType !== emptyGenericType ? getIterationTypesOfGlobalIterableType(globalType, resolver) : undefined; + const iterableIteratorReturnType = iterationTypes ? iterationTypes.returnType : anyType; + const iterableIteratorNextType = iterationTypes ? iterationTypes.nextType : undefinedType; + if (isTypeAssignableTo(returnType, iterableIteratorReturnType) && + isTypeAssignableTo(iterableIteratorNextType, nextType)) { + if (globalType !== emptyGenericType) { + return createTypeFromGenericGlobalType(globalType, [yieldType]); + } + + // The global IterableIterator type doesn't exist, so report an error + resolver.getGlobalIterableIteratorType(/*reportErrors*/ true); + return emptyObjectType; + } + + // The global Generator type doesn't exist, so report an error + resolver.getGlobalGeneratorType(/*reportErrors*/ true); + return emptyObjectType; + } + + return createTypeFromGenericGlobalType(globalGeneratorType, [yieldType, returnType, nextType]); } function checkAndAggregateYieldOperandTypes(func: FunctionLikeDeclaration, checkMode: CheckMode | undefined) { @@ -28240,6 +28253,13 @@ namespace ts { return (type as IterableOrIteratorType)[resolver.iterableCacheKey]; } + function getIterationTypesOfGlobalIterableType(globalType: Type, resolver: IterationTypesResolver) { + const globalIterationTypes = + getIterationTypesOfIterableCached(globalType, resolver) || + getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined); + return globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes; + } + /** * Gets the *yield*, *return*, and *next* types of an `Iterable`-like or `AsyncIterable`-like * type from from common heuristics. @@ -28265,10 +28285,7 @@ namespace ts { // iteration types of their `[Symbol.iterator]()` method. The same is true for their async cousins. // While we define these as `any` and `undefined` in our libs by default, a custom lib *could* use // different definitions. - const globalIterationTypes = - getIterationTypesOfIterableCached(globalType, resolver) || - getIterationTypesOfIterableSlow(globalType, resolver, /*errorNode*/ undefined); - const { returnType, nextType } = globalIterationTypes === noIterationTypes ? defaultIterationTypes : globalIterationTypes; + const { returnType, nextType } = getIterationTypesOfGlobalIterableType(globalType, resolver); return (type as IterableOrIteratorType)[resolver.iterableCacheKey] = createIterationTypes(yieldType, returnType, nextType); } diff --git a/tests/baselines/reference/castOfYield.errors.txt b/tests/baselines/reference/castOfYield.errors.txt index 90725000c90..0d40a4dcd98 100644 --- a/tests/baselines/reference/castOfYield.errors.txt +++ b/tests/baselines/reference/castOfYield.errors.txt @@ -1,8 +1,8 @@ -error TS2318: Cannot find global type 'Generator'. +error TS2318: Cannot find global type 'IterableIterator'. tests/cases/compiler/castOfYield.ts(4,14): error TS1109: Expression expected. -!!! error TS2318: Cannot find global type 'Generator'. +!!! error TS2318: Cannot find global type 'IterableIterator'. ==== tests/cases/compiler/castOfYield.ts (1 errors) ==== function* f() { (yield 0); diff --git a/tests/baselines/reference/generatorReturnTypeFallback.1.symbols b/tests/baselines/reference/generatorReturnTypeFallback.1.symbols new file mode 100644 index 00000000000..9c2b38be4c3 --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.1.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.1.ts === +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +function* f() { +>f : Symbol(f, Decl(generatorReturnTypeFallback.1.ts, 0, 0)) + + yield 1; +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.1.types b/tests/baselines/reference/generatorReturnTypeFallback.1.types new file mode 100644 index 00000000000..8603cb356ca --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.1.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.1.ts === +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +function* f() { +>f : () => IterableIterator + + yield 1; +>yield 1 : any +>1 : 1 +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.2.errors.txt b/tests/baselines/reference/generatorReturnTypeFallback.2.errors.txt new file mode 100644 index 00000000000..9cf7569ef3f --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.2.errors.txt @@ -0,0 +1,10 @@ +error TS2318: Cannot find global type 'IterableIterator'. + + +!!! error TS2318: Cannot find global type 'IterableIterator'. +==== tests/cases/conformance/generators/generatorReturnTypeFallback.2.ts (0 errors) ==== + // Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. + // Report an error if IterableIterator cannot be found. + function* f() { + yield 1; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorReturnTypeFallback.2.symbols b/tests/baselines/reference/generatorReturnTypeFallback.2.symbols new file mode 100644 index 00000000000..5cd344e538c --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.2.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.2.ts === +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +// Report an error if IterableIterator cannot be found. +function* f() { +>f : Symbol(f, Decl(generatorReturnTypeFallback.2.ts, 0, 0)) + + yield 1; +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.2.types b/tests/baselines/reference/generatorReturnTypeFallback.2.types new file mode 100644 index 00000000000..36730010f76 --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.2.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.2.ts === +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +// Report an error if IterableIterator cannot be found. +function* f() { +>f : () => {} + + yield 1; +>yield 1 : any +>1 : 1 +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.3.errors.txt b/tests/baselines/reference/generatorReturnTypeFallback.3.errors.txt new file mode 100644 index 00000000000..a365ba8c6cd --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.3.errors.txt @@ -0,0 +1,10 @@ +error TS2318: Cannot find global type 'Generator'. + + +!!! error TS2318: Cannot find global type 'Generator'. +==== tests/cases/conformance/generators/generatorReturnTypeFallback.3.ts (0 errors) ==== + // Do not allow generators to fallback to IterableIterator while in strictNullChecks mode if they need a type for the sent value. + // NOTE: In non-strictNullChecks mode, `undefined` (the default sent value) is assignable to everything. + function* f() { + const x: string = yield 1; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorReturnTypeFallback.3.symbols b/tests/baselines/reference/generatorReturnTypeFallback.3.symbols new file mode 100644 index 00000000000..17252fab306 --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.3.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.3.ts === +// Do not allow generators to fallback to IterableIterator while in strictNullChecks mode if they need a type for the sent value. +// NOTE: In non-strictNullChecks mode, `undefined` (the default sent value) is assignable to everything. +function* f() { +>f : Symbol(f, Decl(generatorReturnTypeFallback.3.ts, 0, 0)) + + const x: string = yield 1; +>x : Symbol(x, Decl(generatorReturnTypeFallback.3.ts, 3, 9)) +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.3.types b/tests/baselines/reference/generatorReturnTypeFallback.3.types new file mode 100644 index 00000000000..634f3f2277d --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.3.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.3.ts === +// Do not allow generators to fallback to IterableIterator while in strictNullChecks mode if they need a type for the sent value. +// NOTE: In non-strictNullChecks mode, `undefined` (the default sent value) is assignable to everything. +function* f() { +>f : () => {} + + const x: string = yield 1; +>x : string +>yield 1 : any +>1 : 1 +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.4.symbols b/tests/baselines/reference/generatorReturnTypeFallback.4.symbols new file mode 100644 index 00000000000..3be221fffca --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.4.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.4.ts === +// Allow generators to fallback to IterableIterator if they are not in strictNullChecks mode +// NOTE: In non-strictNullChecks mode, `undefined` (the default sent value) is assignable to everything. +function* f() { +>f : Symbol(f, Decl(generatorReturnTypeFallback.4.ts, 0, 0)) + + const x: string = yield 1; +>x : Symbol(x, Decl(generatorReturnTypeFallback.4.ts, 3, 9)) +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.4.types b/tests/baselines/reference/generatorReturnTypeFallback.4.types new file mode 100644 index 00000000000..2879058f37f --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.4.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.4.ts === +// Allow generators to fallback to IterableIterator if they are not in strictNullChecks mode +// NOTE: In non-strictNullChecks mode, `undefined` (the default sent value) is assignable to everything. +function* f() { +>f : () => IterableIterator + + const x: string = yield 1; +>x : string +>yield 1 : any +>1 : 1 +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.5.symbols b/tests/baselines/reference/generatorReturnTypeFallback.5.symbols new file mode 100644 index 00000000000..411ce92a442 --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.5.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.5.ts === +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +function* f(): IterableIterator { +>f : Symbol(f, Decl(generatorReturnTypeFallback.5.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) + + yield 1; +} diff --git a/tests/baselines/reference/generatorReturnTypeFallback.5.types b/tests/baselines/reference/generatorReturnTypeFallback.5.types new file mode 100644 index 00000000000..d0ed4127465 --- /dev/null +++ b/tests/baselines/reference/generatorReturnTypeFallback.5.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/generators/generatorReturnTypeFallback.5.ts === +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +function* f(): IterableIterator { +>f : () => IterableIterator + + yield 1; +>yield 1 : undefined +>1 : 1 +} diff --git a/tests/baselines/reference/spreadOfParamsFromGeneratorMakesRequiredParams.errors.txt b/tests/baselines/reference/spreadOfParamsFromGeneratorMakesRequiredParams.errors.txt index 1b1f93ffc3f..393e21edb6c 100644 --- a/tests/baselines/reference/spreadOfParamsFromGeneratorMakesRequiredParams.errors.txt +++ b/tests/baselines/reference/spreadOfParamsFromGeneratorMakesRequiredParams.errors.txt @@ -1,8 +1,8 @@ -error TS2318: Cannot find global type 'Generator'. +error TS2318: Cannot find global type 'IterableIterator'. tests/cases/compiler/spreadOfParamsFromGeneratorMakesRequiredParams.ts(6,1): error TS2554: Expected 2 arguments, but got 1. -!!! error TS2318: Cannot find global type 'Generator'. +!!! error TS2318: Cannot find global type 'IterableIterator'. ==== tests/cases/compiler/spreadOfParamsFromGeneratorMakesRequiredParams.ts (1 errors) ==== declare function call any>( fn: Fn, diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt index a9699306373..ce0d781d824 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt @@ -1,8 +1,8 @@ -error TS2318: Cannot find global type 'Generator'. +error TS2318: Cannot find global type 'IterableIterator'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,15): error TS1005: '(' expected. -!!! error TS2318: Cannot find global type 'Generator'. +!!! error TS2318: Cannot find global type 'IterableIterator'. ==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts (1 errors) ==== function* gen { ~ diff --git a/tests/baselines/reference/types.forAwait.es2018.3.errors.txt b/tests/baselines/reference/types.forAwait.es2018.3.errors.txt index 1aca869fb0c..296ac0d066b 100644 --- a/tests/baselines/reference/types.forAwait.es2018.3.errors.txt +++ b/tests/baselines/reference/types.forAwait.es2018.3.errors.txt @@ -1,11 +1,11 @@ -error TS2318: Cannot find global type 'AsyncGenerator'. +error TS2318: Cannot find global type 'AsyncIterableIterator'. tests/cases/conformance/types/forAwait/types.forAwait.es2018.3.ts(3,27): error TS2504: Type '{}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. tests/cases/conformance/types/forAwait/types.forAwait.es2018.3.ts(5,21): error TS2504: Type '{}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. tests/cases/conformance/types/forAwait/types.forAwait.es2018.3.ts(10,27): error TS2504: Type '{}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. tests/cases/conformance/types/forAwait/types.forAwait.es2018.3.ts(12,21): error TS2504: Type '{}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. -!!! error TS2318: Cannot find global type 'AsyncGenerator'. +!!! error TS2318: Cannot find global type 'AsyncIterableIterator'. ==== tests/cases/conformance/types/forAwait/types.forAwait.es2018.3.ts (4 errors) ==== async function f1() { let y: number; diff --git a/tests/cases/conformance/generators/generatorReturnTypeFallback.1.ts b/tests/cases/conformance/generators/generatorReturnTypeFallback.1.ts new file mode 100644 index 00000000000..dbf249d7e27 --- /dev/null +++ b/tests/cases/conformance/generators/generatorReturnTypeFallback.1.ts @@ -0,0 +1,9 @@ +// @target: esnext +// @lib: es5,es2015.iterable +// @noemit: true +// @strict: true + +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +function* f() { + yield 1; +} \ No newline at end of file diff --git a/tests/cases/conformance/generators/generatorReturnTypeFallback.2.ts b/tests/cases/conformance/generators/generatorReturnTypeFallback.2.ts new file mode 100644 index 00000000000..4579f05387a --- /dev/null +++ b/tests/cases/conformance/generators/generatorReturnTypeFallback.2.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @lib: es5 +// @noemit: true +// @strict: true + +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +// Report an error if IterableIterator cannot be found. +function* f() { + yield 1; +} \ No newline at end of file diff --git a/tests/cases/conformance/generators/generatorReturnTypeFallback.3.ts b/tests/cases/conformance/generators/generatorReturnTypeFallback.3.ts new file mode 100644 index 00000000000..388d8bee7ee --- /dev/null +++ b/tests/cases/conformance/generators/generatorReturnTypeFallback.3.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @lib: es5,es2015.iterable +// @noemit: true +// @strict: true + +// Do not allow generators to fallback to IterableIterator while in strictNullChecks mode if they need a type for the sent value. +// NOTE: In non-strictNullChecks mode, `undefined` (the default sent value) is assignable to everything. +function* f() { + const x: string = yield 1; +} \ No newline at end of file diff --git a/tests/cases/conformance/generators/generatorReturnTypeFallback.4.ts b/tests/cases/conformance/generators/generatorReturnTypeFallback.4.ts new file mode 100644 index 00000000000..3fc9d4f50c6 --- /dev/null +++ b/tests/cases/conformance/generators/generatorReturnTypeFallback.4.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @lib: es5,es2015.iterable +// @noemit: true +// @strict: false + +// Allow generators to fallback to IterableIterator if they are not in strictNullChecks mode +// NOTE: In non-strictNullChecks mode, `undefined` (the default sent value) is assignable to everything. +function* f() { + const x: string = yield 1; +} \ No newline at end of file diff --git a/tests/cases/conformance/generators/generatorReturnTypeFallback.5.ts b/tests/cases/conformance/generators/generatorReturnTypeFallback.5.ts new file mode 100644 index 00000000000..b495d3ff7b6 --- /dev/null +++ b/tests/cases/conformance/generators/generatorReturnTypeFallback.5.ts @@ -0,0 +1,9 @@ +// @target: esnext +// @lib: es5,es2015.iterable +// @noemit: true +// @strict: true + +// Allow generators to fallback to IterableIterator if they do not need a type for the sent value while in strictNullChecks mode. +function* f(): IterableIterator { + yield 1; +} \ No newline at end of file From 7cdfbceb43e478663cd3263d230fbebf9acb78c1 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 15 Jul 2019 15:17:32 -0700 Subject: [PATCH 23/23] Improve accuracy of remove unnecessary await fix (#32384) --- src/compiler/factory.ts | 2 +- src/services/codefixes/removeUnnecessaryAwait.ts | 16 +++++++++++++--- .../fourslash/codeFixRemoveUnnecessaryAwait.ts | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index f88950f531a..1f0294423a5 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -4701,7 +4701,7 @@ namespace ts { } } - function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) { + export function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) { while (true) { switch (node.kind) { case SyntaxKind.PostfixUnaryExpression: diff --git a/src/services/codefixes/removeUnnecessaryAwait.ts b/src/services/codefixes/removeUnnecessaryAwait.ts index c235d028efb..07028e27937 100644 --- a/src/services/codefixes/removeUnnecessaryAwait.ts +++ b/src/services/codefixes/removeUnnecessaryAwait.ts @@ -26,8 +26,18 @@ namespace ts.codefix { return; } - const parenthesizedExpression = tryCast(awaitExpression.parent, isParenthesizedExpression); - const removeParens = parenthesizedExpression && (isIdentifier(awaitExpression.expression) || isCallExpression(awaitExpression.expression)); - changeTracker.replaceNode(sourceFile, removeParens ? parenthesizedExpression || awaitExpression : awaitExpression, awaitExpression.expression); + let expressionToReplace: Node = awaitExpression; + const hasSurroundingParens = isParenthesizedExpression(awaitExpression.parent); + if (hasSurroundingParens) { + const leftMostExpression = getLeftmostExpression(awaitExpression.expression, /*stopAtCallExpressions*/ false); + if (isIdentifier(leftMostExpression)) { + const precedingToken = findPrecedingToken(awaitExpression.parent.pos, sourceFile); + if (precedingToken && precedingToken.kind !== SyntaxKind.NewKeyword) { + expressionToReplace = awaitExpression.parent; + } + } + } + + changeTracker.replaceNode(sourceFile, expressionToReplace, awaitExpression.expression); } } diff --git a/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts b/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts index b8e1de4605e..3e209cd59f2 100644 --- a/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts +++ b/tests/cases/fourslash/codeFixRemoveUnnecessaryAwait.ts @@ -1,5 +1,6 @@ /// ////declare class C { foo(): void } +////declare function getC(): { Class: C }; ////declare function foo(): string; ////async function f() { //// await ""; @@ -7,6 +8,8 @@ //// (await foo()).toLowerCase(); //// (await 0).toFixed(); //// (await new C).foo(); +//// (await function() { }()); +//// new (await getC()).Class(); ////} verify.codeFix({ @@ -14,6 +17,7 @@ verify.codeFix({ index: 0, newFileContent: `declare class C { foo(): void } +declare function getC(): { Class: C }; declare function foo(): string; async function f() { ""; @@ -21,6 +25,8 @@ async function f() { (await foo()).toLowerCase(); (await 0).toFixed(); (await new C).foo(); + (await function() { }()); + new (await getC()).Class(); }` }); @@ -29,6 +35,7 @@ verify.codeFixAll({ fixId: "removeUnnecessaryAwait", newFileContent: `declare class C { foo(): void } +declare function getC(): { Class: C }; declare function foo(): string; async function f() { ""; @@ -36,5 +43,7 @@ async function f() { foo().toLowerCase(); (0).toFixed(); (new C).foo(); + (function() { } ()); + new (getC()).Class(); }` });