babel-plugin-essor 0.0.5-beta.4 → 0.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
3
+ Copyright (c) 2021-Present jiangxd <jiangxd2016@gmail.com>
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
6
6
  in the Software without restriction, including without limitation the rights
package/dist/index.cjs CHANGED
@@ -20,504 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- default: () => src_default
23
+ one: () => one,
24
+ two: () => two
24
25
  });
25
26
  module.exports = __toCommonJS(src_exports);
26
-
27
- // src/transform.ts
28
- var import_core = require("@babel/core");
29
-
30
- // src/constants.ts
31
- var selfClosingTags = [
32
- "area",
33
- "base",
34
- "br",
35
- "col",
36
- "embed",
37
- "hr",
38
- "img",
39
- "input",
40
- "link",
41
- "meta",
42
- "param",
43
- "source",
44
- "track",
45
- "wbr"
46
- ];
47
- var svgTags = [
48
- "circle",
49
- "clipPath",
50
- "defs",
51
- "ellipse",
52
- "filter",
53
- "g",
54
- "line",
55
- "linearGradient",
56
- "mask",
57
- "path",
58
- "pattern",
59
- "polygon",
60
- "polyline",
61
- "radialGradient",
62
- "rect",
63
- "stop",
64
- "symbol",
65
- "text",
66
- "use"
67
- ];
68
- var imports = /* @__PURE__ */ new Set();
69
-
70
- // src/transform.ts
71
- var transformProgram = {
72
- enter(path) {
73
- path.state = {
74
- h: path.scope.generateUidIdentifier("h$"),
75
- signal: path.scope.generateUidIdentifier("signal$"),
76
- computed: path.scope.generateUidIdentifier("computed$"),
77
- template: path.scope.generateUidIdentifier("template$"),
78
- signalObject: path.scope.generateUidIdentifier("signalObject&"),
79
- tmplDeclaration: import_core.types.variableDeclaration("const", [])
80
- };
81
- imports.clear();
82
- },
83
- exit(path) {
84
- const state = path.state;
85
- if (state.tmplDeclaration.declarations.length > 0) {
86
- const index = path.node.body.findIndex(
87
- (node) => !import_core.types.isImportDeclaration(node) && !import_core.types.isExportDeclaration(node)
88
- );
89
- path.node.body.splice(index, 0, state.tmplDeclaration);
90
- }
91
- if (imports.size > 0) {
92
- path.node.body.unshift(createImport(state, "essor"));
93
- }
94
- }
95
- };
96
- function createImport(state, from) {
97
- const ImportSpecifier = [];
98
- imports.forEach((name) => {
99
- const local = import_core.types.identifier(state[name].name);
100
- const imported = import_core.types.identifier(name);
101
- ImportSpecifier.push(import_core.types.importSpecifier(local, imported));
102
- });
103
- const importSource = import_core.types.stringLiteral(from);
104
- return import_core.types.importDeclaration(ImportSpecifier, importSource);
105
- }
106
-
107
- // src/jsx-transform.ts
108
- var import_core2 = require("@babel/core");
109
- function transformJSX(path) {
110
- const result = {
111
- index: 1,
112
- isLastChild: false,
113
- parentIndex: 0,
114
- props: {},
115
- template: ""
116
- };
117
- transformElement(path, result, true);
118
- path.replaceWith(createEssorNode(path, result));
119
- }
120
- function createEssorNode(path, result) {
121
- var _a, _b;
122
- const state = path.state;
123
- let tmpl;
124
- if (path.isJSXElement() && isComponent(getTagName(path.node))) {
125
- tmpl = import_core2.types.identifier(getTagName(path.node));
126
- } else {
127
- tmpl = path.scope.generateUidIdentifier("_tmpl$");
128
- const template = import_core2.types.callExpression(state.template, [import_core2.types.stringLiteral(result.template)]);
129
- const declarator = import_core2.types.variableDeclarator(tmpl, template);
130
- state.tmplDeclaration.declarations.push(declarator);
131
- imports.add("template");
132
- }
133
- const args = [tmpl, createProps(result.props)];
134
- const key = (_b = result.props.key) != null ? _b : (_a = result.props[0]) == null ? void 0 : _a.key;
135
- if (key) {
136
- args.push(key);
137
- }
138
- imports.add("h");
139
- return import_core2.types.callExpression(state.h, args);
140
- }
141
- function createProps(props) {
142
- const result = [];
143
- for (const prop in props) {
144
- let value = props[prop];
145
- if (prop === "key") {
146
- continue;
147
- }
148
- if (Array.isArray(value)) {
149
- value = import_core2.types.arrayExpression(value);
150
- }
151
- if (typeof value === "object" && value !== null && !import_core2.types.isNode(value)) {
152
- value = createProps(value);
153
- }
154
- if (typeof value === "string") {
155
- value = import_core2.types.stringLiteral(value);
156
- }
157
- if (typeof value === "number") {
158
- value = import_core2.types.numericLiteral(value);
159
- }
160
- if (typeof value === "boolean") {
161
- value = import_core2.types.booleanLiteral(value);
162
- }
163
- if (value === void 0) {
164
- value = import_core2.types.tsUndefinedKeyword();
165
- }
166
- if (value === null) {
167
- value = import_core2.types.nullLiteral();
168
- }
169
- if (prop === "_$spread$") {
170
- result.push(import_core2.types.spreadElement(value));
171
- } else {
172
- result.push(import_core2.types.objectProperty(import_core2.types.stringLiteral(prop), value));
173
- }
174
- }
175
- return import_core2.types.objectExpression(result);
176
- }
177
- function getAttrProps(path) {
178
- const props = {};
179
- path.get("openingElement").get("attributes").forEach((attribute) => {
180
- if (attribute.isJSXAttribute()) {
181
- const name = getAttrName(attribute.node);
182
- const value = attribute.get("value");
183
- if (!value.node) {
184
- props[name] = true;
185
- } else if (value.isStringLiteral()) {
186
- props[name] = value.node.value;
187
- } else {
188
- if (value.isJSXExpressionContainer()) {
189
- const expression = value.get("expression");
190
- if (expression.isStringLiteral()) {
191
- props[name] = expression.node.value;
192
- } else if (expression.isNumericLiteral()) {
193
- props[name] = expression.node.value;
194
- } else if (expression.isJSXElement() || expression.isJSXFragment()) {
195
- transformJSX(expression);
196
- props[name] = expression.node;
197
- } else if (expression.isExpression()) {
198
- if (/^key|ref|on.+$/.test(name)) {
199
- props[name] = expression.node;
200
- } else if (/^bind:.+/.test(name)) {
201
- props[name] = import_core2.types.arrowFunctionExpression([], expression.node);
202
- const value2 = path.scope.generateUidIdentifier("value");
203
- props[`update:${name.slice(5).toLocaleLowerCase()}`] = import_core2.types.arrowFunctionExpression(
204
- [value2],
205
- import_core2.types.assignmentExpression("=", expression.node, value2)
206
- );
207
- } else {
208
- if (expression.isConditionalExpression()) {
209
- props[name] = import_core2.types.arrowFunctionExpression([], expression.node);
210
- } else {
211
- props[name] = expression.node;
212
- }
213
- }
214
- }
215
- } else if (value.isJSXElement() || value.isJSXFragment()) {
216
- transformJSX(value);
217
- props[name] = value.node;
218
- }
219
- }
220
- } else if (attribute.isJSXSpreadAttribute()) {
221
- props._$spread$ = attribute.get("argument").node;
222
- } else {
223
- throw new Error("Unsupported attribute type");
224
- }
225
- });
226
- return props;
227
- }
228
- function transformElement(path, result, isRoot) {
229
- if (path.isJSXElement()) {
230
- const tagName = getTagName(path.node);
231
- const tagIsComponent = isComponent(tagName);
232
- const isSelfClosing = !tagIsComponent && selfClosingTags.includes(tagName);
233
- const isSvgTemplate = svgTags.includes(tagName) && result.index === 1;
234
- const props = getAttrProps(path);
235
- if (tagIsComponent) {
236
- if (isRoot) {
237
- result.props = props;
238
- const children = getChildren(path);
239
- if (children.length > 0) {
240
- const childrenGetter = children.length === 1 ? children[0] : import_core2.types.arrayExpression(children);
241
- result.props.children = childrenGetter;
242
- }
243
- } else {
244
- transformJSX(path);
245
- replaceChild(path.node, result);
246
- }
247
- } else {
248
- if (isSvgTemplate) {
249
- result.template += `<svg _svg_>`;
250
- }
251
- result.template += `<${tagName}`;
252
- handleAttributes(props, result);
253
- result.template += isSelfClosing ? "/>" : ">";
254
- if (!isSelfClosing) {
255
- transformChildren(path, result);
256
- result.template += `</${tagName}>`;
257
- }
258
- }
259
- } else {
260
- result.index--;
261
- transformChildren(path, result);
262
- }
263
- }
264
- function getChildren(path) {
265
- return path.get("children").filter(isValidChild).map((child) => {
266
- if (child.isJSXElement() || child.isJSXFragment()) {
267
- transformJSX(child);
268
- } else if (child.isJSXExpressionContainer()) {
269
- child.replaceWith(child.get("expression"));
270
- } else if (child.isJSXText()) {
271
- child.replaceWith(import_core2.types.stringLiteral(child.node.value));
272
- } else {
273
- throw new Error("Unsupported JSX child");
274
- }
275
- return child.node;
276
- });
277
- }
278
- function handleAttributes(props, result) {
279
- let klass = "";
280
- let style = "";
281
- for (const prop in props) {
282
- const value = props[prop];
283
- if (prop === "class" && typeof value === "string") {
284
- klass += ` ${value}`;
285
- delete props[prop];
286
- continue;
287
- }
288
- if (prop.indexOf("class:") === 0) {
289
- if (value === true) {
290
- const name = prop.replace(/^class:/, "");
291
- klass += ` ${name}`;
292
- delete props[prop];
293
- continue;
294
- }
295
- if (value === false) {
296
- delete props[prop];
297
- continue;
298
- }
299
- }
300
- if (prop === "style" && typeof value === "string") {
301
- style += `${value}${value.at(-1) === ";" ? "" : ";"}`;
302
- delete props[prop];
303
- continue;
304
- }
305
- if (prop.indexOf("style:") === 0 && (typeof value === "string" || typeof value === "number")) {
306
- const name = prop.replace(/^style:/, "");
307
- style += `${name}:${value};`;
308
- delete props[prop];
309
- continue;
310
- }
311
- if (value === true) {
312
- result.template += ` ${prop}`;
313
- delete props[prop];
314
- }
315
- if (value === false) {
316
- delete props[prop];
317
- }
318
- if (typeof value === "string" || typeof value === "number") {
319
- result.template += ` ${prop}="${value}"`;
320
- delete props[prop];
321
- }
322
- }
323
- if (Object.keys(props).length > 0) {
324
- result.props[result.index] = props;
325
- }
326
- klass = klass.trim();
327
- style = style.trim();
328
- if (klass) {
329
- result.template += ` class="${klass}"`;
330
- }
331
- if (style) {
332
- result.template += ` style="${style}"`;
333
- }
334
- }
335
- function transformChildren(path, result) {
336
- const parentIndex = result.index;
337
- path.get("children").reduce((acc, child) => {
338
- if (isValidChild(child)) {
339
- const lastChild = acc.at(-1);
340
- if (lastChild && isTextChild(child) && isTextChild(lastChild)) {
341
- setNodeText(lastChild, getNodeText(lastChild) + getNodeText(child));
342
- } else {
343
- acc.push(child);
344
- }
345
- }
346
- return acc;
347
- }, []).forEach((child, i, arr) => {
348
- result.parentIndex = parentIndex;
349
- result.isLastChild = i === arr.length - 1;
350
- transformChild(child, result);
351
- });
352
- }
353
- function transformChild(child, result) {
354
- result.index++;
355
- if (child.isJSXElement() || child.isJSXFragment()) {
356
- transformElement(child, result);
357
- } else if (child.isJSXExpressionContainer()) {
358
- const expression = child.get("expression");
359
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
360
- result.template += expression.node.value;
361
- } else if (expression.isExpression()) {
362
- replaceChild(expression.node, result);
363
- } else {
364
- throw new Error("Unsupported JSX child");
365
- }
366
- } else if (child.isJSXText()) {
367
- result.template += child.node.value;
368
- } else {
369
- throw new Error("Unsupported JSX child");
370
- }
371
- }
372
- function replaceChild(node, result) {
373
- var _a, _b, _c, _d, _e;
374
- if (result.isLastChild) {
375
- result.index--;
376
- } else {
377
- result.template += "<!>";
378
- }
379
- (_c = (_a = result.props)[_b = result.parentIndex]) != null ? _c : _a[_b] = {};
380
- (_e = (_d = result.props[result.parentIndex]).children) != null ? _e : _d.children = [];
381
- result.props[result.parentIndex].children.push(
382
- import_core2.types.arrayExpression([
383
- import_core2.types.arrowFunctionExpression([], node),
384
- result.isLastChild ? import_core2.types.nullLiteral() : import_core2.types.identifier(String(result.index))
385
- ])
386
- );
387
- }
388
- function getAttrName(attribute) {
389
- if (import_core2.types.isJSXIdentifier(attribute.name)) {
390
- return attribute.name.name;
391
- }
392
- if (import_core2.types.isJSXNamespacedName(attribute.name)) {
393
- return `${attribute.name.namespace.name}:${attribute.name.name.name}`;
394
- }
395
- throw new Error("Unsupported attribute type");
396
- }
397
- function getNodeText(path) {
398
- if (path.isJSXText()) {
399
- return path.node.value;
400
- }
401
- if (path.isJSXExpressionContainer()) {
402
- const expression = path.get("expression");
403
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
404
- return String(expression.node.value);
405
- }
406
- }
407
- return "";
408
- }
409
- function setNodeText(path, text) {
410
- if (path.isJSXText()) {
411
- path.node.value = text;
412
- }
413
- if (path.isJSXExpressionContainer()) {
414
- const expression = path.get("expression");
415
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
416
- expression.replaceWith(import_core2.types.stringLiteral(text));
417
- }
418
- }
419
- }
420
- function getTagName(node) {
421
- const jsxName = node.openingElement.name;
422
- return jsxElementNameToString(jsxName);
423
- }
424
- function isComponent(tagName) {
425
- return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^A-Za-z]/.test(tagName[0]);
426
- }
427
- function isTextChild(path) {
428
- if (path.isJSXExpressionContainer()) {
429
- const expression = path.get("expression");
430
- if (expression.isJSXText() || expression.isStringLiteral() || expression.isNumericLiteral()) {
431
- return true;
432
- }
433
- }
434
- if (path.isJSXText() || path.isStringLiteral() || path.isNullLiteral()) {
435
- return true;
436
- }
437
- return false;
438
- }
439
- function isValidChild(path) {
440
- const regex = /^\s*$/;
441
- if (path.isStringLiteral() || path.isJSXText()) {
442
- return !regex.test(path.node.value);
443
- }
444
- return Object.keys(path.node).length > 0;
445
- }
446
- function jsxElementNameToString(node) {
447
- if (import_core2.types.isJSXMemberExpression(node)) {
448
- return `${jsxElementNameToString(node.object)}.${node.property.name}`;
449
- }
450
- if (import_core2.types.isJSXIdentifier(node) || import_core2.types.isIdentifier(node)) {
451
- return node.name;
452
- }
453
- return `${node.namespace.name}:${node.name.name}`;
454
- }
455
-
456
- // src/symbol-replace.ts
457
- var import_core3 = require("@babel/core");
458
- var import_types = require("@babel/types");
459
- function replaceSymbol(path) {
460
- const init = path.node.init;
461
- const variableName = path.node.id.name;
462
- if (import_core3.types.isObjectPattern(path.node.id) || import_core3.types.isArrayPattern(path.node.id)) {
463
- return;
464
- }
465
- if (!variableName.startsWith("$")) {
466
- return;
467
- }
468
- if (init && (import_core3.types.isFunctionExpression(init) || import_core3.types.isArrowFunctionExpression(init)) && path.parent.kind === "const") {
469
- const newInit = import_core3.types.callExpression(import_core3.types.identifier(path.state.computed.name), init ? [init] : []);
470
- imports.add("computed");
471
- path.node.init = newInit;
472
- } else {
473
- const originalImportDeclarationNodes = (0, import_types.cloneNode)(path.get("id").node, true);
474
- const newInit = import_core3.types.callExpression(import_core3.types.identifier(path.state.signal.name), init ? [init] : []);
475
- imports.add("signal");
476
- path.node.init = newInit;
477
- path.scope.rename(variableName, `${variableName}.value`);
478
- path.get("id").replaceWith(originalImportDeclarationNodes);
479
- path.scope.traverse(path.scope.block, {
480
- Identifier(innerPath) {
481
- if (import_core3.types.isExportSpecifier(innerPath.parent)) {
482
- const { name } = innerPath.node;
483
- if (name.endsWith(".value")) {
484
- innerPath.node.name = name.slice(0, -6);
485
- }
486
- }
487
- }
488
- });
489
- }
490
- }
491
-
492
- // src/import-replace.ts
493
- function replaceImport(path) {
494
- const imports2 = path.node.specifiers;
495
- imports2.forEach((specifier) => {
496
- const variableName = specifier.local.name;
497
- if (variableName.indexOf("$") === 0) {
498
- path.scope.rename(variableName, `${variableName}.value`);
499
- specifier.local.name = `${variableName}`;
500
- }
501
- });
502
- }
503
-
504
- // src/index.ts
505
- function src_default() {
506
- return {
507
- name: "babel-plugin-essor",
508
- manipulateOptions({ filename }, parserOpts) {
509
- if (filename.endsWith("ts") || filename.endsWith("tsx")) {
510
- parserOpts.plugins.push("typescript");
511
- }
512
- parserOpts.plugins.push("jsx");
513
- },
514
- visitor: {
515
- Program: transformProgram,
516
- JSXElement: transformJSX,
517
- JSXFragment: transformJSX,
518
- VariableDeclarator: replaceSymbol,
519
- ImportDeclaration: replaceImport
520
- }
521
- };
522
- }
27
+ var one = 1;
28
+ var two = 2;
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ one,
32
+ two
33
+ });
523
34
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/transform.ts","../src/constants.ts","../src/jsx-transform.ts","../src/symbol-replace.ts","../src/import-replace.ts"],"sourcesContent":["import { transformProgram } from './transform';\nimport { transformJSX } from './jsx-transform';\nimport { replaceSymbol } from './symbol-replace';\nimport { replaceImport } from './import-replace';\nimport type { PluginObj } from '@babel/core';\n\nexport default function (): PluginObj {\n return {\n name: 'babel-plugin-essor',\n manipulateOptions({ filename }, parserOpts) {\n if (filename.endsWith('ts') || filename.endsWith('tsx')) {\n parserOpts.plugins.push('typescript');\n }\n parserOpts.plugins.push('jsx');\n },\n visitor: {\n Program: transformProgram,\n JSXElement: transformJSX,\n JSXFragment: transformJSX,\n VariableDeclarator: replaceSymbol,\n ImportDeclaration: replaceImport,\n },\n };\n}\n","import { types as t } from '@babel/core';\nimport { imports } from './constants';\nimport type { NodePath } from '@babel/core';\nimport type { State } from './types';\n\nexport const transformProgram = {\n enter(path: NodePath<t.Program>) {\n path.state = {\n h: path.scope.generateUidIdentifier('h$'),\n signal: path.scope.generateUidIdentifier('signal$'),\n computed: path.scope.generateUidIdentifier('computed$'),\n template: path.scope.generateUidIdentifier('template$'),\n signalObject: path.scope.generateUidIdentifier('signalObject&'),\n tmplDeclaration: t.variableDeclaration('const', []),\n } as State;\n\n imports.clear();\n },\n exit(path: NodePath<t.Program>) {\n const state: State = path.state;\n\n if (state.tmplDeclaration.declarations.length > 0) {\n const index = path.node.body.findIndex(\n node => !t.isImportDeclaration(node) && !t.isExportDeclaration(node),\n );\n path.node.body.splice(index, 0, state.tmplDeclaration);\n }\n\n if (imports.size > 0) {\n path.node.body.unshift(createImport(state, 'essor'));\n }\n },\n};\nfunction createImport(state: State, from: string) {\n const ImportSpecifier: t.ImportSpecifier[] = [];\n imports.forEach(name => {\n const local = t.identifier(state[name].name);\n const imported = t.identifier(name);\n ImportSpecifier.push(t.importSpecifier(local, imported));\n });\n\n const importSource = t.stringLiteral(from);\n return t.importDeclaration(ImportSpecifier, importSource);\n}\n","export const selfClosingTags = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n];\n\nexport const svgTags = [\n 'circle',\n 'clipPath',\n 'defs',\n 'ellipse',\n 'filter',\n 'g',\n 'line',\n 'linearGradient',\n 'mask',\n 'path',\n 'pattern',\n 'polygon',\n 'polyline',\n 'radialGradient',\n 'rect',\n 'stop',\n 'symbol',\n 'text',\n 'use',\n];\nexport const imports = new Set<string>();\n","import { types as t } from '@babel/core';\nimport { imports, selfClosingTags, svgTags } from './constants';\nimport type { NodePath } from '@babel/core';\nimport type { State } from './types';\n\ninterface Result {\n index: number;\n isLastChild: boolean;\n parentIndex: number;\n props: Record<string, any>;\n template: string;\n}\n\ntype JSXElement = t.JSXElement | t.JSXFragment;\n\ntype JSXChild =\n | t.JSXElement\n | t.JSXFragment\n | t.JSXExpressionContainer\n | t.JSXSpreadChild\n | t.JSXText;\n\n/**\n * Transform JSX element and replace it with a new ES Node.\n *\n * @param {NodePath<JSXElement>} path - The path to the JSX element to transform\n * @return {void}\n */\nexport function transformJSX(path: NodePath<JSXElement>): void {\n const result: Result = {\n index: 1,\n isLastChild: false,\n parentIndex: 0,\n props: {},\n template: '',\n };\n transformElement(path, result, true);\n path.replaceWith(createEssorNode(path, result));\n}\n\n/**\n * Generate a call expression for creating an Essor node based on the given JSXElement path and result.\n *\n * @param {NodePath<JSXElement>} path - The path to the JSXElement\n * @param {Result} result - The result object\n * @return {t.CallExpression} The call expression for creating the Essor node\n */\nfunction createEssorNode(path: NodePath<JSXElement>, result: Result): t.CallExpression {\n const state: State = path.state;\n let tmpl: t.Identifier;\n\n if (path.isJSXElement() && isComponent(getTagName(path.node))) {\n tmpl = t.identifier(getTagName(path.node));\n } else {\n tmpl = path.scope.generateUidIdentifier('_tmpl$');\n const template = t.callExpression(state.template, [t.stringLiteral(result.template)]);\n const declarator = t.variableDeclarator(tmpl, template);\n state.tmplDeclaration.declarations.push(declarator);\n imports.add('template');\n }\n\n const args = [tmpl, createProps(result.props)];\n const key = result.props.key ?? result.props[0]?.key;\n\n if (key) {\n args.push(key);\n }\n imports.add('h');\n return t.callExpression(state.h, args);\n}\n\n/**\n * Generate an object expression based on the given props object.\n *\n * @param {Record<string, any>} props - The object containing the properties to be transformed into an object expression.\n * @return {t.ObjectExpression} The object expression generated from the props object.\n */\nfunction createProps(props: Record<string, any>): t.ObjectExpression {\n const result: (t.ObjectProperty | t.SpreadElement)[] = [];\n\n for (const prop in props) {\n let value = props[prop];\n\n if (prop === 'key') {\n continue;\n }\n\n if (Array.isArray(value)) {\n value = t.arrayExpression(value);\n }\n\n if (typeof value === 'object' && value !== null && !t.isNode(value)) {\n value = createProps(value);\n }\n\n if (typeof value === 'string') {\n value = t.stringLiteral(value);\n }\n\n if (typeof value === 'number') {\n value = t.numericLiteral(value);\n }\n\n if (typeof value === 'boolean') {\n value = t.booleanLiteral(value);\n }\n\n if (value === undefined) {\n value = t.tsUndefinedKeyword();\n }\n\n if (value === null) {\n value = t.nullLiteral();\n }\n\n if (prop === '_$spread$') {\n result.push(t.spreadElement(value));\n } else {\n result.push(t.objectProperty(t.stringLiteral(prop), value));\n }\n }\n\n return t.objectExpression(result);\n}\n\n/**\n * Generates a record of JSX element attributes.\n *\n * @param {NodePath<t.JSXElement>} path - the NodePath of the JSX element\n * @return {Record<string, any>} the generated record of attributes\n */\nfunction getAttrProps(path: NodePath<t.JSXElement>): Record<string, any> {\n const props: Record<string, any> = {};\n\n path\n .get('openingElement')\n .get('attributes')\n .forEach(attribute => {\n if (attribute.isJSXAttribute()) {\n const name = getAttrName(attribute.node);\n const value = attribute.get('value');\n\n if (!value.node) {\n props[name] = true;\n } else if (value.isStringLiteral()) {\n props[name] = value.node.value;\n } else {\n if (value.isJSXExpressionContainer()) {\n const expression = value.get('expression');\n\n if (expression.isStringLiteral()) {\n props[name] = expression.node.value;\n } else if (expression.isNumericLiteral()) {\n props[name] = expression.node.value;\n } else if (expression.isJSXElement() || expression.isJSXFragment()) {\n transformJSX(expression);\n props[name] = expression.node;\n } else if (expression.isExpression()) {\n if (/^key|ref|on.+$/.test(name)) {\n props[name] = expression.node;\n } else if (/^bind:.+/.test(name)) {\n props[name] = t.arrowFunctionExpression([], expression.node);\n const value = path.scope.generateUidIdentifier('value');\n props[`update:${name.slice(5).toLocaleLowerCase()}`] = t.arrowFunctionExpression(\n [value],\n t.assignmentExpression('=', expression.node as any, value),\n );\n } else {\n if (expression.isConditionalExpression()) {\n props[name] = t.arrowFunctionExpression([], expression.node);\n } else {\n props[name] = expression.node;\n }\n }\n }\n } else if (value.isJSXElement() || value.isJSXFragment()) {\n transformJSX(value);\n props[name] = value.node;\n }\n }\n } else if (attribute.isJSXSpreadAttribute()) {\n props._$spread$ = attribute.get('argument').node;\n } else {\n throw new Error('Unsupported attribute type');\n }\n });\n\n return props;\n}\n\n/**\n * Transforms the given JSX element and updates the result.\n *\n * @param {NodePath<JSXElement>} path - the path of the JSX element to transform\n * @param {Result} result - the result object to update\n * @param {boolean} [isRoot] - indicates if the current element is the root element\n * @return {void}\n */\nfunction transformElement(path: NodePath<JSXElement>, result: Result, isRoot?: boolean): void {\n if (path.isJSXElement()) {\n const tagName = getTagName(path.node);\n const tagIsComponent = isComponent(tagName);\n const isSelfClosing = !tagIsComponent && selfClosingTags.includes(tagName);\n const isSvgTemplate = svgTags.includes(tagName) && result.index === 1;\n const props = getAttrProps(path);\n\n if (tagIsComponent) {\n if (isRoot) {\n result.props = props;\n const children = getChildren(path) as any;\n if (children.length > 0) {\n const childrenGetter = children.length === 1 ? children[0] : t.arrayExpression(children);\n result.props.children = childrenGetter;\n }\n } else {\n transformJSX(path);\n replaceChild(path.node, result);\n }\n } else {\n if (isSvgTemplate) {\n result.template += `<svg _svg_>`;\n }\n result.template += `<${tagName}`;\n handleAttributes(props, result);\n result.template += isSelfClosing ? '/>' : '>';\n if (!isSelfClosing) {\n transformChildren(path, result);\n result.template += `</${tagName}>`;\n }\n }\n } else {\n result.index--;\n transformChildren(path, result);\n }\n}\n\n/**\n * Retrieves the children of the given JSX element path, filters out invalid children, and transforms valid children based on their type.\n *\n * @param {NodePath<t.JSXElement>} path - the JSX element path\n * @return {JSXChild[]} an array of transformed JSX children\n */\nfunction getChildren(path: NodePath<t.JSXElement>): JSXChild[] {\n return path\n .get('children')\n .filter(isValidChild)\n .map(child => {\n if (child.isJSXElement() || child.isJSXFragment()) {\n transformJSX(child);\n } else if (child.isJSXExpressionContainer()) {\n child.replaceWith(child.get('expression'));\n } else if (child.isJSXText()) {\n child.replaceWith(t.stringLiteral(child.node.value));\n } else {\n throw new Error('Unsupported JSX child');\n }\n return child.node;\n });\n}\n\n/**\n * Handles attributes from props and updates the result object with template, props, index.\n *\n * @param {Record<string, any>} props - The attributes to be handled\n * @param {Result} result - The result object to be updated with template, props, index\n * @return {void}\n */\nfunction handleAttributes(props: Record<string, any>, result: Result): void {\n let klass = '';\n let style = '';\n\n for (const prop in props) {\n const value = props[prop];\n\n if (prop === 'class' && typeof value === 'string') {\n klass += ` ${value}`;\n delete props[prop];\n continue;\n }\n if (prop.indexOf('class:') === 0) {\n if (value === true) {\n const name = prop.replace(/^class:/, '');\n klass += ` ${name}`;\n delete props[prop];\n continue;\n }\n if (value === false) {\n delete props[prop];\n continue;\n }\n }\n\n if (prop === 'style' && typeof value === 'string') {\n style += `${value}${value.at(-1) === ';' ? '' : ';'}`;\n delete props[prop];\n continue;\n }\n if (prop.indexOf('style:') === 0 && (typeof value === 'string' || typeof value === 'number')) {\n const name = prop.replace(/^style:/, '');\n style += `${name}:${value};`;\n delete props[prop];\n continue;\n }\n\n if (value === true) {\n result.template += ` ${prop}`;\n delete props[prop];\n }\n if (value === false) {\n delete props[prop];\n }\n if (typeof value === 'string' || typeof value === 'number') {\n result.template += ` ${prop}=\"${value}\"`;\n delete props[prop];\n }\n }\n\n if (Object.keys(props).length > 0) {\n result.props[result.index] = props;\n }\n\n klass = klass.trim();\n style = style.trim();\n\n if (klass) {\n result.template += ` class=\"${klass}\"`;\n }\n if (style) {\n result.template += ` style=\"${style}\"`;\n }\n}\n\n/**\n * Transforms the children of the given JSX element path and updates the result object accordingly.\n *\n * @param {NodePath<JSXElement>} path - The path of the JSX element whose children are to be transformed\n * @param {Result} result - The result object to be updated during the transformation\n * @return {void} This function does not return a value\n */\nfunction transformChildren(path: NodePath<JSXElement>, result: Result): void {\n const parentIndex = result.index;\n path\n .get('children')\n .reduce((acc, child) => {\n if (isValidChild(child)) {\n const lastChild = acc.at(-1);\n if (lastChild && isTextChild(child) && isTextChild(lastChild)) {\n setNodeText(lastChild, getNodeText(lastChild) + getNodeText(child));\n } else {\n acc.push(child);\n }\n }\n return acc;\n }, [] as NodePath<JSXChild>[])\n .forEach((child, i, arr) => {\n result.parentIndex = parentIndex;\n result.isLastChild = i === arr.length - 1;\n transformChild(child, result);\n });\n}\n\n/**\n * Transform a JSX child node.\n *\n * @param {NodePath<JSXChild>} child - the JSX child node to transform\n * @param {Result} result - the result object to store transformation results\n */\nfunction transformChild(child: NodePath<JSXChild>, result: Result) {\n result.index++;\n if (child.isJSXElement() || child.isJSXFragment()) {\n transformElement(child, result);\n } else if (child.isJSXExpressionContainer()) {\n const expression = child.get('expression');\n if (expression.isStringLiteral() || expression.isNumericLiteral()) {\n result.template += expression.node.value;\n } else if (expression.isExpression()) {\n replaceChild(expression.node, result);\n } else {\n throw new Error('Unsupported JSX child');\n }\n } else if (child.isJSXText()) {\n result.template += child.node.value;\n } else {\n throw new Error('Unsupported JSX child');\n }\n}\n\n/**\n * Replaces a child node with the provided result.\n *\n * @param {t.Expression} node - the node to be replaced\n * @param {Result} result - the result to replace the node with\n * @return {void}\n */\nfunction replaceChild(node: t.Expression, result: Result): void {\n if (result.isLastChild) {\n result.index--;\n } else {\n result.template += '<!>';\n }\n result.props[result.parentIndex] ??= {};\n result.props[result.parentIndex].children ??= [];\n result.props[result.parentIndex].children.push(\n t.arrayExpression([\n t.arrowFunctionExpression([], node),\n result.isLastChild ? t.nullLiteral() : t.identifier(String(result.index)),\n ]),\n );\n}\n\nfunction getAttrName(attribute: t.JSXAttribute): string {\n if (t.isJSXIdentifier(attribute.name)) {\n return attribute.name.name;\n }\n if (t.isJSXNamespacedName(attribute.name)) {\n return `${attribute.name.namespace.name}:${attribute.name.name.name}`;\n }\n throw new Error('Unsupported attribute type');\n}\n\nfunction getNodeText(path: NodePath<JSXChild>): string {\n if (path.isJSXText()) {\n return path.node.value;\n }\n if (path.isJSXExpressionContainer()) {\n const expression = path.get('expression');\n if (expression.isStringLiteral() || expression.isNumericLiteral()) {\n return String(expression.node.value);\n }\n }\n return '';\n}\n\nfunction setNodeText(path: NodePath<JSXChild>, text: string): void {\n if (path.isJSXText()) {\n path.node.value = text;\n }\n if (path.isJSXExpressionContainer()) {\n const expression = path.get('expression');\n if (expression.isStringLiteral() || expression.isNumericLiteral()) {\n expression.replaceWith(t.stringLiteral(text));\n }\n }\n}\n\nfunction getTagName(node: t.JSXElement): string {\n const jsxName = node.openingElement.name;\n return jsxElementNameToString(jsxName);\n}\n\nfunction isComponent(tagName: string): boolean {\n return (\n (tagName[0] && tagName[0].toLowerCase() !== tagName[0]) ||\n tagName.includes('.') ||\n /[^A-Za-z]/.test(tagName[0])\n );\n}\n\nfunction isTextChild(path: NodePath<JSXChild>): boolean {\n if (path.isJSXExpressionContainer()) {\n const expression = path.get('expression');\n if (expression.isJSXText() || expression.isStringLiteral() || expression.isNumericLiteral()) {\n return true;\n }\n }\n if (path.isJSXText() || path.isStringLiteral() || path.isNullLiteral()) {\n return true;\n }\n return false;\n}\n\nfunction isValidChild(path: NodePath<JSXChild>): boolean {\n const regex = /^\\s*$/;\n if (path.isStringLiteral() || path.isJSXText()) {\n return !regex.test(path.node.value);\n }\n return Object.keys(path.node).length > 0;\n}\n\nfunction jsxElementNameToString(\n node: t.JSXMemberExpression | t.JSXIdentifier | t.JSXNamespacedName,\n): string {\n if (t.isJSXMemberExpression(node)) {\n return `${jsxElementNameToString(node.object)}.${node.property.name}`;\n }\n if (t.isJSXIdentifier(node) || t.isIdentifier(node)) {\n return node.name;\n }\n return `${node.namespace.name}:${node.name.name}`;\n}\n","import { types as t } from '@babel/core';\nimport { type Identifier, type VariableDeclarator, cloneNode } from '@babel/types';\nimport { imports } from './constants';\nimport type { NodePath } from '@babel/core';\n\nexport function replaceSymbol(path: NodePath<VariableDeclarator>) {\n const init = path.node.init;\n const variableName = (path.node.id as Identifier).name;\n\n // pattern does not need to be replaced\n if (t.isObjectPattern(path.node.id) || t.isArrayPattern(path.node.id)) {\n return;\n }\n if (!variableName.startsWith('$')) {\n return;\n }\n\n if (\n init &&\n (t.isFunctionExpression(init) || t.isArrowFunctionExpression(init)) &&\n (path.parent as t.VariableDeclaration).kind === 'const'\n ) {\n const newInit = t.callExpression(t.identifier(path.state.computed.name), init ? [init] : []);\n imports.add('computed');\n path.node.init = newInit;\n } else {\n const originalImportDeclarationNodes = cloneNode(path.get('id').node, true);\n\n const newInit = t.callExpression(t.identifier(path.state.signal.name), init ? [init] : []);\n imports.add('signal');\n path.node.init = newInit;\n\n path.scope.rename(variableName, `${variableName}.value`);\n path.get('id').replaceWith(originalImportDeclarationNodes);\n\n path.scope.traverse(path.scope.block, {\n Identifier(innerPath) {\n if (t.isExportSpecifier(innerPath.parent)) {\n const { name } = innerPath.node;\n if (name.endsWith('.value')) {\n innerPath.node.name = name.slice(0, -6);\n }\n }\n },\n });\n }\n}\n","export function replaceImport(path) {\n const imports = path.node.specifiers;\n imports.forEach(specifier => {\n const variableName = specifier.local.name;\n if (variableName.indexOf('$') === 0) {\n path.scope.rename(variableName, `${variableName}.value`);\n specifier.local.name = `${variableName}`;\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2B;;;ACApB,IAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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,UAAU;AAC3B,cAAI,KAAK,SAAS,QAAQ,GAAG;AAC3B,sBAAU,KAAK,OAAO,KAAK,MAAM,GAAG,EAAE;AAAA,UACxC;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;AC9CO,SAAS,cAAc,MAAM;AAClC,QAAMC,WAAU,KAAK,KAAK;AAC1B,EAAAA,SAAQ,QAAQ,eAAa;AAC3B,UAAM,eAAe,UAAU,MAAM;AACrC,QAAI,aAAa,QAAQ,GAAG,MAAM,GAAG;AACnC,WAAK,MAAM,OAAO,cAAc,GAAG,YAAY,QAAQ;AACvD,gBAAU,MAAM,OAAO,GAAG,YAAY;AAAA,IACxC;AAAA,EACF,CAAC;AACH;;;ALHe,SAAR,cAA+B;AACpC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,kBAAkB,EAAE,SAAS,GAAG,YAAY;AAC1C,UAAI,SAAS,SAAS,IAAI,KAAK,SAAS,SAAS,KAAK,GAAG;AACvD,mBAAW,QAAQ,KAAK,YAAY;AAAA,MACtC;AACA,iBAAW,QAAQ,KAAK,KAAK;AAAA,IAC/B;AAAA,IACA,SAAS;AAAA,MACP,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,aAAa;AAAA,MACb,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;","names":["t","import_core","t","value","import_core","t","imports"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const one = 1;\nexport const two = 2;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,MAAM;AACZ,IAAM,MAAM;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { PluginObj } from '@babel/core';
1
+ declare const one = 1;
2
+ declare const two = 2;
2
3
 
3
- declare function export_default(): PluginObj;
4
-
5
- export { export_default as default };
4
+ export { one, two };
package/dist/index.js CHANGED
@@ -1,500 +1,8 @@
1
- // src/transform.ts
2
- import { types as t } from "@babel/core";
3
-
4
- // src/constants.ts
5
- var selfClosingTags = [
6
- "area",
7
- "base",
8
- "br",
9
- "col",
10
- "embed",
11
- "hr",
12
- "img",
13
- "input",
14
- "link",
15
- "meta",
16
- "param",
17
- "source",
18
- "track",
19
- "wbr"
20
- ];
21
- var svgTags = [
22
- "circle",
23
- "clipPath",
24
- "defs",
25
- "ellipse",
26
- "filter",
27
- "g",
28
- "line",
29
- "linearGradient",
30
- "mask",
31
- "path",
32
- "pattern",
33
- "polygon",
34
- "polyline",
35
- "radialGradient",
36
- "rect",
37
- "stop",
38
- "symbol",
39
- "text",
40
- "use"
41
- ];
42
- var imports = /* @__PURE__ */ new Set();
43
-
44
- // src/transform.ts
45
- var transformProgram = {
46
- enter(path) {
47
- path.state = {
48
- h: path.scope.generateUidIdentifier("h$"),
49
- signal: path.scope.generateUidIdentifier("signal$"),
50
- computed: path.scope.generateUidIdentifier("computed$"),
51
- template: path.scope.generateUidIdentifier("template$"),
52
- signalObject: path.scope.generateUidIdentifier("signalObject&"),
53
- tmplDeclaration: t.variableDeclaration("const", [])
54
- };
55
- imports.clear();
56
- },
57
- exit(path) {
58
- const state = path.state;
59
- if (state.tmplDeclaration.declarations.length > 0) {
60
- const index = path.node.body.findIndex(
61
- (node) => !t.isImportDeclaration(node) && !t.isExportDeclaration(node)
62
- );
63
- path.node.body.splice(index, 0, state.tmplDeclaration);
64
- }
65
- if (imports.size > 0) {
66
- path.node.body.unshift(createImport(state, "essor"));
67
- }
68
- }
69
- };
70
- function createImport(state, from) {
71
- const ImportSpecifier = [];
72
- imports.forEach((name) => {
73
- const local = t.identifier(state[name].name);
74
- const imported = t.identifier(name);
75
- ImportSpecifier.push(t.importSpecifier(local, imported));
76
- });
77
- const importSource = t.stringLiteral(from);
78
- return t.importDeclaration(ImportSpecifier, importSource);
79
- }
80
-
81
- // src/jsx-transform.ts
82
- import { types as t2 } from "@babel/core";
83
- function transformJSX(path) {
84
- const result = {
85
- index: 1,
86
- isLastChild: false,
87
- parentIndex: 0,
88
- props: {},
89
- template: ""
90
- };
91
- transformElement(path, result, true);
92
- path.replaceWith(createEssorNode(path, result));
93
- }
94
- function createEssorNode(path, result) {
95
- var _a, _b;
96
- const state = path.state;
97
- let tmpl;
98
- if (path.isJSXElement() && isComponent(getTagName(path.node))) {
99
- tmpl = t2.identifier(getTagName(path.node));
100
- } else {
101
- tmpl = path.scope.generateUidIdentifier("_tmpl$");
102
- const template = t2.callExpression(state.template, [t2.stringLiteral(result.template)]);
103
- const declarator = t2.variableDeclarator(tmpl, template);
104
- state.tmplDeclaration.declarations.push(declarator);
105
- imports.add("template");
106
- }
107
- const args = [tmpl, createProps(result.props)];
108
- const key = (_b = result.props.key) != null ? _b : (_a = result.props[0]) == null ? void 0 : _a.key;
109
- if (key) {
110
- args.push(key);
111
- }
112
- imports.add("h");
113
- return t2.callExpression(state.h, args);
114
- }
115
- function createProps(props) {
116
- const result = [];
117
- for (const prop in props) {
118
- let value = props[prop];
119
- if (prop === "key") {
120
- continue;
121
- }
122
- if (Array.isArray(value)) {
123
- value = t2.arrayExpression(value);
124
- }
125
- if (typeof value === "object" && value !== null && !t2.isNode(value)) {
126
- value = createProps(value);
127
- }
128
- if (typeof value === "string") {
129
- value = t2.stringLiteral(value);
130
- }
131
- if (typeof value === "number") {
132
- value = t2.numericLiteral(value);
133
- }
134
- if (typeof value === "boolean") {
135
- value = t2.booleanLiteral(value);
136
- }
137
- if (value === void 0) {
138
- value = t2.tsUndefinedKeyword();
139
- }
140
- if (value === null) {
141
- value = t2.nullLiteral();
142
- }
143
- if (prop === "_$spread$") {
144
- result.push(t2.spreadElement(value));
145
- } else {
146
- result.push(t2.objectProperty(t2.stringLiteral(prop), value));
147
- }
148
- }
149
- return t2.objectExpression(result);
150
- }
151
- function getAttrProps(path) {
152
- const props = {};
153
- path.get("openingElement").get("attributes").forEach((attribute) => {
154
- if (attribute.isJSXAttribute()) {
155
- const name = getAttrName(attribute.node);
156
- const value = attribute.get("value");
157
- if (!value.node) {
158
- props[name] = true;
159
- } else if (value.isStringLiteral()) {
160
- props[name] = value.node.value;
161
- } else {
162
- if (value.isJSXExpressionContainer()) {
163
- const expression = value.get("expression");
164
- if (expression.isStringLiteral()) {
165
- props[name] = expression.node.value;
166
- } else if (expression.isNumericLiteral()) {
167
- props[name] = expression.node.value;
168
- } else if (expression.isJSXElement() || expression.isJSXFragment()) {
169
- transformJSX(expression);
170
- props[name] = expression.node;
171
- } else if (expression.isExpression()) {
172
- if (/^key|ref|on.+$/.test(name)) {
173
- props[name] = expression.node;
174
- } else if (/^bind:.+/.test(name)) {
175
- props[name] = t2.arrowFunctionExpression([], expression.node);
176
- const value2 = path.scope.generateUidIdentifier("value");
177
- props[`update:${name.slice(5).toLocaleLowerCase()}`] = t2.arrowFunctionExpression(
178
- [value2],
179
- t2.assignmentExpression("=", expression.node, value2)
180
- );
181
- } else {
182
- if (expression.isConditionalExpression()) {
183
- props[name] = t2.arrowFunctionExpression([], expression.node);
184
- } else {
185
- props[name] = expression.node;
186
- }
187
- }
188
- }
189
- } else if (value.isJSXElement() || value.isJSXFragment()) {
190
- transformJSX(value);
191
- props[name] = value.node;
192
- }
193
- }
194
- } else if (attribute.isJSXSpreadAttribute()) {
195
- props._$spread$ = attribute.get("argument").node;
196
- } else {
197
- throw new Error("Unsupported attribute type");
198
- }
199
- });
200
- return props;
201
- }
202
- function transformElement(path, result, isRoot) {
203
- if (path.isJSXElement()) {
204
- const tagName = getTagName(path.node);
205
- const tagIsComponent = isComponent(tagName);
206
- const isSelfClosing = !tagIsComponent && selfClosingTags.includes(tagName);
207
- const isSvgTemplate = svgTags.includes(tagName) && result.index === 1;
208
- const props = getAttrProps(path);
209
- if (tagIsComponent) {
210
- if (isRoot) {
211
- result.props = props;
212
- const children = getChildren(path);
213
- if (children.length > 0) {
214
- const childrenGetter = children.length === 1 ? children[0] : t2.arrayExpression(children);
215
- result.props.children = childrenGetter;
216
- }
217
- } else {
218
- transformJSX(path);
219
- replaceChild(path.node, result);
220
- }
221
- } else {
222
- if (isSvgTemplate) {
223
- result.template += `<svg _svg_>`;
224
- }
225
- result.template += `<${tagName}`;
226
- handleAttributes(props, result);
227
- result.template += isSelfClosing ? "/>" : ">";
228
- if (!isSelfClosing) {
229
- transformChildren(path, result);
230
- result.template += `</${tagName}>`;
231
- }
232
- }
233
- } else {
234
- result.index--;
235
- transformChildren(path, result);
236
- }
237
- }
238
- function getChildren(path) {
239
- return path.get("children").filter(isValidChild).map((child) => {
240
- if (child.isJSXElement() || child.isJSXFragment()) {
241
- transformJSX(child);
242
- } else if (child.isJSXExpressionContainer()) {
243
- child.replaceWith(child.get("expression"));
244
- } else if (child.isJSXText()) {
245
- child.replaceWith(t2.stringLiteral(child.node.value));
246
- } else {
247
- throw new Error("Unsupported JSX child");
248
- }
249
- return child.node;
250
- });
251
- }
252
- function handleAttributes(props, result) {
253
- let klass = "";
254
- let style = "";
255
- for (const prop in props) {
256
- const value = props[prop];
257
- if (prop === "class" && typeof value === "string") {
258
- klass += ` ${value}`;
259
- delete props[prop];
260
- continue;
261
- }
262
- if (prop.indexOf("class:") === 0) {
263
- if (value === true) {
264
- const name = prop.replace(/^class:/, "");
265
- klass += ` ${name}`;
266
- delete props[prop];
267
- continue;
268
- }
269
- if (value === false) {
270
- delete props[prop];
271
- continue;
272
- }
273
- }
274
- if (prop === "style" && typeof value === "string") {
275
- style += `${value}${value.at(-1) === ";" ? "" : ";"}`;
276
- delete props[prop];
277
- continue;
278
- }
279
- if (prop.indexOf("style:") === 0 && (typeof value === "string" || typeof value === "number")) {
280
- const name = prop.replace(/^style:/, "");
281
- style += `${name}:${value};`;
282
- delete props[prop];
283
- continue;
284
- }
285
- if (value === true) {
286
- result.template += ` ${prop}`;
287
- delete props[prop];
288
- }
289
- if (value === false) {
290
- delete props[prop];
291
- }
292
- if (typeof value === "string" || typeof value === "number") {
293
- result.template += ` ${prop}="${value}"`;
294
- delete props[prop];
295
- }
296
- }
297
- if (Object.keys(props).length > 0) {
298
- result.props[result.index] = props;
299
- }
300
- klass = klass.trim();
301
- style = style.trim();
302
- if (klass) {
303
- result.template += ` class="${klass}"`;
304
- }
305
- if (style) {
306
- result.template += ` style="${style}"`;
307
- }
308
- }
309
- function transformChildren(path, result) {
310
- const parentIndex = result.index;
311
- path.get("children").reduce((acc, child) => {
312
- if (isValidChild(child)) {
313
- const lastChild = acc.at(-1);
314
- if (lastChild && isTextChild(child) && isTextChild(lastChild)) {
315
- setNodeText(lastChild, getNodeText(lastChild) + getNodeText(child));
316
- } else {
317
- acc.push(child);
318
- }
319
- }
320
- return acc;
321
- }, []).forEach((child, i, arr) => {
322
- result.parentIndex = parentIndex;
323
- result.isLastChild = i === arr.length - 1;
324
- transformChild(child, result);
325
- });
326
- }
327
- function transformChild(child, result) {
328
- result.index++;
329
- if (child.isJSXElement() || child.isJSXFragment()) {
330
- transformElement(child, result);
331
- } else if (child.isJSXExpressionContainer()) {
332
- const expression = child.get("expression");
333
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
334
- result.template += expression.node.value;
335
- } else if (expression.isExpression()) {
336
- replaceChild(expression.node, result);
337
- } else {
338
- throw new Error("Unsupported JSX child");
339
- }
340
- } else if (child.isJSXText()) {
341
- result.template += child.node.value;
342
- } else {
343
- throw new Error("Unsupported JSX child");
344
- }
345
- }
346
- function replaceChild(node, result) {
347
- var _a, _b, _c, _d, _e;
348
- if (result.isLastChild) {
349
- result.index--;
350
- } else {
351
- result.template += "<!>";
352
- }
353
- (_c = (_a = result.props)[_b = result.parentIndex]) != null ? _c : _a[_b] = {};
354
- (_e = (_d = result.props[result.parentIndex]).children) != null ? _e : _d.children = [];
355
- result.props[result.parentIndex].children.push(
356
- t2.arrayExpression([
357
- t2.arrowFunctionExpression([], node),
358
- result.isLastChild ? t2.nullLiteral() : t2.identifier(String(result.index))
359
- ])
360
- );
361
- }
362
- function getAttrName(attribute) {
363
- if (t2.isJSXIdentifier(attribute.name)) {
364
- return attribute.name.name;
365
- }
366
- if (t2.isJSXNamespacedName(attribute.name)) {
367
- return `${attribute.name.namespace.name}:${attribute.name.name.name}`;
368
- }
369
- throw new Error("Unsupported attribute type");
370
- }
371
- function getNodeText(path) {
372
- if (path.isJSXText()) {
373
- return path.node.value;
374
- }
375
- if (path.isJSXExpressionContainer()) {
376
- const expression = path.get("expression");
377
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
378
- return String(expression.node.value);
379
- }
380
- }
381
- return "";
382
- }
383
- function setNodeText(path, text) {
384
- if (path.isJSXText()) {
385
- path.node.value = text;
386
- }
387
- if (path.isJSXExpressionContainer()) {
388
- const expression = path.get("expression");
389
- if (expression.isStringLiteral() || expression.isNumericLiteral()) {
390
- expression.replaceWith(t2.stringLiteral(text));
391
- }
392
- }
393
- }
394
- function getTagName(node) {
395
- const jsxName = node.openingElement.name;
396
- return jsxElementNameToString(jsxName);
397
- }
398
- function isComponent(tagName) {
399
- return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^A-Za-z]/.test(tagName[0]);
400
- }
401
- function isTextChild(path) {
402
- if (path.isJSXExpressionContainer()) {
403
- const expression = path.get("expression");
404
- if (expression.isJSXText() || expression.isStringLiteral() || expression.isNumericLiteral()) {
405
- return true;
406
- }
407
- }
408
- if (path.isJSXText() || path.isStringLiteral() || path.isNullLiteral()) {
409
- return true;
410
- }
411
- return false;
412
- }
413
- function isValidChild(path) {
414
- const regex = /^\s*$/;
415
- if (path.isStringLiteral() || path.isJSXText()) {
416
- return !regex.test(path.node.value);
417
- }
418
- return Object.keys(path.node).length > 0;
419
- }
420
- function jsxElementNameToString(node) {
421
- if (t2.isJSXMemberExpression(node)) {
422
- return `${jsxElementNameToString(node.object)}.${node.property.name}`;
423
- }
424
- if (t2.isJSXIdentifier(node) || t2.isIdentifier(node)) {
425
- return node.name;
426
- }
427
- return `${node.namespace.name}:${node.name.name}`;
428
- }
429
-
430
- // src/symbol-replace.ts
431
- import { types as t3 } from "@babel/core";
432
- import { cloneNode } from "@babel/types";
433
- function replaceSymbol(path) {
434
- const init = path.node.init;
435
- const variableName = path.node.id.name;
436
- if (t3.isObjectPattern(path.node.id) || t3.isArrayPattern(path.node.id)) {
437
- return;
438
- }
439
- if (!variableName.startsWith("$")) {
440
- return;
441
- }
442
- if (init && (t3.isFunctionExpression(init) || t3.isArrowFunctionExpression(init)) && path.parent.kind === "const") {
443
- const newInit = t3.callExpression(t3.identifier(path.state.computed.name), init ? [init] : []);
444
- imports.add("computed");
445
- path.node.init = newInit;
446
- } else {
447
- const originalImportDeclarationNodes = cloneNode(path.get("id").node, true);
448
- const newInit = t3.callExpression(t3.identifier(path.state.signal.name), init ? [init] : []);
449
- imports.add("signal");
450
- path.node.init = newInit;
451
- path.scope.rename(variableName, `${variableName}.value`);
452
- path.get("id").replaceWith(originalImportDeclarationNodes);
453
- path.scope.traverse(path.scope.block, {
454
- Identifier(innerPath) {
455
- if (t3.isExportSpecifier(innerPath.parent)) {
456
- const { name } = innerPath.node;
457
- if (name.endsWith(".value")) {
458
- innerPath.node.name = name.slice(0, -6);
459
- }
460
- }
461
- }
462
- });
463
- }
464
- }
465
-
466
- // src/import-replace.ts
467
- function replaceImport(path) {
468
- const imports2 = path.node.specifiers;
469
- imports2.forEach((specifier) => {
470
- const variableName = specifier.local.name;
471
- if (variableName.indexOf("$") === 0) {
472
- path.scope.rename(variableName, `${variableName}.value`);
473
- specifier.local.name = `${variableName}`;
474
- }
475
- });
476
- }
477
-
478
1
  // src/index.ts
479
- function src_default() {
480
- return {
481
- name: "babel-plugin-essor",
482
- manipulateOptions({ filename }, parserOpts) {
483
- if (filename.endsWith("ts") || filename.endsWith("tsx")) {
484
- parserOpts.plugins.push("typescript");
485
- }
486
- parserOpts.plugins.push("jsx");
487
- },
488
- visitor: {
489
- Program: transformProgram,
490
- JSXElement: transformJSX,
491
- JSXFragment: transformJSX,
492
- VariableDeclarator: replaceSymbol,
493
- ImportDeclaration: replaceImport
494
- }
495
- };
496
- }
2
+ var one = 1;
3
+ var two = 2;
497
4
  export {
498
- src_default as default
5
+ one,
6
+ two
499
7
  };
500
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transform.ts","../src/constants.ts","../src/jsx-transform.ts","../src/symbol-replace.ts","../src/import-replace.ts","../src/index.ts"],"sourcesContent":["import { types as t } from '@babel/core';\nimport { imports } from './constants';\nimport type { NodePath } from '@babel/core';\nimport type { State } from './types';\n\nexport const transformProgram = {\n enter(path: NodePath<t.Program>) {\n path.state = {\n h: path.scope.generateUidIdentifier('h$'),\n signal: path.scope.generateUidIdentifier('signal$'),\n computed: path.scope.generateUidIdentifier('computed$'),\n template: path.scope.generateUidIdentifier('template$'),\n signalObject: path.scope.generateUidIdentifier('signalObject&'),\n tmplDeclaration: t.variableDeclaration('const', []),\n } as State;\n\n imports.clear();\n },\n exit(path: NodePath<t.Program>) {\n const state: State = path.state;\n\n if (state.tmplDeclaration.declarations.length > 0) {\n const index = path.node.body.findIndex(\n node => !t.isImportDeclaration(node) && !t.isExportDeclaration(node),\n );\n path.node.body.splice(index, 0, state.tmplDeclaration);\n }\n\n if (imports.size > 0) {\n path.node.body.unshift(createImport(state, 'essor'));\n }\n },\n};\nfunction createImport(state: State, from: string) {\n const ImportSpecifier: t.ImportSpecifier[] = [];\n imports.forEach(name => {\n const local = t.identifier(state[name].name);\n const imported = t.identifier(name);\n ImportSpecifier.push(t.importSpecifier(local, imported));\n });\n\n const importSource = t.stringLiteral(from);\n return t.importDeclaration(ImportSpecifier, importSource);\n}\n","export const selfClosingTags = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n];\n\nexport const svgTags = [\n 'circle',\n 'clipPath',\n 'defs',\n 'ellipse',\n 'filter',\n 'g',\n 'line',\n 'linearGradient',\n 'mask',\n 'path',\n 'pattern',\n 'polygon',\n 'polyline',\n 'radialGradient',\n 'rect',\n 'stop',\n 'symbol',\n 'text',\n 'use',\n];\nexport const imports = new Set<string>();\n","import { types as t } from '@babel/core';\nimport { imports, selfClosingTags, svgTags } from './constants';\nimport type { NodePath } from '@babel/core';\nimport type { State } from './types';\n\ninterface Result {\n index: number;\n isLastChild: boolean;\n parentIndex: number;\n props: Record<string, any>;\n template: string;\n}\n\ntype JSXElement = t.JSXElement | t.JSXFragment;\n\ntype JSXChild =\n | t.JSXElement\n | t.JSXFragment\n | t.JSXExpressionContainer\n | t.JSXSpreadChild\n | t.JSXText;\n\n/**\n * Transform JSX element and replace it with a new ES Node.\n *\n * @param {NodePath<JSXElement>} path - The path to the JSX element to transform\n * @return {void}\n */\nexport function transformJSX(path: NodePath<JSXElement>): void {\n const result: Result = {\n index: 1,\n isLastChild: false,\n parentIndex: 0,\n props: {},\n template: '',\n };\n transformElement(path, result, true);\n path.replaceWith(createEssorNode(path, result));\n}\n\n/**\n * Generate a call expression for creating an Essor node based on the given JSXElement path and result.\n *\n * @param {NodePath<JSXElement>} path - The path to the JSXElement\n * @param {Result} result - The result object\n * @return {t.CallExpression} The call expression for creating the Essor node\n */\nfunction createEssorNode(path: NodePath<JSXElement>, result: Result): t.CallExpression {\n const state: State = path.state;\n let tmpl: t.Identifier;\n\n if (path.isJSXElement() && isComponent(getTagName(path.node))) {\n tmpl = t.identifier(getTagName(path.node));\n } else {\n tmpl = path.scope.generateUidIdentifier('_tmpl$');\n const template = t.callExpression(state.template, [t.stringLiteral(result.template)]);\n const declarator = t.variableDeclarator(tmpl, template);\n state.tmplDeclaration.declarations.push(declarator);\n imports.add('template');\n }\n\n const args = [tmpl, createProps(result.props)];\n const key = result.props.key ?? result.props[0]?.key;\n\n if (key) {\n args.push(key);\n }\n imports.add('h');\n return t.callExpression(state.h, args);\n}\n\n/**\n * Generate an object expression based on the given props object.\n *\n * @param {Record<string, any>} props - The object containing the properties to be transformed into an object expression.\n * @return {t.ObjectExpression} The object expression generated from the props object.\n */\nfunction createProps(props: Record<string, any>): t.ObjectExpression {\n const result: (t.ObjectProperty | t.SpreadElement)[] = [];\n\n for (const prop in props) {\n let value = props[prop];\n\n if (prop === 'key') {\n continue;\n }\n\n if (Array.isArray(value)) {\n value = t.arrayExpression(value);\n }\n\n if (typeof value === 'object' && value !== null && !t.isNode(value)) {\n value = createProps(value);\n }\n\n if (typeof value === 'string') {\n value = t.stringLiteral(value);\n }\n\n if (typeof value === 'number') {\n value = t.numericLiteral(value);\n }\n\n if (typeof value === 'boolean') {\n value = t.booleanLiteral(value);\n }\n\n if (value === undefined) {\n value = t.tsUndefinedKeyword();\n }\n\n if (value === null) {\n value = t.nullLiteral();\n }\n\n if (prop === '_$spread$') {\n result.push(t.spreadElement(value));\n } else {\n result.push(t.objectProperty(t.stringLiteral(prop), value));\n }\n }\n\n return t.objectExpression(result);\n}\n\n/**\n * Generates a record of JSX element attributes.\n *\n * @param {NodePath<t.JSXElement>} path - the NodePath of the JSX element\n * @return {Record<string, any>} the generated record of attributes\n */\nfunction getAttrProps(path: NodePath<t.JSXElement>): Record<string, any> {\n const props: Record<string, any> = {};\n\n path\n .get('openingElement')\n .get('attributes')\n .forEach(attribute => {\n if (attribute.isJSXAttribute()) {\n const name = getAttrName(attribute.node);\n const value = attribute.get('value');\n\n if (!value.node) {\n props[name] = true;\n } else if (value.isStringLiteral()) {\n props[name] = value.node.value;\n } else {\n if (value.isJSXExpressionContainer()) {\n const expression = value.get('expression');\n\n if (expression.isStringLiteral()) {\n props[name] = expression.node.value;\n } else if (expression.isNumericLiteral()) {\n props[name] = expression.node.value;\n } else if (expression.isJSXElement() || expression.isJSXFragment()) {\n transformJSX(expression);\n props[name] = expression.node;\n } else if (expression.isExpression()) {\n if (/^key|ref|on.+$/.test(name)) {\n props[name] = expression.node;\n } else if (/^bind:.+/.test(name)) {\n props[name] = t.arrowFunctionExpression([], expression.node);\n const value = path.scope.generateUidIdentifier('value');\n props[`update:${name.slice(5).toLocaleLowerCase()}`] = t.arrowFunctionExpression(\n [value],\n t.assignmentExpression('=', expression.node as any, value),\n );\n } else {\n if (expression.isConditionalExpression()) {\n props[name] = t.arrowFunctionExpression([], expression.node);\n } else {\n props[name] = expression.node;\n }\n }\n }\n } else if (value.isJSXElement() || value.isJSXFragment()) {\n transformJSX(value);\n props[name] = value.node;\n }\n }\n } else if (attribute.isJSXSpreadAttribute()) {\n props._$spread$ = attribute.get('argument').node;\n } else {\n throw new Error('Unsupported attribute type');\n }\n });\n\n return props;\n}\n\n/**\n * Transforms the given JSX element and updates the result.\n *\n * @param {NodePath<JSXElement>} path - the path of the JSX element to transform\n * @param {Result} result - the result object to update\n * @param {boolean} [isRoot] - indicates if the current element is the root element\n * @return {void}\n */\nfunction transformElement(path: NodePath<JSXElement>, result: Result, isRoot?: boolean): void {\n if (path.isJSXElement()) {\n const tagName = getTagName(path.node);\n const tagIsComponent = isComponent(tagName);\n const isSelfClosing = !tagIsComponent && selfClosingTags.includes(tagName);\n const isSvgTemplate = svgTags.includes(tagName) && result.index === 1;\n const props = getAttrProps(path);\n\n if (tagIsComponent) {\n if (isRoot) {\n result.props = props;\n const children = getChildren(path) as any;\n if (children.length > 0) {\n const childrenGetter = children.length === 1 ? children[0] : t.arrayExpression(children);\n result.props.children = childrenGetter;\n }\n } else {\n transformJSX(path);\n replaceChild(path.node, result);\n }\n } else {\n if (isSvgTemplate) {\n result.template += `<svg _svg_>`;\n }\n result.template += `<${tagName}`;\n handleAttributes(props, result);\n result.template += isSelfClosing ? '/>' : '>';\n if (!isSelfClosing) {\n transformChildren(path, result);\n result.template += `</${tagName}>`;\n }\n }\n } else {\n result.index--;\n transformChildren(path, result);\n }\n}\n\n/**\n * Retrieves the children of the given JSX element path, filters out invalid children, and transforms valid children based on their type.\n *\n * @param {NodePath<t.JSXElement>} path - the JSX element path\n * @return {JSXChild[]} an array of transformed JSX children\n */\nfunction getChildren(path: NodePath<t.JSXElement>): JSXChild[] {\n return path\n .get('children')\n .filter(isValidChild)\n .map(child => {\n if (child.isJSXElement() || child.isJSXFragment()) {\n transformJSX(child);\n } else if (child.isJSXExpressionContainer()) {\n child.replaceWith(child.get('expression'));\n } else if (child.isJSXText()) {\n child.replaceWith(t.stringLiteral(child.node.value));\n } else {\n throw new Error('Unsupported JSX child');\n }\n return child.node;\n });\n}\n\n/**\n * Handles attributes from props and updates the result object with template, props, index.\n *\n * @param {Record<string, any>} props - The attributes to be handled\n * @param {Result} result - The result object to be updated with template, props, index\n * @return {void}\n */\nfunction handleAttributes(props: Record<string, any>, result: Result): void {\n let klass = '';\n let style = '';\n\n for (const prop in props) {\n const value = props[prop];\n\n if (prop === 'class' && typeof value === 'string') {\n klass += ` ${value}`;\n delete props[prop];\n continue;\n }\n if (prop.indexOf('class:') === 0) {\n if (value === true) {\n const name = prop.replace(/^class:/, '');\n klass += ` ${name}`;\n delete props[prop];\n continue;\n }\n if (value === false) {\n delete props[prop];\n continue;\n }\n }\n\n if (prop === 'style' && typeof value === 'string') {\n style += `${value}${value.at(-1) === ';' ? '' : ';'}`;\n delete props[prop];\n continue;\n }\n if (prop.indexOf('style:') === 0 && (typeof value === 'string' || typeof value === 'number')) {\n const name = prop.replace(/^style:/, '');\n style += `${name}:${value};`;\n delete props[prop];\n continue;\n }\n\n if (value === true) {\n result.template += ` ${prop}`;\n delete props[prop];\n }\n if (value === false) {\n delete props[prop];\n }\n if (typeof value === 'string' || typeof value === 'number') {\n result.template += ` ${prop}=\"${value}\"`;\n delete props[prop];\n }\n }\n\n if (Object.keys(props).length > 0) {\n result.props[result.index] = props;\n }\n\n klass = klass.trim();\n style = style.trim();\n\n if (klass) {\n result.template += ` class=\"${klass}\"`;\n }\n if (style) {\n result.template += ` style=\"${style}\"`;\n }\n}\n\n/**\n * Transforms the children of the given JSX element path and updates the result object accordingly.\n *\n * @param {NodePath<JSXElement>} path - The path of the JSX element whose children are to be transformed\n * @param {Result} result - The result object to be updated during the transformation\n * @return {void} This function does not return a value\n */\nfunction transformChildren(path: NodePath<JSXElement>, result: Result): void {\n const parentIndex = result.index;\n path\n .get('children')\n .reduce((acc, child) => {\n if (isValidChild(child)) {\n const lastChild = acc.at(-1);\n if (lastChild && isTextChild(child) && isTextChild(lastChild)) {\n setNodeText(lastChild, getNodeText(lastChild) + getNodeText(child));\n } else {\n acc.push(child);\n }\n }\n return acc;\n }, [] as NodePath<JSXChild>[])\n .forEach((child, i, arr) => {\n result.parentIndex = parentIndex;\n result.isLastChild = i === arr.length - 1;\n transformChild(child, result);\n });\n}\n\n/**\n * Transform a JSX child node.\n *\n * @param {NodePath<JSXChild>} child - the JSX child node to transform\n * @param {Result} result - the result object to store transformation results\n */\nfunction transformChild(child: NodePath<JSXChild>, result: Result) {\n result.index++;\n if (child.isJSXElement() || child.isJSXFragment()) {\n transformElement(child, result);\n } else if (child.isJSXExpressionContainer()) {\n const expression = child.get('expression');\n if (expression.isStringLiteral() || expression.isNumericLiteral()) {\n result.template += expression.node.value;\n } else if (expression.isExpression()) {\n replaceChild(expression.node, result);\n } else {\n throw new Error('Unsupported JSX child');\n }\n } else if (child.isJSXText()) {\n result.template += child.node.value;\n } else {\n throw new Error('Unsupported JSX child');\n }\n}\n\n/**\n * Replaces a child node with the provided result.\n *\n * @param {t.Expression} node - the node to be replaced\n * @param {Result} result - the result to replace the node with\n * @return {void}\n */\nfunction replaceChild(node: t.Expression, result: Result): void {\n if (result.isLastChild) {\n result.index--;\n } else {\n result.template += '<!>';\n }\n result.props[result.parentIndex] ??= {};\n result.props[result.parentIndex].children ??= [];\n result.props[result.parentIndex].children.push(\n t.arrayExpression([\n t.arrowFunctionExpression([], node),\n result.isLastChild ? t.nullLiteral() : t.identifier(String(result.index)),\n ]),\n );\n}\n\nfunction getAttrName(attribute: t.JSXAttribute): string {\n if (t.isJSXIdentifier(attribute.name)) {\n return attribute.name.name;\n }\n if (t.isJSXNamespacedName(attribute.name)) {\n return `${attribute.name.namespace.name}:${attribute.name.name.name}`;\n }\n throw new Error('Unsupported attribute type');\n}\n\nfunction getNodeText(path: NodePath<JSXChild>): string {\n if (path.isJSXText()) {\n return path.node.value;\n }\n if (path.isJSXExpressionContainer()) {\n const expression = path.get('expression');\n if (expression.isStringLiteral() || expression.isNumericLiteral()) {\n return String(expression.node.value);\n }\n }\n return '';\n}\n\nfunction setNodeText(path: NodePath<JSXChild>, text: string): void {\n if (path.isJSXText()) {\n path.node.value = text;\n }\n if (path.isJSXExpressionContainer()) {\n const expression = path.get('expression');\n if (expression.isStringLiteral() || expression.isNumericLiteral()) {\n expression.replaceWith(t.stringLiteral(text));\n }\n }\n}\n\nfunction getTagName(node: t.JSXElement): string {\n const jsxName = node.openingElement.name;\n return jsxElementNameToString(jsxName);\n}\n\nfunction isComponent(tagName: string): boolean {\n return (\n (tagName[0] && tagName[0].toLowerCase() !== tagName[0]) ||\n tagName.includes('.') ||\n /[^A-Za-z]/.test(tagName[0])\n );\n}\n\nfunction isTextChild(path: NodePath<JSXChild>): boolean {\n if (path.isJSXExpressionContainer()) {\n const expression = path.get('expression');\n if (expression.isJSXText() || expression.isStringLiteral() || expression.isNumericLiteral()) {\n return true;\n }\n }\n if (path.isJSXText() || path.isStringLiteral() || path.isNullLiteral()) {\n return true;\n }\n return false;\n}\n\nfunction isValidChild(path: NodePath<JSXChild>): boolean {\n const regex = /^\\s*$/;\n if (path.isStringLiteral() || path.isJSXText()) {\n return !regex.test(path.node.value);\n }\n return Object.keys(path.node).length > 0;\n}\n\nfunction jsxElementNameToString(\n node: t.JSXMemberExpression | t.JSXIdentifier | t.JSXNamespacedName,\n): string {\n if (t.isJSXMemberExpression(node)) {\n return `${jsxElementNameToString(node.object)}.${node.property.name}`;\n }\n if (t.isJSXIdentifier(node) || t.isIdentifier(node)) {\n return node.name;\n }\n return `${node.namespace.name}:${node.name.name}`;\n}\n","import { types as t } from '@babel/core';\nimport { type Identifier, type VariableDeclarator, cloneNode } from '@babel/types';\nimport { imports } from './constants';\nimport type { NodePath } from '@babel/core';\n\nexport function replaceSymbol(path: NodePath<VariableDeclarator>) {\n const init = path.node.init;\n const variableName = (path.node.id as Identifier).name;\n\n // pattern does not need to be replaced\n if (t.isObjectPattern(path.node.id) || t.isArrayPattern(path.node.id)) {\n return;\n }\n if (!variableName.startsWith('$')) {\n return;\n }\n\n if (\n init &&\n (t.isFunctionExpression(init) || t.isArrowFunctionExpression(init)) &&\n (path.parent as t.VariableDeclaration).kind === 'const'\n ) {\n const newInit = t.callExpression(t.identifier(path.state.computed.name), init ? [init] : []);\n imports.add('computed');\n path.node.init = newInit;\n } else {\n const originalImportDeclarationNodes = cloneNode(path.get('id').node, true);\n\n const newInit = t.callExpression(t.identifier(path.state.signal.name), init ? [init] : []);\n imports.add('signal');\n path.node.init = newInit;\n\n path.scope.rename(variableName, `${variableName}.value`);\n path.get('id').replaceWith(originalImportDeclarationNodes);\n\n path.scope.traverse(path.scope.block, {\n Identifier(innerPath) {\n if (t.isExportSpecifier(innerPath.parent)) {\n const { name } = innerPath.node;\n if (name.endsWith('.value')) {\n innerPath.node.name = name.slice(0, -6);\n }\n }\n },\n });\n }\n}\n","export function replaceImport(path) {\n const imports = path.node.specifiers;\n imports.forEach(specifier => {\n const variableName = specifier.local.name;\n if (variableName.indexOf('$') === 0) {\n path.scope.rename(variableName, `${variableName}.value`);\n specifier.local.name = `${variableName}`;\n }\n });\n}\n","import { transformProgram } from './transform';\nimport { transformJSX } from './jsx-transform';\nimport { replaceSymbol } from './symbol-replace';\nimport { replaceImport } from './import-replace';\nimport type { PluginObj } from '@babel/core';\n\nexport default function (): PluginObj {\n return {\n name: 'babel-plugin-essor',\n manipulateOptions({ filename }, parserOpts) {\n if (filename.endsWith('ts') || filename.endsWith('tsx')) {\n parserOpts.plugins.push('typescript');\n }\n parserOpts.plugins.push('jsx');\n },\n visitor: {\n Program: transformProgram,\n JSXElement: transformJSX,\n JSXFragment: transformJSX,\n VariableDeclarator: replaceSymbol,\n ImportDeclaration: replaceImport,\n },\n };\n}\n"],"mappings":";AAAA,SAAS,SAAS,SAAS;;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,kBAAkB,UAAU,MAAM,GAAG;AACzC,gBAAM,EAAE,KAAK,IAAI,UAAU;AAC3B,cAAI,KAAK,SAAS,QAAQ,GAAG;AAC3B,sBAAU,KAAK,OAAO,KAAK,MAAM,GAAG,EAAE;AAAA,UACxC;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;AC9CO,SAAS,cAAc,MAAM;AAClC,QAAMC,WAAU,KAAK,KAAK;AAC1B,EAAAA,SAAQ,QAAQ,eAAa;AAC3B,UAAM,eAAe,UAAU,MAAM;AACrC,QAAI,aAAa,QAAQ,GAAG,MAAM,GAAG;AACnC,WAAK,MAAM,OAAO,cAAc,GAAG,YAAY,QAAQ;AACvD,gBAAU,MAAM,OAAO,GAAG,YAAY;AAAA,IACxC;AAAA,EACF,CAAC;AACH;;;ACHe,SAAR,cAA+B;AACpC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,kBAAkB,EAAE,SAAS,GAAG,YAAY;AAC1C,UAAI,SAAS,SAAS,IAAI,KAAK,SAAS,SAAS,KAAK,GAAG;AACvD,mBAAW,QAAQ,KAAK,YAAY;AAAA,MACtC;AACA,iBAAW,QAAQ,KAAK,KAAK;AAAA,IAC/B;AAAA,IACA,SAAS;AAAA,MACP,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,aAAa;AAAA,MACb,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;","names":["t","t","value","t","t","imports"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const one = 1;\nexport const two = 2;\n"],"mappings":";AAAO,IAAM,MAAM;AACZ,IAAM,MAAM;","names":[]}
package/package.json CHANGED
@@ -1,43 +1,63 @@
1
1
  {
2
2
  "name": "babel-plugin-essor",
3
- "version": "0.0.5-beta.4",
4
- "packageManager": "pnpm@8.15.6",
5
- "description": "",
6
3
  "type": "module",
7
- "keywords": [],
8
- "license": "MIT",
4
+ "version": "0.0.5",
5
+ "packageManager": "pnpm@7.2.1",
6
+ "description": "",
9
7
  "author": "jiangxd <jiangxd2016@gmail.com>",
10
- "files": [
11
- "dist"
12
- ],
13
- "main": "./dist/index.js",
14
- "module": "./dist/index.js",
15
- "types": "./dist/index.d.ts",
8
+ "license": "MIT",
9
+ "funding": "https://github.com/sponsors/estjs",
10
+ "homepage": "https://github.com/estjs/vipassana#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/estjs/vipassana.git"
14
+ },
15
+ "bugs": "https://github.com/estjs/vipassana/issues",
16
+ "keywords": [],
17
+ "sideEffects": false,
16
18
  "exports": {
17
19
  ".": {
18
20
  "types": "./dist/index.d.ts",
19
- "require": "./dist/index.cjs",
20
- "import": "./dist/index.js"
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.cjs"
21
23
  }
22
24
  },
25
+ "main": "./dist/index.mjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts",
23
28
  "typesVersions": {
24
29
  "*": {
25
30
  "*": [
31
+ "./dist/*",
26
32
  "./dist/index.d.ts"
27
33
  ]
28
34
  }
29
35
  },
30
- "sideEffects": false,
31
- "peerDependencies": {
32
- "@babel/core": "^7.24.3",
33
- "@babel/types": "^7.24.0"
34
- },
36
+ "files": [
37
+ "dist"
38
+ ],
35
39
  "devDependencies": {
36
- "@types/babel__core": "^7.20.5",
37
- "typescript": "^5.4.4"
40
+ "@estjs/eslint-config": "^0.6.7",
41
+ "@vitest/coverage-v8": "^0.34.2",
42
+ "bumpp": "^9.1.0",
43
+ "dayjs": "^1.11.7",
44
+ "eslint": "^8.38.0",
45
+ "pnpm": "^8.2.0",
46
+ "tsup": "^6.7.0",
47
+ "typescript": "^5.0.4",
48
+ "vitest": "^0.30.1"
38
49
  },
39
50
  "scripts": {
51
+ "dev": "tsup --watch",
40
52
  "build": "tsup",
41
- "dev": "cross-env BUILD_ENV=production tsup --watch"
53
+ "lint": "eslint --cache --fix \"./src/*.{ts,tsx,js,vue}\"",
54
+ "test": "vitest -r test",
55
+ "play": "pnpm run -C playground dev",
56
+ "play:build": "pnpm run -C playground build",
57
+ "play:test": "pnpm run -C playground test -u",
58
+ "play:preview": "pnpm run -C playground preview",
59
+ "typecheck": "tsc --noEmit",
60
+ "coverage": "vitest run --coverage",
61
+ "release": " pnpm publish --access public"
42
62
  }
43
63
  }
package/dist/index.d.cts DELETED
@@ -1,5 +0,0 @@
1
- import { PluginObj } from '@babel/core';
2
-
3
- declare function export_default(): PluginObj;
4
-
5
- export { export_default as default };