@vesk/vesk-cli 0.2.27 → 0.2.28

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/cli.js +65 -133
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -17843,32 +17843,6 @@ function tokenizeCode(code) {
17843
17843
  return null;
17844
17844
  }
17845
17845
  }
17846
- function collectCalledIdentifiers(code) {
17847
- const tokens = tokenizeCode(code);
17848
- if (tokens !== null) {
17849
- const result = /* @__PURE__ */ new Set();
17850
- for (let i = 0; i < tokens.length; i++) {
17851
- const t = tokens[i];
17852
- if (t.label !== "name") continue;
17853
- const prev = i > 0 ? tokens[i - 1] : null;
17854
- if (prev && (prev.label === "." || prev.label === "?.")) {
17855
- const obj = i >= 2 ? tokens[i - 2] : null;
17856
- const next2 = tokens[i + 1];
17857
- if (obj && obj.label === "name" && next2) {
17858
- const nextCh2 = code[next2.start];
17859
- if (nextCh2 === "(" || nextCh2 === "<") result.add(obj.value);
17860
- }
17861
- continue;
17862
- }
17863
- const next = tokens[i + 1];
17864
- if (!next) continue;
17865
- const nextCh = code[next.start];
17866
- if (nextCh === "(" || nextCh === "<") result.add(t.value);
17867
- }
17868
- return result;
17869
- }
17870
- return manualCollectCalledIdentifiers(code);
17871
- }
17872
17846
  function containsIdentifier(code, name) {
17873
17847
  const tokens = tokenizeCode(code);
17874
17848
  if (tokens !== null) {
@@ -17944,44 +17918,6 @@ function importModuleTarget(importText) {
17944
17918
  }
17945
17919
  return null;
17946
17920
  }
17947
- function manualCollectCalledIdentifiers(code) {
17948
- const result = /* @__PURE__ */ new Set();
17949
- let i = 0;
17950
- let prevIdent = null;
17951
- while (i < code.length) {
17952
- const c = code[i];
17953
- if (c === '"' || c === "'" || c === "`") {
17954
- i = skipString(code, i);
17955
- continue;
17956
- }
17957
- if (c === "/" && (code[i + 1] === "/" || code[i + 1] === "*")) {
17958
- i = skipComment(code, i);
17959
- continue;
17960
- }
17961
- if (isIdentStart(c)) {
17962
- let j = i + 1;
17963
- while (j < code.length && isIdentChar(code[j])) j++;
17964
- const before = i === 0 ? "" : code[i - 1];
17965
- if (before !== "." && !isIdentChar(before)) {
17966
- let k = skipWhitespace(code, j);
17967
- if (code[k] === "<") k = skipTrackGeneric(code, k);
17968
- if (code[k] === "(") result.add(code.slice(i, j));
17969
- } else if (before === "." && prevIdent) {
17970
- let p = i - 1;
17971
- while (p > prevIdent[1] && (code[p] === "." || code[p] === "?" || code[p] === "\n" || code[p] === " " || code[p] === " ")) p--;
17972
- if (p === prevIdent[1]) {
17973
- let k = skipWhitespace(code, j);
17974
- if (code[k] === "(") result.add(code.slice(prevIdent[0], prevIdent[1]));
17975
- }
17976
- }
17977
- prevIdent = [i, j];
17978
- i = j;
17979
- continue;
17980
- }
17981
- i++;
17982
- }
17983
- return result;
17984
- }
17985
17921
  function manualContainsIdentifier(code, name) {
17986
17922
  let i = 0;
17987
17923
  while (i < code.length) {
@@ -19216,6 +19152,65 @@ function estreeCallsFetch(ast) {
19216
19152
  }
19217
19153
  return false;
19218
19154
  }
19155
+ function memberReceiverName(obj) {
19156
+ if (!obj || typeof obj !== "object") return null;
19157
+ const rec = obj;
19158
+ if (rec.type === "Identifier" && typeof rec.name === "string") return rec.name;
19159
+ const prop = rec.type === "MemberExpression" && !rec.computed ? rec.property : null;
19160
+ if (prop && typeof prop === "object" && prop.type === "Identifier") {
19161
+ const propName = prop.name;
19162
+ if (typeof propName === "string") return propName;
19163
+ }
19164
+ return null;
19165
+ }
19166
+ function collectCallAndJsxTargets(ast) {
19167
+ const targets = /* @__PURE__ */ new Set();
19168
+ const stack = [ast];
19169
+ while (stack.length > 0) {
19170
+ const candidate = stack.pop();
19171
+ if (!candidate || typeof candidate !== "object") continue;
19172
+ const node = candidate;
19173
+ if (typeof node.type === "string") {
19174
+ if (node.type === "CallExpression" || node.type === "NewExpression") {
19175
+ const callee = node.callee;
19176
+ if (callee && typeof callee === "object") {
19177
+ const c = callee;
19178
+ if (c.type === "Identifier" && typeof c.name === "string" && node.optional !== true) {
19179
+ targets.add(c.name);
19180
+ } else if (c.type === "MemberExpression" && !c.computed && node.optional !== true) {
19181
+ const receiverName = memberReceiverName(c.object);
19182
+ if (receiverName) targets.add(receiverName);
19183
+ }
19184
+ }
19185
+ } else if (node.type === "JSXElement") {
19186
+ const opening = node.openingElement;
19187
+ const tag = opening && typeof opening === "object" ? opening.name : null;
19188
+ if (tag && typeof tag === "object") {
19189
+ const t = tag;
19190
+ if (t.type === "JSXIdentifier" && typeof t.name === "string") {
19191
+ targets.add(t.name);
19192
+ } else if (t.type === "JSXMemberExpression") {
19193
+ const prop = t.property;
19194
+ if (prop && typeof prop === "object" && prop.type === "JSXIdentifier") {
19195
+ const propName = prop.name;
19196
+ if (typeof propName === "string") targets.add(propName);
19197
+ }
19198
+ }
19199
+ }
19200
+ }
19201
+ for (const key of Object.keys(node)) {
19202
+ if (key === "parent" || key === "loc" || key === "start" || key === "end" || key === "range") continue;
19203
+ const value = node[key];
19204
+ if (Array.isArray(value)) {
19205
+ for (const item of value) stack.push(item);
19206
+ } else {
19207
+ stack.push(value);
19208
+ }
19209
+ }
19210
+ }
19211
+ }
19212
+ return targets;
19213
+ }
19219
19214
  function componentUsesFetch(nodes) {
19220
19215
  for (const node of nodes) {
19221
19216
  if (node instanceof ServerBlock || node instanceof ClientBlock) {
@@ -20207,9 +20202,9 @@ function generateIR(ast, source, filename) {
20207
20202
  const asyncNames = new Set(components.filter((c) => c.isAsync || c.ssrAwait).map((c) => c.name));
20208
20203
  for (const comp of components) {
20209
20204
  if (asyncNames.has(comp.name)) continue;
20210
- const called = /* @__PURE__ */ new Map();
20211
- collectComponentCalls(comp.body, called);
20212
- for (const [childName, start] of called) {
20205
+ const called2 = /* @__PURE__ */ new Map();
20206
+ collectComponentCalls(comp.body, called2);
20207
+ for (const [childName, start] of called2) {
20213
20208
  if (!asyncNames.has(childName)) continue;
20214
20209
  const { line, column } = offsetToLineCol2(source, start >= 0 ? start : 0);
20215
20210
  throw VeskError.asyncChildInSyncParent(comp.name, childName, { file, line, column, code: codeFrame(source, line, column) });
@@ -20270,74 +20265,11 @@ function generateIR(ast, source, filename) {
20270
20265
  "Switch",
20271
20266
  "Match"
20272
20267
  ];
20268
+ const called = collectCallAndJsxTargets(ast);
20273
20269
  const usedFunctions = /* @__PURE__ */ new Set();
20274
- const addUsedFrom = (code) => {
20275
- const called = collectCalledIdentifiers(code);
20276
- for (const fn of autoImportable) {
20277
- if (called.has(fn)) usedFunctions.add(fn);
20278
- }
20279
- };
20280
- for (const code of topLevelCode) addUsedFrom(code);
20281
- for (const code of [loadFn, staticProps]) {
20282
- if (code) addUsedFrom(code);
20283
- }
20284
- function scanForAutoImport(nodes) {
20285
- for (const node of nodes) {
20286
- if (node instanceof RuntimeStatement && node.raw) {
20287
- addUsedFrom(node.raw);
20288
- }
20289
- if (node instanceof TrackDecl && node.init) {
20290
- addUsedFrom(node.init);
20291
- }
20292
- if (node instanceof ForLoop) {
20293
- if (node.init) addUsedFrom(node.init);
20294
- if (node.update) addUsedFrom(node.update);
20295
- if (node.condition && node.condition.raw) addUsedFrom(node.condition.raw);
20296
- scanForAutoImport(node.bodyTemplate);
20297
- }
20298
- if (node instanceof WhileLoop) {
20299
- if (node.condition && node.condition.raw) addUsedFrom(node.condition.raw);
20300
- scanForAutoImport(node.bodyTemplate);
20301
- }
20302
- if (node instanceof SwitchBlock) {
20303
- if (node.discriminant && node.discriminant.raw) addUsedFrom(node.discriminant.raw);
20304
- for (const c of node.cases) {
20305
- if (c.test && c.test.raw) addUsedFrom(c.test.raw);
20306
- scanForAutoImport(c.body);
20307
- }
20308
- }
20309
- if (node instanceof TryCatch) {
20310
- scanForAutoImport(node.bodyTemplate);
20311
- scanForAutoImport(node.catchBody);
20312
- }
20313
- if (node instanceof ComponentCall) {
20314
- if (autoImportable.includes(node.componentName)) {
20315
- usedFunctions.add(node.componentName);
20316
- }
20317
- for (const prop of node.props) {
20318
- if (prop.value && prop.value.raw) {
20319
- addUsedFrom(prop.value.raw);
20320
- }
20321
- }
20322
- scanForAutoImport(node.children);
20323
- }
20324
- if (node instanceof MapRegion) {
20325
- scanForAutoImport(node.bodyTemplate);
20326
- scanForAutoImport(node.alternateNodes);
20327
- }
20328
- if (node instanceof OpaqueDynamicRegion) {
20329
- scanForAutoImport(node.consequentNodes);
20330
- scanForAutoImport(node.alternateNodes);
20331
- }
20332
- if (node instanceof DynamicBinding && node.expression && node.expression.raw) {
20333
- addUsedFrom(node.expression.raw);
20334
- }
20335
- if (node instanceof StaticNode || node instanceof ServerBlock || node instanceof ClientBlock || node instanceof HeadBlock) {
20336
- scanForAutoImport(node.children);
20337
- }
20338
- }
20270
+ for (const fn of autoImportable) {
20271
+ if (called.has(fn)) usedFunctions.add(fn);
20339
20272
  }
20340
- scanForAutoImport(components.flatMap((c) => c.body));
20341
20273
  if (usedFunctions.size > 0) {
20342
20274
  const existing = /* @__PURE__ */ new Set();
20343
20275
  for (const imp of imports) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "type": "module",
5
5
  "description": "Vesk — compiler-first framework for the post-VDOM web. vesk dev, vesk build.",
6
6
  "bin": {
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "main": "./dist/cli.js",
10
10
  "dependencies": {
11
- "@vesk/adapter": "^0.2.27",
12
- "@vesk/compiler": "^0.2.27",
13
- "@vesk/plugin-tailwind": "^0.2.27",
14
- "@vesk/runtime": "^0.2.27",
11
+ "@vesk/adapter": "^0.2.28",
12
+ "@vesk/compiler": "^0.2.28",
13
+ "@vesk/plugin-tailwind": "^0.2.28",
14
+ "@vesk/runtime": "^0.2.28",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",