@bikky/compiler 0.1.0 → 0.1.2
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/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/Libraries/DelayLib.d.mts +34 -2
- package/Libraries/DelayLib.d.mts.map +1 -1
- package/Libraries/DelayLib.mjs +173 -11
- package/Libraries/DelayLib.mjs.map +1 -1
- package/Libraries/DelayLib.mts +219 -14
- package/Libraries/GlobalTypes.d.ts +5 -1
- package/Source/ASTBuilder.d.ts.map +1 -1
- package/Source/ASTHelper.d.ts +1 -1
- package/Source/ASTHelper.d.ts.map +1 -1
- package/Source/ASTHelper.js +22 -4
- package/Source/ASTInterface/Crawler.d.ts +8 -2
- package/Source/ASTInterface/Crawler.d.ts.map +1 -1
- package/Source/ASTInterface/Crawler.js +36 -20
- package/Source/MiscHelpers.d.ts +21 -0
- package/Source/MiscHelpers.d.ts.map +1 -0
- package/Source/MiscHelpers.js +152 -0
- package/Transformers/DelayTransformer.js +52 -0
- package/Transformers/Main.d.ts +2 -1
- package/Transformers/Main.d.ts.map +1 -1
- package/Transformers/Main.js +4 -12
- package/Transformers/ReplicableTransformer.d.ts +2 -0
- package/Transformers/ReplicableTransformer.d.ts.map +1 -0
- package/Transformers/ReplicableTransformer.js +427 -0
- package/package.json +4 -3
- package/tsconfig.build.libs.tsbuildinfo +1 -1
- package/tsconfig.build.src.tsbuildinfo +1 -1
- package/tsconfig.json +4 -5
- package/Transformers/Qdrant.d.ts +0 -18
- package/Transformers/Qdrant.d.ts.map +0 -1
- package/Transformers/Qdrant.js +0 -148
package/Libraries/DelayLib.d.mts
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export interface ChangeInformation {
|
|
2
|
+
file: string;
|
|
3
|
+
exportName: string;
|
|
4
|
+
oldValue: any;
|
|
5
|
+
newValue: any;
|
|
6
|
+
}
|
|
7
|
+
export interface FileConfig {
|
|
8
|
+
onChangeHandlers: ((info: ChangeInformation) => void)[];
|
|
9
|
+
onBeforeRequestReload: (() => void)[];
|
|
10
|
+
exportNewValue?: (newValue: any) => void;
|
|
11
|
+
oldValue: any;
|
|
12
|
+
}
|
|
13
|
+
export declare function SetupReloadHandlers(fullQueryPath: string, exportName: string, rawValue: any, assignFunction: (result: any) => void): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* When used on an exported value, it allows the value to be replaced during a hot reload.
|
|
16
|
+
* @param exportName - The name of the exported value.
|
|
17
|
+
* @param rawValue - The current value (at time of file load) of the exported value. Weirdly this value
|
|
18
|
+
* will update if the file's exported value changes.
|
|
19
|
+
* @param assignFunction - A function that assigns the exported value to the new value.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Reloadable(exportName: string, rawValue: any, assignFunction: (result: any) => void): void;
|
|
22
|
+
/**
|
|
23
|
+
* The exported placeholder class is replaced with the fully fleshed out class once the promise resolves. If a hot
|
|
24
|
+
* reload occurs, then only the delayed class once created will trigger the reload handlers.
|
|
25
|
+
* @param promise - The promise to wait on before creating the class.
|
|
26
|
+
* @param firstModule - The module containing the class to be created.
|
|
27
|
+
* @param makeClass - A function that creates the class when called.
|
|
28
|
+
* @param assignClass - A function that assigns the created class to the exported value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function DelayCreate(promise: any, firstModule: Class<any>, makeClass: () => any, assignClass: (result: any) => void): void;
|
|
31
|
+
export declare function RegisterOnClassUpdated(handler: (info: ChangeInformation) => void): Promise<void>;
|
|
32
|
+
export declare function RegisterOnSpecificClassUpdated(old: any, handler: (upd: ChangeInformation) => void): Promise<void>;
|
|
33
|
+
export declare function RegisterOnHotReload(callback: (info: ChangeInformation) => void, filePath?: string, exportName?: string): Promise<void>;
|
|
34
|
+
export declare function OnRequestHotReload(path: string): Promise<void>;
|
|
3
35
|
//# sourceMappingURL=DelayLib.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DelayLib.d.mts","sourceRoot":"","sources":["DelayLib.mts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"DelayLib.d.mts","sourceRoot":"","sources":["DelayLib.mts"],"names":[],"mappings":"AAIA,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACvB,gBAAgB,EAAE,CAAC,CAAC,IAAI,EAAE,iBAAiB,KAAI,IAAI,CAAC,EAAE,CAAC;IACvD,qBAAqB,EAAE,CAAC,MAAK,IAAI,CAAC,EAAE,CAAC;IACrC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAI,IAAI,CAAC;IACxC,QAAQ,EAAE,GAAG,CAAC;CACjB;AAeD,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,GAAG,KAAI,IAAI,WA2CjI;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,GAAG,KAAI,IAAI,QAoBjG;AAID;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAA;AAsDlI,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAI,IAAI,iBAErF;AAED,wBAAsB,8BAA8B,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAI,IAAI,iBAEtG;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAI,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,iBAoB3H;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,iBA0BpD"}
|
package/Libraries/DelayLib.mjs
CHANGED
|
@@ -1,11 +1,110 @@
|
|
|
1
|
-
|
|
1
|
+
import { BikPath } from "@bikky/path";
|
|
2
|
+
import { Map2D } from "@bikky/smart-collections";
|
|
3
|
+
const OnAnyHotReload = [];
|
|
2
4
|
const OnClassUpdated = [];
|
|
5
|
+
function CallOnClassUpdatedIfClass(info) {
|
|
6
|
+
if (info.oldValue.prototype || info.newValue.prototype) {
|
|
7
|
+
for (let handler of OnClassUpdated) {
|
|
8
|
+
handler(info);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const ObjectToFileMap = new WeakMap();
|
|
13
|
+
const FileReloadHandlers = new Map2D();
|
|
14
|
+
export function SetupReloadHandlers(fullQueryPath, exportName, rawValue, assignFunction) {
|
|
15
|
+
//Remove query string segments.
|
|
16
|
+
let filePath = fullQueryPath.split("?")[0];
|
|
17
|
+
let isFirstRegistration = false;
|
|
18
|
+
if (!FileReloadHandlers.has2D(filePath, exportName)) {
|
|
19
|
+
isFirstRegistration = true;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
let fileConfig = FileReloadHandlers.get2D(filePath, exportName);
|
|
23
|
+
if (!fileConfig.exportNewValue) {
|
|
24
|
+
isFirstRegistration = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (isFirstRegistration) {
|
|
28
|
+
// Cache the old value so when rawValue changes we can compare.
|
|
29
|
+
let oldValue = rawValue;
|
|
30
|
+
ObjectToFileMap.set(oldValue, { file: fullQueryPath, exportName });
|
|
31
|
+
function Reloadable_ExportFunction(newValue) {
|
|
32
|
+
let handlers = FileReloadHandlers.get2D(filePath, exportName);
|
|
33
|
+
for (let handler of handlers?.onChangeHandlers || []) {
|
|
34
|
+
handler({ file: filePath, exportName, oldValue, newValue });
|
|
35
|
+
}
|
|
36
|
+
assignFunction(newValue);
|
|
37
|
+
oldValue = newValue;
|
|
38
|
+
}
|
|
39
|
+
let fileConfig = FileReloadHandlers.get2D(filePath, exportName) ?? {
|
|
40
|
+
onChangeHandlers: [
|
|
41
|
+
(info) => {
|
|
42
|
+
if (typeof rawValue === "object" && "OnHotReload" in rawValue) {
|
|
43
|
+
rawValue.OnHotReload(info);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
onBeforeRequestReload: [],
|
|
48
|
+
exportNewValue: undefined,
|
|
49
|
+
oldValue: rawValue
|
|
50
|
+
};
|
|
51
|
+
fileConfig.exportNewValue = Reloadable_ExportFunction;
|
|
52
|
+
FileReloadHandlers.set2D(filePath, exportName, fileConfig);
|
|
53
|
+
}
|
|
54
|
+
return isFirstRegistration;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* When used on an exported value, it allows the value to be replaced during a hot reload.
|
|
58
|
+
* @param exportName - The name of the exported value.
|
|
59
|
+
* @param rawValue - The current value (at time of file load) of the exported value. Weirdly this value
|
|
60
|
+
* will update if the file's exported value changes.
|
|
61
|
+
* @param assignFunction - A function that assigns the exported value to the new value.
|
|
62
|
+
*/
|
|
63
|
+
export function Reloadable(exportName, rawValue, assignFunction) {
|
|
64
|
+
let fullQueryPath = BikPath.getCallerFilepath();
|
|
65
|
+
//Remove query string segments.
|
|
66
|
+
let filePath = fullQueryPath.split("?")[0];
|
|
67
|
+
if (typeof rawValue === "object") {
|
|
68
|
+
rawValue.__filePath__ = filePath;
|
|
69
|
+
rawValue.__exportName__ = exportName;
|
|
70
|
+
}
|
|
71
|
+
let isFirstRegistration = SetupReloadHandlers(fullQueryPath, exportName, rawValue, assignFunction);
|
|
72
|
+
if (!isFirstRegistration) {
|
|
73
|
+
//Notify updates and store the current value as the old value for next time.
|
|
74
|
+
let fileConfig = FileReloadHandlers.get2D(filePath, exportName);
|
|
75
|
+
let info = { file: filePath, exportName, oldValue: fileConfig.oldValue, newValue: rawValue };
|
|
76
|
+
fileConfig.oldValue = rawValue;
|
|
77
|
+
fileConfig.exportNewValue(rawValue);
|
|
78
|
+
for (let handler of fileConfig.onChangeHandlers) {
|
|
79
|
+
handler(info);
|
|
80
|
+
}
|
|
81
|
+
CallOnClassUpdatedIfClass(info);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function IgnoredProperties() { }
|
|
3
85
|
export function DelayCreate(promise, firstModule, makeClass, assignClass) {
|
|
86
|
+
let fullQueryPath = BikPath.getCallerFilepath();
|
|
87
|
+
let file = fullQueryPath.split("?")[0];
|
|
88
|
+
let className = firstModule.name;
|
|
4
89
|
//This seems to get replaced when the assignClass gets run, which is surprising.
|
|
5
90
|
// so let's cache this.
|
|
6
91
|
let originalModule = firstModule;
|
|
92
|
+
void SetupReloadHandlers(fullQueryPath, className, originalModule, assignClass);
|
|
93
|
+
let reloadedSinceStarting = false;
|
|
94
|
+
let fileConfig = FileReloadHandlers.get2D(file, className);
|
|
95
|
+
fileConfig.onBeforeRequestReload.push(() => {
|
|
96
|
+
reloadedSinceStarting = true;
|
|
97
|
+
});
|
|
98
|
+
if ("OnClassComplete" in originalModule) {
|
|
99
|
+
fileConfig.onChangeHandlers.push(originalModule.OnClassComplete);
|
|
100
|
+
}
|
|
7
101
|
//Await can introduce a small delay, so use a callback on then instead.
|
|
8
102
|
promise.then(function DelayCreate_Internal() {
|
|
103
|
+
// Abort if a reload of this file has happened at any point after the promise waiting started.
|
|
104
|
+
if (reloadedSinceStarting) {
|
|
105
|
+
//Abort, the reload will do it instead.
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
9
108
|
let result = makeClass();
|
|
10
109
|
if (result === originalModule) {
|
|
11
110
|
throw new Error(`Failed to create a new class, was the class marked as "declare" (ambient)?`);
|
|
@@ -21,35 +120,98 @@ export function DelayCreate(promise, firstModule, makeClass, assignClass) {
|
|
|
21
120
|
result[name] = originalModule[name];
|
|
22
121
|
}
|
|
23
122
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if ("OnClassComplete" in
|
|
29
|
-
|
|
123
|
+
//Notify updates and store the current value as the old value for next time.
|
|
124
|
+
let info = { file, exportName: className, oldValue: fileConfig.oldValue, newValue: result };
|
|
125
|
+
fileConfig.oldValue = result;
|
|
126
|
+
fileConfig.exportNewValue(result);
|
|
127
|
+
if ("OnClassComplete" in result && !fileConfig.onChangeHandlers.includes(result.OnClassComplete)) {
|
|
128
|
+
fileConfig.onChangeHandlers.push(result.OnClassComplete);
|
|
30
129
|
}
|
|
31
|
-
for (let handler of
|
|
32
|
-
handler(
|
|
130
|
+
for (let handler of fileConfig.onChangeHandlers) {
|
|
131
|
+
handler(info);
|
|
33
132
|
}
|
|
133
|
+
CallOnClassUpdatedIfClass(info);
|
|
34
134
|
});
|
|
35
135
|
}
|
|
36
136
|
export async function RegisterOnClassUpdated(handler) {
|
|
37
137
|
OnClassUpdated.push(handler);
|
|
38
138
|
}
|
|
139
|
+
export async function RegisterOnSpecificClassUpdated(old, handler) {
|
|
140
|
+
FileReloadHandlers.get2D(old.__filePath__, old.__exportName__)?.onChangeHandlers.push(handler);
|
|
141
|
+
}
|
|
142
|
+
export async function RegisterOnHotReload(callback, filePath, exportName) {
|
|
143
|
+
if (filePath) {
|
|
144
|
+
if (BikPath.isRelative(filePath)) {
|
|
145
|
+
let parent = BikPath.dir(BikPath.getCallerFilepath());
|
|
146
|
+
filePath = BikPath.importable(BikPath.join(parent, filePath));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!filePath || !exportName) {
|
|
150
|
+
OnAnyHotReload.push(callback);
|
|
151
|
+
}
|
|
152
|
+
else if (!exportName) {
|
|
153
|
+
let fileConfigs = FileReloadHandlers.get(filePath);
|
|
154
|
+
for (let [_exportName, fileConfig] of fileConfigs.entries()) {
|
|
155
|
+
fileConfig.onChangeHandlers.push(callback);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
let fileConfig = FileReloadHandlers.get2D(filePath, exportName);
|
|
160
|
+
fileConfig?.onChangeHandlers.push(callback);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export async function OnRequestHotReload(path) {
|
|
164
|
+
let fullQueryPath = BikPath.importable(BikPath.join(BikPath.dir(BikPath.getCallerFilepath())));
|
|
165
|
+
let filePath = fullQueryPath.split("?")[0];
|
|
166
|
+
let exports;
|
|
167
|
+
let fileConfigs = FileReloadHandlers.get(filePath);
|
|
168
|
+
for (let fileConfig of fileConfigs.values()) {
|
|
169
|
+
for (let handler of fileConfig.onBeforeRequestReload) {
|
|
170
|
+
handler();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (fullQueryPath !== filePath) {
|
|
174
|
+
exports = await import(fullQueryPath + `&reload=${Date.now()}`);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
exports = await import(fullQueryPath + `?reload=${Date.now()}`);
|
|
178
|
+
}
|
|
179
|
+
//Don't need to call callbacks here because they're handled in Reload and DelayUntil.
|
|
180
|
+
for (let exportName in exports) {
|
|
181
|
+
if (!fileConfigs.has(exportName)) {
|
|
182
|
+
console.error(`New exported value ${exportName} will not be accessible until next page reload. Found in imported file: ${filePath}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if ("OnHotReload" in exports) {
|
|
186
|
+
exports.OnHotReload();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
39
189
|
//Do not overwrite the function if it already exists, as that means two different
|
|
40
190
|
// bikky library modules have been included, and they will conflict.
|
|
41
191
|
if (typeof global !== "undefined") {
|
|
42
|
-
if (typeof global.
|
|
192
|
+
if (typeof global.__BikRegisterHotReload === "undefined") {
|
|
193
|
+
global.__BikRegisterHotReload = Reloadable;
|
|
194
|
+
global.OnBikHotReload = RegisterOnHotReload;
|
|
195
|
+
global.BikRequestHotReload = OnRequestHotReload;
|
|
43
196
|
global.__BikCompileDelayCreate = DelayCreate;
|
|
44
197
|
global.OnBikDelayCompleted = RegisterOnClassUpdated;
|
|
198
|
+
global.OnBikClassUpdated = RegisterOnSpecificClassUpdated;
|
|
45
199
|
}
|
|
46
200
|
}
|
|
47
201
|
else {
|
|
48
|
-
if (typeof window.
|
|
202
|
+
if (typeof window.__BikRegisterHotReload === "undefined") {
|
|
203
|
+
__BikRegisterHotReload = Reloadable;
|
|
204
|
+
OnBikHotReload = RegisterOnHotReload;
|
|
205
|
+
BikRequestHotReload = OnRequestHotReload;
|
|
206
|
+
window.__BikRegisterHotReload = Reloadable;
|
|
207
|
+
window.OnBikHotReload = RegisterOnHotReload;
|
|
208
|
+
window.BikRequestHotReload = OnRequestHotReload;
|
|
49
209
|
__BikCompileDelayCreate = DelayCreate;
|
|
50
210
|
OnBikDelayCompleted = RegisterOnClassUpdated;
|
|
211
|
+
OnBikClassUpdated = RegisterOnSpecificClassUpdated;
|
|
51
212
|
window.__BikCompileDelayCreate = DelayCreate;
|
|
52
213
|
window.OnBikDelayCompleted = RegisterOnClassUpdated;
|
|
214
|
+
window.OnBikClassUpdated = RegisterOnSpecificClassUpdated;
|
|
53
215
|
}
|
|
54
216
|
}
|
|
55
217
|
//# sourceMappingURL=DelayLib.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DelayLib.mjs","sourceRoot":"","sources":["DelayLib.mts"],"names":[],"m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GAAG,WAAW,CAAC;QACtC,mBAAmB,GAAG,sBAAsB,CAAC;QAC7C,iBAAiB,GAAG,8BAA8B,CAAC;QAClD,MAAc,CAAC,uBAAuB,GAAG,WAAW,CAAC;QACrD,MAAc,CAAC,mBAAmB,GAAG,sBAAsB,CAAC;QAC5D,MAAc,CAAC,iBAAiB,GAAG,8BAA8B,CAAC;IACvE,CAAC;AACL,CAAC"}
|
package/Libraries/DelayLib.mts
CHANGED
|
@@ -1,13 +1,143 @@
|
|
|
1
|
-
|
|
1
|
+
import { BikPath } from "@bikky/path";
|
|
2
|
+
import { Map2D } from "@bikky/smart-collections";
|
|
3
|
+
|
|
4
|
+
// Trigger a reload for each class and module in the file.
|
|
5
|
+
export interface ChangeInformation {
|
|
6
|
+
file: string;
|
|
7
|
+
exportName: string;
|
|
8
|
+
oldValue: any;
|
|
9
|
+
newValue: any;
|
|
10
|
+
}
|
|
2
11
|
|
|
3
|
-
|
|
12
|
+
export interface FileConfig {
|
|
13
|
+
onChangeHandlers: ((info: ChangeInformation)=> void)[],
|
|
14
|
+
onBeforeRequestReload: (()=> void)[],
|
|
15
|
+
exportNewValue?: (newValue: any)=> void,
|
|
16
|
+
oldValue: any,
|
|
17
|
+
}
|
|
4
18
|
|
|
19
|
+
const OnAnyHotReload: ((info: ChangeInformation)=> void)[] = [];
|
|
20
|
+
const OnClassUpdated: ((info: ChangeInformation)=> void)[] = [];
|
|
21
|
+
function CallOnClassUpdatedIfClass(info: ChangeInformation) {
|
|
22
|
+
if (info.oldValue.prototype || info.newValue.prototype) {
|
|
23
|
+
for (let handler of OnClassUpdated) {
|
|
24
|
+
handler(info);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ObjectToFileMap = new WeakMap<any, {file: string, exportName: string}>();
|
|
30
|
+
const FileReloadHandlers = new Map2D<string, FileConfig>()
|
|
31
|
+
|
|
32
|
+
export function SetupReloadHandlers(fullQueryPath: string, exportName: string, rawValue: any, assignFunction: (result: any)=> void) {
|
|
33
|
+
//Remove query string segments.
|
|
34
|
+
let filePath = fullQueryPath.split("?")[0];
|
|
35
|
+
let isFirstRegistration = false;
|
|
36
|
+
if (!FileReloadHandlers.has2D(filePath, exportName)) {
|
|
37
|
+
isFirstRegistration = true;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
let fileConfig = FileReloadHandlers.get2D(filePath, exportName)!;
|
|
41
|
+
if (!fileConfig.exportNewValue) {
|
|
42
|
+
isFirstRegistration = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (isFirstRegistration) {
|
|
46
|
+
// Cache the old value so when rawValue changes we can compare.
|
|
47
|
+
let oldValue = rawValue;
|
|
48
|
+
ObjectToFileMap.set(oldValue, {file: fullQueryPath, exportName});
|
|
49
|
+
function Reloadable_ExportFunction(newValue: any) {
|
|
50
|
+
let handlers = FileReloadHandlers.get2D(filePath, exportName);
|
|
51
|
+
for (let handler of handlers?.onChangeHandlers || []) {
|
|
52
|
+
handler({file: filePath, exportName, oldValue, newValue});
|
|
53
|
+
}
|
|
54
|
+
assignFunction(newValue);
|
|
55
|
+
oldValue = newValue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let fileConfig: FileConfig = FileReloadHandlers.get2D(filePath, exportName) ?? {
|
|
59
|
+
onChangeHandlers: [
|
|
60
|
+
(info: ChangeInformation)=> {
|
|
61
|
+
if (typeof rawValue === "object" && "OnHotReload" in rawValue) {
|
|
62
|
+
rawValue.OnHotReload(info);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
onBeforeRequestReload: [] as (()=> void)[],
|
|
67
|
+
exportNewValue: undefined,
|
|
68
|
+
oldValue: rawValue
|
|
69
|
+
};
|
|
70
|
+
fileConfig.exportNewValue = Reloadable_ExportFunction;
|
|
71
|
+
FileReloadHandlers.set2D(filePath, exportName, fileConfig);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return isFirstRegistration;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* When used on an exported value, it allows the value to be replaced during a hot reload.
|
|
79
|
+
* @param exportName - The name of the exported value.
|
|
80
|
+
* @param rawValue - The current value (at time of file load) of the exported value. Weirdly this value
|
|
81
|
+
* will update if the file's exported value changes.
|
|
82
|
+
* @param assignFunction - A function that assigns the exported value to the new value.
|
|
83
|
+
*/
|
|
84
|
+
export function Reloadable(exportName: string, rawValue: any, assignFunction: (result: any)=> void) {
|
|
85
|
+
let fullQueryPath = BikPath.getCallerFilepath();
|
|
86
|
+
//Remove query string segments.
|
|
87
|
+
let filePath = fullQueryPath.split("?")[0];
|
|
88
|
+
if (typeof rawValue === "object") {
|
|
89
|
+
rawValue.__filePath__ = filePath;
|
|
90
|
+
rawValue.__exportName__ = exportName;
|
|
91
|
+
}
|
|
92
|
+
let isFirstRegistration = SetupReloadHandlers(fullQueryPath, exportName, rawValue, assignFunction);
|
|
93
|
+
if (!isFirstRegistration) {
|
|
94
|
+
//Notify updates and store the current value as the old value for next time.
|
|
95
|
+
let fileConfig = FileReloadHandlers.get2D(filePath, exportName)!;
|
|
96
|
+
let info = { file: filePath, exportName, oldValue: fileConfig.oldValue, newValue: rawValue };
|
|
97
|
+
fileConfig.oldValue = rawValue;
|
|
98
|
+
fileConfig.exportNewValue!(rawValue);
|
|
99
|
+
for (let handler of fileConfig.onChangeHandlers) {
|
|
100
|
+
handler(info);
|
|
101
|
+
}
|
|
102
|
+
CallOnClassUpdatedIfClass(info);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function IgnoredProperties() {}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The exported placeholder class is replaced with the fully fleshed out class once the promise resolves. If a hot
|
|
110
|
+
* reload occurs, then only the delayed class once created will trigger the reload handlers.
|
|
111
|
+
* @param promise - The promise to wait on before creating the class.
|
|
112
|
+
* @param firstModule - The module containing the class to be created.
|
|
113
|
+
* @param makeClass - A function that creates the class when called.
|
|
114
|
+
* @param assignClass - A function that assigns the created class to the exported value.
|
|
115
|
+
*/
|
|
116
|
+
export function DelayCreate(promise: any, firstModule: Class<any>, makeClass: () => any, assignClass: (result: any) => void): void
|
|
5
117
|
export function DelayCreate(promise: any, firstModule: any, makeClass: () => any, assignClass: (result: any) => void) {
|
|
118
|
+
let fullQueryPath = BikPath.getCallerFilepath();
|
|
119
|
+
let file = fullQueryPath.split("?")[0];
|
|
120
|
+
let className: string = firstModule.name;
|
|
6
121
|
//This seems to get replaced when the assignClass gets run, which is surprising.
|
|
7
122
|
// so let's cache this.
|
|
8
|
-
let originalModule = firstModule;
|
|
123
|
+
let originalModule: any = firstModule;
|
|
124
|
+
void SetupReloadHandlers(fullQueryPath, className, originalModule, assignClass);
|
|
125
|
+
let reloadedSinceStarting = false;
|
|
126
|
+
let fileConfig = FileReloadHandlers.get2D(file, className)!;
|
|
127
|
+
fileConfig.onBeforeRequestReload.push(()=> {
|
|
128
|
+
reloadedSinceStarting = true;
|
|
129
|
+
});
|
|
130
|
+
if ("OnClassComplete" in originalModule) {
|
|
131
|
+
fileConfig.onChangeHandlers.push(originalModule.OnClassComplete);
|
|
132
|
+
}
|
|
133
|
+
|
|
9
134
|
//Await can introduce a small delay, so use a callback on then instead.
|
|
10
135
|
promise.then(function DelayCreate_Internal() {
|
|
136
|
+
// Abort if a reload of this file has happened at any point after the promise waiting started.
|
|
137
|
+
if (reloadedSinceStarting) {
|
|
138
|
+
//Abort, the reload will do it instead.
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
11
141
|
let result = makeClass();
|
|
12
142
|
if (result === originalModule) {
|
|
13
143
|
throw new Error(`Failed to create a new class, was the class marked as "declare" (ambient)?`);
|
|
@@ -23,41 +153,116 @@ export function DelayCreate(promise: any, firstModule: any, makeClass: () => any
|
|
|
23
153
|
result[name] = originalModule[name];
|
|
24
154
|
}
|
|
25
155
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
156
|
+
//Notify updates and store the current value as the old value for next time.
|
|
157
|
+
let info = {file, exportName: className, oldValue: fileConfig.oldValue, newValue: result};
|
|
158
|
+
fileConfig.oldValue = result;
|
|
159
|
+
fileConfig.exportNewValue!(result);
|
|
160
|
+
if ("OnClassComplete" in result && !fileConfig.onChangeHandlers.includes(result.OnClassComplete)) {
|
|
161
|
+
fileConfig.onChangeHandlers.push(result.OnClassComplete);
|
|
29
162
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
for (let handler of OnClassUpdated) {
|
|
34
|
-
handler(originalModule, result);
|
|
163
|
+
for (let handler of fileConfig.onChangeHandlers) {
|
|
164
|
+
handler(info);
|
|
35
165
|
}
|
|
166
|
+
CallOnClassUpdatedIfClass(info);
|
|
36
167
|
});
|
|
37
168
|
}
|
|
38
169
|
|
|
39
|
-
export async function RegisterOnClassUpdated(handler: (
|
|
170
|
+
export async function RegisterOnClassUpdated(handler: (info: ChangeInformation)=> void) {
|
|
40
171
|
OnClassUpdated.push(handler);
|
|
41
172
|
}
|
|
42
173
|
|
|
174
|
+
export async function RegisterOnSpecificClassUpdated(old: any, handler: (upd: ChangeInformation)=> void) {
|
|
175
|
+
FileReloadHandlers.get2D(old.__filePath__, old.__exportName__)?.onChangeHandlers.push(handler);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export async function RegisterOnHotReload(callback: (info: ChangeInformation)=> void, filePath?: string, exportName?: string) {
|
|
179
|
+
if (filePath) {
|
|
180
|
+
if (BikPath.isRelative(filePath)) {
|
|
181
|
+
let parent = BikPath.dir(BikPath.getCallerFilepath());
|
|
182
|
+
filePath = BikPath.importable(BikPath.join(parent, filePath));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!filePath || !exportName) {
|
|
186
|
+
OnAnyHotReload.push(callback);
|
|
187
|
+
}
|
|
188
|
+
else if (!exportName) {
|
|
189
|
+
let fileConfigs = FileReloadHandlers.get(filePath);
|
|
190
|
+
for (let [_exportName, fileConfig] of fileConfigs!.entries()) {
|
|
191
|
+
fileConfig.onChangeHandlers.push(callback);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
let fileConfig = FileReloadHandlers.get2D(filePath, exportName);
|
|
196
|
+
fileConfig?.onChangeHandlers.push(callback);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export async function OnRequestHotReload(path: string) {
|
|
201
|
+
let fullQueryPath = BikPath.importable(BikPath.join(BikPath.dir(BikPath.getCallerFilepath())));
|
|
202
|
+
let filePath = fullQueryPath.split("?")[0];
|
|
203
|
+
|
|
204
|
+
let exports: any;
|
|
205
|
+
let fileConfigs = FileReloadHandlers.get(filePath)!;
|
|
206
|
+
for (let fileConfig of fileConfigs.values()) {
|
|
207
|
+
for (let handler of fileConfig.onBeforeRequestReload) {
|
|
208
|
+
handler();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (fullQueryPath !== filePath) {
|
|
212
|
+
exports = await import(fullQueryPath + `&reload=${Date.now()}`);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
exports = await import(fullQueryPath + `?reload=${Date.now()}`);
|
|
216
|
+
}
|
|
217
|
+
//Don't need to call callbacks here because they're handled in Reload and DelayUntil.
|
|
218
|
+
for (let exportName in exports) {
|
|
219
|
+
if (!fileConfigs.has(exportName)) {
|
|
220
|
+
console.error(`New exported value ${exportName} will not be accessible until next page reload. Found in imported file: ${filePath}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if ("OnHotReload" in exports) {
|
|
224
|
+
exports.OnHotReload();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
43
228
|
// @ts-ignore
|
|
44
229
|
declare var window: any;
|
|
230
|
+
|
|
231
|
+
declare var __BikRegisterHotReload: typeof Reloadable;
|
|
232
|
+
declare var OnBikHotReload: typeof RegisterOnHotReload;
|
|
233
|
+
declare var BikRequestHotReload: typeof OnRequestHotReload;
|
|
234
|
+
|
|
45
235
|
declare var __BikCompileDelayCreate: typeof DelayCreate;
|
|
46
236
|
declare var OnBikDelayCompleted: typeof RegisterOnClassUpdated;
|
|
237
|
+
declare var OnBikClassUpdated: typeof RegisterOnSpecificClassUpdated;
|
|
47
238
|
|
|
48
239
|
//Do not overwrite the function if it already exists, as that means two different
|
|
49
240
|
// bikky library modules have been included, and they will conflict.
|
|
50
241
|
if (typeof global !== "undefined") {
|
|
51
|
-
if (typeof (global as any).
|
|
242
|
+
if (typeof (global as any).__BikRegisterHotReload === "undefined") {
|
|
243
|
+
(global as any).__BikRegisterHotReload = Reloadable;
|
|
244
|
+
(global as any).OnBikHotReload = RegisterOnHotReload;
|
|
245
|
+
(global as any).BikRequestHotReload = OnRequestHotReload;
|
|
246
|
+
|
|
52
247
|
(global as any).__BikCompileDelayCreate = DelayCreate;
|
|
53
248
|
(global as any).OnBikDelayCompleted = RegisterOnClassUpdated;
|
|
249
|
+
(global as any).OnBikClassUpdated = RegisterOnSpecificClassUpdated;
|
|
54
250
|
}
|
|
55
251
|
}
|
|
56
252
|
else {
|
|
57
|
-
if (typeof (window as any).
|
|
253
|
+
if (typeof (window as any).__BikRegisterHotReload === "undefined") {
|
|
254
|
+
__BikRegisterHotReload = Reloadable;
|
|
255
|
+
OnBikHotReload = RegisterOnHotReload;
|
|
256
|
+
BikRequestHotReload = OnRequestHotReload;
|
|
257
|
+
(window as any).__BikRegisterHotReload = Reloadable;
|
|
258
|
+
(window as any).OnBikHotReload = RegisterOnHotReload;
|
|
259
|
+
(window as any).BikRequestHotReload = OnRequestHotReload;
|
|
260
|
+
|
|
58
261
|
__BikCompileDelayCreate = DelayCreate;
|
|
59
262
|
OnBikDelayCompleted = RegisterOnClassUpdated;
|
|
263
|
+
OnBikClassUpdated = RegisterOnSpecificClassUpdated;
|
|
60
264
|
(window as any).__BikCompileDelayCreate = DelayCreate;
|
|
61
265
|
(window as any).OnBikDelayCompleted = RegisterOnClassUpdated;
|
|
266
|
+
(window as any).OnBikClassUpdated = RegisterOnSpecificClassUpdated;
|
|
62
267
|
}
|
|
63
268
|
}
|
|
@@ -123,4 +123,8 @@ declare function makeMixer<
|
|
|
123
123
|
)
|
|
124
124
|
);
|
|
125
125
|
|
|
126
|
-
declare function OnBikDelayCompleted(callback: (old: Class<any>, upd: Class<any>)=> void): void;
|
|
126
|
+
declare function OnBikDelayCompleted(callback: (old: Class<any>, upd: Class<any>)=> void): void;
|
|
127
|
+
|
|
128
|
+
declare function InlineClass(version: string): (cls: Class<any>)=> void;
|
|
129
|
+
declare function AddressableClass(version: string): (cls: Class<any>) => void;
|
|
130
|
+
declare function Property(version: string, config?: any): (target: Object, propertyKey: string | symbol)=> void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ASTBuilder.d.ts","sourceRoot":"","sources":["ASTBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ASTBuilder.d.ts","sourceRoot":"","sources":["ASTBuilder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EACH,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAMhD,KAAK,OAAO,GAAG,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;AAE1C,wBAAgB,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACrE,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC;AACnD,wBAAgB,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC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DAE7E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,GAAG,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,6BAM/G;AAED,wBAAgB,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,UAAU,GAAG,UAAU,sBAEvD;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,UAAO,EAAE,YAAY,UAAO,KAO1G;AAGD,cAAM,SAAS;IACX,UAAU,EAAE,CAAC,EAAE,CAAC,UAAU,GAAG,UAAU,CAAC,EAAE,CAAM;IAChD,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,KAAG,CAAC,CAAC,EAAE,EAAE,CAAM;IAErD,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,GAAG,UAAU;IAKpC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,UAAO;IAmB/C,KAAK,IAAI,EAAE,CAAC,SAAS,EAAE;CAY1B;AAED,wBAAgB,SAAS,cAExB"}
|
package/Source/ASTHelper.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export declare class SourceFile {
|
|
|
67
67
|
}
|
|
68
68
|
export declare function logError(node: ts.Node, error: string): undefined;
|
|
69
69
|
export declare namespace Printer {
|
|
70
|
-
function printNode(node: ts.Node, sourceFile: ts.SourceFile): string;
|
|
70
|
+
function printNode(node: ts.Node, sourceFile: ts.SourceFile, emitHint?: ts.EmitHint): string;
|
|
71
71
|
function printNodeFirstLine(node: ts.Node, sourceFile: ts.SourceFile): string;
|
|
72
72
|
}
|
|
73
73
|
//# sourceMappingURL=ASTHelper.d.ts.map
|