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.2.5 to 0.3.0

27

dist/src/index.js

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

function create(info) {
var _a, _b, _c, _d;
const logger = new logger_1.Logger(info.project.projectService.logger);

@@ -16,4 +17,7 @@ if (!isSvelteProject(info.project.getCompilerOptions())) {

logger.log('Starting Svelte plugin');
const snapshotManager = new svelte_snapshots_1.SvelteSnapshotManager(modules.typescript, info.project.projectService, logger);
patchCompilerOptions(info.project);
// If someone knows a better/more performant way to get svelteOptions,
// please tell us :)
const svelteOptions = ((_d = (_c = (_b = (_a = info.languageServiceHost).getParsedCommandLine) === null || _b === void 0 ? void 0 : _b.call(_a, info.project.getCompilerOptions().configFilePath)) === null || _c === void 0 ? void 0 : _c.raw) === null || _d === void 0 ? void 0 : _d.svelteOptions) || { namespace: 'svelteHTML' };
logger.log('svelteOptions:', svelteOptions);
const snapshotManager = new svelte_snapshots_1.SvelteSnapshotManager(modules.typescript, info.project.projectService, svelteOptions, logger);
(0, module_loader_1.patchModuleLoader)(logger, snapshotManager, modules.typescript, info.languageServiceHost, info.project);

@@ -35,25 +39,8 @@ return (0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger);

}
function patchCompilerOptions(project) {
var _a;
const compilerOptions = project.getCompilerOptions();
// Patch needed because svelte2tsx creates jsx/tsx files
compilerOptions.jsx = modules.typescript.JsxEmit.Preserve;
// detect which JSX namespace to use (svelte | svelteNative) if not specified or not compatible
if (!((_a = compilerOptions.jsxFactory) === null || _a === void 0 ? void 0 : _a.startsWith('svelte'))) {
// Default to regular svelte, this causes the usage of the "svelte.JSX" namespace
// We don't need to add a switch for svelte-native because the jsx is only relevant
// within Svelte files, which this plugin does not deal with.
compilerOptions.jsxFactory = 'svelte.createElement';
}
}
function isSvelteProject(compilerOptions) {
// Add more checks like "no Svelte file found" or "no config file found"?
const isNoJsxProject = (!compilerOptions.jsx || compilerOptions.jsx === modules.typescript.JsxEmit.Preserve) &&
(!compilerOptions.jsxFactory || compilerOptions.jsxFactory.startsWith('svelte')) &&
!compilerOptions.jsxFragmentFactory &&
!compilerOptions.jsxImportSource;
try {
const isSvelteProject = typeof compilerOptions.configFilePath !== 'string' ||
require.resolve('svelte', { paths: [compilerOptions.configFilePath] });
return isNoJsxProject && isSvelteProject;
return isSvelteProject;
}

@@ -60,0 +47,0 @@ catch (e) {

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

const resolvedSvelteModule = {
extension: snapshot.isTsFile ? typescript.Extension.Tsx : typescript.Extension.Jsx,
extension: snapshot.isTsFile ? typescript.Extension.Ts : typescript.Extension.Js,
resolvedFileName

@@ -101,0 +101,0 @@ };

@@ -6,15 +6,19 @@ "use strict";

function binaryInsert(array, value, key) {
if (0 === key)
if (0 === key) {
key = '0';
}
const index = 1 + binarySearch(array, (key ? value[key] : value), key);
let i = array.length;
while (index !== i--)
while (index !== i--) {
array[1 + i] = array[i];
}
array[index] = value;
}
function binarySearch(array, target, key) {
if (!array || 0 === array.length)
if (!array || 0 === array.length) {
return -1;
if (0 === key)
}
if (0 === key) {
key = '0';
}
let low = 0;

@@ -25,11 +29,15 @@ let high = array.length - 1;

const item = undefined === key ? array[i] : array[i][key];
if (item === target)
if (item === target) {
return i;
if (item < target)
}
if (item < target) {
low = i + 1;
else
}
else {
high = i - 1;
}
}
if ((low = ~low) < 0)
if ((low = ~low) < 0) {
low = ~low - 1;
}
return low;

@@ -39,6 +47,8 @@ }

constructor(mappings) {
if (typeof mappings === 'string')
if (typeof mappings === 'string') {
this.mappings = (0, sourcemap_codec_1.decode)(mappings);
else
}
else {
this.mappings = mappings;
}
}

@@ -59,4 +69,5 @@ getOriginalPosition(position) {

getGeneratedPosition(position) {
if (!this.reverseMappings)
if (!this.reverseMappings) {
this.computeReversed();
}
const lineMap = this.reverseMappings[position.line];

@@ -84,6 +95,8 @@ if (!lineMap) {

];
if (original_line in this.reverseMappings)
if (original_line in this.reverseMappings) {
binaryInsert(this.reverseMappings[original_line], reordered_char, 0);
else
}
else {
this.reverseMappings[original_line] = [reordered_char];
}
}

@@ -90,0 +103,0 @@ }

@@ -39,5 +39,8 @@ import type ts from 'typescript/lib/tsserverlibrary';

private projectService;
private svelteOptions;
private logger;
private snapshots;
constructor(typescript: typeof ts, projectService: ts.server.ProjectService, logger: Logger);
constructor(typescript: typeof ts, projectService: ts.server.ProjectService, svelteOptions: {
namespace: string;
}, logger: Logger);
get(fileName: string): SvelteSnapshot | undefined;

@@ -44,0 +47,0 @@ create(fileName: string): SvelteSnapshot | undefined;

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

class SvelteSnapshotManager {
constructor(typescript, projectService, logger) {
constructor(typescript, projectService, svelteOptions, logger) {
this.typescript = typescript;
this.projectService = projectService;
this.svelteOptions = svelteOptions;
this.logger = logger;

@@ -238,3 +239,5 @@ this.snapshots = new Map();

filename: path.split('/').pop(),
isTsFile
isTsFile,
mode: 'ts',
typingsNamespace: this.svelteOptions.namespace
});

@@ -241,0 +244,0 @@ const existingSnapshot = this.snapshots.get(path);

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

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

"dependencies": {
"svelte2tsx": "~0.4.0",
"svelte2tsx": "~0.5.0",
"sourcemap-codec": "^1.4.8"
}
}
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