coffeehaml 0.7.0 → 0.7.2

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 (62) 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/types.js +122 -12
  16. package/dist/vite-plugin.js +78 -63
  17. package/package.json +4 -9
  18. package/dist/ast.d.ts +0 -123
  19. package/dist/ast.d.ts.map +0 -1
  20. package/dist/ast.js.map +0 -1
  21. package/dist/cli.d.ts +0 -3
  22. package/dist/cli.d.ts.map +0 -1
  23. package/dist/cli.js.map +0 -1
  24. package/dist/compiler.d.ts +0 -10
  25. package/dist/compiler.d.ts.map +0 -1
  26. package/dist/compiler.js.map +0 -1
  27. package/dist/emitter.d.ts +0 -4
  28. package/dist/emitter.d.ts.map +0 -1
  29. package/dist/emitter.js.map +0 -1
  30. package/dist/errors.d.ts +0 -3
  31. package/dist/errors.d.ts.map +0 -1
  32. package/dist/errors.js.map +0 -1
  33. package/dist/expressions.d.ts +0 -22
  34. package/dist/expressions.d.ts.map +0 -1
  35. package/dist/expressions.js.map +0 -1
  36. package/dist/index.d.ts +0 -7
  37. package/dist/index.d.ts.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/lexer.d.ts +0 -30
  40. package/dist/lexer.d.ts.map +0 -1
  41. package/dist/lexer.js.map +0 -1
  42. package/dist/parser.d.ts +0 -10
  43. package/dist/parser.d.ts.map +0 -1
  44. package/dist/parser.js.map +0 -1
  45. package/dist/prettier/coffeescript-formatter.d.ts +0 -31
  46. package/dist/prettier/coffeescript-formatter.d.ts.map +0 -1
  47. package/dist/prettier/coffeescript-formatter.js.map +0 -1
  48. package/dist/prettier/index.d.ts +0 -8
  49. package/dist/prettier/index.d.ts.map +0 -1
  50. package/dist/prettier/index.js.map +0 -1
  51. package/dist/prettier/options.d.ts +0 -10
  52. package/dist/prettier/options.d.ts.map +0 -1
  53. package/dist/prettier/options.js.map +0 -1
  54. package/dist/prettier/printer.d.ts +0 -45
  55. package/dist/prettier/printer.d.ts.map +0 -1
  56. package/dist/prettier/printer.js.map +0 -1
  57. package/dist/types.d.ts +0 -76
  58. package/dist/types.d.ts.map +0 -1
  59. package/dist/types.js.map +0 -1
  60. package/dist/vite-plugin.d.ts +0 -7
  61. package/dist/vite-plugin.d.ts.map +0 -1
  62. package/dist/vite-plugin.js.map +0 -1
package/dist/compiler.js CHANGED
@@ -1,95 +1,132 @@
1
- import { tokenize } from './lexer.js';
2
- import { parse } from './parser.js';
3
- import { emit } from './emitter.js';
4
- import { CompileError } from './types.js';
5
- import { isCoffeeScriptAvailable, getCoffeeScriptUnavailableReason } from './expressions.js';
6
- import { readFileSync, existsSync } from 'fs';
7
- /** Supported CoffeeHaml file extensions (in order of preference). */
8
- export const COFFEEHAML_EXTENSIONS = ['.coffeehaml', '.cohaml', '.chaml'];
9
- /** Resolve a CoffeeHaml file path, trying each extension if none given. */
10
- export function resolveCoffeeHamlFile(filepath) {
11
- if (existsSync(filepath))
12
- return filepath;
13
- for (const ext of COFFEEHAML_EXTENSIONS) {
14
- const withExt = filepath + ext;
15
- if (existsSync(withExt))
16
- return withExt;
17
- }
18
- return null;
19
- }
20
- /** Compile CoffeeHaml source to JavaScript. */
21
- export function compile(source, options = {}) {
22
- const errors = [];
23
- const warnings = [];
24
- // Warn if CoffeeScript is unavailable — expressions will pass through raw
25
- if (!isCoffeeScriptAvailable()) {
26
- warnings.push({
27
- message: `CoffeeScript expression compiler unavailable: ${getCoffeeScriptUnavailableReason()}. CoffeeScript expressions will passthrough raw and may produce invalid JavaScript. Install coffeescript as a peer dependency.`,
28
- phase: 'compiler',
29
- });
1
+ // Generated by CoffeeScript 2.7.0
2
+ // compiler.coffee — compile pipeline orchestration
3
+ var wrapError;
4
+
5
+ import {
6
+ tokenize
7
+ } from './lexer.js';
8
+
9
+ import {
10
+ parse
11
+ } from './parser.js';
12
+
13
+ import {
14
+ emit
15
+ } from './emitter.js';
16
+
17
+ import {
18
+ CompileError
19
+ } from './types.js';
20
+
21
+ import {
22
+ isCoffeeScriptAvailable,
23
+ getCoffeeScriptUnavailableReason
24
+ } from './expressions.js';
25
+
26
+ import {
27
+ readFileSync,
28
+ existsSync
29
+ } from 'fs';
30
+
31
+ // Supported extensions
32
+ export var COFFEEHAML_EXTENSIONS = ['.coffeehaml', '.cohaml', '.chaml'];
33
+
34
+ // Resolve a CoffeeHaml file path
35
+ export var resolveCoffeeHamlFile = function(filepath) {
36
+ var ext, i, len, withExt;
37
+ if (existsSync(filepath)) {
38
+ return filepath;
39
+ }
40
+ for (i = 0, len = COFFEEHAML_EXTENSIONS.length; i < len; i++) {
41
+ ext = COFFEEHAML_EXTENSIONS[i];
42
+ withExt = filepath + ext;
43
+ if (existsSync(withExt)) {
44
+ return withExt;
30
45
  }
46
+ }
47
+ return null;
48
+ };
49
+
50
+ // Compile CoffeeHaml source to JavaScript
51
+ export var compile = function(source, options = {}) {
52
+ var ast, e, errors, parsed, result, tokens, warnings;
53
+ errors = [];
54
+ warnings = [];
55
+ // Warn if CoffeeScript unavailable
56
+ if (!isCoffeeScriptAvailable()) {
57
+ warnings.push({
58
+ message: `CoffeeScript expression compiler unavailable: ${getCoffeeScriptUnavailableReason()}. CoffeeScript expressions will passthrough raw and may produce invalid JavaScript. Install coffeescript as a peer dependency.`,
59
+ phase: 'compiler'
60
+ });
61
+ }
62
+ try {
31
63
  // Phase 1: Lex
32
- let tokens;
33
- try {
34
- tokens = tokenize(source, options.filename);
35
- }
36
- catch (e) {
37
- return {
38
- code: '',
39
- errors: [wrapError(e, 'lexer')],
40
- warnings: [],
41
- };
42
- }
43
- // Phase 2: Parse
44
- const parsed = parse(tokens, options.filename);
45
- const ast = parsed.document;
46
- // Collect parse errors (non-fatal — parsing continues with recovery)
47
- if (parsed.errors.length > 0) {
48
- errors.push(...parsed.errors);
49
- if (ast.children.length === 0) {
50
- return { code: '', errors, warnings };
51
- }
64
+ tokens = tokenize(source, options.filename);
65
+ } catch (error) {
66
+ e = error;
67
+ return {
68
+ code: '',
69
+ errors: [wrapError(e, 'lexer')],
70
+ warnings: []
71
+ };
72
+ }
73
+ // Phase 2: Parse
74
+ parsed = parse(tokens, options.filename);
75
+ ast = parsed.document;
76
+ if (parsed.errors.length > 0) {
77
+ errors.push(...parsed.errors);
78
+ if (ast.children.length === 0) {
79
+ return {
80
+ code: '',
81
+ errors,
82
+ warnings
83
+ };
52
84
  }
85
+ }
86
+ try {
53
87
  // Phase 3: Emit
54
- let result;
55
- try {
56
- result = emit(ast, {
57
- sourceMap: options.sourceMap,
58
- filename: options.filename,
59
- jsxRuntime: options.jsxRuntime,
60
- filters: options.filters,
61
- wrap: options.wrap,
62
- componentName: options.componentName,
63
- });
64
- }
65
- catch (e) {
66
- return {
67
- code: '',
68
- errors: [wrapError(e, 'emitter')],
69
- warnings,
70
- };
71
- }
72
- // Collect warnings from emit phase
73
- if (result.warnings) {
74
- warnings.push(...result.warnings);
75
- }
88
+ result = emit(ast, {
89
+ sourceMap: options.sourceMap,
90
+ filename: options.filename,
91
+ jsxRuntime: options.jsxRuntime,
92
+ filters: options.filters,
93
+ wrap: options.wrap,
94
+ componentName: options.componentName
95
+ });
96
+ } catch (error) {
97
+ e = error;
76
98
  return {
77
- code: result.code,
78
- sourceMap: result.sourceMap,
79
- errors,
80
- warnings,
99
+ code: '',
100
+ errors: [wrapError(e, 'emitter')],
101
+ warnings
81
102
  };
82
- }
83
- /** Compile a CoffeeHaml file from disk. */
84
- export function compileFile(filepath, options = {}) {
85
- const source = readFileSync(filepath, 'utf-8');
86
- return compile(source, { ...options, filename: filepath });
87
- }
88
- function wrapError(e, phase) {
89
- if (e instanceof CompileError) {
90
- e.phase = phase;
91
- return e;
92
- }
93
- return new CompileError(e instanceof Error ? e.message : String(e), phase, 'INTERNAL_ERROR');
94
- }
95
- //# sourceMappingURL=compiler.js.map
103
+ }
104
+ if (result.warnings) {
105
+ warnings.push(...result.warnings);
106
+ }
107
+ return {
108
+ code: result.code,
109
+ sourceMap: result.sourceMap,
110
+ errors,
111
+ warnings
112
+ };
113
+ };
114
+
115
+ // Compile from disk
116
+ export var compileFile = function(filepath, options = {}) {
117
+ var source;
118
+ source = readFileSync(filepath, 'utf-8');
119
+ return compile(source, {
120
+ ...options,
121
+ filename: filepath
122
+ });
123
+ };
124
+
125
+ // ─── Helpers ───────────────────────────────────────────────
126
+ wrapError = function(e, phase) {
127
+ if (e instanceof CompileError) {
128
+ e.phase = phase;
129
+ return e;
130
+ }
131
+ return new CompileError(e instanceof Error ? e.message : String(e), phase, 'INTERNAL_ERROR');
132
+ };