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

@astrojs/ts-plugin

Package Overview
Dependencies
Maintainers
3
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astrojs/ts-plugin - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

6

dist/astro2tsx.d.ts

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

import { VirtualFile } from '@volar/language-core';
export declare function astro2tsx(input: string, fileName: string, ts: typeof import('typescript/lib/tsserverlibrary.js')): {
virtualFile: VirtualFile;
import type { VirtualCode } from '@volar/language-core';
export declare function astro2tsx(input: string, fileName: string, ts: typeof import('typescript')): {
virtualFile: VirtualCode<string>;
diagnostics: import("@astrojs/compiler").DiagnosticMessage[] | {

@@ -5,0 +5,0 @@ code: 1000;

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

const sourcemap_codec_1 = require("@jridgewell/sourcemap-codec");
const language_core_1 = require("@volar/language-core");
const node_path_1 = __importDefault(require("node:path"));

@@ -88,12 +87,19 @@ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");

if (lastMapping &&
lastMapping.generatedRange[1] === current.genOffset &&
lastMapping.sourceRange[1] === current.sourceOffset) {
lastMapping.generatedRange[1] = current.genOffset + length;
lastMapping.sourceRange[1] = current.sourceOffset + length;
lastMapping.generatedOffsets[0] + lastMapping.lengths[0] === current.genOffset &&
lastMapping.sourceOffsets[0] + lastMapping.lengths[0] === current.sourceOffset) {
lastMapping.lengths[0] += length;
}
else {
mappings.push({
sourceRange: [current.sourceOffset, current.sourceOffset + length],
generatedRange: [current.genOffset, current.genOffset + length],
data: language_core_1.FileRangeCapabilities.full,
sourceOffsets: [current.sourceOffset],
generatedOffsets: [current.genOffset],
lengths: [length],
data: {
verification: true,
completion: true,
semantic: true,
navigation: true,
structure: true,
format: false,
},
});

@@ -113,22 +119,5 @@ }

}
const ast = ts.createSourceFile('/a.tsx', tsx.code, ts.ScriptTarget.ESNext);
if (ast.statements[0]) {
mappings.push({
sourceRange: [0, input.length],
generatedRange: [ast.statements[0].getStart(ast), tsx.code.length],
data: {},
});
}
return {
fileName: fileName + '.tsx',
kind: language_core_1.FileKind.TypeScriptHostFile,
capabilities: {
codeAction: true,
documentFormatting: false,
diagnostic: true,
documentSymbol: true,
inlayHint: true,
foldingRange: true,
},
codegenStacks: [],
id: 'tsx',
languageId: 'typescriptreact',
snapshot: {

@@ -140,3 +129,3 @@ getText: (start, end) => tsx.code.substring(start, end),

mappings: mappings,
embeddedFiles: [],
embeddedCodes: [],
};

@@ -143,0 +132,0 @@ }

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

import type ts from 'typescript/lib/tsserverlibrary';
declare const init: ts.server.PluginModuleFactory;
export = init;
declare const _default: ts.server.PluginModuleFactory;
export = _default;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
const language_core_1 = require("@volar/language-core");
const typescript_1 = require("@volar/typescript");
const semver = __importStar(require("semver"));
const createLanguageServicePlugin_js_1 = require("@volar/typescript/lib/quickstart/createLanguageServicePlugin.js");
const language_js_1 = require("./language.js");
const externalFiles = new WeakMap();
const init = (modules) => {
const { typescript: ts } = modules;
const pluginModule = {
create(info) {
const virtualFiles = (0, language_core_1.createVirtualFiles)([(0, language_js_1.getLanguageModule)(ts)]);
(0, typescript_1.decorateLanguageService)(virtualFiles, info.languageService, true);
(0, typescript_1.decorateLanguageServiceHost)(virtualFiles, info.languageServiceHost, ts, ['.astro']);
if (semver.lt(ts.version, '5.3.0')) {
// HACK: AutoImportProviderProject's script kind does not match the one of the language service host here
// this causes TypeScript to throw and crash. So, we'll fake being a TS file here for now until they fix it
// Fixed by https://github.com/microsoft/TypeScript/pull/55716
const getScriptKind = info.languageServiceHost.getScriptKind?.bind(info.languageServiceHost.getScriptKind);
if (getScriptKind) {
info.languageServiceHost.getScriptKind = (fileName) => {
if (fileName.endsWith('.astro')) {
return ts.ScriptKind.TS;
}
return getScriptKind(fileName);
};
}
}
return info.languageService;
},
getExternalFiles(project, updateLevel = 0) {
if (
// @ts-expect-error wait for TS 5.3
updateLevel >= (1) ||
!externalFiles.has(project)) {
const oldFiles = externalFiles.get(project);
const newFiles = (0, typescript_1.searchExternalFiles)(ts, project, ['.astro']);
externalFiles.set(project, newFiles);
if (oldFiles && !arrayItemsEqual(oldFiles, newFiles)) {
project.refreshDiagnostics();
}
}
return externalFiles.get(project);
},
};
return pluginModule;
};
function arrayItemsEqual(a, b) {
if (a.length !== b.length) {
return false;
}
const set = new Set(a);
for (const file of b) {
if (!set.has(file)) {
return false;
}
}
return true;
}
module.exports = init;
module.exports = (0, createLanguageServicePlugin_js_1.createLanguageServicePlugin)((ts) => [(0, language_js_1.getLanguageModule)(ts)]);

@@ -1,17 +0,16 @@

import { FileCapabilities, FileKind, type Language, type VirtualFile } from '@volar/language-core';
import type ts from 'typescript/lib/tsserverlibrary.js';
export declare function getLanguageModule(ts: typeof import('typescript/lib/tsserverlibrary.js')): Language<AstroFile>;
export declare class AstroFile implements VirtualFile {
sourceFileName: string;
import { type CodeMapping, type LanguagePlugin, type VirtualCode } from '@volar/language-core';
import type ts from 'typescript';
export declare function getLanguageModule(ts: typeof import('typescript')): LanguagePlugin<AstroVirtualCode>;
export declare class AstroVirtualCode implements VirtualCode {
fileName: string;
snapshot: ts.IScriptSnapshot;
private readonly ts;
kind: FileKind;
capabilities: FileCapabilities;
fileName: string;
mappings: VirtualFile['mappings'];
embeddedFiles: VirtualFile['embeddedFiles'];
id: string;
languageId: string;
mappings: CodeMapping[];
embeddedCodes: VirtualCode[];
codegenStacks: never[];
constructor(sourceFileName: string, snapshot: ts.IScriptSnapshot, ts: typeof import('typescript/lib/tsserverlibrary.js'));
constructor(fileName: string, snapshot: ts.IScriptSnapshot, ts: typeof import('typescript'));
update(newSnapshot: ts.IScriptSnapshot): void;
onSnapshotUpdated(): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AstroFile = exports.getLanguageModule = void 0;
exports.AstroVirtualCode = exports.getLanguageModule = void 0;
const language_core_1 = require("@volar/language-core");

@@ -8,22 +8,37 @@ const astro2tsx_js_1 = require("./astro2tsx.js");

return {
createVirtualFile(fileName, snapshot) {
if (fileName.endsWith('.astro')) {
return new AstroFile(fileName, snapshot, ts);
createVirtualCode(fileId, languageId, snapshot) {
if (languageId === 'astro') {
const fileName = fileId.includes('://') ? fileId.split('://')[1] : fileId;
return new AstroVirtualCode(fileName, snapshot, ts);
}
},
updateVirtualFile(astroFile, snapshot) {
updateVirtualCode(_fileId, astroFile, snapshot) {
astroFile.update(snapshot);
return astroFile;
},
typescript: {
extraFileExtensions: [{ extension: 'astro', isMixedContent: true, scriptKind: 7 }],
getScript(astroCode) {
for (const code of (0, language_core_1.forEachEmbeddedCode)(astroCode)) {
if (code.id === 'tsx') {
return {
code,
extension: '.tsx',
scriptKind: 4,
};
}
}
},
},
};
}
exports.getLanguageModule = getLanguageModule;
class AstroFile {
constructor(sourceFileName, snapshot, ts) {
this.sourceFileName = sourceFileName;
class AstroVirtualCode {
constructor(fileName, snapshot, ts) {
this.fileName = fileName;
this.snapshot = snapshot;
this.ts = ts;
this.kind = language_core_1.FileKind.TextFile;
this.capabilities = language_core_1.FileCapabilities.full;
this.id = 'root';
this.languageId = 'astro';
this.codegenStacks = [];
this.fileName = sourceFileName;
this.onSnapshotUpdated();

@@ -38,12 +53,20 @@ }

{
sourceRange: [0, this.snapshot.getLength()],
generatedRange: [0, this.snapshot.getLength()],
data: language_core_1.FileRangeCapabilities.full,
sourceOffsets: [0],
generatedOffsets: [0],
lengths: [this.snapshot.getLength()],
data: {
verification: true,
completion: true,
semantic: true,
navigation: true,
structure: true,
format: false,
},
},
];
this.embeddedFiles = [];
this.embeddedCodes = [];
const tsx = (0, astro2tsx_js_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName, this.ts);
this.embeddedFiles.push(tsx.virtualFile);
this.embeddedCodes.push(tsx.virtualFile);
}
}
exports.AstroFile = AstroFile;
exports.AstroVirtualCode = AstroVirtualCode;
{
"name": "@astrojs/ts-plugin",
"version": "1.4.0",
"version": "1.5.0",
"description": "A TypeScript Plugin providing Astro intellisense",

@@ -25,4 +25,4 @@ "main": "dist/index.js",

"dependencies": {
"@volar/language-core": "~1.10.9",
"@volar/typescript": "~1.10.9",
"@volar/language-core": "~2.0.2",
"@volar/typescript": "~2.0.2",
"@astrojs/compiler": "^2.4.0",

@@ -29,0 +29,0 @@ "@jridgewell/sourcemap-codec": "^1.4.15",

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