From 4fbb60ff68cefd99c0af37af912b5cfb74f7a601 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 25 Dec 2024 16:20:09 +0800 Subject: [PATCH] fix: more --- .../language-service/lib/plugins/vue-extract-file.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/language-service/lib/plugins/vue-extract-file.ts b/packages/language-service/lib/plugins/vue-extract-file.ts index c580096e58..947090c633 100644 --- a/packages/language-service/lib/plugins/vue-extract-file.ts +++ b/packages/language-service/lib/plugins/vue-extract-file.ts @@ -1,6 +1,6 @@ import type { CreateFile, LanguageServiceContext, LanguageServicePlugin, TextDocumentEdit, TextEdit } from '@volar/language-service'; import type { ExpressionNode, TemplateChildNode } from '@vue/compiler-dom'; -import { Sfc, VueVirtualCode, scriptRanges } from '@vue/language-core'; +import { Sfc, VueVirtualCode, tsCodegen } from '@vue/language-core'; import type * as ts from 'typescript'; import type * as vscode from 'vscode-languageserver-protocol'; import { URI } from 'vscode-uri'; @@ -153,7 +153,7 @@ export function create( ]; if (sfc.script) { - const edit = createAddComponentToOptionEdit(ts, sfc.script.ast, newName); + const edit = createAddComponentToOptionEdit(ts, sfc, sfc.script.ast, newName); if (edit) { sfcEdits.push({ range: { @@ -299,12 +299,13 @@ export function getLastImportNode(ts: typeof import('typescript'), sourceFile: t return lastImportNode; } -export function createAddComponentToOptionEdit(ts: typeof import('typescript'), ast: ts.SourceFile, componentName: string) { +export function createAddComponentToOptionEdit(ts: typeof import('typescript'), sfc: Sfc, ast: ts.SourceFile, componentName: string) { - const exportDefault = scriptRanges.parseScriptRanges(ts, ast, false, true).exportDefault; - if (!exportDefault) { + const scriptRanges = tsCodegen.get(sfc)?.scriptRanges.get(); + if (!scriptRanges?.exportDefault) { return; } + const { exportDefault } = scriptRanges; // https://github.com/microsoft/TypeScript/issues/36174 const printer = ts.createPrinter();