• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { FormattingContext } from "../_namespaces/ts.formatting";
2import { emptyArray, SyntaxKind } from "../_namespaces/ts";
3
4/** @internal */
5export interface Rule {
6    // Used for debugging to identify each rule based on the property name it's assigned to.
7    readonly debugName: string;
8    readonly context: readonly ContextPredicate[];
9    readonly action: RuleAction;
10    readonly flags: RuleFlags;
11}
12
13/** @internal */
14export type ContextPredicate = (context: FormattingContext) => boolean;
15/** @internal */
16export const anyContext: readonly ContextPredicate[] = emptyArray;
17
18/** @internal */
19export const enum RuleAction {
20    StopProcessingSpaceActions = 1 << 0,
21    StopProcessingTokenActions = 1 << 1,
22    InsertSpace                = 1 << 2,
23    InsertNewLine              = 1 << 3,
24    DeleteSpace                = 1 << 4,
25    DeleteToken                = 1 << 5,
26    InsertTrailingSemicolon    = 1 << 6,
27
28    StopAction = StopProcessingSpaceActions | StopProcessingTokenActions,
29    ModifySpaceAction = InsertSpace | InsertNewLine | DeleteSpace,
30    ModifyTokenAction = DeleteToken | InsertTrailingSemicolon,
31}
32
33/** @internal */
34export const enum RuleFlags {
35    None,
36    CanDeleteNewLines,
37}
38
39/** @internal */
40export interface TokenRange {
41    readonly tokens: readonly SyntaxKind[];
42    readonly isSpecific: boolean;
43}
44