@oxc-solid-js/compiler 1.1.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 +77 -0
- package/index.d.ts +119 -0
- package/index.js +131 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 taskylizard
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# oxc-solid-js
|
|
2
|
+
|
|
3
|
+
Native JSX compiler for [Solid.js](https://www.solidjs.com/) users built with the [OXC](https://oxc.rs/) toolchain.
|
|
4
|
+
|
|
5
|
+
Very work in progress, but I encourage you to try it out and report issues!
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# compiler
|
|
11
|
+
npm install @oxc-solid-js/compiler
|
|
12
|
+
|
|
13
|
+
# vite plugin
|
|
14
|
+
npm install -D @oxc-solid-js/vite
|
|
15
|
+
|
|
16
|
+
# rolldown plugin
|
|
17
|
+
npm install -D @oxc-solid-js/rolldown
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Vite
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
// vite.config.js
|
|
26
|
+
import { defineConfig } from "vite";
|
|
27
|
+
import solidOxc from "@oxc-solid-js/vite";
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
plugins: [solidOxc()],
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Options:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
solidOxc({
|
|
38
|
+
generate: "dom", // "dom" | "ssr" | "universal"
|
|
39
|
+
hydratable: false,
|
|
40
|
+
hot: true, // HMR via solid-refresh (dev only)
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Rolldown
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
// rolldown.config.js
|
|
48
|
+
import solidOxc from "@oxc-solid-js/rolldown";
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
plugins: [solidOxc()],
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Direct API
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import { transformJsx } from "@oxc-solid-js/compiler";
|
|
59
|
+
|
|
60
|
+
const { code, map } = transformJsx(`<div class="hello">world</div>`, {
|
|
61
|
+
generate: "dom",
|
|
62
|
+
moduleName: "solid-js/web",
|
|
63
|
+
sourceMap: true,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
This project is licensed under the [MIT License](./LICENSE).
|
|
70
|
+
|
|
71
|
+
This project also contains code derived or copied from the following projects:
|
|
72
|
+
|
|
73
|
+
- [babel-plugin-jsx-dom-expressions (MIT)](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions)
|
|
74
|
+
- [solid-refresh (MIT)](https://github.com/solidjs/solid-refresh)
|
|
75
|
+
- [vite-plugin-solid (MIT)](https://github.com/solidjs/vite-plugin-solid)
|
|
76
|
+
|
|
77
|
+
Licenses of these projects are listed in [THIRD-PARTY-LICENSES](./THIRD-PARTY-LICENSES).
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export interface JsRendererConfig {
|
|
4
|
+
name: string
|
|
5
|
+
moduleName: string
|
|
6
|
+
elements: Array<string>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Transform options exposed to JavaScript */
|
|
10
|
+
export interface JsTransformOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The module to import runtime helpers from
|
|
13
|
+
* @default "solid-js/web"
|
|
14
|
+
*/
|
|
15
|
+
moduleName?: string
|
|
16
|
+
/** Multi-renderer configuration used by `generate: "dynamic"` */
|
|
17
|
+
renderers?: Array<JsRendererConfig>
|
|
18
|
+
/**
|
|
19
|
+
* Generate mode: "dom", "ssr", "universal", or "dynamic"
|
|
20
|
+
* @default "dom"
|
|
21
|
+
*/
|
|
22
|
+
generate?: string
|
|
23
|
+
/**
|
|
24
|
+
* Whether to enable hydration support
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
hydratable?: boolean
|
|
28
|
+
/**
|
|
29
|
+
* Whether to delegate events
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
delegateEvents?: boolean
|
|
33
|
+
/**
|
|
34
|
+
* Whether to wrap conditionals
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
wrapConditionals?: boolean
|
|
38
|
+
/**
|
|
39
|
+
* Whether nested closing tags may be omitted in template output
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
omitNestedClosingTags?: boolean
|
|
43
|
+
/**
|
|
44
|
+
* Whether the last closing tag may be omitted in template output
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
omitLastClosingTag?: boolean
|
|
48
|
+
/**
|
|
49
|
+
* Whether static attributes may omit quotes when safe
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
omitQuotes?: boolean
|
|
53
|
+
/**
|
|
54
|
+
* Whether static styles may be inlined into template HTML
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
inlineStyles?: boolean
|
|
58
|
+
/**
|
|
59
|
+
* Whether to pass context to custom elements
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
62
|
+
contextToCustomElements?: boolean
|
|
63
|
+
/**
|
|
64
|
+
* Source filename
|
|
65
|
+
* @default "input.jsx"
|
|
66
|
+
*/
|
|
67
|
+
filename?: string
|
|
68
|
+
/**
|
|
69
|
+
* Whether to generate source maps
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
72
|
+
sourceMap?: boolean
|
|
73
|
+
/**
|
|
74
|
+
* Only transform files containing a matching `@jsxImportSource <value>` comment
|
|
75
|
+
* @default undefined
|
|
76
|
+
*/
|
|
77
|
+
requireImportSource?: string
|
|
78
|
+
/**
|
|
79
|
+
* Whether to validate generated HTML templates for browser rewrites
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
validate?: boolean
|
|
83
|
+
/**
|
|
84
|
+
* Enable HMR (solid-refresh) transform
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
hmr?: boolean
|
|
88
|
+
/**
|
|
89
|
+
* HMR bundler type: "esm", "vite", "standard", "webpack5", "rspack-esm"
|
|
90
|
+
* @default "standard"
|
|
91
|
+
*/
|
|
92
|
+
hmrBundler?: string
|
|
93
|
+
/**
|
|
94
|
+
* Enable granular HMR (dependency tracking + signatures)
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
hmrGranular?: boolean
|
|
98
|
+
/**
|
|
99
|
+
* Enable JSX expression extraction for HMR
|
|
100
|
+
* @default true
|
|
101
|
+
*/
|
|
102
|
+
hmrJsx?: boolean
|
|
103
|
+
/**
|
|
104
|
+
* Fix render() calls for HMR (wrap with cleanup + dispose)
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
hmrFixRender?: boolean
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Transform JSX source code */
|
|
111
|
+
export declare function transformJsx(source: string, options?: JsTransformOptions | undefined | null): TransformResult
|
|
112
|
+
|
|
113
|
+
/** Result of a transform operation */
|
|
114
|
+
export interface TransformResult {
|
|
115
|
+
/** The transformed code */
|
|
116
|
+
code: string
|
|
117
|
+
/** Source map (if enabled) */
|
|
118
|
+
map?: string
|
|
119
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oxc-solid-js/compiler - OXC-based JSX compiler for SolidJS
|
|
3
|
+
*
|
|
4
|
+
* CJS entry point - provides the same interface as babel-preset-solid.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { platform, arch } = require('node:process');
|
|
8
|
+
const { join } = require('node:path');
|
|
9
|
+
|
|
10
|
+
let nativeBinding = null;
|
|
11
|
+
|
|
12
|
+
const explicitPath = process.env.NAPI_RS_NATIVE_LIBRARY_PATH;
|
|
13
|
+
if (explicitPath) {
|
|
14
|
+
try {
|
|
15
|
+
nativeBinding = require(explicitPath);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.warn(`@oxc-solid-js/compiler: Failed to load native module from ${explicitPath}.`);
|
|
18
|
+
console.warn(e instanceof Error ? e.message : String(e));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Map Node.js platform/arch to binary file suffix
|
|
23
|
+
const platformMap = {
|
|
24
|
+
'darwin-arm64': 'darwin-arm64',
|
|
25
|
+
'darwin-x64': 'darwin-x64',
|
|
26
|
+
'linux-x64': 'linux-x64-gnu',
|
|
27
|
+
'linux-arm64': 'linux-arm64-gnu',
|
|
28
|
+
'win32-x64': 'win32-x64-msvc',
|
|
29
|
+
'win32-arm64': 'win32-arm64-msvc',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const platformKey = `${platform}-${arch}`;
|
|
33
|
+
const nativeTarget = platformMap[platformKey];
|
|
34
|
+
|
|
35
|
+
// Try to load the native module
|
|
36
|
+
if (!nativeBinding) {
|
|
37
|
+
try {
|
|
38
|
+
if (nativeTarget) {
|
|
39
|
+
// Try platform-specific binary first
|
|
40
|
+
nativeBinding = require(join(__dirname, `oxc-solid-js-compiler.${nativeTarget}.node`));
|
|
41
|
+
} else {
|
|
42
|
+
// Fallback to generic name
|
|
43
|
+
nativeBinding = require(join(__dirname, 'oxc-solid-js-compiler.node'));
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
// Fallback message if native module not found
|
|
47
|
+
console.warn(
|
|
48
|
+
`@oxc-solid-js/compiler: Native module not found for ${platformKey}. Run \`npm run build\` to compile.`,
|
|
49
|
+
);
|
|
50
|
+
console.warn(e instanceof Error ? e.message : String(e));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Default options matching babel-preset-solid
|
|
56
|
+
*/
|
|
57
|
+
const defaultOptions = {
|
|
58
|
+
moduleName: 'solid-js/web',
|
|
59
|
+
builtIns: [
|
|
60
|
+
'For',
|
|
61
|
+
'Show',
|
|
62
|
+
'Switch',
|
|
63
|
+
'Match',
|
|
64
|
+
'Suspense',
|
|
65
|
+
'SuspenseList',
|
|
66
|
+
'Portal',
|
|
67
|
+
'Index',
|
|
68
|
+
'Dynamic',
|
|
69
|
+
'ErrorBoundary',
|
|
70
|
+
],
|
|
71
|
+
contextToCustomElements: true,
|
|
72
|
+
wrapConditionals: true,
|
|
73
|
+
generate: 'dom', // 'dom' | 'ssr' | 'universal'
|
|
74
|
+
hydratable: false,
|
|
75
|
+
delegateEvents: true,
|
|
76
|
+
sourceMap: false,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Transform JSX source code
|
|
81
|
+
* @param {string} source - The source code to transform
|
|
82
|
+
* @param {object} options - Transform options
|
|
83
|
+
* @returns {{ code: string, map?: string }}
|
|
84
|
+
*/
|
|
85
|
+
function transform(source, options = {}) {
|
|
86
|
+
if (!nativeBinding) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
'@oxc-solid-js/compiler: Native module not loaded. Ensure it is built for your platform.',
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
93
|
+
|
|
94
|
+
// NAPI-RS automatically converts camelCase (JS) to snake_case (Rust)
|
|
95
|
+
// so we can pass options directly without manual conversion
|
|
96
|
+
return nativeBinding.transformJsx(source, mergedOptions);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create a preset configuration (for compatibility with babel-preset-solid interface)
|
|
101
|
+
* @param {object} _context - Babel context (ignored, for compatibility)
|
|
102
|
+
* @param {object} options - User options
|
|
103
|
+
* @returns {object}
|
|
104
|
+
*/
|
|
105
|
+
function preset(_context, options = {}) {
|
|
106
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
// Return the options that would be passed to the transform
|
|
110
|
+
options: mergedOptions,
|
|
111
|
+
|
|
112
|
+
// The transform function
|
|
113
|
+
transform: (source) => transform(source, mergedOptions),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Low-level transform function from the native binding
|
|
119
|
+
*/
|
|
120
|
+
const transformJsx = nativeBinding ? nativeBinding.transformJsx : null;
|
|
121
|
+
|
|
122
|
+
exports.transform = transform;
|
|
123
|
+
exports.preset = preset;
|
|
124
|
+
exports.defaultOptions = defaultOptions;
|
|
125
|
+
exports.transformJsx = transformJsx;
|
|
126
|
+
exports.default = {
|
|
127
|
+
transform,
|
|
128
|
+
preset,
|
|
129
|
+
defaultOptions,
|
|
130
|
+
transformJsx,
|
|
131
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oxc-solid-js/compiler",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Port of babel-jsx-dom-expressions to oxc",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"N-API",
|
|
7
|
+
"NAPI",
|
|
8
|
+
"Rust",
|
|
9
|
+
"napi-rs",
|
|
10
|
+
"node-addon",
|
|
11
|
+
"node-addon-api"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+ssh://git@github.com/taskylizard/oxc-solid-js.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"index.js"
|
|
21
|
+
],
|
|
22
|
+
"main": "index.js",
|
|
23
|
+
"types": "index.d.ts",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"artifacts": "napi artifacts",
|
|
30
|
+
"bench": "node --import @oxc-node/core/register benchmark/bench.ts",
|
|
31
|
+
"build": "napi build --platform --release --features napi --no-js --dts index.d.ts",
|
|
32
|
+
"build:debug": "napi build --platform",
|
|
33
|
+
"format": "run-p format:js format:rs",
|
|
34
|
+
"format:js": "oxfmt .",
|
|
35
|
+
"format:rs": "cargo fmt",
|
|
36
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
37
|
+
"version": "napi version"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@emnapi/core": "^1.5.0",
|
|
41
|
+
"@emnapi/runtime": "^1.5.0",
|
|
42
|
+
"@napi-rs/cli": "^3.2.0",
|
|
43
|
+
"@napi-rs/wasm-runtime": "^1.0.4",
|
|
44
|
+
"@oxc-node/core": "^0.0.35",
|
|
45
|
+
"@tybys/wasm-util": "^0.10.0",
|
|
46
|
+
"chalk": "^5.6.2",
|
|
47
|
+
"emnapi": "^1.5.0",
|
|
48
|
+
"husky": "^9.1.7",
|
|
49
|
+
"lint-staged": "^16.1.6",
|
|
50
|
+
"npm-run-all2": "^8.0.4",
|
|
51
|
+
"oxfmt": "^0.42.0",
|
|
52
|
+
"tinybench": "^6.0.0",
|
|
53
|
+
"typescript": "^5.9.2"
|
|
54
|
+
},
|
|
55
|
+
"lint-staged": {
|
|
56
|
+
"*.@(js|ts|tsx|yml|yaml|md|json)": [
|
|
57
|
+
"oxfmt"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"napi": {
|
|
61
|
+
"constEnum": true,
|
|
62
|
+
"binaryName": "oxc-solid-js-compiler",
|
|
63
|
+
"targets": [
|
|
64
|
+
"x86_64-apple-darwin",
|
|
65
|
+
"aarch64-apple-darwin",
|
|
66
|
+
"x86_64-unknown-linux-gnu",
|
|
67
|
+
"x86_64-pc-windows-msvc"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0 < 10 || >= 10.0.0"
|
|
72
|
+
},
|
|
73
|
+
"packageManager": "pnpm@10.32.1",
|
|
74
|
+
"optionalDependencies": {
|
|
75
|
+
"@oxc-solid-js/compiler-darwin-x64": "1.1.1",
|
|
76
|
+
"@oxc-solid-js/compiler-darwin-arm64": "1.1.1",
|
|
77
|
+
"@oxc-solid-js/compiler-linux-x64-gnu": "1.1.1",
|
|
78
|
+
"@oxc-solid-js/compiler-win32-x64-msvc": "1.1.1"
|
|
79
|
+
}
|
|
80
|
+
}
|