Merge pull request #4650 from Microsoft/Port-4646
Port PR-4646 into release-1.6
This commit is contained in:
commit
03d373dfae
|
@ -17,7 +17,8 @@ namespace ts.formatting {
|
|||
Scan,
|
||||
RescanGreaterThanToken,
|
||||
RescanSlashToken,
|
||||
RescanTemplateToken
|
||||
RescanTemplateToken,
|
||||
RescanJsxIdentifier
|
||||
}
|
||||
|
||||
export function getFormattingScanner(sourceFile: SourceFile, startPos: number, endPos: number): FormattingScanner {
|
||||
|
@ -109,6 +110,20 @@ namespace ts.formatting {
|
|||
return false;
|
||||
}
|
||||
|
||||
function shouldRescanJsxIdentifier(node: Node): boolean {
|
||||
if (node.parent) {
|
||||
switch(node.parent.kind) {
|
||||
case SyntaxKind.JsxAttribute:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
return node.kind === SyntaxKind.Identifier;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function shouldRescanSlashToken(container: Node): boolean {
|
||||
return container.kind === SyntaxKind.RegularExpressionLiteral;
|
||||
}
|
||||
|
@ -141,6 +156,8 @@ namespace ts.formatting {
|
|||
? ScanAction.RescanSlashToken
|
||||
: shouldRescanTemplateToken(n)
|
||||
? ScanAction.RescanTemplateToken
|
||||
: shouldRescanJsxIdentifier(n)
|
||||
? ScanAction.RescanJsxIdentifier
|
||||
: ScanAction.Scan
|
||||
|
||||
if (lastTokenInfo && expectedScanAction === lastScanAction) {
|
||||
|
@ -176,6 +193,10 @@ namespace ts.formatting {
|
|||
currentToken = scanner.reScanTemplateToken();
|
||||
lastScanAction = ScanAction.RescanTemplateToken;
|
||||
}
|
||||
else if (expectedScanAction === ScanAction.RescanJsxIdentifier && currentToken === SyntaxKind.Identifier) {
|
||||
currentToken = scanner.scanJsxIdentifier();
|
||||
lastScanAction = ScanAction.RescanJsxIdentifier;
|
||||
}
|
||||
else {
|
||||
lastScanAction = ScanAction.Scan;
|
||||
}
|
||||
|
|
|
@ -431,6 +431,7 @@ namespace ts.formatting {
|
|||
case SyntaxKind.ArrayBindingPattern:
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//@Filename: file.tsx
|
||||
////function () {
|
||||
////function foo0() {
|
||||
//// return (
|
||||
//// <div className="commentBox" >
|
||||
////Hello, World!/*autoformat*/
|
||||
|
@ -10,6 +10,42 @@
|
|||
//// )
|
||||
////}
|
||||
////
|
||||
////function foo1() {
|
||||
//// return (
|
||||
//// <div className="commentBox" data-id="test">
|
||||
////Hello, World!/*autoformat1*/
|
||||
/////*indent1*/
|
||||
//// </div>
|
||||
//// )
|
||||
////}
|
||||
////
|
||||
////function foo2() {
|
||||
//// return (
|
||||
//// <div data-name="commentBox"
|
||||
////class1= {/*1*/
|
||||
////}>/*2*/
|
||||
////Hello, World!/*autoformat2*/
|
||||
/////*indent2*/
|
||||
//// </div>
|
||||
//// )
|
||||
////}
|
||||
////function foo3() {
|
||||
//// return (
|
||||
//// <jsx-element className="commentBox"
|
||||
//// class2= {/*3*/
|
||||
//// }>/*4*/
|
||||
//// Hello, World!/*autoformat3*/
|
||||
//// /*indent3*/
|
||||
//// </jsx-element>
|
||||
//// )
|
||||
////}
|
||||
////function foo4() {
|
||||
//// return (
|
||||
//// <jsx-element className="commentBox"
|
||||
//// class3= {/*5*/
|
||||
//// }/>/*6*/
|
||||
//// )
|
||||
////}
|
||||
|
||||
|
||||
format.document();
|
||||
|
@ -17,3 +53,33 @@ goTo.marker("autoformat");
|
|||
verify.currentLineContentIs(' Hello, World!');
|
||||
goTo.marker("indent");
|
||||
verify.indentationIs(12);
|
||||
|
||||
goTo.marker("autoformat1");
|
||||
verify.currentLineContentIs(' Hello, World!');
|
||||
goTo.marker("indent1");
|
||||
verify.indentationIs(12);
|
||||
|
||||
goTo.marker("1");
|
||||
verify.currentLineContentIs(' class1= {');
|
||||
goTo.marker("2");
|
||||
verify.currentLineContentIs(' }>');
|
||||
|
||||
goTo.marker("autoformat2");
|
||||
verify.currentLineContentIs(' Hello, World!');
|
||||
goTo.marker("indent2");
|
||||
verify.indentationIs(12);
|
||||
|
||||
goTo.marker("3");
|
||||
verify.currentLineContentIs(' class2= {');
|
||||
goTo.marker("4");
|
||||
verify.currentLineContentIs(' }>');
|
||||
|
||||
goTo.marker("autoformat3");
|
||||
verify.currentLineContentIs(' Hello, World!');
|
||||
goTo.marker("indent3");
|
||||
verify.indentationIs(12);
|
||||
|
||||
goTo.marker("5");
|
||||
verify.currentLineContentIs(' class3= {');
|
||||
goTo.marker("6");
|
||||
verify.currentLineContentIs(' }/>');
|
||||
|
|
Loading…
Reference in a new issue