@flint.fyi/svelte-language 0.0.3 → 0.0.5

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,5 +1,4 @@
1
+ import type { AST } from "svelte/compiler";
1
2
  import { type SourceFileWithLineMap } from "@flint.fyi/core";
2
3
  import type { ExtractedDirective } from "@flint.fyi/typescript-language";
3
- import type { AST } from "svelte/compiler";
4
4
  export declare function extractDirectives(ast: AST.Root, source: SourceFileWithLineMap): ExtractedDirective[];
5
- //# sourceMappingURL=extractDirectives.d.ts.map
@@ -23,5 +23,3 @@ function extractDirectives(ast, source) {
23
23
  }
24
24
  //#endregion
25
25
  export { extractDirectives };
26
-
27
- //# sourceMappingURL=extractDirectives.js.map
package/lib/language.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import { AST } from "svelte/compiler";
2
- import * as _flint_fyi_core0 from "@flint.fyi/core";
3
- import * as _flint_fyi_typescript_language0 from "@flint.fyi/typescript-language";
4
2
 
5
3
  //#region src/language.d.ts
6
4
  interface SvelteServices {
@@ -9,7 +7,6 @@ interface SvelteServices {
9
7
  sourceText: string;
10
8
  };
11
9
  }
12
- declare const svelteLanguage: _flint_fyi_core0.Language<_flint_fyi_typescript_language0.TypeScriptNodesByName, Partial<SvelteServices> & _flint_fyi_typescript_language0.TypeScriptFileServices>;
10
+ declare const svelteLanguage: import("@flint.fyi/core").Language<import("@flint.fyi/typescript-language").TypeScriptNodesByName, Partial<SvelteServices> & import("@flint.fyi/typescript-language").TypeScriptFileServices>;
13
11
  //#endregion
14
- export { svelteLanguage };
15
- //# sourceMappingURL=language.d.ts.map
12
+ export { SvelteServices, svelteLanguage };
package/lib/language.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { extractDirectives } from "./extractDirectives.js";
2
2
  import { errorToLanguageReport, virtualCodeReports, volarLanguagePlugin } from "./volarLanguagePlugin.js";
3
+ import { parse } from "svelte/compiler";
3
4
  import { setTSExtraSupportedExtensions } from "@flint.fyi/ts-patch";
4
5
  import { createVolarBasedLanguage } from "@flint.fyi/volar-language";
5
- import { parse } from "svelte/compiler";
6
6
  //#region src/language.ts
7
7
  setTSExtraSupportedExtensions([".svelte"]);
8
8
  const svelteLanguage = createVolarBasedLanguage((ts, options) => {
@@ -61,5 +61,3 @@ const svelteLanguage = createVolarBasedLanguage((ts, options) => {
61
61
  });
62
62
  //#endregion
63
63
  export { svelteLanguage };
64
-
65
- //# sourceMappingURL=language.js.map
@@ -1,7 +1,7 @@
1
- import { type LanguageReport } from "@flint.fyi/core";
2
1
  import { type LanguagePlugin, type VirtualCode } from "@volar/language-core";
3
- import type * as ts from "typescript";
4
- export declare function volarLanguagePlugin(ts: typeof import("typescript"), options: ts.CreateProgramOptions): LanguagePlugin<string>;
2
+ import type ts from "typescript";
3
+ import type { CreateProgramOptions } from "typescript";
4
+ import { type LanguageReport } from "@flint.fyi/core";
5
+ export declare function volarLanguagePlugin(typescript: typeof ts, options: CreateProgramOptions): LanguagePlugin<string>;
5
6
  export declare const virtualCodeReports: WeakMap<VirtualCode, LanguageReport>;
6
7
  export declare function errorToLanguageReport(fileName: string, error: unknown): LanguageReport;
7
- //# sourceMappingURL=volarLanguagePlugin.d.ts.map
@@ -1,20 +1,20 @@
1
1
  import { getPositionOfColumnAndLine } from "@flint.fyi/core";
2
- import { decode } from "@jridgewell/sourcemap-codec";
3
- import { forEachEmbeddedCode } from "@volar/language-core";
4
2
  import path from "node:path";
5
3
  import url from "node:url";
4
+ import { decode } from "@jridgewell/sourcemap-codec";
5
+ import { forEachEmbeddedCode } from "@volar/language-core";
6
6
  import { internalHelpers, svelte2tsx } from "svelte2tsx";
7
7
  //#region src/volarLanguagePlugin.ts
8
8
  const sveltePath = path.dirname(url.fileURLToPath(import.meta.resolve("svelte/package.json")));
9
9
  const svelte2tsxPath = path.dirname(url.fileURLToPath(import.meta.resolve("svelte2tsx/package.json")));
10
- function volarLanguagePlugin(ts, options) {
11
- const cwd = typeof options.options.configFilePath === "string" ? path.dirname(options.options.configFilePath) : (options.host ?? ts.sys).getCurrentDirectory();
10
+ function volarLanguagePlugin(typescript, options) {
11
+ const cwd = typeof options.options.configFilePath === "string" ? path.dirname(options.options.configFilePath) : (options.host ?? typescript.sys).getCurrentDirectory();
12
12
  return {
13
13
  createVirtualCode(fileName, languageId, snapshot) {
14
14
  if (languageId !== "svelte") return;
15
15
  return {
16
16
  codegenStacks: [],
17
- embeddedCodes: [getEmbeddedTsCode(ts, cwd, fileName, snapshot.getText(0, snapshot.getLength()))],
17
+ embeddedCodes: [getEmbeddedTsCode(typescript, cwd, fileName, snapshot.getText(0, snapshot.getLength()))],
18
18
  id: "root",
19
19
  languageId,
20
20
  mappings: [],
@@ -40,20 +40,34 @@ function volarLanguagePlugin(ts, options) {
40
40
  },
41
41
  updateVirtualCode(fileName, virtualCode, snapshot) {
42
42
  virtualCode.snapshot = snapshot;
43
- virtualCode.embeddedCodes = [getEmbeddedTsCode(ts, cwd, fileName, snapshot.getText(0, snapshot.getLength()))];
43
+ virtualCode.embeddedCodes = [getEmbeddedTsCode(typescript, cwd, fileName, snapshot.getText(0, snapshot.getLength()))];
44
44
  return virtualCode;
45
45
  }
46
46
  };
47
47
  }
48
48
  const virtualCodeReports = /* @__PURE__ */ new WeakMap();
49
49
  function errorToLanguageReport(fileName, error) {
50
- if (typeof error !== "object" || error == null) return { text: `${fileName} - Unknown error` };
51
- const res = { text: `${fileName}${"position" in error && Array.isArray(error.position) ? `:${error.position[0]}:${error.position[1]}` : ""} - ${"message" in error && typeof error.message === "string" ? error.message : "Codegen error"}` };
50
+ if (typeof error !== "object" || error == null) return {
51
+ source: "svelte",
52
+ text: `${fileName} - Unknown error`
53
+ };
54
+ const svelteError = isSvelteCompileError(error) ? error : null;
55
+ const res = {
56
+ source: "svelte",
57
+ text: `${fileName}${svelteError?.start != null ? `:${svelteError.start.line}:${svelteError.start.column}` : ""} - ${"message" in error && typeof error.message === "string" ? error.message : "Codegen error"}`
58
+ };
59
+ if (svelteError?.start != null) res.range = {
60
+ begin: svelteError.start.character,
61
+ end: svelteError.end?.character ?? svelteError.start.character
62
+ };
52
63
  if ("code" in error && typeof error.code === "string") res.code = error.code;
53
64
  return res;
54
65
  }
55
- function getEmbeddedTsCode(ts, cwd, fileName, text) {
56
- const svelteTsxFiles = internalHelpers.get_global_types(ts.sys, false, sveltePath, svelte2tsxPath, cwd);
66
+ function isSvelteCompileError(error) {
67
+ return "start" in error && typeof error.start === "object" && error.start !== null && "character" in error.start && typeof error.start.character === "number";
68
+ }
69
+ function getEmbeddedTsCode(typescript, cwd, fileName, text) {
70
+ const svelteTsxFiles = internalHelpers.get_global_types(typescript.sys, false, sveltePath, svelte2tsxPath, cwd);
57
71
  try {
58
72
  const tsx = svelte2tsx(text, {
59
73
  isTsFile: true,
@@ -145,5 +159,3 @@ function getEmbeddedTsCode(ts, cwd, fileName, text) {
145
159
  }
146
160
  //#endregion
147
161
  export { errorToLanguageReport, virtualCodeReports, volarLanguagePlugin };
148
-
149
- //# sourceMappingURL=volarLanguagePlugin.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flint.fyi/svelte-language",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "[Experimental] Svelte language for Flint.",
5
5
  "homepage": "https://flint.fyi",
6
6
  "repository": {
@@ -19,23 +19,22 @@
19
19
  ".": "./lib/index.js"
20
20
  },
21
21
  "files": [
22
- "lib/",
23
- "!lib/**/*.map"
22
+ "lib/"
24
23
  ],
25
24
  "dependencies": {
26
25
  "@jridgewell/sourcemap-codec": "^1.5.5",
27
26
  "@volar/language-core": "2.4.28",
28
27
  "svelte": "^5.0.0",
29
- "svelte2tsx": "^0.7.52",
28
+ "svelte2tsx": "^0.7.55",
30
29
  "typescript": "^5.9.0 || ^6.0.0",
31
- "@flint.fyi/typescript-language": "^0.18.2",
32
- "@flint.fyi/core": "^0.22.0",
33
- "@flint.fyi/ts-patch": "^0.13.5",
30
+ "@flint.fyi/core": "^0.23.3",
31
+ "@flint.fyi/ts-patch": "^0.14.0",
34
32
  "@flint.fyi/utils": "^0.14.1",
35
- "@flint.fyi/volar-language": "^0.1.1"
33
+ "@flint.fyi/volar-language": "^0.1.4",
34
+ "@flint.fyi/typescript-language": "^0.18.4"
36
35
  },
37
36
  "devDependencies": {
38
- "tsdown": "0.21.0",
37
+ "tsdown": "0.22.3",
39
38
  "vitest": "4.1.0"
40
39
  },
41
40
  "engines": {