@volar/language-core 1.4.0-alpha.0 → 1.4.0-alpha.10

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/out/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
3
  if (k2 === undefined) k2 = k;
3
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,7 +1,9 @@
1
1
  import type * as ts from 'typescript/lib/tsserverlibrary';
2
2
  import { LanguageModule, LanguageServiceHost } from './types';
3
3
  export type LanguageContext = ReturnType<typeof createLanguageContext>;
4
- export declare function createLanguageContext(host: LanguageServiceHost, languageModules: LanguageModule[]): {
4
+ export declare function createLanguageContext(host: LanguageServiceHost, modules: {
5
+ typescript?: typeof import('typescript/lib/tsserverlibrary');
6
+ }, languageModules: LanguageModule[]): {
5
7
  typescript: {
6
8
  languageServiceHost: ts.LanguageServiceHost;
7
9
  };
@@ -1,10 +1,10 @@
1
+ "use strict";
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
3
  exports.createLanguageContext = void 0;
3
4
  const path_1 = require("path");
4
5
  const virtualFiles_1 = require("./virtualFiles");
5
6
  const types_1 = require("./types");
6
- function createLanguageContext(host, languageModules) {
7
- var _a;
7
+ function createLanguageContext(host, modules, languageModules) {
8
8
  for (const languageModule of languageModules.reverse()) {
9
9
  if (languageModule.proxyLanguageServiceHost) {
10
10
  const proxyApis = languageModule.proxyLanguageServiceHost(host);
@@ -21,7 +21,7 @@ function createLanguageContext(host, languageModules) {
21
21
  let lastProjectVersion;
22
22
  let tsProjectVersion = 0;
23
23
  const virtualFiles = (0, virtualFiles_1.createVirtualFiles)(languageModules);
24
- const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
24
+ const ts = modules.typescript;
25
25
  const scriptSnapshots = new Map();
26
26
  const sourceTsFileVersions = new Map();
27
27
  const sourceFileVersions = new Map();
@@ -29,7 +29,6 @@ function createLanguageContext(host, languageModules) {
29
29
  const _tsHost = {
30
30
  fileExists: host.fileExists
31
31
  ? fileName => {
32
- var _a, _b;
33
32
  const ext = fileName.substring(fileName.lastIndexOf('.'));
34
33
  if (ext === '.js'
35
34
  || ext === '.ts'
@@ -46,14 +45,14 @@ function createLanguageContext(host, languageModules) {
46
45
  if (!virtualFiles.hasSource(sourceFileName)) {
47
46
  const scriptSnapshot = host.getScriptSnapshot(sourceFileName);
48
47
  if (scriptSnapshot) {
49
- virtualFiles.updateSource(sourceFileName, scriptSnapshot, (_a = host.getScriptLanguageId) === null || _a === void 0 ? void 0 : _a.call(host, sourceFileName));
48
+ virtualFiles.updateSource(sourceFileName, scriptSnapshot, host.getScriptLanguageId?.(sourceFileName));
50
49
  }
51
50
  }
52
51
  }
53
52
  if (virtualFiles.hasVirtualFile(fileName)) {
54
53
  return true;
55
54
  }
56
- return !!((_b = host.fileExists) === null || _b === void 0 ? void 0 : _b.call(host, fileName));
55
+ return !!host.fileExists?.(fileName);
57
56
  }
58
57
  : undefined,
59
58
  getProjectVersion: () => {
@@ -63,8 +62,7 @@ function createLanguageContext(host, languageModules) {
63
62
  getScriptVersion,
64
63
  getScriptSnapshot,
65
64
  readDirectory: (_path, extensions, exclude, include, depth) => {
66
- var _a, _b;
67
- const result = (_b = (_a = host.readDirectory) === null || _a === void 0 ? void 0 : _a.call(host, _path, extensions, exclude, include, depth)) !== null && _b !== void 0 ? _b : [];
65
+ const result = host.readDirectory?.(_path, extensions, exclude, include, depth) ?? [];
68
66
  for (const { fileName } of virtualFiles.allSources()) {
69
67
  const vuePath2 = path_1.posix.join(_path, path_1.posix.basename(fileName));
70
68
  if (path_1.posix.relative(_path.toLowerCase(), fileName.toLowerCase()).startsWith('..')) {
@@ -112,8 +110,7 @@ function createLanguageContext(host, languageModules) {
112
110
  }),
113
111
  };
114
112
  function update() {
115
- var _a, _b, _c;
116
- const newProjectVersion = (_a = host.getProjectVersion) === null || _a === void 0 ? void 0 : _a.call(host);
113
+ const newProjectVersion = host.getProjectVersion?.();
117
114
  const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion;
118
115
  lastProjectVersion = newProjectVersion;
119
116
  if (!shouldUpdate)
@@ -136,7 +133,7 @@ function createLanguageContext(host, languageModules) {
136
133
  if (sourceFileVersions.get(fileName) !== newVersion) {
137
134
  // update
138
135
  sourceFileVersions.set(fileName, newVersion);
139
- virtualFiles.updateSource(fileName, snapshot, (_b = host.getScriptLanguageId) === null || _b === void 0 ? void 0 : _b.call(host, fileName));
136
+ virtualFiles.updateSource(fileName, snapshot, host.getScriptLanguageId?.(fileName));
140
137
  virtualFilesUpdatedNum++;
141
138
  }
142
139
  }
@@ -148,7 +145,7 @@ function createLanguageContext(host, languageModules) {
148
145
  for (const fileName of [...remainRootFiles]) {
149
146
  const snapshot = host.getScriptSnapshot(fileName);
150
147
  if (snapshot) {
151
- const virtualFile = virtualFiles.updateSource(fileName, snapshot, (_c = host.getScriptLanguageId) === null || _c === void 0 ? void 0 : _c.call(host, fileName));
148
+ const virtualFile = virtualFiles.updateSource(fileName, snapshot, host.getScriptLanguageId?.(fileName));
152
149
  if (virtualFile) {
153
150
  remainRootFiles.delete(fileName);
154
151
  }
@@ -180,9 +177,8 @@ function createLanguageContext(host, languageModules) {
180
177
  for (const { root: rootVirtualFile } of virtualFiles.allSources()) {
181
178
  if (!shouldUpdateTsProject) {
182
179
  (0, virtualFiles_1.forEachEmbeddedFile)(rootVirtualFile, embedded => {
183
- var _a;
184
180
  if (embedded.kind === types_1.FileKind.TypeScriptHostFile) {
185
- if (virtualFileVersions.has(embedded.fileName) && ((_a = virtualFileVersions.get(embedded.fileName)) === null || _a === void 0 ? void 0 : _a.virtualFileSnapshot) !== embedded.snapshot) {
181
+ if (virtualFileVersions.has(embedded.fileName) && virtualFileVersions.get(embedded.fileName)?.virtualFileSnapshot !== embedded.snapshot) {
186
182
  shouldUpdateTsProject = true;
187
183
  }
188
184
  }
package/out/sourceMaps.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
3
  exports.MirrorMap = void 0;
3
4
  const SourceMaps = require("@volar/source-map");
package/out/types.d.ts CHANGED
@@ -59,7 +59,6 @@ export interface LanguageModule<T extends VirtualFile = VirtualFile> {
59
59
  proxyLanguageServiceHost?(host: LanguageServiceHost): Partial<LanguageServiceHost>;
60
60
  }
61
61
  export interface LanguageServiceHost extends ts.LanguageServiceHost {
62
- getTypeScriptModule?(): typeof import('typescript/lib/tsserverlibrary');
63
62
  getScriptLanguageId?(fileName: string): string | undefined;
64
63
  isTsc?: boolean;
65
64
  }
package/out/types.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
3
  exports.FileKind = exports.MirrorBehaviorCapabilities = exports.FileRangeCapabilities = exports.FileCapabilities = void 0;
3
4
  var FileCapabilities;
@@ -1,6 +1,7 @@
1
1
  import { SourceMap } from '@volar/source-map';
2
+ import type * as ts from 'typescript/lib/tsserverlibrary';
2
3
  import { MirrorMap } from './sourceMaps';
3
- import type { LanguageModule, FileRangeCapabilities, VirtualFile } from './types';
4
+ import type { FileRangeCapabilities, LanguageModule, VirtualFile } from './types';
4
5
  export type VirtualFiles = ReturnType<typeof createVirtualFiles>;
5
6
  export interface Source {
6
7
  fileName: string;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
3
  exports.forEachEmbeddedFile = exports.createVirtualFiles = void 0;
3
4
  const source_map_1 = require("@volar/source-map");
@@ -31,11 +32,10 @@ function createVirtualFiles(languageModules) {
31
32
  }
32
33
  },
33
34
  deleteSource(fileName) {
34
- var _a, _b;
35
35
  const key = normalizePath(fileName);
36
36
  const value = sourceFiles.get(key);
37
37
  if (value) {
38
- (_b = (_a = value.languageModule).deleteFile) === null || _b === void 0 ? void 0 : _b.call(_a, value.root);
38
+ value.languageModule.deleteFile?.(value.root);
39
39
  sourceFiles.delete(key); // deleted
40
40
  sourceFilesDirty = true;
41
41
  }
@@ -81,7 +81,7 @@ function createVirtualFiles(languageModules) {
81
81
  sources.add(map.source);
82
82
  }
83
83
  for (const source of sources) {
84
- const sourceFileName = source !== null && source !== void 0 ? source : getVirtualFilesMap().get(normalizePath(virtualFile.fileName)).source.fileName;
84
+ const sourceFileName = source ?? getVirtualFilesMap().get(normalizePath(virtualFile.fileName)).source.fileName;
85
85
  if (!sourceMapsBySourceFileName.has(sourceFileName)) {
86
86
  sourceMapsBySourceFileName.set(sourceFileName, [
87
87
  sourceFileName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-core",
3
- "version": "1.4.0-alpha.0",
3
+ "version": "1.4.0-alpha.10",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/source-map": "1.4.0-alpha.0"
16
+ "@volar/source-map": "1.4.0-alpha.10"
17
17
  },
18
- "gitHead": "2607410cae341cf802b446062d446ad497be2057"
18
+ "gitHead": "715bc5f17a0d1cadd4190712dcaff732989eb330"
19
19
  }