@rsvelte/compiler 0.2.0 → 0.3.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/LICENSE +21 -0
- package/README.md +247 -107
- package/package.json +19 -33
- package/svelte_compiler_rust.d.ts +108 -0
- package/svelte_compiler_rust.js +455 -0
- package/svelte_compiler_rust_bg.wasm +0 -0
- package/index.cjs +0 -79
- package/index.d.ts +0 -140
- package/index.js +0 -133
package/index.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// rsvelte - High-performance Svelte compiler
|
|
2
|
-
// Native binding with WASM fallback
|
|
3
|
-
|
|
4
|
-
import { createRequire } from 'node:module';
|
|
5
|
-
|
|
6
|
-
let nativeBinding = null;
|
|
7
|
-
let loadError = null;
|
|
8
|
-
|
|
9
|
-
function loadNativeBinding() {
|
|
10
|
-
const platform = process.platform;
|
|
11
|
-
const arch = process.arch;
|
|
12
|
-
|
|
13
|
-
const platformPackages = {
|
|
14
|
-
'darwin-arm64': '@rsvelte/binding-darwin-arm64',
|
|
15
|
-
'darwin-x64': '@rsvelte/binding-darwin-x64',
|
|
16
|
-
'linux-x64': '@rsvelte/binding-linux-x64-gnu',
|
|
17
|
-
'linux-arm64': '@rsvelte/binding-linux-arm64-gnu',
|
|
18
|
-
'win32-x64': '@rsvelte/binding-win32-x64-msvc',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const key = `${platform}-${arch}`;
|
|
22
|
-
const packageName = platformPackages[key];
|
|
23
|
-
|
|
24
|
-
if (!packageName) {
|
|
25
|
-
loadError = new Error(`Unsupported platform: ${key}`);
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const require = createRequire(import.meta.url);
|
|
31
|
-
return require(packageName);
|
|
32
|
-
} catch (e) {
|
|
33
|
-
loadError = e;
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
nativeBinding = loadNativeBinding();
|
|
39
|
-
|
|
40
|
-
function getBinding() {
|
|
41
|
-
if (nativeBinding) return nativeBinding;
|
|
42
|
-
throw new Error(
|
|
43
|
-
`rsvelte native binding not available for this platform. ` +
|
|
44
|
-
`Ensure the correct @rsvelte/binding-* package is installed. ` +
|
|
45
|
-
`Error: ${loadError?.message}`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Compile a Svelte component.
|
|
51
|
-
* @param {string} source - Svelte component source code
|
|
52
|
-
* @param {object} [options] - Compilation options
|
|
53
|
-
* @returns {object} Compilation result with js, css, warnings, and metadata
|
|
54
|
-
*/
|
|
55
|
-
export function compile(source, options = {}) {
|
|
56
|
-
return getBinding().compile(source, options);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Compile a Svelte module (.svelte.js/.svelte.ts).
|
|
61
|
-
* @param {string} source - Module source code
|
|
62
|
-
* @param {object} [options] - Compilation options
|
|
63
|
-
* @returns {object} Compilation result
|
|
64
|
-
*/
|
|
65
|
-
export function compileModule(source, options = {}) {
|
|
66
|
-
return getBinding().compileModule(source, options);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Parse a Svelte component into an AST.
|
|
71
|
-
* @param {string} source - Svelte component source code
|
|
72
|
-
* @param {object} [options] - Parse options
|
|
73
|
-
* @returns {object} AST
|
|
74
|
-
*/
|
|
75
|
-
export function parse(source, options = {}) {
|
|
76
|
-
return getBinding().parse(source, options);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Preprocess a Svelte component.
|
|
81
|
-
* NOTE: This is an async function.
|
|
82
|
-
* @param {string} source - Svelte component source code
|
|
83
|
-
* @param {object|object[]} preprocessor - Preprocessor(s)
|
|
84
|
-
* @param {object} [options] - Preprocess options
|
|
85
|
-
* @returns {Promise<object>} Preprocessed result
|
|
86
|
-
*/
|
|
87
|
-
export async function preprocess(source, preprocessor, options = {}) {
|
|
88
|
-
return getBinding().preprocess(source, preprocessor, options);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Print an AST back to source code.
|
|
93
|
-
* @param {object} ast - Svelte AST
|
|
94
|
-
* @param {object} [options] - Print options
|
|
95
|
-
* @returns {object} Print result with code and map
|
|
96
|
-
*/
|
|
97
|
-
export function print(ast, options = {}) {
|
|
98
|
-
return getBinding().print(ast, options);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Parse CSS.
|
|
103
|
-
* @param {string} source - CSS source code
|
|
104
|
-
* @returns {object} Parsed CSS AST
|
|
105
|
-
*/
|
|
106
|
-
export function parseCss(source) {
|
|
107
|
-
return getBinding().parseCss(source);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @deprecated Use estree-walker instead.
|
|
112
|
-
*/
|
|
113
|
-
export function walk() {
|
|
114
|
-
throw new Error(
|
|
115
|
-
'walk() is deprecated. Use estree-walker instead: https://github.com/Rich-Harris/estree-walker'
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Not yet implemented in rsvelte.
|
|
121
|
-
*/
|
|
122
|
-
export function migrate() {
|
|
123
|
-
throw new Error('migrate() is not yet implemented in rsvelte.');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** Compiler version string. */
|
|
127
|
-
let _version;
|
|
128
|
-
try {
|
|
129
|
-
_version = nativeBinding?.getVersion?.() ?? '0.2.0';
|
|
130
|
-
} catch {
|
|
131
|
-
_version = '0.2.0';
|
|
132
|
-
}
|
|
133
|
-
export const VERSION = _version;
|