@flint.fyi/volar-language 0.3.0 → 0.4.0

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.
package/dist/index.d.mts CHANGED
@@ -3,7 +3,6 @@ import { FileAboutData, FileReport, Language, LanguageFileCacheImpacts, Language
3
3
  import { AST, ExtractedDirective, TypeScriptFileServices, TypeScriptNodesByName } from "@flint.fyi/typescript-language";
4
4
  import { Language as Language$1, LanguagePlugin, SourceScript } from "@volar/language-core";
5
5
  import { TypeScriptServiceScript } from "@volar/typescript";
6
-
7
6
  //#region src/language.d.ts
8
7
  type VolarLanguagePluginInitializer<FileServices extends object> = (typescript: typeof ts, options: CreateProgramOptions) => {
9
8
  createFile: VolarBasedLanguageCreateFile<FileServices>;
@@ -28,7 +27,7 @@ type VolarBasedLanguageCreateFile<FileServices extends object> = (ctx: VolarBase
28
27
  reports?: FileReport[];
29
28
  };
30
29
  type VolarLanguage<FileServices extends object> = Language<TypeScriptNodesByName, Partial<FileServices> & TypeScriptFileServices>;
31
- declare function createVolarBasedLanguage<FileServices extends object>(initializer: VolarLanguagePluginInitializer<FileServices>): VolarLanguage<FileServices>;
32
- declare function reportSourceCode<T extends string>(context: RuleContext<T>, report: RuleReport<T>): void;
30
+ export declare function createVolarBasedLanguage<FileServices extends object>(initializer: VolarLanguagePluginInitializer<FileServices>): VolarLanguage<FileServices>;
31
+ export declare function reportSourceCode<T extends string>(context: RuleContext<T>, report: RuleReport<T>): void;
33
32
  //#endregion
34
- export { type VolarLanguage, createVolarBasedLanguage, reportSourceCode };
33
+ export type { VolarLanguage };
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { proxyCreateProgram } from "@volar/typescript/lib/node/proxyCreateProgram.js";
2
- import { getPreEmitDiagnostics } from "typescript";
3
- import { DirectivesCollector, createLanguage, getColumnAndLineOfPosition, isSuggestionForFiles } from "@flint.fyi/core";
2
+ import { SyntaxKind, getPreEmitDiagnostics } from "typescript";
3
+ import { DirectivesCollector, createLanguage, getColumnAndLineOfPosition, isSuggestionForFiles, runFileVisitorSubscriptions } from "@flint.fyi/core";
4
4
  import { setTSProgramCreationProxy } from "@flint.fyi/ts-patch";
5
- import { NodeSyntaxKinds, convertTypeScriptDiagnosticToLanguageReport, extractDirectivesFromTypeScriptFile, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage } from "@flint.fyi/typescript-language";
5
+ import { convertTypeScriptDiagnosticToLanguageReport, createNodeVisitorsForFile, extractDirectivesFromTypeScriptFile, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage } from "@flint.fyi/typescript-language";
6
6
  import { FlintAssertionError, assert, nullThrows } from "@flint.fyi/utils";
7
7
  //#region package.json
8
8
  var name = "@flint.fyi/volar-language";
9
- var version = "0.3.0";
9
+ var version = "0.4.0";
10
10
  //#endregion
11
11
  //#region src/language.ts
12
12
  const stateSymbol = Symbol.for("@flint.fyi/volar-language/state");
@@ -18,7 +18,7 @@ const { pluginInitializers } = globalTyped[stateSymbol] = {
18
18
  };
19
19
  setTSProgramCreationProxy((ts, createProgram) => new Proxy(function() {}, { apply(_, thisArg, args) {
20
20
  let volarLanguage = null;
21
- const proxied = proxyCreateProgram(ts, new Proxy(createProgram, { apply(target, thisArg, [options]) {
21
+ const createProgramProxy = new Proxy(createProgram, { apply(target, thisArg, [options]) {
22
22
  assert(options.host != null, "Expected options.host to be defined");
23
23
  const patchedGetSourceFile = options.host.getSourceFile.bind(options.host);
24
24
  options.host.getSourceFile = (...args) => {
@@ -30,7 +30,8 @@ setTSProgramCreationProxy((ts, createProgram) => new Proxy(function() {}, { appl
30
30
  }
31
31
  };
32
32
  return Reflect.apply(target, thisArg, args);
33
- } }), (ts, options) => {
33
+ } });
34
+ const proxied = proxyCreateProgram(ts, createProgramProxy, (ts, options) => {
34
35
  return {
35
36
  languagePlugins: Array.from(pluginInitializers).map((initializer) => initializer(ts, options)).flatMap(({ createFile, languagePlugins }) => languagePlugins.map((plugin) => {
36
37
  if (plugin.typescript == null) return plugin;
@@ -100,21 +101,13 @@ setVolarCreateFile((data, program, sourceFile) => {
100
101
  const collected = directivesCollector.collect();
101
102
  return {
102
103
  __volarServices: {
103
- runVisitors(file, options, runtime) {
104
- const { visitors } = runtime;
104
+ runVisitors(fileVisitors) {
105
+ const visitors = createNodeVisitorsForFile(fileVisitors);
105
106
  if (!visitors) return;
106
- const visitorServices = {
107
- options,
108
- ...file.services
109
- };
107
+ const { enter, exit, visit } = visitors;
110
108
  let lastMappingIdx = 0;
111
- const visit = (node) => {
112
- const key = NodeSyntaxKinds[node.kind];
113
- visitors[key]?.(node, visitorServices);
114
- node.forEachChild(visit);
115
- visitors[`${key}:exit`]?.(node, visitorServices);
116
- };
117
- visitors.SourceFile?.(sourceFile, visitorServices);
109
+ const sourceFileEnter = enter?.[SyntaxKind.SourceFile];
110
+ if (sourceFileEnter !== void 0) runFileVisitorSubscriptions(sourceFileEnter, sourceFile);
118
111
  Statements: for (const statement of sourceFile.statements) {
119
112
  while (true) {
120
113
  const currentMapping = sortedMappings[lastMappingIdx];
@@ -131,7 +124,8 @@ setVolarCreateFile((data, program, sourceFile) => {
131
124
  visit(statement);
132
125
  }
133
126
  visit(sourceFile.endOfFileToken);
134
- visitors["SourceFile:exit"]?.(sourceFile, visitorServices);
127
+ const sourceFileExit = exit?.[SyntaxKind.SourceFile];
128
+ if (sourceFileExit !== void 0) runFileVisitorSubscriptions(sourceFileExit, sourceFile);
135
129
  },
136
130
  getLanguageReports() {
137
131
  return [...getPreEmitDiagnostics(program, sourceFile).map((diagnostic) => convertTypeScriptDiagnosticToLanguageReport({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flint.fyi/volar-language",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "[Experimental] Volar.js language for Flint.",
5
5
  "homepage": "https://flint.fyi",
6
6
  "repository": {
@@ -22,18 +22,18 @@
22
22
  "dist/"
23
23
  ],
24
24
  "dependencies": {
25
+ "@flint.fyi/core": "^0.27.0",
26
+ "@flint.fyi/ts-patch": "^0.17.0",
27
+ "@flint.fyi/typescript-language": "^0.21.0",
28
+ "@flint.fyi/utils": "^0.16.0",
25
29
  "@volar/language-core": "2.4.28",
26
30
  "@volar/typescript": "2.4.28",
27
- "typescript": "^5.9.0 || ^6.0.0",
28
- "@flint.fyi/core": "^0.25.0",
29
- "@flint.fyi/ts-patch": "^0.16.0",
30
- "@flint.fyi/utils": "^0.16.0",
31
- "@flint.fyi/typescript-language": "^0.20.0"
31
+ "typescript": "^6.0.3"
32
32
  },
33
33
  "devDependencies": {
34
- "tsdown": "0.22.3",
35
- "vitest": "4.1.0",
36
- "@flint.fyi/build": "^0.1.0"
34
+ "@flint.fyi/build": "^0.1.0",
35
+ "tsdown": "0.23.0",
36
+ "vitest": "5.0.1"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=26.1.0"