Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/typescript-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import type ts from 'typescript/lib/tsserverlibrary';
function init(modules: { typescript: typeof ts }) {
function create(info: ts.server.PluginCreateInfo) {
const logger = new Logger(info.project.projectService.logger);

if (!isSvelteProject(info)) {
if (!isSvelteProject(info.project.getCompilerOptions())) {
logger.log('Detected that this is not a Svelte project, abort patching TypeScript');
return info.languageService;
}
Expand All @@ -34,6 +33,10 @@ function init(modules: { typescript: typeof ts }) {
}

function getExternalFiles(project: ts.server.ConfiguredProject) {
if (!isSvelteProject(project.getCompilerOptions())) {
return [];
}

// Needed so the ambient definitions are known inside the tsx files
const svelteTsPath = dirname(require.resolve('svelte2tsx'));
const svelteTsxFiles = [
Expand All @@ -58,9 +61,8 @@ function init(modules: { typescript: typeof ts }) {
}
}

function isSvelteProject(info: ts.server.PluginCreateInfo) {
function isSvelteProject(compilerOptions: ts.CompilerOptions) {
// Add more checks like "no Svelte file found" or "no config file found"?
const compilerOptions = info.project.getCompilerOptions();
const isNoJsxProject =
(!compilerOptions.jsx || compilerOptions.jsx === modules.typescript.JsxEmit.Preserve) &&
(!compilerOptions.jsxFactory || compilerOptions.jsxFactory.startsWith('svelte')) &&
Expand Down