@geajs/vite-plugin 1.2.2 → 1.2.3
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.mjs +37 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -281,6 +281,9 @@ const GEA_COMPILER_SYMBOL_IMPORTS = [
|
|
|
281
281
|
"GEA_MAP_CONFIG_COUNT",
|
|
282
282
|
"GEA_CLONE_ITEM",
|
|
283
283
|
"GEA_CLONE_TEMPLATE",
|
|
284
|
+
"GEA_COMPILED",
|
|
285
|
+
"GEA_EVENTS_CACHE",
|
|
286
|
+
"GEA_LIFECYCLE_CALLED",
|
|
284
287
|
"GEA_ON_PROP_CHANGE",
|
|
285
288
|
"GEA_SETUP_LOCAL_STATE_OBSERVERS",
|
|
286
289
|
"GEA_SETUP_REFS",
|
|
@@ -4490,7 +4493,7 @@ function wrapEventsGetterWithCache(getter) {
|
|
|
4490
4493
|
const body = getter.body.body;
|
|
4491
4494
|
const returnStmt = body.find((s) => t.isReturnStatement(s) && s.argument !== null);
|
|
4492
4495
|
if (!returnStmt?.argument) return;
|
|
4493
|
-
const cachedProp = t.memberExpression(t.thisExpression(), t.identifier("
|
|
4496
|
+
const cachedProp = t.memberExpression(t.thisExpression(), t.identifier("GEA_EVENTS_CACHE"), true);
|
|
4494
4497
|
const elementProp = t.memberExpression(t.thisExpression(), id("GEA_ELEMENT"), true);
|
|
4495
4498
|
const tmpId = t.identifier("__geaEvtsResult");
|
|
4496
4499
|
const objectExpr = returnStmt.argument;
|
|
@@ -9618,6 +9621,9 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
|
|
|
9618
9621
|
if (name === "events" && member.kind === "get") wrapEventsGetterWithCache(member);
|
|
9619
9622
|
if (member.computed && name === "GEA_ON_PROP_CHANGE") wrapSubpathCacheGuards(member, subpathPcCounter, path.node.body);
|
|
9620
9623
|
}
|
|
9624
|
+
const compiledProp = t.classProperty(t.identifier("GEA_COMPILED"), t.booleanLiteral(true), void 0, void 0, true, true);
|
|
9625
|
+
path.node.body.body.push(compiledProp);
|
|
9626
|
+
injectLifecycleCallsIntoConstructor(path.node.body);
|
|
9621
9627
|
path.stop();
|
|
9622
9628
|
} });
|
|
9623
9629
|
return transformed;
|
|
@@ -9712,6 +9718,36 @@ function transformRemainingJSX(ast, imports) {
|
|
|
9712
9718
|
}
|
|
9713
9719
|
});
|
|
9714
9720
|
}
|
|
9721
|
+
function injectLifecycleCallsIntoConstructor(classBody) {
|
|
9722
|
+
const createdCall = js`this.created(this.props);`;
|
|
9723
|
+
const createdHooksCall = js`this.createdHooks(this.props);`;
|
|
9724
|
+
const setupObserversAccess = t.memberExpression(t.thisExpression(), t.identifier("GEA_SETUP_LOCAL_STATE_OBSERVERS"), true);
|
|
9725
|
+
const setupObserversCall = t.ifStatement(t.binaryExpression("===", t.unaryExpression("typeof", setupObserversAccess), t.stringLiteral("function")), t.expressionStatement(t.callExpression(setupObserversAccess, [])));
|
|
9726
|
+
const lifecycleCalledAccess = t.memberExpression(t.thisExpression(), t.identifier("GEA_LIFECYCLE_CALLED"), true);
|
|
9727
|
+
const setLifecycleCalled = t.expressionStatement(t.assignmentExpression("=", t.cloneNode(lifecycleCalledAccess), t.booleanLiteral(true)));
|
|
9728
|
+
const guardedBlock = t.ifStatement(t.unaryExpression("!", lifecycleCalledAccess), t.blockStatement([
|
|
9729
|
+
setLifecycleCalled,
|
|
9730
|
+
createdCall,
|
|
9731
|
+
createdHooksCall,
|
|
9732
|
+
setupObserversCall
|
|
9733
|
+
]));
|
|
9734
|
+
const ctor = classBody.body.find((m) => t.isClassMethod(m) && (m.kind === "constructor" || t.isIdentifier(m.key) && m.key.name === "constructor"));
|
|
9735
|
+
if (ctor) {
|
|
9736
|
+
let superIdx = -1;
|
|
9737
|
+
for (let i = 0; i < ctor.body.body.length; i++) {
|
|
9738
|
+
const s = ctor.body.body[i];
|
|
9739
|
+
if (t.isExpressionStatement(s) && t.isCallExpression(s.expression) && t.isSuper(s.expression.callee)) {
|
|
9740
|
+
superIdx = i;
|
|
9741
|
+
break;
|
|
9742
|
+
}
|
|
9743
|
+
}
|
|
9744
|
+
if (superIdx >= 0) ctor.body.body.splice(superIdx + 1, 0, guardedBlock);
|
|
9745
|
+
else ctor.body.body.unshift(guardedBlock);
|
|
9746
|
+
} else {
|
|
9747
|
+
const newCtor = appendToBody(jsMethod`${id("constructor")}(...args) {}`, js`super(...args);`, guardedBlock);
|
|
9748
|
+
classBody.body.unshift(newCtor);
|
|
9749
|
+
}
|
|
9750
|
+
}
|
|
9715
9751
|
//#endregion
|
|
9716
9752
|
//#region src/postprocess/hmr.ts
|
|
9717
9753
|
const hot = () => t.memberExpression(t.metaProperty(t.identifier("import"), t.identifier("meta")), t.identifier("hot"));
|