@fukict/babel-preset 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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/auto-define-fukict.d.ts +9 -0
- package/dist/auto-define-fukict.d.ts.map +1 -0
- package/dist/auto-define-fukict.js +230 -0
- package/dist/auto-define-fukict.js.map +1 -0
- package/dist/display-name.d.ts +9 -0
- package/dist/display-name.d.ts.map +1 -0
- package/dist/display-name.js +118 -0
- package/dist/display-name.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-transform.d.ts +9 -0
- package/dist/jsx-transform.d.ts.map +1 -0
- package/dist/jsx-transform.js +304 -0
- package/dist/jsx-transform.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +52 -0
- package/dist/utils.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Fukict Team
|
|
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,103 @@
|
|
|
1
|
+
# @fukict/babel-preset
|
|
2
|
+
|
|
3
|
+
Zero-config Babel preset for Fukict with automatic component wrapping and JSX compilation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Zero Configuration**: Just add the preset, no extra setup needed
|
|
8
|
+
- **Auto Component Wrapping**: Automatically wraps function components with `defineFukict`
|
|
9
|
+
- **Built-in JSX Transform**: Compiles JSX to hyperscript calls
|
|
10
|
+
- **Development Mode**: Injects `displayName` for better debugging
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add -D @fukict/babel-preset @babel/core
|
|
16
|
+
pnpm add @fukict/basic
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### babel.config.js
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
module.exports = {
|
|
25
|
+
presets: ['@fukict/babel-preset'],
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### .babelrc.json
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"presets": ["@fukict/babel-preset"]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## What it does
|
|
38
|
+
|
|
39
|
+
### Auto Component Wrapping
|
|
40
|
+
|
|
41
|
+
Automatically wraps uppercase-named arrow functions that return JSX:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// Input
|
|
45
|
+
const Greeting = ({ name }) => <div>Hello {name}</div>;
|
|
46
|
+
|
|
47
|
+
// Output
|
|
48
|
+
import { defineFukict } from '@fukict/basic';
|
|
49
|
+
const Greeting = defineFukict(({ name }) => <div>Hello {name}</div>);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### JSX Transform
|
|
53
|
+
|
|
54
|
+
Transforms JSX to hyperscript calls:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// Input
|
|
58
|
+
<div class="container" on:click={handleClick}>
|
|
59
|
+
Hello {name}
|
|
60
|
+
</div>;
|
|
61
|
+
|
|
62
|
+
// Output
|
|
63
|
+
hyperscript(
|
|
64
|
+
'div',
|
|
65
|
+
{ class: 'container', 'on:click': handleClick },
|
|
66
|
+
'Hello ',
|
|
67
|
+
name,
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Development Mode
|
|
72
|
+
|
|
73
|
+
In development mode (`NODE_ENV=development`), automatically injects `displayName`:
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
// Input
|
|
77
|
+
const Greeting = ({ name }) => <div>Hello {name}</div>;
|
|
78
|
+
|
|
79
|
+
// Output (development)
|
|
80
|
+
const Greeting = defineFukict(({ name }) => <div>Hello {name}</div>);
|
|
81
|
+
Greeting.displayName = 'Greeting';
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Opt-out
|
|
85
|
+
|
|
86
|
+
Use `@nofukict` comment to prevent auto-wrapping:
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
/** @nofukict */
|
|
90
|
+
const helper = () => <div>Not a component</div>;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Documentation
|
|
94
|
+
|
|
95
|
+
See [docs](./docs) for detailed documentation:
|
|
96
|
+
|
|
97
|
+
- [DESIGN.md](./docs/DESIGN.md) - Design decisions and architecture
|
|
98
|
+
- [API.md](./docs/API.md) - API reference
|
|
99
|
+
- [EXAMPLES.md](./docs/EXAMPLES.md) - Usage examples
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PluginObj } from '@babel/core';
|
|
2
|
+
import type { PluginOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Auto defineFukict Plugin
|
|
5
|
+
* Automatically wraps function components with defineFukict
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: (api: object, options: PluginOptions | null | undefined, dirname: string) => PluginObj<import("@babel/core").PluginPass>;
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=auto-define-fukict.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-define-fukict.d.ts","sourceRoot":"","sources":["../src/auto-define-fukict.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAc,MAAM,aAAa,CAAC;AAGnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD;;;GAGG;;AACH,wBA6NG"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
/**
|
|
6
|
+
* Auto defineFukict Plugin
|
|
7
|
+
* Automatically wraps function components with defineFukict
|
|
8
|
+
*/
|
|
9
|
+
exports.default = (0, helper_plugin_utils_1.declare)(api => {
|
|
10
|
+
api.assertVersion(7);
|
|
11
|
+
const { types: t } = api;
|
|
12
|
+
return {
|
|
13
|
+
name: '@fukict/babel-preset/auto-define-fukict',
|
|
14
|
+
visitor: {
|
|
15
|
+
Program(path) {
|
|
16
|
+
let needsDefineFukict = false;
|
|
17
|
+
// First pass: check if we need defineFukict
|
|
18
|
+
path.traverse({
|
|
19
|
+
VariableDeclarator(varPath) {
|
|
20
|
+
if (shouldWrapComponent(varPath, t)) {
|
|
21
|
+
needsDefineFukict = true;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
// Add import if needed
|
|
26
|
+
if (needsDefineFukict) {
|
|
27
|
+
// Check if defineFukict is already imported
|
|
28
|
+
const hasImport = path.node.body.some(node => {
|
|
29
|
+
if (!t.isImportDeclaration(node))
|
|
30
|
+
return false;
|
|
31
|
+
if (node.source.value !== '@fukict/basic')
|
|
32
|
+
return false;
|
|
33
|
+
return node.specifiers.some(spec => t.isImportSpecifier(spec) &&
|
|
34
|
+
t.isIdentifier(spec.imported) &&
|
|
35
|
+
spec.imported.name === 'defineFukict');
|
|
36
|
+
});
|
|
37
|
+
if (!hasImport) {
|
|
38
|
+
// Find existing @fukict/basic import
|
|
39
|
+
const existingImport = path.node.body.find(node => t.isImportDeclaration(node) &&
|
|
40
|
+
node.source.value === '@fukict/basic');
|
|
41
|
+
if (existingImport) {
|
|
42
|
+
// Add to existing import
|
|
43
|
+
existingImport.specifiers.push(t.importSpecifier(t.identifier('defineFukict'), t.identifier('defineFukict')));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Create new import
|
|
47
|
+
const importDeclaration = t.importDeclaration([
|
|
48
|
+
t.importSpecifier(t.identifier('defineFukict'), t.identifier('defineFukict')),
|
|
49
|
+
], t.stringLiteral('@fukict/basic'));
|
|
50
|
+
path.unshiftContainer('body', importDeclaration);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
VariableDeclarator(path) {
|
|
56
|
+
if (!shouldWrapComponent(path, t)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const id = path.node.id;
|
|
60
|
+
const init = path.node.init;
|
|
61
|
+
if (!init || !t.isIdentifier(id))
|
|
62
|
+
return;
|
|
63
|
+
// Check if already wrapped
|
|
64
|
+
if (isDefineFukictCall(init, t)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// Wrap with defineFukict
|
|
68
|
+
const wrappedInit = t.callExpression(t.identifier('defineFukict'), [
|
|
69
|
+
init,
|
|
70
|
+
]);
|
|
71
|
+
path.node.init = wrappedInit;
|
|
72
|
+
// Add __COMPONENT_TYPE__ marker after variable declaration
|
|
73
|
+
// This allows JSX transform to know it's a function component at compile time
|
|
74
|
+
const parentPath = path.parentPath;
|
|
75
|
+
if (parentPath && parentPath.isVariableDeclaration()) {
|
|
76
|
+
const grandParentPath = parentPath.parentPath;
|
|
77
|
+
// Only add type marker if we're in a valid statement context
|
|
78
|
+
if (grandParentPath &&
|
|
79
|
+
(grandParentPath.isProgram() || grandParentPath.isBlockStatement())) {
|
|
80
|
+
const typeMarker = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(id.name), t.identifier('__COMPONENT_TYPE__')), t.stringLiteral('function')));
|
|
81
|
+
parentPath.insertAfter(typeMarker);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
ExportDefaultDeclaration(path) {
|
|
86
|
+
const declaration = path.node.declaration;
|
|
87
|
+
// Only handle anonymous function components
|
|
88
|
+
if (!t.isArrowFunctionExpression(declaration) &&
|
|
89
|
+
!t.isFunctionExpression(declaration)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// Check if returns JSX
|
|
93
|
+
if (!returnsJSX(declaration, t)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Check for @nofukict comment
|
|
97
|
+
if ((0, utils_js_1.hasNoFukictComment)(path.node.leadingComments)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// Check if already wrapped
|
|
101
|
+
if (isDefineFukictCall(declaration, t)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// Create a temporary variable for the wrapped component
|
|
105
|
+
const tempId = path.scope.generateUidIdentifier('component');
|
|
106
|
+
// Wrap with defineFukict
|
|
107
|
+
const wrappedComponent = t.callExpression(t.identifier('defineFukict'), [declaration]);
|
|
108
|
+
// Create variable declaration
|
|
109
|
+
const varDeclaration = t.variableDeclaration('const', [
|
|
110
|
+
t.variableDeclarator(tempId, wrappedComponent),
|
|
111
|
+
]);
|
|
112
|
+
// Add __COMPONENT_TYPE__ marker
|
|
113
|
+
const typeMarker = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(tempId, t.identifier('__COMPONENT_TYPE__')), t.stringLiteral('function')));
|
|
114
|
+
// Export the temp variable
|
|
115
|
+
const exportDeclaration = t.exportDefaultDeclaration(tempId);
|
|
116
|
+
path.replaceWithMultiple([
|
|
117
|
+
varDeclaration,
|
|
118
|
+
typeMarker,
|
|
119
|
+
exportDeclaration,
|
|
120
|
+
]);
|
|
121
|
+
},
|
|
122
|
+
// Handle class components
|
|
123
|
+
ClassDeclaration(path) {
|
|
124
|
+
const node = path.node;
|
|
125
|
+
const id = node.id;
|
|
126
|
+
// Must have a name
|
|
127
|
+
if (!id)
|
|
128
|
+
return;
|
|
129
|
+
// Check if it extends Fukict
|
|
130
|
+
if (!extendsClass(node, 'Fukict', t)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// Add __COMPONENT_TYPE__ marker after class declaration
|
|
134
|
+
const parentPath = path.parentPath;
|
|
135
|
+
if (parentPath &&
|
|
136
|
+
(parentPath.isProgram() ||
|
|
137
|
+
parentPath.isBlockStatement() ||
|
|
138
|
+
parentPath.isExportNamedDeclaration() ||
|
|
139
|
+
parentPath.isExportDefaultDeclaration())) {
|
|
140
|
+
const typeMarker = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(id.name), t.identifier('__COMPONENT_TYPE__')), t.stringLiteral('class')));
|
|
141
|
+
// Insert after the class or after the export statement
|
|
142
|
+
if (parentPath.isExportNamedDeclaration() ||
|
|
143
|
+
parentPath.isExportDefaultDeclaration()) {
|
|
144
|
+
parentPath.insertAfter(typeMarker);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
path.insertAfter(typeMarker);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
/**
|
|
155
|
+
* Check if a variable declarator should be wrapped with defineFukict
|
|
156
|
+
*/
|
|
157
|
+
function shouldWrapComponent(path, t) {
|
|
158
|
+
const id = path.node.id;
|
|
159
|
+
const init = path.node.init;
|
|
160
|
+
// Must be identifier (const Greeting = ...)
|
|
161
|
+
if (!t.isIdentifier(id)) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
// Check if name starts with uppercase
|
|
165
|
+
if (!(0, utils_js_1.isComponentName)(id.name)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
// Must be function expression or arrow function
|
|
169
|
+
if (!t.isArrowFunctionExpression(init) && !t.isFunctionExpression(init)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
// Check if returns JSX
|
|
173
|
+
if (!returnsJSX(init, t)) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
// Check for @nofukict comment
|
|
177
|
+
const parent = path.parentPath;
|
|
178
|
+
if (parent &&
|
|
179
|
+
parent.node &&
|
|
180
|
+
(0, utils_js_1.hasNoFukictComment)(parent.node.leadingComments)) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if a function returns JSX
|
|
187
|
+
*/
|
|
188
|
+
function returnsJSX(func, t) {
|
|
189
|
+
// Arrow function with expression body
|
|
190
|
+
if (t.isArrowFunctionExpression(func) &&
|
|
191
|
+
(t.isJSXElement(func.body) || t.isJSXFragment(func.body))) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
// Check block statement for return statements
|
|
195
|
+
if (t.isBlockStatement(func.body)) {
|
|
196
|
+
let hasJSXReturn = false;
|
|
197
|
+
// Simple traverse to check return statements
|
|
198
|
+
for (const statement of func.body.body) {
|
|
199
|
+
if (t.isReturnStatement(statement)) {
|
|
200
|
+
const argument = statement.argument;
|
|
201
|
+
if (t.isJSXElement(argument) || t.isJSXFragment(argument)) {
|
|
202
|
+
hasJSXReturn = true;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return hasJSXReturn;
|
|
208
|
+
}
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Check if expression is a defineFukict call
|
|
213
|
+
*/
|
|
214
|
+
function isDefineFukictCall(node, t) {
|
|
215
|
+
if (!node)
|
|
216
|
+
return false;
|
|
217
|
+
return (t.isCallExpression(node) &&
|
|
218
|
+
t.isIdentifier(node.callee) &&
|
|
219
|
+
node.callee.name === 'defineFukict');
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Check if a class extends a specific base class
|
|
223
|
+
*/
|
|
224
|
+
function extendsClass(node, className, t) {
|
|
225
|
+
const superClass = node.superClass;
|
|
226
|
+
if (!superClass)
|
|
227
|
+
return false;
|
|
228
|
+
return t.isIdentifier(superClass) && superClass.name === className;
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=auto-define-fukict.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-define-fukict.js","sourceRoot":"","sources":["../src/auto-define-fukict.ts"],"names":[],"mappings":";;AACA,oEAAqD;AAGrD,yCAAiE;AAEjE;;;GAGG;AACH,kBAAe,IAAA,6BAAO,EAAgB,GAAG,CAAC,EAAE;IAC1C,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAErB,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,GA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,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CACzB,IAAqD,EACrD,CAAgC;IAEhC,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IAExB,OAAO,CACL,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC;QACxB,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,cAAc,CACpC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CACnB,IAAwB,EACxB,SAAiB,EACjB,CAAgC;IAEhC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACnC,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAE9B,OAAO,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PluginObj } from '@babel/core';
|
|
2
|
+
import type { PluginOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Display Name Plugin
|
|
5
|
+
* Injects displayName for components in development mode
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: (api: object, options: PluginOptions | null | undefined, dirname: string) => PluginObj<import("@babel/core").PluginPass>;
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=display-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-name.d.ts","sourceRoot":"","sources":["../src/display-name.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAc,MAAM,aAAa,CAAC;AAGnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD;;;GAGG;;AACH,wBAwHG"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
/**
|
|
6
|
+
* Display Name Plugin
|
|
7
|
+
* Injects displayName for components in development mode
|
|
8
|
+
*/
|
|
9
|
+
exports.default = (0, helper_plugin_utils_1.declare)((api, options) => {
|
|
10
|
+
api.assertVersion(7);
|
|
11
|
+
const { types: t } = api;
|
|
12
|
+
const { development = false } = options;
|
|
13
|
+
// Skip in production mode
|
|
14
|
+
if (!development) {
|
|
15
|
+
return {
|
|
16
|
+
name: '@fukict/babel-preset/display-name',
|
|
17
|
+
visitor: {},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
name: '@fukict/babel-preset/display-name',
|
|
22
|
+
visitor: {
|
|
23
|
+
VariableDeclarator(path) {
|
|
24
|
+
const id = path.node.id;
|
|
25
|
+
const init = path.node.init;
|
|
26
|
+
// Must be identifier
|
|
27
|
+
if (!t.isIdentifier(id)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Check if name starts with uppercase (component)
|
|
31
|
+
if (!(0, utils_js_1.isComponentName)(id.name)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Must be defineFukict call or function
|
|
35
|
+
if (!isDefineFukictCall(init, t) &&
|
|
36
|
+
!t.isArrowFunctionExpression(init) &&
|
|
37
|
+
!t.isFunctionExpression(init)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Inject displayName
|
|
41
|
+
injectDisplayName(path, id.name, t);
|
|
42
|
+
},
|
|
43
|
+
ExportDefaultDeclaration(path) {
|
|
44
|
+
const declaration = path.node.declaration;
|
|
45
|
+
// Skip function/class declarations
|
|
46
|
+
if (t.isFunctionDeclaration(declaration) ||
|
|
47
|
+
t.isClassDeclaration(declaration)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Handle anonymous default export
|
|
51
|
+
if (t.isArrowFunctionExpression(declaration) ||
|
|
52
|
+
t.isFunctionExpression(declaration)) {
|
|
53
|
+
// Create a variable for the component
|
|
54
|
+
const componentId = path.scope.generateUidIdentifier('Component');
|
|
55
|
+
// Replace export with variable declaration + export
|
|
56
|
+
const varDeclaration = t.variableDeclaration('const', [
|
|
57
|
+
t.variableDeclarator(componentId, declaration),
|
|
58
|
+
]);
|
|
59
|
+
// Add displayName
|
|
60
|
+
const displayNameAssignment = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(componentId, t.identifier('displayName')), t.stringLiteral('DefaultExport')));
|
|
61
|
+
// Export the component
|
|
62
|
+
const exportDeclaration = t.exportDefaultDeclaration(componentId);
|
|
63
|
+
path.replaceWithMultiple([
|
|
64
|
+
varDeclaration,
|
|
65
|
+
displayNameAssignment,
|
|
66
|
+
exportDeclaration,
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
else if (t.isCallExpression(declaration) &&
|
|
70
|
+
t.isIdentifier(declaration.callee) &&
|
|
71
|
+
declaration.callee.name === 'defineFukict') {
|
|
72
|
+
// Handle defineFukict call
|
|
73
|
+
const componentId = path.scope.generateUidIdentifier('Component');
|
|
74
|
+
const varDeclaration = t.variableDeclaration('const', [
|
|
75
|
+
t.variableDeclarator(componentId, declaration),
|
|
76
|
+
]);
|
|
77
|
+
const displayNameAssignment = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(componentId, t.identifier('displayName')), t.stringLiteral('DefaultExport')));
|
|
78
|
+
const exportDeclaration = t.exportDefaultDeclaration(componentId);
|
|
79
|
+
path.replaceWithMultiple([
|
|
80
|
+
varDeclaration,
|
|
81
|
+
displayNameAssignment,
|
|
82
|
+
exportDeclaration,
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* Inject displayName assignment after variable declaration
|
|
91
|
+
*/
|
|
92
|
+
function injectDisplayName(path, name, t) {
|
|
93
|
+
const parentPath = path.parentPath;
|
|
94
|
+
if (!parentPath || !parentPath.isVariableDeclaration()) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const grandParentPath = parentPath.parentPath;
|
|
98
|
+
// Only inject if we're in a valid statement context
|
|
99
|
+
if (!grandParentPath ||
|
|
100
|
+
!(grandParentPath.isProgram() || grandParentPath.isBlockStatement())) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Create displayName assignment
|
|
104
|
+
const displayNameAssignment = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(name), t.identifier('displayName')), t.stringLiteral(name)));
|
|
105
|
+
// Insert after the variable declaration
|
|
106
|
+
parentPath.insertAfter(displayNameAssignment);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if expression is a defineFukict call
|
|
110
|
+
*/
|
|
111
|
+
function isDefineFukictCall(node, t) {
|
|
112
|
+
if (!node)
|
|
113
|
+
return false;
|
|
114
|
+
return (t.isCallExpression(node) &&
|
|
115
|
+
t.isIdentifier(node.callee) &&
|
|
116
|
+
node.callee.name === 'defineFukict');
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=display-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-name.js","sourceRoot":"","sources":["../src/display-name.ts"],"names":[],"mappings":";;AACA,oEAAqD;AAGrD,yCAA6C;AAE7C;;;GAGG;AACH,kBAAe,IAAA,6BAAO,EAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;IACrD,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAErB,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,GAAG,CAAC;IACzB,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAExC,0BAA0B;IAC1B,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;YACL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AAC,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,cAAc,CACpC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const auto_define_fukict_1 = __importDefault(require("./auto-define-fukict"));
|
|
7
|
+
const display_name_1 = __importDefault(require("./display-name"));
|
|
8
|
+
const jsx_transform_1 = __importDefault(require("./jsx-transform"));
|
|
9
|
+
/**
|
|
10
|
+
* Fukict Babel Preset
|
|
11
|
+
* Zero-config preset with JSX transform and auto component wrapping
|
|
12
|
+
*/
|
|
13
|
+
function fukictPreset(_api, options = {}) {
|
|
14
|
+
const { development = process.env.NODE_ENV !== 'production', typescript = true, // Enable TypeScript support by default
|
|
15
|
+
} = options;
|
|
16
|
+
const pluginOptions = {
|
|
17
|
+
development,
|
|
18
|
+
};
|
|
19
|
+
const presets = [];
|
|
20
|
+
const plugins = [
|
|
21
|
+
// 0. Enable JSX syntax parsing
|
|
22
|
+
'@babel/plugin-syntax-jsx',
|
|
23
|
+
// 1. Auto wrap components with defineFukict (must run before JSX transform)
|
|
24
|
+
[auto_define_fukict_1.default, pluginOptions],
|
|
25
|
+
// 2. Transform JSX to hyperscript
|
|
26
|
+
[jsx_transform_1.default, pluginOptions],
|
|
27
|
+
// 3. Inject displayName in development mode
|
|
28
|
+
[display_name_1.default, pluginOptions],
|
|
29
|
+
];
|
|
30
|
+
// Add TypeScript support if enabled
|
|
31
|
+
if (typescript) {
|
|
32
|
+
presets.push([
|
|
33
|
+
'@babel/preset-typescript',
|
|
34
|
+
{
|
|
35
|
+
// Allow JSX in .tsx files
|
|
36
|
+
isTSX: true,
|
|
37
|
+
// Treat all files as modules
|
|
38
|
+
allExtensions: true,
|
|
39
|
+
},
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
presets,
|
|
44
|
+
plugins,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// CommonJS export for Babel 7 compatibility
|
|
48
|
+
module.exports = fukictPreset;
|
|
49
|
+
// Also export as default for dual compatibility
|
|
50
|
+
module.exports.default = fukictPreset;
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,8EAAoD;AACpD,kEAAyC;AACzC,oEAA2C;AAG3C;;;GAGG;AACH,SAAS,YAAY,CAAC,IAAS,EAAE,UAA+B,EAAE;IAChE,MAAM,EACJ,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EACnD,UAAU,GAAG,IAAI,EAAE,uCAAuC;MAC3D,GAAG,OAAO,CAAC;IAEZ,MAAM,aAAa,GAAG;QACpB,WAAW;KACZ,CAAC;IAEF,MAAM,OAAO,GAAU,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAU;QACrB,+BAA+B;QAC/B,0BAA0B;QAE1B,4EAA4E;QAC5E,CAAC,4BAAgB,EAAE,aAAa,CAAC;QAEjC,kCAAkC;QAClC,CAAC,uBAAY,EAAE,aAAa,CAAC;QAE7B,4CAA4C;QAC5C,CAAC,sBAAW,EAAE,aAAa,CAAC;KAC7B,CAAC;IAEF,oCAAoC;IACpC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC;YACX,0BAA0B;YAC1B;gBACE,0BAA0B;gBAC1B,KAAK,EAAE,IAAI;gBACX,6BAA6B;gBAC7B,aAAa,EAAE,IAAI;aACpB;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,OAAO;QACP,OAAO;KACR,CAAC;AACJ,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC;AAC9B,gDAAgD;AAC/C,MAAM,CAAC,OAA6C,CAAC,OAAO,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PluginObj } from '@babel/core';
|
|
2
|
+
import type { PluginOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* JSX Transform Plugin
|
|
5
|
+
* Transforms JSX to hyperscript calls
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: (api: object, options: PluginOptions | null | undefined, dirname: string) => PluginObj<import("@babel/core").PluginPass>;
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=jsx-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-transform.d.ts","sourceRoot":"","sources":["../src/jsx-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,aAAa,CAAC;AAGzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD;;;GAGG;;AACH,wBA4UG"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
/**
|
|
6
|
+
* JSX Transform Plugin
|
|
7
|
+
* Transforms JSX to hyperscript calls
|
|
8
|
+
*/
|
|
9
|
+
exports.default = (0, helper_plugin_utils_1.declare)(api => {
|
|
10
|
+
api.assertVersion(7);
|
|
11
|
+
const { types: t } = api;
|
|
12
|
+
return {
|
|
13
|
+
name: '@fukict/babel-preset/jsx-transform',
|
|
14
|
+
visitor: {
|
|
15
|
+
Program(path) {
|
|
16
|
+
// Track if we need to import hyperscript and Fragment
|
|
17
|
+
let needsHyperscript = false;
|
|
18
|
+
let needsFragment = false;
|
|
19
|
+
path.traverse({
|
|
20
|
+
JSXElement() {
|
|
21
|
+
needsHyperscript = true;
|
|
22
|
+
},
|
|
23
|
+
JSXFragment() {
|
|
24
|
+
needsHyperscript = true;
|
|
25
|
+
needsFragment = true;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
// Add imports if needed
|
|
29
|
+
if (needsHyperscript || needsFragment) {
|
|
30
|
+
// Find existing VALUE import from @fukict/basic (not type-only)
|
|
31
|
+
let existingImport = null;
|
|
32
|
+
for (const node of path.node.body) {
|
|
33
|
+
if (t.isImportDeclaration(node) &&
|
|
34
|
+
node.source.value === '@fukict/basic' &&
|
|
35
|
+
node.importKind !== 'type' // Skip type-only imports
|
|
36
|
+
) {
|
|
37
|
+
existingImport = node;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const existingSpecifierNames = new Set();
|
|
42
|
+
if (existingImport) {
|
|
43
|
+
for (const spec of existingImport.specifiers) {
|
|
44
|
+
if (t.isImportSpecifier(spec) && t.isIdentifier(spec.imported)) {
|
|
45
|
+
existingSpecifierNames.add(spec.imported.name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Collect specifiers to add
|
|
50
|
+
const specsToAdd = [];
|
|
51
|
+
if (needsHyperscript && !existingSpecifierNames.has('hyperscript')) {
|
|
52
|
+
specsToAdd.push(t.importSpecifier(t.identifier('hyperscript'), t.identifier('hyperscript')));
|
|
53
|
+
}
|
|
54
|
+
if (needsFragment && !existingSpecifierNames.has('Fragment')) {
|
|
55
|
+
specsToAdd.push(t.importSpecifier(t.identifier('Fragment'), t.identifier('Fragment')));
|
|
56
|
+
}
|
|
57
|
+
// Add missing specifiers
|
|
58
|
+
if (specsToAdd.length > 0) {
|
|
59
|
+
if (existingImport) {
|
|
60
|
+
// Add to existing import
|
|
61
|
+
existingImport.specifiers.push(...specsToAdd);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Create new import declaration
|
|
65
|
+
const importDeclaration = t.importDeclaration(specsToAdd, t.stringLiteral('@fukict/basic'));
|
|
66
|
+
path.unshiftContainer('body', importDeclaration);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
JSXElement: {
|
|
72
|
+
exit(path) {
|
|
73
|
+
const node = path.node;
|
|
74
|
+
const openingElement = node.openingElement;
|
|
75
|
+
// Get element type
|
|
76
|
+
let elementType;
|
|
77
|
+
let vnodeTypeHint = null;
|
|
78
|
+
if (t.isJSXIdentifier(openingElement.name)) {
|
|
79
|
+
const name = openingElement.name.name;
|
|
80
|
+
// Check if it's Fragment
|
|
81
|
+
if (name === 'Fragment') {
|
|
82
|
+
elementType = t.identifier('Fragment');
|
|
83
|
+
vnodeTypeHint = 'fragment';
|
|
84
|
+
}
|
|
85
|
+
else if (name[0] === name[0].toUpperCase()) {
|
|
86
|
+
// Component (uppercase) - try to determine type at compile time
|
|
87
|
+
elementType = t.identifier(name);
|
|
88
|
+
// Check if we can determine component type via __COMPONENT_TYPE__
|
|
89
|
+
// This will be a runtime check: ComponentName.__COMPONENT_TYPE__ || 'function'
|
|
90
|
+
// For now, we'll generate code that reads __COMPONENT_TYPE__ at runtime
|
|
91
|
+
vnodeTypeHint = 'component'; // Special marker for component
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Native element (lowercase) - use string literal for tag name
|
|
95
|
+
elementType = t.stringLiteral(name);
|
|
96
|
+
vnodeTypeHint = 'element';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (t.isJSXMemberExpression(openingElement.name)) {
|
|
100
|
+
elementType = convertJSXMemberExpression(openingElement.name, t);
|
|
101
|
+
// Member expressions are components
|
|
102
|
+
vnodeTypeHint = 'component';
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw path.buildCodeFrameError('Unsupported JSX element type');
|
|
106
|
+
}
|
|
107
|
+
// Build props object and extract fukict:slot
|
|
108
|
+
const { props, slotName } = buildProps(openingElement.attributes, t);
|
|
109
|
+
// Get children paths - at this point, child JSX nodes have already been transformed
|
|
110
|
+
const childrenPaths = path.get('children');
|
|
111
|
+
const children = [];
|
|
112
|
+
for (const childPath of childrenPaths) {
|
|
113
|
+
const child = childPath.node;
|
|
114
|
+
if (t.isJSXText(child)) {
|
|
115
|
+
const text = child.value.replace(/\s+/g, ' ');
|
|
116
|
+
if (text.trim() === '')
|
|
117
|
+
continue;
|
|
118
|
+
children.push(t.stringLiteral(text));
|
|
119
|
+
}
|
|
120
|
+
else if (t.isJSXExpressionContainer(child)) {
|
|
121
|
+
if (t.isJSXEmptyExpression(child.expression))
|
|
122
|
+
continue;
|
|
123
|
+
const expr = child.expression;
|
|
124
|
+
// Spread arrays for:
|
|
125
|
+
// 1. CallExpression (e.g., demos.map(...)) - likely returns array
|
|
126
|
+
// 2. Identifier named "children" - props.children is typically an array
|
|
127
|
+
if (t.isCallExpression(expr) ||
|
|
128
|
+
(t.isIdentifier(expr) && expr.name === 'children')) {
|
|
129
|
+
// Use spread with runtime array check
|
|
130
|
+
children.push(t.spreadElement(t.conditionalExpression(t.callExpression(t.memberExpression(t.identifier('Array'), t.identifier('isArray')), [expr]), expr, t.arrayExpression([expr]))));
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// For all other expressions, push directly
|
|
134
|
+
children.push(expr);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (t.isJSXSpreadChild(child)) {
|
|
138
|
+
// Skip spread children
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
else if (t.isExpression(child)) {
|
|
142
|
+
// This should be the transformed JSX element (now an expression)
|
|
143
|
+
children.push(child);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Create hyperscript call directly: hyperscript(type, props, children)
|
|
147
|
+
const call = t.callExpression(t.identifier('hyperscript'), [
|
|
148
|
+
elementType,
|
|
149
|
+
props,
|
|
150
|
+
t.arrayExpression(children),
|
|
151
|
+
]);
|
|
152
|
+
// Build assignments: __type__ and optionally __slot_name__
|
|
153
|
+
const vnodeId = path.scope.generateUidIdentifier('vnode');
|
|
154
|
+
const assignments = [];
|
|
155
|
+
// Add __type__ based on what we know at compile time
|
|
156
|
+
if (vnodeTypeHint === 'element' || vnodeTypeHint === 'fragment') {
|
|
157
|
+
// For element and fragment, we know the exact type
|
|
158
|
+
assignments.push(t.assignmentExpression('=', t.memberExpression(vnodeId, t.identifier('__type__')), t.stringLiteral(vnodeTypeHint)));
|
|
159
|
+
}
|
|
160
|
+
else if (vnodeTypeHint === 'component') {
|
|
161
|
+
// For components, read __COMPONENT_TYPE__ at runtime
|
|
162
|
+
assignments.push(t.assignmentExpression('=', t.memberExpression(vnodeId, t.identifier('__type__')),
|
|
163
|
+
// Read __COMPONENT_TYPE__ from component function, default to runtime detection
|
|
164
|
+
t.logicalExpression('||', t.memberExpression(elementType, t.identifier('__COMPONENT_TYPE__')),
|
|
165
|
+
// Fallback: let runtime detect (class vs function)
|
|
166
|
+
t.stringLiteral('function'))));
|
|
167
|
+
}
|
|
168
|
+
// Add __slot_name__ if fukict:slot is present
|
|
169
|
+
if (slotName) {
|
|
170
|
+
assignments.push(t.assignmentExpression('=', t.memberExpression(vnodeId, t.identifier('__slot_name__')), t.stringLiteral(slotName)));
|
|
171
|
+
}
|
|
172
|
+
// Wrap with IIFE if we have assignments
|
|
173
|
+
if (assignments.length > 0) {
|
|
174
|
+
const wrappedCall = t.callExpression(t.arrowFunctionExpression([vnodeId], t.sequenceExpression([...assignments, vnodeId])), [call]);
|
|
175
|
+
path.replaceWith(wrappedCall);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// No optimization possible
|
|
179
|
+
path.replaceWith(call);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
JSXFragment: {
|
|
184
|
+
exit(path) {
|
|
185
|
+
// Get children paths - at this point, child JSX nodes have already been transformed
|
|
186
|
+
const childrenPaths = path.get('children');
|
|
187
|
+
const children = [];
|
|
188
|
+
for (const childPath of childrenPaths) {
|
|
189
|
+
const child = childPath.node;
|
|
190
|
+
if (t.isJSXText(child)) {
|
|
191
|
+
const text = child.value.replace(/\s+/g, ' ');
|
|
192
|
+
if (text.trim() === '')
|
|
193
|
+
continue;
|
|
194
|
+
children.push(t.stringLiteral(text));
|
|
195
|
+
}
|
|
196
|
+
else if (t.isJSXExpressionContainer(child)) {
|
|
197
|
+
if (t.isJSXEmptyExpression(child.expression))
|
|
198
|
+
continue;
|
|
199
|
+
const expr = child.expression;
|
|
200
|
+
// Spread arrays for:
|
|
201
|
+
// 1. CallExpression (e.g., demos.map(...)) - likely returns array
|
|
202
|
+
// 2. Identifier named "children" - props.children is typically an array
|
|
203
|
+
if (t.isCallExpression(expr) ||
|
|
204
|
+
(t.isIdentifier(expr) && expr.name === 'children')) {
|
|
205
|
+
// Use spread with runtime array check
|
|
206
|
+
children.push(t.spreadElement(t.conditionalExpression(t.callExpression(t.memberExpression(t.identifier('Array'), t.identifier('isArray')), [expr]), expr, t.arrayExpression([expr]))));
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// For all other expressions, push directly
|
|
210
|
+
children.push(expr);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (t.isJSXSpreadChild(child)) {
|
|
214
|
+
// Skip spread children
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
else if (t.isExpression(child)) {
|
|
218
|
+
// This should be the transformed JSX element (now an expression)
|
|
219
|
+
children.push(child);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Create hyperscript call with Fragment
|
|
223
|
+
const call = t.callExpression(t.identifier('hyperscript'), [
|
|
224
|
+
t.identifier('Fragment'),
|
|
225
|
+
t.nullLiteral(),
|
|
226
|
+
t.arrayExpression(children),
|
|
227
|
+
]);
|
|
228
|
+
// Add __type__ for Fragment
|
|
229
|
+
const vnodeId = path.scope.generateUidIdentifier('vnode');
|
|
230
|
+
const wrappedCall = t.callExpression(t.arrowFunctionExpression([vnodeId], t.sequenceExpression([
|
|
231
|
+
t.assignmentExpression('=', t.memberExpression(vnodeId, t.identifier('__type__')), t.stringLiteral('fragment')),
|
|
232
|
+
vnodeId,
|
|
233
|
+
])), [call]);
|
|
234
|
+
path.replaceWith(wrappedCall);
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
/**
|
|
241
|
+
* Convert JSX member expression to member expression
|
|
242
|
+
*/
|
|
243
|
+
function convertJSXMemberExpression(node, t) {
|
|
244
|
+
if (t.isJSXIdentifier(node.object)) {
|
|
245
|
+
return t.memberExpression(t.identifier(node.object.name), t.identifier(node.property.name));
|
|
246
|
+
}
|
|
247
|
+
if (t.isJSXMemberExpression(node.object)) {
|
|
248
|
+
return t.memberExpression(convertJSXMemberExpression(node.object, t), t.identifier(node.property.name));
|
|
249
|
+
}
|
|
250
|
+
throw new Error('Unsupported JSX member expression');
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Build props object from JSX attributes
|
|
254
|
+
* Returns both props and extracted fukict:slot value
|
|
255
|
+
*/
|
|
256
|
+
function buildProps(attributes, t) {
|
|
257
|
+
if (attributes.length === 0) {
|
|
258
|
+
return { props: t.nullLiteral(), slotName: null };
|
|
259
|
+
}
|
|
260
|
+
const properties = [];
|
|
261
|
+
let slotName = null;
|
|
262
|
+
for (const attr of attributes) {
|
|
263
|
+
if (t.isJSXSpreadAttribute(attr)) {
|
|
264
|
+
properties.push(t.spreadElement(attr.argument));
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const name = (0, utils_js_1.getAttributeName)(attr, t);
|
|
268
|
+
// Extract fukict:slot and don't add it to props
|
|
269
|
+
if (name === 'fukict:slot') {
|
|
270
|
+
if (t.isStringLiteral(attr.value)) {
|
|
271
|
+
slotName = attr.value.value;
|
|
272
|
+
}
|
|
273
|
+
else if (t.isJSXExpressionContainer(attr.value)) {
|
|
274
|
+
// Only support string literals for slot names
|
|
275
|
+
if (t.isStringLiteral(attr.value.expression)) {
|
|
276
|
+
slotName = attr.value.expression.value;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
continue; // Skip adding to props
|
|
280
|
+
}
|
|
281
|
+
const normalizedName = (0, utils_js_1.normalizeAttributeName)(name);
|
|
282
|
+
let value;
|
|
283
|
+
if (attr.value === null) {
|
|
284
|
+
// <div disabled /> -> { disabled: true }
|
|
285
|
+
value = t.booleanLiteral(true);
|
|
286
|
+
}
|
|
287
|
+
else if (t.isStringLiteral(attr.value)) {
|
|
288
|
+
value = attr.value;
|
|
289
|
+
}
|
|
290
|
+
else if (t.isJSXExpressionContainer(attr.value)) {
|
|
291
|
+
if (t.isJSXEmptyExpression(attr.value.expression)) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
value = attr.value.expression;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
properties.push(t.objectProperty(t.stringLiteral(normalizedName), value));
|
|
300
|
+
}
|
|
301
|
+
const props = properties.length === 0 ? t.nullLiteral() : t.objectExpression(properties);
|
|
302
|
+
return { props, slotName };
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=jsx-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-transform.js","sourceRoot":"","sources":["../src/jsx-transform.ts"],"names":[],"mappings":";;AACA,oEAAqD;AAGrD,yCAAsE;AAEtE;;;GAGG;AACH,kBAAe,IAAA,6BAAO,EAAgB,GAAG,CAAC,EAAE;IAC1C,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAErB,MAAM,EAAE,KAAK,EAAE,C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0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Babel preset options for Fukict
|
|
3
|
+
*/
|
|
4
|
+
export interface FukictPresetOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Development mode
|
|
7
|
+
* @default process.env.NODE_ENV !== 'production'
|
|
8
|
+
*/
|
|
9
|
+
development?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Enable TypeScript support
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
typescript?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Internal plugin options
|
|
18
|
+
*/
|
|
19
|
+
export interface PluginOptions {
|
|
20
|
+
development: boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a JSX element is a Fragment
|
|
4
|
+
*/
|
|
5
|
+
export declare function isFragment(node: t.JSXElement, t: typeof import('@babel/types')): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Check if identifier name starts with uppercase
|
|
8
|
+
*/
|
|
9
|
+
export declare function isComponentName(name: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Check if node has @nofukict comment
|
|
12
|
+
*/
|
|
13
|
+
export declare function hasNoFukictComment(comments: ReadonlyArray<t.Comment> | null | undefined): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Extract JSX attribute name (handles namespaced names like on:click)
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAttributeName(attribute: t.JSXAttribute, t: typeof import('@babel/types')): string;
|
|
18
|
+
/**
|
|
19
|
+
* Convert className to class
|
|
20
|
+
*/
|
|
21
|
+
export declare function normalizeAttributeName(name: string): string;
|
|
22
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,CAAC,CAAC,UAAU,EAClB,CAAC,EAAE,cAAc,cAAc,CAAC,GAC/B,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GACpD,OAAO,CAIT;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,CAAC,CAAC,YAAY,EACzB,CAAC,EAAE,cAAc,cAAc,CAAC,GAC/B,MAAM,CAUR;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3D"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFragment = isFragment;
|
|
4
|
+
exports.isComponentName = isComponentName;
|
|
5
|
+
exports.hasNoFukictComment = hasNoFukictComment;
|
|
6
|
+
exports.getAttributeName = getAttributeName;
|
|
7
|
+
exports.normalizeAttributeName = normalizeAttributeName;
|
|
8
|
+
/**
|
|
9
|
+
* Check if a JSX element is a Fragment
|
|
10
|
+
*/
|
|
11
|
+
function isFragment(node, t) {
|
|
12
|
+
const openingElement = node.openingElement;
|
|
13
|
+
return (t.isJSXFragment(openingElement) ||
|
|
14
|
+
(t.isJSXIdentifier(openingElement.name) &&
|
|
15
|
+
openingElement.name.name === 'Fragment'));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if identifier name starts with uppercase
|
|
19
|
+
*/
|
|
20
|
+
function isComponentName(name) {
|
|
21
|
+
return /^[A-Z]/.test(name);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check if node has @nofukict comment
|
|
25
|
+
*/
|
|
26
|
+
function hasNoFukictComment(comments) {
|
|
27
|
+
if (!comments)
|
|
28
|
+
return false;
|
|
29
|
+
return comments.some(comment => /@nofukict/.test(comment.value));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Extract JSX attribute name (handles namespaced names like on:click)
|
|
33
|
+
*/
|
|
34
|
+
function getAttributeName(attribute, t) {
|
|
35
|
+
if (t.isJSXIdentifier(attribute.name)) {
|
|
36
|
+
return attribute.name.name;
|
|
37
|
+
}
|
|
38
|
+
if (t.isJSXNamespacedName(attribute.name)) {
|
|
39
|
+
return `${attribute.name.namespace.name}:${attribute.name.name.name}`;
|
|
40
|
+
}
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert className to class
|
|
45
|
+
*/
|
|
46
|
+
function normalizeAttributeName(name) {
|
|
47
|
+
if (name === 'className') {
|
|
48
|
+
return 'class';
|
|
49
|
+
}
|
|
50
|
+
return name;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"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AAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fukict/babel-preset",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zero-config Babel preset for Fukict with automatic component wrapping",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"fukict",
|
|
7
|
+
"babel",
|
|
8
|
+
"preset",
|
|
9
|
+
"jsx",
|
|
10
|
+
"compiler",
|
|
11
|
+
"transform"
|
|
12
|
+
],
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/fukict/fukict/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/fukict/fukict.git",
|
|
19
|
+
"directory": "packages/babel-preset"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Fukict Team",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@babel/core": "^7.26.0",
|
|
37
|
+
"@babel/helper-plugin-utils": "^7.25.9",
|
|
38
|
+
"@babel/plugin-syntax-jsx": "^7.25.9",
|
|
39
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
40
|
+
"@babel/types": "^7.26.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/babel__core": "^7.20.5",
|
|
44
|
+
"@types/babel__helper-plugin-utils": "^7.10.3",
|
|
45
|
+
"typescript": "^5.6.3"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@babel/core": "^7.26.0"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=16.0.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsx ../../scripts/build-package.ts --pkg-name babel-preset --no-watch",
|
|
55
|
+
"dev": "tsx ../../scripts/build-package.ts --pkg-name babel-preset --watch",
|
|
56
|
+
"lint": "tsc --noEmit",
|
|
57
|
+
"test": "node --test test/**/*.test.js",
|
|
58
|
+
"typecheck": "tsc --noEmit"
|
|
59
|
+
}
|
|
60
|
+
}
|