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