Skip to content

Commit fce856b

Browse files
committed
refactor(language-core): use internal property to pass style module info
1 parent 47f6715 commit fce856b

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

packages/language-core/lib/types.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ export interface SfcBlock {
101101
attrs: Record<string, string | true>;
102102
}
103103

104-
export interface SFCStyleOverride {
105-
module?: {
106-
name: string;
107-
offset?: number;
108-
};
109-
}
110-
111104
export interface Sfc {
112105
content: string;
113106
template: SfcBlock & {
@@ -126,8 +119,12 @@ export interface Sfc {
126119
genericOffset: number;
127120
ast: ts.SourceFile;
128121
} | undefined;
129-
styles: readonly (SfcBlock & SFCStyleOverride & {
122+
styles: readonly (SfcBlock & {
130123
scoped: boolean;
124+
module?: {
125+
name: string;
126+
offset?: number;
127+
};
131128
cssVars: {
132129
text: string;
133130
offset: number;
@@ -142,6 +139,15 @@ export interface Sfc {
142139
})[];
143140
}
144141

142+
declare module '@vue/compiler-sfc' {
143+
interface SFCStyleBlock {
144+
__module?: {
145+
name: string;
146+
offset?: number;
147+
};
148+
}
149+
}
150+
145151
export interface TextRange {
146152
start: number;
147153
end: number;

packages/language-core/lib/utils/parseSfc.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ElementNode, SourceLocation } from '@vue/compiler-dom';
22
import * as compiler from '@vue/compiler-dom';
33
import type { CompilerError, SFCBlock, SFCDescriptor, SFCParseResult, SFCScriptBlock, SFCStyleBlock, SFCTemplateBlock } from '@vue/compiler-sfc';
4-
import { SFCStyleOverride } from '../types';
54

65
export function parse(source: string): SFCParseResult {
76

@@ -92,8 +91,7 @@ function createBlock(node: ElementNode, source: string) {
9291
};
9392
const attrs: Record<string, any> = {};
9493
const block: SFCBlock
95-
& Pick<SFCStyleBlock, 'scoped'>
96-
& Pick<SFCStyleOverride, 'module'>
94+
& Pick<SFCStyleBlock, 'scoped' | '__module'>
9795
& Pick<SFCScriptBlock, 'setup'> = {
9896
type,
9997
content,
@@ -114,7 +112,7 @@ function createBlock(node: ElementNode, source: string) {
114112
block.scoped = true;
115113
}
116114
else if (p.name === 'module') {
117-
block.module = {
115+
block.__module = {
118116
name: p.value?.content ?? '$style',
119117
offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
120118
};

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type * as CompilerDOM from '@vue/compiler-dom';
22
import type { SFCBlock, SFCParseResult } from '@vue/compiler-sfc';
33
import { computed, ISignal, Signal, System, Unstable } from 'alien-signals';
44
import type * as ts from 'typescript';
5-
import type { Sfc, SfcBlock, SFCStyleOverride, VueLanguagePluginReturn } from '../types';
5+
import type { Sfc, SfcBlock, VueLanguagePluginReturn } from '../types';
66
import { parseCssClassNames } from '../utils/parseCssClassNames';
77
import { parseCssVars } from '../utils/parseCssVars';
88

@@ -118,10 +118,10 @@ export function computedSfc(
118118
(block, i) => {
119119
const base = computedSfcBlock('style_' + i, 'css', block);
120120
const module = computed(() => {
121-
const _module = block.get().module as SFCStyleOverride['module'];
122-
return _module ? {
123-
name: _module.name,
124-
offset: _module.offset ? base.start + _module.offset : undefined
121+
const { __module } = block.get();
122+
return __module ? {
123+
name: __module.name,
124+
offset: __module.offset ? base.start + __module.offset : undefined
125125
} : undefined;
126126
});
127127
const scoped = computed(() => !!block.get().scoped);

0 commit comments

Comments
 (0)