mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Formatting for generators
This commit is contained in:
parent
7f5a89ae5e
commit
be5557a644
@ -193,12 +193,16 @@ module ts.formatting {
|
||||
// Insert space after function keyword for anonymous functions
|
||||
public SpaceAfterAnonymousFunctionKeyword: Rule;
|
||||
public NoSpaceAfterAnonymousFunctionKeyword: Rule;
|
||||
|
||||
|
||||
// Insert space after @ in decorator
|
||||
public SpaceBeforeAt: Rule;
|
||||
public NoSpaceAfterAt: Rule;
|
||||
public SpaceAfterDecorator: Rule;
|
||||
|
||||
// Generator: function*
|
||||
public NoSpaceBetweenFunctionKeywordAndStar: Rule;
|
||||
public SpaceAfterStarInGenerator: Rule;
|
||||
|
||||
constructor() {
|
||||
///
|
||||
/// Common Rules
|
||||
@ -340,6 +344,9 @@ module ts.formatting {
|
||||
this.NoSpaceAfterAt = new Rule(RuleDescriptor.create3(SyntaxKind.AtToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.SpaceAfterDecorator = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.ExportKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.ClassKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PublicKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword, SyntaxKind.OpenBracketToken, SyntaxKind.AsteriskToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), RuleAction.Space));
|
||||
|
||||
this.NoSpaceBetweenFunctionKeywordAndStar = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), RuleAction.Delete));
|
||||
this.SpaceAfterStarInGenerator = new Rule(RuleDescriptor.create3(SyntaxKind.AsteriskToken, Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.OpenParenToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), RuleAction.Space));
|
||||
|
||||
// These rules are higher in priority than user-configurable rules.
|
||||
this.HighPriorityCommonRules =
|
||||
[
|
||||
@ -357,6 +364,7 @@ module ts.formatting {
|
||||
this.NoSpaceAfterCloseBrace,
|
||||
this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext,
|
||||
this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets,
|
||||
this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGenerator,
|
||||
this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember,
|
||||
this.NoSpaceBetweenReturnAndSemicolon,
|
||||
this.SpaceAfterCertainKeywords,
|
||||
@ -574,6 +582,10 @@ module ts.formatting {
|
||||
return false;
|
||||
}
|
||||
|
||||
static IsFunctionDeclarationOrFunctionExpressionContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.FunctionDeclaration || context.contextNode.kind === SyntaxKind.FunctionExpression;
|
||||
}
|
||||
|
||||
static IsTypeScriptDeclWithBlockContext(context: FormattingContext): boolean {
|
||||
return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode);
|
||||
}
|
||||
|
||||
10
tests/cases/fourslash/generatorDeclarationFormatting.ts
Normal file
10
tests/cases/fourslash/generatorDeclarationFormatting.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// function *g() { }/*1*/
|
||||
//// var v = function *() { };/*2*/
|
||||
|
||||
format.document();
|
||||
goTo.marker('1');
|
||||
verify.currentLineContentIs("function* g() { }");
|
||||
goTo.marker('2');
|
||||
verify.currentLineContentIs("var v = function* () { };");
|
||||
Loading…
x
Reference in New Issue
Block a user