@statorjs/language-server 0.1.0 → 0.1.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/server.cjs +35 -4
  2. package/package.json +2 -2
package/dist/server.cjs CHANGED
@@ -45328,8 +45328,37 @@ function extractFrontmatterTypes(fm) {
45328
45328
  var import_typescript6 = __toESM(require("typescript"), 1);
45329
45329
 
45330
45330
  // ../stator/src/compiler/virtual-code.ts
45331
- var TEMPLATE_IMPORTS = "import { read, each, when, match, on, classList, styleList, raw } from '@statorjs/stator/template';\n";
45332
- var CLIENT_IMPORTS = "import { StatorElement, use, machine, defineElement, bind, effect, dispatch } from '@statorjs/stator/client';\n";
45331
+ var TEMPLATE_GLOBALS = ["read", "each", "when", "match", "on", "classList", "styleList"];
45332
+ var CLIENT_GLOBALS = [
45333
+ "StatorElement",
45334
+ "use",
45335
+ "machine",
45336
+ "defineElement",
45337
+ "bind",
45338
+ "effect",
45339
+ "dispatch"
45340
+ ];
45341
+ function userImportedLocals(code, modulePath) {
45342
+ const locals = /* @__PURE__ */ new Set();
45343
+ const re = new RegExp(
45344
+ `import\\s+(?:type\\s+)?\\{([^}]*)\\}\\s+from\\s+['"]${modulePath.replace(/\//g, "\\/")}['"]`,
45345
+ "g"
45346
+ );
45347
+ for (const m of code.matchAll(re)) {
45348
+ for (const spec of m[1].split(",")) {
45349
+ const parts = spec.trim().split(/\s+as\s+/);
45350
+ const local = (parts[1] ?? parts[0] ?? "").trim().replace(/^type\s+/, "");
45351
+ if (local) locals.add(local);
45352
+ }
45353
+ }
45354
+ return locals;
45355
+ }
45356
+ function injectImports(globals, modulePath, userCode) {
45357
+ const bound = userImportedLocals(userCode, modulePath);
45358
+ const missing = globals.filter((g) => !bound.has(g));
45359
+ return missing.length > 0 ? `import { ${missing.join(", ")} } from '${modulePath}';
45360
+ ` : "";
45361
+ }
45333
45362
  var AMBIENT_TYPE_IMPORTS = "import type { AnyMachineDef as __SMachineDef } from '@statorjs/stator/machine';\nimport type { InstanceOf as __SInstanceOf } from '@statorjs/stator/template';\n";
45334
45363
  var STATOR_AMBIENT = `declare const Stator: {
45335
45364
  props<P>(): P;
@@ -45354,7 +45383,8 @@ function toVirtualCode(source) {
45354
45383
  }
45355
45384
  function buildServerTsx(regions) {
45356
45385
  const mappings = [];
45357
- let code = TEMPLATE_IMPORTS + AMBIENT_TYPE_IMPORTS + STATOR_AMBIENT;
45386
+ const userCode = (regions.frontmatter?.content ?? "") + regions.template.content;
45387
+ let code = injectImports(TEMPLATE_GLOBALS, "@statorjs/stator/template", userCode) + AMBIENT_TYPE_IMPORTS + STATOR_AMBIENT;
45358
45388
  if (regions.frontmatter?.content.trim()) {
45359
45389
  push(
45360
45390
  mappings,
@@ -45385,7 +45415,8 @@ function buildServerTsx(regions) {
45385
45415
  }
45386
45416
  function buildClientTsx(regions) {
45387
45417
  const mappings = [];
45388
- let code = TEMPLATE_IMPORTS + CLIENT_IMPORTS + AMBIENT_TYPE_IMPORTS + STATOR_AMBIENT;
45418
+ const userScript = regions.scripts.map((s) => s.content).join("\n");
45419
+ let code = injectImports(TEMPLATE_GLOBALS, "@statorjs/stator/template", userScript) + injectImports(CLIENT_GLOBALS, "@statorjs/stator/client", userScript) + AMBIENT_TYPE_IMPORTS + STATOR_AMBIENT;
45389
45420
  for (const script of regions.scripts) {
45390
45421
  push(mappings, script.contentOffset, code.length, script.content.length);
45391
45422
  code += `${script.content}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statorjs/language-server",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Volar-based language server for .stator files.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  "volar-service-typescript": "0.0.71",
34
34
  "vscode-css-languageservice": "^6.3.0",
35
35
  "vscode-uri": "^3.0.8",
36
- "@statorjs/stator": "1.0.0"
36
+ "@statorjs/stator": "1.1.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "typescript": "^5.6.0"