@vesk/compiler 0.2.35 → 0.2.36

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.
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * Resolve `import ... from './path.vsk'` statements so helper components can
3
3
  * live in arbitrary `.vsk` files and be imported into any page, layout,
4
- * component or route file.
4
+ * component or route file. Bare-alias specifiers (`@/components/Button.vsk`,
5
+ * `@app/...` and anything else mapped by tsconfig `paths`) also resolve, so a
6
+ * shared component in `components/` can be imported with the root `@/` alias
7
+ * exactly like in Next.js.
5
8
  */
6
9
  export declare function vskImportTarget(importText: string): string | null;
7
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"vsk-imports.d.ts","sourceRoot":"","sources":["../src/vsk-imports.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AAEH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAahE;AA0BD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAUrF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAKnD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsBhE"}
1
+ {"version":3,"file":"vsk-imports.d.ts","sourceRoot":"","sources":["../src/vsk-imports.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AAEH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAahE;AA0BD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAerF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAKnD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsBhE"}
@@ -3,11 +3,15 @@ import { existsSync } from 'node:fs';
3
3
  import { print } from 'esrap';
4
4
  import ts from 'esrap/languages/ts';
5
5
  import { parse } from '@vesk/compiler/src/parser';
6
+ import { resolveImportPath } from '@vesk/compiler/src/module-imports';
6
7
  import { importModuleTarget, tokenizeCode } from '@vesk/compiler/src/tokens';
7
8
  /**
8
9
  * Resolve `import ... from './path.vsk'` statements so helper components can
9
10
  * live in arbitrary `.vsk` files and be imported into any page, layout,
10
- * component or route file.
11
+ * component or route file. Bare-alias specifiers (`@/components/Button.vsk`,
12
+ * `@app/...` and anything else mapped by tsconfig `paths`) also resolve, so a
13
+ * shared component in `components/` can be imported with the root `@/` alias
14
+ * exactly like in Next.js.
11
15
  */
12
16
  export function vskImportTarget(importText) {
13
17
  const spec = importModuleTarget(importText);
@@ -82,11 +86,17 @@ export function collectVskImportPaths(imports, sourcePath) {
82
86
  if (stripTypeImport(imp) === null)
83
87
  continue;
84
88
  const target = vskImportTarget(imp);
85
- if (!target || !target.startsWith('.'))
89
+ if (!target)
86
90
  continue;
87
- const full = resolve(dirname(sourcePath), target);
88
- if (existsSync(full))
89
- out.push(full);
91
+ if (target.startsWith('.')) {
92
+ const full = resolve(dirname(sourcePath), target);
93
+ if (existsSync(full))
94
+ out.push(full);
95
+ continue;
96
+ }
97
+ const aliased = resolveImportPath(target, dirname(sourcePath));
98
+ if (aliased !== target && existsSync(aliased))
99
+ out.push(aliased);
90
100
  }
91
101
  return out;
92
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/compiler",
3
- "version": "0.2.35",
3
+ "version": "0.2.36",
4
4
  "type": "module",
5
5
  "description": "Vesk compiler — lexer, parser, semantic analysis, IR, codegen",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@sveltejs/acorn-typescript": "^1.0.0",
23
- "@vesk/types": "^0.2.35",
23
+ "@vesk/types": "^0.2.36",
24
24
  "acorn": "^8.15.0",
25
25
  "esrap": "^2.3.0",
26
26
  "is-reference": "^3.0.0",