Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@volar/typescript

Package Overview
Dependencies
Maintainers
1
Versions
222
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@volar/typescript - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

4

lib/node/decorateLanguageServiceHost.d.ts

@@ -1,4 +0,4 @@

import { type FileRegistry } from '@volar/language-core';
import type { FileRegistry } from '@volar/language-core';
import type * as ts from 'typescript';
export declare function decorateLanguageServiceHost(virtualFiles: FileRegistry, languageServiceHost: ts.LanguageServiceHost, ts: typeof import('typescript')): void;
export declare function decorateLanguageServiceHost(files: FileRegistry, languageServiceHost: ts.LanguageServiceHost, ts: typeof import('typescript')): void;
export declare function searchExternalFiles(ts: typeof import('typescript'), project: ts.server.Project, exts: string[]): string[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchExternalFiles = exports.decorateLanguageServiceHost = void 0;
const language_core_1 = require("@volar/language-core");
const resolveModuleName_1 = require("../resolveModuleName");
function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts) {
function decorateLanguageServiceHost(files, languageServiceHost, ts) {
let extraProjectVersion = 0;
const { languagePlugins } = virtualFiles;
const { languagePlugins } = files;
const exts = languagePlugins

@@ -18,2 +17,3 @@ .map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [])

const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost);
const getScriptVersion = languageServiceHost.getScriptVersion.bind(languageServiceHost);
const getScriptKind = languageServiceHost.getScriptKind?.bind(languageServiceHost);

@@ -34,3 +34,3 @@ // path completion

if (languagePlugins.some(language => language.typescript?.extraFileExtensions.length)) {
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, languagePlugins, fileName => virtualFiles.get(fileName));
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, languagePlugins, fileName => files.get(fileName));
if (resolveModuleNameLiterals) {

@@ -69,2 +69,9 @@ languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, ...rest) => {

};
languageServiceHost.getScriptVersion = fileName => {
if (exts.some(ext => fileName.endsWith(ext))) {
updateScript(fileName);
return scripts.get(fileName)?.version.toString() ?? '';
}
return getScriptVersion(fileName);
};
if (getScriptKind) {

@@ -84,36 +91,48 @@ languageServiceHost.getScriptKind = fileName => {

function updateScript(fileName) {
const version = languageServiceHost.getScriptVersion(fileName);
if (version !== scripts.get(fileName)?.version) {
let extension = '.ts';
let snapshotSnapshot;
let scriptKind = ts.ScriptKind.TS;
const snapshot = getScriptSnapshot(fileName);
if (snapshot) {
const version = getProjectVersion?.();
const cache = scripts.get(fileName);
if (version === undefined || version !== cache?.projectVersion) {
const file = files.get(fileName);
const script = file?.generated?.languagePlugin.typescript?.getScript(file.generated.code);
if (script?.code.snapshot !== cache?.snapshot) {
let extension = '.ts';
let snapshotSnapshot;
let scriptKind = ts.ScriptKind.TS;
extraProjectVersion++;
const sourceFile = virtualFiles.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot);
if (sourceFile.generated) {
const text = snapshot.getText(0, snapshot.getLength());
let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
const script = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code);
if (script) {
if (script) {
if (file?.generated) {
const text = file.snapshot.getText(0, file.snapshot.getLength());
let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
extension = script.extension;
scriptKind = script.scriptKind;
patchedText += script.code.snapshot.getText(0, script.code.snapshot.getLength());
snapshotSnapshot = ts.ScriptSnapshot.fromString(patchedText);
if (file.generated.languagePlugin.typescript?.getExtraScripts) {
console.warn('getExtraScripts() is not available in this use case.');
}
}
snapshotSnapshot = ts.ScriptSnapshot.fromString(patchedText);
if (sourceFile.generated.languagePlugin.typescript?.getExtraScripts) {
console.warn('getExtraScripts() is not available in this use case.');
}
}
else if (files.get(fileName)) {
files.delete(fileName);
}
if (!cache) {
scripts.set(fileName, {
projectVersion: version,
version: 0,
extension,
snapshot: snapshotSnapshot,
kind: scriptKind,
});
}
else {
cache.projectVersion = version;
cache.version++;
cache.extension = extension;
cache.snapshot = snapshotSnapshot;
cache.kind = scriptKind;
}
}
else if (virtualFiles.get(fileName)) {
extraProjectVersion++;
virtualFiles.delete(fileName);
else if (cache) {
cache.projectVersion = version;
}
scripts.set(fileName, {
version,
extension,
snapshot: snapshotSnapshot,
kind: scriptKind,
});
}

@@ -120,0 +139,0 @@ return scripts.get(fileName);

{
"name": "@volar/typescript",
"version": "2.1.0",
"version": "2.1.1",
"license": "MIT",

@@ -15,3 +15,3 @@ "files": [

"dependencies": {
"@volar/language-core": "2.1.0",
"@volar/language-core": "2.1.1",
"path-browserify": "^1.0.1"

@@ -22,5 +22,5 @@ },

"@types/path-browserify": "latest",
"@volar/language-service": "2.1.0"
"@volar/language-service": "2.1.1"
},
"gitHead": "09e1792f0adafb02caf89a5a45a6fcaaf3177808"
"gitHead": "e56916097fe7be2920aab6592a564a8e2ceafd14"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc