@pandacss/parser 0.0.0-dev-20230620140733 → 0.0.0-dev-20230621062854
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 +107 -1
- package/dist/index.mjs +97 -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,89 @@ 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
|
+
console.log(parsed);
|
|
420
|
+
const fileStr = new import_magic_string.default(code);
|
|
421
|
+
parsed.descriptor.template.ast.children.forEach((node) => {
|
|
422
|
+
if (node.type === NodeTypes.ELEMENT) {
|
|
423
|
+
node.props.forEach((prop) => {
|
|
424
|
+
if (prop.type === NodeTypes.DIRECTIVE && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
425
|
+
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
const templateStart = code.indexOf("<template");
|
|
431
|
+
const templateEnd = code.indexOf("</template>") + "</template>".length;
|
|
432
|
+
const scriptContent = (parsed.descriptor.scriptSetup ?? parsed.descriptor.script)?.content + "\n";
|
|
433
|
+
const transformed = new import_magic_string.default(
|
|
434
|
+
`${scriptContent}
|
|
435
|
+
const render = ${fileStr.snip(templateStart, templateEnd).toString()}`
|
|
436
|
+
);
|
|
437
|
+
return transformed.toString();
|
|
438
|
+
} catch (err) {
|
|
439
|
+
return "";
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// src/svelte-to-tsx.ts
|
|
444
|
+
var svelte = __toESM(require("svelte/compiler"));
|
|
445
|
+
var import_magic_string2 = __toESM(require("magic-string"));
|
|
446
|
+
var svelteToTsx = (code) => {
|
|
447
|
+
try {
|
|
448
|
+
const parsed = svelte.parse(code);
|
|
449
|
+
const fileStr = new import_magic_string2.default(code);
|
|
450
|
+
if (parsed.instance && parsed.instance.content) {
|
|
451
|
+
const content = parsed.instance.content;
|
|
452
|
+
fileStr.update(parsed.instance.start, parsed.instance.end, code.slice(content.start, content.end));
|
|
453
|
+
}
|
|
454
|
+
const moduleContext = parsed.module ? fileStr.snip(parsed.module.start, parsed.module.end) : "";
|
|
455
|
+
const scriptContent = parsed.instance ? fileStr.snip(parsed.instance.start, parsed.instance.end) : "";
|
|
456
|
+
const templateContent = parsed.html.children?.map((child) => fileStr.snip(child.start, child.end)).join("").trimStart() ?? "";
|
|
457
|
+
const transformed = new import_magic_string2.default(
|
|
458
|
+
`${moduleContext + "\n"}${scriptContent + "\n"}
|
|
459
|
+
const render = <div>${templateContent}</div>`
|
|
460
|
+
);
|
|
461
|
+
return transformed.toString().trim();
|
|
462
|
+
} catch (err) {
|
|
463
|
+
return "";
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
374
467
|
// src/project.ts
|
|
375
468
|
var createTsProject = (options) => new import_ts_morph2.Project({
|
|
376
469
|
skipAddingFilesFromTsConfig: true,
|
|
@@ -416,6 +509,10 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
416
509
|
if (!sourceFile)
|
|
417
510
|
return;
|
|
418
511
|
const content = sourceFile.getText();
|
|
512
|
+
const transformed = transformFile(filePath, content);
|
|
513
|
+
if (content !== transformed) {
|
|
514
|
+
sourceFile.replaceWithText(transformed);
|
|
515
|
+
}
|
|
419
516
|
hooks.callHook("parser:before", filePath, content);
|
|
420
517
|
const result = parser(sourceFile)?.setFilePath(filePath);
|
|
421
518
|
hooks.callHook("parser:after", filePath, result);
|
|
@@ -440,6 +537,15 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
440
537
|
})),
|
|
441
538
|
import_lil_fp.Obj.omit(["project", "parser"])
|
|
442
539
|
);
|
|
540
|
+
var transformFile = (filePath, content) => {
|
|
541
|
+
if (filePath.endsWith(".vue")) {
|
|
542
|
+
return vueToTsx(content);
|
|
543
|
+
}
|
|
544
|
+
if (filePath.endsWith(".svelte")) {
|
|
545
|
+
return svelteToTsx(content);
|
|
546
|
+
}
|
|
547
|
+
return content;
|
|
548
|
+
};
|
|
443
549
|
// Annotate the CommonJS export names for ESM import in node:
|
|
444
550
|
0 && (module.exports = {
|
|
445
551
|
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,89 @@ 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
|
+
console.log(parsed);
|
|
382
|
+
const fileStr = new MagicString(code);
|
|
383
|
+
parsed.descriptor.template.ast.children.forEach((node) => {
|
|
384
|
+
if (node.type === NodeTypes.ELEMENT) {
|
|
385
|
+
node.props.forEach((prop) => {
|
|
386
|
+
if (prop.type === NodeTypes.DIRECTIVE && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
387
|
+
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
const templateStart = code.indexOf("<template");
|
|
393
|
+
const templateEnd = code.indexOf("</template>") + "</template>".length;
|
|
394
|
+
const scriptContent = (parsed.descriptor.scriptSetup ?? parsed.descriptor.script)?.content + "\n";
|
|
395
|
+
const transformed = new MagicString(
|
|
396
|
+
`${scriptContent}
|
|
397
|
+
const render = ${fileStr.snip(templateStart, templateEnd).toString()}`
|
|
398
|
+
);
|
|
399
|
+
return transformed.toString();
|
|
400
|
+
} catch (err) {
|
|
401
|
+
return "";
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// src/svelte-to-tsx.ts
|
|
406
|
+
import * as svelte from "svelte/compiler";
|
|
407
|
+
import MagicString2 from "magic-string";
|
|
408
|
+
var svelteToTsx = (code) => {
|
|
409
|
+
try {
|
|
410
|
+
const parsed = svelte.parse(code);
|
|
411
|
+
const fileStr = new MagicString2(code);
|
|
412
|
+
if (parsed.instance && parsed.instance.content) {
|
|
413
|
+
const content = parsed.instance.content;
|
|
414
|
+
fileStr.update(parsed.instance.start, parsed.instance.end, code.slice(content.start, content.end));
|
|
415
|
+
}
|
|
416
|
+
const moduleContext = parsed.module ? fileStr.snip(parsed.module.start, parsed.module.end) : "";
|
|
417
|
+
const scriptContent = parsed.instance ? fileStr.snip(parsed.instance.start, parsed.instance.end) : "";
|
|
418
|
+
const templateContent = parsed.html.children?.map((child) => fileStr.snip(child.start, child.end)).join("").trimStart() ?? "";
|
|
419
|
+
const transformed = new MagicString2(
|
|
420
|
+
`${moduleContext + "\n"}${scriptContent + "\n"}
|
|
421
|
+
const render = <div>${templateContent}</div>`
|
|
422
|
+
);
|
|
423
|
+
return transformed.toString().trim();
|
|
424
|
+
} catch (err) {
|
|
425
|
+
return "";
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
346
429
|
// src/project.ts
|
|
347
430
|
var createTsProject = (options) => new TsProject({
|
|
348
431
|
skipAddingFilesFromTsConfig: true,
|
|
@@ -388,6 +471,10 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
388
471
|
if (!sourceFile)
|
|
389
472
|
return;
|
|
390
473
|
const content = sourceFile.getText();
|
|
474
|
+
const transformed = transformFile(filePath, content);
|
|
475
|
+
if (content !== transformed) {
|
|
476
|
+
sourceFile.replaceWithText(transformed);
|
|
477
|
+
}
|
|
391
478
|
hooks.callHook("parser:before", filePath, content);
|
|
392
479
|
const result = parser(sourceFile)?.setFilePath(filePath);
|
|
393
480
|
hooks.callHook("parser:after", filePath, result);
|
|
@@ -412,6 +499,15 @@ var createProject = ({ getFiles, readFile, parserOptions, hooks, ...projectOptio
|
|
|
412
499
|
})),
|
|
413
500
|
Obj.omit(["project", "parser"])
|
|
414
501
|
);
|
|
502
|
+
var transformFile = (filePath, content) => {
|
|
503
|
+
if (filePath.endsWith(".vue")) {
|
|
504
|
+
return vueToTsx(content);
|
|
505
|
+
}
|
|
506
|
+
if (filePath.endsWith(".svelte")) {
|
|
507
|
+
return svelteToTsx(content);
|
|
508
|
+
}
|
|
509
|
+
return content;
|
|
510
|
+
};
|
|
415
511
|
export {
|
|
416
512
|
ParserResult,
|
|
417
513
|
createParserResult,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20230621062854",
|
|
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.0.0-dev-
|
|
18
|
-
"@pandacss/is-valid-prop": "0.0.0-dev-
|
|
19
|
-
"@pandacss/
|
|
20
|
-
"@pandacss/
|
|
21
|
-
"@pandacss/
|
|
20
|
+
"@pandacss/extractor": "0.0.0-dev-20230621062854",
|
|
21
|
+
"@pandacss/is-valid-prop": "0.0.0-dev-20230621062854",
|
|
22
|
+
"@pandacss/shared": "0.0.0-dev-20230621062854",
|
|
23
|
+
"@pandacss/types": "0.0.0-dev-20230621062854",
|
|
24
|
+
"@pandacss/logger": "0.0.0-dev-20230621062854"
|
|
22
25
|
},
|
|
23
26
|
"devDependencies": {
|
|
24
27
|
"hookable": "5.5.3",
|
|
25
|
-
"@pandacss/fixture": "0.0.0-dev-
|
|
26
|
-
"@pandacss/generator": "0.0.0-dev-
|
|
28
|
+
"@pandacss/fixture": "0.0.0-dev-20230621062854",
|
|
29
|
+
"@pandacss/generator": "0.0.0-dev-20230621062854"
|
|
27
30
|
},
|
|
28
31
|
"files": [
|
|
29
32
|
"dist"
|