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

typescript-svelte-plugin

Package Overview
Dependencies
Maintainers
3
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-svelte-plugin - npm Package Compare versions

Comparing version 0.3.17 to 0.3.18

dist/src/language-service/hover.d.ts

39

dist/src/index.js

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

const configManager = new config_manager_1.ConfigManager();
let resolvedSvelteTsxFiles;
function create(info) {

@@ -90,3 +91,3 @@ var _a, _b, _c, _d;

});
return decorateLanguageServiceDispose((0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger, configManager, modules.typescript), projectSvelteFilesManager !== null && projectSvelteFilesManager !== void 0 ? projectSvelteFilesManager : {
return decorateLanguageServiceDispose((0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger, configManager, info, modules.typescript), projectSvelteFilesManager !== null && projectSvelteFilesManager !== void 0 ? projectSvelteFilesManager : {
dispose() { }

@@ -101,2 +102,15 @@ });

// Needed so the ambient definitions are known inside the tsx files
const svelteTsxFiles = resolveSvelteTsxFiles();
if (!project.getCompilerOptions().configFilePath) {
svelteTsxFiles.forEach((file) => {
openSvelteTsxFileForInferredProject(project, file);
});
}
// let ts know project svelte files to do its optimization
return svelteTsxFiles.concat((_b = (_a = project_svelte_files_1.ProjectSvelteFilesManager.getInstance(project.getProjectName())) === null || _a === void 0 ? void 0 : _a.getFiles()) !== null && _b !== void 0 ? _b : []);
}
function resolveSvelteTsxFiles() {
if (resolvedSvelteTsxFiles) {
return resolvedSvelteTsxFiles;
}
const svelteTsPath = (0, path_1.dirname)(require.resolve('svelte2tsx'));

@@ -108,4 +122,4 @@ const svelteTsxFiles = [

].map((f) => modules.typescript.sys.resolvePath((0, path_1.resolve)(svelteTsPath, f)));
// let ts know project svelte files to do its optimization
return svelteTsxFiles.concat((_b = (_a = project_svelte_files_1.ProjectSvelteFilesManager.getInstance(project.getProjectName())) === null || _a === void 0 ? void 0 : _a.getFiles()) !== null && _b !== void 0 ? _b : []);
resolvedSvelteTsxFiles = svelteTsxFiles;
return svelteTsxFiles;
}

@@ -135,2 +149,21 @@ function isSvelteProject(compilerOptions) {

}
/**
* TypeScript doesn't load the external files in projects without a config file. So we load it by ourselves.
* TypeScript also seems to expect files added to the root to be opened by the client in this situation.
*/
function openSvelteTsxFileForInferredProject(project, file) {
const normalizedPath = modules.typescript.server.toNormalizedPath(file);
if (project.containsFile(normalizedPath)) {
return;
}
const scriptInfo = project.projectService.getOrCreateScriptInfoForNormalizedPath(normalizedPath,
/*openedByClient*/ true, project.readFile(file));
if (!scriptInfo) {
return;
}
if (!project.projectService.openFiles.has(scriptInfo.path)) {
project.projectService.openFiles.set(scriptInfo.path, undefined);
}
project.addRoot(scriptInfo);
}
return { create, getExternalFiles, onConfigurationChanged };

@@ -137,0 +170,0 @@ }

4

dist/src/language-service/completions.d.ts

@@ -1,5 +0,5 @@

import type ts from 'typescript';
import type ts from 'typescript/lib/tsserverlibrary';
import { Logger } from '../logger';
type _ts = typeof ts;
export declare function decorateCompletions(ls: ts.LanguageService, ts: _ts, logger: Logger): void;
export declare function decorateCompletions(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, ts: _ts, logger: Logger): void;
export {};

@@ -6,9 +6,54 @@ "use strict";

const utils_1 = require("../utils");
const sveltekit_1 = require("./sveltekit");
const componentPostfix = '__SvelteComponent_';
function decorateCompletions(ls, ts, logger) {
function decorateCompletions(ls, info, ts, logger) {
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
ls.getCompletionsAtPosition = (fileName, position, options) => {
var _a, _b, _c, _d;
const completions = getCompletionsAtPosition(fileName, position, options);
ls.getCompletionsAtPosition = (fileName, position, options, settings) => {
var _a, _b, _c, _d, _e;
let completions;
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
if (result) {
const { languageService, toVirtualPos, toOriginalPos } = result;
completions = languageService.getCompletionsAtPosition(fileName, toVirtualPos(position), options, settings);
if (completions) {
completions.entries = completions.entries.map((c) => {
if (c.replacementSpan) {
return {
...c,
replacementSpan: {
...c.replacementSpan,
start: toOriginalPos(c.replacementSpan.start).pos
}
};
}
return c;
});
}
}
completions =
completions !== null && completions !== void 0 ? completions : getCompletionsAtPosition(fileName, position, options, settings);
if (!completions) {
// No completions hints at a top level export in the making
const source = (_a = ls.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
const node = source && (0, utils_1.findNodeAtPosition)(source, position);
if (node && (0, utils_1.isTopLevelExport)(ts, node, source)) {
return {
entries: Object.entries(sveltekit_1.kitExports).map(([key, value]) => ({
kind: ts.ScriptElementKind.constElement,
name: key,
labelDetails: {
description: value.documentation.map((d) => d.text).join('')
},
sortText: '0',
data: {
__sveltekit: key,
exportName: key // TS needs this
}
})),
isGlobalCompletion: false,
isMemberCompletion: false,
isNewIdentifierLocation: false,
isIncomplete: true
};
}
return completions;

@@ -20,3 +65,3 @@ }

for (const c of completions.entries) {
if (((_a = c.source) === null || _a === void 0 ? void 0 : _a.includes('.svelte-kit/types')) && c.data) {
if (((_b = c.source) === null || _b === void 0 ? void 0 : _b.includes('.svelte-kit/types')) && c.data) {
$typeImports.set(c.name, c);

@@ -29,3 +74,3 @@ }

const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
const relativeFileName = (_b = fileName.split(routesFolder)[1]) === null || _b === void 0 ? void 0 : _b.slice(1);
const relativeFileName = (_c = fileName.split(routesFolder)[1]) === null || _c === void 0 ? void 0 : _c.slice(1);
if (relativeFileName) {

@@ -45,4 +90,4 @@ const relativePath = (0, path_1.dirname)(relativeFileName) === '.' ? '' : `${(0, path_1.dirname)(relativeFileName)}/`;

...$typeImport.data,
fileName: (_c = $typeImport.data.fileName) === null || _c === void 0 ? void 0 : _c.replace($typeImport.source, modifiedSource),
moduleSpecifier: (_d = $typeImport.data.moduleSpecifier) === null || _d === void 0 ? void 0 : _d.replace($typeImport.source, modifiedSource),
fileName: (_d = $typeImport.data.fileName) === null || _d === void 0 ? void 0 : _d.replace($typeImport.source, modifiedSource),
moduleSpecifier: (_e = $typeImport.data.moduleSpecifier) === null || _e === void 0 ? void 0 : _e.replace($typeImport.source, modifiedSource),
__is_sveltekit$typeImport: true

@@ -54,16 +99,2 @@ }

}
if ((0, path_1.basename)(fileName).startsWith('+page') || (0, path_1.basename)(fileName).startsWith('+layout')) {
if ((0, path_1.extname)(fileName) === '.js') {
completions.entries.push({
// TODO doesn't show up for "export" and "load" only at the bottom for "function"
kind: ts.ScriptElementKind.functionElement,
name: 'export function load() {}',
sortText: '-99',
kindModifiers: ts.ScriptElementKindModifier.exportedModifier,
insertText: `/** @type {import('./$types').Foo} */\nexport function load() {}`
});
}
else {
}
}
return {

@@ -85,8 +116,42 @@ ...completions,

ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
var _a;
var _a, _b;
if (data === null || data === void 0 ? void 0 : data.__sveltekit) {
const key = data === null || data === void 0 ? void 0 : data.__sveltekit;
return {
name: key,
kind: ts.ScriptElementKind.constElement,
kindModifiers: ts.ScriptElementKindModifier.none,
displayParts: sveltekit_1.kitExports[key].displayParts,
documentation: sveltekit_1.kitExports[key].documentation
};
}
const is$typeImport = data === null || data === void 0 ? void 0 : data.__is_sveltekit$typeImport;
const details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
let details;
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
if (result) {
const { languageService, toVirtualPos, toOriginalPos } = result;
details = languageService.getCompletionEntryDetails(fileName, toVirtualPos(position), entryName, formatOptions, source, preferences, data);
if (details) {
details.codeActions = (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((codeAction) => {
codeAction.changes = codeAction.changes.map((change) => {
change.textChanges = change.textChanges.map((textChange) => {
return {
...textChange,
span: {
...textChange.span,
start: toOriginalPos(textChange.span.start).pos
}
};
});
return change;
});
return codeAction;
});
}
}
details =
details !== null && details !== void 0 ? details : getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
if (details) {
if (is$typeImport) {
details.codeActions = (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((codeAction) => {
details.codeActions = (_b = details.codeActions) === null || _b === void 0 ? void 0 : _b.map((codeAction) => {
codeAction.description = adjustPath(codeAction.description);

@@ -125,2 +190,11 @@ codeAction.changes = codeAction.changes.map((change) => {

};
const getSignatureHelpItems = ls.getSignatureHelpItems;
ls.getSignatureHelpItems = (fileName, position, options) => {
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
if (result) {
const { languageService, toVirtualPos } = result;
return languageService.getSignatureHelpItems(fileName, toVirtualPos(position), options);
}
return getSignatureHelpItems(fileName, position, options);
};
}

@@ -127,0 +201,0 @@ exports.decorateCompletions = decorateCompletions;

import type ts from 'typescript/lib/tsserverlibrary';
import { Logger } from '../logger';
import { SvelteSnapshotManager } from '../svelte-snapshots';
export declare function decorateGetDefinition(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger): void;
type _ts = typeof ts;
export declare function decorateGetDefinition(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, ts: _ts, snapshotManager: SvelteSnapshotManager, logger: Logger): void;
export {};

@@ -5,3 +5,4 @@ "use strict";

const utils_1 = require("../utils");
function decorateGetDefinition(ls, snapshotManager, logger) {
const sveltekit_1 = require("./sveltekit");
function decorateGetDefinition(ls, info, ts, snapshotManager, logger) {
const getDefinitionAndBoundSpan = ls.getDefinitionAndBoundSpan;

@@ -11,3 +12,3 @@ ls.getDefinitionAndBoundSpan = (fileName, position) => {

if (!(definition === null || definition === void 0 ? void 0 : definition.definitions)) {
return definition;
return getKitDefinitions(ts, info, fileName, position);
}

@@ -43,2 +44,19 @@ return {

exports.decorateGetDefinition = decorateGetDefinition;
function getKitDefinitions(ts, info, fileName, position) {
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
if (!result)
return;
const { languageService, toOriginalPos, toVirtualPos } = result;
const virtualPos = toVirtualPos(position);
const definitions = languageService.getDefinitionAndBoundSpan(fileName, virtualPos);
if (!definitions)
return;
// Assumption: This is only called when the original definitions didn't turn up anything.
// Therefore we are called on things like export function load ({ fetch }) .
// This means the textSpan needs conversion but none of the definitions because they are all referencing other files.
return {
...definitions,
textSpan: { ...definitions.textSpan, start: toOriginalPos(definitions.textSpan.start).pos }
};
}
//# sourceMappingURL=definition.js.map
import type ts from 'typescript/lib/tsserverlibrary';
import { Logger } from '../logger';
export declare function decorateDiagnostics(ls: ts.LanguageService, logger: Logger): void;
export declare function decorateDiagnostics(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, typescript: typeof ts, logger: Logger): void;

@@ -5,9 +5,10 @@ "use strict";

const utils_1 = require("../utils");
function decorateDiagnostics(ls, logger) {
decorateSyntacticDiagnostics(ls);
decorateSemanticDiagnostics(ls);
decorateSuggestionDiagnostics(ls);
const sveltekit_1 = require("./sveltekit");
function decorateDiagnostics(ls, info, typescript, logger) {
decorateSyntacticDiagnostics(ls, info, typescript, logger);
decorateSemanticDiagnostics(ls, info, typescript, logger);
decorateSuggestionDiagnostics(ls, info, typescript, logger);
}
exports.decorateDiagnostics = decorateDiagnostics;
function decorateSyntacticDiagnostics(ls) {
function decorateSyntacticDiagnostics(ls, info, typescript, logger) {
const getSyntacticDiagnostics = ls.getSyntacticDiagnostics;

@@ -20,6 +21,7 @@ ls.getSyntacticDiagnostics = (fileName) => {

}
return getSyntacticDiagnostics(fileName);
const kitDiagnostics = getKitDiagnostics('getSyntacticDiagnostics', fileName, info, typescript, logger);
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSyntacticDiagnostics(fileName);
};
}
function decorateSemanticDiagnostics(ls) {
function decorateSemanticDiagnostics(ls, info, typescript, logger) {
const getSemanticDiagnostics = ls.getSemanticDiagnostics;

@@ -32,6 +34,7 @@ ls.getSemanticDiagnostics = (fileName) => {

}
return getSemanticDiagnostics(fileName);
const kitDiagnostics = getKitDiagnostics('getSemanticDiagnostics', fileName, info, typescript, logger);
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSemanticDiagnostics(fileName);
};
}
function decorateSuggestionDiagnostics(ls) {
function decorateSuggestionDiagnostics(ls, info, typescript, logger) {
const getSuggestionDiagnostics = ls.getSuggestionDiagnostics;

@@ -44,5 +47,45 @@ ls.getSuggestionDiagnostics = (fileName) => {

}
return getSuggestionDiagnostics(fileName);
const kitDiagnostics = getKitDiagnostics('getSuggestionDiagnostics', fileName, info, typescript, logger);
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSuggestionDiagnostics(fileName);
};
}
function getKitDiagnostics(methodName, fileName, info, ts, logger) {
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts, logger);
if (!result)
return;
const { languageService, toOriginalPos } = result;
const diagnostics = [];
for (let diagnostic of languageService[methodName](fileName)) {
if (!diagnostic.start || !diagnostic.length) {
diagnostics.push(diagnostic);
continue;
}
const mapped = toOriginalPos(diagnostic.start);
if (mapped.inGenerated) {
// If not "Cannot find module './$types' .." then filter out
if (diagnostic.code !== 2307) {
continue;
}
else {
diagnostic = {
...diagnostic,
// adjust length so it doesn't spill over to the next line
length: 1,
messageText: typeof diagnostic.messageText === 'string' &&
diagnostic.messageText.includes('./$types')
? diagnostic.messageText +
` (this likely means that SvelteKit's type generation didn't run yet)`
: diagnostic.messageText
};
}
}
diagnostic = {
...diagnostic,
start: mapped.pos
};
diagnostics.push(diagnostic);
}
// @ts-ignore TS doesn't get the return type right
return diagnostics;
}
//# sourceMappingURL=diagnostics.js.map

@@ -6,2 +6,2 @@ import type ts from 'typescript/lib/tsserverlibrary';

export declare function isPatched(ls: ts.LanguageService): boolean;
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, typescript: typeof ts): ts.LanguageService;
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, info: ts.server.PluginCreateInfo, typescript: typeof ts): ts.LanguageService;

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

const find_references_1 = require("./find-references");
const hover_1 = require("./hover");
const implementation_1 = require("./implementation");

@@ -19,20 +20,21 @@ const rename_1 = require("./rename");

exports.isPatched = isPatched;
function decorateLanguageService(ls, snapshotManager, logger, configManager, typescript) {
function decorateLanguageService(ls, snapshotManager, logger, configManager, info, typescript) {
// Decorate using a proxy so we can dynamically enable/disable method
// patches depending on the enabled state of our config
const proxy = new Proxy(ls, createProxyHandler(configManager));
decorateLanguageServiceInner(proxy, snapshotManager, logger, typescript);
decorateLanguageServiceInner(proxy, snapshotManager, logger, info, typescript);
return proxy;
}
exports.decorateLanguageService = decorateLanguageService;
function decorateLanguageServiceInner(ls, snapshotManager, logger, typescript) {
function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescript) {
patchLineColumnOffset(ls, snapshotManager);
(0, rename_1.decorateRename)(ls, snapshotManager, logger);
(0, diagnostics_1.decorateDiagnostics)(ls, logger);
(0, diagnostics_1.decorateDiagnostics)(ls, info, typescript, logger);
(0, find_references_1.decorateFindReferences)(ls, snapshotManager, logger);
(0, completions_1.decorateCompletions)(ls, typescript, logger);
(0, definition_1.decorateGetDefinition)(ls, snapshotManager, logger);
(0, completions_1.decorateCompletions)(ls, info, typescript, logger);
(0, definition_1.decorateGetDefinition)(ls, info, typescript, snapshotManager, logger);
(0, implementation_1.decorateGetImplementation)(ls, snapshotManager, logger);
(0, update_imports_1.decorateUpdateImports)(ls, snapshotManager, logger);
(0, call_hierarchy_1.decorateCallHierarchy)(ls, snapshotManager, typescript);
(0, hover_1.decorateHover)(ls, info, typescript, logger);
return ls;

@@ -39,0 +41,0 @@ }

@@ -81,3 +81,3 @@ "use strict";

function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile) {
logger.log('Resolving modules names for ' + containingFile);
logger.debug('Resolving modules names for ' + containingFile);
// Try resolving all module names with the original method first.

@@ -123,3 +123,3 @@ // The ones that are undefined will be re-checked if they are a

var _a;
logger.log('Resolving modules names for ' + containingFile);
logger.debug('Resolving modules names for ' + containingFile);
// Try resolving all module names with the original method first.

@@ -126,0 +126,0 @@ // The ones that are undefined will be re-checked if they are a

@@ -27,3 +27,3 @@ "use strict";

const i = low + ((high - low) >> 1);
const item = undefined === key ? array[i] : array[i][key];
const item = (undefined === key ? array[i] : array[i][key]);
if (item === target) {

@@ -30,0 +30,0 @@ return i;

import type ts from 'typescript/lib/tsserverlibrary';
import { SvelteSnapshot } from './svelte-snapshots';
type _ts = typeof ts;
export declare function isSvelteFilePath(filePath: string): boolean;

@@ -34,2 +35,10 @@ export declare function isVirtualSvelteFilePath(filePath: string): boolean;

}, predicate?: NodeTypePredicate<T>): T | void;
/**
* Finds node somewhere at position.
*/
export declare function findNodeAtPosition<T extends ts.Node>(node: ts.Node, pos: number, predicate?: NodeTypePredicate<T>): T | void;
/**
* True if is `export const/let/function`
*/
export declare function isTopLevelExport(ts: _ts, node: ts.Node, source: ts.SourceFile): boolean;
export declare function isGeneratedSvelteComponentName(className: string): boolean;

@@ -36,0 +45,0 @@ export declare function offsetOfGeneratedComponentExport(snapshot: SvelteSnapshot): number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.gatherDescendants = exports.offsetOfGeneratedComponentExport = exports.isGeneratedSvelteComponentName = exports.findNodeAtSpan = exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
exports.gatherDescendants = exports.offsetOfGeneratedComponentExport = exports.isGeneratedSvelteComponentName = exports.isTopLevelExport = exports.findNodeAtPosition = exports.findNodeAtSpan = exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
function isSvelteFilePath(filePath) {

@@ -110,2 +110,44 @@ return filePath.endsWith('.svelte');

exports.findNodeAtSpan = findNodeAtSpan;
/**
* Finds node somewhere at position.
*/
function findNodeAtPosition(node, pos, predicate) {
for (const child of node.getChildren()) {
const childStart = child.getStart();
if (pos < childStart) {
return;
}
const childEnd = child.getEnd();
if (pos > childEnd) {
continue;
}
const foundInChildren = findNodeAtPosition(child, pos, predicate);
if (foundInChildren) {
return foundInChildren;
}
if (!predicate) {
return child;
}
if (predicate(child)) {
return child;
}
}
}
exports.findNodeAtPosition = findNodeAtPosition;
/**
* True if is `export const/let/function`
*/
function isTopLevelExport(ts, node, source) {
var _a, _b;
return ((ts.isVariableStatement(node) && source.statements.includes(node)) ||
(ts.isIdentifier(node) &&
node.parent &&
ts.isVariableDeclaration(node.parent) &&
source.statements.includes((_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent)) ||
(ts.isIdentifier(node) &&
node.parent &&
ts.isFunctionDeclaration(node.parent) &&
source.statements.includes(node.parent)));
}
exports.isTopLevelExport = isTopLevelExport;
const COMPONENT_SUFFIX = '__SvelteComponent_';

@@ -112,0 +154,0 @@ function isGeneratedSvelteComponentName(className) {

{
"name": "typescript-svelte-plugin",
"version": "0.3.17",
"version": "0.3.18",
"description": "A TypeScript Plugin providing Svelte intellisense",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

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