@vue/language-core 3.0.8 → 3.1.0

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.
Files changed (37) hide show
  1. package/lib/codegen/globalTypes.js +19 -13
  2. package/lib/codegen/localTypes.d.ts +2 -4
  3. package/lib/codegen/localTypes.js +10 -33
  4. package/lib/codegen/script/component.d.ts +0 -3
  5. package/lib/codegen/script/component.js +15 -22
  6. package/lib/codegen/script/context.d.ts +2 -4
  7. package/lib/codegen/script/index.d.ts +4 -6
  8. package/lib/codegen/script/index.js +70 -59
  9. package/lib/codegen/script/scriptSetup.js +140 -141
  10. package/lib/codegen/script/template.d.ts +1 -3
  11. package/lib/codegen/script/template.js +90 -16
  12. package/lib/codegen/template/context.js +1 -1
  13. package/lib/codegen/template/element.js +1 -3
  14. package/lib/codegen/template/elementProps.js +2 -6
  15. package/lib/codegen/template/index.d.ts +1 -1
  16. package/lib/codegen/template/index.js +10 -10
  17. package/lib/codegen/utils/index.d.ts +1 -0
  18. package/lib/codegen/utils/index.js +7 -0
  19. package/lib/compilerOptions.js +1 -3
  20. package/lib/languagePlugin.js +8 -19
  21. package/lib/parsers/scriptRanges.d.ts +0 -1
  22. package/lib/parsers/scriptRanges.js +6 -9
  23. package/lib/parsers/scriptSetupRanges.d.ts +0 -6
  24. package/lib/parsers/scriptSetupRanges.js +7 -93
  25. package/lib/parsers/utils.d.ts +12 -0
  26. package/lib/parsers/utils.js +95 -0
  27. package/lib/plugins/vue-tsx.d.ts +2 -5
  28. package/lib/plugins/vue-tsx.js +15 -10
  29. package/lib/types.d.ts +1 -1
  30. package/lib/utils/shared.d.ts +0 -1
  31. package/lib/utils/shared.js +0 -4
  32. package/lib/virtualFile/computedSfc.js +4 -4
  33. package/package.json +3 -4
  34. package/lib/codegen/script/componentSelf.d.ts +0 -5
  35. package/lib/codegen/script/componentSelf.js +0 -53
  36. package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
  37. package/lib/utils/vue2TemplateCompiler.js +0 -90
@@ -245,9 +245,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
245
245
  ],
246
246
  dataAttributes: [],
247
247
  htmlAttributes: ['aria-*'],
248
- optionsWrapper: target >= 2.7
249
- ? [`(await import('${lib}')).defineComponent(`, `)`]
250
- : [`(await import('${lib}')).default.extend(`, `)`],
248
+ optionsWrapper: [`(await import('${lib}')).defineComponent(`, `)`],
251
249
  macros: {
252
250
  defineProps: ['defineProps'],
253
251
  defineSlots: ['defineSlots'],
@@ -6,7 +6,6 @@ exports.getAllExtensions = getAllExtensions;
6
6
  const language_core_1 = require("@volar/language-core");
7
7
  const CompilerDOM = require("@vue/compiler-dom");
8
8
  const plugins_1 = require("./plugins");
9
- const CompilerVue2 = require("./utils/vue2TemplateCompiler");
10
9
  const vueFile_1 = require("./virtualFile/vueFile");
11
10
  const fileRegistries = [];
12
11
  function getVueFileRegistry(key, plugins) {
@@ -38,12 +37,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
38
37
  function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
39
38
  const pluginContext = {
40
39
  modules: {
41
- '@vue/compiler-dom': vueCompilerOptions.target < 3
42
- ? {
43
- ...CompilerDOM,
44
- compile: CompilerVue2.compile,
45
- }
46
- : CompilerDOM,
40
+ '@vue/compiler-dom': CompilerDOM,
47
41
  typescript: ts,
48
42
  },
49
43
  compilerOptions,
@@ -109,17 +103,12 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
109
103
  };
110
104
  }
111
105
  function getAllExtensions(options) {
112
- const result = new Set();
113
- for (const key in options) {
114
- if (key === 'extensions' || key.endsWith('Extensions')) {
115
- const value = options[key];
116
- if (Array.isArray(value) && value.every(v => typeof v === 'string')) {
117
- for (const ext of value) {
118
- result.add(ext);
119
- }
120
- }
121
- }
122
- }
123
- return [...result];
106
+ return [
107
+ ...new Set([
108
+ 'extensions',
109
+ 'vitePressExtensions',
110
+ 'petiteVueExtensions',
111
+ ].flatMap(key => options[key])),
112
+ ];
124
113
  }
125
114
  //# sourceMappingURL=languagePlugin.js.map
@@ -13,7 +13,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
13
13
  nameOption: TextRange | undefined;
14
14
  inheritAttrsOption: string | undefined;
15
15
  }) | undefined;
16
- classBlockEnd: number | undefined;
17
16
  bindings: {
18
17
  range: TextRange;
19
18
  moduleName?: string;
@@ -2,11 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptRanges = parseScriptRanges;
4
4
  const shared_1 = require("../utils/shared");
5
- const scriptSetupRanges_1 = require("./scriptSetupRanges");
5
+ const utils_1 = require("./utils");
6
6
  function parseScriptRanges(ts, ast, hasScriptSetup) {
7
7
  let exportDefault;
8
- let classBlockEnd;
9
- const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
8
+ const bindings = hasScriptSetup ? (0, utils_1.parseBindingRanges)(ts, ast) : [];
10
9
  ts.forEachChild(ast, raw => {
11
10
  if (ts.isExportAssignment(raw)) {
12
11
  let node = raw;
@@ -56,17 +55,15 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
56
55
  nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
57
56
  inheritAttrsOption,
58
57
  };
58
+ const comment = (0, utils_1.getClosestMultiLineCommentRange)(ts, raw, [], ast);
59
+ if (comment) {
60
+ exportDefault.start = comment.start;
61
+ }
59
62
  }
60
63
  }
61
- if (ts.isClassDeclaration(raw)
62
- && raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
63
- && raw.modifiers.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
64
- classBlockEnd = raw.end - 1;
65
- }
66
64
  });
67
65
  return {
68
66
  exportDefault,
69
- classBlockEnd,
70
67
  bindings,
71
68
  };
72
69
  function _getStartEnd(node) {
@@ -66,10 +66,4 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
66
66
  useSlots: CallExpressionRange[];
67
67
  useTemplateRef: UseTemplateRef[];
68
68
  };
69
- export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
70
- range: TextRange;
71
- moduleName?: string;
72
- isDefaultImport?: boolean;
73
- isNamespace?: boolean;
74
- }[];
75
69
  export {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
- exports.parseBindingRanges = parseBindingRanges;
5
4
  const collectBindings_1 = require("../utils/collectBindings");
6
5
  const shared_1 = require("../utils/shared");
7
- const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
6
+ const utils_1 = require("./utils");
7
+ const tsCheckReg = /^\/\/\s*@ts-(?:no)?check(?:$|\s)/;
8
8
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
9
9
  const defineModel = [];
10
10
  let defineProps;
@@ -20,7 +20,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
20
20
  const text = ast.text;
21
21
  const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
22
22
  const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
23
- let bindings = parseBindingRanges(ts, ast);
23
+ let bindings = (0, utils_1.parseBindingRanges)(ts, ast);
24
24
  let foundNonImportExportNode = false;
25
25
  let importSectionEndOffset = 0;
26
26
  ts.forEachChild(ast, node => {
@@ -134,7 +134,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
134
134
  runtimeType,
135
135
  defaultValue,
136
136
  required,
137
- comments: getClosestMultiLineCommentRange(ts, node, parents, ast),
137
+ comments: (0, utils_1.getClosestMultiLineCommentRange)(ts, node, parents, ast),
138
138
  argNode: options,
139
139
  });
140
140
  }
@@ -250,7 +250,9 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
250
250
  }
251
251
  function parseCallExpressionAssignment(node, parent) {
252
252
  return {
253
- name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
253
+ name: ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)
254
+ ? _getNodeText(parent.name)
255
+ : undefined,
254
256
  ...parseCallExpression(node),
255
257
  };
256
258
  }
@@ -261,77 +263,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
261
263
  return (0, shared_1.getNodeText)(ts, node, ast);
262
264
  }
263
265
  }
264
- function parseBindingRanges(ts, ast) {
265
- const bindings = [];
266
- ts.forEachChild(ast, node => {
267
- if (ts.isVariableStatement(node)) {
268
- for (const decl of node.declarationList.declarations) {
269
- const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
270
- bindings.push(...ranges.map(range => ({ range })));
271
- }
272
- }
273
- else if (ts.isFunctionDeclaration(node)) {
274
- if (node.name && ts.isIdentifier(node.name)) {
275
- bindings.push({
276
- range: _getStartEnd(node.name),
277
- });
278
- }
279
- }
280
- else if (ts.isClassDeclaration(node)) {
281
- if (node.name) {
282
- bindings.push({
283
- range: _getStartEnd(node.name),
284
- });
285
- }
286
- }
287
- else if (ts.isEnumDeclaration(node)) {
288
- bindings.push({
289
- range: _getStartEnd(node.name),
290
- });
291
- }
292
- if (ts.isImportDeclaration(node)) {
293
- const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
294
- if (node.importClause && !node.importClause.isTypeOnly) {
295
- const { name, namedBindings } = node.importClause;
296
- if (name) {
297
- bindings.push({
298
- range: _getStartEnd(name),
299
- moduleName,
300
- isDefaultImport: true,
301
- });
302
- }
303
- if (namedBindings) {
304
- if (ts.isNamedImports(namedBindings)) {
305
- for (const element of namedBindings.elements) {
306
- if (element.isTypeOnly) {
307
- continue;
308
- }
309
- bindings.push({
310
- range: _getStartEnd(element.name),
311
- moduleName,
312
- isDefaultImport: element.propertyName?.text === 'default',
313
- });
314
- }
315
- }
316
- else {
317
- bindings.push({
318
- range: _getStartEnd(namedBindings.name),
319
- moduleName,
320
- isNamespace: true,
321
- });
322
- }
323
- }
324
- }
325
- }
326
- });
327
- return bindings;
328
- function _getStartEnd(node) {
329
- return (0, shared_1.getStartEnd)(ts, node, ast);
330
- }
331
- function _getNodeText(node) {
332
- return (0, shared_1.getNodeText)(ts, node, ast);
333
- }
334
- }
335
266
  function getStatementRange(ts, parents, node, ast) {
336
267
  let statementRange;
337
268
  for (let i = parents.length - 1; i >= 0; i--) {
@@ -350,21 +281,4 @@ function getStatementRange(ts, parents, node, ast) {
350
281
  }
351
282
  return statementRange;
352
283
  }
353
- function getClosestMultiLineCommentRange(ts, node, parents, ast) {
354
- for (let i = parents.length - 1; i >= 0; i--) {
355
- if (ts.isStatement(node)) {
356
- break;
357
- }
358
- node = parents[i];
359
- }
360
- const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
361
- ?.reverse()
362
- .find(range => range.kind === 3);
363
- if (comment) {
364
- return {
365
- start: comment.pos,
366
- end: comment.end,
367
- };
368
- }
369
- }
370
284
  //# sourceMappingURL=scriptSetupRanges.js.map
@@ -0,0 +1,12 @@
1
+ import type * as ts from 'typescript';
2
+ import type { TextRange } from '../types';
3
+ export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
4
+ range: TextRange;
5
+ moduleName?: string;
6
+ isDefaultImport?: boolean;
7
+ isNamespace?: boolean;
8
+ }[];
9
+ export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
10
+ start: number;
11
+ end: number;
12
+ } | undefined;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseBindingRanges = parseBindingRanges;
4
+ exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
+ const collectBindings_1 = require("../utils/collectBindings");
6
+ const shared_1 = require("../utils/shared");
7
+ function parseBindingRanges(ts, ast) {
8
+ const bindings = [];
9
+ ts.forEachChild(ast, node => {
10
+ if (ts.isVariableStatement(node)) {
11
+ for (const decl of node.declarationList.declarations) {
12
+ const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
13
+ bindings.push(...ranges.map(range => ({ range })));
14
+ }
15
+ }
16
+ else if (ts.isFunctionDeclaration(node)) {
17
+ if (node.name && ts.isIdentifier(node.name)) {
18
+ bindings.push({
19
+ range: _getStartEnd(node.name),
20
+ });
21
+ }
22
+ }
23
+ else if (ts.isClassDeclaration(node)) {
24
+ if (node.name) {
25
+ bindings.push({
26
+ range: _getStartEnd(node.name),
27
+ });
28
+ }
29
+ }
30
+ else if (ts.isEnumDeclaration(node)) {
31
+ bindings.push({
32
+ range: _getStartEnd(node.name),
33
+ });
34
+ }
35
+ if (ts.isImportDeclaration(node)) {
36
+ const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
37
+ if (node.importClause && !node.importClause.isTypeOnly) {
38
+ const { name, namedBindings } = node.importClause;
39
+ if (name) {
40
+ bindings.push({
41
+ range: _getStartEnd(name),
42
+ moduleName,
43
+ isDefaultImport: true,
44
+ });
45
+ }
46
+ if (namedBindings) {
47
+ if (ts.isNamedImports(namedBindings)) {
48
+ for (const element of namedBindings.elements) {
49
+ if (element.isTypeOnly) {
50
+ continue;
51
+ }
52
+ bindings.push({
53
+ range: _getStartEnd(element.name),
54
+ moduleName,
55
+ isDefaultImport: element.propertyName?.text === 'default',
56
+ });
57
+ }
58
+ }
59
+ else {
60
+ bindings.push({
61
+ range: _getStartEnd(namedBindings.name),
62
+ moduleName,
63
+ isNamespace: true,
64
+ });
65
+ }
66
+ }
67
+ }
68
+ }
69
+ });
70
+ return bindings;
71
+ function _getStartEnd(node) {
72
+ return (0, shared_1.getStartEnd)(ts, node, ast);
73
+ }
74
+ function _getNodeText(node) {
75
+ return (0, shared_1.getNodeText)(ts, node, ast);
76
+ }
77
+ }
78
+ function getClosestMultiLineCommentRange(ts, node, parents, ast) {
79
+ for (let i = parents.length - 1; i >= 0; i--) {
80
+ if (ts.isStatement(node)) {
81
+ break;
82
+ }
83
+ node = parents[i];
84
+ }
85
+ const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
86
+ ?.reverse()
87
+ .find(range => range.kind === 3);
88
+ if (comment) {
89
+ return {
90
+ start: comment.pos,
91
+ end: comment.end,
92
+ };
93
+ }
94
+ }
95
+ //# sourceMappingURL=utils.js.map
@@ -12,7 +12,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
12
12
  nameOption: import("../types").TextRange | undefined;
13
13
  inheritAttrsOption: string | undefined;
14
14
  }) | undefined;
15
- classBlockEnd: number | undefined;
16
15
  bindings: {
17
16
  range: import("../types").TextRange;
18
17
  moduleName?: string;
@@ -124,11 +123,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
124
123
  bypassDefineComponent: boolean;
125
124
  bindingNames: Set<string>;
126
125
  localTypes: {
127
- generate: (names: string[]) => Generator<string, void, unknown>;
128
- getUsedNames(): Set<string>;
126
+ generate: () => Generator<string, void, unknown>;
129
127
  readonly PrettifyLocal: string;
130
- readonly OmitKeepDiscriminatedUnion: string;
131
- readonly WithDefaults: string;
128
+ readonly WithDefaultsLocal: string;
132
129
  readonly WithSlots: string;
133
130
  readonly PropsChildren: string;
134
131
  readonly TypePropsToOption: string;
@@ -118,25 +118,30 @@ function createTsx(fileName, sfc, ctx) {
118
118
  return newNames;
119
119
  });
120
120
  const setupHasDefineSlots = (0, alien_signals_1.computed)(() => !!getScriptSetupRanges()?.defineSlots);
121
- const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
122
121
  const getSetupPropsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineProps?.name);
122
+ const getSetupSlotsAssignName = (0, alien_signals_1.computed)(() => getScriptSetupRanges()?.defineSlots?.name);
123
123
  const getSetupInheritAttrs = (0, alien_signals_1.computed)(() => {
124
124
  const value = getScriptSetupRanges()?.defineOptions?.inheritAttrs
125
125
  ?? getScriptRanges()?.exportDefault?.inheritAttrsOption;
126
126
  return value !== 'false';
127
127
  });
128
128
  const getComponentSelfName = (0, alien_signals_1.computed)(() => {
129
+ let name;
129
130
  const { exportDefault } = getScriptRanges() ?? {};
130
131
  if (sfc.script && exportDefault?.nameOption) {
131
- const { nameOption } = exportDefault;
132
- return sfc.script.content.slice(nameOption.start + 1, nameOption.end - 1);
132
+ name = sfc.script.content.slice(exportDefault.nameOption.start + 1, exportDefault.nameOption.end - 1);
133
133
  }
134
- const { defineOptions } = getScriptSetupRanges() ?? {};
135
- if (sfc.scriptSetup && defineOptions?.name) {
136
- return defineOptions.name;
134
+ else {
135
+ const { defineOptions } = getScriptSetupRanges() ?? {};
136
+ if (sfc.scriptSetup && defineOptions?.name) {
137
+ name = defineOptions.name;
138
+ }
139
+ else {
140
+ const baseName = path.basename(fileName);
141
+ name = baseName.slice(0, baseName.lastIndexOf('.'));
142
+ }
137
143
  }
138
- const baseName = path.basename(fileName);
139
- return (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
144
+ return (0, shared_1.capitalize)((0, shared_1.camelize)(name));
140
145
  });
141
146
  const getGeneratedTemplate = (0, alien_signals_1.computed)(() => {
142
147
  if (getResolvedOptions().skipTemplateCodegen || !sfc.template) {
@@ -152,8 +157,8 @@ function createTsx(fileName, sfc, ctx) {
152
157
  destructuredPropNames: getSetupDestructuredPropNames(),
153
158
  templateRefNames: getSetupTemplateRefNames(),
154
159
  hasDefineSlots: setupHasDefineSlots(),
155
- slotsAssignName: getSetupSlotsAssignName(),
156
160
  propsAssignName: getSetupPropsAssignName(),
161
+ slotsAssignName: getSetupSlotsAssignName(),
157
162
  inheritAttrs: getSetupInheritAttrs(),
158
163
  selfComponentName: getComponentSelfName(),
159
164
  });
@@ -163,7 +168,7 @@ function createTsx(fileName, sfc, ctx) {
163
168
  ts,
164
169
  compilerOptions: ctx.compilerOptions,
165
170
  vueCompilerOptions: getResolvedOptions(),
166
- sfc: sfc,
171
+ sfc,
167
172
  fileName,
168
173
  lang: getLang(),
169
174
  scriptRanges: getScriptRanges(),
package/lib/types.d.ts CHANGED
@@ -8,7 +8,7 @@ export type { SFCParseResult } from '@vue/compiler-sfc';
8
8
  export { VueEmbeddedCode };
9
9
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>> & {
10
10
  strictTemplates?: boolean;
11
- target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
11
+ target?: 'auto' | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
12
12
  globalTypesPath?: string;
13
13
  plugins?: string[];
14
14
  };
@@ -3,7 +3,6 @@ import type * as ts from 'typescript';
3
3
  import type { Sfc, TextRange } from '../types';
4
4
  export { hyphenate as hyphenateTag } from '@vue/shared';
5
5
  export declare function hyphenateAttr(str: string): string;
6
- export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
7
6
  export declare function getElementTagOffsets(node: CompilerDOM.ElementNode, template: NonNullable<Sfc['template']>): [number] | [number, number];
8
7
  export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
9
8
  export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hyphenateTag = void 0;
4
4
  exports.hyphenateAttr = hyphenateAttr;
5
- exports.getSlotsPropertyName = getSlotsPropertyName;
6
5
  exports.getElementTagOffsets = getElementTagOffsets;
7
6
  exports.getStartEnd = getStartEnd;
8
7
  exports.getNodeText = getNodeText;
@@ -17,9 +16,6 @@ function hyphenateAttr(str) {
17
16
  }
18
17
  return hyphencase;
19
18
  }
20
- function getSlotsPropertyName(vueVersion) {
21
- return vueVersion < 3 ? '$scopedSlots' : '$slots';
22
- }
23
19
  function getElementTagOffsets(node, template) {
24
20
  const tagOffsets = [
25
21
  template.content.indexOf(node.tag, node.loc.start.offset),
@@ -7,9 +7,9 @@ const signals_1 = require("../utils/signals");
7
7
  exports.templateInlineTsAsts = new WeakMap();
8
8
  function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
9
9
  const getUntrackedSnapshot = () => {
10
- const pausedSub = (0, alien_signals_1.setCurrentSub)(undefined);
10
+ const pausedSub = (0, alien_signals_1.setActiveSub)(undefined);
11
11
  const res = getSnapshot();
12
- (0, alien_signals_1.setCurrentSub)(pausedSub);
12
+ (0, alien_signals_1.setActiveSub)(pausedSub);
13
13
  return res;
14
14
  };
15
15
  const getContent = (0, alien_signals_1.computed)(() => {
@@ -201,9 +201,9 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
201
201
  if (cache?.plugin.updateSFCTemplate) {
202
202
  const change = getUntrackedSnapshot().getChangeRange(cache.snapshot);
203
203
  if (change) {
204
- const pausedSub = (0, alien_signals_1.setCurrentSub)(undefined);
204
+ const pausedSub = (0, alien_signals_1.setActiveSub)(undefined);
205
205
  const templateOffset = base.startTagEnd;
206
- (0, alien_signals_1.setCurrentSub)(pausedSub);
206
+ (0, alien_signals_1.setActiveSub)(pausedSub);
207
207
  const newText = getUntrackedSnapshot().getText(change.span.start, change.span.start + change.newLength);
208
208
  const newResult = cache.plugin.updateSFCTemplate(cache.result, {
209
209
  start: change.span.start - templateOffset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.8",
3
+ "version": "3.1.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -15,9 +15,8 @@
15
15
  "dependencies": {
16
16
  "@volar/language-core": "2.4.23",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
- "@vue/compiler-vue2": "^2.7.16",
19
18
  "@vue/shared": "^3.5.0",
20
- "alien-signals": "^2.0.5",
19
+ "alien-signals": "^3.0.0",
21
20
  "muggle-string": "^0.4.1",
22
21
  "path-browserify": "^1.0.1",
23
22
  "picomatch": "^4.0.2"
@@ -37,5 +36,5 @@
37
36
  "optional": true
38
37
  }
39
38
  },
40
- "gitHead": "f7bdeaa7bb476df1fc8ff46c504d75c1869b0be9"
39
+ "gitHead": "fa32cb67b68c4fd01a146c7e2a276ffa022df268"
41
40
  }
@@ -1,5 +0,0 @@
1
- import type { Code } from '../../types';
2
- import type { TemplateCodegenContext } from '../template/context';
3
- import type { ScriptCodegenContext } from './context';
4
- import type { ScriptCodegenOptions } from './index';
5
- export declare function generateComponentSelf(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateComponentSelf = generateComponentSelf;
4
- const shared_1 = require("@vue/shared");
5
- const path = require("path-browserify");
6
- const codeFeatures_1 = require("../codeFeatures");
7
- const utils_1 = require("../utils");
8
- const component_1 = require("./component");
9
- function* generateComponentSelf(options, ctx, templateCodegenCtx) {
10
- if (options.sfc.scriptSetup && options.scriptSetupRanges) {
11
- yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
12
- yield `setup: () => ({${utils_1.newLine}`;
13
- if (ctx.bypassDefineComponent) {
14
- for (const code of (0, component_1.generateComponentSetupReturns)(options.scriptSetupRanges)) {
15
- yield `...${code},${utils_1.newLine}`;
16
- }
17
- }
18
- // bindings
19
- const templateUsageVars = new Set([
20
- ...options.sfc.template?.ast?.components.flatMap(c => [(0, shared_1.camelize)(c), (0, shared_1.capitalize)((0, shared_1.camelize)(c))]) ?? [],
21
- ...options.templateCodegen?.accessExternalVariables.keys() ?? [],
22
- ...templateCodegenCtx.accessExternalVariables.keys(),
23
- ]);
24
- for (const varName of ctx.bindingNames) {
25
- if (!templateUsageVars.has(varName)) {
26
- continue;
27
- }
28
- const token = Symbol(varName.length);
29
- yield ['', undefined, 0, { __linkedToken: token }];
30
- yield `${varName}: ${varName} as typeof `;
31
- yield ['', undefined, 0, { __linkedToken: token }];
32
- yield `${varName},${utils_1.newLine}`;
33
- }
34
- yield `}),${utils_1.newLine}`;
35
- if (!ctx.bypassDefineComponent) {
36
- const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
37
- yield* emitOptionCodes;
38
- yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
39
- }
40
- if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
41
- const { args } = options.scriptRanges.exportDefault;
42
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
43
- }
44
- yield `})${utils_1.endOfLine}`; // defineComponent {
45
- }
46
- else if (options.sfc.script) {
47
- yield `let __VLS_self!: typeof import('./${path.basename(options.fileName)}').default${utils_1.endOfLine}`;
48
- }
49
- else {
50
- yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
51
- }
52
- }
53
- //# sourceMappingURL=componentSelf.js.map
@@ -1,2 +0,0 @@
1
- import * as CompilerDOM from '@vue/compiler-dom';
2
- export declare const compile: typeof CompilerDOM.compile;