@vue/language-core 1.8.18 → 1.8.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,23 +4,14 @@ exports.getStartEnd = exports.findBindingVars = exports.parseBindingRanges = exp
4
4
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
5
5
  let foundNonImportExportNode = false;
6
6
  let importSectionEndOffset = 0;
7
- let withDefaultsArg;
8
- let propsAssignName;
9
- let withDefaults;
10
- let defineProps;
11
- let propsRuntimeArg;
12
- let propsTypeArg;
13
- let defineSlots;
14
- let defineEmits;
15
- let defineExpose;
16
- let slotsAssignName;
17
- let emitsAssignName;
18
- let exposeRuntimeArg;
19
- let exposeTypeArg;
7
+ const props = {};
8
+ const slots = {};
9
+ const emits = {};
10
+ const expose = {};
20
11
  const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
21
12
  const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.getFullText().trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
22
13
  const defineProp = [];
23
- const bindings = parseBindingRanges(ts, ast, false);
14
+ const bindings = parseBindingRanges(ts, ast);
24
15
  const text = ast.getFullText();
25
16
  const leadingCommentEndOffset = ts.getLeadingCommentRanges(text, 0)?.reverse()[0].end ?? 0;
26
17
  ast.forEachChild(node => {
@@ -42,30 +33,22 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
42
33
  foundNonImportExportNode = true;
43
34
  }
44
35
  });
45
- ast.forEachChild(child => visitNode(child, ast));
36
+ ast.forEachChild(child => visitNode(child, [ast]));
46
37
  return {
47
38
  leadingCommentEndOffset,
48
39
  importSectionEndOffset,
49
40
  bindings,
50
- withDefaultsArg,
51
- withDefaults,
52
- defineProps,
53
- defineSlots,
54
- defineEmits,
55
- defineExpose,
56
- propsAssignName,
57
- propsRuntimeArg,
58
- propsTypeArg,
59
- slotsAssignName,
60
- emitsAssignName,
61
- exposeRuntimeArg,
62
- exposeTypeArg,
41
+ props,
42
+ slots,
43
+ emits,
44
+ expose,
63
45
  defineProp,
64
46
  };
65
47
  function _getStartEnd(node) {
66
48
  return getStartEnd(node, ast);
67
49
  }
68
- function visitNode(node, parent) {
50
+ function visitNode(node, parents) {
51
+ const parent = parents[parents.length - 1];
69
52
  if (ts.isCallExpression(node)
70
53
  && ts.isIdentifier(node.expression)) {
71
54
  const callText = node.expression.getText(ast);
@@ -145,90 +128,102 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
145
128
  }
146
129
  }
147
130
  else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
148
- defineSlots = _getStartEnd(node);
131
+ slots.define = _getStartEnd(node);
149
132
  if (ts.isVariableDeclaration(parent)) {
150
- slotsAssignName = parent.name.getText(ast);
133
+ slots.name = parent.name.getText(ast);
151
134
  }
152
135
  }
153
136
  else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
154
- defineEmits = _getStartEnd(node);
137
+ emits.define = _getStartEnd(node);
155
138
  if (ts.isVariableDeclaration(parent)) {
156
- emitsAssignName = parent.name.getText(ast);
139
+ emits.name = parent.name.getText(ast);
157
140
  }
158
141
  }
159
142
  else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
160
- defineExpose = _getStartEnd(node);
143
+ expose.define = _getStartEnd(node);
161
144
  if (node.arguments.length) {
162
- exposeRuntimeArg = _getStartEnd(node.arguments[0]);
145
+ expose.define.arg = _getStartEnd(node.arguments[0]);
163
146
  }
164
147
  if (node.typeArguments?.length) {
165
- exposeTypeArg = _getStartEnd(node.typeArguments[0]);
148
+ expose.define.typeArg = _getStartEnd(node.typeArguments[0]);
166
149
  }
167
150
  }
168
151
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
169
- defineProps = _getStartEnd(node);
152
+ let statementRange;
153
+ for (let i = parents.length - 1; i >= 0; i--) {
154
+ if (ts.isStatement(parents[i])) {
155
+ const statement = parents[i];
156
+ statement.forEachChild(child => {
157
+ const range = _getStartEnd(child);
158
+ statementRange ??= range;
159
+ statementRange.end = range.end;
160
+ });
161
+ break;
162
+ }
163
+ }
164
+ if (!statementRange) {
165
+ statementRange = _getStartEnd(node);
166
+ }
167
+ props.define = {
168
+ ..._getStartEnd(node),
169
+ statement: statementRange,
170
+ };
170
171
  if (ts.isVariableDeclaration(parent)) {
171
- propsAssignName = parent.name.getText(ast);
172
+ props.name = parent.name.getText(ast);
172
173
  }
173
174
  if (node.arguments.length) {
174
- propsRuntimeArg = _getStartEnd(node.arguments[0]);
175
+ props.define.arg = _getStartEnd(node.arguments[0]);
175
176
  }
176
177
  if (node.typeArguments?.length) {
177
- propsTypeArg = _getStartEnd(node.typeArguments[0]);
178
+ props.define.typeArg = _getStartEnd(node.typeArguments[0]);
178
179
  }
179
180
  }
180
181
  else if (vueCompilerOptions.macros.withDefaults.includes(callText)) {
181
- withDefaults = _getStartEnd(node);
182
+ props.withDefaults = _getStartEnd(node);
182
183
  if (node.arguments.length >= 2) {
183
184
  const arg = node.arguments[1];
184
- withDefaultsArg = _getStartEnd(arg);
185
+ props.withDefaults.arg = _getStartEnd(arg);
185
186
  }
186
187
  if (ts.isVariableDeclaration(parent)) {
187
- propsAssignName = parent.name.getText(ast);
188
+ props.name = parent.name.getText(ast);
188
189
  }
189
190
  }
190
191
  }
191
- node.forEachChild(child => visitNode(child, node));
192
+ node.forEachChild(child => {
193
+ parents.push(node);
194
+ visitNode(child, parents);
195
+ parents.pop();
196
+ });
192
197
  }
193
198
  }
194
199
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
195
- function parseBindingRanges(ts, sourceFile, isType) {
200
+ function parseBindingRanges(ts, sourceFile) {
196
201
  const bindings = [];
197
202
  sourceFile.forEachChild(node => {
198
- if (!isType) {
199
- if (ts.isVariableStatement(node)) {
200
- for (const node_2 of node.declarationList.declarations) {
201
- const vars = _findBindingVars(node_2.name);
202
- for (const _var of vars) {
203
- bindings.push(_var);
204
- }
205
- }
206
- }
207
- else if (ts.isFunctionDeclaration(node)) {
208
- if (node.name && ts.isIdentifier(node.name)) {
209
- bindings.push(_getStartEnd(node.name));
203
+ if (ts.isVariableStatement(node)) {
204
+ for (const node_2 of node.declarationList.declarations) {
205
+ const vars = _findBindingVars(node_2.name);
206
+ for (const _var of vars) {
207
+ bindings.push(_var);
210
208
  }
211
209
  }
212
- else if (ts.isClassDeclaration(node)) {
213
- if (node.name) {
214
- bindings.push(_getStartEnd(node.name));
215
- }
216
- }
217
- else if (ts.isEnumDeclaration(node)) {
218
- bindings.push(_getStartEnd(node.name));
219
- }
220
210
  }
221
- else {
222
- if (ts.isTypeAliasDeclaration(node)) {
211
+ else if (ts.isFunctionDeclaration(node)) {
212
+ if (node.name && ts.isIdentifier(node.name)) {
223
213
  bindings.push(_getStartEnd(node.name));
224
214
  }
225
- else if (ts.isInterfaceDeclaration(node)) {
215
+ }
216
+ else if (ts.isClassDeclaration(node)) {
217
+ if (node.name) {
226
218
  bindings.push(_getStartEnd(node.name));
227
219
  }
228
220
  }
221
+ else if (ts.isEnumDeclaration(node)) {
222
+ bindings.push(_getStartEnd(node.name));
223
+ }
229
224
  if (ts.isImportDeclaration(node)) {
230
- if (node.importClause && (isType || !node.importClause.isTypeOnly)) {
231
- if (node.importClause.name && !isType) {
225
+ if (node.importClause && !node.importClause.isTypeOnly) {
226
+ if (node.importClause.name) {
232
227
  bindings.push(_getStartEnd(node.importClause.name));
233
228
  }
234
229
  if (node.importClause.namedBindings) {
@@ -1,7 +1,7 @@
1
1
  import { Sfc, VueLanguagePlugin } from '../types';
2
2
  import * as muggle from 'muggle-string';
3
3
  export declare const tsCodegen: WeakMap<Sfc, {
4
- scriptRanges: import("@vue/reactivity").ComputedRef<{
4
+ scriptRanges: () => {
5
5
  exportDefault: (import("../types").TextRange & {
6
6
  expression: import("../types").TextRange;
7
7
  args: import("../types").TextRange;
@@ -11,24 +11,37 @@ export declare const tsCodegen: WeakMap<Sfc, {
11
11
  nameOption: import("../types").TextRange | undefined;
12
12
  }) | undefined;
13
13
  bindings: import("../types").TextRange[];
14
- } | undefined>;
15
- scriptSetupRanges: import("@vue/reactivity").ComputedRef<{
14
+ } | undefined;
15
+ scriptSetupRanges: () => {
16
16
  leadingCommentEndOffset: number;
17
17
  importSectionEndOffset: number;
18
18
  bindings: import("../types").TextRange[];
19
- withDefaultsArg: import("../types").TextRange | undefined;
20
- withDefaults: import("../types").TextRange | undefined;
21
- defineProps: import("../types").TextRange | undefined;
22
- defineSlots: import("../types").TextRange | undefined;
23
- defineEmits: import("../types").TextRange | undefined;
24
- defineExpose: import("../types").TextRange | undefined;
25
- propsAssignName: string | undefined;
26
- propsRuntimeArg: import("../types").TextRange | undefined;
27
- propsTypeArg: import("../types").TextRange | undefined;
28
- slotsAssignName: string | undefined;
29
- emitsAssignName: string | undefined;
30
- exposeRuntimeArg: import("../types").TextRange | undefined;
31
- exposeTypeArg: import("../types").TextRange | undefined;
19
+ props: {
20
+ name?: string | undefined;
21
+ define?: (import("../types").TextRange & {
22
+ statement: import("../types").TextRange;
23
+ arg?: import("../types").TextRange | undefined;
24
+ typeArg?: import("../types").TextRange | undefined;
25
+ }) | undefined;
26
+ withDefaults?: (import("../types").TextRange & {
27
+ arg?: import("../types").TextRange | undefined;
28
+ }) | undefined;
29
+ };
30
+ slots: {
31
+ name?: string | undefined;
32
+ define?: import("../types").TextRange | undefined;
33
+ };
34
+ emits: {
35
+ name?: string | undefined;
36
+ define?: import("../types").TextRange | undefined;
37
+ };
38
+ expose: {
39
+ name?: string | undefined;
40
+ define?: (import("../types").TextRange & {
41
+ arg?: import("../types").TextRange | undefined;
42
+ typeArg?: import("../types").TextRange | undefined;
43
+ }) | undefined;
44
+ };
32
45
  defineProp: {
33
46
  name: import("../types").TextRange | undefined;
34
47
  nameIsString: boolean;
@@ -36,14 +49,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
36
49
  defaultValue: import("../types").TextRange | undefined;
37
50
  required: boolean;
38
51
  }[];
39
- } | undefined>;
40
- lang: import("@vue/reactivity").ComputedRef<string>;
41
- tsxGen: import("@vue/reactivity").ComputedRef<{
52
+ } | undefined;
53
+ lang: () => string;
54
+ generatedScript: () => {
42
55
  codes: muggle.Segment<import("@volar/language-core").FileRangeCapabilities>[];
43
56
  codeStacks: muggle.StackNode[];
44
57
  mirrorBehaviorMappings: import("@volar/source-map").Mapping<[import("@volar/language-core").MirrorBehaviorCapabilities, import("@volar/language-core").MirrorBehaviorCapabilities]>[];
45
- }>;
46
- htmlGen: import("@vue/reactivity").ComputedRef<{
58
+ };
59
+ generatedTemplate: () => {
47
60
  codes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
48
61
  codeStacks: muggle.StackNode[];
49
62
  formatCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
@@ -51,9 +64,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
51
64
  cssCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
52
65
  cssCodeStacks: muggle.StackNode[];
53
66
  tagNames: Record<string, number[]>;
54
- identifiers: Set<string>;
67
+ accessedGlobalVariables: Set<string>;
55
68
  hasSlot: boolean;
56
- } | undefined>;
69
+ } | undefined;
57
70
  }>;
58
71
  declare const plugin: VueLanguagePlugin;
59
72
  export default plugin;
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.tsCodegen = void 0;
27
- const reactivity_1 = require("@vue/reactivity");
27
+ const computeds_1 = require("computeds");
28
28
  const script_1 = require("../generators/script");
29
- const templateGen = __importStar(require("../generators/template"));
29
+ const template_1 = require("../generators/template");
30
30
  const scriptRanges_1 = require("../parsers/scriptRanges");
31
31
  const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
32
32
  const language_core_1 = require("@volar/language-core");
@@ -44,8 +44,8 @@ const plugin = (ctx) => {
44
44
  getEmbeddedFileNames(fileName, sfc) {
45
45
  const tsx = useTsx(fileName, sfc);
46
46
  const fileNames = [];
47
- if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.value)) {
48
- fileNames.push(fileName + '.' + tsx.lang.value);
47
+ if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
48
+ fileNames.push(fileName + '.' + tsx.lang());
49
49
  }
50
50
  if (sfc.template) {
51
51
  fileNames.push(fileName + '.template_format.ts');
@@ -56,7 +56,7 @@ const plugin = (ctx) => {
56
56
  resolveEmbeddedFile(fileName, sfc, embeddedFile) {
57
57
  const _tsx = useTsx(fileName, sfc);
58
58
  const suffix = embeddedFile.fileName.replace(fileName, '');
59
- if (suffix === '.' + _tsx.lang.value) {
59
+ if (suffix === '.' + _tsx.lang()) {
60
60
  embeddedFile.kind = language_core_1.FileKind.TypeScriptHostFile;
61
61
  embeddedFile.capabilities = {
62
62
  ...language_core_1.FileCapabilities.full,
@@ -64,7 +64,7 @@ const plugin = (ctx) => {
64
64
  documentFormatting: false,
65
65
  documentSymbol: false,
66
66
  };
67
- const tsx = _tsx.tsxGen.value;
67
+ const tsx = _tsx.generatedScript();
68
68
  if (tsx) {
69
69
  const [content, contentStacks] = ctx.codegenStack ? muggle.track([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
70
70
  embeddedFile.content = content;
@@ -82,8 +82,11 @@ const plugin = (ctx) => {
82
82
  codeAction: false,
83
83
  inlayHint: false,
84
84
  };
85
- if (_tsx.htmlGen.value) {
86
- const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.htmlGen.value.formatCodes], [..._tsx.htmlGen.value.formatCodeStacks]) : [[..._tsx.htmlGen.value.formatCodes], [..._tsx.htmlGen.value.formatCodeStacks]];
85
+ const template = _tsx.generatedTemplate();
86
+ if (template) {
87
+ const [content, contentStacks] = ctx.codegenStack
88
+ ? muggle.track([...template.formatCodes], [...template.formatCodeStacks])
89
+ : [[...template.formatCodes], [...template.formatCodeStacks]];
87
90
  embeddedFile.content = content;
88
91
  embeddedFile.contentStacks = contentStacks;
89
92
  }
@@ -103,8 +106,11 @@ const plugin = (ctx) => {
103
106
  }
104
107
  else if (suffix.match(templateStyleCssReg)) {
105
108
  embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
106
- if (_tsx.htmlGen.value) {
107
- const [content, contentStacks] = ctx.codegenStack ? muggle.track([..._tsx.htmlGen.value.cssCodes], [..._tsx.htmlGen.value.cssCodeStacks]) : [[..._tsx.htmlGen.value.cssCodes], [..._tsx.htmlGen.value.cssCodeStacks]];
109
+ const template = _tsx.generatedTemplate();
110
+ if (template) {
111
+ const [content, contentStacks] = ctx.codegenStack
112
+ ? muggle.track([...template.cssCodes], [...template.cssCodeStacks])
113
+ : [[...template.cssCodes], [...template.cssCodeStacks]];
108
114
  embeddedFile.content = content;
109
115
  embeddedFile.contentStacks = contentStacks;
110
116
  }
@@ -123,40 +129,54 @@ const plugin = (ctx) => {
123
129
  exports.default = plugin;
124
130
  function createTsx(fileName, _sfc, { vueCompilerOptions, compilerOptions, codegenStack, modules }) {
125
131
  const ts = modules.typescript;
126
- const lang = (0, reactivity_1.computed)(() => {
132
+ const lang = (0, computeds_1.computed)(() => {
127
133
  return !_sfc.script && !_sfc.scriptSetup ? 'ts'
128
134
  : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
129
135
  : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
130
136
  : 'js';
131
137
  });
132
- const scriptRanges = (0, reactivity_1.computed)(() => _sfc.scriptAst
133
- ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.scriptAst, !!_sfc.scriptSetup, false)
138
+ const scriptRanges = (0, computeds_1.computed)(() => _sfc.script
139
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
134
140
  : undefined);
135
- const scriptSetupRanges = (0, reactivity_1.computed)(() => _sfc.scriptSetupAst
136
- ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetupAst, vueCompilerOptions)
141
+ const scriptSetupRanges = (0, computeds_1.computed)(() => _sfc.scriptSetup
142
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, vueCompilerOptions)
137
143
  : undefined);
138
- const htmlGen = (0, reactivity_1.computed)(() => {
139
- if (!_sfc.templateAst)
140
- return;
141
- return templateGen.generate(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', _sfc, hasScriptSetupSlots.value, slotsAssignName.value, propsAssignName.value, codegenStack);
144
+ const shouldGenerateScopedClasses = (0, computeds_1.computed)(() => {
145
+ const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
146
+ return _sfc.styles.some(s => {
147
+ return option === 'always' || (option === 'scoped' && s.scoped);
148
+ });
142
149
  });
143
- //#region remove when https://github.com/vuejs/core/pull/5912 merged
144
- const hasScriptSetupSlots = (0, reactivity_1.shallowRef)(false);
145
- const slotsAssignName = (0, reactivity_1.shallowRef)();
146
- const propsAssignName = (0, reactivity_1.shallowRef)();
147
- //#endregion
148
- const tsxGen = (0, reactivity_1.computed)(() => {
149
- hasScriptSetupSlots.value = !!scriptSetupRanges.value?.defineSlots;
150
- slotsAssignName.value = scriptSetupRanges.value?.slotsAssignName;
151
- propsAssignName.value = scriptSetupRanges.value?.propsAssignName;
152
- return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, htmlGen.value, compilerOptions, vueCompilerOptions, codegenStack);
150
+ const stylesScopedClasses = (0, computeds_1.computedSet)(() => {
151
+ const classes = new Set();
152
+ if (!shouldGenerateScopedClasses()) {
153
+ return classes;
154
+ }
155
+ for (const style of _sfc.styles) {
156
+ const option = vueCompilerOptions.experimentalResolveStyleCssClasses;
157
+ if ((option === 'always' || option === 'scoped') && style.scoped) {
158
+ for (const className of style.classNames) {
159
+ classes.add(className.text.substring(1));
160
+ }
161
+ }
162
+ }
163
+ return classes;
164
+ });
165
+ const generatedTemplate = (0, computeds_1.computed)(() => {
166
+ if (!_sfc.template)
167
+ return;
168
+ return (0, template_1.generate)(ts, compilerOptions, vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), codegenStack);
153
169
  });
170
+ const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
171
+ const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
172
+ const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
173
+ const generatedScript = (0, computeds_1.computed)(() => (0, script_1.generate)(ts, fileName, _sfc.script, _sfc.scriptSetup, _sfc.styles, lang(), scriptRanges(), scriptSetupRanges(), generatedTemplate(), compilerOptions, vueCompilerOptions, codegenStack));
154
174
  return {
155
175
  scriptRanges,
156
176
  scriptSetupRanges,
157
177
  lang,
158
- tsxGen,
159
- htmlGen,
178
+ generatedScript,
179
+ generatedTemplate,
160
180
  };
161
181
  }
162
182
  //# sourceMappingURL=vue-tsx.js.map
package/out/plugins.d.ts CHANGED
@@ -20,6 +20,6 @@ export declare function getDefaultVueLanguagePlugins(ts: typeof import('typescri
20
20
  newText: string;
21
21
  }): CompilerDOM.CodegenResult | undefined;
22
22
  getEmbeddedFileNames?(fileName: string, sfc: import("./types").Sfc): string[];
23
- resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./sourceFile").VueEmbeddedFile): void;
23
+ resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./virtualFile/embeddedFile").VueEmbeddedFile): void;
24
24
  }[];
25
25
  //# sourceMappingURL=plugins.d.ts.map
package/out/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { SFCParseResult } from '@vue/compiler-sfc';
3
3
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
- import type { VueEmbeddedFile } from './sourceFile';
4
+ import type { VueEmbeddedFile } from './virtualFile/embeddedFile';
5
5
  export type { SFCParseResult } from '@vue/compiler-sfc';
6
6
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
7
7
  target?: 'auto' | 2 | 2.7 | 3 | 3.3;
@@ -75,16 +75,22 @@ export interface SfcBlock {
75
75
  attrs: Record<string, string | true>;
76
76
  }
77
77
  export interface Sfc {
78
- template: SfcBlock | null;
78
+ template: SfcBlock & {
79
+ ast: CompilerDOM.RootNode | undefined;
80
+ errors: CompilerDOM.CompilerError[];
81
+ warnings: CompilerDOM.CompilerError[];
82
+ } | undefined;
79
83
  script: (SfcBlock & {
80
84
  src: string | undefined;
81
85
  srcOffset: number;
82
- }) | null;
86
+ ast: ts.SourceFile;
87
+ }) | undefined;
83
88
  scriptSetup: SfcBlock & {
84
89
  generic: string | undefined;
85
90
  genericOffset: number;
86
- } | null;
87
- styles: (SfcBlock & {
91
+ ast: ts.SourceFile;
92
+ } | undefined;
93
+ styles: readonly (SfcBlock & {
88
94
  module: string | undefined;
89
95
  scoped: boolean;
90
96
  cssVars: {
@@ -96,11 +102,20 @@ export interface Sfc {
96
102
  offset: number;
97
103
  }[];
98
104
  })[];
99
- customBlocks: (SfcBlock & {
105
+ customBlocks: readonly (SfcBlock & {
100
106
  type: string;
101
107
  })[];
108
+ /**
109
+ * @deprecated use `template.ast` instead
110
+ */
102
111
  templateAst: CompilerDOM.RootNode | undefined;
112
+ /**
113
+ * @deprecated use `script.ast` instead
114
+ */
103
115
  scriptAst: ts.SourceFile | undefined;
116
+ /**
117
+ * @deprecated use `scriptSetup.ast` instead
118
+ */
104
119
  scriptSetupAst: ts.SourceFile | undefined;
105
120
  }
106
121
  export interface TextRange {
@@ -15,6 +15,11 @@ type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
15
15
 
16
16
  type __VLS_Prettify<T> = { [K in keyof T]: T[K]; } & {};
17
17
 
18
+ type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> =
19
+ T extends any
20
+ ? Pick<T, Exclude<keyof T, K>>
21
+ : never;
22
+
18
23
  type __VLS_GlobalComponents =
19
24
  __VLS_PickNotAny<import('vue').GlobalComponents, {}>
20
25
  & __VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>
@@ -27,6 +32,8 @@ type __VLS_GlobalComponents =
27
32
  | 'Teleport'
28
33
  >;
29
34
 
35
+ declare const __VLS_intrinsicElements: __VLS_IntrinsicElements;
36
+
30
37
  // v-for
31
38
  declare function __VLS_getVForSourceType(source: number): [number, number, number][];
32
39
  declare function __VLS_getVForSourceType(source: string): [string, number, number][];
@@ -1,9 +1,9 @@
1
1
  import type * as ts from 'typescript/lib/tsserverlibrary';
2
2
  import { VueCompilerOptions } from '../types';
3
- export declare function walkInterpolationFragment(ts: typeof import('typescript/lib/tsserverlibrary'), code: string, ast: ts.SourceFile, cb: (fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean) => void, localVars: Record<string, number>, identifiers: Set<string>, vueOptions: VueCompilerOptions): {
3
+ export declare function walkInterpolationFragment(ts: typeof import('typescript/lib/tsserverlibrary'), code: string, ast: ts.SourceFile, cb: (fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean) => void, localVars: Map<string, number>, identifiers: Set<string>, vueOptions: VueCompilerOptions): {
4
4
  text: string;
5
5
  isShorthand: boolean;
6
6
  offset: number;
7
7
  }[];
8
- export declare function colletVars(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, result: string[]): void;
8
+ export declare function collectVars(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, result: string[]): void;
9
9
  //# sourceMappingURL=transform.d.ts.map
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.colletVars = exports.walkInterpolationFragment = void 0;
3
+ exports.collectVars = exports.walkInterpolationFragment = void 0;
4
4
  const shared_1 = require("@vue/shared");
5
5
  function walkInterpolationFragment(ts, code, ast, cb, localVars, identifiers, vueOptions) {
6
6
  let ctxVars = [];
7
7
  const varCb = (id, isShorthand) => {
8
- if (!!localVars[id.text] ||
8
+ if (localVars.get(id.text) ||
9
9
  // https://github.com/vuejs/core/blob/245230e135152900189f13a4281302de45fdcfaa/packages/compiler-core/src/transforms/transformExpression.ts#L342-L352
10
10
  (0, shared_1.isGloballyWhitelisted)(id.text) ||
11
11
  id.text === 'require' ||
@@ -99,9 +99,9 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
99
99
  walkIdentifiers(ts, node.expression, cb, localVars, blockVars, false);
100
100
  }
101
101
  else if (ts.isVariableDeclaration(node)) {
102
- colletVars(ts, node.name, blockVars);
102
+ collectVars(ts, node.name, blockVars);
103
103
  for (const varName of blockVars) {
104
- localVars[varName] = (localVars[varName] ?? 0) + 1;
104
+ localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
105
105
  }
106
106
  if (node.initializer)
107
107
  walkIdentifiers(ts, node.initializer, cb, localVars, blockVars, false);
@@ -109,16 +109,16 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
109
109
  else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
110
110
  const functionArgs = [];
111
111
  for (const param of node.parameters) {
112
- colletVars(ts, param.name, functionArgs);
112
+ collectVars(ts, param.name, functionArgs);
113
113
  if (param.type) {
114
114
  walkIdentifiers(ts, param.type, cb, localVars, blockVars, false);
115
115
  }
116
116
  }
117
117
  for (const varName of functionArgs)
118
- localVars[varName] = (localVars[varName] ?? 0) + 1;
118
+ localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
119
119
  walkIdentifiers(ts, node.body, cb, localVars, blockVars, false);
120
120
  for (const varName of functionArgs)
121
- localVars[varName]--;
121
+ localVars.set(varName, localVars.get(varName) - 1);
122
122
  }
123
123
  else if (ts.isObjectLiteralExpression(node)) {
124
124
  for (const prop of node.properties) {
@@ -152,14 +152,14 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
152
152
  node.forEachChild(node => walkIdentifiers(ts, node, cb, localVars, blockVars, false));
153
153
  if (ts.isBlock(node)) {
154
154
  for (const varName of blockVars) {
155
- localVars[varName]--;
155
+ localVars.set(varName, localVars.get(varName) - 1);
156
156
  }
157
157
  }
158
158
  blockVars = _blockVars;
159
159
  }
160
160
  if (isRoot) {
161
161
  for (const varName of blockVars) {
162
- localVars[varName]--;
162
+ localVars.set(varName, localVars.get(varName) - 1);
163
163
  }
164
164
  }
165
165
  }
@@ -171,25 +171,25 @@ function walkIdentifiersInTypeReference(ts, node, cb) {
171
171
  node.forEachChild(node => walkIdentifiersInTypeReference(ts, node, cb));
172
172
  }
173
173
  }
174
- function colletVars(ts, node, result) {
174
+ function collectVars(ts, node, result) {
175
175
  if (ts.isIdentifier(node)) {
176
176
  result.push(node.text);
177
177
  }
178
178
  else if (ts.isObjectBindingPattern(node)) {
179
179
  for (const el of node.elements) {
180
- colletVars(ts, el.name, result);
180
+ collectVars(ts, el.name, result);
181
181
  }
182
182
  }
183
183
  else if (ts.isArrayBindingPattern(node)) {
184
184
  for (const el of node.elements) {
185
185
  if (ts.isBindingElement(el)) {
186
- colletVars(ts, el.name, result);
186
+ collectVars(ts, el.name, result);
187
187
  }
188
188
  }
189
189
  }
190
190
  else {
191
- node.forEachChild(node => colletVars(ts, node, result));
191
+ node.forEachChild(node => collectVars(ts, node, result));
192
192
  }
193
193
  }
194
- exports.colletVars = colletVars;
194
+ exports.collectVars = collectVars;
195
195
  //# sourceMappingURL=transform.js.map
@@ -0,0 +1,4 @@
1
+ import { VirtualFile } from '@volar/language-core';
2
+ import type { Sfc, VueLanguagePlugin } from '../types';
3
+ export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc, codegenStack: boolean): () => VirtualFile[];
4
+ //# sourceMappingURL=computedFiles.d.ts.map