babel-plugin-vasille 0.99.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.
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.trProgram = trProgram;
27
+ const t = __importStar(require("@babel/types"));
28
+ const internal_js_1 = require("./internal.js");
29
+ const mesh_js_1 = require("./mesh.js");
30
+ const imports = new Map([["vasille-dx", "VasilleDX"], ["vasille-web", "VasilleWeb"]]);
31
+ const ignoreMembers = new Set([
32
+ "value",
33
+ "ref",
34
+ "bind",
35
+ "calculate",
36
+ "watch",
37
+ "arrayModel",
38
+ "mapModel",
39
+ "reactiveObject",
40
+ "setModel",
41
+ ]);
42
+ function extractText(node) {
43
+ return t.isIdentifier(node) ? node.name : node.value;
44
+ }
45
+ function trProgram(path, devMode) {
46
+ let id;
47
+ const internal = {
48
+ get id() {
49
+ this.internalUsed = true;
50
+ return id;
51
+ },
52
+ set id(expr) {
53
+ id = expr;
54
+ },
55
+ stack: new internal_js_1.StackedStates(),
56
+ mapping: new Map(),
57
+ global: "",
58
+ prefix: "Vasille_",
59
+ importStatement: null,
60
+ internalUsed: false,
61
+ devMode: devMode,
62
+ };
63
+ for (const statementPath of path.get("body")) {
64
+ const statement = statementPath.node;
65
+ if (t.isImportDeclaration(statement)) {
66
+ const name = imports.get(statement.source.value);
67
+ if (name) {
68
+ internal.prefix = `${name}_`;
69
+ for (const specifier of statement.specifiers) {
70
+ if (t.isImportNamespaceSpecifier(specifier)) {
71
+ internal.global = specifier.local.name;
72
+ id = t.memberExpression(t.identifier(internal.global), t.identifier("$"));
73
+ }
74
+ else if (t.isImportSpecifier(specifier)) {
75
+ const imported = extractText(specifier.imported);
76
+ const local = specifier.local.name;
77
+ internal.mapping.set(local, imported);
78
+ if (!id) {
79
+ id = t.identifier(name);
80
+ }
81
+ internal.importStatement = statementPath;
82
+ }
83
+ }
84
+ statement.specifiers = statement.specifiers.filter(spec => {
85
+ if (!t.isImportSpecifier(spec)) {
86
+ return true;
87
+ }
88
+ else {
89
+ return !ignoreMembers.has(extractText(spec.imported));
90
+ }
91
+ });
92
+ }
93
+ }
94
+ else {
95
+ if (!id) {
96
+ return;
97
+ }
98
+ (0, mesh_js_1.meshStatement)(statementPath, internal);
99
+ }
100
+ }
101
+ if (internal.internalUsed && !internal.global && internal.importStatement) {
102
+ const statementPath = internal.importStatement;
103
+ const statement = statementPath.node;
104
+ statementPath.replaceWith(t.importDeclaration([
105
+ ...statement.specifiers.filter(item => {
106
+ if (t.isImportSpecifier(item) && t.isIdentifier(item.local)) {
107
+ return statementPath.scope.bindings[item.local.name].referenced;
108
+ }
109
+ return true;
110
+ }),
111
+ t.importSpecifier(internal.id, t.identifier("$")),
112
+ ], statement.source));
113
+ }
114
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "babel-plugin-vasille",
3
+ "version": "0.99.0",
4
+ "description": "",
5
+ "main": "lib/index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ "import": "./lib/index.js",
9
+ "browser": "./lib/index.js",
10
+ "node": "./lib-node/index.js",
11
+ "require": "./lib-node/index.js"
12
+ },
13
+ "scripts": {
14
+ "prepack": "cp -f ../README.md ./README.md",
15
+ "prettier": "prettier src test/**/*.ts* --write",
16
+ "build": "tsc --build tsconfig-build.json",
17
+ "build-node": "tsc --build tsconfig-build-node.json",
18
+ "test": "jest",
19
+ "test-coverage": "jest --coverage"
20
+ },
21
+ "keywords": [
22
+ "front-end",
23
+ "framework",
24
+ "dx"
25
+ ],
26
+ "author": "lixcode",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "vasille-dx": "^3.0.1"
30
+ },
31
+ "devDependencies": {
32
+ "@babel/parser": "^7.26.1",
33
+ "@babel/plugin-syntax-jsx": "^7.25.9",
34
+ "@babel/plugin-transform-typescript": "^7.25.9",
35
+ "@babel/types": "^7.26.0",
36
+ "@types/babel__core": "^7.20.5",
37
+ "@types/jest": "^29.5.14",
38
+ "@types/jsdom": "^21.1.7",
39
+ "@types/node": "^22.8.1",
40
+ "jest": "^29.7.0",
41
+ "jsdom": "^25.0.1",
42
+ "path": "^0.12.7",
43
+ "prettier": "^3.3.3",
44
+ "ts-jest": "^29.2.5",
45
+ "typescript": "^5.6.3"
46
+ }
47
+ }