@pandacss/parser 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +106 -1
- package/dist/index.mjs +96 -1
- package/package.json +11 -8
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -194,7 +204,7 @@ function createParser(options) {
|
|
|
194
204
|
if (jsx) {
|
|
195
205
|
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.name)]));
|
|
196
206
|
}
|
|
197
|
-
return function
|
|
207
|
+
return function parse3(sourceFile) {
|
|
198
208
|
if (!sourceFile)
|
|
199
209
|
return;
|
|
200
210
|
const filePath = sourceFile.getFilePath();
|
|
@@ -371,6 +381,88 @@ function createParser(options) {
|
|
|
371
381
|
}
|
|
372
382
|
var isUpperCase = (value) => value[0] === value[0]?.toUpperCase();
|
|
373
383
|
|
|
384
|
+
// src/vue-to-tsx.ts
|
|
385
|
+
var import_compiler_sfc = require("@vue/compiler-sfc");
|
|
386
|
+
var import_magic_string = __toESM(require("magic-string"));
|
|
387
|
+
var NodeTypes = {
|
|
388
|
+
ROOT: 0,
|
|
389
|
+
ELEMENT: 1,
|
|
390
|
+
TEXT: 2,
|
|
391
|
+
COMMENT: 3,
|
|
392
|
+
SIMPLE_EXPRESSION: 4,
|
|
393
|
+
INTERPOLATION: 5,
|
|
394
|
+
ATTRIBUTE: 6,
|
|
395
|
+
DIRECTIVE: 7,
|
|
396
|
+
COMPOUND_EXPRESSION: 8,
|
|
397
|
+
IF: 9,
|
|
398
|
+
IF_BRANCH: 10,
|
|
399
|
+
FOR: 11,
|
|
400
|
+
TEXT_CALL: 12,
|
|
401
|
+
VNODE_CALL: 13,
|
|
402
|
+
JS_CALL_EXPRESSION: 14,
|
|
403
|
+
JS_OBJECT_EXPRESSION: 15,
|
|
404
|
+
JS_PROPERTY: 16,
|
|
405
|
+
JS_ARRAY_EXPRESSION: 17,
|
|
406
|
+
JS_FUNCTION_EXPRESSION: 18,
|
|
407
|
+
JS_CONDITIONAL_EXPRESSION: 19,
|
|
408
|
+
JS_CACHE_EXPRESSION: 20,
|
|
409
|
+
JS_BLOCK_STATEMENT: 21,
|
|
410
|
+
JS_TEMPLATE_LITERAL: 22,
|
|
411
|
+
JS_IF_STATEMENT: 23,
|
|
412
|
+
JS_ASSIGNMENT_EXPRESSION: 24,
|
|
413
|
+
JS_SEQUENCE_EXPRESSION: 25,
|
|
414
|
+
JS_RETURN_STATEMENT: 26
|
|
415
|
+
};
|
|
416
|
+
var vueToTsx = (code) => {
|
|
417
|
+
try {
|
|
418
|
+
const parsed = (0, import_compiler_sfc.parse)(code);
|
|
419
|
+
const fileStr = new import_magic_string.default(code);
|
|
420
|
+
parsed.descriptor.template.ast.children.forEach((node) => {
|
|
421
|
+
if (node.type === NodeTypes.ELEMENT) {
|
|
422
|
+
node.props.forEach((prop) => {
|
|
423
|
+
if (prop.type === NodeTypes.DIRECTIVE && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
424
|
+
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
const templateStart = code.indexOf("<template");
|
|
430
|
+
const templateEnd = code.indexOf("</template>") + "</template>".length;
|
|
431
|
+
const scriptContent = (parsed.descriptor.scriptSetup ?? parsed.descriptor.script)?.content + "\n";
|
|
432
|
+
const transformed = new import_magic_string.default(
|
|
433
|
+
`${scriptContent}
|
|
434
|
+
const render = ${fileStr.snip(templateStart, templateEnd).toString()}`
|
|
435
|
+
);
|
|
436
|
+
return transformed.toString();
|
|
437
|
+
} catch (err) {
|
|
438
|
+
return "";
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// src/svelte-to-tsx.ts
|
|
443
|
+
var svelte = __toESM(require("svelte/compiler"));
|
|
444
|
+
var import_magic_string2 = __toESM(require("magic-string"));
|
|
445
|
+
var svelteToTsx = (code) => {
|
|
446
|
+
try {
|
|
447
|
+
const parsed = svelte.parse(code);
|
|
448
|
+
const fileStr = new import_magic_string2.default(code);
|
|
449
|
+
if (parsed.instance && parsed.instance.content) {
|
|
450
|
+
const content = parsed.instance.content;
|
|
451
|
+
fileStr.update(parsed.instance.start, parsed.instance.end, code.slice(content.start, content.end));
|
|
452
|
+
}
|
|
453
|
+
const moduleContext = parsed.module ? fileStr.snip(parsed.module.start, parsed.module.end) : "";
|
|
454
|
+
const scriptContent = parsed.instance ? fileStr.snip(parsed.instance.start, parsed.instance.end) : "";
|
|
455
|
+
const templateContent = parsed.html.children?.map((child) => fileStr.snip(child.start, child.end)).join("").trimStart() ?? "";
|
|
456
|
+
const transformed = new import_magic_string2.default(
|
|
457
|
+
`${moduleContext + "\n"}${scriptContent + "\n"}
|
|
458
|
+
const render = <div>${templateContent}</div>`
|
|
459
|
+
);
|
|
460
|
+
return transformed.toString().trim();
|
|
461
|
+
} catch (err) {
|
|
462
|
+
return "";
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
374
466
|
// src/project.ts
|
|
375
467
|
var createTsProject = (options) => new import_ts_morph2.Project({
|
|
376
468
|
skipAddingFilesFromTsConfig: true,
|
|
@@ -416,6 +508,10 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
416
508
|
if (!sourceFile)
|
|
417
509
|
return;
|
|
418
510
|
const content = sourceFile.getText();
|
|
511
|
+
const transformed = transformFile(filePath, content);
|
|
512
|
+
if (content !== transformed) {
|
|
513
|
+
sourceFile.replaceWithText(transformed);
|
|
514
|
+
}
|
|
419
515
|
hooks.callHook("parser:before", filePath, content);
|
|
420
516
|
const result = parser(sourceFile)?.setFilePath(filePath);
|
|
421
517
|
hooks.callHook("parser:after", filePath, result);
|
|
@@ -440,6 +536,15 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
440
536
|
})),
|
|
441
537
|
import_lil_fp.Obj.omit(["project", "parser"])
|
|
442
538
|
);
|
|
539
|
+
var transformFile = (filePath, content) => {
|
|
540
|
+
if (filePath.endsWith(".vue")) {
|
|
541
|
+
return vueToTsx(content);
|
|
542
|
+
}
|
|
543
|
+
if (filePath.endsWith(".svelte")) {
|
|
544
|
+
return svelteToTsx(content);
|
|
545
|
+
}
|
|
546
|
+
return content;
|
|
547
|
+
};
|
|
443
548
|
// Annotate the CommonJS export names for ESM import in node:
|
|
444
549
|
0 && (module.exports = {
|
|
445
550
|
ParserResult,
|
package/dist/index.mjs
CHANGED
|
@@ -166,7 +166,7 @@ function createParser(options) {
|
|
|
166
166
|
if (jsx) {
|
|
167
167
|
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.name)]));
|
|
168
168
|
}
|
|
169
|
-
return function
|
|
169
|
+
return function parse3(sourceFile) {
|
|
170
170
|
if (!sourceFile)
|
|
171
171
|
return;
|
|
172
172
|
const filePath = sourceFile.getFilePath();
|
|
@@ -343,6 +343,88 @@ function createParser(options) {
|
|
|
343
343
|
}
|
|
344
344
|
var isUpperCase = (value) => value[0] === value[0]?.toUpperCase();
|
|
345
345
|
|
|
346
|
+
// src/vue-to-tsx.ts
|
|
347
|
+
import { parse } from "@vue/compiler-sfc";
|
|
348
|
+
import MagicString from "magic-string";
|
|
349
|
+
var NodeTypes = {
|
|
350
|
+
ROOT: 0,
|
|
351
|
+
ELEMENT: 1,
|
|
352
|
+
TEXT: 2,
|
|
353
|
+
COMMENT: 3,
|
|
354
|
+
SIMPLE_EXPRESSION: 4,
|
|
355
|
+
INTERPOLATION: 5,
|
|
356
|
+
ATTRIBUTE: 6,
|
|
357
|
+
DIRECTIVE: 7,
|
|
358
|
+
COMPOUND_EXPRESSION: 8,
|
|
359
|
+
IF: 9,
|
|
360
|
+
IF_BRANCH: 10,
|
|
361
|
+
FOR: 11,
|
|
362
|
+
TEXT_CALL: 12,
|
|
363
|
+
VNODE_CALL: 13,
|
|
364
|
+
JS_CALL_EXPRESSION: 14,
|
|
365
|
+
JS_OBJECT_EXPRESSION: 15,
|
|
366
|
+
JS_PROPERTY: 16,
|
|
367
|
+
JS_ARRAY_EXPRESSION: 17,
|
|
368
|
+
JS_FUNCTION_EXPRESSION: 18,
|
|
369
|
+
JS_CONDITIONAL_EXPRESSION: 19,
|
|
370
|
+
JS_CACHE_EXPRESSION: 20,
|
|
371
|
+
JS_BLOCK_STATEMENT: 21,
|
|
372
|
+
JS_TEMPLATE_LITERAL: 22,
|
|
373
|
+
JS_IF_STATEMENT: 23,
|
|
374
|
+
JS_ASSIGNMENT_EXPRESSION: 24,
|
|
375
|
+
JS_SEQUENCE_EXPRESSION: 25,
|
|
376
|
+
JS_RETURN_STATEMENT: 26
|
|
377
|
+
};
|
|
378
|
+
var vueToTsx = (code) => {
|
|
379
|
+
try {
|
|
380
|
+
const parsed = parse(code);
|
|
381
|
+
const fileStr = new MagicString(code);
|
|
382
|
+
parsed.descriptor.template.ast.children.forEach((node) => {
|
|
383
|
+
if (node.type === NodeTypes.ELEMENT) {
|
|
384
|
+
node.props.forEach((prop) => {
|
|
385
|
+
if (prop.type === NodeTypes.DIRECTIVE && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
386
|
+
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
const templateStart = code.indexOf("<template");
|
|
392
|
+
const templateEnd = code.indexOf("</template>") + "</template>".length;
|
|
393
|
+
const scriptContent = (parsed.descriptor.scriptSetup ?? parsed.descriptor.script)?.content + "\n";
|
|
394
|
+
const transformed = new MagicString(
|
|
395
|
+
`${scriptContent}
|
|
396
|
+
const render = ${fileStr.snip(templateStart, templateEnd).toString()}`
|
|
397
|
+
);
|
|
398
|
+
return transformed.toString();
|
|
399
|
+
} catch (err) {
|
|
400
|
+
return "";
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// src/svelte-to-tsx.ts
|
|
405
|
+
import * as svelte from "svelte/compiler";
|
|
406
|
+
import MagicString2 from "magic-string";
|
|
407
|
+
var svelteToTsx = (code) => {
|
|
408
|
+
try {
|
|
409
|
+
const parsed = svelte.parse(code);
|
|
410
|
+
const fileStr = new MagicString2(code);
|
|
411
|
+
if (parsed.instance && parsed.instance.content) {
|
|
412
|
+
const content = parsed.instance.content;
|
|
413
|
+
fileStr.update(parsed.instance.start, parsed.instance.end, code.slice(content.start, content.end));
|
|
414
|
+
}
|
|
415
|
+
const moduleContext = parsed.module ? fileStr.snip(parsed.module.start, parsed.module.end) : "";
|
|
416
|
+
const scriptContent = parsed.instance ? fileStr.snip(parsed.instance.start, parsed.instance.end) : "";
|
|
417
|
+
const templateContent = parsed.html.children?.map((child) => fileStr.snip(child.start, child.end)).join("").trimStart() ?? "";
|
|
418
|
+
const transformed = new MagicString2(
|
|
419
|
+
`${moduleContext + "\n"}${scriptContent + "\n"}
|
|
420
|
+
const render = <div>${templateContent}</div>`
|
|
421
|
+
);
|
|
422
|
+
return transformed.toString().trim();
|
|
423
|
+
} catch (err) {
|
|
424
|
+
return "";
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
346
428
|
// src/project.ts
|
|
347
429
|
var createTsProject = (options) => new TsProject({
|
|
348
430
|
skipAddingFilesFromTsConfig: true,
|
|
@@ -388,6 +470,10 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
388
470
|
if (!sourceFile)
|
|
389
471
|
return;
|
|
390
472
|
const content = sourceFile.getText();
|
|
473
|
+
const transformed = transformFile(filePath, content);
|
|
474
|
+
if (content !== transformed) {
|
|
475
|
+
sourceFile.replaceWithText(transformed);
|
|
476
|
+
}
|
|
391
477
|
hooks.callHook("parser:before", filePath, content);
|
|
392
478
|
const result = parser(sourceFile)?.setFilePath(filePath);
|
|
393
479
|
hooks.callHook("parser:after", filePath, result);
|
|
@@ -412,6 +498,15 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
412
498
|
})),
|
|
413
499
|
Obj.omit(["project", "parser"])
|
|
414
500
|
);
|
|
501
|
+
var transformFile = (filePath, content) => {
|
|
502
|
+
if (filePath.endsWith(".vue")) {
|
|
503
|
+
return vueToTsx(content);
|
|
504
|
+
}
|
|
505
|
+
if (filePath.endsWith(".svelte")) {
|
|
506
|
+
return svelteToTsx(content);
|
|
507
|
+
}
|
|
508
|
+
return content;
|
|
509
|
+
};
|
|
415
510
|
export {
|
|
416
511
|
ParserResult,
|
|
417
512
|
createParserResult,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The static parser for panda css",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -11,19 +11,22 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@vue/compiler-sfc": "^3.3.4",
|
|
14
15
|
"lil-fp": "1.4.5",
|
|
16
|
+
"magic-string": "^0.30.0",
|
|
17
|
+
"svelte": "^3.59.1",
|
|
15
18
|
"ts-morph": "18.0.0",
|
|
16
19
|
"ts-pattern": "4.3.0",
|
|
17
|
-
"@pandacss/extractor": "0.
|
|
18
|
-
"@pandacss/
|
|
19
|
-
"@pandacss/
|
|
20
|
-
"@pandacss/shared": "0.
|
|
21
|
-
"@pandacss/types": "0.
|
|
20
|
+
"@pandacss/extractor": "0.4.0",
|
|
21
|
+
"@pandacss/logger": "0.4.0",
|
|
22
|
+
"@pandacss/is-valid-prop": "0.4.0",
|
|
23
|
+
"@pandacss/shared": "0.4.0",
|
|
24
|
+
"@pandacss/types": "0.4.0"
|
|
22
25
|
},
|
|
23
26
|
"devDependencies": {
|
|
24
27
|
"hookable": "5.5.3",
|
|
25
|
-
"@pandacss/fixture": "0.
|
|
26
|
-
"@pandacss/generator": "0.
|
|
28
|
+
"@pandacss/fixture": "0.4.0",
|
|
29
|
+
"@pandacss/generator": "0.4.0"
|
|
27
30
|
},
|
|
28
31
|
"files": [
|
|
29
32
|
"dist"
|