From 9dfcb4419ca52efce7321ef08e88a1c4c0491c93 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 25 Jun 2016 19:23:46 +0900 Subject: [PATCH 01/10] do not format comma/closeparen in jsxelement --- src/services/formatting/rules.ts | 10 ++++--- .../cases/fourslash/formattingJsxElements.ts | 26 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index b4916025af2aa..5fb6b330b42ea 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -316,7 +316,7 @@ namespace ts.formatting { // Add a space between statements. All keywords except (do,else,case) has open/close parens after them. // So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any] - this.SpaceBetweenStatements = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNotForContext), RuleAction.Space)); + this.SpaceBetweenStatements = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext, Rules.IsNotForContext), RuleAction.Space)); // This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter. this.SpaceAfterTryFinally = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword]), SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space)); @@ -444,8 +444,8 @@ namespace ts.formatting { /// // Insert space after comma delimiter - this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space)); - this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete)); + this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space)); + this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext), RuleAction.Delete)); // Insert space before and after binary operators this.SpaceBeforeBinaryOperator = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.BinaryOperators), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), RuleAction.Space)); @@ -723,6 +723,10 @@ namespace ts.formatting { return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText; } + static isNonJsxElementContext(context: FormattingContext): boolean { + return context.contextNode.kind !== SyntaxKind.JsxElement; + } + static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean { return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context); } diff --git a/tests/cases/fourslash/formattingJsxElements.ts b/tests/cases/fourslash/formattingJsxElements.ts index fbe4bb5d29ed4..50e9bb8ea8fc6 100644 --- a/tests/cases/fourslash/formattingJsxElements.ts +++ b/tests/cases/fourslash/formattingJsxElements.ts @@ -9,7 +9,7 @@ //// //// ) ////} -//// +//// ////function foo1() { //// return ( ////
@@ -45,8 +45,8 @@ //// class3= {/*5*/ //// }/>/*6*/ //// ) -////} -//// +////} +//// ////(function () { //// return
/*grandchildJsxElementAutoformat*/ /////*containedClosingTagAutoformat*/ -//// +////; +//// +////
,{integer}
;/*commaInJsxElement*/ +////
, {integer}
;/*commaInJsxElement2*/ +////);/*closingParenInJsxElement*/ +////) ;/*closingParenInJsxElement2*/ format.document(); goTo.marker("autoformat"); @@ -114,7 +119,7 @@ verify.indentationIs(12); goTo.marker("danglingBracketAutoformat") // TODO: verify.currentLineContentIs(" >"); -verify.currentLineContentIs(" >"); +verify.currentLineContentIs(" >"); goTo.marker("closingTagAutoformat"); verify.currentLineContentIs("
"); @@ -125,4 +130,13 @@ verify.indentationIs(8); goTo.marker("grandchildJsxElementAutoformat"); verify.currentLineContentIs(" "); goTo.marker("containedClosingTagAutoformat"); -verify.currentLineContentIs(" "); \ No newline at end of file +verify.currentLineContentIs(" "); + +goTo.marker("commaInJsxElement"); +verify.currentLineContentIs("
,{integer}
;"); +goTo.marker("commaInJsxElement2"); +verify.currentLineContentIs("
, {integer}
;"); +goTo.marker("closingParenInJsxElement"); +verify.currentLineContentIs(");"); +goTo.marker("closingParenInJsxElement2"); +verify.currentLineContentIs(") ;"); \ No newline at end of file From 378c6b5fc77957ae4413fbbb68fed44a47efa2d1 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 26 Jun 2016 15:17:05 +0900 Subject: [PATCH 02/10] format jsx expression --- src/services/formatting/rules.ts | 13 +++++++++++++ tests/cases/fourslash/formattingJsxElements.ts | 12 +++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 5fb6b330b42ea..50d6d596198e7 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -52,6 +52,10 @@ namespace ts.formatting { public SpaceBeforeCloseBrace: Rule; public NoSpaceBetweenEmptyBraceBrackets: Rule; + // No space after { and before } in JSX expression + public NoSpaceAfterOpenBraceInJsxExpression: Rule; + public NoSpaceBeforeCloseBraceInJsxExpression: Rule; + // Insert new line after { and before } in multi-line contexts. public NewLineAfterOpenBraceInBlockContext: Rule; @@ -276,6 +280,10 @@ namespace ts.formatting { this.SpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSingleLineBlockContext), RuleAction.Space)); this.NoSpaceBetweenEmptyBraceBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsObjectContext), RuleAction.Delete)); + // No space after { and before } in JSX expression + this.NoSpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete)); + this.NoSpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete)); + // Insert new line after { and before } in multi-line contexts. this.NewLineAfterOpenBraceInBlockContext = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsMultilineBlockContext), RuleAction.NewLine)); @@ -395,6 +403,7 @@ namespace ts.formatting { this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, this.NoSpaceAfterCloseBrace, this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, + this.NoSpaceAfterOpenBraceInJsxExpression, this.NoSpaceBeforeCloseBraceInJsxExpression, this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGeneratorDeclaration, this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, @@ -727,6 +736,10 @@ namespace ts.formatting { return context.contextNode.kind !== SyntaxKind.JsxElement; } + static isJsxExpressionContext(context: FormattingContext): boolean { + return context.contextNode.kind === SyntaxKind.JsxExpression; + } + static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean { return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context); } diff --git a/tests/cases/fourslash/formattingJsxElements.ts b/tests/cases/fourslash/formattingJsxElements.ts index 50e9bb8ea8fc6..e07149960dba9 100644 --- a/tests/cases/fourslash/formattingJsxElements.ts +++ b/tests/cases/fourslash/formattingJsxElements.ts @@ -66,10 +66,12 @@ /////*containedClosingTagAutoformat*/ ////; //// -////
,{integer}
;/*commaInJsxElement*/ -////
, {integer}
;/*commaInJsxElement2*/ +////
,{integer}
;/*commaInJsxElement*/ +////
, {integer}
;/*commaInJsxElement2*/ ////);/*closingParenInJsxElement*/ ////) ;/*closingParenInJsxElement2*/ +////;/*jsxExpressionSpaces*/ +////;/*jsxExpressionSpaces2*/ format.document(); goTo.marker("autoformat"); @@ -139,4 +141,8 @@ verify.currentLineContentIs("
, {integer}
;"); goTo.marker("closingParenInJsxElement"); verify.currentLineContentIs(");"); goTo.marker("closingParenInJsxElement2"); -verify.currentLineContentIs(") ;"); \ No newline at end of file +verify.currentLineContentIs(") ;"); +goTo.marker("jsxExpressionSpaces"); +verify.currentLineContentIs(";"); +goTo.marker("jsxExpressionSpaces2"); +verify.currentLineContentIs(";"); \ No newline at end of file From cbfbfe1aa6dfe7310c5899cd103f614187eee798 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 27 Jun 2016 16:04:53 +0900 Subject: [PATCH 03/10] make rules optional --- src/harness/fourslash.ts | 1 + src/server/editorServices.ts | 1 + src/services/formatting/rules.ts | 21 ++++++------ src/services/formatting/rulesProvider.ts | 9 ++++++ src/services/services.ts | 1 + .../fourslash/formattingOptionsChangeJsx.ts | 32 +++++++++++++++++++ 6 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 tests/cases/fourslash/formattingOptionsChangeJsx.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index bae2977c44ae8..a42abbbc60909 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -324,6 +324,7 @@ namespace FourSlash { InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, + InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false, PlaceOpenBraceOnNewLineForFunctions: false, PlaceOpenBraceOnNewLineForControlBlocks: false, }; diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index e48d61920177f..092450e526c16 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1580,6 +1580,7 @@ namespace ts.server { InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, + InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false, PlaceOpenBraceOnNewLineForFunctions: false, PlaceOpenBraceOnNewLineForControlBlocks: false, }); diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 50d6d596198e7..6e132f03465c9 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -52,10 +52,6 @@ namespace ts.formatting { public SpaceBeforeCloseBrace: Rule; public NoSpaceBetweenEmptyBraceBrackets: Rule; - // No space after { and before } in JSX expression - public NoSpaceAfterOpenBraceInJsxExpression: Rule; - public NoSpaceBeforeCloseBraceInJsxExpression: Rule; - // Insert new line after { and before } in multi-line contexts. public NewLineAfterOpenBraceInBlockContext: Rule; @@ -229,6 +225,12 @@ namespace ts.formatting { public NoSpaceBeforeTemplateMiddleAndTail: Rule; public SpaceBeforeTemplateMiddleAndTail: Rule; + // No space after { and before } in JSX expression + public NoSpaceAfterOpenBraceInJsxExpression: Rule; + public SpaceAfterOpenBraceInJsxExpression: Rule; + public NoSpaceBeforeCloseBraceInJsxExpression: Rule; + public SpaceBeforeCloseBraceInJsxExpression: Rule; + constructor() { /// /// Common Rules @@ -280,10 +282,6 @@ namespace ts.formatting { this.SpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSingleLineBlockContext), RuleAction.Space)); this.NoSpaceBetweenEmptyBraceBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsObjectContext), RuleAction.Delete)); - // No space after { and before } in JSX expression - this.NoSpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete)); - this.NoSpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete)); - // Insert new line after { and before } in multi-line contexts. this.NewLineAfterOpenBraceInBlockContext = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsMultilineBlockContext), RuleAction.NewLine)); @@ -403,7 +401,6 @@ namespace ts.formatting { this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, this.NoSpaceAfterCloseBrace, this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, - this.NoSpaceAfterOpenBraceInJsxExpression, this.NoSpaceBeforeCloseBraceInJsxExpression, this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGeneratorDeclaration, this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, @@ -500,6 +497,12 @@ namespace ts.formatting { this.NoSpaceBeforeTemplateMiddleAndTail = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete)); this.SpaceBeforeTemplateMiddleAndTail = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space)); + // No space after { and before } in JSX expression + this.NoSpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete)); + this.SpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Space)); + this.NoSpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete)); + this.SpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Space)); + // Insert space after function keyword for anonymous functions this.SpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space)); this.NoSpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Delete)); diff --git a/src/services/formatting/rulesProvider.ts b/src/services/formatting/rulesProvider.ts index d672a401d89d8..1be0f9e912d2e 100644 --- a/src/services/formatting/rulesProvider.ts +++ b/src/services/formatting/rulesProvider.ts @@ -90,6 +90,15 @@ namespace ts.formatting { rules.push(this.globalRules.NoSpaceBeforeTemplateMiddleAndTail); } + if (options.InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces) { + rules.push(this.globalRules.SpaceAfterOpenBraceInJsxExpression); + rules.push(this.globalRules.SpaceBeforeCloseBraceInJsxExpression); + } + else { + rules.push(this.globalRules.NoSpaceAfterOpenBraceInJsxExpression); + rules.push(this.globalRules.NoSpaceBeforeCloseBraceInJsxExpression); + } + if (options.InsertSpaceAfterSemicolonInForStatements) { rules.push(this.globalRules.SpaceAfterSemicolonInFor); } diff --git a/src/services/services.ts b/src/services/services.ts index a17d9feed2485..5142b19b6c0ef 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1267,6 +1267,7 @@ namespace ts { InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean; InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; + InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; [s: string]: boolean | number | string | undefined; diff --git a/tests/cases/fourslash/formattingOptionsChangeJsx.ts b/tests/cases/fourslash/formattingOptionsChangeJsx.ts new file mode 100644 index 0000000000000..a3c7e28a1ef7e --- /dev/null +++ b/tests/cases/fourslash/formattingOptionsChangeJsx.ts @@ -0,0 +1,32 @@ +/// + +//@Filename: file.tsx +/////*InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces*/; + +runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces", ";", ";"); + + +function runTest(propertyName: string, expectedStringWhenTrue: string, expectedStringWhenFalse: string) { + // Go to the correct file + goTo.marker(propertyName); + + // Set the option to false first + format.setOption(propertyName, false); + + // Format + format.document(); + + // Verify + goTo.marker(propertyName); + verify.currentLineContentIs(expectedStringWhenFalse); + + // Set the option to true + format.setOption(propertyName, true); + + // Format + format.document(); + + // Verify + goTo.marker(propertyName); + verify.currentLineContentIs(expectedStringWhenTrue); +} \ No newline at end of file From 0b6ba9682769d50e8c11b63e37557942e2f10c10 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 27 Jun 2016 15:04:51 -0700 Subject: [PATCH 04/10] Remove upper boilerplate from issue template Our issue stats did not improve appreciably when we added the issue template. Reduce upper boilerplate text and try to make it more action-oriented --- issue_template.md | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/issue_template.md b/issue_template.md index dcd2280570ccb..78e0ae8be91e6 100644 --- a/issue_template.md +++ b/issue_template.md @@ -1,24 +1,13 @@ - + + -For bug reports, please include the information below. -__________________________________________________________ --> - -**TypeScript Version:** - -1.7.5 / 1.8.0-beta / nightly (1.9.0-dev.20160217) +**TypeScript Version:** 1.8.0 / nightly (1.9.0-dev.201xxxxx) **Code** ```ts -// A self-contained demonstration of the problem follows... +// A *self-contained* demonstration of the problem follows... ``` From 8ddba289eb98d51cb711350c4e29038cc65670f8 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 27 Jun 2016 22:18:52 -0700 Subject: [PATCH 05/10] Update issue_template.md --- issue_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/issue_template.md b/issue_template.md index 78e0ae8be91e6..7799960ec7805 100644 --- a/issue_template.md +++ b/issue_template.md @@ -2,7 +2,7 @@ -**TypeScript Version:** 1.8.0 / nightly (1.9.0-dev.201xxxxx) +**TypeScript Version:** 1.8.0 / nightly (2.0.0-dev.201xxxxx) **Code** From 6e984eb3a37b18b9b075217b094ea6284f1e7279 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Wed, 29 Jun 2016 03:28:22 +0900 Subject: [PATCH 06/10] new options should be optional for compatibility --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 5142b19b6c0ef..529ce8a7bf7d5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1267,7 +1267,7 @@ namespace ts { InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean; InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; - InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: boolean; + InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; [s: string]: boolean | number | string | undefined; From 3fdaf194f7c02a27920fade8304ea6b9de457c1c Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 28 Jun 2016 21:26:18 +0200 Subject: [PATCH 07/10] VarDate interface and relevant Date.prototype members --- src/lib/scripthost.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/scripthost.d.ts b/src/lib/scripthost.d.ts index 7faae06714c28..baf93f55d552b 100644 --- a/src/lib/scripthost.d.ts +++ b/src/lib/scripthost.d.ts @@ -276,3 +276,13 @@ interface VBArrayConstructor { } declare var VBArray: VBArrayConstructor; + +/** + * Automation date (VT_DATE) + */ +interface VarDate { } + +interface DateConstructor { + new (vd: VarDate): Date; + getVarDate: () => VarDate; +} \ No newline at end of file From 6ff91b84aba99fbf66ac8f4e1d63068794ca8dcd Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 28 Jun 2016 11:43:07 -0700 Subject: [PATCH 08/10] Add getCurrentDirectory to ServerHost --- src/compiler/program.ts | 18 ++++++++++++++++-- src/server/editorServices.ts | 1 + .../fourslash/server/typeReferenceOnServer.ts | 9 +++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/server/typeReferenceOnServer.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7593f4f5434f5..decbb835a8c9f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -187,8 +187,22 @@ namespace ts { const typeReferenceExtensions = [".d.ts"]; function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) { - return options.typeRoots || - map(defaultTypeRoots, d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d)); + if (options.typeRoots) { + return options.typeRoots; + } + + let currentDirectory: string; + if (options.configFilePath) { + currentDirectory = getDirectoryPath(options.configFilePath); + } + else if (host.getCurrentDirectory) { + currentDirectory = host.getCurrentDirectory(); + } + + if (!currentDirectory) { + return undefined; + } + return map(defaultTypeRoots, d => combinePaths(currentDirectory, d)); } /** diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index e48d61920177f..e4b989b0ca7bc 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -113,6 +113,7 @@ namespace ts.server { this.moduleResolutionHost = { fileExists: fileName => this.fileExists(fileName), readFile: fileName => this.host.readFile(fileName), + getCurrentDirectory: () => this.host.getCurrentDirectory(), directoryExists: directoryName => this.host.directoryExists(directoryName) }; } diff --git a/tests/cases/fourslash/server/typeReferenceOnServer.ts b/tests/cases/fourslash/server/typeReferenceOnServer.ts new file mode 100644 index 0000000000000..574ea6f60c46e --- /dev/null +++ b/tests/cases/fourslash/server/typeReferenceOnServer.ts @@ -0,0 +1,9 @@ +/// + +/////// +////var x: number; +////x./*1*/ + +goTo.marker("1"); +verify.not.completionListIsEmpty(); + From d5cad239e858ca71e89aa8963a7d875928652a65 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 28 Jun 2016 12:10:26 -0700 Subject: [PATCH 09/10] Add nullchecks for typeRoots, remove getCurrentDirectory from ServerHost as it is always the installation location --- src/compiler/program.ts | 10 ++++++---- src/server/editorServices.ts | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index decbb835a8c9f..fb74f1dcaab33 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -242,7 +242,7 @@ namespace ts { const failedLookupLocations: string[] = []; // Check primary library paths - if (typeRoots.length) { + if (typeRoots && typeRoots.length) { if (traceEnabled) { trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", ")); } @@ -1060,9 +1060,11 @@ namespace ts { let result: string[] = []; if (host.directoryExists && host.getDirectories) { const typeRoots = getEffectiveTypeRoots(options, host); - for (const root of typeRoots) { - if (host.directoryExists(root)) { - result = result.concat(host.getDirectories(root)); + if (typeRoots) { + for (const root of typeRoots) { + if (host.directoryExists(root)) { + result = result.concat(host.getDirectories(root)); + } } } } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index e4b989b0ca7bc..e48d61920177f 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -113,7 +113,6 @@ namespace ts.server { this.moduleResolutionHost = { fileExists: fileName => this.fileExists(fileName), readFile: fileName => this.host.readFile(fileName), - getCurrentDirectory: () => this.host.getCurrentDirectory(), directoryExists: directoryName => this.host.directoryExists(directoryName) }; } From 29107e636b39ceb12abe5eb061891a6092ab5918 Mon Sep 17 00:00:00 2001 From: Yui Date: Tue, 28 Jun 2016 13:33:11 -0700 Subject: [PATCH 10/10] Fix 9363: Object destructuring broken-variables are bound to the wrong object (#9383) * Fix emit incorrect destructuring mapping in var declaration * Add tests and baselines * Add additional tests and baselines --- src/compiler/emitter.ts | 4 ++- .../destructuringParameterDeclaration7ES5.js | 27 +++++++++++++++ ...tructuringParameterDeclaration7ES5.symbols | 33 +++++++++++++++++++ ...estructuringParameterDeclaration7ES5.types | 33 +++++++++++++++++++ .../destructuringParameterDeclaration7ES5.ts | 14 ++++++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration7ES5.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration7ES5.symbols create mode 100644 tests/baselines/reference/destructuringParameterDeclaration7ES5.types create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0879a3a9ee426..30f0e74adb434 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4545,8 +4545,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } write(";"); - tempIndex++; } + // Regardless of whether we will emit a var declaration for the binding pattern, we generate the temporary + // variable for the parameter (see: emitParameter) + tempIndex++; } else if (initializer) { writeLine(); diff --git a/tests/baselines/reference/destructuringParameterDeclaration7ES5.js b/tests/baselines/reference/destructuringParameterDeclaration7ES5.js new file mode 100644 index 0000000000000..f9dac1ae2fabe --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration7ES5.js @@ -0,0 +1,27 @@ +//// [destructuringParameterDeclaration7ES5.ts] + +interface ISomething { + foo: string, + bar: string +} + +function foo({}, {foo, bar}: ISomething) {} + +function baz([], {foo, bar}: ISomething) {} + +function one([], {}) {} + +function two([], [a, b, c]: number[]) {} + + +//// [destructuringParameterDeclaration7ES5.js] +function foo(_a, _b) { + var foo = _b.foo, bar = _b.bar; +} +function baz(_a, _b) { + var foo = _b.foo, bar = _b.bar; +} +function one(_a, _b) { } +function two(_a, _b) { + var a = _b[0], b = _b[1], c = _b[2]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration7ES5.symbols b/tests/baselines/reference/destructuringParameterDeclaration7ES5.symbols new file mode 100644 index 0000000000000..44709f18e1b2b --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration7ES5.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts === + +interface ISomething { +>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5.ts, 0, 0)) + + foo: string, +>foo : Symbol(ISomething.foo, Decl(destructuringParameterDeclaration7ES5.ts, 1, 22)) + + bar: string +>bar : Symbol(ISomething.bar, Decl(destructuringParameterDeclaration7ES5.ts, 2, 16)) +} + +function foo({}, {foo, bar}: ISomething) {} +>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5.ts, 4, 1)) +>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5.ts, 6, 18)) +>bar : Symbol(bar, Decl(destructuringParameterDeclaration7ES5.ts, 6, 22)) +>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5.ts, 0, 0)) + +function baz([], {foo, bar}: ISomething) {} +>baz : Symbol(baz, Decl(destructuringParameterDeclaration7ES5.ts, 6, 43)) +>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5.ts, 8, 18)) +>bar : Symbol(bar, Decl(destructuringParameterDeclaration7ES5.ts, 8, 22)) +>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5.ts, 0, 0)) + +function one([], {}) {} +>one : Symbol(one, Decl(destructuringParameterDeclaration7ES5.ts, 8, 43)) + +function two([], [a, b, c]: number[]) {} +>two : Symbol(two, Decl(destructuringParameterDeclaration7ES5.ts, 10, 23)) +>a : Symbol(a, Decl(destructuringParameterDeclaration7ES5.ts, 12, 18)) +>b : Symbol(b, Decl(destructuringParameterDeclaration7ES5.ts, 12, 20)) +>c : Symbol(c, Decl(destructuringParameterDeclaration7ES5.ts, 12, 23)) + diff --git a/tests/baselines/reference/destructuringParameterDeclaration7ES5.types b/tests/baselines/reference/destructuringParameterDeclaration7ES5.types new file mode 100644 index 0000000000000..7d64383b0b668 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration7ES5.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts === + +interface ISomething { +>ISomething : ISomething + + foo: string, +>foo : string + + bar: string +>bar : string +} + +function foo({}, {foo, bar}: ISomething) {} +>foo : ({}: {}, {foo, bar}: ISomething) => void +>foo : string +>bar : string +>ISomething : ISomething + +function baz([], {foo, bar}: ISomething) {} +>baz : ([]: any[], {foo, bar}: ISomething) => void +>foo : string +>bar : string +>ISomething : ISomething + +function one([], {}) {} +>one : ([]: any[], {}: {}) => void + +function two([], [a, b, c]: number[]) {} +>two : ([]: any[], [a, b, c]: number[]) => void +>a : number +>b : number +>c : number + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts new file mode 100644 index 0000000000000..97822e92e2dba --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts @@ -0,0 +1,14 @@ +// @target: es5 + +interface ISomething { + foo: string, + bar: string +} + +function foo({}, {foo, bar}: ISomething) {} + +function baz([], {foo, bar}: ISomething) {} + +function one([], {}) {} + +function two([], [a, b, c]: number[]) {}