coffeehaml 0.6.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.
- package/README.md +21 -5
- package/dist/ast.js +334 -123
- package/dist/cli.js +363 -291
- package/dist/compiler.js +126 -89
- package/dist/emitter.js +771 -736
- package/dist/errors.js +5 -2
- package/dist/expressions.js +211 -154
- package/dist/index.js +22 -4
- package/dist/lexer.js +536 -340
- package/dist/parser.js +533 -432
- package/dist/prettier/coffeescript-formatter.js +309 -0
- package/dist/prettier/index.js +105 -0
- package/dist/prettier/options.js +232 -0
- package/dist/prettier/printer.js +559 -0
- package/dist/src/ast.js +338 -0
- package/dist/src/cli.js +430 -0
- package/dist/src/compiler.js +132 -0
- package/dist/src/emitter.js +791 -0
- package/dist/src/errors.js +5 -0
- package/dist/src/expressions.js +223 -0
- package/dist/src/index.js +22 -0
- package/dist/src/lexer.js +504 -0
- package/dist/src/parser.js +575 -0
- package/dist/src/types.js +122 -0
- package/dist/src/vite-plugin.js +78 -0
- package/dist/types.js +122 -12
- package/dist/vite-plugin.js +78 -63
- package/docs/examples.md +201 -1
- package/docs/grammar.md +90 -1
- package/docs/index.html +260 -37
- package/package.json +12 -10
- package/syntaxes/CoffeeHaml.tmLanguage +815 -868
- package/syntaxes/coffeehaml.tmLanguage.json +352 -161
- package/dist/ast.d.ts +0 -117
- package/dist/ast.d.ts.map +0 -1
- package/dist/ast.js.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/compiler.d.ts +0 -10
- package/dist/compiler.d.ts.map +0 -1
- package/dist/compiler.js.map +0 -1
- package/dist/emitter.d.ts +0 -4
- package/dist/emitter.d.ts.map +0 -1
- package/dist/emitter.js.map +0 -1
- package/dist/errors.d.ts +0 -3
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/expressions.d.ts +0 -22
- package/dist/expressions.d.ts.map +0 -1
- package/dist/expressions.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lexer.d.ts +0 -30
- package/dist/lexer.d.ts.map +0 -1
- package/dist/lexer.js.map +0 -1
- package/dist/parser.d.ts +0 -10
- package/dist/parser.d.ts.map +0 -1
- package/dist/parser.js.map +0 -1
- package/dist/types.d.ts +0 -76
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/vite-plugin.d.ts +0 -7
- package/dist/vite-plugin.d.ts.map +0 -1
- package/dist/vite-plugin.js.map +0 -1
package/dist/compiler.js
CHANGED
|
@@ -1,95 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
warnings,
|
|
99
|
+
code: '',
|
|
100
|
+
errors: [wrapError(e, 'emitter')],
|
|
101
|
+
warnings
|
|
81
102
|
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
+
};
|