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

@vue/typescript-plugin

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue/typescript-plugin - npm Package Compare versions

Comparing version 2.0.7 to 2.0.10

lib/requests/getImportPathForFile.d.ts

41

index.js

@@ -23,36 +23,25 @@ "use strict";

const vueOptions = getVueCompilerOptions();
const languagePlugin = vue.createVueLanguagePlugin(ts, id => id, fileName => {
if (info.languageServiceHost.useCaseSensitiveFileNames?.() ?? false) {
return externalFiles.get(info.project)?.has(fileName) ?? false;
}
else {
const lowerFileName = fileName.toLowerCase();
for (const externalFile of externalFiles.get(info.project) ?? []) {
if (externalFile.toLowerCase() === lowerFileName) {
return true;
}
}
return false;
}
}, info.languageServiceHost.getCompilationSettings(), vueOptions);
const languagePlugin = vue.createVueLanguagePlugin(ts, id => id, info.languageServiceHost.useCaseSensitiveFileNames?.() ?? false, () => info.languageServiceHost.getProjectVersion?.() ?? '', () => externalFiles.get(info.project) ?? [], info.languageServiceHost.getCompilationSettings(), vueOptions);
const extensions = languagePlugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [];
const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
const files = (0, language_core_1.createFileRegistry)([languagePlugin], ts.sys.useCaseSensitiveFileNames, fileName => {
const getLanguageId = (fileName) => {
if (extensions.some(ext => fileName.endsWith(ext))) {
return 'vue';
}
return (0, language_core_1.resolveCommonLanguageId)(fileName);
};
const language = (0, language_core_1.createLanguage)([languagePlugin], ts.sys.useCaseSensitiveFileNames, fileName => {
const snapshot = getScriptSnapshot(fileName);
if (snapshot) {
let languageId = (0, language_core_1.resolveCommonLanguageId)(fileName);
if (extensions.some(ext => fileName.endsWith(ext))) {
languageId = 'vue';
}
files.set(fileName, languageId, snapshot);
language.scripts.set(fileName, getLanguageId(fileName), snapshot);
}
else {
files.delete(fileName);
language.scripts.delete(fileName);
}
});
projectExternalFileExtensions.set(info.project, extensions);
server_1.projects.set(info.project, { info, files, vueOptions });
(0, decorateLanguageService_1.decorateLanguageService)(files, info.languageService);
(0, common_1.decorateLanguageServiceForVue)(files, info.languageService, vueOptions, ts, true);
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(files, info.languageServiceHost, ts);
server_1.projects.set(info.project, { info, language, vueOptions });
(0, decorateLanguageService_1.decorateLanguageService)(language, info.languageService);
(0, common_1.decorateLanguageServiceForVue)(language, info.languageService, vueOptions, ts, true);
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(ts, language, info.languageServiceHost, getLanguageId);
(0, server_1.startNamedPipeServer)(ts, info.project.projectKind, info.project.getCurrentDirectory());

@@ -80,3 +69,3 @@ }

if (!newFiles.has(oldFile)) {
server_1.projects.get(project)?.files.delete(oldFile);
server_1.projects.get(project)?.language.scripts.delete(oldFile);
}

@@ -83,0 +72,0 @@ }

@@ -6,2 +6,3 @@ export declare function collectExtractProps(...args: Parameters<typeof import('./requests/collectExtractProps.js')['collectExtractProps']>): Promise<{

}[] | null | undefined>;
export declare function getImportPathForFile(...args: Parameters<typeof import('./requests/getImportPathForFile.js')['getImportPathForFile']>): Promise<string | null | undefined>;
export declare function getPropertiesAtLocation(...args: Parameters<typeof import('./requests/getPropertiesAtLocation.js')['getPropertiesAtLocation']>): Promise<string[] | null | undefined>;

@@ -8,0 +9,0 @@ export declare function getQuickInfoAtPosition(...args: Parameters<typeof import('./requests/getQuickInfoAtPosition.js')['getQuickInfoAtPosition']>): Promise<import("typescript").QuickInfo | null | undefined>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getElementAttrs = exports.getComponentNames = exports.getTemplateContextProps = exports.getComponentEvents = exports.getComponentProps = exports.getQuickInfoAtPosition = exports.getPropertiesAtLocation = exports.collectExtractProps = void 0;
exports.getElementAttrs = exports.getComponentNames = exports.getTemplateContextProps = exports.getComponentEvents = exports.getComponentProps = exports.getQuickInfoAtPosition = exports.getPropertiesAtLocation = exports.getImportPathForFile = exports.collectExtractProps = void 0;
const utils_1 = require("./utils");

@@ -12,2 +12,9 @@ function collectExtractProps(...args) {

exports.collectExtractProps = collectExtractProps;
async function getImportPathForFile(...args) {
return await sendRequest({
type: 'getImportPathForFile',
args,
});
}
exports.getImportPathForFile = getImportPathForFile;
async function getPropertiesAtLocation(...args) {

@@ -14,0 +21,0 @@ return await sendRequest({

import * as vue from '@vue/language-core';
import type * as ts from 'typescript';
export declare function decorateLanguageServiceForVue(files: vue.FileRegistry, languageService: ts.LanguageService, vueOptions: vue.VueCompilerOptions, ts: typeof import('typescript'), isTsPlugin: boolean): void;
export declare function decorateLanguageServiceForVue(language: vue.Language, languageService: ts.LanguageService, vueOptions: vue.VueCompilerOptions, ts: typeof import('typescript'), isTsPlugin: boolean): void;
export declare function getComponentSpans(this: {

@@ -5,0 +5,0 @@ typescript: typeof import('typescript');

@@ -7,6 +7,6 @@ "use strict";

const componentInfos_1 = require("./requests/componentInfos");
function decorateLanguageServiceForVue(files, languageService, vueOptions, ts, isTsPlugin) {
function decorateLanguageServiceForVue(language, languageService, vueOptions, ts, isTsPlugin) {
const { getCompletionsAtPosition, getCompletionEntryDetails, getCodeFixesAtPosition, getEncodedSemanticClassifications, } = languageService;
languageService.getCompletionsAtPosition = (fileName, position, options) => {
const result = getCompletionsAtPosition(fileName, position, options);
languageService.getCompletionsAtPosition = (fileName, position, options, formattingSettings) => {
const result = getCompletionsAtPosition(fileName, position, options, formattingSettings);
if (result) {

@@ -71,7 +71,7 @@ // filter __VLS_

const result = getEncodedSemanticClassifications(fileName, span, format);
const file = files.get(fileName);
if (file?.generated?.code instanceof vue.VueGeneratedCode) {
const { template } = file.generated.code.sfc;
const file = language.scripts.get(fileName);
if (file?.generated?.root instanceof vue.VueGeneratedCode) {
const { template } = file.generated.root.sfc;
if (template) {
for (const componentSpan of getComponentSpans.call({ typescript: ts, languageService, vueOptions }, file.generated.code, template, {
for (const componentSpan of getComponentSpans.call({ typescript: ts, languageService, vueOptions }, file.generated.root, template, {
start: span.start - template.startTagEnd,

@@ -97,7 +97,7 @@ length: span.length,

]);
template.ast?.children.forEach(function visit(node) {
if (node.loc.end.offset <= spanTemplateRange.start || node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
return;
}
if (node.type === 1) {
if (template.ast) {
for (const node of vue.forEachElementNode(template.ast)) {
if (node.loc.end.offset <= spanTemplateRange.start || node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
continue;
}
if (components.has(node.tag)) {

@@ -119,19 +119,4 @@ let start = node.loc.start.offset;

}
for (const child of node.children) {
visit(child);
}
}
else if (node.type === 9) {
for (const branch of node.branches) {
for (const child of branch.children) {
visit(child);
}
}
}
else if (node.type === 11) {
for (const child of node.children) {
visit(child);
}
}
});
}
return result;

@@ -138,0 +123,0 @@ }

@@ -1,2 +0,2 @@

import { FileRegistry } from '@vue/language-core';
import { Language } from '@vue/language-core';
import type * as ts from 'typescript';

@@ -6,3 +6,3 @@ export declare function collectExtractProps(this: {

languageService: ts.LanguageService;
files: FileRegistry;
language: Language;
isTsPlugin: boolean;

@@ -9,0 +9,0 @@ getFileId: (fileName: string) => string;

@@ -6,5 +6,5 @@ "use strict";

function collectExtractProps(fileName, templateCodeRange) {
const { typescript: ts, languageService, files, isTsPlugin, getFileId } = this;
const volarFile = files.get(getFileId(fileName));
if (!(volarFile?.generated?.code instanceof language_core_1.VueGeneratedCode)) {
const { typescript: ts, languageService, language, isTsPlugin, getFileId } = this;
const volarFile = language.scripts.get(getFileId(fileName));
if (!(volarFile?.generated?.root instanceof language_core_1.VueGeneratedCode)) {
return;

@@ -19,5 +19,5 @@ }

const checker = program.getTypeChecker();
const script = volarFile.generated?.languagePlugin.typescript?.getScript(volarFile.generated.code);
const maps = script ? [...files.getMaps(script.code).values()] : [];
const sfc = volarFile.generated.code.sfc;
const script = volarFile.generated?.languagePlugin.typescript?.getServiceScript(volarFile.generated.root);
const maps = script ? [...language.maps.forEach(script.code).values()] : [];
const sfc = volarFile.generated.root.sfc;
sourceFile.forEachChild(function visit(node) {

@@ -24,0 +24,0 @@ if (ts.isPropertyAccessExpression(node)

@@ -6,3 +6,3 @@ import * as vue from '@vue/language-core';

languageService: ts.LanguageService;
files: vue.FileRegistry;
language: vue.Language;
vueOptions: vue.VueCompilerOptions;

@@ -14,3 +14,3 @@ getFileId: (fileName: string) => string;

languageService: ts.LanguageService;
files: vue.FileRegistry;
language: vue.Language;
vueOptions: vue.VueCompilerOptions;

@@ -22,3 +22,3 @@ getFileId: (fileName: string) => string;

languageService: ts.LanguageService;
files: vue.FileRegistry;
language: vue.Language;
getFileId: (fileName: string) => string;

@@ -29,3 +29,3 @@ }, fileName: string): string[] | undefined;

languageService: ts.LanguageService;
files: vue.FileRegistry;
language: vue.Language;
vueOptions: vue.VueCompilerOptions;

@@ -38,4 +38,4 @@ getFileId: (fileName: string) => string;

languageService: ts.LanguageService;
files: vue.FileRegistry;
language: vue.Language;
getFileId: (fileName: string) => string;
}, fileName: string, tagName: string): string[] | undefined;

@@ -7,8 +7,8 @@ "use strict";

function getComponentProps(fileName, tag, requiredOnly = false) {
const { typescript: ts, files, vueOptions, languageService, getFileId } = this;
const volarFile = files.get(getFileId(fileName));
if (!(volarFile?.generated?.code instanceof vue.VueGeneratedCode)) {
const { typescript: ts, language, vueOptions, languageService, getFileId } = this;
const volarFile = language.scripts.get(getFileId(fileName));
if (!(volarFile?.generated?.root instanceof vue.VueGeneratedCode)) {
return;
}
const vueCode = volarFile.generated.code;
const vueCode = volarFile.generated.root;
const program = languageService.getCurrentProgram();

@@ -75,8 +75,8 @@ if (!program) {

function getComponentEvents(fileName, tag) {
const { typescript: ts, files, vueOptions, languageService, getFileId } = this;
const volarFile = files.get(getFileId(fileName));
if (!(volarFile?.generated?.code instanceof vue.VueGeneratedCode)) {
const { typescript: ts, language, vueOptions, languageService, getFileId } = this;
const volarFile = language.scripts.get(getFileId(fileName));
if (!(volarFile?.generated?.root instanceof vue.VueGeneratedCode)) {
return;
}
const vueCode = volarFile.generated.code;
const vueCode = volarFile.generated.root;
const program = languageService.getCurrentProgram();

@@ -137,8 +137,8 @@ if (!program) {

function getTemplateContextProps(fileName) {
const { typescript: ts, files, languageService, getFileId } = this;
const volarFile = files.get(getFileId(fileName));
if (!(volarFile?.generated?.code instanceof vue.VueGeneratedCode)) {
const { typescript: ts, language, languageService, getFileId } = this;
const volarFile = language.scripts.get(getFileId(fileName));
if (!(volarFile?.generated?.root instanceof vue.VueGeneratedCode)) {
return;
}
const vueCode = volarFile.generated.code;
const vueCode = volarFile.generated.root;
return getVariableType(ts, languageService, vueCode, '__VLS_ctx')

@@ -151,8 +151,8 @@ ?.type

function getComponentNames(fileName) {
const { typescript: ts, files, vueOptions, languageService, getFileId } = this;
const volarFile = files.get(getFileId(fileName));
if (!(volarFile?.generated?.code instanceof vue.VueGeneratedCode)) {
const { typescript: ts, language, vueOptions, languageService, getFileId } = this;
const volarFile = language.scripts.get(getFileId(fileName));
if (!(volarFile?.generated?.root instanceof vue.VueGeneratedCode)) {
return;
}
const vueCode = volarFile.generated.code;
const vueCode = volarFile.generated.root;
return getVariableType(ts, languageService, vueCode, '__VLS_components')

@@ -178,5 +178,5 @@ ?.type

function getElementAttrs(fileName, tagName) {
const { typescript: ts, files, languageService, getFileId } = this;
const volarFile = files.get(getFileId(fileName));
if (!(volarFile?.generated?.code instanceof vue.VueGeneratedCode)) {
const { typescript: ts, language, languageService, getFileId } = this;
const volarFile = language.scripts.get(getFileId(fileName));
if (!(volarFile?.generated?.root instanceof vue.VueGeneratedCode)) {
return;

@@ -183,0 +183,0 @@ }

@@ -1,2 +0,2 @@

import { FileRegistry } from '@vue/language-core';
import { Language } from '@vue/language-core';
import type * as ts from 'typescript';

@@ -6,5 +6,5 @@ export declare function getPropertiesAtLocation(this: {

languageService: ts.LanguageService;
files: FileRegistry;
language: Language;
isTsPlugin: boolean;
getFileId: (fileName: string) => string;
}, fileName: string, position: number): string[] | undefined;

@@ -6,7 +6,7 @@ "use strict";

function getPropertiesAtLocation(fileName, position) {
const { languageService, files, typescript: ts, isTsPlugin, getFileId } = this;
const { languageService, language, typescript: ts, isTsPlugin, getFileId } = this;
// mapping
const file = files.get(getFileId(fileName));
const file = language.scripts.get(getFileId(fileName));
if (file?.generated) {
const virtualScript = file.generated.languagePlugin.typescript?.getScript(file.generated.code);
const virtualScript = file.generated.languagePlugin.typescript?.getServiceScript(file.generated.root);
if (!virtualScript) {

@@ -16,3 +16,3 @@ return;

let mapped = false;
for (const [_1, [_2, map]] of files.getMaps(virtualScript.code)) {
for (const [_1, [_2, map]] of language.maps.forEach(virtualScript.code)) {
for (const [position2, mapping] of map.getGeneratedOffsets(position)) {

@@ -19,0 +19,0 @@ if ((0, language_core_1.isCompletionEnabled)(mapping.data)) {

import type * as ts from 'typescript';
import type { FileRegistry, VueCompilerOptions } from '@vue/language-core';
import type { Language, VueCompilerOptions } from '@vue/language-core';
export interface Request {
type: 'containsFile' | 'collectExtractProps' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'getComponentProps' | 'getComponentEvents' | 'getTemplateContextProps' | 'getComponentNames' | 'getElementAttrs';
type: 'containsFile' | 'collectExtractProps' | 'getImportPathForFile' | 'getPropertiesAtLocation' | 'getQuickInfoAtPosition' | 'getComponentProps' | 'getComponentEvents' | 'getTemplateContextProps' | 'getComponentNames' | 'getElementAttrs';
args: [fileName: string, ...rest: any];

@@ -10,4 +10,4 @@ }

info: ts.server.PluginCreateInfo;
files: FileRegistry;
language: Language;
vueOptions: VueCompilerOptions;
}>;

@@ -8,2 +8,3 @@ "use strict";

const componentInfos_1 = require("./requests/componentInfos");
const getImportPathForFile_1 = require("./requests/getImportPathForFile");
const getPropertiesAtLocation_1 = require("./requests/getPropertiesAtLocation");

@@ -27,7 +28,11 @@ const getQuickInfoAtPosition_1 = require("./requests/getQuickInfoAtPosition");

const project = getProject(fileName);
if (project) {
if (request.type === 'containsFile') {
connection.write(JSON.stringify(!!project));
}
else if (project) {
const requestContext = {
typescript: ts,
languageService: project.info.languageService,
files: project.files,
languageServiceHost: project.info.languageServiceHost,
language: project.language,
vueOptions: project.vueOptions,

@@ -37,8 +42,8 @@ isTsPlugin: true,

};
if (request.type === 'containsFile') {
const result = !!getProject(fileName);
if (request.type === 'collectExtractProps') {
const result = collectExtractProps_1.collectExtractProps.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));
}
else if (request.type === 'collectExtractProps') {
const result = collectExtractProps_1.collectExtractProps.apply(requestContext, request.args);
else if (request.type === 'getImportPathForFile') {
const result = getImportPathForFile_1.getImportPathForFile.apply(requestContext, request.args);
connection.write(JSON.stringify(result ?? null));

@@ -45,0 +50,0 @@ }

{
"name": "@vue/typescript-plugin",
"version": "2.0.7",
"version": "2.0.10",
"license": "MIT",

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

"dependencies": {
"@volar/typescript": "~2.1.3",
"@vue/language-core": "2.0.7",
"@volar/typescript": "~2.2.0-alpha.5",
"@vue/language-core": "2.0.10",
"@vue/shared": "^3.4.0"

@@ -23,3 +23,3 @@ },

},
"gitHead": "4a37e8f3ebcf31ecfd2ea627f7611d5990ec5df6"
"gitHead": "a20a2ee950b63a949660b7e8faf0faed0e5bad33"
}
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