Skip to content

Commit 9977aea

Browse files
committed
refactor: move to alien-signals
1 parent f4d7300 commit 9977aea

18 files changed

+180
-189
lines changed

packages/component-meta/lib/base.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ function readVueComponentDefaultProps(
721721

722722
function scriptSetupWorker() {
723723

724-
const descriptor = vueSourceFile.sfc;
724+
const descriptor = vueSourceFile._sfc;
725725
const scriptSetupRanges = descriptor.scriptSetup ? vue.parseScriptSetupRanges(ts, descriptor.scriptSetup.ast, vueCompilerOptions) : undefined;
726726

727727
if (descriptor.scriptSetup && scriptSetupRanges?.props.withDefaults?.arg) {
@@ -772,7 +772,7 @@ function readVueComponentDefaultProps(
772772

773773
function scriptWorker() {
774774

775-
const descriptor = vueSourceFile.sfc;
775+
const descriptor = vueSourceFile._sfc;
776776

777777
if (descriptor.script) {
778778
const scriptResult = readTsComponentDefaultProps(descriptor.script.lang, descriptor.script.content, 'default', printer, ts);

packages/language-core/lib/plugins/vue-tsx.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Mapping } from '@volar/language-core';
2-
import { computed } from 'computeds';
2+
import { computed } from 'alien-signals';
33
import { posix as path } from 'path-browserify';
44
import { generateScript } from '../codegen/script';
55
import { generateTemplate } from '../codegen/template';
@@ -30,8 +30,8 @@ const plugin: VueLanguagePlugin = ctx => {
3030
id: string;
3131
lang: string;
3232
}[] = [];
33-
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
34-
files.push({ id: 'script_' + tsx.lang(), lang: tsx.lang() });
33+
if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.get())) {
34+
files.push({ id: 'script_' + tsx.lang.get(), lang: tsx.lang.get() });
3535
}
3636
return files;
3737
},
@@ -41,7 +41,7 @@ const plugin: VueLanguagePlugin = ctx => {
4141
const _tsx = useTsx(fileName, sfc);
4242

4343
if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
44-
const tsx = _tsx.generatedScript();
44+
const tsx = _tsx.generatedScript.get();
4545
if (tsx) {
4646
const content: Code[] = [...tsx.codes];
4747
embeddedFile.content = content;
@@ -102,14 +102,14 @@ function createTsx(
102102
vueCompilerOptions: ctx.vueCompilerOptions,
103103
template: _sfc.template,
104104
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
105-
scriptSetupBindingNames: scriptSetupBindingNames(),
106-
scriptSetupImportComponentNames: scriptSetupImportComponentNames(),
107-
destructuredPropNames: destructuredPropNames(),
108-
templateRefNames: templateRefNames(),
109-
hasDefineSlots: hasDefineSlots(),
110-
slotsAssignName: slotsAssignName(),
111-
propsAssignName: propsAssignName(),
112-
inheritAttrs: inheritAttrs(),
105+
scriptSetupBindingNames: scriptSetupBindingNames.get(),
106+
scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
107+
destructuredPropNames: destructuredPropNames.get(),
108+
templateRefNames: templateRefNames.get(),
109+
hasDefineSlots: hasDefineSlots.get(),
110+
slotsAssignName: slotsAssignName.get(),
111+
propsAssignName: propsAssignName.get(),
112+
inheritAttrs: inheritAttrs.get(),
113113
});
114114

115115
let current = codegen.next();
@@ -127,7 +127,7 @@ function createTsx(
127127
});
128128
const scriptSetupBindingNames = computed<Set<string>>(oldNames => {
129129
const newNames = new Set<string>();
130-
const bindings = scriptSetupRanges()?.bindings;
130+
const bindings = scriptSetupRanges.get()?.bindings;
131131
if (_sfc.scriptSetup && bindings) {
132132
for (const binding of bindings) {
133133
newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
@@ -139,15 +139,15 @@ function createTsx(
139139
return newNames;
140140
});
141141
const scriptSetupImportComponentNames = computed<Set<string>>(oldNames => {
142-
const newNames = scriptSetupRanges()?.importComponentNames ?? new Set();
142+
const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
143143
if (oldNames && twoSetsEqual(newNames, oldNames)) {
144144
return oldNames;
145145
}
146146
return newNames;
147147
});
148148
const destructuredPropNames = computed<Set<string>>(oldNames => {
149-
const newNames = scriptSetupRanges()?.props.destructured ?? new Set();
150-
const rest = scriptSetupRanges()?.props.destructuredRest;
149+
const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
150+
const rest = scriptSetupRanges.get()?.props.destructuredRest;
151151
if (rest) {
152152
newNames.add(rest);
153153
}
@@ -158,7 +158,7 @@ function createTsx(
158158
});
159159
const templateRefNames = computed<Set<string>>(oldNames => {
160160
const newNames = new Set(
161-
scriptSetupRanges()?.templateRefs
161+
scriptSetupRanges.get()?.templateRefs
162162
.map(({ name }) => name)
163163
.filter(name => name !== undefined)
164164
);
@@ -167,11 +167,11 @@ function createTsx(
167167
}
168168
return newNames;
169169
});
170-
const hasDefineSlots = computed(() => !!scriptSetupRanges()?.slots.define);
171-
const slotsAssignName = computed(() => scriptSetupRanges()?.slots.name);
172-
const propsAssignName = computed(() => scriptSetupRanges()?.props.name);
170+
const hasDefineSlots = computed(() => !!scriptSetupRanges.get()?.slots.define);
171+
const slotsAssignName = computed(() => scriptSetupRanges.get()?.slots.name);
172+
const propsAssignName = computed(() => scriptSetupRanges.get()?.props.name);
173173
const inheritAttrs = computed(() => {
174-
const value = scriptSetupRanges()?.options.inheritAttrs ?? scriptRanges()?.exportDefault?.inheritAttrsOption;
174+
const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
175175
return value !== 'false';
176176
});
177177
const generatedScript = computed(() => {
@@ -182,10 +182,10 @@ function createTsx(
182182
ts,
183183
fileBaseName: path.basename(fileName),
184184
sfc: _sfc,
185-
lang: lang(),
186-
scriptRanges: scriptRanges(),
187-
scriptSetupRanges: scriptSetupRanges(),
188-
templateCodegen: generatedTemplate(),
185+
lang: lang.get(),
186+
scriptRanges: scriptRanges.get(),
187+
scriptSetupRanges: scriptSetupRanges.get(),
188+
templateCodegen: generatedTemplate.get(),
189189
compilerOptions: ctx.compilerOptions,
190190
vueCompilerOptions: ctx.vueCompilerOptions,
191191
edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,

packages/language-core/lib/virtualFile/computedEmbeddedCodes.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { VirtualCode } from '@volar/language-core';
2-
import { computed } from 'computeds';
2+
import { Computed, computed } from 'alien-signals';
33
import { toString } from 'muggle-string';
44
import type * as ts from 'typescript';
55
import type { Code, Sfc, SfcBlock, VueLanguagePluginReturn } from '../types';
@@ -32,12 +32,12 @@ export function computedEmbeddedCodes(
3232
return blocks;
3333
});
3434
const pluginsResult = plugins.map(plugin => computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, nameToBlock));
35-
const flatResult = computed(() => pluginsResult.map(r => r()).flat());
35+
const flatResult = computed(() => pluginsResult.map(r => r.get()).flat());
3636
const structuredResult = computed(() => {
3737

3838
const embeddedCodes: VirtualCode[] = [];
3939

40-
let remain = [...flatResult()];
40+
let remain = [...flatResult.get()];
4141

4242
while (remain.length) {
4343
const beforeLength = remain.length;
@@ -105,9 +105,9 @@ function computedPluginEmbeddedCodes(
105105
plugin: VueLanguagePluginReturn,
106106
fileName: string,
107107
sfc: Sfc,
108-
nameToBlock: () => Record<string, SfcBlock>
108+
nameToBlock: Computed<Record<string, SfcBlock>>
109109
) {
110-
const computeds = new Map<string, () => { code: VueEmbeddedCode; snapshot: ts.IScriptSnapshot; }>();
110+
const computeds = new Map<string, Computed<{ code: VueEmbeddedCode; snapshot: ts.IScriptSnapshot; }>>();
111111
const getComputedKey = (code: {
112112
id: string;
113113
lang: string;
@@ -171,8 +171,8 @@ function computedPluginEmbeddedCodes(
171171
});
172172

173173
return computed(() => {
174-
return codes().map(_file => {
175-
const { code, snapshot } = _file();
174+
return codes.get().map(_file => {
175+
const { code, snapshot } = _file.get();
176176
const mappings = buildMappings(code.content.map<Code>(segment => {
177177
if (typeof segment === 'string') {
178178
return segment;
@@ -181,7 +181,7 @@ function computedPluginEmbeddedCodes(
181181
if (source === undefined) {
182182
return segment;
183183
}
184-
const block = nameToBlock()[source];
184+
const block = nameToBlock.get()[source];
185185
if (!block) {
186186
// console.warn('Unable to find block: ' + source);
187187
return segment;

0 commit comments

Comments
 (0)