@chilts/weave 0.1.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.
- package/ReadMe.md +177 -0
- package/bin/weave.js +4 -0
- package/dist/cli/index.d.ts +31 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +250 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/codegen/index.d.ts +27 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +604 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/sourcemap.d.ts +43 -0
- package/dist/codegen/sourcemap.d.ts.map +1 -0
- package/dist/codegen/sourcemap.js +113 -0
- package/dist/codegen/sourcemap.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer/index.d.ts +14 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js +679 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/parser/index.d.ts +10 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +392 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/types.d.ts +125 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +3 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/runtime/index.d.ts +15 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +82 -0
- package/dist/runtime/index.js.map +1 -0
- package/package.json +55 -0
package/ReadMe.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Weave
|
|
2
|
+
|
|
3
|
+
A Pug-inspired templating engine that compiles to TypeScript. Write indentation-based templates, get typed functions that return HTML.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
views/*.weave → weave compiler → lib/views/*.ts → tsc
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Why Weave?
|
|
10
|
+
|
|
11
|
+
Pug is great. Weave takes the same indentation-based syntax and makes it TypeScript-native — your templates become typed functions, checked by `tsc` like any other code.
|
|
12
|
+
|
|
13
|
+
- **Type-safe templates** — template parameters are real TypeScript types
|
|
14
|
+
- **Type-safe mixins** — positional args with TS type annotations
|
|
15
|
+
- **Tailwind-friendly** — class names with colons (`.md:flex`, `.hover:bg-blue-500`) just work
|
|
16
|
+
- **Single-pass escaping** — values are escaped once at render time, never pre-escaped
|
|
17
|
+
- **No runtime template engine** — compiled output is plain TypeScript
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
A `.weave` template:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
import type { SimpleProps } from '../types/views.js'
|
|
25
|
+
|
|
26
|
+
template simple({ title, content }: SimpleProps)
|
|
27
|
+
doctype html
|
|
28
|
+
html(lang="en")
|
|
29
|
+
head
|
|
30
|
+
title= title
|
|
31
|
+
body
|
|
32
|
+
h1= title
|
|
33
|
+
p= content
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Compiles to a `.ts` file:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { h, doctype } from "@chilts/weave"
|
|
40
|
+
import type { SimpleProps } from '../types/views.js'
|
|
41
|
+
|
|
42
|
+
export function simple({ title, content }: SimpleProps) {
|
|
43
|
+
return [
|
|
44
|
+
doctype(),
|
|
45
|
+
h("html", { lang: "en" },
|
|
46
|
+
h("head", {},
|
|
47
|
+
h("title", {}, title)
|
|
48
|
+
),
|
|
49
|
+
h("body", {},
|
|
50
|
+
h("h1", {}, title),
|
|
51
|
+
h("p", {}, content)
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Now `tsc` catches type errors, your IDE gives you autocomplete, and calling `simple({ title: "Hello", content: "World" })` returns HTML.
|
|
59
|
+
|
|
60
|
+
## Syntax
|
|
61
|
+
|
|
62
|
+
Weave's syntax will be familiar if you've used Pug.
|
|
63
|
+
|
|
64
|
+
### Elements, classes, IDs, and attributes
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
h1 Hello World
|
|
68
|
+
p.intro This is a paragraph with a class
|
|
69
|
+
.container
|
|
70
|
+
span#main.text-lg.md:text-xl Content here
|
|
71
|
+
a(href="/about" class="nav-link") About
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Conditionals
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
if role === "admin"
|
|
78
|
+
p.badge You are an administrator
|
|
79
|
+
else if role === "editor"
|
|
80
|
+
p.badge You are an editor
|
|
81
|
+
else
|
|
82
|
+
p Welcome, visitor
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Iteration
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
for ( const post of posts )
|
|
89
|
+
h2= post.title
|
|
90
|
+
p= post.content
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Mixins
|
|
94
|
+
|
|
95
|
+
Mixins use positional args. An implicit `attrs` parameter captures any extra attributes passed at the call site.
|
|
96
|
+
|
|
97
|
+
Definition:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
mixin button(label: string, variant: "primary" | "secondary" = "primary")
|
|
101
|
+
button.btn(class=`btn-${variant}` ...attrs)= label
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Usage:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
+button("Save", "primary")(class="mr-2")
|
|
108
|
+
+button("Cancel", "secondary")
|
|
109
|
+
+button("Delete", "secondary")(class="ml-4" data-confirm="true")
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Layouts with extends and blocks
|
|
113
|
+
|
|
114
|
+
A layout defines named blocks as content slots:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
template layout({ title }: LayoutProps)
|
|
118
|
+
doctype html
|
|
119
|
+
html(lang="en")
|
|
120
|
+
head
|
|
121
|
+
title= title
|
|
122
|
+
body
|
|
123
|
+
main
|
|
124
|
+
block content
|
|
125
|
+
footer
|
|
126
|
+
p © 2024
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
A page extends the layout, filling in the blocks. Data is passed explicitly — nothing is implicitly inherited:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
template home({ title, welcomeMessage }: HomeProps)
|
|
133
|
+
extends layout({ title })
|
|
134
|
+
block content
|
|
135
|
+
h1= welcomeMessage
|
|
136
|
+
p Welcome to our site.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Blocks can have default content in the layout. If a page doesn't override a block, the default renders.
|
|
140
|
+
|
|
141
|
+
### Includes
|
|
142
|
+
|
|
143
|
+
Include another `.weave` file to use its mixins:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
include ./components/button
|
|
147
|
+
|
|
148
|
+
template actionsPage({ title }: ActionsPageProps)
|
|
149
|
+
doctype html
|
|
150
|
+
html(lang="en")
|
|
151
|
+
body
|
|
152
|
+
+button("Save", "primary")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Imports
|
|
156
|
+
|
|
157
|
+
Standard TypeScript imports pass through to the compiled output:
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
import type { BlogPost } from '../types/models.js'
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npm run build # compile TypeScript to dist/
|
|
167
|
+
npm test # run tests (vitest)
|
|
168
|
+
npm run lint # type-check without emitting (tsc --noEmit)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Status
|
|
172
|
+
|
|
173
|
+
Weave is in early design. The `examples/` directory contains paired `.weave` and `.ts` files that define the target syntax and expected compiler output. The compiler is under active development.
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
ISC
|
package/bin/weave.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface CompileArgs {
|
|
2
|
+
mode: 'compile';
|
|
3
|
+
inputPath: string;
|
|
4
|
+
outputPath: string;
|
|
5
|
+
sourcemap: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface WatchArgs {
|
|
8
|
+
mode: 'watch';
|
|
9
|
+
inputPath: string;
|
|
10
|
+
outputPath: string;
|
|
11
|
+
sourcemap: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface HelpArgs {
|
|
14
|
+
mode: 'help';
|
|
15
|
+
}
|
|
16
|
+
type CliArgs = CompileArgs | WatchArgs | HelpArgs;
|
|
17
|
+
export declare class UsageError extends Error {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare function parseArgs(argv: string[]): CliArgs;
|
|
21
|
+
export declare function usage(): string;
|
|
22
|
+
export declare function discoverFiles(inputDir: string): string[];
|
|
23
|
+
export declare function formatElapsed(ms: number): string;
|
|
24
|
+
export declare function formatCodeFrame(source: string, line: number, col: number): string;
|
|
25
|
+
export declare function formatError(filePath: string, err: unknown, source?: string): string;
|
|
26
|
+
export declare function compileFile(inputFile: string, outputFile: string, sourcemap?: boolean): void;
|
|
27
|
+
export declare function compileDir(inputDir: string, outputDir: string, sourcemap?: boolean): boolean;
|
|
28
|
+
export declare function watchDir(inputDir: string, outputDir: string, sourcemap?: boolean): void;
|
|
29
|
+
export declare function main(argv: string[]): void;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AASA,UAAU,WAAW;IACjB,IAAI,EAAE,SAAS,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;CACrB;AAED,UAAU,SAAS;IACf,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,UAA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
|
|
3
|
+
import { compile, compileWithSourceMap } from '../codegen/index.js';
|
|
4
|
+
import { LexerError } from '../lexer/index.js';
|
|
5
|
+
import { ParserError } from '../parser/index.js';
|
|
6
|
+
import { CodegenError } from '../codegen/index.js';
|
|
7
|
+
export class UsageError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'UsageError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// --- Functions ---
|
|
14
|
+
const FLAGS = ['--watch', '-w', '--no-sourcemap'];
|
|
15
|
+
export function parseArgs(argv) {
|
|
16
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
17
|
+
return { mode: 'help' };
|
|
18
|
+
}
|
|
19
|
+
const isWatch = argv.includes('--watch') || argv.includes('-w');
|
|
20
|
+
const noSourcemap = argv.includes('--no-sourcemap');
|
|
21
|
+
const positional = argv.filter(a => !FLAGS.includes(a));
|
|
22
|
+
if (positional.length < 2) {
|
|
23
|
+
throw new UsageError('missing required arguments');
|
|
24
|
+
}
|
|
25
|
+
if (positional.length > 2) {
|
|
26
|
+
throw new UsageError('too many arguments');
|
|
27
|
+
}
|
|
28
|
+
const inputPath = positional[0];
|
|
29
|
+
const outputPath = positional[1];
|
|
30
|
+
if (isWatch) {
|
|
31
|
+
if (inputPath.endsWith('.weave')) {
|
|
32
|
+
throw new UsageError('--watch requires a directory, not a single file');
|
|
33
|
+
}
|
|
34
|
+
return { mode: 'watch', inputPath, outputPath, sourcemap: !noSourcemap };
|
|
35
|
+
}
|
|
36
|
+
return { mode: 'compile', inputPath, outputPath, sourcemap: !noSourcemap };
|
|
37
|
+
}
|
|
38
|
+
export function usage() {
|
|
39
|
+
return [
|
|
40
|
+
'Usage: weave [--watch] [--no-sourcemap] <input> <output>',
|
|
41
|
+
'',
|
|
42
|
+
' Compile .weave templates to TypeScript.',
|
|
43
|
+
'',
|
|
44
|
+
' <input> A .weave file or directory containing .weave files',
|
|
45
|
+
' <output> Output .ts file or directory for compiled output',
|
|
46
|
+
'',
|
|
47
|
+
'Options:',
|
|
48
|
+
' --watch, -w Watch for changes and recompile (directory mode only)',
|
|
49
|
+
' --no-sourcemap Disable source map generation',
|
|
50
|
+
'',
|
|
51
|
+
'Examples:',
|
|
52
|
+
' weave views/ lib/views/ Compile all templates',
|
|
53
|
+
' weave views/page.weave lib/views/page.ts Compile single file',
|
|
54
|
+
' weave --watch views/ lib/views/ Watch and recompile on changes',
|
|
55
|
+
].join('\n');
|
|
56
|
+
}
|
|
57
|
+
export function discoverFiles(inputDir) {
|
|
58
|
+
const results = [];
|
|
59
|
+
walk(inputDir, '', results);
|
|
60
|
+
return results.sort();
|
|
61
|
+
}
|
|
62
|
+
function walk(dir, base, results) {
|
|
63
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
64
|
+
const rel = base ? path.join(base, entry.name) : entry.name;
|
|
65
|
+
if (entry.isDirectory()) {
|
|
66
|
+
walk(path.join(dir, entry.name), rel, results);
|
|
67
|
+
}
|
|
68
|
+
else if (entry.name.endsWith('.weave')) {
|
|
69
|
+
results.push(rel);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function formatElapsed(ms) {
|
|
74
|
+
if (ms < 1)
|
|
75
|
+
return `${Math.round(ms * 1000)}µs`;
|
|
76
|
+
if (ms < 1000)
|
|
77
|
+
return `${Math.round(ms)}ms`;
|
|
78
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
79
|
+
}
|
|
80
|
+
export function formatCodeFrame(source, line, col) {
|
|
81
|
+
const lines = source.split('\n');
|
|
82
|
+
if (line < 1 || line > lines.length)
|
|
83
|
+
return '';
|
|
84
|
+
const sourceLine = lines[line - 1];
|
|
85
|
+
const lineNum = String(line);
|
|
86
|
+
const gutter = ' '.repeat(lineNum.length);
|
|
87
|
+
return `\n ${lineNum} | ${sourceLine}\n ${gutter} | ${' '.repeat(col - 1)}^`;
|
|
88
|
+
}
|
|
89
|
+
export function formatError(filePath, err, source) {
|
|
90
|
+
let line;
|
|
91
|
+
let col;
|
|
92
|
+
let msg;
|
|
93
|
+
if (err instanceof LexerError || err instanceof ParserError || err instanceof CodegenError) {
|
|
94
|
+
line = err.line;
|
|
95
|
+
col = err.col;
|
|
96
|
+
msg = err.message.replace(/ at line \d+, col \d+$/, '');
|
|
97
|
+
}
|
|
98
|
+
else if (err instanceof Error) {
|
|
99
|
+
msg = err.message;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
msg = String(err);
|
|
103
|
+
}
|
|
104
|
+
const location = line !== undefined && col !== undefined ? `${filePath}:${line}:${col}` : filePath;
|
|
105
|
+
let result = `weave: ${location}: ${msg}`;
|
|
106
|
+
if (source && line !== undefined && col !== undefined) {
|
|
107
|
+
result += formatCodeFrame(source, line, col);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
function writeCompiled(inputFile, outputFile, source, sourcemap) {
|
|
112
|
+
const start = performance.now();
|
|
113
|
+
if (sourcemap) {
|
|
114
|
+
const basename = path.basename(outputFile);
|
|
115
|
+
const sourceRelPath = path.relative(path.dirname(outputFile), inputFile);
|
|
116
|
+
const { code, sourceMap } = compileWithSourceMap(source, {
|
|
117
|
+
file: basename,
|
|
118
|
+
sourceFile: sourceRelPath,
|
|
119
|
+
});
|
|
120
|
+
mkdirSync(path.dirname(outputFile), { recursive: true });
|
|
121
|
+
writeFileSync(outputFile, code + `//# sourceMappingURL=${basename}.map\n`);
|
|
122
|
+
writeFileSync(outputFile + '.map', JSON.stringify(sourceMap));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const result = compile(source);
|
|
126
|
+
mkdirSync(path.dirname(outputFile), { recursive: true });
|
|
127
|
+
writeFileSync(outputFile, result);
|
|
128
|
+
}
|
|
129
|
+
return performance.now() - start;
|
|
130
|
+
}
|
|
131
|
+
export function compileFile(inputFile, outputFile, sourcemap = true) {
|
|
132
|
+
const source = readFileSync(inputFile, 'utf-8');
|
|
133
|
+
const elapsed = writeCompiled(inputFile, outputFile, source, sourcemap);
|
|
134
|
+
console.log(`${outputFile} (${formatElapsed(elapsed)})`);
|
|
135
|
+
}
|
|
136
|
+
export function compileDir(inputDir, outputDir, sourcemap = true) {
|
|
137
|
+
let files;
|
|
138
|
+
try {
|
|
139
|
+
files = discoverFiles(inputDir);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
|
|
143
|
+
console.error(`weave: ${inputDir}: no such file or directory`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.error(`weave: ${inputDir}: ${err instanceof Error ? err.message : String(err)}`);
|
|
147
|
+
}
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
if (files.length === 0) {
|
|
151
|
+
console.error(`weave: no .weave files found in ${inputDir}`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
let hasErrors = false;
|
|
155
|
+
for (const relPath of files) {
|
|
156
|
+
const inFile = path.join(inputDir, relPath);
|
|
157
|
+
const outFile = path.join(outputDir, relPath.replace(/\.weave$/, '.ts'));
|
|
158
|
+
const source = readFileSync(inFile, 'utf-8');
|
|
159
|
+
try {
|
|
160
|
+
const elapsed = writeCompiled(inFile, outFile, source, sourcemap);
|
|
161
|
+
console.log(`${outFile} (${formatElapsed(elapsed)})`);
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
console.error(formatError(inFile, err, source));
|
|
165
|
+
hasErrors = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return hasErrors;
|
|
169
|
+
}
|
|
170
|
+
export function watchDir(inputDir, outputDir, sourcemap = true) {
|
|
171
|
+
compileDir(inputDir, outputDir, sourcemap);
|
|
172
|
+
console.log('\nwatching for changes...');
|
|
173
|
+
const pending = new Map();
|
|
174
|
+
watch(inputDir, { recursive: true }, (_event, filename) => {
|
|
175
|
+
if (!filename || !filename.endsWith('.weave'))
|
|
176
|
+
return;
|
|
177
|
+
// Debounce: fs.watch fires multiple events per save
|
|
178
|
+
const existing = pending.get(filename);
|
|
179
|
+
if (existing)
|
|
180
|
+
clearTimeout(existing);
|
|
181
|
+
pending.set(filename, setTimeout(() => {
|
|
182
|
+
pending.delete(filename);
|
|
183
|
+
compileWatchedFile(inputDir, outputDir, filename, sourcemap);
|
|
184
|
+
}, 50));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function compileWatchedFile(inputDir, outputDir, relPath, sourcemap) {
|
|
188
|
+
const inFile = path.join(inputDir, relPath);
|
|
189
|
+
const outFile = path.join(outputDir, relPath.replace(/\.weave$/, '.ts'));
|
|
190
|
+
let source;
|
|
191
|
+
try {
|
|
192
|
+
source = readFileSync(inFile, 'utf-8');
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// File may have been deleted — ignore
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const elapsed = writeCompiled(inFile, outFile, source, sourcemap);
|
|
200
|
+
console.log(`${outFile} (${formatElapsed(elapsed)})`);
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
console.error(formatError(inFile, err, source));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export function main(argv) {
|
|
207
|
+
let args;
|
|
208
|
+
try {
|
|
209
|
+
args = parseArgs(argv);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
if (err instanceof UsageError) {
|
|
213
|
+
console.error(`weave: ${err.message}\n`);
|
|
214
|
+
console.error(usage());
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
throw err;
|
|
218
|
+
}
|
|
219
|
+
if (args.mode === 'help') {
|
|
220
|
+
console.log(usage());
|
|
221
|
+
process.exit(0);
|
|
222
|
+
}
|
|
223
|
+
const { inputPath, outputPath, sourcemap } = args;
|
|
224
|
+
if (args.mode === 'watch') {
|
|
225
|
+
watchDir(inputPath, outputPath, sourcemap);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (inputPath.endsWith('.weave')) {
|
|
229
|
+
// Single-file mode
|
|
230
|
+
const outFile = outputPath.endsWith('.ts')
|
|
231
|
+
? outputPath
|
|
232
|
+
: path.join(outputPath, path.basename(inputPath).replace(/\.weave$/, '.ts'));
|
|
233
|
+
const source = readFileSync(inputPath, 'utf-8');
|
|
234
|
+
try {
|
|
235
|
+
const elapsed = writeCompiled(inputPath, outFile, source, sourcemap);
|
|
236
|
+
console.log(`${outFile} (${formatElapsed(elapsed)})`);
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
console.error(formatError(inputPath, err, source));
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
// Directory mode
|
|
245
|
+
if (compileDir(inputPath, outputPath, sourcemap)) {
|
|
246
|
+
process.exit(1);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpF,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAwBlD,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAA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AM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC;YACtC,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAA;QAChF,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAC/C,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;YACpE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,KAAK,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QACzD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;YAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,iBAAiB;QACjB,IAAI,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,CAAC;YAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AstNode, DocumentNode } from '../parser/types.js';
|
|
2
|
+
import type { Mapping, SourceMap } from './sourcemap.js';
|
|
3
|
+
export type { CodeChunk, Mapping, SourceMap } from './sourcemap.js';
|
|
4
|
+
export interface GenerateResult {
|
|
5
|
+
code: string;
|
|
6
|
+
mappings: Mapping[];
|
|
7
|
+
}
|
|
8
|
+
export declare class CodegenError extends Error {
|
|
9
|
+
readonly line: number;
|
|
10
|
+
readonly col: number;
|
|
11
|
+
constructor(message: string, line: number, col: number);
|
|
12
|
+
}
|
|
13
|
+
/** Generate a TypeScript expression from a single AST node. */
|
|
14
|
+
export declare function generateExpr(node: AstNode): string;
|
|
15
|
+
/** Generate TypeScript source from a DocumentNode. */
|
|
16
|
+
export declare function generate(doc: DocumentNode): GenerateResult;
|
|
17
|
+
/** Full pipeline: source string → TypeScript source. */
|
|
18
|
+
export declare function compile(source: string): string;
|
|
19
|
+
/** Full pipeline with source map generation. */
|
|
20
|
+
export declare function compileWithSourceMap(source: string, opts: {
|
|
21
|
+
file: string;
|
|
22
|
+
sourceFile: string;
|
|
23
|
+
}): {
|
|
24
|
+
code: string;
|
|
25
|
+
sourceMap: SourceMap;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,OAAO,EAIP,YAAY,EAef,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAa,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAGnE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAEnE,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,EAAE,CAAA;CACtB;AAED,qBAAa,YAAa,SAAQ,KAAK;IACnC,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,GAAG,EAAE,MAAM,CAAA;gBAEf,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;CAMzD;AAmiBD,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAKlD;AAED,sDAAsD;AACtD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,cAAc,CAwE1D;AAED,wDAAwD;AACxD,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED,gDAAgD;AAChD,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAMxC"}
|