@macroforge/svelte-preprocessor 0.1.79 → 0.1.80
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 +6 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,37 +1,10 @@
|
|
|
1
1
|
# @macroforge/svelte-preprocessor
|
|
2
2
|
|
|
3
|
-
Svelte preprocessor for expanding Macroforge macros in component script blocks
|
|
4
|
-
|
|
5
3
|
[](https://www.npmjs.com/package/@macroforge/svelte-preprocessor)
|
|
6
4
|
|
|
7
5
|
## Overview
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Svelte preprocessor for expanding Macroforge macros in component script blocks.
|
|
12
|
-
|
|
13
|
-
This module provides integration between Macroforge's macro expansion system and
|
|
14
|
-
Svelte's preprocessing pipeline. It intercepts `<script>` blocks in `.svelte`
|
|
15
|
-
files, detects `@derive` decorators, and expands them into generated code before
|
|
16
|
-
TypeScript compilation occurs.
|
|
17
|
-
|
|
18
|
-
## How It Works
|
|
19
|
-
|
|
20
|
-
1. The preprocessor is registered in `svelte.config.js` as part of the
|
|
21
|
-
preprocess array
|
|
22
|
-
2. When Svelte compiles a component, it passes each `<script>` block to this
|
|
23
|
-
preprocessor
|
|
24
|
-
3. The preprocessor checks if the script contains `@derive` decorators
|
|
25
|
-
4. If found, it calls the native `macroforge` binding to expand the macros
|
|
26
|
-
5. The expanded code replaces the original script content
|
|
27
|
-
|
|
28
|
-
## Important Notes
|
|
29
|
-
|
|
30
|
-
- Must be placed BEFORE other preprocessors (like `vitePreprocess()`) in the
|
|
31
|
-
chain
|
|
32
|
-
- Uses lazy-loading for native bindings to avoid initialization overhead
|
|
33
|
-
- Gracefully degrades if native bindings are unavailable
|
|
34
|
-
- Only processes TypeScript blocks by default (configurable via options)
|
|
7
|
+
Svelte preprocessor for expanding Macroforge macros in component script blocks
|
|
35
8
|
|
|
36
9
|
## Installation
|
|
37
10
|
|
|
@@ -43,23 +16,17 @@ npm install @macroforge/svelte-preprocessor
|
|
|
43
16
|
|
|
44
17
|
### Functions
|
|
45
18
|
|
|
46
|
-
- **`macroforgePreprocess`** -
|
|
47
|
-
|
|
19
|
+
- **`macroforgePreprocess`** - Creates a Svelte preprocessor that expands
|
|
20
|
+
Macroforge macros in `<script>` blocks.
|
|
48
21
|
|
|
49
|
-
###
|
|
22
|
+
### Interfaces
|
|
50
23
|
|
|
51
|
-
- **`ExpandResult`** - Whether to preserve `@derive` decorators in the expanded
|
|
52
|
-
output.
|
|
53
24
|
- **`MacroforgePreprocessorOptions`** - Configuration options for the Macroforge
|
|
54
25
|
Svelte preprocessor.
|
|
55
26
|
|
|
56
|
-
|
|
27
|
+
### Constants
|
|
57
28
|
|
|
58
|
-
|
|
59
|
-
macroforgePreprocess();
|
|
60
|
-
macroforgePreprocess({ keepDecorators: true });
|
|
61
|
-
macroforgePreprocess({ processJavaScript: true });
|
|
62
|
-
```
|
|
29
|
+
- **`default`** - Default export for convenient importing.
|
|
63
30
|
|
|
64
31
|
## Documentation
|
|
65
32
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA6OvE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,6BAAkC,GAC1C,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA6OvE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,6BAAkC,GAC1C,iBAAiB,CAoJnB;AAED;;;;;;;GAOG;AACH,eAAe,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
*
|
|
26
26
|
* @packageDocumentation
|
|
27
27
|
*/
|
|
28
|
-
import { hasMacroAnnotations } from "@macroforge/shared";
|
|
29
28
|
// ============================================================================
|
|
30
29
|
// Source Map Generation
|
|
31
30
|
// ============================================================================
|
|
@@ -271,14 +270,7 @@ export function macroforgePreprocess(options = {}) {
|
|
|
271
270
|
/*
|
|
272
271
|
* STEP 2: Quick Scan Optimization
|
|
273
272
|
*
|
|
274
|
-
|
|
275
|
-
* Most components won't have macros, so this saves the cost of loading
|
|
276
|
-
* and calling the native expansion engine in the common case.
|
|
277
|
-
*/
|
|
278
|
-
if (!hasMacroAnnotations(content)) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
/*
|
|
273
|
+
/*
|
|
282
274
|
* STEP 3: Load Native Bindings
|
|
283
275
|
*
|
|
284
276
|
* The expansion engine is a native module (Rust compiled to Node addon).
|
|
@@ -327,7 +319,8 @@ export function macroforgePreprocess(options = {}) {
|
|
|
327
319
|
* - map: Source map for debugging (optional, not yet implemented)
|
|
328
320
|
*/
|
|
329
321
|
if (result.code && result.code !== content) {
|
|
330
|
-
const mapping = result
|
|
322
|
+
const mapping = result
|
|
323
|
+
.sourceMapping;
|
|
331
324
|
const map = mapping?.segments?.length && filename
|
|
332
325
|
? buildSourceMap(content, result.code, mapping, filename)
|
|
333
326
|
: undefined;
|
package/package.json
CHANGED