/
types.ts
101 lines (91 loc) · 3.07 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import type { SFCParseResult } from '@vue/compiler-sfc';
import * as CompilerDom from '@vue/compiler-dom';
import type * as ts from 'typescript/lib/tsserverlibrary';
import { VueEmbeddedFile } from './sourceFile';
export type { SFCParseResult } from '@vue/compiler-sfc';
export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
target?: 'auto' | 2 | 2.7 | 3 | 3.3;
plugins?: string[];
};
export interface VueCompilerOptions {
target: number;
lib: string;
extensions: string[];
jsxSlots: boolean;
strictTemplates: boolean;
skipTemplateCodegen: boolean;
dataAttributes: string[];
htmlAttributes: string[];
optionsWrapper: [string, string] | [];
macros: {
defineProps: string[],
defineSlots: string[],
defineEmits: string[],
defineExpose: string[],
withDefaults: string[],
};
plugins: VueLanguagePlugin[];
hooks: string[];
// experimental
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
experimentalUseElementAccessInTemplate: boolean;
experimentalAdditionalLanguageModules: string[];
}
export type VueLanguagePlugin = (ctx: {
modules: {
typescript: typeof import('typescript/lib/tsserverlibrary');
'@vue/compiler-dom': typeof import('@vue/compiler-dom');
},
compilerOptions: ts.CompilerOptions,
vueCompilerOptions: VueCompilerOptions,
}) => {
version: 1;
name?: string;
order?: number;
parseSFC?(fileName: string, content: string): SFCParseResult | undefined;
updateSFC?(oldResult: SFCParseResult, textChange: { start: number, end: number, newText: string; }): SFCParseResult | undefined;
resolveTemplateCompilerOptions?(options: CompilerDom.CompilerOptions): CompilerDom.CompilerOptions;
compileSFCTemplate?(lang: string, template: string, options: CompilerDom.CompilerOptions): CompilerDom.CodegenResult | undefined;
updateSFCTemplate?(oldResult: CompilerDom.CodegenResult, textChange: { start: number, end: number, newText: string; }): CompilerDom.CodegenResult | undefined;
getEmbeddedFileNames?(fileName: string, sfc: Sfc): string[];
resolveEmbeddedFile?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedFile): void;
};
export interface SfcBlock {
name: string,
start: number;
end: number;
startTagEnd: number;
endTagStart: number;
lang: string;
content: string;
attrs: Record<string, string | true>;
}
export interface Sfc {
template: SfcBlock | null;
script: (SfcBlock & {
src: string | undefined;
srcOffset: number;
}) | null;
scriptSetup: SfcBlock & {
// https://github.com/vuejs/rfcs/discussions/436
generic: string | undefined;
genericOffset: number;
} | null;
styles: (SfcBlock & {
module: string | undefined;
scoped: boolean;
})[];
customBlocks: (SfcBlock & {
type: string;
})[];
// ast
templateAst: CompilerDom.RootNode | undefined;
scriptAst: ts.SourceFile | undefined;
scriptSetupAst: ts.SourceFile | undefined;
}
export interface TextRange {
start: number,
end: number,
}