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

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.
@@ -4,7 +4,6 @@ const path_1 = require("path");
4
4
  const virtualFiles_1 = require("./virtualFiles");
5
5
  const types_1 = require("./types");
6
6
  function createLanguageContext(host, languageModules) {
7
- var _a;
8
7
  for (const languageModule of languageModules.reverse()) {
9
8
  if (languageModule.proxyLanguageServiceHost) {
10
9
  const proxyApis = languageModule.proxyLanguageServiceHost(host);
@@ -21,7 +20,7 @@ function createLanguageContext(host, languageModules) {
21
20
  let lastProjectVersion;
22
21
  let tsProjectVersion = 0;
23
22
  const virtualFiles = (0, virtualFiles_1.createVirtualFiles)(languageModules);
24
- const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
23
+ const ts = host.getTypeScriptModule?.();
25
24
  const scriptSnapshots = new Map();
26
25
  const sourceTsFileVersions = new Map();
27
26
  const sourceFileVersions = new Map();
@@ -29,7 +28,6 @@ function createLanguageContext(host, languageModules) {
29
28
  const _tsHost = {
30
29
  fileExists: host.fileExists
31
30
  ? fileName => {
32
- var _a, _b;
33
31
  const ext = fileName.substring(fileName.lastIndexOf('.'));
34
32
  if (ext === '.js'
35
33
  || ext === '.ts'
@@ -46,14 +44,14 @@ function createLanguageContext(host, languageModules) {
46
44
  if (!virtualFiles.hasSource(sourceFileName)) {
47
45
  const scriptSnapshot = host.getScriptSnapshot(sourceFileName);
48
46
  if (scriptSnapshot) {
49
- virtualFiles.updateSource(sourceFileName, scriptSnapshot, (_a = host.getScriptLanguageId) === null || _a === void 0 ? void 0 : _a.call(host, sourceFileName));
47
+ virtualFiles.updateSource(sourceFileName, scriptSnapshot, host.getScriptLanguageId?.(sourceFileName));
50
48
  }
51
49
  }
52
50
  }
53
51
  if (virtualFiles.hasVirtualFile(fileName)) {
54
52
  return true;
55
53
  }
56
- return !!((_b = host.fileExists) === null || _b === void 0 ? void 0 : _b.call(host, fileName));
54
+ return !!host.fileExists?.(fileName);
57
55
  }
58
56
  : undefined,
59
57
  getProjectVersion: () => {
@@ -63,8 +61,7 @@ function createLanguageContext(host, languageModules) {
63
61
  getScriptVersion,
64
62
  getScriptSnapshot,
65
63
  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 : [];
64
+ const result = host.readDirectory?.(_path, extensions, exclude, include, depth) ?? [];
68
65
  for (const { fileName } of virtualFiles.allSources()) {
69
66
  const vuePath2 = path_1.posix.join(_path, path_1.posix.basename(fileName));
70
67
  if (path_1.posix.relative(_path.toLowerCase(), fileName.toLowerCase()).startsWith('..')) {
@@ -112,8 +109,7 @@ function createLanguageContext(host, languageModules) {
112
109
  }),
113
110
  };
114
111
  function update() {
115
- var _a, _b, _c;
116
- const newProjectVersion = (_a = host.getProjectVersion) === null || _a === void 0 ? void 0 : _a.call(host);
112
+ const newProjectVersion = host.getProjectVersion?.();
117
113
  const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion;
118
114
  lastProjectVersion = newProjectVersion;
119
115
  if (!shouldUpdate)
@@ -136,7 +132,7 @@ function createLanguageContext(host, languageModules) {
136
132
  if (sourceFileVersions.get(fileName) !== newVersion) {
137
133
  // update
138
134
  sourceFileVersions.set(fileName, newVersion);
139
- virtualFiles.updateSource(fileName, snapshot, (_b = host.getScriptLanguageId) === null || _b === void 0 ? void 0 : _b.call(host, fileName));
135
+ virtualFiles.updateSource(fileName, snapshot, host.getScriptLanguageId?.(fileName));
140
136
  virtualFilesUpdatedNum++;
141
137
  }
142
138
  }
@@ -148,7 +144,7 @@ function createLanguageContext(host, languageModules) {
148
144
  for (const fileName of [...remainRootFiles]) {
149
145
  const snapshot = host.getScriptSnapshot(fileName);
150
146
  if (snapshot) {
151
- const virtualFile = virtualFiles.updateSource(fileName, snapshot, (_c = host.getScriptLanguageId) === null || _c === void 0 ? void 0 : _c.call(host, fileName));
147
+ const virtualFile = virtualFiles.updateSource(fileName, snapshot, host.getScriptLanguageId?.(fileName));
152
148
  if (virtualFile) {
153
149
  remainRootFiles.delete(fileName);
154
150
  }
@@ -180,9 +176,8 @@ function createLanguageContext(host, languageModules) {
180
176
  for (const { root: rootVirtualFile } of virtualFiles.allSources()) {
181
177
  if (!shouldUpdateTsProject) {
182
178
  (0, virtualFiles_1.forEachEmbeddedFile)(rootVirtualFile, embedded => {
183
- var _a;
184
179
  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) {
180
+ if (virtualFileVersions.has(embedded.fileName) && virtualFileVersions.get(embedded.fileName)?.virtualFileSnapshot !== embedded.snapshot) {
186
181
  shouldUpdateTsProject = true;
187
182
  }
188
183
  }
@@ -31,11 +31,10 @@ function createVirtualFiles(languageModules) {
31
31
  }
32
32
  },
33
33
  deleteSource(fileName) {
34
- var _a, _b;
35
34
  const key = normalizePath(fileName);
36
35
  const value = sourceFiles.get(key);
37
36
  if (value) {
38
- (_b = (_a = value.languageModule).deleteFile) === null || _b === void 0 ? void 0 : _b.call(_a, value.root);
37
+ value.languageModule.deleteFile?.(value.root);
39
38
  sourceFiles.delete(key); // deleted
40
39
  sourceFilesDirty = true;
41
40
  }
@@ -81,7 +80,7 @@ function createVirtualFiles(languageModules) {
81
80
  sources.add(map.source);
82
81
  }
83
82
  for (const source of sources) {
84
- const sourceFileName = source !== null && source !== void 0 ? source : getVirtualFilesMap().get(normalizePath(virtualFile.fileName)).source.fileName;
83
+ const sourceFileName = source ?? getVirtualFilesMap().get(normalizePath(virtualFile.fileName)).source.fileName;
85
84
  if (!sourceMapsBySourceFileName.has(sourceFileName)) {
86
85
  sourceMapsBySourceFileName.set(sourceFileName, [
87
86
  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.2",
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.2"
17
17
  },
18
- "gitHead": "2607410cae341cf802b446062d446ad497be2057"
18
+ "gitHead": "034b230da17794a6fcf5a0b07668710f98ff84e3"
19
19
  }