coffeehaml 0.7.0 → 0.7.1

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 (73) hide show
  1. package/README.md +21 -5
  2. package/dist/ast.js +334 -125
  3. package/dist/cli.js +363 -291
  4. package/dist/compiler.js +126 -89
  5. package/dist/emitter.js +771 -736
  6. package/dist/errors.js +5 -2
  7. package/dist/expressions.js +211 -154
  8. package/dist/index.js +22 -6
  9. package/dist/lexer.js +536 -340
  10. package/dist/parser.js +533 -438
  11. package/dist/prettier/coffeescript-formatter.js +292 -392
  12. package/dist/prettier/index.js +96 -60
  13. package/dist/prettier/options.js +179 -147
  14. package/dist/prettier/printer.js +549 -642
  15. package/dist/src/ast.js +338 -0
  16. package/dist/src/cli.js +430 -0
  17. package/dist/src/compiler.js +132 -0
  18. package/dist/src/emitter.js +791 -0
  19. package/dist/src/errors.js +5 -0
  20. package/dist/src/expressions.js +223 -0
  21. package/dist/src/index.js +22 -0
  22. package/dist/src/lexer.js +504 -0
  23. package/dist/src/parser.js +575 -0
  24. package/dist/src/types.js +122 -0
  25. package/dist/src/vite-plugin.js +78 -0
  26. package/dist/types.js +122 -12
  27. package/dist/vite-plugin.js +78 -63
  28. package/package.json +4 -9
  29. package/dist/ast.d.ts +0 -123
  30. package/dist/ast.d.ts.map +0 -1
  31. package/dist/ast.js.map +0 -1
  32. package/dist/cli.d.ts +0 -3
  33. package/dist/cli.d.ts.map +0 -1
  34. package/dist/cli.js.map +0 -1
  35. package/dist/compiler.d.ts +0 -10
  36. package/dist/compiler.d.ts.map +0 -1
  37. package/dist/compiler.js.map +0 -1
  38. package/dist/emitter.d.ts +0 -4
  39. package/dist/emitter.d.ts.map +0 -1
  40. package/dist/emitter.js.map +0 -1
  41. package/dist/errors.d.ts +0 -3
  42. package/dist/errors.d.ts.map +0 -1
  43. package/dist/errors.js.map +0 -1
  44. package/dist/expressions.d.ts +0 -22
  45. package/dist/expressions.d.ts.map +0 -1
  46. package/dist/expressions.js.map +0 -1
  47. package/dist/index.d.ts +0 -7
  48. package/dist/index.d.ts.map +0 -1
  49. package/dist/index.js.map +0 -1
  50. package/dist/lexer.d.ts +0 -30
  51. package/dist/lexer.d.ts.map +0 -1
  52. package/dist/lexer.js.map +0 -1
  53. package/dist/parser.d.ts +0 -10
  54. package/dist/parser.d.ts.map +0 -1
  55. package/dist/parser.js.map +0 -1
  56. package/dist/prettier/coffeescript-formatter.d.ts +0 -31
  57. package/dist/prettier/coffeescript-formatter.d.ts.map +0 -1
  58. package/dist/prettier/coffeescript-formatter.js.map +0 -1
  59. package/dist/prettier/index.d.ts +0 -8
  60. package/dist/prettier/index.d.ts.map +0 -1
  61. package/dist/prettier/index.js.map +0 -1
  62. package/dist/prettier/options.d.ts +0 -10
  63. package/dist/prettier/options.d.ts.map +0 -1
  64. package/dist/prettier/options.js.map +0 -1
  65. package/dist/prettier/printer.d.ts +0 -45
  66. package/dist/prettier/printer.d.ts.map +0 -1
  67. package/dist/prettier/printer.js.map +0 -1
  68. package/dist/types.d.ts +0 -76
  69. package/dist/types.d.ts.map +0 -1
  70. package/dist/types.js.map +0 -1
  71. package/dist/vite-plugin.d.ts +0 -7
  72. package/dist/vite-plugin.d.ts.map +0 -1
  73. package/dist/vite-plugin.js.map +0 -1
@@ -1,69 +1,105 @@
1
- // CoffeeHaml Prettier Plugin — Entry Point
2
- //
3
- // Auto-discovered by Prettier when listed in plugins.
4
- // Usage in .prettierrc: { "plugins": ["prettier-plugin-coffeehaml"] }
5
- import { tokenize } from '../lexer.js';
6
- import { parse } from '../parser.js';
7
- import { print, embedCoffeeScript } from './printer.js';
8
- import { options, defaultOptions } from './options.js';
1
+ // Generated by CoffeeScript 2.7.0
2
+ // index.coffee — CoffeeHaml Prettier Plugin entry point
3
+ var _parsers, _printers, coffeeHamlLanguage, coffeeHamlParser, coffeeHamlPrinter, plugin;
4
+
5
+ import {
6
+ tokenize
7
+ } from '../lexer.js';
8
+
9
+ import {
10
+ parse
11
+ } from '../parser.js';
12
+
13
+ import {
14
+ print,
15
+ embedCoffeeScript
16
+ } from './printer.js';
17
+
18
+ import {
19
+ options,
20
+ defaultOptions
21
+ } from './options.js';
22
+
9
23
  // ─── Language ──────────────────────────────────────────────
10
- const coffeeHamlLanguage = {
11
- name: 'CoffeeHaml',
12
- parsers: ['coffeehaml'],
13
- extensions: ['.chaml', '.coffeehaml'],
14
- vscodeLanguageIds: ['coffeehaml'],
24
+ coffeeHamlLanguage = {
25
+ name: 'CoffeeHaml',
26
+ parsers: ['coffeehaml'],
27
+ extensions: ['.chaml', '.coffeehaml'],
28
+ vscodeLanguageIds: ['coffeehaml']
15
29
  };
30
+
16
31
  // ─── Parser ────────────────────────────────────────────────
17
- const coffeeHamlParser = {
18
- parse(text, _options) {
19
- const tokens = tokenize(text);
20
- const result = parse(tokens);
21
- if (result.errors.length > 0 && result.document.children.length === 0) {
22
- throw new Error('CoffeeHaml parse errors:\n' +
23
- result.errors.map(e => ` ${e.message}`).join('\n'));
24
- }
25
- return result.document;
26
- },
27
- astFormat: 'coffeehaml-ast',
28
- locStart(node) {
29
- return node?.location?.offset ?? 0;
30
- },
31
- locEnd(node) {
32
- if (!node?.location)
33
- return 0;
34
- return node.location.offset + node.location.length;
35
- },
36
- hasPragma(text) {
37
- return /\/\*\*\s*@format\s*\*\//.test(text) || /^\/\s*@format/.test(text);
38
- },
32
+ coffeeHamlParser = {
33
+ parse: function(text, _options) {
34
+ var result, tokens;
35
+ tokens = tokenize(text);
36
+ result = parse(tokens);
37
+ if (result.errors.length > 0 && result.document.children.length === 0) {
38
+ throw new Error('CoffeeHaml parse errors:\n' + result.errors.map(function(e) {
39
+ return ` ${e.message}`;
40
+ }).join('\n'));
41
+ }
42
+ return result.document;
43
+ },
44
+ astFormat: 'coffeehaml-ast',
45
+ locStart: function(node) {
46
+ var ref, ref1;
47
+ return (ref = node != null ? (ref1 = node.location) != null ? ref1.offset : void 0 : void 0) != null ? ref : 0;
48
+ },
49
+ locEnd: function(node) {
50
+ if (!(node != null ? node.location : void 0)) {
51
+ return 0;
52
+ }
53
+ return node.location.offset + node.location.length;
54
+ },
55
+ hasPragma: function(text) {
56
+ return /\/\*\*\s*@format\s*\*\//.test(text) || /^\/\s*@format/.test(text);
57
+ }
39
58
  };
59
+
40
60
  // ─── Printer ───────────────────────────────────────────────
41
- const coffeeHamlPrinter = {
42
- print(path, options, printFn, _args) {
43
- // Merge Prettier core options + our plugin options into CoffeeHamlFormatOptions
44
- const opts = options;
45
- // Pass original text for blank-line detection
46
- if (options.originalText) {
47
- opts.originalText = options.originalText;
48
- }
49
- return print(path, opts, printFn);
50
- },
51
- embed(path, _options) {
52
- return embedCoffeeScript(path, print) ?? null;
53
- },
54
- insertPragma(text) {
55
- return '/** @format */\n' + text;
56
- },
61
+ coffeeHamlPrinter = {
62
+ print: function(path, options, printFn, _args) {
63
+ var opts;
64
+ opts = options;
65
+ if (options.originalText) {
66
+ opts.originalText = options.originalText;
67
+ }
68
+ return print(path, opts, printFn);
69
+ },
70
+ embed: function(path, _options) {
71
+ var ref;
72
+ return (ref = embedCoffeeScript(path, print)) != null ? ref : null;
73
+ },
74
+ insertPragma: function(text) {
75
+ return '/** @format */\n' + text;
76
+ }
57
77
  };
78
+
58
79
  // ─── Export ────────────────────────────────────────────────
59
- const plugin = {
60
- languages: [coffeeHamlLanguage],
61
- parsers: { coffeehaml: coffeeHamlParser },
62
- printers: { 'coffeehaml-ast': coffeeHamlPrinter },
63
- options,
64
- defaultOptions,
80
+ _parsers = {};
81
+
82
+ _parsers.coffeehaml = coffeeHamlParser;
83
+
84
+ _printers = {};
85
+
86
+ _printers['coffeehaml-ast'] = coffeeHamlPrinter;
87
+
88
+ plugin = {
89
+ languages: [coffeeHamlLanguage],
90
+ parsers: _parsers,
91
+ printers: _printers,
92
+ options,
93
+ defaultOptions
65
94
  };
95
+
66
96
  export default plugin;
67
- export { options, defaultOptions } from './options.js';
68
- export { print } from './printer.js';
69
- //# sourceMappingURL=index.js.map
97
+
98
+ export {
99
+ options,
100
+ defaultOptions
101
+ } from './options.js';
102
+
103
+ export {
104
+ print
105
+ } from './printer.js';
@@ -1,200 +1,232 @@
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 = {
1
+ // Generated by CoffeeScript 2.7.0
2
+ // options.coffee — CoffeeHaml Prettier formatting options
3
+ export var CAT = {
4
+ STRUCTURE: 'CoffeeHaml: Structure',
5
+ ATTRIBUTES: 'CoffeeHaml: Attributes',
6
+ COFFEESCRIPT: 'CoffeeHaml: CoffeeScript',
7
+ WHITESPACE: 'CoffeeHaml: Whitespace',
8
+ CONTROL_FLOW: 'CoffeeHaml: Control Flow',
9
+ COMMENTS: 'CoffeeHaml: Comments'
10
+ };
11
+
12
+ export var options = {
13
+ tagCase: {
19
14
  category: CAT.STRUCTURE,
20
15
  type: 'choice',
21
16
  description: 'Normalize HTML tag casing. Component tags (%MyComponent) never affected.',
22
17
  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 = {
18
+ {
19
+ value: 'preserve',
20
+ description: 'Leave tag case as written'
21
+ },
22
+ {
23
+ value: 'lowercase',
24
+ description: '%DIV to %div (HTML tags only)'
25
+ }
26
+ ]
27
+ },
28
+ implicitDivExpansion: {
29
29
  category: CAT.STRUCTURE,
30
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 = {
31
+ description: 'Expand .class to %div.class (anti-idiomatic in HAML).'
32
+ },
33
+ maxChainLength: {
35
34
  category: CAT.STRUCTURE,
36
35
  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 = {
36
+ description: 'Max .class chain length before breaking into indented hierarchy. 0 = always break.'
37
+ },
38
+ inlineThreshold: {
41
39
  category: CAT.STRUCTURE,
42
40
  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 = {
41
+ description: 'Try single-line if estimated width <= this. -1 = never inline children.'
42
+ },
43
+ voidElementStyle: {
47
44
  category: CAT.STRUCTURE,
48
45
  type: 'choice',
49
46
  description: 'How void elements (%br, %img, etc.) are formatted.',
50
47
  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 = {
48
+ {
49
+ value: 'self-closing',
50
+ description: 'Self-closing (no children)'
51
+ },
52
+ {
53
+ value: 'explicit',
54
+ description: 'Preserve %br/ syntax, otherwise self-close'
55
+ }
56
+ ]
57
+ },
58
+ attributeStyle: {
57
59
  category: CAT.ATTRIBUTES,
58
60
  type: 'choice',
59
61
  description: 'Enforce attribute syntax: {braces}, (parens), bare, or preserve.',
60
62
  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 = {
63
+ {
64
+ value: 'preserve',
65
+ description: 'Keep as written'
66
+ },
67
+ {
68
+ value: 'braces',
69
+ description: 'Convert to {CoffeeScript} style'
70
+ },
71
+ {
72
+ value: 'parens',
73
+ description: 'Convert to HTML (parens) style'
74
+ },
75
+ {
76
+ value: 'bare',
77
+ description: 'Convert to bare HAML style'
78
+ }
79
+ ]
80
+ },
81
+ attributeMultilineThreshold: {
69
82
  category: CAT.ATTRIBUTES,
70
83
  type: 'int',
71
- description: 'Break attributes across lines when count >= this. 0 = always multiline.',
72
- };
73
- /** Sort attribute keys. */
74
- const attributeSort = {
84
+ description: 'Break attributes across lines when count >= this. 0 = always multiline.'
85
+ },
86
+ attributeSort: {
75
87
  category: CAT.ATTRIBUTES,
76
88
  type: 'choice',
77
89
  description: 'Sort attribute keys (spread attributes always last).',
78
90
  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 = {
91
+ {
92
+ value: 'none',
93
+ description: 'Preserve author order'
94
+ },
95
+ {
96
+ value: 'alphabetical',
97
+ description: 'Sort A to Z'
98
+ },
99
+ {
100
+ value: 'idiomatic',
101
+ description: 'id first, class second, rest A to Z'
102
+ }
103
+ ]
104
+ },
105
+ quoteStyle: {
86
106
  category: CAT.ATTRIBUTES,
87
107
  type: 'choice',
88
108
  description: 'Quote style for bare/HAML attributes.',
89
109
  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 = {
110
+ {
111
+ value: 'preserve',
112
+ description: 'Keep as written'
113
+ },
114
+ {
115
+ value: 'double',
116
+ description: 'Force double quotes'
117
+ },
118
+ {
119
+ value: 'single',
120
+ description: 'Force single quotes'
121
+ }
122
+ ]
123
+ },
124
+ coffeeScriptFormat: {
97
125
  category: CAT.COFFEESCRIPT,
98
126
  type: 'boolean',
99
- description: 'Format CoffeeScript expressions using prettier/plugins/coffeescript.',
100
- };
101
- /** Align chained method calls on newlines. */
102
- const methodChainAlign = {
127
+ description: 'Format CoffeeScript expressions using prettier/plugins/coffeescript.'
128
+ },
129
+ methodChainAlign: {
103
130
  category: CAT.COFFEESCRIPT,
104
131
  type: 'boolean',
105
- description: 'Align .method chains on newlines for = expressions.',
106
- };
107
- /** Blank line handling between sibling elements. */
108
- const blankLineHandling = {
132
+ description: 'Align .method chains on newlines for = expressions.'
133
+ },
134
+ blankLineHandling: {
109
135
  category: CAT.WHITESPACE,
110
136
  type: 'choice',
111
137
  description: 'How blank lines between sibling elements are treated.',
112
138
  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 = {
139
+ {
140
+ value: 'preserve',
141
+ description: 'Keep single; collapse multiples'
142
+ },
143
+ {
144
+ value: 'collapse',
145
+ description: 'Remove all blank lines between siblings'
146
+ },
147
+ {
148
+ value: 'respect',
149
+ description: 'Keep exactly as written'
150
+ }
151
+ ]
152
+ },
153
+ trailingWhitespace: {
120
154
  category: CAT.WHITESPACE,
121
155
  type: 'choice',
122
156
  description: 'Handle trailing whitespace.',
123
157
  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 = {
158
+ {
159
+ value: 'remove',
160
+ description: 'Strip trailing whitespace'
161
+ },
162
+ {
163
+ value: 'preserve',
164
+ description: 'Leave as written'
165
+ }
166
+ ]
167
+ },
168
+ continuationStyle: {
130
169
  category: CAT.CONTROL_FLOW,
131
170
  type: 'choice',
132
171
  description: 'How \\ continuations are formatted.',
133
172
  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 = {
173
+ {
174
+ value: 'preserve',
175
+ description: 'Keep as written'
176
+ },
177
+ {
178
+ value: 'indent',
179
+ description: 'Always use indented continuation'
180
+ },
181
+ {
182
+ value: 'backslash',
183
+ description: 'Always use \\ continuation'
184
+ }
185
+ ]
186
+ },
187
+ controlFlowInline: {
141
188
  category: CAT.CONTROL_FLOW,
142
189
  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 = {
190
+ description: 'Allow - if x then .ok one-liners (anti-Prettier by default).'
191
+ },
192
+ statementMerging: {
147
193
  category: CAT.CONTROL_FLOW,
148
194
  type: 'choice',
149
195
  description: 'Merge consecutive - lines into a single indented block. Only childless statements.',
150
196
  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 = {
197
+ {
198
+ value: 'preserve',
199
+ description: 'Keep each - line separate'
200
+ },
201
+ {
202
+ value: 'merge',
203
+ description: 'Merge consecutive childless statements into one indented block'
204
+ }
205
+ ]
206
+ },
207
+ commentFormat: {
157
208
  category: CAT.COMMENTS,
158
209
  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,
210
+ description: 'Reflow/word-wrap comment text (experimental).'
211
+ }
212
+ };
213
+
214
+ export var defaultOptions = {
215
+ tagCase: 'preserve',
216
+ implicitDivExpansion: false,
217
+ maxChainLength: 4,
218
+ inlineThreshold: -1,
219
+ voidElementStyle: 'self-closing',
220
+ attributeStyle: 'preserve',
221
+ attributeMultilineThreshold: 1,
222
+ attributeSort: 'none',
223
+ quoteStyle: 'preserve',
224
+ coffeeScriptFormat: true,
225
+ methodChainAlign: true,
226
+ blankLineHandling: 'preserve',
227
+ trailingWhitespace: 'remove',
228
+ continuationStyle: 'indent',
229
+ controlFlowInline: false,
230
+ statementMerging: 'preserve',
231
+ commentFormat: false
199
232
  };
200
- //# sourceMappingURL=options.js.map