@tslite/services 0.0.0-stage → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/LICENSE +55 -0
  2. package/NOTICE +13 -0
  3. package/dist/_namespaces/edit.d.ts +8 -0
  4. package/dist/_namespaces/edit.js +11 -0
  5. package/dist/_namespaces/ts.Completions.StringCompletions.d.ts +1 -0
  6. package/dist/_namespaces/ts.Completions.StringCompletions.js +2 -0
  7. package/dist/_namespaces/ts.Completions.d.ts +2 -0
  8. package/dist/_namespaces/ts.Completions.js +3 -0
  9. package/dist/_namespaces/ts.FindAllReferences.d.ts +2 -0
  10. package/dist/_namespaces/ts.FindAllReferences.js +3 -0
  11. package/dist/_namespaces/ts.GoToDefinition.d.ts +1 -0
  12. package/dist/_namespaces/ts.GoToDefinition.js +2 -0
  13. package/dist/_namespaces/ts.NavigationBar.d.ts +1 -0
  14. package/dist/_namespaces/ts.NavigationBar.js +2 -0
  15. package/dist/_namespaces/ts.OrganizeImports.d.ts +1 -0
  16. package/dist/_namespaces/ts.OrganizeImports.js +2 -0
  17. package/dist/_namespaces/ts.OutliningElementsCollector.d.ts +1 -0
  18. package/dist/_namespaces/ts.OutliningElementsCollector.js +2 -0
  19. package/dist/_namespaces/ts.Rename.d.ts +1 -0
  20. package/dist/_namespaces/ts.Rename.js +2 -0
  21. package/dist/_namespaces/ts.SignatureHelp.d.ts +1 -0
  22. package/dist/_namespaces/ts.SignatureHelp.js +2 -0
  23. package/dist/_namespaces/ts.SmartSelectionRange.d.ts +1 -0
  24. package/dist/_namespaces/ts.SmartSelectionRange.js +2 -0
  25. package/dist/_namespaces/ts.SymbolDisplay.d.ts +1 -0
  26. package/dist/_namespaces/ts.SymbolDisplay.js +2 -0
  27. package/dist/_namespaces/ts.codefix.d.ts +26 -0
  28. package/dist/_namespaces/ts.codefix.js +27 -0
  29. package/dist/_namespaces/ts.d.ts +17 -0
  30. package/dist/_namespaces/ts.formatting.d.ts +7 -0
  31. package/dist/_namespaces/ts.formatting.js +8 -0
  32. package/dist/_namespaces/ts.js +20 -0
  33. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.d.ts +1 -0
  34. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +2 -0
  35. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.d.ts +1 -0
  36. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +2 -0
  37. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.d.ts +1 -0
  38. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +2 -0
  39. package/dist/_namespaces/ts.refactor.d.ts +9 -0
  40. package/dist/_namespaces/ts.refactor.extractSymbol.d.ts +1 -0
  41. package/dist/_namespaces/ts.refactor.extractSymbol.js +2 -0
  42. package/dist/_namespaces/ts.refactor.js +10 -0
  43. package/dist/_namespaces/ts.textChanges.d.ts +1 -0
  44. package/dist/_namespaces/ts.textChanges.js +2 -0
  45. package/dist/classifier.d.ts +5 -0
  46. package/dist/classifier.js +439 -0
  47. package/dist/codeFixProvider.d.ts +13 -0
  48. package/dist/codeFixProvider.js +84 -0
  49. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +1 -0
  50. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +21 -0
  51. package/dist/codefixes/addEmptyExportDeclaration.d.ts +1 -0
  52. package/dist/codefixes/addEmptyExportDeclaration.js +17 -0
  53. package/dist/codefixes/addMissingAsync.d.ts +1 -0
  54. package/dist/codefixes/addMissingAsync.js +75 -0
  55. package/dist/codefixes/addMissingAwait.d.ts +1 -0
  56. package/dist/codefixes/addMissingAwait.js +236 -0
  57. package/dist/codefixes/addMissingConst.d.ts +1 -0
  58. package/dist/codefixes/addMissingConst.js +91 -0
  59. package/dist/codefixes/addNameToNamelessParameter.d.ts +1 -0
  60. package/dist/codefixes/addNameToNamelessParameter.js +29 -0
  61. package/dist/codefixes/convertConstToLet.d.ts +1 -0
  62. package/dist/codefixes/convertConstToLet.js +30 -0
  63. package/dist/codefixes/convertToAsyncFunction.d.ts +1 -0
  64. package/dist/codefixes/convertToAsyncFunction.js +495 -0
  65. package/dist/codefixes/convertToMappedObjectType.d.ts +1 -0
  66. package/dist/codefixes/convertToMappedObjectType.js +48 -0
  67. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.d.ts +1 -0
  68. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +33 -0
  69. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.d.ts +1 -0
  70. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +27 -0
  71. package/dist/codefixes/fixAwaitInSyncFunction.d.ts +1 -0
  72. package/dist/codefixes/fixAwaitInSyncFunction.js +69 -0
  73. package/dist/codefixes/fixExpectedComma.d.ts +1 -0
  74. package/dist/codefixes/fixExpectedComma.js +35 -0
  75. package/dist/codefixes/fixInvalidJsxCharacters.d.ts +1 -0
  76. package/dist/codefixes/fixInvalidJsxCharacters.js +41 -0
  77. package/dist/codefixes/fixMissingCallParentheses.d.ts +1 -0
  78. package/dist/codefixes/fixMissingCallParentheses.js +42 -0
  79. package/dist/codefixes/fixSpelling.d.ts +1 -0
  80. package/dist/codefixes/fixSpelling.js +94 -0
  81. package/dist/codefixes/fixUnreachableCode.d.ts +1 -0
  82. package/dist/codefixes/fixUnreachableCode.js +65 -0
  83. package/dist/codefixes/fixUnusedIdentifier.d.ts +1 -0
  84. package/dist/codefixes/fixUnusedIdentifier.js +224 -0
  85. package/dist/codefixes/helpers.d.ts +8 -0
  86. package/dist/codefixes/helpers.js +53 -0
  87. package/dist/codefixes/importFixes.d.ts +14 -0
  88. package/dist/codefixes/importFixes.js +441 -0
  89. package/dist/codefixes/inferFromUsage.d.ts +1 -0
  90. package/dist/codefixes/inferFromUsage.js +742 -0
  91. package/dist/codefixes/removeUnnecessaryAwait.d.ts +1 -0
  92. package/dist/codefixes/removeUnnecessaryAwait.js +41 -0
  93. package/dist/codefixes/returnValueCorrect.d.ts +1 -0
  94. package/dist/codefixes/returnValueCorrect.js +132 -0
  95. package/dist/codefixes/splitTypeOnlyImport.d.ts +1 -0
  96. package/dist/codefixes/splitTypeOnlyImport.js +32 -0
  97. package/dist/codefixes/useBigintLiteral.d.ts +1 -0
  98. package/dist/codefixes/useBigintLiteral.js +29 -0
  99. package/dist/completions.d.ts +83 -0
  100. package/dist/completions.js +1720 -0
  101. package/dist/documentHighlights.d.ts +8 -0
  102. package/dist/documentHighlights.js +367 -0
  103. package/dist/documentRegistry.d.ts +36 -0
  104. package/dist/documentRegistry.js +63 -0
  105. package/dist/editingServices.d.ts +1 -0
  106. package/dist/editingServices.js +4 -0
  107. package/dist/findAllReferences.d.ts +113 -0
  108. package/dist/findAllReferences.js +1366 -0
  109. package/dist/formatting/formatting.d.ts +26 -0
  110. package/dist/formatting/formatting.js +1021 -0
  111. package/dist/formatting/formattingContext.d.ts +34 -0
  112. package/dist/formatting/formattingContext.js +78 -0
  113. package/dist/formatting/formattingScanner.d.ts +14 -0
  114. package/dist/formatting/formattingScanner.js +228 -0
  115. package/dist/formatting/rule.d.ts +31 -0
  116. package/dist/formatting/rule.js +22 -0
  117. package/dist/formatting/rules.d.ts +7 -0
  118. package/dist/formatting/rules.js +610 -0
  119. package/dist/formatting/rulesMap.d.ts +5 -0
  120. package/dist/formatting/rulesMap.js +127 -0
  121. package/dist/formatting/smartIndenter.d.ts +44 -0
  122. package/dist/formatting/smartIndenter.js +518 -0
  123. package/dist/getEditsForFileRename.d.ts +6 -0
  124. package/dist/getEditsForFileRename.js +86 -0
  125. package/dist/goToDefinition.d.ts +8 -0
  126. package/dist/goToDefinition.js +246 -0
  127. package/dist/importTracker.d.ts +50 -0
  128. package/dist/importTracker.js +422 -0
  129. package/dist/index.d.ts +1 -0
  130. package/dist/index.js +3 -0
  131. package/dist/navigationBar.d.ts +3 -0
  132. package/dist/navigationBar.js +549 -0
  133. package/dist/organizeImports.d.ts +18 -0
  134. package/dist/organizeImports.js +290 -0
  135. package/dist/outliningElementsCollector.d.ts +2 -0
  136. package/dist/outliningElementsCollector.js +261 -0
  137. package/dist/refactorProvider.d.ts +5 -0
  138. package/dist/refactorProvider.js +16 -0
  139. package/dist/refactors/addOrRemoveBracesToArrowFunction.d.ts +1 -0
  140. package/dist/refactors/addOrRemoveBracesToArrowFunction.js +86 -0
  141. package/dist/refactors/convertExport.d.ts +1 -0
  142. package/dist/refactors/convertExport.js +126 -0
  143. package/dist/refactors/convertImport.d.ts +1 -0
  144. package/dist/refactors/convertImport.js +116 -0
  145. package/dist/refactors/convertParamsToDestructuredObject.d.ts +1 -0
  146. package/dist/refactors/convertParamsToDestructuredObject.js +282 -0
  147. package/dist/refactors/convertStringOrTemplateLiteral.d.ts +1 -0
  148. package/dist/refactors/convertStringOrTemplateLiteral.js +148 -0
  149. package/dist/refactors/extractSymbol.d.ts +60 -0
  150. package/dist/refactors/extractSymbol.js +1281 -0
  151. package/dist/refactors/extractType.d.ts +1 -0
  152. package/dist/refactors/extractType.js +102 -0
  153. package/dist/refactors/moveToNewFile.d.ts +1 -0
  154. package/dist/refactors/moveToNewFile.js +477 -0
  155. package/dist/rename.d.ts +2 -0
  156. package/dist/rename.js +100 -0
  157. package/dist/services.d.ts +48 -0
  158. package/dist/services.js +1480 -0
  159. package/dist/signatureHelp.d.ts +8 -0
  160. package/dist/signatureHelp.js +414 -0
  161. package/dist/smartSelection.d.ts +2 -0
  162. package/dist/smartSelection.js +243 -0
  163. package/dist/stringCompletions.d.ts +4 -0
  164. package/dist/stringCompletions.js +220 -0
  165. package/dist/suggestionDiagnostics.d.ts +6 -0
  166. package/dist/suggestionDiagnostics.js +92 -0
  167. package/dist/symbolDisplay.d.ts +16 -0
  168. package/dist/symbolDisplay.js +400 -0
  169. package/dist/textChanges.d.ts +161 -0
  170. package/dist/textChanges.js +1163 -0
  171. package/dist/types.d.ts +908 -0
  172. package/dist/types.js +263 -0
  173. package/dist/utilities.d.ts +283 -0
  174. package/dist/utilities.js +1981 -0
  175. package/package.json +45 -3
  176. package/README.md +0 -3
@@ -0,0 +1,610 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/formatting/rules.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { SemicolonPreference, SyntaxKind, contains, findAncestor, findNextToken, isArray, isFunctionLikeKind, isPropertySignature, isTrivia, positionIsASICandidate, typeKeywords, } from "../_namespaces/edit.js";
3
+ import { anyContext, } from "../_namespaces/ts.formatting.js";
4
+ export function getAllRules() {
5
+ const allTokens = [];
6
+ for (let token = SyntaxKind.FirstToken; token <= SyntaxKind.LastToken; token++) {
7
+ if (token !== SyntaxKind.EndOfFileToken) {
8
+ allTokens.push(token);
9
+ }
10
+ }
11
+ function anyTokenExcept(...tokens) {
12
+ return { tokens: allTokens.filter(t => !tokens.some(t2 => t2 === t)), isSpecific: false };
13
+ }
14
+ const anyToken = { tokens: allTokens, isSpecific: false };
15
+ const anyTokenIncludingMultilineComments = tokenRangeFrom([...allTokens, SyntaxKind.MultiLineCommentTrivia]);
16
+ const anyTokenIncludingEOF = tokenRangeFrom([...allTokens, SyntaxKind.EndOfFileToken]);
17
+ const keywords = tokenRangeFromRange(SyntaxKind.FirstKeyword, SyntaxKind.LastKeyword);
18
+ const binaryOperators = tokenRangeFromRange(SyntaxKind.FirstBinaryOperator, SyntaxKind.LastBinaryOperator);
19
+ // Nas listas de palavras, na tag, também as que saíram do scanner com o que a Linguagem não tem (CK-56): aqui, o
20
+ // `instanceof`, o `this` e o `new` (CK-02).
21
+ const binaryKeywordOperators = [SyntaxKind.InKeyword, SyntaxKind.OfKeyword, SyntaxKind.AsKeyword, SyntaxKind.IsKeyword];
22
+ const unaryPrefixOperators = [SyntaxKind.PlusPlusToken, SyntaxKind.MinusMinusToken, SyntaxKind.TildeToken, SyntaxKind.ExclamationToken];
23
+ const unaryPrefixExpressions = [
24
+ SyntaxKind.NumericLiteral, SyntaxKind.BigIntLiteral, SyntaxKind.Identifier, SyntaxKind.OpenParenToken,
25
+ SyntaxKind.OpenBracketToken, SyntaxKind.OpenBraceToken
26
+ ];
27
+ const unaryPreincrementExpressions = [SyntaxKind.Identifier, SyntaxKind.OpenParenToken];
28
+ const unaryPostincrementExpressions = [SyntaxKind.Identifier, SyntaxKind.CloseParenToken, SyntaxKind.CloseBracketToken];
29
+ const unaryPredecrementExpressions = [SyntaxKind.Identifier, SyntaxKind.OpenParenToken];
30
+ const unaryPostdecrementExpressions = [SyntaxKind.Identifier, SyntaxKind.CloseParenToken, SyntaxKind.CloseBracketToken];
31
+ const comments = [SyntaxKind.SingleLineCommentTrivia, SyntaxKind.MultiLineCommentTrivia];
32
+ const typeNames = [SyntaxKind.Identifier, ...typeKeywords];
33
+ // Place a space before open brace in a function declaration
34
+ // TypeScript: Function can have return types, which can be made of tons of different token kinds
35
+ const functionOpenBraceLeftTokenRange = anyTokenIncludingMultilineComments;
36
+ // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc)
37
+ // Na tag, também depois do `class` (CK-02).
38
+ const typeScriptOpenBraceLeftTokenRange = tokenRangeFrom([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.ExportKeyword, SyntaxKind.ImportKeyword]);
39
+ // Place a space before open brace in a control flow construct
40
+ const controlOpenBraceLeftTokenRange = tokenRangeFrom([SyntaxKind.CloseParenToken, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.DoKeyword, SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword, SyntaxKind.ElseKeyword]);
41
+ // These rules are higher in priority than user-configurable
42
+ const highPriorityCommonRules = [
43
+ // Leave comments alone
44
+ rule("IgnoreBeforeComment", anyToken, comments, anyContext, 1 /* RuleAction.StopProcessingSpaceActions */),
45
+ rule("IgnoreAfterLineComment", SyntaxKind.SingleLineCommentTrivia, anyToken, anyContext, 1 /* RuleAction.StopProcessingSpaceActions */),
46
+ rule("NotSpaceBeforeColon", anyToken, SyntaxKind.ColonToken, [isNonJsxSameLineTokenContext, isNotBinaryOpContext, isNotTypeAnnotationContext], 16 /* RuleAction.DeleteSpace */),
47
+ rule("SpaceAfterColon", SyntaxKind.ColonToken, anyToken, [isNonJsxSameLineTokenContext, isNotBinaryOpContext], 4 /* RuleAction.InsertSpace */),
48
+ rule("NoSpaceBeforeQuestionMark", anyToken, SyntaxKind.QuestionToken, [isNonJsxSameLineTokenContext, isNotBinaryOpContext], 16 /* RuleAction.DeleteSpace */),
49
+ // insert space after '?' only when it is used in conditional operator
50
+ rule("SpaceAfterQuestionMarkInConditionalOperator", SyntaxKind.QuestionToken, anyToken, [isNonJsxSameLineTokenContext, isConditionalOperatorContext], 4 /* RuleAction.InsertSpace */),
51
+ // in other cases there should be no space between '?' and next token
52
+ rule("NoSpaceAfterQuestionMark", SyntaxKind.QuestionToken, anyToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
53
+ rule("NoSpaceBeforeDot", anyToken, [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
54
+ rule("NoSpaceAfterDot", [SyntaxKind.DotToken, SyntaxKind.QuestionDotToken], anyToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
55
+ rule("NoSpaceBetweenImportParenInImportType", SyntaxKind.ImportKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isImportTypeContext], 16 /* RuleAction.DeleteSpace */),
56
+ // Special handling of unary operators.
57
+ // Prefix operators generally shouldn't have a space between
58
+ // them and their target unary expression.
59
+ rule("NoSpaceAfterUnaryPrefixOperator", unaryPrefixOperators, unaryPrefixExpressions, [isNonJsxSameLineTokenContext, isNotBinaryOpContext], 16 /* RuleAction.DeleteSpace */),
60
+ rule("NoSpaceAfterUnaryPreincrementOperator", SyntaxKind.PlusPlusToken, unaryPreincrementExpressions, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
61
+ rule("NoSpaceAfterUnaryPredecrementOperator", SyntaxKind.MinusMinusToken, unaryPredecrementExpressions, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
62
+ rule("NoSpaceBeforeUnaryPostincrementOperator", unaryPostincrementExpressions, SyntaxKind.PlusPlusToken, [isNonJsxSameLineTokenContext, isNotStatementConditionContext], 16 /* RuleAction.DeleteSpace */),
63
+ rule("NoSpaceBeforeUnaryPostdecrementOperator", unaryPostdecrementExpressions, SyntaxKind.MinusMinusToken, [isNonJsxSameLineTokenContext, isNotStatementConditionContext], 16 /* RuleAction.DeleteSpace */),
64
+ // More unary operator special-casing.
65
+ // DevDiv 181814: Be careful when removing leading whitespace
66
+ // around unary operators. Examples:
67
+ // 1 - -2 --X--> 1--2
68
+ // a + ++b --X--> a+++b
69
+ rule("SpaceAfterPostincrementWhenFollowedByAdd", SyntaxKind.PlusPlusToken, SyntaxKind.PlusToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
70
+ rule("SpaceAfterAddWhenFollowedByUnaryPlus", SyntaxKind.PlusToken, SyntaxKind.PlusToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
71
+ rule("SpaceAfterAddWhenFollowedByPreincrement", SyntaxKind.PlusToken, SyntaxKind.PlusPlusToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
72
+ rule("SpaceAfterPostdecrementWhenFollowedBySubtract", SyntaxKind.MinusMinusToken, SyntaxKind.MinusToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
73
+ rule("SpaceAfterSubtractWhenFollowedByUnaryMinus", SyntaxKind.MinusToken, SyntaxKind.MinusToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
74
+ rule("SpaceAfterSubtractWhenFollowedByPredecrement", SyntaxKind.MinusToken, SyntaxKind.MinusMinusToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
75
+ rule("NoSpaceAfterCloseBrace", SyntaxKind.CloseBraceToken, [SyntaxKind.CommaToken, SyntaxKind.SemicolonToken], [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
76
+ // For functions and control block place } on a new line [multi-line rule]
77
+ rule("NewLineBeforeCloseBraceInBlockContext", anyTokenIncludingMultilineComments, SyntaxKind.CloseBraceToken, [isMultilineBlockContext], 8 /* RuleAction.InsertNewLine */),
78
+ // Space/new line after }.
79
+ rule("SpaceAfterCloseBrace", SyntaxKind.CloseBraceToken, anyTokenExcept(SyntaxKind.CloseParenToken), [isNonJsxSameLineTokenContext, isAfterCodeBlockContext], 4 /* RuleAction.InsertSpace */),
80
+ // Special case for (}, else) and (}, while) since else & while tokens are not part of the tree which makes SpaceAfterCloseBrace rule not applied
81
+ // Also should not apply to })
82
+ rule("SpaceBetweenCloseBraceAndElse", SyntaxKind.CloseBraceToken, SyntaxKind.ElseKeyword, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
83
+ rule("SpaceBetweenCloseBraceAndWhile", SyntaxKind.CloseBraceToken, SyntaxKind.WhileKeyword, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
84
+ rule("NoSpaceBetweenEmptyBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isNonJsxSameLineTokenContext, isObjectContext], 16 /* RuleAction.DeleteSpace */),
85
+ // Add a space after control dec context if the next character is an open bracket ex: 'if (false)[a, b] = [1, 2];' -> 'if (false) [a, b] = [1, 2];'
86
+ rule("SpaceAfterConditionalClosingParen", SyntaxKind.CloseParenToken, SyntaxKind.OpenBracketToken, [isControlDeclContext], 4 /* RuleAction.InsertSpace */),
87
+ // Na tag, também o espaço do `function` e da estrela do generator (CK-02).
88
+ // Insert new line after { and before } in multi-line contexts.
89
+ rule("NewLineAfterOpenBraceInBlockContext", SyntaxKind.OpenBraceToken, anyToken, [isMultilineBlockContext], 8 /* RuleAction.InsertNewLine */),
90
+ // Na tag, também o espaço depois do `get` e do `set` de um acessor, e o do `yield` (CK-02).
91
+ rule("NoSpaceBetweenReturnAndSemicolon", SyntaxKind.ReturnKeyword, SyntaxKind.SemicolonToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
92
+ // Na tag, também depois do `var` (CK-54) e do `new` (CK-02).
93
+ rule("SpaceAfterCertainKeywords", [SyntaxKind.ThrowKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword, SyntaxKind.AwaitKeyword], anyToken, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
94
+ rule("SpaceAfterLetConstInVariableDeclaration", [SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword], anyToken, [isNonJsxSameLineTokenContext, isStartOfVariableDeclarationList], 4 /* RuleAction.InsertSpace */),
95
+ rule("NoSpaceBeforeOpenParenInFuncCall", anyToken, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isFunctionCallOrNewContext, isPreviousTokenNotComma], 16 /* RuleAction.DeleteSpace */),
96
+ // Special case for binary operators (that are keywords). For these we have to add a space and shouldn't follow any user options.
97
+ rule("SpaceBeforeBinaryKeywordOperator", anyToken, binaryKeywordOperators, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
98
+ rule("SpaceAfterBinaryKeywordOperator", binaryKeywordOperators, anyToken, [isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
99
+ // Na tag, também o espaço depois do operador `void` (CK-63).
100
+ // Async-await
101
+ rule("SpaceBetweenAsyncAndOpenParen", SyntaxKind.AsyncKeyword, SyntaxKind.OpenParenToken, [isArrowFunctionContext, isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
102
+ // Na tag, também o espaço entre o `async` e o `function` (CK-02).
103
+ rule("SpaceBetweenAsyncAndFunctionKeyword", SyntaxKind.AsyncKeyword, [SyntaxKind.Identifier], [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
104
+ // Na tag, também o espaço entre a tag e o template marcado (CK-02).
105
+ // JSX opening elements
106
+ rule("SpaceBeforeJsxAttribute", anyToken, SyntaxKind.Identifier, [isNextTokenParentJsxAttribute, isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
107
+ rule("SpaceBeforeSlashInJsxOpeningElement", anyToken, SyntaxKind.SlashToken, [isJsxSelfClosingElementContext, isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
108
+ rule("NoSpaceBeforeGreaterThanTokenInJsxOpeningElement", SyntaxKind.SlashToken, SyntaxKind.GreaterThanToken, [isJsxSelfClosingElementContext, isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
109
+ rule("NoSpaceBeforeEqualInJsxAttribute", anyToken, SyntaxKind.EqualsToken, [isJsxAttributeContext, isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
110
+ rule("NoSpaceAfterEqualInJsxAttribute", SyntaxKind.EqualsToken, anyToken, [isJsxAttributeContext, isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
111
+ // TypeScript-specific rules
112
+ // Na tag, também o `module("m")` e o `require("m")` de um `import =` (CK-03).
113
+ // Add a space around certain TypeScript keywords
114
+ // Na tag, também depois das palavras da classe, da interface, do enum, do acessor e do `module` (CK-02, CK-56).
115
+ rule("SpaceAfterCertainTypeScriptKeywords", [
116
+ SyntaxKind.DeclareKeyword,
117
+ SyntaxKind.DefaultKeyword,
118
+ SyntaxKind.ExportKeyword,
119
+ SyntaxKind.ExtendsKeyword,
120
+ SyntaxKind.ImportKeyword,
121
+ SyntaxKind.NamespaceKeyword,
122
+ SyntaxKind.ReadonlyKeyword,
123
+ SyntaxKind.TypeKeyword,
124
+ SyntaxKind.FromKeyword,
125
+ SyntaxKind.KeyOfKeyword,
126
+ SyntaxKind.InferKeyword,
127
+ ], anyToken, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
128
+ // Na tag, também antes do `implements` (CK-02).
129
+ rule("SpaceBeforeCertainTypeScriptKeywords", anyToken, [SyntaxKind.ExtendsKeyword, SyntaxKind.FromKeyword], [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
130
+ // Na tag, também o espaço depois do nome em string de um `module "m" {` (CK-02).
131
+ // Lambda expressions
132
+ rule("SpaceBeforeArrow", anyToken, SyntaxKind.EqualsGreaterThanToken, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
133
+ rule("SpaceAfterArrow", SyntaxKind.EqualsGreaterThanToken, anyToken, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
134
+ // Optional parameters and let args
135
+ rule("NoSpaceAfterEllipsis", SyntaxKind.DotDotDotToken, SyntaxKind.Identifier, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
136
+ rule("NoSpaceAfterOptionalParameters", SyntaxKind.QuestionToken, [SyntaxKind.CloseParenToken, SyntaxKind.CommaToken], [isNonJsxSameLineTokenContext, isNotBinaryOpContext], 16 /* RuleAction.DeleteSpace */),
137
+ // Remove spaces in empty interface literals. e.g.: x: {}
138
+ rule("NoSpaceBetweenEmptyInterfaceBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isNonJsxSameLineTokenContext, isObjectTypeContext], 16 /* RuleAction.DeleteSpace */),
139
+ // generics and type assertions
140
+ rule("NoSpaceBeforeOpenAngularBracket", typeNames, SyntaxKind.LessThanToken, [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext], 16 /* RuleAction.DeleteSpace */),
141
+ rule("NoSpaceBetweenCloseParenAndAngularBracket", SyntaxKind.CloseParenToken, SyntaxKind.LessThanToken, [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext], 16 /* RuleAction.DeleteSpace */),
142
+ rule("NoSpaceAfterOpenAngularBracket", SyntaxKind.LessThanToken, anyToken, [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext], 16 /* RuleAction.DeleteSpace */),
143
+ rule("NoSpaceBeforeCloseAngularBracket", anyToken, SyntaxKind.GreaterThanToken, [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext], 16 /* RuleAction.DeleteSpace */),
144
+ rule("NoSpaceAfterCloseAngularBracket", SyntaxKind.GreaterThanToken, [SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.GreaterThanToken, SyntaxKind.CommaToken], [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext, isNotFunctionDeclContext /*To prevent an interference with the SpaceBeforeOpenParenInFuncDecl rule*/], 16 /* RuleAction.DeleteSpace */),
145
+ // Na tag, também os espaços do decorator, o do `x!` e o do `new` de uma construct signature (CK-02).
146
+ rule("SpaceLessThanAndNonJSXTypeAnnotation", SyntaxKind.LessThanToken, SyntaxKind.LessThanToken, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
147
+ ];
148
+ // These rules are applied after high priority
149
+ const userConfigurableRules = [
150
+ // Na tag, também o espaço depois do `constructor` (CK-02).
151
+ rule("SpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionEnabled("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNextTokenNotCloseBracket, isNextTokenNotCloseParen], 4 /* RuleAction.InsertSpace */),
152
+ rule("NoSpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext], 16 /* RuleAction.DeleteSpace */),
153
+ // Na tag, também o espaço depois do `function` e da estrela do generator de uma function expression (CK-02).
154
+ // Insert space after keywords in control flow statements
155
+ rule("SpaceAfterKeywordInControl", keywords, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterKeywordsInControlFlowStatements"), isControlDeclContext], 4 /* RuleAction.InsertSpace */),
156
+ rule("NoSpaceAfterKeywordInControl", keywords, SyntaxKind.OpenParenToken, [isOptionDisabledOrUndefined("insertSpaceAfterKeywordsInControlFlowStatements"), isControlDeclContext], 16 /* RuleAction.DeleteSpace */),
157
+ // Insert space after opening and before closing nonempty parenthesis
158
+ rule("SpaceAfterOpenParen", SyntaxKind.OpenParenToken, anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis"), isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
159
+ rule("SpaceBeforeCloseParen", anyToken, SyntaxKind.CloseParenToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis"), isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
160
+ rule("SpaceBetweenOpenParens", SyntaxKind.OpenParenToken, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis"), isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
161
+ rule("NoSpaceBetweenParens", SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
162
+ rule("NoSpaceAfterOpenParen", SyntaxKind.OpenParenToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
163
+ rule("NoSpaceBeforeCloseParen", anyToken, SyntaxKind.CloseParenToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
164
+ // Insert space after opening and before closing nonempty brackets
165
+ rule("SpaceAfterOpenBracket", SyntaxKind.OpenBracketToken, anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets"), isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
166
+ rule("SpaceBeforeCloseBracket", anyToken, SyntaxKind.CloseBracketToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets"), isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
167
+ rule("NoSpaceBetweenBrackets", SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
168
+ rule("NoSpaceAfterOpenBracket", SyntaxKind.OpenBracketToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
169
+ rule("NoSpaceBeforeCloseBracket", anyToken, SyntaxKind.CloseBracketToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
170
+ // Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}.
171
+ rule("SpaceAfterOpenBrace", SyntaxKind.OpenBraceToken, anyToken, [isOptionEnabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"), isBraceWrappedContext], 4 /* RuleAction.InsertSpace */),
172
+ rule("SpaceBeforeCloseBrace", anyToken, SyntaxKind.CloseBraceToken, [isOptionEnabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"), isBraceWrappedContext], 4 /* RuleAction.InsertSpace */),
173
+ rule("NoSpaceBetweenEmptyBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isNonJsxSameLineTokenContext, isObjectContext], 16 /* RuleAction.DeleteSpace */),
174
+ rule("NoSpaceAfterOpenBrace", SyntaxKind.OpenBraceToken, anyToken, [isOptionDisabled("insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
175
+ rule("NoSpaceBeforeCloseBrace", anyToken, SyntaxKind.CloseBraceToken, [isOptionDisabled("insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
176
+ // Insert a space after opening and before closing empty brace brackets
177
+ rule("SpaceBetweenEmptyBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingEmptyBraces")], 4 /* RuleAction.InsertSpace */),
178
+ rule("NoSpaceBetweenEmptyBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isOptionDisabled("insertSpaceAfterOpeningAndBeforeClosingEmptyBraces"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
179
+ // Insert space after opening and before closing template string braces
180
+ rule("SpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
181
+ rule("SpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
182
+ rule("NoSpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
183
+ rule("NoSpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
184
+ // No space after { and before } in JSX expression
185
+ rule("SpaceAfterOpenBraceInJsxExpression", SyntaxKind.OpenBraceToken, anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces"), isNonJsxSameLineTokenContext, isJsxExpressionContext], 4 /* RuleAction.InsertSpace */),
186
+ rule("SpaceBeforeCloseBraceInJsxExpression", anyToken, SyntaxKind.CloseBraceToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces"), isNonJsxSameLineTokenContext, isJsxExpressionContext], 4 /* RuleAction.InsertSpace */),
187
+ rule("NoSpaceAfterOpenBraceInJsxExpression", SyntaxKind.OpenBraceToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces"), isNonJsxSameLineTokenContext, isJsxExpressionContext], 16 /* RuleAction.DeleteSpace */),
188
+ rule("NoSpaceBeforeCloseBraceInJsxExpression", anyToken, SyntaxKind.CloseBraceToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces"), isNonJsxSameLineTokenContext, isJsxExpressionContext], 16 /* RuleAction.DeleteSpace */),
189
+ // Insert space after semicolon in for statement
190
+ rule("SpaceAfterSemicolonInFor", SyntaxKind.SemicolonToken, anyToken, [isOptionEnabled("insertSpaceAfterSemicolonInForStatements"), isNonJsxSameLineTokenContext, isForContext], 4 /* RuleAction.InsertSpace */),
191
+ rule("NoSpaceAfterSemicolonInFor", SyntaxKind.SemicolonToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterSemicolonInForStatements"), isNonJsxSameLineTokenContext, isForContext], 16 /* RuleAction.DeleteSpace */),
192
+ // Insert space before and after binary operators
193
+ rule("SpaceBeforeBinaryOperator", anyToken, binaryOperators, [isOptionEnabled("insertSpaceBeforeAndAfterBinaryOperators"), isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
194
+ rule("SpaceAfterBinaryOperator", binaryOperators, anyToken, [isOptionEnabled("insertSpaceBeforeAndAfterBinaryOperators"), isNonJsxSameLineTokenContext, isBinaryOpContext], 4 /* RuleAction.InsertSpace */),
195
+ rule("NoSpaceBeforeBinaryOperator", anyToken, binaryOperators, [isOptionDisabledOrUndefined("insertSpaceBeforeAndAfterBinaryOperators"), isNonJsxSameLineTokenContext, isBinaryOpContext], 16 /* RuleAction.DeleteSpace */),
196
+ rule("NoSpaceAfterBinaryOperator", binaryOperators, anyToken, [isOptionDisabledOrUndefined("insertSpaceBeforeAndAfterBinaryOperators"), isNonJsxSameLineTokenContext, isBinaryOpContext], 16 /* RuleAction.DeleteSpace */),
197
+ rule("SpaceBeforeOpenParenInFuncDecl", anyToken, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceBeforeFunctionParenthesis"), isNonJsxSameLineTokenContext, isFunctionDeclContext], 4 /* RuleAction.InsertSpace */),
198
+ rule("NoSpaceBeforeOpenParenInFuncDecl", anyToken, SyntaxKind.OpenParenToken, [isOptionDisabledOrUndefined("insertSpaceBeforeFunctionParenthesis"), isNonJsxSameLineTokenContext, isFunctionDeclContext], 16 /* RuleAction.DeleteSpace */),
199
+ // Open Brace braces after control block
200
+ rule("NewLineBeforeOpenBraceInControl", controlOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken, [isOptionEnabled("placeOpenBraceOnNewLineForControlBlocks"), isControlDeclContext, isBeforeMultilineBlockContext], 8 /* RuleAction.InsertNewLine */, 1 /* RuleFlags.CanDeleteNewLines */),
201
+ // Open Brace braces after function
202
+ // TypeScript: Function can have return types, which can be made of tons of different token kinds
203
+ rule("NewLineBeforeOpenBraceInFunction", functionOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken, [isOptionEnabled("placeOpenBraceOnNewLineForFunctions"), isFunctionDeclContext, isBeforeMultilineBlockContext], 8 /* RuleAction.InsertNewLine */, 1 /* RuleFlags.CanDeleteNewLines */),
204
+ // Open Brace braces after TypeScript module/class/interface
205
+ rule("NewLineBeforeOpenBraceInTypeScriptDeclWithBlock", typeScriptOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken, [isOptionEnabled("placeOpenBraceOnNewLineForFunctions"), isTypeScriptDeclWithBlockContext, isBeforeMultilineBlockContext], 8 /* RuleAction.InsertNewLine */, 1 /* RuleFlags.CanDeleteNewLines */),
206
+ // Na tag, também o espaço depois da asserção de tipo `<T>x` (CK-02).
207
+ rule("SpaceBeforeTypeAnnotation", anyToken, SyntaxKind.ColonToken, [isOptionEnabled("insertSpaceBeforeTypeAnnotation"), isNonJsxSameLineTokenContext, isTypeAnnotationContext], 4 /* RuleAction.InsertSpace */),
208
+ rule("NoSpaceBeforeTypeAnnotation", anyToken, SyntaxKind.ColonToken, [isOptionDisabledOrUndefined("insertSpaceBeforeTypeAnnotation"), isNonJsxSameLineTokenContext, isTypeAnnotationContext], 16 /* RuleAction.DeleteSpace */),
209
+ rule("NoOptionalSemicolon", SyntaxKind.SemicolonToken, anyTokenIncludingEOF, [optionEquals("semicolons", SemicolonPreference.Remove), isSemicolonDeletionContext], 32 /* RuleAction.DeleteToken */),
210
+ rule("OptionalSemicolon", anyToken, anyTokenIncludingEOF, [optionEquals("semicolons", SemicolonPreference.Insert), isSemicolonInsertionContext], 64 /* RuleAction.InsertTrailingSemicolon */),
211
+ ];
212
+ // These rules are lower in priority than user-configurable. Rules earlier in this list have priority over rules later in the list.
213
+ const lowPriorityCommonRules = [
214
+ // Space after keyword but not before ; or : or ?
215
+ rule("NoSpaceBeforeSemicolon", anyToken, SyntaxKind.SemicolonToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
216
+ rule("SpaceBeforeOpenBraceInControl", controlOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken, [isOptionDisabledOrUndefinedOrTokensOnSameLine("placeOpenBraceOnNewLineForControlBlocks"), isControlDeclContext, isNotFormatOnEnter, isSameLineTokenOrBeforeBlockContext], 4 /* RuleAction.InsertSpace */, 1 /* RuleFlags.CanDeleteNewLines */),
217
+ rule("SpaceBeforeOpenBraceInFunction", functionOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken, [isOptionDisabledOrUndefinedOrTokensOnSameLine("placeOpenBraceOnNewLineForFunctions"), isFunctionDeclContext, isBeforeBlockContext, isNotFormatOnEnter, isSameLineTokenOrBeforeBlockContext], 4 /* RuleAction.InsertSpace */, 1 /* RuleFlags.CanDeleteNewLines */),
218
+ rule("SpaceBeforeOpenBraceInTypeScriptDeclWithBlock", typeScriptOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken, [isOptionDisabledOrUndefinedOrTokensOnSameLine("placeOpenBraceOnNewLineForFunctions"), isTypeScriptDeclWithBlockContext, isNotFormatOnEnter, isSameLineTokenOrBeforeBlockContext], 4 /* RuleAction.InsertSpace */, 1 /* RuleFlags.CanDeleteNewLines */),
219
+ rule("NoSpaceBeforeComma", anyToken, SyntaxKind.CommaToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
220
+ // No space before and after indexer `x[]`
221
+ rule("NoSpaceBeforeOpenBracket", anyTokenExcept(SyntaxKind.AsyncKeyword, SyntaxKind.CaseKeyword), SyntaxKind.OpenBracketToken, [isNonJsxSameLineTokenContext], 16 /* RuleAction.DeleteSpace */),
222
+ rule("NoSpaceAfterCloseBracket", SyntaxKind.CloseBracketToken, anyToken, [isNonJsxSameLineTokenContext, isNotBeforeBlockInFunctionDeclarationContext], 16 /* RuleAction.DeleteSpace */),
223
+ rule("SpaceAfterSemicolon", SyntaxKind.SemicolonToken, anyToken, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
224
+ // Remove extra space between for and await
225
+ rule("SpaceBetweenForAndAwaitKeyword", SyntaxKind.ForKeyword, SyntaxKind.AwaitKeyword, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
226
+ // Add a space between statements. All keywords except (do,else,case) has open/close parens after them.
227
+ // So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any]
228
+ rule("SpaceBetweenStatements", [SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword], anyToken, [isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNotForContext], 4 /* RuleAction.InsertSpace */),
229
+ // This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
230
+ rule("SpaceAfterTryFinally", [SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword], SyntaxKind.OpenBraceToken, [isNonJsxSameLineTokenContext], 4 /* RuleAction.InsertSpace */),
231
+ ];
232
+ return [
233
+ ...highPriorityCommonRules,
234
+ ...userConfigurableRules,
235
+ ...lowPriorityCommonRules,
236
+ ];
237
+ }
238
+ /**
239
+ * A rule takes a two tokens (left/right) and a particular context
240
+ * for which you're meant to look at them. You then declare what should the
241
+ * whitespace annotation be between these tokens via the action param.
242
+ *
243
+ * @param debugName Name to print
244
+ * @param left The left side of the comparison
245
+ * @param right The right side of the comparison
246
+ * @param context A set of filters to narrow down the space in which this formatter rule applies
247
+ * @param action a declaration of the expected whitespace
248
+ * @param flags whether the rule deletes a line or not, defaults to no-op
249
+ */
250
+ function rule(debugName, left, right, context, action, flags = 0 /* RuleFlags.None */) {
251
+ return { leftTokenRange: toTokenRange(left), rightTokenRange: toTokenRange(right), rule: { debugName, context, action, flags } };
252
+ }
253
+ function tokenRangeFrom(tokens) {
254
+ return { tokens, isSpecific: true };
255
+ }
256
+ function toTokenRange(arg) {
257
+ return typeof arg === "number" ? tokenRangeFrom([arg]) : isArray(arg) ? tokenRangeFrom(arg) : arg;
258
+ }
259
+ function tokenRangeFromRange(from, to, except = []) {
260
+ const tokens = [];
261
+ for (let token = from; token <= to; token++) {
262
+ if (!contains(except, token)) {
263
+ tokens.push(token);
264
+ }
265
+ }
266
+ return tokenRangeFrom(tokens);
267
+ }
268
+ ///
269
+ /// Contexts
270
+ ///
271
+ function optionEquals(optionName, optionValue) {
272
+ return (context) => context.options && context.options[optionName] === optionValue;
273
+ }
274
+ function isOptionEnabled(optionName) {
275
+ return (context) => context.options && context.options.hasOwnProperty(optionName) && !!context.options[optionName];
276
+ }
277
+ function isOptionDisabled(optionName) {
278
+ return (context) => context.options && context.options.hasOwnProperty(optionName) && !context.options[optionName];
279
+ }
280
+ function isOptionDisabledOrUndefined(optionName) {
281
+ return (context) => !context.options || !context.options.hasOwnProperty(optionName) || !context.options[optionName];
282
+ }
283
+ function isOptionDisabledOrUndefinedOrTokensOnSameLine(optionName) {
284
+ return (context) => !context.options || !context.options.hasOwnProperty(optionName) || !context.options[optionName] || context.TokensAreOnSameLine();
285
+ }
286
+ function isOptionEnabledOrUndefined(optionName) {
287
+ return (context) => !context.options || !context.options.hasOwnProperty(optionName) || !!context.options[optionName];
288
+ }
289
+ function isForContext(context) {
290
+ return context.contextNode.kind === SyntaxKind.ForStatement;
291
+ }
292
+ function isNotForContext(context) {
293
+ return !isForContext(context);
294
+ }
295
+ function isBinaryOpContext(context) {
296
+ switch (context.contextNode.kind) {
297
+ case SyntaxKind.BinaryExpression:
298
+ return context.contextNode.operatorToken.kind !== SyntaxKind.CommaToken;
299
+ case SyntaxKind.ConditionalExpression:
300
+ case SyntaxKind.ConditionalType:
301
+ case SyntaxKind.AsExpression:
302
+ case SyntaxKind.ExportSpecifier:
303
+ case SyntaxKind.ImportSpecifier:
304
+ case SyntaxKind.TypePredicate:
305
+ case SyntaxKind.UnionType:
306
+ case SyntaxKind.IntersectionType:
307
+ return true;
308
+ // equals in binding elements: function foo([[x, y] = [1, 2]])
309
+ case SyntaxKind.BindingElement:
310
+ // equals in type X = ...
311
+ // falls through
312
+ case SyntaxKind.TypeAliasDeclaration:
313
+ // Na tag, também o `=` do `import =` (CK-03).
314
+ // equal in let a = 0
315
+ // falls through
316
+ case SyntaxKind.VariableDeclaration:
317
+ // equal in p = 0
318
+ // falls through
319
+ case SyntaxKind.Parameter:
320
+ // Na tag, também o membro de enum e a propriedade de classe (CK-02).
321
+ case SyntaxKind.PropertySignature:
322
+ return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken;
323
+ // "in" keyword in for (let x in []) { }
324
+ case SyntaxKind.ForInStatement:
325
+ // "in" keyword in [P in keyof T]: T[P]
326
+ // falls through
327
+ case SyntaxKind.TypeParameter:
328
+ return context.currentTokenSpan.kind === SyntaxKind.InKeyword || context.nextTokenSpan.kind === SyntaxKind.InKeyword || context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken;
329
+ // Technically, "of" is not a binary operator, but format it the same way as "in"
330
+ case SyntaxKind.ForOfStatement:
331
+ return context.currentTokenSpan.kind === SyntaxKind.OfKeyword || context.nextTokenSpan.kind === SyntaxKind.OfKeyword;
332
+ }
333
+ return false;
334
+ }
335
+ function isNotBinaryOpContext(context) {
336
+ return !isBinaryOpContext(context);
337
+ }
338
+ function isNotTypeAnnotationContext(context) {
339
+ return !isTypeAnnotationContext(context);
340
+ }
341
+ function isTypeAnnotationContext(context) {
342
+ const contextKind = context.contextNode.kind;
343
+ // Na tag, também a propriedade de classe (CK-02).
344
+ return contextKind === SyntaxKind.PropertySignature ||
345
+ contextKind === SyntaxKind.Parameter ||
346
+ contextKind === SyntaxKind.VariableDeclaration ||
347
+ isFunctionLikeKind(contextKind);
348
+ }
349
+ function isConditionalOperatorContext(context) {
350
+ return context.contextNode.kind === SyntaxKind.ConditionalExpression ||
351
+ context.contextNode.kind === SyntaxKind.ConditionalType;
352
+ }
353
+ function isSameLineTokenOrBeforeBlockContext(context) {
354
+ return context.TokensAreOnSameLine() || isBeforeBlockContext(context);
355
+ }
356
+ function isBraceWrappedContext(context) {
357
+ return context.contextNode.kind === SyntaxKind.ObjectBindingPattern ||
358
+ context.contextNode.kind === SyntaxKind.MappedType ||
359
+ isSingleLineBlockContext(context);
360
+ }
361
+ // This check is done before an open brace in a control construct, a function, or a typescript block declaration
362
+ function isBeforeMultilineBlockContext(context) {
363
+ return isBeforeBlockContext(context) && !(context.NextNodeAllOnSameLine() || context.NextNodeBlockIsOnOneLine());
364
+ }
365
+ function isMultilineBlockContext(context) {
366
+ return isBlockContext(context) && !(context.ContextNodeAllOnSameLine() || context.ContextNodeBlockIsOnOneLine());
367
+ }
368
+ function isSingleLineBlockContext(context) {
369
+ return isBlockContext(context) && (context.ContextNodeAllOnSameLine() || context.ContextNodeBlockIsOnOneLine());
370
+ }
371
+ function isBlockContext(context) {
372
+ return nodeIsBlockContext(context.contextNode);
373
+ }
374
+ function isBeforeBlockContext(context) {
375
+ return nodeIsBlockContext(context.nextTokenParent);
376
+ }
377
+ // IMPORTANT!!! This method must return true ONLY for nodes with open and close braces as immediate children
378
+ function nodeIsBlockContext(node) {
379
+ if (nodeIsTypeScriptDeclWithBlockContext(node)) {
380
+ // This means we are in a context that looks like a block to the user, but in the grammar is actually not a node (it's a class, module, enum, object type literal, etc).
381
+ return true;
382
+ }
383
+ switch (node.kind) {
384
+ case SyntaxKind.Block:
385
+ case SyntaxKind.CaseBlock:
386
+ case SyntaxKind.ObjectLiteralExpression:
387
+ case SyntaxKind.ModuleBlock:
388
+ return true;
389
+ }
390
+ return false;
391
+ }
392
+ function isFunctionDeclContext(context) {
393
+ switch (context.contextNode.kind) {
394
+ // Na tag, também a `function`, o método, a method signature, o acessor, a function expression, o construtor e a
395
+ // interface, que para a formatação agia como uma função (CK-02, CK-36).
396
+ case SyntaxKind.CallSignature:
397
+ case SyntaxKind.ArrowFunction:
398
+ return true;
399
+ }
400
+ return false;
401
+ }
402
+ function isNotFunctionDeclContext(context) {
403
+ return !isFunctionDeclContext(context);
404
+ }
405
+ // Na tag, também o contexto da `function` e da function expression, que só as regras da estrela do generator liam (CK-02).
406
+ function isTypeScriptDeclWithBlockContext(context) {
407
+ return nodeIsTypeScriptDeclWithBlockContext(context.contextNode);
408
+ }
409
+ function nodeIsTypeScriptDeclWithBlockContext(node) {
410
+ switch (node.kind) {
411
+ // Na tag, também a classe, a class expression, a interface e o enum (CK-02).
412
+ case SyntaxKind.TypeLiteral:
413
+ case SyntaxKind.ModuleDeclaration:
414
+ case SyntaxKind.ExportDeclaration:
415
+ case SyntaxKind.NamedExports:
416
+ case SyntaxKind.ImportDeclaration:
417
+ case SyntaxKind.NamedImports:
418
+ return true;
419
+ }
420
+ return false;
421
+ }
422
+ function isAfterCodeBlockContext(context) {
423
+ switch (context.currentTokenParent.kind) {
424
+ // Na tag, também a classe e o enum (CK-02).
425
+ case SyntaxKind.ModuleDeclaration:
426
+ case SyntaxKind.CatchClause:
427
+ case SyntaxKind.ModuleBlock:
428
+ case SyntaxKind.SwitchStatement:
429
+ return true;
430
+ case SyntaxKind.Block: {
431
+ const blockParent = context.currentTokenParent.parent;
432
+ // In a codefix scenario, we can't rely on parents being set. So just always return true.
433
+ // Na tag, também o corpo de uma function expression (CK-02).
434
+ if (!blockParent || blockParent.kind !== SyntaxKind.ArrowFunction) {
435
+ return true;
436
+ }
437
+ }
438
+ }
439
+ return false;
440
+ }
441
+ function isControlDeclContext(context) {
442
+ switch (context.contextNode.kind) {
443
+ case SyntaxKind.IfStatement:
444
+ case SyntaxKind.SwitchStatement:
445
+ case SyntaxKind.ForStatement:
446
+ case SyntaxKind.ForInStatement:
447
+ case SyntaxKind.ForOfStatement:
448
+ case SyntaxKind.WhileStatement:
449
+ case SyntaxKind.TryStatement:
450
+ case SyntaxKind.DoStatement:
451
+ // Na tag, também o `with` (CK-02).
452
+ // TODO
453
+ // case SyntaxKind.ElseClause:
454
+ // falls through
455
+ case SyntaxKind.CatchClause:
456
+ return true;
457
+ default:
458
+ return false;
459
+ }
460
+ }
461
+ function isObjectContext(context) {
462
+ return context.contextNode.kind === SyntaxKind.ObjectLiteralExpression;
463
+ }
464
+ function isFunctionCallContext(context) {
465
+ return context.contextNode.kind === SyntaxKind.CallExpression;
466
+ }
467
+ /** A chamada. Na tag, também o `new` (CK-02). */
468
+ function isFunctionCallOrNewContext(context) {
469
+ return isFunctionCallContext(context);
470
+ }
471
+ function isPreviousTokenNotComma(context) {
472
+ return context.currentTokenSpan.kind !== SyntaxKind.CommaToken;
473
+ }
474
+ function isNextTokenNotCloseBracket(context) {
475
+ return context.nextTokenSpan.kind !== SyntaxKind.CloseBracketToken;
476
+ }
477
+ function isNextTokenNotCloseParen(context) {
478
+ return context.nextTokenSpan.kind !== SyntaxKind.CloseParenToken;
479
+ }
480
+ function isArrowFunctionContext(context) {
481
+ return context.contextNode.kind === SyntaxKind.ArrowFunction;
482
+ }
483
+ function isImportTypeContext(context) {
484
+ return context.contextNode.kind === SyntaxKind.ImportType;
485
+ }
486
+ function isNonJsxSameLineTokenContext(context) {
487
+ return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
488
+ }
489
+ function isNonJsxElementOrFragmentContext(context) {
490
+ return context.contextNode.kind !== SyntaxKind.JsxElement && context.contextNode.kind !== SyntaxKind.JsxFragment;
491
+ }
492
+ function isJsxExpressionContext(context) {
493
+ return context.contextNode.kind === SyntaxKind.JsxExpression || context.contextNode.kind === SyntaxKind.JsxSpreadAttribute;
494
+ }
495
+ function isNextTokenParentJsxAttribute(context) {
496
+ return context.nextTokenParent.kind === SyntaxKind.JsxAttribute;
497
+ }
498
+ function isJsxAttributeContext(context) {
499
+ return context.contextNode.kind === SyntaxKind.JsxAttribute;
500
+ }
501
+ function isJsxSelfClosingElementContext(context) {
502
+ return context.contextNode.kind === SyntaxKind.JsxSelfClosingElement;
503
+ }
504
+ function isNotBeforeBlockInFunctionDeclarationContext(context) {
505
+ return !isFunctionDeclContext(context) && !isBeforeBlockContext(context);
506
+ }
507
+ // Na tag, também o contexto do fim de um decorator (CK-02).
508
+ function isStartOfVariableDeclarationList(context) {
509
+ return context.currentTokenParent.kind === SyntaxKind.VariableDeclarationList &&
510
+ context.currentTokenParent.getStart(context.sourceFile) === context.currentTokenSpan.pos;
511
+ }
512
+ function isNotFormatOnEnter(context) {
513
+ return context.formattingRequestKind !== 2 /* FormattingRequestKind.FormatOnEnter */;
514
+ }
515
+ // Na tag, também o contexto do `module "m"`, que só a regra do nome em string lia (CK-02).
516
+ function isObjectTypeContext(context) {
517
+ return context.contextNode.kind === SyntaxKind.TypeLiteral; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration;
518
+ }
519
+ // Na tag, também o contexto da construct signature (CK-02).
520
+ function isTypeArgumentOrParameterOrAssertion(token, parent) {
521
+ if (token.kind !== SyntaxKind.LessThanToken && token.kind !== SyntaxKind.GreaterThanToken) {
522
+ return false;
523
+ }
524
+ switch (parent.kind) {
525
+ // Na tag, também a asserção de tipo `<T>x`, a classe, a class expression, a interface, a `function`, a function
526
+ // expression, o método, a construct signature, o `new` e a herança (CK-02), e a method signature (CK-36).
527
+ case SyntaxKind.TypeReference:
528
+ case SyntaxKind.TypeAliasDeclaration:
529
+ case SyntaxKind.ArrowFunction:
530
+ case SyntaxKind.CallSignature:
531
+ case SyntaxKind.CallExpression:
532
+ return true;
533
+ default:
534
+ return false;
535
+ }
536
+ }
537
+ function isTypeArgumentOrParameterOrAssertionContext(context) {
538
+ return isTypeArgumentOrParameterOrAssertion(context.currentTokenSpan, context.currentTokenParent) ||
539
+ isTypeArgumentOrParameterOrAssertion(context.nextTokenSpan, context.nextTokenParent);
540
+ }
541
+ // Na tag, também os contextos da asserção de tipo `<T>x`, do operador `void`, do `yield` e do `x!` (CK-02, CK-63).
542
+ function isNotStatementConditionContext(context) {
543
+ return !isStatementConditionContext(context);
544
+ }
545
+ function isStatementConditionContext(context) {
546
+ switch (context.contextNode.kind) {
547
+ case SyntaxKind.IfStatement:
548
+ case SyntaxKind.ForStatement:
549
+ case SyntaxKind.ForInStatement:
550
+ case SyntaxKind.ForOfStatement:
551
+ case SyntaxKind.DoStatement:
552
+ case SyntaxKind.WhileStatement:
553
+ return true;
554
+ default:
555
+ return false;
556
+ }
557
+ }
558
+ function isSemicolonDeletionContext(context) {
559
+ let nextTokenKind = context.nextTokenSpan.kind;
560
+ let nextTokenStart = context.nextTokenSpan.pos;
561
+ if (isTrivia(nextTokenKind)) {
562
+ const nextRealToken = context.nextTokenParent === context.currentTokenParent
563
+ ? findNextToken(context.currentTokenParent, findAncestor(context.currentTokenParent, a => !a.parent), context.sourceFile)
564
+ : context.nextTokenParent.getFirstToken(context.sourceFile);
565
+ if (!nextRealToken) {
566
+ return true;
567
+ }
568
+ nextTokenKind = nextRealToken.kind;
569
+ nextTokenStart = nextRealToken.getStart(context.sourceFile);
570
+ }
571
+ const startLine = context.sourceFile.getLineAndCharacterOfPosition(context.currentTokenSpan.pos).line;
572
+ const endLine = context.sourceFile.getLineAndCharacterOfPosition(nextTokenStart).line;
573
+ if (startLine === endLine) {
574
+ return nextTokenKind === SyntaxKind.CloseBraceToken
575
+ || nextTokenKind === SyntaxKind.EndOfFileToken;
576
+ }
577
+ // Na tag, também o `;` solto no corpo de uma classe (CK-02).
578
+ if (nextTokenKind === SyntaxKind.SemicolonToken) {
579
+ return false;
580
+ }
581
+ // Na tag, também o corpo de uma interface (CK-02).
582
+ if (context.contextNode.kind === SyntaxKind.TypeAliasDeclaration) {
583
+ // Can’t remove semicolon after `foo`; it would parse as a method declaration:
584
+ //
585
+ // interface I {
586
+ // foo;
587
+ // (): void
588
+ // }
589
+ return !isPropertySignature(context.currentTokenParent)
590
+ || !!context.currentTokenParent.type
591
+ || nextTokenKind !== SyntaxKind.OpenParenToken;
592
+ }
593
+ // Na tag, também a propriedade de classe sem inicializador (CK-02).
594
+ // Na tag, também o `;` solto no corpo de uma classe e o literal de regex (CK-02).
595
+ return context.currentTokenParent.kind !== SyntaxKind.ForStatement
596
+ && context.currentTokenParent.kind !== SyntaxKind.EmptyStatement
597
+ && nextTokenKind !== SyntaxKind.OpenBracketToken
598
+ && nextTokenKind !== SyntaxKind.OpenParenToken
599
+ && nextTokenKind !== SyntaxKind.PlusToken
600
+ && nextTokenKind !== SyntaxKind.MinusToken
601
+ && nextTokenKind !== SyntaxKind.SlashToken
602
+ && nextTokenKind !== SyntaxKind.CommaToken
603
+ && nextTokenKind !== SyntaxKind.TemplateExpression
604
+ && nextTokenKind !== SyntaxKind.TemplateHead
605
+ && nextTokenKind !== SyntaxKind.NoSubstitutionTemplateLiteral
606
+ && nextTokenKind !== SyntaxKind.DotToken;
607
+ }
608
+ function isSemicolonInsertionContext(context) {
609
+ return positionIsASICandidate(context.currentTokenSpan.end, context.currentTokenParent, context.sourceFile);
610
+ }
@@ -0,0 +1,5 @@
1
+ import type { FormatCodeSettings, FormattingHost } from "../_namespaces/edit.js";
2
+ import { FormattingContext } from "../_namespaces/ts.formatting.js";
3
+ import type { FormatContext, Rule } from "../_namespaces/ts.formatting.js";
4
+ export declare function getFormatContext(options: FormatCodeSettings, host: FormattingHost): FormatContext;
5
+ export type RulesMap = (context: FormattingContext) => readonly Rule[] | undefined;