coffeehaml 0.6.0 → 0.7.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.
@@ -0,0 +1,200 @@
1
+ /**
2
+ * CoffeeHaml Prettier Plugin — Formatting Options
3
+ *
4
+ * Every formatting feature is independently deactivatable.
5
+ * 'preserve', false, or -1 means "leave as-is, no intervention."
6
+ */
7
+ // ─── Category labels ───────────────────────────────────────
8
+ const CAT = {
9
+ STRUCTURE: 'CoffeeHaml: Structure',
10
+ ATTRIBUTES: 'CoffeeHaml: Attributes',
11
+ COFFEESCRIPT: 'CoffeeHaml: CoffeeScript',
12
+ WHITESPACE: 'CoffeeHaml: Whitespace',
13
+ CONTROL_FLOW: 'CoffeeHaml: Control Flow',
14
+ COMMENTS: 'CoffeeHaml: Comments',
15
+ };
16
+ // ─── Option definitions ────────────────────────────────────
17
+ /** Tag name case normalization. 'preserve' = leave as written. */
18
+ const tagCase = {
19
+ category: CAT.STRUCTURE,
20
+ type: 'choice',
21
+ description: 'Normalize HTML tag casing. Component tags (%MyComponent) never affected.',
22
+ choices: [
23
+ { value: 'preserve', description: 'Leave tag case as written' },
24
+ { value: 'lowercase', description: '%DIV to %div (HTML tags only)' },
25
+ ],
26
+ };
27
+ /** Expand .class to %div.class. */
28
+ const implicitDivExpansion = {
29
+ category: CAT.STRUCTURE,
30
+ type: 'boolean',
31
+ description: 'Expand .class to %div.class (anti-idiomatic in HAML).',
32
+ };
33
+ /** Max .class chain length before breaking into indented hierarchy. */
34
+ const maxChainLength = {
35
+ category: CAT.STRUCTURE,
36
+ type: 'int',
37
+ description: 'Max .class chain length before breaking into indented hierarchy. 0 = always break.',
38
+ };
39
+ /** Threshold for single-line vs multi-line layout. */
40
+ const inlineThreshold = {
41
+ category: CAT.STRUCTURE,
42
+ type: 'int',
43
+ description: 'Try single-line if estimated width <= this. -1 = never inline children.',
44
+ };
45
+ /** Self-closing style for void elements. */
46
+ const voidElementStyle = {
47
+ category: CAT.STRUCTURE,
48
+ type: 'choice',
49
+ description: 'How void elements (%br, %img, etc.) are formatted.',
50
+ choices: [
51
+ { value: 'self-closing', description: 'Self-closing (no children)' },
52
+ { value: 'explicit', description: 'Preserve %br/ syntax, otherwise self-close' },
53
+ ],
54
+ };
55
+ /** Enforce a specific attribute syntax style. */
56
+ const attributeStyle = {
57
+ category: CAT.ATTRIBUTES,
58
+ type: 'choice',
59
+ description: 'Enforce attribute syntax: {braces}, (parens), bare, or preserve.',
60
+ choices: [
61
+ { value: 'preserve', description: 'Keep as written' },
62
+ { value: 'braces', description: 'Convert to {CoffeeScript} style' },
63
+ { value: 'parens', description: 'Convert to HTML (parens) style' },
64
+ { value: 'bare', description: 'Convert to bare HAML style' },
65
+ ],
66
+ };
67
+ /** Number of attributes before forcing multiline layout. */
68
+ const attributeMultilineThreshold = {
69
+ category: CAT.ATTRIBUTES,
70
+ type: 'int',
71
+ description: 'Break attributes across lines when count >= this. 0 = always multiline.',
72
+ };
73
+ /** Sort attribute keys. */
74
+ const attributeSort = {
75
+ category: CAT.ATTRIBUTES,
76
+ type: 'choice',
77
+ description: 'Sort attribute keys (spread attributes always last).',
78
+ choices: [
79
+ { value: 'none', description: 'Preserve author order' },
80
+ { value: 'alphabetical', description: 'Sort A to Z' },
81
+ { value: 'idiomatic', description: 'id first, class second, rest A to Z' },
82
+ ],
83
+ };
84
+ /** Quote style for bare/HAML attributes. */
85
+ const quoteStyle = {
86
+ category: CAT.ATTRIBUTES,
87
+ type: 'choice',
88
+ description: 'Quote style for bare/HAML attributes.',
89
+ choices: [
90
+ { value: 'preserve', description: 'Keep as written' },
91
+ { value: 'double', description: 'Force double quotes' },
92
+ { value: 'single', description: 'Force single quotes' },
93
+ ],
94
+ };
95
+ /** Format embedded CoffeeScript via Prettier's CS plugin. */
96
+ const coffeeScriptFormat = {
97
+ category: CAT.COFFEESCRIPT,
98
+ type: 'boolean',
99
+ description: 'Format CoffeeScript expressions using prettier/plugins/coffeescript.',
100
+ };
101
+ /** Align chained method calls on newlines. */
102
+ const methodChainAlign = {
103
+ category: CAT.COFFEESCRIPT,
104
+ type: 'boolean',
105
+ description: 'Align .method chains on newlines for = expressions.',
106
+ };
107
+ /** Blank line handling between sibling elements. */
108
+ const blankLineHandling = {
109
+ category: CAT.WHITESPACE,
110
+ type: 'choice',
111
+ description: 'How blank lines between sibling elements are treated.',
112
+ choices: [
113
+ { value: 'preserve', description: 'Keep single; collapse multiples' },
114
+ { value: 'collapse', description: 'Remove all blank lines between siblings' },
115
+ { value: 'respect', description: 'Keep exactly as written' },
116
+ ],
117
+ };
118
+ /** Trailing whitespace handling. */
119
+ const trailingWhitespace = {
120
+ category: CAT.WHITESPACE,
121
+ type: 'choice',
122
+ description: 'Handle trailing whitespace.',
123
+ choices: [
124
+ { value: 'remove', description: 'Strip trailing whitespace' },
125
+ { value: 'preserve', description: 'Leave as written' },
126
+ ],
127
+ };
128
+ /** Control flow \\ continuation style. */
129
+ const continuationStyle = {
130
+ category: CAT.CONTROL_FLOW,
131
+ type: 'choice',
132
+ description: 'How \\ continuations are formatted.',
133
+ choices: [
134
+ { value: 'preserve', description: 'Keep as written' },
135
+ { value: 'indent', description: 'Always use indented continuation' },
136
+ { value: 'backslash', description: 'Always use \\ continuation' },
137
+ ],
138
+ };
139
+ /** Inline control flow with 'then'. */
140
+ const controlFlowInline = {
141
+ category: CAT.CONTROL_FLOW,
142
+ type: 'boolean',
143
+ description: 'Allow - if x then .ok one-liners (anti-Prettier by default).',
144
+ };
145
+ /** Merge consecutive standalone - statements into indented block. */
146
+ const statementMerging = {
147
+ category: CAT.CONTROL_FLOW,
148
+ type: 'choice',
149
+ description: 'Merge consecutive - lines into a single indented block. Only childless statements.',
150
+ choices: [
151
+ { value: 'preserve', description: 'Keep each - line separate' },
152
+ { value: 'merge', description: 'Merge consecutive childless statements into one indented block' },
153
+ ],
154
+ };
155
+ /** Reflow/format comment text. */
156
+ const commentFormat = {
157
+ category: CAT.COMMENTS,
158
+ type: 'boolean',
159
+ description: 'Reflow/word-wrap comment text (experimental).',
160
+ };
161
+ // ─── Exports ────────────────────────────────────────────────
162
+ export const options = {
163
+ tagCase,
164
+ implicitDivExpansion,
165
+ maxChainLength,
166
+ inlineThreshold,
167
+ voidElementStyle,
168
+ attributeStyle,
169
+ attributeMultilineThreshold,
170
+ attributeSort,
171
+ quoteStyle,
172
+ coffeeScriptFormat,
173
+ methodChainAlign,
174
+ blankLineHandling,
175
+ trailingWhitespace,
176
+ continuationStyle,
177
+ controlFlowInline,
178
+ statementMerging,
179
+ commentFormat,
180
+ };
181
+ export const defaultOptions = {
182
+ tagCase: 'preserve',
183
+ implicitDivExpansion: false,
184
+ maxChainLength: 4,
185
+ inlineThreshold: -1,
186
+ voidElementStyle: 'self-closing',
187
+ attributeStyle: 'preserve',
188
+ attributeMultilineThreshold: 1,
189
+ attributeSort: 'none',
190
+ quoteStyle: 'preserve',
191
+ coffeeScriptFormat: true,
192
+ methodChainAlign: true,
193
+ blankLineHandling: 'preserve',
194
+ trailingWhitespace: 'remove',
195
+ continuationStyle: 'indent',
196
+ controlFlowInline: false,
197
+ statementMerging: 'preserve',
198
+ commentFormat: false,
199
+ };
200
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/prettier/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,8DAA8D;AAE9D,MAAM,GAAG,GAAG;IACV,SAAS,EAAE,uBAAuB;IAClC,UAAU,EAAE,wBAAwB;IACpC,YAAY,EAAE,0BAA0B;IACxC,UAAU,EAAE,wBAAwB;IACpC,YAAY,EAAE,0BAA0B;IACxC,QAAQ,EAAE,sBAAsB;CACxB,CAAC;AAEX,8DAA8D;AAE9D,kEAAkE;AAClE,MAAM,OAAO,GAAkD;IAC7D,QAAQ,EAAE,GAAG,CAAC,SAAS;IACvB,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,0EAA0E;IACvF,OAAO,EAAE;QACP,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E,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,2BAA2B,EAAE;QAC/D,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,gEAAgE,EAAE;KAClG;CACF,CAAC;AAEF,kCAAkC;AAClC,MAAM,aAAa,GAAyB;IAC1C,QAAQ,EAAE,GAAG,CAAC,QAAQ;IACtB,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,+CAA+C;CAC7D,CAAC;AAEF,+DAA+D;AAE/D,MAAM,CAAC,MAAM,OAAO,GAAkC;IACpD,OAAO;IACP,oBAAoB;IACpB,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,2BAA2B;IAC3B,aAAa;IACb,UAAU;IACV,kBAAkB;IAClB,gBAAgB;IAChB,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;IACjB,iBAAiB;IACjB,gBAAgB;IAChB,aAAa;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAwB;IACjD,OAAO,EAAE,UAAU;IACnB,oBAAoB,EAAE,KAAK;IAC3B,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC,CAAC;IACnB,gBAAgB,EAAE,cAAc;IAChC,cAAc,EAAE,UAAU;IAC1B,2BAA2B,EAAE,CAAC;IAC9B,aAAa,EAAE,MAAM;IACrB,UAAU,EAAE,UAAU;IACtB,kBAAkB,EAAE,IAAI;IACxB,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,UAAU;IAC7B,kBAAkB,EAAE,QAAQ;IAC5B,iBAAiB,EAAE,QAAQ;IAC3B,iBAAiB,EAAE,KAAK;IACxB,gBAAgB,EAAE,UAAU;IAC5B,aAAa,EAAE,KAAK;CACrB,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * CoffeeHaml Prettier Printer — AST to Prettier Doc IR.
3
+ *
4
+ * Uses Prettier's `print` callback for recursive descent via path.map.
5
+ * Each formatting decision gated by options for independent deactivation.
6
+ *
7
+ * Note: uses `any` for Path types because the abstract Node base class
8
+ * doesn't declare `children`, so Prettier's typed AstPath.map can't
9
+ * resolve property access chains on our AST nodes.
10
+ */
11
+ import type { Doc } from 'prettier';
12
+ export interface CoffeeHamlFormatOptions {
13
+ tagCase: 'preserve' | 'lowercase';
14
+ implicitDivExpansion: boolean;
15
+ maxChainLength: number;
16
+ inlineThreshold: number;
17
+ voidElementStyle: 'self-closing' | 'explicit';
18
+ attributeStyle: 'preserve' | 'braces' | 'parens' | 'bare';
19
+ attributeMultilineThreshold: number;
20
+ attributeSort: 'none' | 'alphabetical' | 'idiomatic';
21
+ quoteStyle: 'preserve' | 'double' | 'single';
22
+ coffeeScriptFormat: boolean;
23
+ methodChainAlign: boolean;
24
+ blankLineHandling: 'preserve' | 'collapse' | 'respect';
25
+ trailingWhitespace: 'remove' | 'preserve';
26
+ continuationStyle: 'preserve' | 'indent' | 'backslash';
27
+ controlFlowInline: boolean;
28
+ statementMerging: 'preserve' | 'merge';
29
+ commentFormat: boolean;
30
+ tabWidth: number;
31
+ useTabs: boolean;
32
+ printWidth: number;
33
+ originalText?: string;
34
+ }
35
+ type Path = any;
36
+ type PrintFn = (selector?: any, args?: unknown) => Doc;
37
+ export declare function print(path: Path, options: CoffeeHamlFormatOptions, printFn: PrintFn): Doc;
38
+ /**
39
+ * Prettier embed function — formats full CoffeeScript blocks
40
+ * (Statement bodies, CoffeeScript filters) via the async textToDoc
41
+ * mechanism. Inline expressions are handled synchronously via formatCS.
42
+ */
43
+ export declare function embedCoffeeScript(path: any, _printFn: any): Doc | undefined;
44
+ export {};
45
+ //# sourceMappingURL=printer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../src/prettier/printer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAapC,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,UAAU,GAAG,WAAW,CAAC;IA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