From 6e98431cecdd5304cbd082ed577e0155634cdd24 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 26 May 2020 18:56:53 +0300 Subject: [PATCH 01/15] fix(23716): show generic type in tagged template expression --- src/services/symbolDisplay.ts | 4 +-- ...kInfoForGenericTaggedTemplateExpression.ts | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoForGenericTaggedTemplateExpression.ts diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 11f20195131..e6891bc1225 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -159,14 +159,14 @@ namespace ts.SymbolDisplay { } // try get the call/construct signature from the type if it matches - let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement | undefined; + let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement | TaggedTemplateExpression | undefined; if (isCallOrNewExpression(location)) { callExpressionLike = location; } else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { callExpressionLike = location.parent; } - else if (location.parent && isJsxOpeningLikeElement(location.parent) && isFunctionLike(symbol.valueDeclaration)) { + else if (location.parent && (isJsxOpeningLikeElement(location.parent) || isTaggedTemplateExpression(location.parent)) && isFunctionLike(symbol.valueDeclaration)) { callExpressionLike = location.parent; } diff --git a/tests/cases/fourslash/quickInfoForGenericTaggedTemplateExpression.ts b/tests/cases/fourslash/quickInfoForGenericTaggedTemplateExpression.ts new file mode 100644 index 00000000000..922c9984355 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForGenericTaggedTemplateExpression.ts @@ -0,0 +1,28 @@ +/// + +////interface T1 {} +////class T2 {} +////type T3 = "a" | "b"; +//// +////declare function foo(strings: TemplateStringsArray, ...values: T[]): void; +//// +/////*1*/foo``; +/////*2*/foo``; +/////*3*/foo<{ a: number }>``; +/////*4*/foo``; +/////*5*/foo``; +/////*6*/foo``; +/////*7*/foo``; + +verify.quickInfoAt("1", "function foo(strings: TemplateStringsArray, ...values: number[]): void"); +verify.quickInfoAt("2", "function foo(strings: TemplateStringsArray, ...values: (string | number)[]): void"); +verify.quickInfoAt("3", +`function foo<{ + a: number; +}>(strings: TemplateStringsArray, ...values: { + a: number; +}[]): void`); +verify.quickInfoAt("4", "function foo(strings: TemplateStringsArray, ...values: T1[]): void"); +verify.quickInfoAt("5", "function foo(strings: TemplateStringsArray, ...values: T2[]): void"); +verify.quickInfoAt("6", "function foo(strings: TemplateStringsArray, ...values: T3[]): void"); +verify.quickInfoAt("7", "function foo(strings: TemplateStringsArray, ...values: unknown[]): void"); From 69769ab670ef4cc07c4818fb2e12ba22897c5f1b Mon Sep 17 00:00:00 2001 From: Swapnil Satish Shinde Date: Tue, 26 May 2020 23:04:44 +0530 Subject: [PATCH 02/15] Delete .gitmodules --- .gitmodules | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29bb2d..00000000000 From 9256b85947e4c78ef3ee51e9076ce6fa3c5755f2 Mon Sep 17 00:00:00 2001 From: Ankit Singh Balyan Date: Wed, 27 May 2020 20:51:44 +0200 Subject: [PATCH 03/15] Convert HTML tags in doc-comments into markdown HTML tags in doc-comments don't get parsed properly by tools like TypeDoc, once it encounters an open HTML tag like in the comments, all the subsequent doc-comments become bold in the generated docs. --- src/lib/es2015.core.d.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lib/es2015.core.d.ts b/src/lib/es2015.core.d.ts index 1487891d524..032a7afc0ec 100644 --- a/src/lib/es2015.core.d.ts +++ b/src/lib/es2015.core.d.ts @@ -434,48 +434,48 @@ interface String { startsWith(searchString: string, position?: number): boolean; /** - * Returns an HTML anchor element and sets the name attribute to the text value + * Returns an `` HTML anchor element and sets the name attribute to the text value * @param name */ anchor(name: string): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ big(): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ blink(): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ bold(): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ fixed(): string; - /** Returns a HTML element and sets the color attribute value */ + /** Returns a `` HTML element and sets the color attribute value */ fontcolor(color: string): string; - /** Returns a HTML element and sets the size attribute value */ + /** Returns a `` HTML element and sets the size attribute value */ fontsize(size: number): string; - /** Returns a HTML element and sets the size attribute value */ + /** Returns a `` HTML element and sets the size attribute value */ fontsize(size: string): string; - /** Returns an HTML element */ + /** Returns an `` HTML element */ italics(): string; - /** Returns an HTML element and sets the href attribute value */ + /** Returns an `` HTML element and sets the href attribute value */ link(url: string): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ small(): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ strike(): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ sub(): string; - /** Returns a HTML element */ + /** Returns a `` HTML element */ sup(): string; } From 1507b189c6f28e3f1baedfc5596d8200bef48c7a Mon Sep 17 00:00:00 2001 From: csigs Date: Thu, 28 May 2020 16:10:42 +0000 Subject: [PATCH 04/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl index 3ef0faaabc6..d97c8bb95f7 100644 --- a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -4759,7 +4759,7 @@ - + @@ -5376,6 +5376,12 @@ + + + + + + @@ -12748,7 +12754,7 @@ - + From 8325a0f3eaedf69d120ecdcc0f6e522f23f094cb Mon Sep 17 00:00:00 2001 From: csigs Date: Fri, 29 May 2020 22:10:46 +0000 Subject: [PATCH 05/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl index 951906e5d4b..d937f6fc108 100644 --- a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5373,6 +5373,15 @@ + + + + + + + + + From 8caaf2f01fad2bd92f637a4d767259ee081b91b2 Mon Sep 17 00:00:00 2001 From: csigs Date: Sat, 30 May 2020 04:10:38 +0000 Subject: [PATCH 06/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl index 6b42975c304..f6c3dc0e81b 100644 --- a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5388,6 +5388,15 @@ + + + + + + + + + From 7f98da0837b751e4ca4f46d376c6abe2412842c1 Mon Sep 17 00:00:00 2001 From: csigs Date: Sat, 30 May 2020 10:10:59 +0000 Subject: [PATCH 07/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl index 4cf890368c0..3d92ad9ffd2 100644 --- a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5369,6 +5369,15 @@ + + + + + + + + + From 82f84e5411c6e105a4c101091f5c4a787da091a9 Mon Sep 17 00:00:00 2001 From: csigs Date: Sun, 31 May 2020 04:10:39 +0000 Subject: [PATCH 08/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl index c2237313af1..15bb26e6d67 100644 --- a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5385,6 +5385,15 @@ + + + + + + + + + From cd64b13faf4c6f4a1ad17a964f70a4423b73d661 Mon Sep 17 00:00:00 2001 From: csigs Date: Mon, 1 Jun 2020 04:10:40 +0000 Subject: [PATCH 09/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 467e38f828c..93926ffeeda 100644 --- a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5388,6 +5388,15 @@ + + + + + + + + + From 287cdbf079dc54afb18afe7840f887d870306210 Mon Sep 17 00:00:00 2001 From: csigs Date: Mon, 1 Jun 2020 10:10:57 +0000 Subject: [PATCH 10/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl index d4724951e58..911a8ba9fd0 100644 --- a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5376,6 +5376,15 @@ + + + + + + + + + diff --git a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 0eb0bfd00d1..687c81b165c 100644 --- a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5366,6 +5366,15 @@ + + + + + + + + + From 85cb8e14f431b78eaade5425cfc6a84b3e0af100 Mon Sep 17 00:00:00 2001 From: csigs Date: Mon, 1 Jun 2020 16:10:38 +0000 Subject: [PATCH 11/15] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 3 +++ .../diagnosticMessages.generated.json.lcl | 15 ++++++++++++--- .../diagnosticMessages.generated.json.lcl | 9 +++++++++ .../diagnosticMessages.generated.json.lcl | 9 +++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl index d97c8bb95f7..143e47d395d 100644 --- a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5379,6 +5379,9 @@ + + + diff --git a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 4404dd117eb..96b12537d67 100644 --- a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -3691,7 +3691,7 @@ - + @@ -5376,6 +5376,15 @@ + + + + + + + + + @@ -12091,7 +12100,7 @@ - + @@ -12748,7 +12757,7 @@ - + diff --git a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl index a9c43418c77..414c7377cdf 100644 --- a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5376,6 +5376,15 @@ + + + + + + + + + diff --git a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 98d6bbd7b17..6bbb07d3ba6 100644 --- a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -5369,6 +5369,15 @@ + + + + + + + + + From 68d2ee055c7abd7ae43db50b49a90f1ae4d26897 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 1 Jun 2020 20:27:11 +0300 Subject: [PATCH 12/15] fix(38815): dive in arrow functions to check only this usage instead of checking all statements (#38865) --- src/services/refactors/extractSymbol.ts | 16 +++++++++++++++- tests/cases/fourslash/extract-method40.ts | 23 +++++++++++++++++++++++ tests/cases/fourslash/extract-method41.ts | 20 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/extract-method40.ts create mode 100644 tests/cases/fourslash/extract-method41.ts diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 8c6c8f6fc69..be51d89ed6d 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -405,6 +405,20 @@ namespace ts.refactor.extractSymbol { rangeFacts |= RangeFacts.UsesThis; } break; + case SyntaxKind.ArrowFunction: + // check if arrow function uses this + forEachChild(node, function check(n) { + if (isThis(n)) { + rangeFacts |= RangeFacts.UsesThis; + } + else if (isClassLike(n) || (isFunctionLike(n) && !isArrowFunction(n))) { + return false; + } + else { + forEachChild(n, check); + } + }); + // falls through case SyntaxKind.ClassDeclaration: case SyntaxKind.FunctionDeclaration: if (isSourceFile(node.parent) && node.parent.externalModuleIndicator === undefined) { @@ -418,7 +432,7 @@ namespace ts.refactor.extractSymbol { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - // do not dive into functions (except arrow functions) or classes + // do not dive into functions or classes return false; } diff --git a/tests/cases/fourslash/extract-method40.ts b/tests/cases/fourslash/extract-method40.ts new file mode 100644 index 00000000000..e59c56fe352 --- /dev/null +++ b/tests/cases/fourslash/extract-method40.ts @@ -0,0 +1,23 @@ +/// + +////const foo = /*start*/{ +//// a: 1, +//// b: () => { return 1; } +////}/*end*/ + +goTo.select("start", "end"); +edit.applyRefactor({ + refactorName: "Extract Symbol", + actionName: "function_scope_0", + actionDescription: "Extract to function in global scope", + newContent: +`const foo = /*RENAME*/newFunction() + +function newFunction() { + return { + a: 1, + b: () => { return 1; } + }; +} +` +}); diff --git a/tests/cases/fourslash/extract-method41.ts b/tests/cases/fourslash/extract-method41.ts new file mode 100644 index 00000000000..d90ee90eeac --- /dev/null +++ b/tests/cases/fourslash/extract-method41.ts @@ -0,0 +1,20 @@ +/// + +////function bar(fn: () => void) {} +//// +////class Foo { +//// x: number; +//// foo() { +//// /*start*/bar(() => { +//// () => { +//// () => { +//// this.x; +//// } +//// } +//// });/*end*/ +//// } +////} + +goTo.select("start", "end"); +verify.refactorAvailable("Extract Symbol", "function_scope_1"); +verify.not.refactorAvailable("Extract Symbol", "function_scope_2"); From fa49ac0b78047fb89f0c99bbc29a3d46f8ab1549 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 1 Jun 2020 20:30:52 +0300 Subject: [PATCH 13/15] fix(19385): add space after brace in the multiline string template (#38742) --- src/services/formatting/rules.ts | 8 ++- ...formatNoSpaceAfterTemplateHeadAndMiddle.ts | 52 +++++++++++++++++++ .../formatSpaceAfterTemplateHeadAndMiddle.ts | 52 +++++++++++++++++++ 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/formatNoSpaceAfterTemplateHeadAndMiddle.ts create mode 100644 tests/cases/fourslash/formatSpaceAfterTemplateHeadAndMiddle.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 4d6eb8f7a99..1f84b04e531 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -279,9 +279,9 @@ namespace ts.formatting { rule("NoSpaceBetweenEmptyBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isOptionDisabled("insertSpaceAfterOpeningAndBeforeClosingEmptyBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), // Insert space after opening and before closing template string braces - rule("SpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.InsertSpace), + rule("SpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxTextContext], RuleAction.InsertSpace, RuleFlags.CanDeleteNewLines), rule("SpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.InsertSpace), - rule("NoSpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), + rule("NoSpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxTextContext], RuleAction.DeleteSpace, RuleFlags.CanDeleteNewLines), rule("NoSpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), // No space after { and before } in JSX expression @@ -690,6 +690,10 @@ namespace ts.formatting { return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText; } + function isNonJsxTextContext(context: FormattingContext): boolean { + return context.contextNode.kind !== SyntaxKind.JsxText; + } + function isNonJsxElementOrFragmentContext(context: FormattingContext): boolean { return context.contextNode.kind !== SyntaxKind.JsxElement && context.contextNode.kind !== SyntaxKind.JsxFragment; } diff --git a/tests/cases/fourslash/formatNoSpaceAfterTemplateHeadAndMiddle.ts b/tests/cases/fourslash/formatNoSpaceAfterTemplateHeadAndMiddle.ts new file mode 100644 index 00000000000..4c4758917ad --- /dev/null +++ b/tests/cases/fourslash/formatNoSpaceAfterTemplateHeadAndMiddle.ts @@ -0,0 +1,52 @@ +/// + +////const a1 = `${ 1 }${ 1 }`; +////const a2 = ` +//// ${ 1 }${ 1 } +////`; +////const a3 = ` +//// +//// +//// ${ 1 }${ 1 } +////`; +////const a4 = ` +//// +//// ${ 1 }${ 1 } +//// +////`; +////const a5 = `text ${ 1 } text ${ 1 } text`; +////const a6 = ` +//// text ${ 1 } +//// text ${ 1 } +//// text +////`; + +format.setOption("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", false); +format.document(); +verify.currentFileContentIs( + "const a1 = `${1}${1}`;\n" + + + "const a2 = `\n" + + " ${1}${1}\n" + + "`;\n" + + + "const a3 = `\n" + + "\n" + + "\n" + + " ${1}${1}\n" + + "`;\n" + + + "const a4 = `\n" + + "\n" + + " ${1}${1}\n" + + "\n" + + "`;\n" + + + "const a5 = `text ${1} text ${1} text`;\n" + + + "const a6 = `\n" + + " text ${1}\n" + + " text ${1}\n" + + " text\n" + + "`;" +); diff --git a/tests/cases/fourslash/formatSpaceAfterTemplateHeadAndMiddle.ts b/tests/cases/fourslash/formatSpaceAfterTemplateHeadAndMiddle.ts new file mode 100644 index 00000000000..b75c4f59623 --- /dev/null +++ b/tests/cases/fourslash/formatSpaceAfterTemplateHeadAndMiddle.ts @@ -0,0 +1,52 @@ +/// + +////const a1 = `${1}${1}`; +////const a2 = ` +//// ${1}${1} +////`; +////const a3 = ` +//// +//// +//// ${1}${1} +////`; +////const a4 = ` +//// +//// ${1}${1} +//// +////`; +////const a5 = `text ${1} text ${1} text`; +////const a6 = ` +//// text ${1} +//// text ${1} +//// text +////`; + +format.setOption("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", true); +format.document(); +verify.currentFileContentIs( + "const a1 = `${ 1 }${ 1 }`;\n" + + + "const a2 = `\n" + + " ${ 1 }${ 1 }\n" + + "`;\n" + + + "const a3 = `\n" + + "\n" + + "\n" + + " ${ 1 }${ 1 }\n" + + "`;\n" + + + "const a4 = `\n" + + "\n" + + " ${ 1 }${ 1 }\n" + + "\n" + + "`;\n" + + + "const a5 = `text ${ 1 } text ${ 1 } text`;\n" + + + "const a6 = `\n" + + " text ${ 1 }\n" + + " text ${ 1 }\n" + + " text\n" + + "`;" +); From 4f0b81d415146329fd705e4517e8100bf3c9e061 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 1 Jun 2020 21:45:05 +0300 Subject: [PATCH 14/15] fix(32341): add prefix name for module exports properties (#38541) --- src/services/findAllReferences.ts | 37 ++++++++++++++----- .../renameModuleExportsProperties1.ts | 8 ++++ .../renameModuleExportsProperties2.ts | 8 ++++ .../renameModuleExportsProperties3.ts | 10 +++++ 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 tests/cases/fourslash/renameModuleExportsProperties1.ts create mode 100644 tests/cases/fourslash/renameModuleExportsProperties2.ts create mode 100644 tests/cases/fourslash/renameModuleExportsProperties3.ts diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 74dffc3b00b..05d85fb7087 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -399,23 +399,40 @@ namespace ts.FindAllReferences { function getPrefixAndSuffixText(entry: Entry, originalNode: Node, checker: TypeChecker): PrefixAndSuffix { if (entry.kind !== EntryKind.Span && isIdentifier(originalNode)) { const { node, kind } = entry; + const parent = node.parent; const name = originalNode.text; - const isShorthandAssignment = isShorthandPropertyAssignment(node.parent); - if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(node.parent) && node.parent.name === node) { + const isShorthandAssignment = isShorthandPropertyAssignment(parent); + if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(parent) && parent.name === node) { const prefixColon: PrefixAndSuffix = { prefixText: name + ": " }; const suffixColon: PrefixAndSuffix = { suffixText: ": " + name }; - return kind === EntryKind.SearchedLocalFoundProperty ? prefixColon - : kind === EntryKind.SearchedPropertyFoundLocal ? suffixColon - // In `const o = { x }; o.x`, symbolAtLocation at `x` in `{ x }` is the property symbol. - // For a binding element `const { x } = o;`, symbolAtLocation at `x` is the property symbol. - : isShorthandAssignment ? suffixColon : prefixColon; + if (kind === EntryKind.SearchedLocalFoundProperty) { + return prefixColon; + } + if (kind === EntryKind.SearchedPropertyFoundLocal) { + return suffixColon; + } + + // In `const o = { x }; o.x`, symbolAtLocation at `x` in `{ x }` is the property symbol. + // For a binding element `const { x } = o;`, symbolAtLocation at `x` is the property symbol. + if (isShorthandAssignment) { + const grandParent = parent.parent; + if (isObjectLiteralExpression(grandParent) && + isBinaryExpression(grandParent.parent) && + isModuleExportsAccessExpression(grandParent.parent.left)) { + return prefixColon; + } + return suffixColon; + } + else { + return prefixColon; + } } - else if (isImportSpecifier(entry.node.parent) && !entry.node.parent.propertyName) { + else if (isImportSpecifier(parent) && !parent.propertyName) { // If the original symbol was using this alias, just rename the alias. const originalSymbol = isExportSpecifier(originalNode.parent) ? checker.getExportSpecifierLocalTargetSymbol(originalNode.parent) : checker.getSymbolAtLocation(originalNode); - return contains(originalSymbol!.declarations, entry.node.parent) ? { prefixText: name + " as " } : emptyOptions; + return contains(originalSymbol!.declarations, parent) ? { prefixText: name + " as " } : emptyOptions; } - else if (isExportSpecifier(entry.node.parent) && !entry.node.parent.propertyName) { + else if (isExportSpecifier(parent) && !parent.propertyName) { // If the symbol for the node is same as declared node symbol use prefix text return originalNode === entry.node || checker.getSymbolAtLocation(originalNode) === checker.getSymbolAtLocation(entry.node) ? { prefixText: name + " as " } : diff --git a/tests/cases/fourslash/renameModuleExportsProperties1.ts b/tests/cases/fourslash/renameModuleExportsProperties1.ts new file mode 100644 index 00000000000..29d74bde6cb --- /dev/null +++ b/tests/cases/fourslash/renameModuleExportsProperties1.ts @@ -0,0 +1,8 @@ +/// + +////[|class [|{| "contextRangeIndex": 0 |}A|] {}|] +////module.exports = { [|A|] } + +const [r0Def, r0, r1] = test.ranges(); +verify.renameLocations(r0, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true }); +verify.renameLocations(r1, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true }); diff --git a/tests/cases/fourslash/renameModuleExportsProperties2.ts b/tests/cases/fourslash/renameModuleExportsProperties2.ts new file mode 100644 index 00000000000..fa2c31029e6 --- /dev/null +++ b/tests/cases/fourslash/renameModuleExportsProperties2.ts @@ -0,0 +1,8 @@ +/// + +////[|class [|{| "contextRangeIndex": 0 |}A|] {}|] +////module.exports = { B: [|A|] } + +const [r0Def, r0, r1] = test.ranges(); +verify.renameLocations(r0, [r0, r1]); +verify.renameLocations(r1, [r0, r1]); diff --git a/tests/cases/fourslash/renameModuleExportsProperties3.ts b/tests/cases/fourslash/renameModuleExportsProperties3.ts new file mode 100644 index 00000000000..2f163c55f0f --- /dev/null +++ b/tests/cases/fourslash/renameModuleExportsProperties3.ts @@ -0,0 +1,10 @@ +/// + +// @allowJs: true +// @Filename: a.js +////[|class [|{| "contextRangeIndex": 0 |}A|] {}|] +////module.exports = { [|A|] } + +const [r0Def, r0, r1] = test.ranges(); +verify.renameLocations(r0, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true }); +verify.renameLocations(r1, { ranges: [r0, { range: r1, prefixText: "A: " }], providePrefixAndSuffixTextForRename: true }); From 8e290e5aaeec9b3ec90accaf73e1020243be77bc Mon Sep 17 00:00:00 2001 From: Jack Works Date: Tue, 2 Jun 2020 03:22:44 +0800 Subject: [PATCH 15/15] Improve error range for ts2657 (jsx expr must have parent element), add code fix for it (#37917) * fix: range of ts2657 (jsx expr must have parent) and remove 2695 (LHS expr of comma has no side effects) * feat: add code fix for 2657 * fix: resolve review * chore: hoist a var * chore: add test for skipTrivia * fix: rebase error * Update src/compiler/diagnosticMessages.json Co-authored-by: Andrew Branch * Update src/services/codefixes/wrapJsxInFragment.ts Co-authored-by: Andrew Branch Co-authored-by: Andrew Branch Co-authored-by: Andrew Branch --- src/compiler/checker.ts | 9 ++- src/compiler/diagnosticMessages.json | 8 +++ src/compiler/parser.ts | 7 +- src/services/codefixes/wrapJsxInFragment.ts | 71 +++++++++++++++++++ src/services/tsconfig.json | 1 + .../jsxEsprimaFbTestSuite.errors.txt | 12 ++-- .../jsxInvalidEsprimaTestSuite.errors.txt | 27 +++---- .../reference/jsxInvalidEsprimaTestSuite.js | 4 +- .../jsxInvalidEsprimaTestSuite.symbols | 2 +- .../jsxInvalidEsprimaTestSuite.types | 2 +- .../reference/tsxErrorRecovery2.errors.txt | 23 +++--- .../reference/tsxErrorRecovery3.errors.txt | 23 +++--- .../reference/tsxFragmentErrors.errors.txt | 7 +- .../jsx/jsxInvalidEsprimaTestSuite.tsx | 2 +- .../fourslash/codeFixWrapJsxInFragment.ts | 7 ++ .../fourslash/codeFixWrapJsxInFragment2.ts | 7 ++ 16 files changed, 152 insertions(+), 60 deletions(-) create mode 100644 src/services/codefixes/wrapJsxInFragment.ts create mode 100644 tests/cases/fourslash/codeFixWrapJsxInFragment.ts create mode 100644 tests/cases/fourslash/codeFixWrapJsxInFragment2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4ed83e41eb5..cf13225e2b5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -28769,7 +28769,14 @@ namespace ts { } case SyntaxKind.CommaToken: if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right)) { - error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects); + const sf = getSourceFileOfNode(left); + const sourceText = sf.text; + const start = skipTrivia(sourceText, left.pos); + const isInDiag2657 = sf.parseDiagnostics.some(diag => { + if (diag.code !== Diagnostics.JSX_expressions_must_have_one_parent_element.code) return false; + return textSpanContainsPosition(diag, start); + }); + if (!isInDiag2657) error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects); } return rightType; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5c050494e36..be27a8ecc1c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5709,6 +5709,14 @@ "category": "Message", "code": 95119 }, + "Wrap in JSX fragment": { + "category": "Message", + "code": 95120 + }, + "Wrap all unparented JSX in JSX fragment": { + "category": "Message", + "code": 95121 + }, "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9754cdf64d3..e886c9e5477 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4503,7 +4503,7 @@ namespace ts { return finishNode(node); } - function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean): JsxElement | JsxSelfClosingElement | JsxFragment { + function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number): JsxElement | JsxSelfClosingElement | JsxFragment { const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext); let result: JsxElement | JsxSelfClosingElement | JsxFragment; if (opening.kind === SyntaxKind.JsxOpeningElement) { @@ -4541,15 +4541,16 @@ namespace ts { // Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios // of one sort or another. if (inExpressionContext && token() === SyntaxKind.LessThanToken) { - const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true)); + const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition; + const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos)); if (invalidElement) { - parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element); const badNode = createNode(SyntaxKind.BinaryExpression, result.pos); badNode.end = invalidElement.end; badNode.left = result; badNode.right = invalidElement; badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false); badNode.operatorToken.pos = badNode.operatorToken.end = badNode.right.pos; + parseErrorAt(skipTrivia(sourceText, topBadPos), invalidElement.end, Diagnostics.JSX_expressions_must_have_one_parent_element); return badNode; } } diff --git a/src/services/codefixes/wrapJsxInFragment.ts b/src/services/codefixes/wrapJsxInFragment.ts new file mode 100644 index 00000000000..243bbf778da --- /dev/null +++ b/src/services/codefixes/wrapJsxInFragment.ts @@ -0,0 +1,71 @@ +/* @internal */ +namespace ts.codefix { + const fixID = "wrapJsxInFragment"; + const errorCodes = [Diagnostics.JSX_expressions_must_have_one_parent_element.code]; + registerCodeFix({ + errorCodes, + getCodeActions: context => { + const { jsx } = context.program.getCompilerOptions(); + if (jsx !== JsxEmit.React && jsx !== JsxEmit.ReactNative) { + return undefined; + } + const { sourceFile, span } = context; + const node = findNodeToFix(sourceFile, span.start); + if (!node) return undefined; + const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, node)); + return [createCodeFixAction(fixID, changes, Diagnostics.Wrap_in_JSX_fragment, fixID, Diagnostics.Wrap_all_unparented_JSX_in_JSX_fragment)]; + }, + fixIds: [fixID], + getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => { + const node = findNodeToFix(context.sourceFile, diag.start); + if (!node) return undefined; + doChange(changes, context.sourceFile, node); + }), + }); + + function findNodeToFix(sourceFile: SourceFile, pos: number): BinaryExpression | undefined { + // The error always at 1st token that is "<" in "" + const lessThanToken = getTokenAtPosition(sourceFile, pos); + const firstJsxElementOrOpenElement = lessThanToken.parent; + let binaryExpr = firstJsxElementOrOpenElement.parent; + if (!isBinaryExpression(binaryExpr)) { + // In case the start element is a JsxSelfClosingElement, it the end. + // For JsxOpenElement, find one more parent + binaryExpr = binaryExpr.parent; + if (!isBinaryExpression(binaryExpr)) return undefined; + } + if (!nodeIsMissing(binaryExpr.operatorToken)) return undefined; + return binaryExpr; + } + + function doChange(changeTracker: textChanges.ChangeTracker, sf: SourceFile, node: Node) { + const jsx = flattenInvalidBinaryExpr(node); + if (jsx) changeTracker.replaceNode(sf, node, createJsxFragment(createJsxOpeningFragment(), jsx, createJsxJsxClosingFragment())); + } + // The invalid syntax is constructed as + // InvalidJsxTree :: One of + // JsxElement CommaToken InvalidJsxTree + // JsxElement CommaToken JsxElement + function flattenInvalidBinaryExpr(node: Node): JsxChild[] | undefined { + const children: JsxChild[] = []; + let current = node; + while (true) { + if (isBinaryExpression(current) && nodeIsMissing(current.operatorToken) && current.operatorToken.kind === SyntaxKind.CommaToken) { + children.push(current.left); + if (isJsxChild(current.right)) { + children.push(current.right); + // Indicates the tree has go to the bottom + return children; + } + else if (isBinaryExpression(current.right)) { + current = current.right; + continue; + } + // Unreachable case + else return undefined; + } + // Unreachable case + else return undefined; + } + } +} diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index afa2e93c8d1..dafc056d338 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -97,6 +97,7 @@ "codefixes/useDefaultImport.ts", "codefixes/useBigintLiteral.ts", "codefixes/fixAddModuleReferTypeMissingTypeof.ts", + "codefixes/wrapJsxInFragment.ts", "codefixes/convertToMappedObjectType.ts", "codefixes/removeUnnecessaryAwait.ts", "codefixes/splitTypeOnlyImport.ts", diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt b/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt index 91f3e22962c..c9e4aeb457c 100644 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt +++ b/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,1): error TS2695: Left side of comma operator is unused and has no side effects. +tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,1): error TS2657: JSX expressions must have one parent element. tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,17): error TS1005: '{' expected. +tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS1005: ';' expected. tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS2304: Cannot find name 'right'. -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS2657: JSX expressions must have one parent element. tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,41): error TS1382: Unexpected token. Did you mean `{'>'}` or `>`? tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,57): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,58): error TS1109: Expression expected. @@ -47,14 +47,14 @@ tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,58): error TS1109: Expr

7x invalid-js-identifier
; right=monkeys /> gorillas />; - ~~~~~~~~~~~~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2657: JSX expressions must have one parent element. ~ !!! error TS1005: '{' expected. ~~~~~ -!!! error TS2304: Cannot find name 'right'. +!!! error TS1005: ';' expected. ~~~~~ -!!! error TS2657: JSX expressions must have one parent element. +!!! error TS2304: Cannot find name 'right'. ~ !!! error TS1382: Unexpected token. Did you mean `{'>'}` or `>`? ~ diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt index 1195ff4457e..a7deeac2aaa 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt @@ -33,10 +33,8 @@ tests/cases/conformance/jsx/16.tsx(1,2): error TS17008: JSX element 'a' has no c tests/cases/conformance/jsx/16.tsx(1,10): error TS1005: 'one
two
;; - ~~~~~~~~~~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. - ~ +==== tests/cases/conformance/jsx/18.tsx (1 errors) ==== + var x = /* Leading trivia */
one
two
;; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2657: JSX expressions must have one parent element. -==== tests/cases/conformance/jsx/19.tsx (2 errors) ==== +==== tests/cases/conformance/jsx/19.tsx (1 errors) ==== var x =
one
/* intervening comment */
two
;; - ~~~~~~~~~~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. - ~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2657: JSX expressions must have one parent element. ==== tests/cases/conformance/jsx/20.tsx (2 errors) ====
{"str";}; @@ -313,14 +307,15 @@ tests/cases/conformance/jsx/9.tsx(1,16): error TS1109: Expression expected. !!! error TS1005: '; - ~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. + ~~~~~~~~~ ~ !!! error TS1005: '{' expected. ~ !!! error TS1003: Identifier expected. +!!! error TS2657: JSX expressions must have one parent element. + !!! error TS1005: '}; diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js index b04a03079b7..fb128b51e4c 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js @@ -37,7 +37,7 @@ declare var React: any; //// [17.tsx] ; //// [18.tsx] -var x =
one
two
;; +var x = /* Leading trivia */
one
two
;; //// [19.tsx] var x =
one
/* intervening comment */
two
;; //// [20.tsx] @@ -117,7 +117,7 @@ a['foo'] > ; //// [17.jsx]
;; //// [18.jsx] -var x =
one
,
two
; +var x = /* Leading trivia */
one
,
two
; ; //// [19.jsx] var x =
one
/* intervening comment */, /* intervening comment */
two
; diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.symbols b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.symbols index 7be7925fa39..3e029e49c79 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.symbols +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.symbols @@ -50,7 +50,7 @@ No type information for this code.=== tests/cases/conformance/jsx/17.tsx === >b : Symbol(b, Decl(17.tsx, 0, 2)) === tests/cases/conformance/jsx/18.tsx === -var x =
one
two
;; +var x = /* Leading trivia */
one
two
;; >x : Symbol(x, Decl(18.tsx, 0, 3), Decl(19.tsx, 0, 3)) === tests/cases/conformance/jsx/19.tsx === diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types index adb7f6b7271..3b7ca699c8c 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types @@ -159,7 +159,7 @@ declare var React: any; > : any === tests/cases/conformance/jsx/18.tsx === -var x =
one
two
;; +var x = /* Leading trivia */
one
two
;; >x : any >
one
two
: any >
one
: any diff --git a/tests/baselines/reference/tsxErrorRecovery2.errors.txt b/tests/baselines/reference/tsxErrorRecovery2.errors.txt index b1c75964467..c64f09af9ef 100644 --- a/tests/baselines/reference/tsxErrorRecovery2.errors.txt +++ b/tests/baselines/reference/tsxErrorRecovery2.errors.txt @@ -1,23 +1,18 @@ -tests/cases/conformance/jsx/file1.tsx(3,1): error TS2695: Left side of comma operator is unused and has no side effects. -tests/cases/conformance/jsx/file1.tsx(5,1): error TS2657: JSX expressions must have one parent element. -tests/cases/conformance/jsx/file2.tsx(1,9): error TS2695: Left side of comma operator is unused and has no side effects. -tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element. +tests/cases/conformance/jsx/file1.tsx(3,1): error TS2657: JSX expressions must have one parent element. +tests/cases/conformance/jsx/file2.tsx(1,9): error TS2657: JSX expressions must have one parent element. -==== tests/cases/conformance/jsx/file1.tsx (2 errors) ==== +==== tests/cases/conformance/jsx/file1.tsx (1 errors) ==== declare namespace JSX { interface Element { } }
~~~~~~~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects.
- - + ~~~~~~~~~~~ !!! error TS2657: JSX expressions must have one parent element. -==== tests/cases/conformance/jsx/file2.tsx (2 errors) ==== + +==== tests/cases/conformance/jsx/file2.tsx (1 errors) ==== var x =
- ~~~~~~~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. - - -!!! error TS2657: JSX expressions must have one parent element. \ No newline at end of file + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2657: JSX expressions must have one parent element. + \ No newline at end of file diff --git a/tests/baselines/reference/tsxErrorRecovery3.errors.txt b/tests/baselines/reference/tsxErrorRecovery3.errors.txt index 2ee6b582cd3..12d562599e8 100644 --- a/tests/baselines/reference/tsxErrorRecovery3.errors.txt +++ b/tests/baselines/reference/tsxErrorRecovery3.errors.txt @@ -1,35 +1,30 @@ -tests/cases/conformance/jsx/file1.tsx(3,1): error TS2695: Left side of comma operator is unused and has no side effects. +tests/cases/conformance/jsx/file1.tsx(3,1): error TS2657: JSX expressions must have one parent element. tests/cases/conformance/jsx/file1.tsx(3,2): error TS2304: Cannot find name 'React'. tests/cases/conformance/jsx/file1.tsx(4,2): error TS2304: Cannot find name 'React'. -tests/cases/conformance/jsx/file1.tsx(5,1): error TS2657: JSX expressions must have one parent element. -tests/cases/conformance/jsx/file2.tsx(1,9): error TS2695: Left side of comma operator is unused and has no side effects. +tests/cases/conformance/jsx/file2.tsx(1,9): error TS2657: JSX expressions must have one parent element. tests/cases/conformance/jsx/file2.tsx(1,10): error TS2304: Cannot find name 'React'. tests/cases/conformance/jsx/file2.tsx(1,21): error TS2304: Cannot find name 'React'. -tests/cases/conformance/jsx/file2.tsx(2,1): error TS2657: JSX expressions must have one parent element. -==== tests/cases/conformance/jsx/file1.tsx (4 errors) ==== +==== tests/cases/conformance/jsx/file1.tsx (3 errors) ==== declare namespace JSX { interface Element { } }
~~~~~~~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. ~~~ !!! error TS2304: Cannot find name 'React'.
+ ~~~~~~~~~~~ +!!! error TS2657: JSX expressions must have one parent element. ~~~ !!! error TS2304: Cannot find name 'React'. - -!!! error TS2657: JSX expressions must have one parent element. -==== tests/cases/conformance/jsx/file2.tsx (4 errors) ==== +==== tests/cases/conformance/jsx/file2.tsx (3 errors) ==== var x =
- ~~~~~~~~~~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2657: JSX expressions must have one parent element. ~~~ !!! error TS2304: Cannot find name 'React'. ~~~ !!! error TS2304: Cannot find name 'React'. - - -!!! error TS2657: JSX expressions must have one parent element. \ No newline at end of file + \ No newline at end of file diff --git a/tests/baselines/reference/tsxFragmentErrors.errors.txt b/tests/baselines/reference/tsxFragmentErrors.errors.txt index 03397452abc..46d8a0c09b7 100644 --- a/tests/baselines/reference/tsxFragmentErrors.errors.txt +++ b/tests/baselines/reference/tsxFragmentErrors.errors.txt @@ -1,9 +1,10 @@ +tests/cases/conformance/jsx/file.tsx(9,1): error TS2657: JSX expressions must have one parent element. tests/cases/conformance/jsx/file.tsx(9,7): error TS17015: Expected corresponding closing tag for JSX fragment. tests/cases/conformance/jsx/file.tsx(9,11): error TS17014: JSX fragment has no corresponding closing tag. tests/cases/conformance/jsx/file.tsx(11,17): error TS1005: 'hi // Error + ~~~~~~~~~~~~~~~~~~~ ~~~ !!! error TS17015: Expected corresponding closing tag for JSX fragment. ~~~~~~~~~ + <>eof // Error + ~~~~~~~~~~~~~~~~ +!!! error TS2657: JSX expressions must have one parent element. ~~ !!! error TS17014: JSX fragment has no corresponding closing tag. diff --git a/tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx b/tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx index 599efc358fc..5164dc1ce55 100644 --- a/tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx +++ b/tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx @@ -36,7 +36,7 @@ declare var React: any; // @filename: 17.tsx
; // @filename: 18.tsx -var x =
one
two
;; +var x = /* Leading trivia */
one
two
;; // @filename: 19.tsx var x =
one
/* intervening comment */
two
;; // @filename: 20.tsx diff --git a/tests/cases/fourslash/codeFixWrapJsxInFragment.ts b/tests/cases/fourslash/codeFixWrapJsxInFragment.ts new file mode 100644 index 00000000000..10acf5916b7 --- /dev/null +++ b/tests/cases/fourslash/codeFixWrapJsxInFragment.ts @@ -0,0 +1,7 @@ +/// + +// @jsx: react +// @Filename: /a.tsx +////[|
|] + +verify.rangeAfterCodeFix(`<>`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0); diff --git a/tests/cases/fourslash/codeFixWrapJsxInFragment2.ts b/tests/cases/fourslash/codeFixWrapJsxInFragment2.ts new file mode 100644 index 00000000000..229f554c801 --- /dev/null +++ b/tests/cases/fourslash/codeFixWrapJsxInFragment2.ts @@ -0,0 +1,7 @@ +/// + +// @jsx: react +// @Filename: /a.tsx +////[||] + +verify.rangeAfterCodeFix(`<>`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);