@geajs/vite-plugin 1.4.0 → 1.4.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.
Files changed (2) hide show
  1. package/dist/index.mjs +48 -3
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -3008,8 +3008,21 @@ function buildInlinePropKeyedListBlock(options) {
3008
3008
  __PATCH__: options.patchEntryArrow
3009
3009
  });
3010
3010
  replaceByKeyMarker(block, options.relMatches);
3011
+ if (options.ctx.embedded) rewriteObserveReconcileForEmbedded(block);
3011
3012
  return block;
3012
3013
  }
3014
+ function rewriteObserveReconcileForEmbedded(node) {
3015
+ if (!node || typeof node !== "object") return;
3016
+ if (Array.isArray(node)) {
3017
+ for (const value of node) rewriteObserveReconcileForEmbedded(value);
3018
+ return;
3019
+ }
3020
+ if (node.type === "CallExpression" && t.isIdentifier(node.callee, { name: "__kl_reconcile" }) && node.arguments.length >= 1 && t.isIdentifier(node.arguments[0], { name: "_value" })) node.arguments[0] = t.callExpression(t.identifier("__kl_resolve"), []);
3021
+ for (const key of Object.keys(node)) {
3022
+ if (key === "loc" || key === "start" || key === "end" || key === "type") continue;
3023
+ rewriteObserveReconcileForEmbedded(node[key]);
3024
+ }
3025
+ }
3013
3026
  function isDirectIdKey(expr) {
3014
3027
  if (!t.isArrowFunctionExpression(expr) || expr.params.length === 0) return false;
3015
3028
  const firstParam = expr.params[0];
@@ -5811,6 +5824,7 @@ function transformFile(source, _filename, options = {}) {
5811
5824
  }
5812
5825
  const ctx = createEmitContext();
5813
5826
  ctx.irTemplates = [];
5827
+ ctx.embedded = options.embedded;
5814
5828
  ctx.directFnComponents = collectDirectFnComponents(ast);
5815
5829
  ctx.directFnComponentParams = collectDirectFnComponentParams(ast, ctx.directFnComponents);
5816
5830
  ctx.directFnStringProps = collectDirectFnStringProps(ast, ctx.directFnComponents);
@@ -6584,7 +6598,8 @@ function transform(ctx) {
6584
6598
  const emitted = transformFile(code, sourceFile, {
6585
6599
  directClassComponents: knownClassComponentImports,
6586
6600
  directFactoryComponents: knownFactoryComponentImports,
6587
- enableTinyReactiveComponents: !isServe
6601
+ enableTinyReactiveComponents: !isServe,
6602
+ embedded: ctx.embedded
6588
6603
  });
6589
6604
  if (emitted.changed) {
6590
6605
  ir = emitted.ir;
@@ -6674,9 +6689,10 @@ function transformCompiledStoreModule(source, moduleId = "<unknown>", resolveImp
6674
6689
  if (classDecls.length === 0) return null;
6675
6690
  const constants = collectImportedLiteralConstants(ast, moduleId, resolveImportPath);
6676
6691
  const fallbackIrs = classDecls.map((classDecl) => buildStoreIr(classDecl, moduleId, "compiled", constants, ast));
6692
+ const fallbackKeepAlive = storeMethodFreeFunctionKeepAlive(ast, classDecls);
6677
6693
  const fallback = {
6678
- code: source,
6679
- changed: false,
6694
+ code: fallbackKeepAlive ? `${source}${fallbackKeepAlive}` : source,
6695
+ changed: !!fallbackKeepAlive,
6680
6696
  ir: fallbackIrs[0],
6681
6697
  irs: fallbackIrs
6682
6698
  };
@@ -6943,6 +6959,34 @@ function literalConstantsFromFile(file, names) {
6943
6959
  }
6944
6960
  return constants;
6945
6961
  }
6962
+ function moduleFreeFunctionNames(ast) {
6963
+ const names = /* @__PURE__ */ new Set();
6964
+ for (const node of ast.program.body) if (t.isFunctionDeclaration(node) && node.id) names.add(node.id.name);
6965
+ else if (t.isExportNamedDeclaration(node) && node.declaration && t.isFunctionDeclaration(node.declaration) && node.declaration.id) names.add(node.declaration.id.name);
6966
+ return names;
6967
+ }
6968
+ function nodeReferencesIdentifier(node, name) {
6969
+ if (!node || typeof node !== "object") return false;
6970
+ if (Array.isArray(node)) {
6971
+ for (const child of node) if (nodeReferencesIdentifier(child, name)) return true;
6972
+ return false;
6973
+ }
6974
+ const record = node;
6975
+ if (record.type === "Identifier" && record.name === name) return true;
6976
+ for (const key of Object.keys(record)) {
6977
+ if (key === "type" || key === "loc" || key === "start" || key === "end" || key === "leadingComments" || key === "trailingComments") continue;
6978
+ if (nodeReferencesIdentifier(record[key], name)) return true;
6979
+ }
6980
+ return false;
6981
+ }
6982
+ function storeMethodFreeFunctionKeepAlive(ast, classDecls) {
6983
+ const freeFns = moduleFreeFunctionNames(ast);
6984
+ if (freeFns.size === 0) return "";
6985
+ const kept = [];
6986
+ for (const name of freeFns) if (classDecls.some((classDecl) => classDecl.body.body.some((member) => t.isClassMethod(member) && nodeReferencesIdentifier(member.body, name)))) kept.push(name);
6987
+ if (kept.length === 0) return "";
6988
+ return `\n;(globalThis.__GEA_IR_KEEP__ ||= []).push(${kept.join(", ")});\n`;
6989
+ }
6946
6990
  function literalConstant(name, value) {
6947
6991
  if (t.isStringLiteral(value)) return {
6948
6992
  name,
@@ -8280,6 +8324,7 @@ function geaPlugin(options = {}) {
8280
8324
  code: transformedCode,
8281
8325
  isServe: isServeCommand,
8282
8326
  isSSR,
8327
+ embedded: !!irOptions?.enabled,
8283
8328
  hmrImportSource: HMR_RUNTIME_ID,
8284
8329
  isStoreModule,
8285
8330
  isComponentModule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geajs/vite-plugin",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Vite plugin for Gea framework - JSX/TSX transform, reactivity, HMR",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",