@ktjs/transformer 0.2.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 +7 -0
- package/dist/if-else.d.ts +4 -0
- package/dist/if-else.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +421 -0
- package/dist/index.mjs.map +1 -0
- package/dist/k-for.d.ts +5 -0
- package/dist/k-for.d.ts.map +1 -0
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/svg-mathml-flag.d.ts +4 -0
- package/dist/svg-mathml-flag.d.ts.map +1 -0
- package/dist/transform.d.ts +8 -0
- package/dist/transform.d.ts.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 kasukabe tsumugi
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"if-else.d.ts","sourceRoot":"","sources":["../src/if-else.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAiFlC,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QA8DtE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as _babel_core from '@babel/core';
|
|
2
|
+
import { PluginObj, TransformOptions } from '@babel/core';
|
|
3
|
+
|
|
4
|
+
declare function transformerKTjsx(): PluginObj;
|
|
5
|
+
|
|
6
|
+
type ReservedTransformOptions = 'ast' | 'babelrc' | 'configFile' | 'parserOpts' | 'plugins' | 'sourceMaps';
|
|
7
|
+
type KTjsxTransformOptions = Omit<TransformOptions, ReservedTransformOptions> & {
|
|
8
|
+
parserPlugins?: NonNullable<TransformOptions['parserOpts']>['plugins'];
|
|
9
|
+
};
|
|
10
|
+
declare function transformWithKTjsx(code: string, options?: KTjsxTransformOptions): Promise<_babel_core.BabelFileResult>;
|
|
11
|
+
|
|
12
|
+
export { transformerKTjsx as default, transformWithKTjsx, transformerKTjsx };
|
|
13
|
+
export type { KTjsxTransformOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { parseSync, transformAsync } from '@babel/core';
|
|
3
|
+
|
|
4
|
+
function isSvgTag(tag) {
|
|
5
|
+
return tag === 'svg' || (typeof tag === 'string' && tag.startsWith('svg:'));
|
|
6
|
+
}
|
|
7
|
+
function isMathTag(tag) {
|
|
8
|
+
return tag === 'math' || (typeof tag === 'string' && tag.startsWith('math:'));
|
|
9
|
+
}
|
|
10
|
+
function addFlagToSvgMathMLElement(path) {
|
|
11
|
+
const opening = path.node.openingElement;
|
|
12
|
+
if (!opening) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const oname = opening.name;
|
|
16
|
+
if (t.isJSXNamespacedName(oname)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!t.isJSXIdentifier(oname)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const tag = oname.name;
|
|
23
|
+
const isSvgRoot = isSvgTag(tag);
|
|
24
|
+
const isMathRoot = isMathTag(tag);
|
|
25
|
+
let insideSvg = false;
|
|
26
|
+
if (!isSvgRoot) {
|
|
27
|
+
/**
|
|
28
|
+
* @type {import('@babel/core').NodePath | null}
|
|
29
|
+
*/
|
|
30
|
+
const parentSvg = path.findParent((p) => {
|
|
31
|
+
if (!p.isJSXElement()) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const popping = p.node.openingElement && p.node.openingElement.name;
|
|
35
|
+
if (!popping) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (t.isJSXIdentifier(popping)) {
|
|
39
|
+
return isSvgTag(popping.name);
|
|
40
|
+
}
|
|
41
|
+
if (t.isJSXNamespacedName(popping)) {
|
|
42
|
+
return t.isJSXIdentifier(popping.namespace) && popping.namespace.name === 'svg';
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
});
|
|
46
|
+
insideSvg = !!parentSvg;
|
|
47
|
+
}
|
|
48
|
+
let insideMath = false;
|
|
49
|
+
if (!isMathRoot) {
|
|
50
|
+
/**
|
|
51
|
+
* @type {import('@babel/core').NodePath | null}
|
|
52
|
+
*/
|
|
53
|
+
const parentMath = path.findParent((p) => {
|
|
54
|
+
if (!p.isJSXElement()) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const popping = p.node.openingElement && p.node.openingElement.name;
|
|
58
|
+
if (!popping) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (t.isJSXIdentifier(popping)) {
|
|
62
|
+
return isMathTag(popping.name);
|
|
63
|
+
}
|
|
64
|
+
if (t.isJSXNamespacedName(popping)) {
|
|
65
|
+
return t.isJSXIdentifier(popping.namespace) && popping.namespace.name === 'math';
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
});
|
|
69
|
+
insideMath = !!parentMath;
|
|
70
|
+
}
|
|
71
|
+
// If this element is neither an svg/math root nor inside one, skip.
|
|
72
|
+
const inSvgContext = isSvgRoot || insideSvg;
|
|
73
|
+
const inMathContext = isMathRoot || insideMath;
|
|
74
|
+
if (!inSvgContext && !inMathContext) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Add boolean attribute (SVG or MATHML) to opening element if not present
|
|
78
|
+
const attrs = opening.attributes || [];
|
|
79
|
+
const flag = inSvgContext ? "__svg" : "__mathml";
|
|
80
|
+
const hasFlag = attrs.some((a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name === flag);
|
|
81
|
+
if (!hasFlag) {
|
|
82
|
+
attrs.push(t.jsxAttribute(t.jsxIdentifier(flag)));
|
|
83
|
+
opening.attributes = attrs;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function hasConditionalDirective(element) {
|
|
88
|
+
const attributes = element.openingElement.attributes || [];
|
|
89
|
+
return attributes.some((attr) => {
|
|
90
|
+
if (!t.isJSXAttribute(attr)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (!t.isJSXIdentifier(attr.name)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return attr.name.name === 'k-if' || attr.name.name === 'k-else-if' || attr.name.name === 'k-else';
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function getConditionalDirective(element) {
|
|
100
|
+
const attributes = element.openingElement.attributes || [];
|
|
101
|
+
for (const attr of attributes) {
|
|
102
|
+
if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (attr.name.name === 'k-if' || attr.name.name === 'k-else-if') {
|
|
106
|
+
let condition = null;
|
|
107
|
+
if (attr.value) {
|
|
108
|
+
if (t.isJSXExpressionContainer(attr.value)) {
|
|
109
|
+
condition = attr.value.expression;
|
|
110
|
+
}
|
|
111
|
+
else if (t.isStringLiteral(attr.value)) {
|
|
112
|
+
condition = attr.value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { type: attr.name.name, condition };
|
|
116
|
+
}
|
|
117
|
+
if (attr.name.name === 'k-else') {
|
|
118
|
+
return { type: 'k-else', condition: null };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
function removeConditionalDirectives(attributes) {
|
|
124
|
+
return attributes.filter((attr) => {
|
|
125
|
+
if (!t.isJSXAttribute(attr)) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if (!t.isJSXIdentifier(attr.name)) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return attr.name.name !== 'k-if' && attr.name.name !== 'k-else-if' && attr.name.name !== 'k-else';
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function createCompoundCondition(prevConditions, currentCondition = null) {
|
|
135
|
+
if (prevConditions.length === 0) {
|
|
136
|
+
if (currentCondition && t.isExpression(currentCondition)) {
|
|
137
|
+
return currentCondition;
|
|
138
|
+
}
|
|
139
|
+
return t.booleanLiteral(true);
|
|
140
|
+
}
|
|
141
|
+
const first = prevConditions[0];
|
|
142
|
+
let compound = t.unaryExpression('!', t.isExpression(first) ? first : t.booleanLiteral(false));
|
|
143
|
+
for (let i = 1; i < prevConditions.length; i++) {
|
|
144
|
+
const condition = prevConditions[i];
|
|
145
|
+
const negated = t.unaryExpression('!', t.isExpression(condition) ? condition : t.booleanLiteral(false));
|
|
146
|
+
compound = t.logicalExpression('&&', compound, negated);
|
|
147
|
+
}
|
|
148
|
+
if (currentCondition && t.isExpression(currentCondition)) {
|
|
149
|
+
compound = t.logicalExpression('&&', compound, currentCondition);
|
|
150
|
+
}
|
|
151
|
+
return compound;
|
|
152
|
+
}
|
|
153
|
+
function transformConditionalChains(path) {
|
|
154
|
+
const { node } = path;
|
|
155
|
+
if (!hasConditionalDirective(node)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const prevSibling = path.getPrevSibling();
|
|
159
|
+
if (prevSibling && prevSibling.isJSXElement() && hasConditionalDirective(prevSibling.node)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const chain = [path];
|
|
163
|
+
let current = path;
|
|
164
|
+
while (true) {
|
|
165
|
+
const nextSibling = current.getNextSibling();
|
|
166
|
+
if (!nextSibling || !nextSibling.isJSXElement() || !hasConditionalDirective(nextSibling.node)) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
chain.push(nextSibling);
|
|
170
|
+
current = nextSibling;
|
|
171
|
+
}
|
|
172
|
+
if (chain.length === 1) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const prevConditions = [];
|
|
176
|
+
for (let i = 0; i < chain.length; i++) {
|
|
177
|
+
const elementPath = chain[i];
|
|
178
|
+
const element = elementPath.node;
|
|
179
|
+
const directive = getConditionalDirective(element);
|
|
180
|
+
if (!directive) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const openingElement = element.openingElement;
|
|
184
|
+
const newAttributes = removeConditionalDirectives(openingElement.attributes || []);
|
|
185
|
+
let newCondition;
|
|
186
|
+
if (directive.type === 'k-if') {
|
|
187
|
+
newCondition = t.isExpression(directive.condition) ? directive.condition : t.booleanLiteral(true);
|
|
188
|
+
prevConditions.push(directive.condition);
|
|
189
|
+
}
|
|
190
|
+
else if (directive.type === 'k-else-if') {
|
|
191
|
+
if (prevConditions.length === 0) {
|
|
192
|
+
newCondition = t.isExpression(directive.condition) ? directive.condition : t.booleanLiteral(true);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
newCondition = createCompoundCondition(prevConditions, directive.condition);
|
|
196
|
+
}
|
|
197
|
+
prevConditions.push(directive.condition);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
if (prevConditions.length === 0) {
|
|
201
|
+
newCondition = t.booleanLiteral(true);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
newCondition = createCompoundCondition(prevConditions);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
newAttributes.push(t.jsxAttribute(t.jsxIdentifier('k-if'), t.jsxExpressionContainer(newCondition)));
|
|
208
|
+
openingElement.attributes = newAttributes;
|
|
209
|
+
elementPath.skip();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const KFOR_SINGLE_PATTERN = /^([A-Za-z_$][A-Za-z0-9_$]*)\s+(in|of)\s+([\s\S]+)$/;
|
|
214
|
+
const KFOR_TUPLE_PATTERN = /^\(\s*([A-Za-z_$][A-Za-z0-9_$]*)(?:\s*,\s*([A-Za-z_$][A-Za-z0-9_$]*))?(?:\s*,\s*([A-Za-z_$][A-Za-z0-9_$]*))?\s*\)\s+(in|of)\s+([\s\S]+)$/;
|
|
215
|
+
function validateDirectiveCombinations(path) {
|
|
216
|
+
const opening = path.node.openingElement;
|
|
217
|
+
const hasFor = hasAttribute(opening, 'k-for');
|
|
218
|
+
const hasIf = hasAttribute(opening, 'k-if');
|
|
219
|
+
const hasElse = hasAttribute(opening, 'k-else');
|
|
220
|
+
const hasElseIf = hasAttribute(opening, 'k-else-if');
|
|
221
|
+
if (hasIf && hasElse) {
|
|
222
|
+
throw path.buildCodeFrameError('Invalid directive usage: `k-if` and `k-else` cannot be used on the same element.');
|
|
223
|
+
}
|
|
224
|
+
if (hasFor && (hasIf || hasElseIf || hasElse)) {
|
|
225
|
+
throw path.buildCodeFrameError('Invalid directive usage: `k-for` cannot be combined with `k-if` / `k-else-if` / `k-else` on the same element.');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function transformKFor(path) {
|
|
229
|
+
const opening = path.node.openingElement;
|
|
230
|
+
const forAttr = getAttribute(opening, 'k-for');
|
|
231
|
+
if (!forAttr) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
const parsedForText = readAttributeStringValue(forAttr, path, 'k-for');
|
|
235
|
+
const parsedFor = parseKForExpression(parsedForText);
|
|
236
|
+
if (!parsedFor) {
|
|
237
|
+
throw path.buildCodeFrameError('Invalid `k-for` expression. Expected `item in list` or `(item, index[, array]) in list`.');
|
|
238
|
+
}
|
|
239
|
+
const sourceExpression = parseTextAsExpression(path, parsedFor.source, 'k-for source');
|
|
240
|
+
const keyAttr = getAttribute(opening, 'k-key');
|
|
241
|
+
if (keyAttr && hasStringLikeValue(keyAttr)) {
|
|
242
|
+
const keyText = readAttributeStringValue(keyAttr, path, 'k-key');
|
|
243
|
+
parseTextAsExpression(path, keyText, 'k-key');
|
|
244
|
+
}
|
|
245
|
+
const renderNode = t.cloneNode(path.node, true);
|
|
246
|
+
const renderOpening = renderNode.openingElement;
|
|
247
|
+
renderOpening.attributes = removeAttributes(renderOpening.attributes, ['k-for', 'k-key']);
|
|
248
|
+
const callbackParams = parsedFor.aliases.map((alias) => t.identifier(alias));
|
|
249
|
+
const callback = t.arrowFunctionExpression(callbackParams, renderNode);
|
|
250
|
+
const mapCall = t.callExpression(t.memberExpression(sourceExpression, t.identifier('map')), [callback]);
|
|
251
|
+
if (isInsideJSXChildren(path)) {
|
|
252
|
+
path.replaceWith(t.jsxExpressionContainer(mapCall));
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
path.replaceWith(mapCall);
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
function parseKForExpression(raw) {
|
|
260
|
+
const value = raw.trim();
|
|
261
|
+
if (!value) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
const tupleMatch = KFOR_TUPLE_PATTERN.exec(value);
|
|
265
|
+
if (tupleMatch) {
|
|
266
|
+
const source = tupleMatch[5]?.trim();
|
|
267
|
+
if (!source) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
const aliases = [tupleMatch[1], tupleMatch[2], tupleMatch[3]].filter((item) => typeof item === 'string' && item.length > 0);
|
|
271
|
+
return {
|
|
272
|
+
aliases,
|
|
273
|
+
source,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const singleMatch = KFOR_SINGLE_PATTERN.exec(value);
|
|
277
|
+
if (singleMatch) {
|
|
278
|
+
const source = singleMatch[3]?.trim();
|
|
279
|
+
if (!source) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
aliases: [singleMatch[1]],
|
|
284
|
+
source,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
function parseTextAsExpression(path, text, label) {
|
|
290
|
+
try {
|
|
291
|
+
const ast = parseSync(`(${text});`, {
|
|
292
|
+
configFile: false,
|
|
293
|
+
babelrc: false,
|
|
294
|
+
sourceType: 'module',
|
|
295
|
+
parserOpts: {
|
|
296
|
+
plugins: ['typescript', 'jsx'],
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
if (!ast) {
|
|
300
|
+
throw new Error('Babel returned an empty AST.');
|
|
301
|
+
}
|
|
302
|
+
const statement = ast.program.body[0];
|
|
303
|
+
if (!statement || !t.isExpressionStatement(statement)) {
|
|
304
|
+
throw new Error('Expected an expression statement.');
|
|
305
|
+
}
|
|
306
|
+
return statement.expression;
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
310
|
+
throw path.buildCodeFrameError(`Failed to parse ${label}: ${message}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function getAttribute(opening, name) {
|
|
314
|
+
const attributes = opening.attributes || [];
|
|
315
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
316
|
+
const attr = attributes[i];
|
|
317
|
+
if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (attr.name.name === name) {
|
|
321
|
+
return attr;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
326
|
+
function hasAttribute(opening, name) {
|
|
327
|
+
return !!getAttribute(opening, name);
|
|
328
|
+
}
|
|
329
|
+
function readAttributeStringValue(attr, path, attrName) {
|
|
330
|
+
if (!attr.value) {
|
|
331
|
+
throw path.buildCodeFrameError(`Directive \`${attrName}\` requires a string value.`);
|
|
332
|
+
}
|
|
333
|
+
if (t.isStringLiteral(attr.value)) {
|
|
334
|
+
return attr.value.value;
|
|
335
|
+
}
|
|
336
|
+
if (!t.isJSXExpressionContainer(attr.value)) {
|
|
337
|
+
throw path.buildCodeFrameError(`Directive \`${attrName}\` must be a string literal.`);
|
|
338
|
+
}
|
|
339
|
+
if (t.isJSXEmptyExpression(attr.value.expression)) {
|
|
340
|
+
throw path.buildCodeFrameError(`Directive \`${attrName}\` cannot be empty.`);
|
|
341
|
+
}
|
|
342
|
+
if (t.isStringLiteral(attr.value.expression)) {
|
|
343
|
+
return attr.value.expression.value;
|
|
344
|
+
}
|
|
345
|
+
if (t.isTemplateLiteral(attr.value.expression) && attr.value.expression.expressions.length === 0) {
|
|
346
|
+
return attr.value.expression.quasis[0]?.value.cooked ?? '';
|
|
347
|
+
}
|
|
348
|
+
throw path.buildCodeFrameError(`Directive \`${attrName}\` must be a string literal.`);
|
|
349
|
+
}
|
|
350
|
+
function hasStringLikeValue(attr) {
|
|
351
|
+
if (!attr.value) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
if (t.isStringLiteral(attr.value)) {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
if (!t.isJSXExpressionContainer(attr.value)) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
if (t.isStringLiteral(attr.value.expression)) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
return t.isTemplateLiteral(attr.value.expression) && attr.value.expression.expressions.length === 0;
|
|
364
|
+
}
|
|
365
|
+
function removeAttributes(attributes, names) {
|
|
366
|
+
const set = new Set(names);
|
|
367
|
+
if (!attributes || attributes.length === 0) {
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
return attributes.filter((attr) => {
|
|
371
|
+
if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
return !set.has(attr.name.name);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
function isInsideJSXChildren(path) {
|
|
378
|
+
if (!path.inList || path.listKey !== 'children') {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
const parent = path.parentPath;
|
|
382
|
+
return !!parent && (parent.isJSXElement() || parent.isJSXFragment());
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function transformerKTjsx() {
|
|
386
|
+
return {
|
|
387
|
+
name: 'ktjs-transformer',
|
|
388
|
+
visitor: {
|
|
389
|
+
JSXElement: {
|
|
390
|
+
enter(path) {
|
|
391
|
+
validateDirectiveCombinations(path);
|
|
392
|
+
transformConditionalChains(path);
|
|
393
|
+
addFlagToSvgMathMLElement(path);
|
|
394
|
+
},
|
|
395
|
+
exit(path) {
|
|
396
|
+
transformKFor(path);
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const DEFAULT_PARSER_PLUGINS = ['jsx', 'typescript'];
|
|
404
|
+
async function transformWithKTjsx(code, options = {}) {
|
|
405
|
+
const { parserPlugins = DEFAULT_PARSER_PLUGINS, ...babelConfig } = options;
|
|
406
|
+
return transformAsync(code, {
|
|
407
|
+
ast: false,
|
|
408
|
+
babelrc: false,
|
|
409
|
+
configFile: false,
|
|
410
|
+
sourceMaps: true,
|
|
411
|
+
parserOpts: {
|
|
412
|
+
sourceType: 'module',
|
|
413
|
+
plugins: parserPlugins,
|
|
414
|
+
},
|
|
415
|
+
plugins: [transformerKTjsx()],
|
|
416
|
+
...babelConfig,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export { transformerKTjsx as default, transformWithKTjsx, transformerKTjsx };
|
|
421
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/svg-mathml-flag.ts","../src/if-else.ts","../src/k-for.ts","../src/plugin.ts","../src/transform.ts"],"sourcesContent":["import type { NodePath } from '@babel/core';\nimport * as t from '@babel/types';\n\nfunction isSvgTag(tag: string) {\n return tag === 'svg' || (typeof tag === 'string' && tag.startsWith('svg:'));\n}\n\nfunction isMathTag(tag: string) {\n return tag === 'math' || (typeof tag === 'string' && tag.startsWith('math:'));\n}\n\nexport function addFlagToSvgMathMLElement(path: NodePath<t.JSXElement>) {\n const opening = path.node.openingElement;\n if (!opening) {\n return;\n }\n\n const oname = opening.name;\n if (t.isJSXNamespacedName(oname)) {\n return;\n }\n if (!t.isJSXIdentifier(oname)) {\n return;\n }\n\n const tag = oname.name;\n const isSvgRoot = isSvgTag(tag);\n const isMathRoot = isMathTag(tag);\n\n let insideSvg = false;\n if (!isSvgRoot) {\n /**\n * @type {import('@babel/core').NodePath | null}\n */\n const parentSvg = path.findParent((p) => {\n if (!p.isJSXElement()) {\n return false;\n }\n const popping = p.node.openingElement && p.node.openingElement.name;\n if (!popping) {\n return false;\n }\n if (t.isJSXIdentifier(popping)) {\n return isSvgTag(popping.name);\n }\n if (t.isJSXNamespacedName(popping)) {\n return t.isJSXIdentifier(popping.namespace) && popping.namespace.name === 'svg';\n }\n return false;\n });\n insideSvg = !!parentSvg;\n }\n\n let insideMath = false;\n if (!isMathRoot) {\n /**\n * @type {import('@babel/core').NodePath | null}\n */\n const parentMath = path.findParent((p) => {\n if (!p.isJSXElement()) {\n return false;\n }\n const popping = p.node.openingElement && p.node.openingElement.name;\n if (!popping) {\n return false;\n }\n if (t.isJSXIdentifier(popping)) {\n return isMathTag(popping.name);\n }\n if (t.isJSXNamespacedName(popping)) {\n return t.isJSXIdentifier(popping.namespace) && popping.namespace.name === 'math';\n }\n return false;\n });\n insideMath = !!parentMath;\n }\n\n // If this element is neither an svg/math root nor inside one, skip.\n const inSvgContext = isSvgRoot || insideSvg;\n const inMathContext = isMathRoot || insideMath;\n if (!inSvgContext && !inMathContext) {\n return;\n }\n\n // Add boolean attribute (SVG or MATHML) to opening element if not present\n const attrs = opening.attributes || [];\n const flag = inSvgContext ? flags.svg : flags.mathml;\n const hasFlag = attrs.some((a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name === flag);\n if (!hasFlag) {\n attrs.push(t.jsxAttribute(t.jsxIdentifier(flag)));\n opening.attributes = attrs;\n }\n}\n","import type { NodePath } from '@babel/core';\nimport * as t from '@babel/types';\n\nfunction hasConditionalDirective(element: t.JSXElement): boolean {\n const attributes = element.openingElement.attributes || [];\n return attributes.some((attr) => {\n if (!t.isJSXAttribute(attr)) {\n return false;\n }\n if (!t.isJSXIdentifier(attr.name)) {\n return false;\n }\n return attr.name.name === 'k-if' || attr.name.name === 'k-else-if' || attr.name.name === 'k-else';\n });\n}\n\nfunction getConditionalDirective(\n element: t.JSXElement,\n): { type: 'k-if' | 'k-else-if' | 'k-else'; condition: t.Expression | t.StringLiteral | null } | null {\n const attributes = element.openingElement.attributes || [];\n for (const attr of attributes) {\n if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) {\n continue;\n }\n\n if (attr.name.name === 'k-if' || attr.name.name === 'k-else-if') {\n let condition: t.Expression | t.StringLiteral | null = null;\n if (attr.value) {\n if (t.isJSXExpressionContainer(attr.value)) {\n condition = attr.value.expression as t.Expression;\n } else if (t.isStringLiteral(attr.value)) {\n condition = attr.value;\n }\n }\n return { type: attr.name.name, condition };\n }\n\n if (attr.name.name === 'k-else') {\n return { type: 'k-else', condition: null };\n }\n }\n return null;\n}\n\nfunction removeConditionalDirectives(attributes: (t.JSXAttribute | t.JSXSpreadAttribute)[]) {\n return attributes.filter((attr) => {\n if (!t.isJSXAttribute(attr)) {\n return true;\n }\n if (!t.isJSXIdentifier(attr.name)) {\n return true;\n }\n return attr.name.name !== 'k-if' && attr.name.name !== 'k-else-if' && attr.name.name !== 'k-else';\n });\n}\n\nfunction createCompoundCondition(\n prevConditions: Array<t.Expression | t.StringLiteral | null>,\n currentCondition: t.Expression | t.StringLiteral | null = null,\n): t.Expression {\n if (prevConditions.length === 0) {\n if (currentCondition && t.isExpression(currentCondition)) {\n return currentCondition;\n }\n return t.booleanLiteral(true);\n }\n\n const first = prevConditions[0];\n let compound: t.Expression = t.unaryExpression('!', t.isExpression(first) ? first : t.booleanLiteral(false));\n for (let i = 1; i < prevConditions.length; i++) {\n const condition = prevConditions[i];\n const negated = t.unaryExpression('!', t.isExpression(condition) ? condition : t.booleanLiteral(false));\n compound = t.logicalExpression('&&', compound, negated);\n }\n\n if (currentCondition && t.isExpression(currentCondition)) {\n compound = t.logicalExpression('&&', compound, currentCondition);\n }\n\n return compound;\n}\n\nexport function transformConditionalChains(path: NodePath<t.JSXElement>) {\n const { node } = path;\n if (!hasConditionalDirective(node)) {\n return;\n }\n\n const prevSibling = path.getPrevSibling();\n if (prevSibling && prevSibling.isJSXElement() && hasConditionalDirective(prevSibling.node)) {\n return;\n }\n\n const chain: Array<NodePath<t.JSXElement>> = [path];\n let current: NodePath<t.JSXElement> = path;\n\n while (true) {\n const nextSibling = current.getNextSibling();\n if (!nextSibling || !nextSibling.isJSXElement() || !hasConditionalDirective(nextSibling.node)) {\n break;\n }\n chain.push(nextSibling);\n current = nextSibling;\n }\n\n if (chain.length === 1) {\n return;\n }\n\n const prevConditions: Array<t.Expression | t.StringLiteral | null> = [];\n for (let i = 0; i < chain.length; i++) {\n const elementPath = chain[i];\n const element = elementPath.node;\n const directive = getConditionalDirective(element);\n if (!directive) {\n continue;\n }\n\n const openingElement = element.openingElement;\n const newAttributes = removeConditionalDirectives(openingElement.attributes || []);\n\n let newCondition: t.Expression;\n if (directive.type === 'k-if') {\n newCondition = t.isExpression(directive.condition) ? directive.condition : t.booleanLiteral(true);\n prevConditions.push(directive.condition);\n } else if (directive.type === 'k-else-if') {\n if (prevConditions.length === 0) {\n newCondition = t.isExpression(directive.condition) ? directive.condition : t.booleanLiteral(true);\n } else {\n newCondition = createCompoundCondition(prevConditions, directive.condition);\n }\n prevConditions.push(directive.condition);\n } else {\n if (prevConditions.length === 0) {\n newCondition = t.booleanLiteral(true);\n } else {\n newCondition = createCompoundCondition(prevConditions);\n }\n }\n\n newAttributes.push(t.jsxAttribute(t.jsxIdentifier('k-if'), t.jsxExpressionContainer(newCondition)));\n openingElement.attributes = newAttributes;\n elementPath.skip();\n }\n}\n","import { parseSync, type NodePath } from '@babel/core';\nimport * as t from '@babel/types';\n\nconst KFOR_SINGLE_PATTERN = /^([A-Za-z_$][A-Za-z0-9_$]*)\\s+(in|of)\\s+([\\s\\S]+)$/;\nconst KFOR_TUPLE_PATTERN =\n /^\\(\\s*([A-Za-z_$][A-Za-z0-9_$]*)(?:\\s*,\\s*([A-Za-z_$][A-Za-z0-9_$]*))?(?:\\s*,\\s*([A-Za-z_$][A-Za-z0-9_$]*))?\\s*\\)\\s+(in|of)\\s+([\\s\\S]+)$/;\n\ninterface ParsedKForExpression {\n aliases: string[];\n source: string;\n}\n\nexport function validateDirectiveCombinations(path: NodePath<t.JSXElement>) {\n const opening = path.node.openingElement;\n const hasFor = hasAttribute(opening, 'k-for');\n const hasIf = hasAttribute(opening, 'k-if');\n const hasElse = hasAttribute(opening, 'k-else');\n const hasElseIf = hasAttribute(opening, 'k-else-if');\n\n if (hasIf && hasElse) {\n throw path.buildCodeFrameError(\n 'Invalid directive usage: `k-if` and `k-else` cannot be used on the same element.',\n );\n }\n\n if (hasFor && (hasIf || hasElseIf || hasElse)) {\n throw path.buildCodeFrameError(\n 'Invalid directive usage: `k-for` cannot be combined with `k-if` / `k-else-if` / `k-else` on the same element.',\n );\n }\n}\n\nexport function transformKFor(path: NodePath<t.JSXElement>): boolean {\n const opening = path.node.openingElement;\n const forAttr = getAttribute(opening, 'k-for');\n if (!forAttr) {\n return false;\n }\n\n const parsedForText = readAttributeStringValue(forAttr, path, 'k-for');\n const parsedFor = parseKForExpression(parsedForText);\n if (!parsedFor) {\n throw path.buildCodeFrameError(\n 'Invalid `k-for` expression. Expected `item in list` or `(item, index[, array]) in list`.',\n );\n }\n\n const sourceExpression = parseTextAsExpression(path, parsedFor.source, 'k-for source');\n const keyAttr = getAttribute(opening, 'k-key');\n if (keyAttr && hasStringLikeValue(keyAttr)) {\n const keyText = readAttributeStringValue(keyAttr, path, 'k-key');\n parseTextAsExpression(path, keyText, 'k-key');\n }\n\n const renderNode = t.cloneNode(path.node, true) as t.JSXElement;\n const renderOpening = renderNode.openingElement;\n renderOpening.attributes = removeAttributes(renderOpening.attributes, ['k-for', 'k-key']);\n\n const callbackParams = parsedFor.aliases.map((alias) => t.identifier(alias));\n const callback = t.arrowFunctionExpression(callbackParams, renderNode);\n const mapCall = t.callExpression(t.memberExpression(sourceExpression, t.identifier('map')), [callback]);\n\n if (isInsideJSXChildren(path)) {\n path.replaceWith(t.jsxExpressionContainer(mapCall));\n } else {\n path.replaceWith(mapCall);\n }\n\n return true;\n}\n\nfunction parseKForExpression(raw: string): ParsedKForExpression | null {\n const value = raw.trim();\n if (!value) {\n return null;\n }\n\n const tupleMatch = KFOR_TUPLE_PATTERN.exec(value);\n if (tupleMatch) {\n const source = tupleMatch[5]?.trim();\n if (!source) {\n return null;\n }\n const aliases = [tupleMatch[1], tupleMatch[2], tupleMatch[3]].filter(\n (item): item is string => typeof item === 'string' && item.length > 0,\n );\n return {\n aliases,\n source,\n };\n }\n\n const singleMatch = KFOR_SINGLE_PATTERN.exec(value);\n if (singleMatch) {\n const source = singleMatch[3]?.trim();\n if (!source) {\n return null;\n }\n return {\n aliases: [singleMatch[1]],\n source,\n };\n }\n\n return null;\n}\n\nfunction parseTextAsExpression(path: NodePath<t.JSXElement>, text: string, label: string): t.Expression {\n try {\n const ast = parseSync(`(${text});`, {\n configFile: false,\n babelrc: false,\n sourceType: 'module',\n parserOpts: {\n plugins: ['typescript', 'jsx'],\n },\n });\n\n if (!ast) {\n throw new Error('Babel returned an empty AST.');\n }\n const statement = ast.program.body[0];\n if (!statement || !t.isExpressionStatement(statement)) {\n throw new Error('Expected an expression statement.');\n }\n return statement.expression;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw path.buildCodeFrameError(`Failed to parse ${label}: ${message}`);\n }\n}\n\nfunction getAttribute(\n opening: t.JSXOpeningElement,\n name: string,\n): t.JSXAttribute | undefined {\n const attributes = opening.attributes || [];\n for (let i = 0; i < attributes.length; i++) {\n const attr = attributes[i];\n if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) {\n continue;\n }\n if (attr.name.name === name) {\n return attr;\n }\n }\n return undefined;\n}\n\nfunction hasAttribute(opening: t.JSXOpeningElement, name: string): boolean {\n return !!getAttribute(opening, name);\n}\n\nfunction readAttributeStringValue(\n attr: t.JSXAttribute,\n path: NodePath<t.JSXElement>,\n attrName: string,\n): string {\n if (!attr.value) {\n throw path.buildCodeFrameError(`Directive \\`${attrName}\\` requires a string value.`);\n }\n\n if (t.isStringLiteral(attr.value)) {\n return attr.value.value;\n }\n\n if (!t.isJSXExpressionContainer(attr.value)) {\n throw path.buildCodeFrameError(`Directive \\`${attrName}\\` must be a string literal.`);\n }\n if (t.isJSXEmptyExpression(attr.value.expression)) {\n throw path.buildCodeFrameError(`Directive \\`${attrName}\\` cannot be empty.`);\n }\n if (t.isStringLiteral(attr.value.expression)) {\n return attr.value.expression.value;\n }\n if (t.isTemplateLiteral(attr.value.expression) && attr.value.expression.expressions.length === 0) {\n return attr.value.expression.quasis[0]?.value.cooked ?? '';\n }\n\n throw path.buildCodeFrameError(`Directive \\`${attrName}\\` must be a string literal.`);\n}\n\nfunction hasStringLikeValue(attr: t.JSXAttribute): boolean {\n if (!attr.value) {\n return false;\n }\n if (t.isStringLiteral(attr.value)) {\n return true;\n }\n if (!t.isJSXExpressionContainer(attr.value)) {\n return false;\n }\n if (t.isStringLiteral(attr.value.expression)) {\n return true;\n }\n return t.isTemplateLiteral(attr.value.expression) && attr.value.expression.expressions.length === 0;\n}\n\nfunction removeAttributes(\n attributes: (t.JSXAttribute | t.JSXSpreadAttribute)[] | undefined,\n names: string[],\n): (t.JSXAttribute | t.JSXSpreadAttribute)[] {\n const set = new Set(names);\n if (!attributes || attributes.length === 0) {\n return [];\n }\n return attributes.filter((attr) => {\n if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name)) {\n return true;\n }\n return !set.has(attr.name.name);\n });\n}\n\nfunction isInsideJSXChildren(path: NodePath<t.JSXElement>): boolean {\n if (!path.inList || path.listKey !== 'children') {\n return false;\n }\n const parent = path.parentPath;\n return !!parent && (parent.isJSXElement() || parent.isJSXFragment());\n}\n","import type { PluginObj } from '@babel/core';\nimport { addFlagToSvgMathMLElement } from './svg-mathml-flag.js';\nimport { transformConditionalChains } from './if-else.js';\nimport { transformKFor, validateDirectiveCombinations } from './k-for.js';\n\nexport function transformerKTjsx(): PluginObj {\n return {\n name: 'ktjs-transformer',\n visitor: {\n JSXElement: {\n enter(path) {\n validateDirectiveCombinations(path);\n transformConditionalChains(path);\n addFlagToSvgMathMLElement(path);\n },\n exit(path) {\n transformKFor(path);\n },\n },\n },\n };\n}\n\nexport default transformerKTjsx;\n","import { transformAsync, type TransformOptions } from '@babel/core';\nimport transformerKTjsx from './plugin.js';\n\nconst DEFAULT_PARSER_PLUGINS: NonNullable<TransformOptions['parserOpts']>['plugins'] = ['jsx', 'typescript'];\n\ntype ReservedTransformOptions =\n | 'ast'\n | 'babelrc'\n | 'configFile'\n | 'parserOpts'\n | 'plugins'\n | 'sourceMaps';\n\nexport type KTjsxTransformOptions = Omit<TransformOptions, ReservedTransformOptions> & {\n parserPlugins?: NonNullable<TransformOptions['parserOpts']>['plugins'];\n};\n\nexport async function transformWithKTjsx(code: string, options: KTjsxTransformOptions = {}) {\n const { parserPlugins = DEFAULT_PARSER_PLUGINS, ...babelConfig } = options;\n\n return transformAsync(code, {\n ast: false,\n babelrc: false,\n configFile: false,\n sourceMaps: true,\n parserOpts: {\n sourceType: 'module',\n plugins: parserPlugins,\n },\n plugins: [transformerKTjsx()],\n ...babelConfig,\n });\n}\n"],"names":[],"mappings":";;;AAGA,SAAS,QAAQ,CAAC,GAAW,EAAA;AAC3B,IAAA,OAAO,GAAG,KAAK,KAAK,KAAK,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC7E;AAEA,SAAS,SAAS,CAAC,GAAW,EAAA;AAC5B,IAAA,OAAO,GAAG,KAAK,MAAM,KAAK,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC/E;AAEM,SAAU,yBAAyB,CAAC,IAA4B,EAAA;AACpE,IAAA,MAAM,OAAO,GAA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AE,UAAiC,EAAE,EAAA;IACxF,MAAM,EAAE,aAAa,GAAG,sBAAsB,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO;IAE1E,OAAO,cAAc,CAAC,IAAI,EAAE;AAC1B,QAAA,GAAG,EAAE,KAAK;AACV,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,UAAU,EAAE,KAAK;AACjB,QAAA,UAAU,EAAE,IAAI;AAChB,QAAA,UAAU,EAAE;AACV,YAAA,UAAU,EAAE,QAAQ;AACpB,YAAA,OAAO,EAAE,aAAa;AACvB,SAAA;AACD,QAAA,OAAO,EAAE,CAAC,gBAAgB,EAAE,CAAC;AAC7B,QAAA,GAAG,WAAW;AACf,KAAA,CAAC;AACJ;;;;"}
|
package/dist/k-for.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type NodePath } from '@babel/core';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
export declare function validateDirectiveCombinations(path: NodePath<t.JSXElement>): void;
|
|
4
|
+
export declare function transformKFor(path: NodePath<t.JSXElement>): boolean;
|
|
5
|
+
//# sourceMappingURL=k-for.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"k-for.d.ts","sourceRoot":"","sources":["../src/k-for.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAWlC,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAkBzE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,OAAO,CAqCnE"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK7C,wBAAgB,gBAAgB,IAAI,SAAS,CAgB5C;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svg-mathml-flag.d.ts","sourceRoot":"","sources":["../src/svg-mathml-flag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAUlC,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAiFrE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type TransformOptions } from '@babel/core';
|
|
2
|
+
type ReservedTransformOptions = 'ast' | 'babelrc' | 'configFile' | 'parserOpts' | 'plugins' | 'sourceMaps';
|
|
3
|
+
export type KTjsxTransformOptions = Omit<TransformOptions, ReservedTransformOptions> & {
|
|
4
|
+
parserPlugins?: NonNullable<TransformOptions['parserOpts']>['plugins'];
|
|
5
|
+
};
|
|
6
|
+
export declare function transformWithKTjsx(code: string, options?: KTjsxTransformOptions): Promise<import("@babel/core").BabelFileResult>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKpE,KAAK,wBAAwB,GACzB,KAAK,GACL,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,YAAY,CAAC;AAEjB,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,GAAG;IACrF,aAAa,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;CACxE,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,kDAezF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ktjs/transformer",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Kasukabe Tsumugi",
|
|
19
|
+
"email": "futami16237@gmail.com"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/ktjs/kt.js",
|
|
24
|
+
"directory": "packages/transformer"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"description": "Shared JSX transform core used by KT.js Babel and Vite plugins.",
|
|
28
|
+
"description_zh": "KT.js Babel 与 Vite 插件共用的 JSX 转换核心。",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@babel/core": "^7.0.0",
|
|
31
|
+
"@babel/types": "^7.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/babel__core": "^7.20.5",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
}
|
|
37
|
+
}
|