Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into release-2.0 #9400

Merged
merged 18 commits into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions issue_template.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
<!--
Thank you for contributing to TypeScript! Please review this checklist
before submitting your issue.
[ ] Many common issues and suggestions are addressed in the FAQ
https://github.com/Microsoft/TypeScript/wiki/FAQ
[ ] Search for duplicates before logging new issues
https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue
[ ] Questions are best asked and answered at Stack Overflow
http://stackoverflow.com/questions/tagged/typescript
<!-- BUGS: Please use this template. -->
<!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->
<!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->

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 (2.0.0-dev.201xxxxx)

**Code**

```ts
// A self-contained demonstration of the problem follows...
// A *self-contained* demonstration of the problem follows...

```

Expand Down
4 changes: 3 additions & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ namespace FourSlash {
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
PlaceOpenBraceOnNewLineForFunctions: false,
PlaceOpenBraceOnNewLineForControlBlocks: false,
};
Expand Down
10 changes: 10 additions & 0 deletions src/lib/scripthost.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,13 @@ interface VBArrayConstructor {
}

declare var VBArray: VBArrayConstructor;

/**
* Automation date (VT_DATE)
*/
interface VarDate { }

interface DateConstructor {
new (vd: VarDate): Date;
getVarDate: () => VarDate;
}
1 change: 1 addition & 0 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,7 @@ namespace ts.server {
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
PlaceOpenBraceOnNewLineForFunctions: false,
PlaceOpenBraceOnNewLineForControlBlocks: false,
});
Expand Down
26 changes: 23 additions & 3 deletions src/services/formatting/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,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
Expand Down Expand Up @@ -316,7 +322,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));
Expand Down Expand Up @@ -444,8 +450,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));
Expand Down Expand Up @@ -491,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));
Expand Down Expand Up @@ -729,6 +741,14 @@ namespace ts.formatting {
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
}

static isNonJsxElementContext(context: FormattingContext): boolean {
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);
}
Expand Down
9 changes: 9 additions & 0 deletions src/services/formatting/rulesProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ namespace ts {
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean;
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean;
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
PlaceOpenBraceOnNewLineForFunctions: boolean;
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
[s: string]: boolean | number | string | undefined;
Expand Down
27 changes: 27 additions & 0 deletions tests/baselines/reference/destructuringParameterDeclaration7ES5.js
Original file line number Diff line number Diff line change
@@ -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];
}
Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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[]) {}
32 changes: 26 additions & 6 deletions tests/cases/fourslash/formattingJsxElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//// </div>
//// )
////}
////
////
////function foo1() {
//// return (
//// <div className="commentBox" data-id="test">
Expand Down Expand Up @@ -45,8 +45,8 @@
//// class3= {/*5*/
//// }/>/*6*/
//// )
////}
////
////}
////
////(function () {
//// return <div
////className=""/*attrAutoformat*/
Expand All @@ -64,7 +64,14 @@
/////*childJsxElementIndent*/
////<span></span>/*grandchildJsxElementAutoformat*/
////</span>/*containedClosingTagAutoformat*/
////</h5>
////</h5>;
////
////<div>,{integer}</div>;/*commaInJsxElement*/
////<div>, {integer}</div>;/*commaInJsxElement2*/
////<span>)</span>;/*closingParenInJsxElement*/
////<span>) </span>;/*closingParenInJsxElement2*/
////<Router routes={ 3 } />;/*jsxExpressionSpaces*/
////<Router routes={ (3) } />;/*jsxExpressionSpaces2*/

format.document();
goTo.marker("autoformat");
Expand Down Expand Up @@ -114,7 +121,7 @@ verify.indentationIs(12);

goTo.marker("danglingBracketAutoformat")
// TODO: verify.currentLineContentIs(" >");
verify.currentLineContentIs(" >");
verify.currentLineContentIs(" >");
goTo.marker("closingTagAutoformat");
verify.currentLineContentIs(" </div>");

Expand All @@ -125,4 +132,17 @@ verify.indentationIs(8);
goTo.marker("grandchildJsxElementAutoformat");
verify.currentLineContentIs(" <span></span>");
goTo.marker("containedClosingTagAutoformat");
verify.currentLineContentIs(" </span>");
verify.currentLineContentIs(" </span>");

goTo.marker("commaInJsxElement");
verify.currentLineContentIs("<div>,{integer}</div>;");
goTo.marker("commaInJsxElement2");
verify.currentLineContentIs("<div>, {integer}</div>;");
goTo.marker("closingParenInJsxElement");
verify.currentLineContentIs("<span>)</span>;");
goTo.marker("closingParenInJsxElement2");
verify.currentLineContentIs("<span>) </span>;");
goTo.marker("jsxExpressionSpaces");
verify.currentLineContentIs("<Router routes={3} />;");
goTo.marker("jsxExpressionSpaces2");
verify.currentLineContentIs("<Router routes={(3)} />;");
32 changes: 32 additions & 0 deletions tests/cases/fourslash/formattingOptionsChangeJsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
///<reference path="fourslash.ts"/>

//@Filename: file.tsx
/////*InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces*/<Madoka homu={ true } saya={ (true) } />;

runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces", "<Madoka homu={ true } saya={ (true) } />;", "<Madoka homu={true} saya={(true)} />;");


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);
}