one 2.22.0 → 2.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/fork/getPathFromState.cjs +2 -1
- package/dist/cjs/fork/getPathFromState.native.cjs +4 -1
- package/dist/cjs/fork/getPathFromState.native.js +4 -1
- package/dist/cjs/fork/getPathFromState.native.js.map +1 -1
- package/dist/cjs/platform/streams.cjs +17 -0
- package/dist/cjs/platform/streams.native.cjs +19 -0
- package/dist/cjs/platform/streams.native.js +21 -0
- package/dist/cjs/platform/streams.native.js.map +1 -0
- package/dist/cjs/routeTypes.cjs +17 -0
- package/dist/cjs/routeTypes.native.cjs +19 -0
- package/dist/cjs/routeTypes.native.js +21 -0
- package/dist/cjs/routeTypes.native.js.map +1 -0
- package/dist/cjs/router/router.cjs +1 -1
- package/dist/cjs/router/router.native.cjs +1 -1
- package/dist/cjs/router/router.native.js +1 -1
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.cjs +22 -6
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.native.cjs +100 -25
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.native.js +100 -25
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/oneNativeMembers.cjs +288 -57
- package/dist/cjs/vite/plugins/oneNativeMembers.native.cjs +537 -169
- package/dist/cjs/vite/plugins/oneNativeMembers.native.js +537 -169
- package/dist/cjs/vite/plugins/oneNativeMembers.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState.mjs +2 -1
- package/dist/esm/fork/getPathFromState.mjs.map +1 -1
- package/dist/esm/fork/getPathFromState.native.js +4 -1
- package/dist/esm/fork/getPathFromState.native.js.map +1 -1
- package/dist/esm/platform/streams.mjs +0 -0
- package/dist/esm/platform/streams.native.js +0 -0
- package/dist/esm/routeTypes.mjs +0 -0
- package/dist/esm/routeTypes.native.js +0 -0
- package/dist/esm/router/router.mjs +2 -2
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +2 -2
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/vite/plugins/iosLinkSetPlugin.mjs +22 -6
- package/dist/esm/vite/plugins/iosLinkSetPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/iosLinkSetPlugin.native.js +100 -25
- package/dist/esm/vite/plugins/iosLinkSetPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/oneNativeMembers.mjs +289 -58
- package/dist/esm/vite/plugins/oneNativeMembers.mjs.map +1 -1
- package/dist/esm/vite/plugins/oneNativeMembers.native.js +538 -170
- package/dist/esm/vite/plugins/oneNativeMembers.native.js.map +1 -1
- package/ios/OneNativeSlot.swift +17 -0
- package/package.json +13 -13
- package/src/Root.tsx +1 -1
- package/src/constants.ts +1 -1
- package/src/createApp.native.tsx +1 -1
- package/src/createApp.tsx +3 -2
- package/src/fork/getPathFromState.test.ts +20 -0
- package/src/fork/getPathFromState.ts +8 -2
- package/src/headless.tsx +1 -1
- package/src/interfaces/router.ts +3 -27
- package/src/platform/file-system/classes.native.ts +6 -5
- package/src/platform/file-system/classes.ts +6 -5
- package/src/platform/streams.ts +14 -0
- package/src/routeTypes.ts +83 -0
- package/src/router/FlagsContext.ts +1 -1
- package/src/router/Route.tsx +1 -1
- package/src/router/getRoutes.ts +1 -1
- package/src/router/linkToColdRoute.test.ts +61 -1
- package/src/router/matchers.ts +1 -1
- package/src/router/router.ts +3 -8
- package/src/router/useInitializeOneRouter.ts +1 -1
- package/src/router/useViteRoutes.tsx +1 -1
- package/src/router/warmState.ts +1 -1
- package/src/types.ts +1 -1
- package/src/useMatches.ts +1 -1
- package/src/vite/one-server-only.tsx +5 -2
- package/src/vite/plugins/iosLinkSetPlugin.ts +39 -6
- package/src/vite/plugins/oneNativeMembers.ts +417 -82
- package/src/vite/types.ts +12 -51
- package/types/Root.d.ts +1 -1
- package/types/config.d.ts +1 -2
- package/types/config.d.ts.map +1 -1
- package/types/constants.d.ts +1 -1
- package/types/createApp.d.ts +3 -2
- package/types/createApp.d.ts.map +1 -1
- package/types/daemon/server.d.ts +1 -1
- package/types/fork/getPathFromState.d.ts.map +1 -1
- package/types/headless.d.ts +1 -1
- package/types/interfaces/router.d.ts +3 -19
- package/types/interfaces/router.d.ts.map +1 -1
- package/types/platform/file-system/classes.d.ts +4 -3
- package/types/platform/file-system/classes.d.ts.map +1 -1
- package/types/platform/file-system/classes.native.d.ts +4 -3
- package/types/platform/file-system/classes.native.d.ts.map +1 -1
- package/types/platform/streams.d.ts +12 -0
- package/types/platform/streams.d.ts.map +1 -0
- package/types/routeTypes.d.ts +66 -0
- package/types/routeTypes.d.ts.map +1 -0
- package/types/router/FlagsContext.d.ts +1 -1
- package/types/router/Route.d.ts +1 -1
- package/types/router/getRoutes.d.ts +1 -1
- package/types/router/matchers.d.ts +1 -1
- package/types/router/router.d.ts +1 -1
- package/types/router/router.d.ts.map +1 -1
- package/types/router/useInitializeOneRouter.d.ts +1 -1
- package/types/router/useViteRoutes.d.ts +1 -1
- package/types/router/warmState.d.ts +1 -1
- package/types/types.d.ts +1 -1
- package/types/useMatches.d.ts +1 -1
- package/types/vite/one-server-only.d.ts +5 -3
- package/types/vite/one-server-only.d.ts.map +1 -1
- package/types/vite/plugins/oneNativeMembers.d.ts +1 -1
- package/types/vite/plugins/oneNativeMembers.d.ts.map +1 -1
- package/types/vite/types.d.ts +12 -49
- package/types/vite/types.d.ts.map +1 -1
|
@@ -50,6 +50,7 @@ function analysisPlugin() {
|
|
|
50
50
|
} catch (unused) {}
|
|
51
51
|
var usage = (0, import_iosLinkSetAnalysis.emptyUsage)();
|
|
52
52
|
var rewriteMembers = (0, import_oneNativeMembers.nativeOneMembers)((0, import_path.join)((0, import_iosLinkSet.oneDirectory)(), "dist/esm/one-shared.native.js"));
|
|
53
|
+
var escapes = [];
|
|
53
54
|
return {
|
|
54
55
|
name: "one:ios-link-set",
|
|
55
56
|
transform: {
|
|
@@ -60,47 +61,51 @@ function analysisPlugin() {
|
|
|
60
61
|
if (own.some(function(dir) {
|
|
61
62
|
return file.startsWith(dir + "/");
|
|
62
63
|
})) return;
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
return rewriteMembers(code, file)
|
|
64
|
+
if ((0, import_iosLinkSetAnalysis.mightUseGroups)(code, keySet, pattern)) (0, import_iosLinkSetAnalysis.analyzeModule)(code, file, keySet, usage);
|
|
65
|
+
if (!/["'`]one["'`]/.test(code)) return;
|
|
66
|
+
return rewriteMembers(code, file, function(reason) {
|
|
67
|
+
return escapes.push(`${file}: ${reason}`);
|
|
68
|
+
});
|
|
66
69
|
}
|
|
67
70
|
},
|
|
68
71
|
generateBundle(_options, bundle) {
|
|
69
72
|
var _this = this;
|
|
70
73
|
var groups = (0, import_iosLinkSetAnalysis.groupsForUsage)(usage, catalog);
|
|
71
|
-
if ([...this.getModuleIds()].some(function(
|
|
74
|
+
if ([...this.getModuleIds()].some(function(id2) {
|
|
72
75
|
var _this_getModuleInfo;
|
|
73
|
-
return (_this_getModuleInfo = _this.getModuleInfo(
|
|
76
|
+
return (_this_getModuleInfo = _this.getModuleInfo(id2)) === null || _this_getModuleInfo === void 0 ? void 0 : _this_getModuleInfo.meta.oneDOM;
|
|
74
77
|
})) {
|
|
75
78
|
if (!groups.includes("web")) groups.push("web");
|
|
76
79
|
}
|
|
77
80
|
var frameworks = /* @__PURE__ */ new Set();
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
var scan = function scan2(code) {
|
|
82
|
+
var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;
|
|
83
|
+
try {
|
|
84
|
+
for (var _iterator3 = code.matchAll(/["'`]([A-Za-z_][A-Za-z0-9_]*)_([a-f0-9]{16})["'`]/g)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
85
|
+
var match = _step3.value;
|
|
86
|
+
if (match[2] === sdk.generation && sdkModules.has(match[1])) frameworks.add(match[1]);
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
_didIteratorError3 = true;
|
|
90
|
+
_iteratorError3 = err;
|
|
91
|
+
} finally {
|
|
84
92
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (match[2] === sdk.generation && sdkModules.has(match[1])) frameworks.add(match[1]);
|
|
93
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
94
|
+
_iterator3.return();
|
|
88
95
|
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
_didIteratorError1 = true;
|
|
91
|
-
_iteratorError1 = err;
|
|
92
96
|
} finally {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_iterator1.return();
|
|
96
|
-
}
|
|
97
|
-
} finally {
|
|
98
|
-
if (_didIteratorError1) {
|
|
99
|
-
throw _iteratorError1;
|
|
100
|
-
}
|
|
97
|
+
if (_didIteratorError3) {
|
|
98
|
+
throw _iteratorError3;
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
101
|
}
|
|
102
|
+
};
|
|
103
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
104
|
+
try {
|
|
105
|
+
for (var _iterator = Object.values(bundle)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
106
|
+
var output = _step.value;
|
|
107
|
+
if (output.type === "chunk") scan(output.code);
|
|
108
|
+
}
|
|
104
109
|
} catch (err) {
|
|
105
110
|
_didIteratorError = true;
|
|
106
111
|
_iteratorError = err;
|
|
@@ -115,6 +120,76 @@ function analysisPlugin() {
|
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
}
|
|
123
|
+
var dist = own.map(function(dir) {
|
|
124
|
+
return (0, import_path.join)(dir, "dist/esm");
|
|
125
|
+
});
|
|
126
|
+
var oneObject = dist.flatMap(function(dir) {
|
|
127
|
+
return ["one.native.js", "one-shared.native.js"].map(function(name2) {
|
|
128
|
+
return (0, import_path.join)(dir, name2);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
var entries = dist.map(function(dir) {
|
|
132
|
+
return (0, import_path.join)(dir, "index.native.js");
|
|
133
|
+
});
|
|
134
|
+
if (!escapes.length && !oneObject.some(function(id2) {
|
|
135
|
+
var _this_getModuleInfo;
|
|
136
|
+
return (_this_getModuleInfo = _this.getModuleInfo(id2)) === null || _this_getModuleInfo === void 0 ? void 0 : _this_getModuleInfo.importers.some(function(importer) {
|
|
137
|
+
return !oneObject.includes(importer) && !entries.includes(importer);
|
|
138
|
+
});
|
|
139
|
+
})) {
|
|
140
|
+
var inBundle = new Set(frameworks);
|
|
141
|
+
frameworks.clear();
|
|
142
|
+
var seen = new Set([...this.getModuleIds()].filter(function(id2) {
|
|
143
|
+
var _this_getModuleInfo;
|
|
144
|
+
return (_this_getModuleInfo = _this.getModuleInfo(id2)) === null || _this_getModuleInfo === void 0 ? void 0 : _this_getModuleInfo.isEntry;
|
|
145
|
+
}));
|
|
146
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
147
|
+
try {
|
|
148
|
+
for (var _iterator1 = seen[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
149
|
+
var id = _step1.value;
|
|
150
|
+
var info = this.getModuleInfo(id);
|
|
151
|
+
if (!info) continue;
|
|
152
|
+
if (info.code) scan(info.code);
|
|
153
|
+
for (var _i = 0, _iter = [...info.importedIds, ...info.dynamicallyImportedIds]; _i < _iter.length; _i++) {
|
|
154
|
+
var next = _iter[_i];
|
|
155
|
+
if (!oneObject.includes(next)) seen.add(next);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
_didIteratorError1 = true;
|
|
160
|
+
_iteratorError1 = err;
|
|
161
|
+
} finally {
|
|
162
|
+
try {
|
|
163
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
164
|
+
_iterator1.return();
|
|
165
|
+
}
|
|
166
|
+
} finally {
|
|
167
|
+
if (_didIteratorError1) {
|
|
168
|
+
throw _iteratorError1;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
|
173
|
+
try {
|
|
174
|
+
for (var _iterator2 = frameworks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
175
|
+
var name = _step2.value;
|
|
176
|
+
if (!inBundle.has(name)) frameworks.delete(name);
|
|
177
|
+
}
|
|
178
|
+
} catch (err) {
|
|
179
|
+
_didIteratorError2 = true;
|
|
180
|
+
_iteratorError2 = err;
|
|
181
|
+
} finally {
|
|
182
|
+
try {
|
|
183
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
184
|
+
_iterator2.return();
|
|
185
|
+
}
|
|
186
|
+
} finally {
|
|
187
|
+
if (_didIteratorError2) {
|
|
188
|
+
throw _iteratorError2;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
118
193
|
var sdkFrameworks = [...frameworks].sort();
|
|
119
194
|
var report = process.env[import_iosLinkSet.IOS_LINK_SET_REPORT_ENV];
|
|
120
195
|
if (report) (0, import_fs.writeFileSync)(report, JSON.stringify({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iosLinkSetPlugin.native.js","names":[],"sources":["cjs/vite/plugins/iosLinkSetPlugin.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar iosLinkSetPlugin_exports = {};\n__export(iosLinkSetPlugin_exports, {\n iosLinkSetPlugin: () => iosLinkSetPlugin\n});\nmodule.exports = __toCommonJS(iosLinkSetPlugin_exports);\nvar import_fs = require(\"fs\");\nvar import_path = require(\"path\");\nvar import_oneNativeMembers = require(\"./oneNativeMembers\");\nvar import_iosLinkSet = require(\"../../cli/iosLinkSet\");\nvar import_iosLinkSetAnalysis = require(\"../../cli/iosLinkSetAnalysis\");\nfunction iosLinkSetPlugin() {\n return {\n name: \"one:ios-link-set\",\n api: {\n // the analysis runs only on the production ios bundle\n vxrnNative: function vxrnNative(context) {\n return context.platform === \"ios\" && !context.dev ? analysisPlugin() : {\n name: \"one:ios-link-set\"\n };\n }\n }\n };\n}\nfunction analysisPlugin() {\n var catalog = (0, import_iosLinkSet.readCatalog)();\n var sdk = JSON.parse((0, import_fs.readFileSync)((0, import_path.join)((0, import_iosLinkSet.oneDirectory)(), \"ios-bindings/manifest.json\"), \"utf8\"));\n var sdkModules = new Set(sdk.frameworks);\n var { keys } = (0, import_iosLinkSetAnalysis.catalogNames)(catalog);\n var keySet = new Set(keys.keys());\n var pattern = (0, import_iosLinkSetAnalysis.keyPattern)(keySet);\n var own = [\n (0, import_iosLinkSet.oneDirectory)()\n ];\n try {\n own.push((0, import_fs.realpathSync)(own[0]));\n } catch (unused) {\n }\n var usage = (0, import_iosLinkSetAnalysis.emptyUsage)();\n var rewriteMembers = (0, import_oneNativeMembers.nativeOneMembers)((0, import_path.join)((0, import_iosLinkSet.oneDirectory)(), \"dist/esm/one-shared.native.js\"));\n return {\n name: \"one:ios-link-set\",\n transform: {\n order: \"pre\",\n handler(code, id) {\n var file = id.split(\"?\")[0];\n if (file.startsWith(\"\\0\") || file.startsWith(\"virtual:\")) return;\n if (own.some(function(dir) {\n return file.startsWith(dir + \"/\");\n })) return;\n if (!(0, import_iosLinkSetAnalysis.mightUseGroups)(code, keySet, pattern)) return;\n (0, import_iosLinkSetAnalysis.analyzeModule)(code, file, keySet, usage);\n return rewriteMembers(code, file);\n }\n },\n generateBundle(_options, bundle) {\n var _this = this;\n var groups = (0, import_iosLinkSetAnalysis.groupsForUsage)(usage, catalog);\n if ([\n ...this.getModuleIds()\n ].some(function(id) {\n var _this_getModuleInfo;\n return (_this_getModuleInfo = _this.getModuleInfo(id)) === null || _this_getModuleInfo === void 0 ? void 0 : _this_getModuleInfo.meta.oneDOM;\n })) {\n if (!groups.includes(\"web\")) groups.push(\"web\");\n }\n var frameworks = /* @__PURE__ */ new Set();\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = Object.values(bundle)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var output = _step.value;\n if (output.type !== \"chunk\") continue;\n var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;\n try {\n for (var _iterator1 = output.code.matchAll(/[\"'`]([A-Za-z_][A-Za-z0-9_]*)_([a-f0-9]{16})[\"'`]/g)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {\n var match = _step1.value;\n if (match[2] === sdk.generation && sdkModules.has(match[1])) frameworks.add(match[1]);\n }\n } catch (err) {\n _didIteratorError1 = true;\n _iteratorError1 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion1 && _iterator1.return != null) {\n _iterator1.return();\n }\n } finally {\n if (_didIteratorError1) {\n throw _iteratorError1;\n }\n }\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n var sdkFrameworks = [\n ...frameworks\n ].sort();\n var report = process.env[import_iosLinkSet.IOS_LINK_SET_REPORT_ENV];\n if (report) (0, import_fs.writeFileSync)(report, JSON.stringify({\n groups,\n frameworks: sdkFrameworks\n }) + \"\\n\");\n (0, import_iosLinkSet.assertLinkSet)(groups, process.env, sdkFrameworks);\n }\n };\n}\n//# sourceMappingURL=iosLinkSetPlugin.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,2BAA2B,CAAC;AAChC,SAAS,0BAA0B,EACjC,wBAAwB,iBAC1B,CAAC;AACD,OAAO,UAAU,aAAa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AM,OAAO,IAAI,cAAc,WAAW,IAAI,MAAM,EAAE,GAAG,WAAW,IAAI,MAAM,EAAE;MACtF;KACF,SAAS,KAAK;MACZ,qBAAqB;MACrB,kBAAkB;KACpB,UAAU;MACR,IAAI;OACF,IAAI,CAAC,8BAA8B,WAAW,UAAU,MAAM;QAC5D,WAAW,OAAO;OACpB;MACF,UAAU;OACR,IAAI,oBAAoB;QACtB,MAAM;OACR;MACF;KACF;IACF;GACF,SAAS,KAAK;IACZ,oBAAoB;IACpB,iBAAiB;GACnB,UAAU;IACR,IAAI;KACF,IAAI,CAAC,6BAA6B,UAAU,UAAU,MAAM;MAC1D,UAAU,OAAO;KACnB;IACF,UAAU;KACR,IAAI,mBAAmB;MACrB,MAAM;KACR;IACF;GACF;GACA,IAAI,gBAAgB,CAClB,GAAG,UACL,CAAC,CAAC,KAAK;GACP,IAAI,SAAS,QAAQ,IAAI,kBAAkB;GAC3C,IAAI,QAAQ,CAAC,GAAG,UAAU,cAAa,CAAE,QAAQ,KAAK,UAAU;IAC9D;IACA,YAAY;GACd,CAAC,IAAI,IAAI;GACT,CAAC,GAAG,kBAAkB,cAAa,CAAE,QAAQ,QAAQ,KAAK,aAAa;EACzE;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"iosLinkSetPlugin.native.js","names":[],"sources":["cjs/vite/plugins/iosLinkSetPlugin.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar iosLinkSetPlugin_exports = {};\n__export(iosLinkSetPlugin_exports, {\n iosLinkSetPlugin: () => iosLinkSetPlugin\n});\nmodule.exports = __toCommonJS(iosLinkSetPlugin_exports);\nvar import_fs = require(\"fs\");\nvar import_path = require(\"path\");\nvar import_oneNativeMembers = require(\"./oneNativeMembers\");\nvar import_iosLinkSet = require(\"../../cli/iosLinkSet\");\nvar import_iosLinkSetAnalysis = require(\"../../cli/iosLinkSetAnalysis\");\nfunction iosLinkSetPlugin() {\n return {\n name: \"one:ios-link-set\",\n api: {\n // the analysis runs only on the production ios bundle\n vxrnNative: function vxrnNative(context) {\n return context.platform === \"ios\" && !context.dev ? analysisPlugin() : {\n name: \"one:ios-link-set\"\n };\n }\n }\n };\n}\nfunction analysisPlugin() {\n var catalog = (0, import_iosLinkSet.readCatalog)();\n var sdk = JSON.parse((0, import_fs.readFileSync)((0, import_path.join)((0, import_iosLinkSet.oneDirectory)(), \"ios-bindings/manifest.json\"), \"utf8\"));\n var sdkModules = new Set(sdk.frameworks);\n var { keys } = (0, import_iosLinkSetAnalysis.catalogNames)(catalog);\n var keySet = new Set(keys.keys());\n var pattern = (0, import_iosLinkSetAnalysis.keyPattern)(keySet);\n var own = [\n (0, import_iosLinkSet.oneDirectory)()\n ];\n try {\n own.push((0, import_fs.realpathSync)(own[0]));\n } catch (unused) {\n }\n var usage = (0, import_iosLinkSetAnalysis.emptyUsage)();\n var rewriteMembers = (0, import_oneNativeMembers.nativeOneMembers)((0, import_path.join)((0, import_iosLinkSet.oneDirectory)(), \"dist/esm/one-shared.native.js\"));\n var escapes = [];\n return {\n name: \"one:ios-link-set\",\n transform: {\n order: \"pre\",\n handler(code, id) {\n var file = id.split(\"?\")[0];\n if (file.startsWith(\"\\0\") || file.startsWith(\"virtual:\")) return;\n if (own.some(function(dir) {\n return file.startsWith(dir + \"/\");\n })) return;\n if ((0, import_iosLinkSetAnalysis.mightUseGroups)(code, keySet, pattern)) (0, import_iosLinkSetAnalysis.analyzeModule)(code, file, keySet, usage);\n if (!/[\"'`]one[\"'`]/.test(code)) return;\n return rewriteMembers(code, file, function(reason) {\n return escapes.push(`${file}: ${reason}`);\n });\n }\n },\n generateBundle(_options, bundle) {\n var _this = this;\n var groups = (0, import_iosLinkSetAnalysis.groupsForUsage)(usage, catalog);\n if ([\n ...this.getModuleIds()\n ].some(function(id2) {\n var _this_getModuleInfo;\n return (_this_getModuleInfo = _this.getModuleInfo(id2)) === null || _this_getModuleInfo === void 0 ? void 0 : _this_getModuleInfo.meta.oneDOM;\n })) {\n if (!groups.includes(\"web\")) groups.push(\"web\");\n }\n var frameworks = /* @__PURE__ */ new Set();\n var scan = function scan2(code) {\n var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;\n try {\n for (var _iterator3 = code.matchAll(/[\"'`]([A-Za-z_][A-Za-z0-9_]*)_([a-f0-9]{16})[\"'`]/g)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {\n var match = _step3.value;\n if (match[2] === sdk.generation && sdkModules.has(match[1])) frameworks.add(match[1]);\n }\n } catch (err) {\n _didIteratorError3 = true;\n _iteratorError3 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion3 && _iterator3.return != null) {\n _iterator3.return();\n }\n } finally {\n if (_didIteratorError3) {\n throw _iteratorError3;\n }\n }\n }\n };\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = Object.values(bundle)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var output = _step.value;\n if (output.type === \"chunk\") scan(output.code);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n var dist = own.map(function(dir) {\n return (0, import_path.join)(dir, \"dist/esm\");\n });\n var oneObject = dist.flatMap(function(dir) {\n return [\n \"one.native.js\",\n \"one-shared.native.js\"\n ].map(function(name2) {\n return (0, import_path.join)(dir, name2);\n });\n });\n var entries = dist.map(function(dir) {\n return (0, import_path.join)(dir, \"index.native.js\");\n });\n if (!escapes.length && !oneObject.some(function(id2) {\n var _this_getModuleInfo;\n return (_this_getModuleInfo = _this.getModuleInfo(id2)) === null || _this_getModuleInfo === void 0 ? void 0 : _this_getModuleInfo.importers.some(function(importer) {\n return !oneObject.includes(importer) && !entries.includes(importer);\n });\n })) {\n var inBundle = new Set(frameworks);\n frameworks.clear();\n var seen = new Set([\n ...this.getModuleIds()\n ].filter(function(id2) {\n var _this_getModuleInfo;\n return (_this_getModuleInfo = _this.getModuleInfo(id2)) === null || _this_getModuleInfo === void 0 ? void 0 : _this_getModuleInfo.isEntry;\n }));\n var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;\n try {\n for (var _iterator1 = seen[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {\n var id = _step1.value;\n var info = this.getModuleInfo(id);\n if (!info) continue;\n if (info.code) scan(info.code);\n for (var _i = 0, _iter = [\n ...info.importedIds,\n ...info.dynamicallyImportedIds\n ]; _i < _iter.length; _i++) {\n var next = _iter[_i];\n if (!oneObject.includes(next)) seen.add(next);\n }\n }\n } catch (err) {\n _didIteratorError1 = true;\n _iteratorError1 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion1 && _iterator1.return != null) {\n _iterator1.return();\n }\n } finally {\n if (_didIteratorError1) {\n throw _iteratorError1;\n }\n }\n }\n var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;\n try {\n for (var _iterator2 = frameworks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {\n var name = _step2.value;\n if (!inBundle.has(name)) frameworks.delete(name);\n }\n } catch (err) {\n _didIteratorError2 = true;\n _iteratorError2 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion2 && _iterator2.return != null) {\n _iterator2.return();\n }\n } finally {\n if (_didIteratorError2) {\n throw _iteratorError2;\n }\n }\n }\n }\n var sdkFrameworks = [\n ...frameworks\n ].sort();\n var report = process.env[import_iosLinkSet.IOS_LINK_SET_REPORT_ENV];\n if (report) (0, import_fs.writeFileSync)(report, JSON.stringify({\n groups,\n frameworks: sdkFrameworks\n }) + \"\\n\");\n (0, import_iosLinkSet.assertLinkSet)(groups, process.env, sdkFrameworks);\n }\n };\n}\n//# sourceMappingURL=iosLinkSetPlugin.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,2BAA2B,CAAC;AAChC,SAAS,0BAA0B,EACjC,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O,SAAS,CAAC,GAAG,QAAQ,EAAE,8BAA8B,SAAS,WAAW,KAAK,EAAC,CAAE,OAAO,6BAA6B,MAAM;MACjK,IAAI,OAAO,OAAO;MAClB,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG,WAAW,OAAO,IAAI;KACjD;IACF,SAAS,KAAK;KACZ,qBAAqB;KACrB,kBAAkB;IACpB,UAAU;KACR,IAAI;MACF,IAAI,CAAC,8BAA8B,WAAW,UAAU,MAAM;OAC5D,WAAW,OAAO;MACpB;KACF,UAAU;MACR,IAAI,oBAAoB;OACtB,MAAM;MACR;KACF;IACF;GACF;GACA,IAAI,gBAAgB,CAClB,GAAG,UACL,CAAC,CAAC,KAAK;GACP,IAAI,SAAS,QAAQ,IAAI,kBAAkB;GAC3C,IAAI,QAAQ,CAAC,GAAG,UAAU,cAAa,CAAE,QAAQ,KAAK,UAAU;IAC9D;IACA,YAAY;GACd,CAAC,IAAI,IAAI;GACT,CAAC,GAAG,kBAAkB,cAAa,CAAE,QAAQ,QAAQ,KAAK,aAAa;EACzE;CACF;AACF"}
|
|
@@ -32,42 +32,168 @@ var import_node_fs = require("node:fs");
|
|
|
32
32
|
var import_node_path = require("node:path");
|
|
33
33
|
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
34
34
|
var import_oxc_parser = require("oxc-parser");
|
|
35
|
-
function nativeOneMembers(file) {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
function nativeOneMembers(file, platform = "ios") {
|
|
36
|
+
const modules = /* @__PURE__ */ new Map();
|
|
37
|
+
const load = (path) => {
|
|
38
|
+
if (modules.has(path)) return modules.get(path);
|
|
39
|
+
let code;
|
|
40
|
+
try {
|
|
41
|
+
code = (0, import_node_fs.readFileSync)(path, "utf8");
|
|
42
|
+
} catch {
|
|
43
|
+
modules.set(path, void 0);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const module2 = {
|
|
47
|
+
path,
|
|
48
|
+
imports: /* @__PURE__ */ new Map(),
|
|
49
|
+
values: /* @__PURE__ */ new Map(),
|
|
50
|
+
exports: /* @__PURE__ */ new Map(),
|
|
51
|
+
reexports: /* @__PURE__ */ new Map(),
|
|
52
|
+
stars: []
|
|
53
|
+
};
|
|
54
|
+
modules.set(path, module2);
|
|
55
|
+
const from = (specifier) => {
|
|
56
|
+
if (!specifier.startsWith(".")) return specifier;
|
|
57
|
+
const base = (0, import_node_path.resolve)((0, import_node_path.dirname)(path), specifier);
|
|
58
|
+
return [
|
|
59
|
+
"",
|
|
60
|
+
`.${platform}.js`,
|
|
61
|
+
".native.js",
|
|
62
|
+
".js",
|
|
63
|
+
`/index.${platform}.js`,
|
|
64
|
+
"/index.native.js",
|
|
65
|
+
"/index.js"
|
|
66
|
+
].map((suffix) => base + suffix).find((candidate) => (0, import_node_fs.statSync)(candidate, { throwIfNoEntry: false })?.isFile()) ?? base;
|
|
67
|
+
};
|
|
68
|
+
const name = (node) => String(node.name ?? node.value);
|
|
69
|
+
for (const statement of (0, import_oxc_parser.parseSync)(path, code).program.body) {
|
|
70
|
+
if (statement.type === "ExportAllDeclaration") {
|
|
71
|
+
if (statement.exported) module2.reexports.set(name(statement.exported), {
|
|
72
|
+
source: from(statement.source.value),
|
|
73
|
+
imported: "*"
|
|
46
74
|
});
|
|
75
|
+
else module2.stars.push(from(statement.source.value));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (statement.type === "ExportNamedDeclaration") {
|
|
79
|
+
for (const item of statement.specifiers ?? []) {
|
|
80
|
+
if (statement.source) module2.reexports.set(name(item.exported), {
|
|
81
|
+
source: from(statement.source.value),
|
|
82
|
+
imported: name(item.local)
|
|
83
|
+
});
|
|
84
|
+
else module2.exports.set(name(item.exported), name(item.local));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const node = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
88
|
+
if (node?.type === "ImportDeclaration") {
|
|
89
|
+
for (const item of node.specifiers) {
|
|
90
|
+
module2.imports.set(item.local.name, {
|
|
91
|
+
source: from(node.source.value),
|
|
92
|
+
imported: item.type === "ImportSpecifier" ? name(item.imported) : item.type === "ImportDefaultSpecifier" ? "default" : "*"
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
} else if (node?.type === "VariableDeclaration") {
|
|
96
|
+
for (const declaration of node.declarations) if (declaration.id.type === "Identifier") {
|
|
97
|
+
if (declaration.init) module2.values.set(declaration.id.name, declaration.init);
|
|
98
|
+
if (node !== statement) module2.exports.set(declaration.id.name, declaration.id.name);
|
|
99
|
+
}
|
|
100
|
+
} else if (node && node !== statement && node.id) {
|
|
101
|
+
module2.exports.set(node.id.name, node.id.name);
|
|
47
102
|
}
|
|
48
|
-
} else if (node?.type === "VariableDeclaration") {
|
|
49
|
-
for (const declaration of node.declarations) if (declaration.id.type === "Identifier" && declaration.init) values.set(declaration.id.name, declaration.init);
|
|
50
103
|
}
|
|
51
|
-
|
|
52
|
-
|
|
104
|
+
return module2;
|
|
105
|
+
};
|
|
106
|
+
const resolveExport = (source, name, seen = /* @__PURE__ */ new Set()) => {
|
|
107
|
+
const module2 = load(source);
|
|
108
|
+
if (!module2 || seen.has(source)) return;
|
|
109
|
+
seen.add(source);
|
|
110
|
+
const here = {
|
|
111
|
+
source,
|
|
112
|
+
imported: name
|
|
113
|
+
};
|
|
114
|
+
const follow = (binding) => !load(binding.source) ? here : binding.imported === "*" ? binding : resolveExport(binding.source, binding.imported, seen) ?? here;
|
|
115
|
+
const reexport = module2.reexports.get(name);
|
|
116
|
+
if (reexport) return follow(reexport);
|
|
117
|
+
const local = module2.exports.get(name);
|
|
118
|
+
if (local !== void 0) {
|
|
119
|
+
const imported = module2.imports.get(local);
|
|
120
|
+
return imported && !module2.values.has(local) ? follow(imported) : here;
|
|
121
|
+
}
|
|
122
|
+
for (const star of module2.stars) {
|
|
123
|
+
if (!load(star)) return here;
|
|
124
|
+
const found = resolveExport(star, name, seen);
|
|
125
|
+
if (found) return found;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const bind = (imported) => !load(imported.source) ? void 0 : imported.imported === "*" ? imported : resolveExport(imported.source, imported.imported) ?? imported;
|
|
129
|
+
const descend = (binding, path, consumed) => {
|
|
130
|
+
const target = load(binding.source);
|
|
131
|
+
if (!target || !path.length) return {
|
|
132
|
+
binding,
|
|
133
|
+
consumed
|
|
134
|
+
};
|
|
135
|
+
if (binding.imported === "*") {
|
|
136
|
+
const inner = resolveExport(binding.source, path[0]);
|
|
137
|
+
return inner && descend(inner, path.slice(1), consumed + 1);
|
|
138
|
+
}
|
|
139
|
+
const value = target.values.get(target.exports.get(binding.imported) ?? "");
|
|
140
|
+
const found = value && member(target, value, path, consumed);
|
|
141
|
+
if (found) return found;
|
|
142
|
+
const object = value?.type === "CallExpression" && value.callee.property?.name === "freeze" ? value.arguments[0] : value;
|
|
143
|
+
const index = object?.type === "ObjectExpression" ? object.properties.findLastIndex((property) => property.type === "SpreadElement" || !property.computed && (property.key.name ?? property.key.value) === path[0]) : -1;
|
|
144
|
+
return index >= 0 && object.properties[index].type === "Property" ? {
|
|
145
|
+
binding,
|
|
146
|
+
consumed: consumed + 1,
|
|
147
|
+
suffix: [path[0]]
|
|
148
|
+
} : {
|
|
149
|
+
binding,
|
|
150
|
+
consumed
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
const member = (module2, expression, path, consumed = 0) => {
|
|
53
154
|
if (expression.type === "Identifier") {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
binding
|
|
155
|
+
const imported = module2.imports.get(expression.name);
|
|
156
|
+
if (imported) {
|
|
157
|
+
const binding = bind(imported);
|
|
158
|
+
return binding && descend(binding, path, consumed);
|
|
159
|
+
}
|
|
160
|
+
const value = module2.values.get(expression.name);
|
|
161
|
+
const found = value && member(module2, value, path, consumed);
|
|
162
|
+
if (found || module2.path === file) return found;
|
|
163
|
+
for (const [exported, local] of module2.exports) if (local === expression.name) return {
|
|
164
|
+
binding: {
|
|
165
|
+
source: module2.path,
|
|
166
|
+
imported: exported
|
|
167
|
+
},
|
|
57
168
|
consumed
|
|
58
169
|
};
|
|
59
|
-
|
|
60
|
-
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (expression.type === "CallExpression" && expression.callee.type === "MemberExpression" && expression.callee.object.name === "Object" && expression.callee.property.name === "freeze") return member(module2, expression.arguments[0], path, consumed);
|
|
173
|
+
if (expression.type === "MemberExpression" && !expression.computed) {
|
|
174
|
+
const found = member(module2, expression.object, [expression.property.name, ...path], consumed - 1);
|
|
175
|
+
if (!found || found.consumed >= consumed) return found;
|
|
176
|
+
if (found.call || found.consumed < consumed - 1) return;
|
|
177
|
+
return {
|
|
178
|
+
...found,
|
|
179
|
+
consumed,
|
|
180
|
+
suffix: [...found.suffix ?? [], expression.property.name]
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (expression.type === "ConditionalExpression") {
|
|
184
|
+
const test = expression.test;
|
|
185
|
+
if (test.type === "BinaryExpression" && test.left.type === "MemberExpression" && test.left.property.name === "OS" && typeof test.right.value === "string" && ["===", "!=="].includes(test.operator)) return member(module2, test.right.value === platform === (test.operator === "===") ? expression.consequent : expression.alternate, path, consumed);
|
|
186
|
+
return;
|
|
61
187
|
}
|
|
62
|
-
if (expression.type === "CallExpression" && expression.callee.type === "MemberExpression" && expression.callee.object.name === "Object" && expression.callee.property.name === "freeze") return member(expression.arguments[0], path, consumed);
|
|
63
188
|
if (expression.type !== "ObjectExpression" || !path.length) return;
|
|
64
189
|
for (const property of expression.properties.toReversed()) {
|
|
65
190
|
if (property.type === "Property" && !property.computed && (property.key.name ?? property.key.value) === path[0]) {
|
|
66
|
-
if (property.kind === "init") return member(property.value, path.slice(1), consumed + 1);
|
|
191
|
+
if (property.kind === "init") return member(module2, property.value, path.slice(1), consumed + 1);
|
|
67
192
|
const body = property.value.body.body;
|
|
68
193
|
const returned = body.length === 1 && body[0].type === "ReturnStatement" ? body[0].argument : void 0;
|
|
69
194
|
if (property.kind === "get" && returned?.type === "CallExpression" && returned.callee.type === "Identifier" && !returned.arguments.length) {
|
|
70
|
-
const
|
|
195
|
+
const imported = module2.imports.get(returned.callee.name);
|
|
196
|
+
const binding = imported && bind(imported);
|
|
71
197
|
if (binding) return {
|
|
72
198
|
binding,
|
|
73
199
|
consumed: consumed + 1,
|
|
@@ -77,24 +203,69 @@ function nativeOneMembers(file) {
|
|
|
77
203
|
return;
|
|
78
204
|
}
|
|
79
205
|
if (property.type === "SpreadElement") {
|
|
80
|
-
const found = member(property.argument, path, consumed);
|
|
81
|
-
if (found) return found;
|
|
206
|
+
const found = member(module2, property.argument, path, consumed);
|
|
207
|
+
if (found && found.consumed > consumed) return found;
|
|
82
208
|
}
|
|
83
209
|
}
|
|
84
210
|
};
|
|
85
|
-
|
|
211
|
+
const shared = load(file);
|
|
212
|
+
const one = shared.values.get("One");
|
|
213
|
+
return (source, id, escape = () => {}) => {
|
|
214
|
+
if (/\b(require|import)\s*\(\s*["'`]one["'`]\s*\)/.test(source) || /export\s*(\*(\s*as\s+[\w$]+)?|\{[^}]*\bOne\b[^}]*\})\s*from\s*["']one["']/.test(source)) escape("dynamic or re-exported one");
|
|
86
215
|
const parsed = (0, import_oxc_parser.parseSync)(id, source, { lang: /\.tsx$/.test(id) ? "tsx" : /\.[cm]?ts$/.test(id) ? "ts" : "jsx" });
|
|
87
|
-
if (parsed.errors.length)
|
|
216
|
+
if (parsed.errors.length) {
|
|
217
|
+
escape("parse error");
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
88
220
|
const app = parsed.program;
|
|
89
221
|
const roots = /* @__PURE__ */ new Map();
|
|
90
222
|
for (const node of app.body) {
|
|
91
|
-
if (node.type !== "ImportDeclaration" || node.source.value !== "one") continue;
|
|
223
|
+
if (node.type !== "ImportDeclaration" || node.source.value !== "one" || node.importKind === "type") continue;
|
|
92
224
|
for (const item of node.specifiers) {
|
|
93
|
-
if (item.type === "ImportSpecifier" && (item.imported.name ?? item.imported.value) === "One") roots.set(item.local.name,
|
|
94
|
-
|
|
225
|
+
if (item.type === "ImportSpecifier" && item.importKind !== "type" && (item.imported.name ?? item.imported.value) === "One") roots.set(item.local.name, {
|
|
226
|
+
prefix: [],
|
|
227
|
+
base: []
|
|
228
|
+
});
|
|
229
|
+
else if (item.type === "ImportNamespaceSpecifier") roots.set(item.local.name, {
|
|
230
|
+
prefix: ["One"],
|
|
231
|
+
base: []
|
|
232
|
+
});
|
|
95
233
|
}
|
|
96
234
|
}
|
|
97
235
|
if (!roots.size) return;
|
|
236
|
+
const chain = (node) => {
|
|
237
|
+
const path = [];
|
|
238
|
+
const nodes = [];
|
|
239
|
+
let root = node;
|
|
240
|
+
while (root.type === "MemberExpression" && !root.computed || root.type === "JSXMemberExpression") {
|
|
241
|
+
path.unshift(root.property.name);
|
|
242
|
+
nodes.unshift(root);
|
|
243
|
+
root = root.object;
|
|
244
|
+
}
|
|
245
|
+
const read = roots.get(root.name);
|
|
246
|
+
return {
|
|
247
|
+
root,
|
|
248
|
+
path,
|
|
249
|
+
nodes,
|
|
250
|
+
read,
|
|
251
|
+
onePath: read && read.prefix.every((name, index) => path[index] === name) ? [...read.base, ...path.slice(read.prefix.length)] : void 0
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
255
|
+
for (const statement of app.body) {
|
|
256
|
+
if (statement.type !== "VariableDeclaration" || statement.kind !== "const") continue;
|
|
257
|
+
for (const declaration of statement.declarations) {
|
|
258
|
+
if (declaration.id.type !== "Identifier" || !declaration.init) continue;
|
|
259
|
+
const { onePath } = chain(declaration.init);
|
|
260
|
+
if (!onePath?.length) continue;
|
|
261
|
+
if (member(shared, one, onePath)?.consumed === onePath.length) continue;
|
|
262
|
+
roots.set(declaration.id.name, {
|
|
263
|
+
prefix: [],
|
|
264
|
+
base: onePath
|
|
265
|
+
});
|
|
266
|
+
aliases.add(declaration);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
98
269
|
const children = (node, visit2) => {
|
|
99
270
|
for (const [key, value] of Object.entries(node)) {
|
|
100
271
|
if (key === "typeAnnotation" || key === "returnType" || key === "typeParameters" || key === "typeArguments") continue;
|
|
@@ -104,11 +275,14 @@ function nativeOneMembers(file) {
|
|
|
104
275
|
const pattern = (node) => {
|
|
105
276
|
if (node.type === "Identifier") roots.delete(node.name);
|
|
106
277
|
else if (node.type === "Property") pattern(node.value);
|
|
107
|
-
else
|
|
278
|
+
else if (node.type === "AssignmentPattern") pattern(node.left);
|
|
279
|
+
else if (node.type === "RestElement") pattern(node.argument);
|
|
280
|
+
else if (node.type === "TSParameterProperty") pattern(node.parameter);
|
|
281
|
+
else if (node.type === "ArrayPattern" || node.type === "ObjectPattern") children(node, pattern);
|
|
108
282
|
};
|
|
109
283
|
const shadows = (node) => {
|
|
110
284
|
if (node.type === "ImportDeclaration") return;
|
|
111
|
-
if (node.type === "VariableDeclarator") pattern(node.id);
|
|
285
|
+
if (node.type === "VariableDeclarator" && !aliases.has(node)) pattern(node.id);
|
|
112
286
|
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
113
287
|
if (node.id) pattern(node.id);
|
|
114
288
|
for (const parameter of node.params) pattern(parameter);
|
|
@@ -119,46 +293,103 @@ function nativeOneMembers(file) {
|
|
|
119
293
|
if (node.type === "CatchClause" && node.param) pattern(node.param);
|
|
120
294
|
children(node, shadows);
|
|
121
295
|
};
|
|
296
|
+
const imported = roots.size;
|
|
122
297
|
shadows(app);
|
|
298
|
+
if (roots.size < imported) escape("shadowed One");
|
|
123
299
|
const output = new import_magic_string.default(source);
|
|
124
300
|
const added = /* @__PURE__ */ new Map();
|
|
301
|
+
const rootOf = (node) => node.type === "MemberExpression" ? rootOf(node.object) : node;
|
|
302
|
+
const escaped = /* @__PURE__ */ new Set();
|
|
303
|
+
const kept = (name, reason) => {
|
|
304
|
+
escaped.add(name);
|
|
305
|
+
escape(reason);
|
|
306
|
+
};
|
|
307
|
+
const typeOnly = (node) => node.declare || node.type === "TSTypeAliasDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSDeclareFunction" || node.type.startsWith("TS") && node.type.endsWith("Type");
|
|
308
|
+
let rewritten = 0;
|
|
125
309
|
const visit = (node) => {
|
|
126
|
-
if (node.type === "ImportDeclaration" ||
|
|
127
|
-
if (node.type === "
|
|
128
|
-
|
|
310
|
+
if (node.type === "ImportDeclaration" || aliases.has(node) || typeOnly(node)) return;
|
|
311
|
+
if (node.type === "Identifier") {
|
|
312
|
+
if (roots.has(node.name)) kept(node.name, `One read at ${node.start}`);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if ((node.type === "Property" || node.type === "MethodDefinition" || node.type === "PropertyDefinition") && !node.computed) {
|
|
316
|
+
if (node.value) visit(node.value);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const target = node.type === "AssignmentExpression" ? node.left : node.type === "UpdateExpression" || node.type === "UnaryExpression" && node.operator === "delete" ? node.argument : void 0;
|
|
320
|
+
if (target) {
|
|
321
|
+
if (roots.has(rootOf(target).name)) kept(rootOf(target).name, `One written at ${node.start}`);
|
|
322
|
+
if (node.type === "AssignmentExpression") visit(node.right);
|
|
129
323
|
return;
|
|
130
324
|
}
|
|
131
|
-
if (node.type === "UpdateExpression" || node.type === "UnaryExpression" && node.operator === "delete") return;
|
|
132
325
|
if (node.type === "MemberExpression" || node.type === "JSXMemberExpression") {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
const prefix = roots.get(root.name);
|
|
142
|
-
if (prefix && prefix.every((name, index) => path[index] === name)) {
|
|
143
|
-
const found = member(values.get("One"), path.slice(prefix.length));
|
|
144
|
-
if (found && found.consumed && !(found.call && node.type === "JSXMemberExpression")) {
|
|
145
|
-
let alias = added.get(found.binding);
|
|
146
|
-
if (!alias) {
|
|
147
|
-
alias = `__one_member_${added.size}`;
|
|
148
|
-
while (new RegExp(`\\b${alias}\\b`).test(source)) alias += "_";
|
|
149
|
-
added.set(found.binding, alias);
|
|
150
|
-
}
|
|
151
|
-
output.overwrite(root.start, nodes[prefix.length + found.consumed - 1].end, found.call ? `(${alias}())` : alias);
|
|
326
|
+
const { root, nodes, read, onePath } = chain(node);
|
|
327
|
+
if (read) {
|
|
328
|
+
if (!onePath) return;
|
|
329
|
+
const found = member(shared, one, onePath);
|
|
330
|
+
const consumed = (found?.consumed ?? 0) - read.base.length;
|
|
331
|
+
if (!found || consumed < 1 || found.call && node.type === "JSXMemberExpression") {
|
|
332
|
+
kept(root.name, `One.${onePath.join(".")}`);
|
|
152
333
|
return;
|
|
153
334
|
}
|
|
335
|
+
const key = `${found.binding.source}\0${found.binding.imported}`;
|
|
336
|
+
let alias = added.get(key)?.alias;
|
|
337
|
+
if (!alias) {
|
|
338
|
+
alias = `__one_member_${added.size}`;
|
|
339
|
+
while (new RegExp(`\\b${alias}\\b`).test(source)) alias += "_";
|
|
340
|
+
added.set(key, {
|
|
341
|
+
binding: found.binding,
|
|
342
|
+
alias
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
rewritten++;
|
|
346
|
+
output.overwrite(root.start, nodes[read.prefix.length + consumed - 1].end, found.call ? `(${alias}())` : alias + (found.suffix ?? []).map((name) => `.${name}`).join(""));
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (nodes.length) {
|
|
350
|
+
visit(root);
|
|
351
|
+
return;
|
|
154
352
|
}
|
|
155
353
|
}
|
|
156
354
|
children(node, visit);
|
|
157
355
|
};
|
|
158
356
|
visit(app);
|
|
159
|
-
|
|
357
|
+
let references = 0;
|
|
358
|
+
const count = (node) => {
|
|
359
|
+
if (node.type === "ImportDeclaration" || aliases.has(node) || typeOnly(node)) return;
|
|
360
|
+
if (node.type === "Identifier" || node.type === "JSXIdentifier") {
|
|
361
|
+
if (roots.has(node.name)) references++;
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (node.type === "MemberExpression" || node.type === "JSXMemberExpression") {
|
|
365
|
+
count(node.object);
|
|
366
|
+
if (node.computed) count(node.property);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if ((node.type === "Property" || node.type === "MethodDefinition" || node.type === "PropertyDefinition" || node.type === "JSXAttribute") && !node.computed) {
|
|
370
|
+
if (node.value) count(node.value);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (node.type === "LabeledStatement" || node.type === "BreakStatement" || node.type === "ContinueStatement") {
|
|
374
|
+
if (node.body) count(node.body);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (node.type === "ExportSpecifier") {
|
|
378
|
+
count(node.local);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
children(node, count);
|
|
382
|
+
};
|
|
383
|
+
count(app);
|
|
384
|
+
const complete = references === rewritten && roots.size === imported;
|
|
385
|
+
if (!complete) escape("One reference left unrewritten");
|
|
386
|
+
for (const declaration of [...aliases].toReversed()) {
|
|
387
|
+
if (complete && roots.has(declaration.id.name) && !escaped.has(declaration.id.name)) output.overwrite(declaration.init.start, declaration.init.end, "void 0");
|
|
388
|
+
else escaped.add(chain(declaration.init).root.name);
|
|
389
|
+
}
|
|
390
|
+
if (!added.size && !aliases.size) return;
|
|
160
391
|
const lastImport = app.body.filter((node) => node.type === "ImportDeclaration").at(-1);
|
|
161
|
-
output.appendLeft(lastImport.end, "\n" + [...added].map((
|
|
392
|
+
output.appendLeft(lastImport.end, "\n" + [...added.values()].map(({ binding, alias }) => `import ${binding.imported === "*" ? `* as ${alias}` : `{ ${binding.imported} as ${alias} }`} from ${JSON.stringify(binding.source)};
|
|
162
393
|
`).join(""));
|
|
163
394
|
return {
|
|
164
395
|
code: output.toString(),
|