@vue/language-core 2.1.6 → 2.1.8

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 (49) hide show
  1. package/lib/codegen/common.d.ts +2 -2
  2. package/lib/codegen/common.js +8 -10
  3. package/lib/codegen/globalTypes.js +13 -8
  4. package/lib/codegen/inlayHints.d.ts +11 -0
  5. package/lib/codegen/inlayHints.js +17 -0
  6. package/lib/codegen/script/component.d.ts +1 -1
  7. package/lib/codegen/script/component.js +8 -5
  8. package/lib/codegen/script/componentSelf.js +1 -1
  9. package/lib/codegen/script/context.d.ts +1 -1
  10. package/lib/codegen/script/index.d.ts +1 -0
  11. package/lib/codegen/script/index.js +23 -10
  12. package/lib/codegen/script/scriptSetup.js +103 -112
  13. package/lib/codegen/script/styleModulesType.js +3 -5
  14. package/lib/codegen/script/template.d.ts +1 -1
  15. package/lib/codegen/script/template.js +9 -12
  16. package/lib/codegen/template/context.d.ts +3 -2
  17. package/lib/codegen/template/context.js +1 -0
  18. package/lib/codegen/template/element.d.ts +1 -1
  19. package/lib/codegen/template/element.js +31 -11
  20. package/lib/codegen/template/elementDirectives.js +63 -31
  21. package/lib/codegen/template/elementProps.js +7 -17
  22. package/lib/codegen/template/index.d.ts +1 -0
  23. package/lib/codegen/template/index.js +63 -53
  24. package/lib/codegen/template/interpolation.d.ts +1 -1
  25. package/lib/codegen/template/interpolation.js +34 -28
  26. package/lib/codegen/template/slotOutlet.js +5 -0
  27. package/lib/codegen/template/templateChild.d.ts +1 -1
  28. package/lib/codegen/template/templateChild.js +6 -2
  29. package/lib/codegen/template/vFor.js +1 -1
  30. package/lib/parsers/scriptSetupRanges.d.ts +14 -4
  31. package/lib/parsers/scriptSetupRanges.js +39 -26
  32. package/lib/plugins/vue-tsx.d.ts +27 -16
  33. package/lib/plugins/vue-tsx.js +43 -31
  34. package/lib/types.d.ts +3 -1
  35. package/lib/utils/parseCssClassNames.d.ts +1 -1
  36. package/lib/utils/parseCssClassNames.js +5 -4
  37. package/lib/utils/parseCssVars.d.ts +3 -2
  38. package/lib/utils/parseCssVars.js +12 -11
  39. package/lib/utils/ts.d.ts +1 -1
  40. package/lib/utils/ts.js +3 -5
  41. package/lib/virtualFile/computedEmbeddedCodes.d.ts +2 -1
  42. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  43. package/lib/virtualFile/computedSfc.d.ts +2 -1
  44. package/lib/virtualFile/computedSfc.js +77 -76
  45. package/lib/virtualFile/computedVueSfc.d.ts +2 -1
  46. package/lib/virtualFile/computedVueSfc.js +8 -8
  47. package/lib/virtualFile/vueFile.d.ts +6 -7
  48. package/lib/virtualFile/vueFile.js +13 -12
  49. package/package.json +9 -8
@@ -8,8 +8,7 @@ const common_1 = require("../common");
8
8
  function* generateInterpolation(options, ctx, _code, astHolder, start, data, prefix, suffix) {
9
9
  const code = prefix + _code + suffix;
10
10
  const ast = (0, common_1.createTsAst)(options.ts, astHolder, code);
11
- const vars = [];
12
- for (let [section, offset, onlyError] of forEachInterpolationSegment(options.ts, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
11
+ for (let [section, offset, type] of forEachInterpolationSegment(options.ts, options.destructuredPropNames, options.templateRefNames, ctx, code, start !== undefined ? start - prefix.length : undefined, ast)) {
13
12
  if (offset === undefined) {
14
13
  yield section;
15
14
  }
@@ -26,29 +25,28 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
26
25
  section = section.substring(-offset);
27
26
  offset = 0;
28
27
  }
29
- if (start !== undefined && data !== undefined) {
30
- yield [
31
- section,
32
- 'template',
33
- start + offset,
34
- onlyError
35
- ? ctx.codeFeatures.verification
36
- : typeof data === 'function' ? data(start + offset) : data,
37
- ];
38
- }
39
- else {
40
- yield section;
28
+ const shouldSkip = section.length === 0 && (type === 'startText' || type === 'endText');
29
+ if (!shouldSkip) {
30
+ if (start !== undefined
31
+ && data) {
32
+ yield [
33
+ section,
34
+ 'template',
35
+ start + offset,
36
+ type === 'errorMappingOnly'
37
+ ? ctx.codeFeatures.verification
38
+ : typeof data === 'function' ? data(start + offset) : data,
39
+ ];
40
+ }
41
+ else {
42
+ yield section;
43
+ }
41
44
  }
42
45
  yield addSuffix;
43
46
  }
44
47
  }
45
- if (start !== undefined) {
46
- for (const v of vars) {
47
- v.offset = start + v.offset - prefix.length;
48
- }
49
- }
50
48
  }
51
- function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, ast) {
49
+ function* forEachInterpolationSegment(ts, destructuredPropNames, templateRefNames, ctx, code, offset, ast) {
52
50
  let ctxVars = [];
53
51
  const varCb = (id, isShorthand) => {
54
52
  const text = (0, scriptSetupRanges_1.getNodeText)(ts, id, ast);
@@ -65,6 +63,9 @@ function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, a
65
63
  isShorthand: isShorthand,
66
64
  offset: (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start,
67
65
  });
66
+ if (destructuredPropNames?.has(text)) {
67
+ return;
68
+ }
68
69
  if (offset !== undefined) {
69
70
  ctx.accessExternalVariable(text, offset + (0, scriptSetupRanges_1.getStartEnd)(ts, id, ast).start);
70
71
  }
@@ -80,13 +81,13 @@ function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, a
80
81
  yield [code.substring(0, ctxVars[0].offset + ctxVars[0].text.length), 0];
81
82
  yield [': ', undefined];
82
83
  }
83
- else {
84
- yield [code.substring(0, ctxVars[0].offset), 0];
84
+ else if (ctxVars[0].offset > 0) {
85
+ yield [code.substring(0, ctxVars[0].offset), 0, 'startText'];
85
86
  }
86
87
  for (let i = 0; i < ctxVars.length - 1; i++) {
87
88
  const curVar = ctxVars[i];
88
89
  const nextVar = ctxVars[i + 1];
89
- yield* generateVar(code, templateRefNames, curVar, nextVar);
90
+ yield* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar);
90
91
  if (nextVar.isShorthand) {
91
92
  yield [code.substring(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
92
93
  yield [': ', undefined];
@@ -96,17 +97,20 @@ function* forEachInterpolationSegment(ts, templateRefNames, ctx, code, offset, a
96
97
  }
97
98
  }
98
99
  const lastVar = ctxVars.at(-1);
99
- yield* generateVar(code, templateRefNames, lastVar);
100
- yield [code.substring(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length];
100
+ yield* generateVar(code, destructuredPropNames, templateRefNames, lastVar);
101
+ if (lastVar.offset + lastVar.text.length < code.length) {
102
+ yield [code.substring(lastVar.offset + lastVar.text.length), lastVar.offset + lastVar.text.length, 'endText'];
103
+ }
101
104
  }
102
105
  else {
103
106
  yield [code, 0];
104
107
  }
105
108
  }
106
- function* generateVar(code, templateRefNames, curVar, nextVar = curVar) {
109
+ function* generateVar(code, destructuredPropNames, templateRefNames, curVar, nextVar = curVar) {
107
110
  // fix https://github.com/vuejs/language-tools/issues/1205
108
111
  // fix https://github.com/vuejs/language-tools/issues/1264
109
- yield ['', nextVar.offset, true];
112
+ yield ['', nextVar.offset, 'errorMappingOnly'];
113
+ const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
110
114
  const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
111
115
  if (isTemplateRef) {
112
116
  yield [`__VLS_unref(`, undefined];
@@ -114,7 +118,9 @@ function* generateVar(code, templateRefNames, curVar, nextVar = curVar) {
114
118
  yield [`)`, undefined];
115
119
  }
116
120
  else {
117
- yield [`__VLS_ctx.`, undefined];
121
+ if (!isDestructuredProp) {
122
+ yield [`__VLS_ctx.`, undefined];
123
+ }
118
124
  yield [code.substring(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
119
125
  }
120
126
  }
@@ -6,6 +6,7 @@ const common_1 = require("../common");
6
6
  const elementChildren_1 = require("./elementChildren");
7
7
  const elementProps_1 = require("./elementProps");
8
8
  const interpolation_1 = require("./interpolation");
9
+ const inlayHints_1 = require("../inlayHints");
9
10
  function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxVar) {
10
11
  const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
11
12
  const varSlot = ctx.getInternalVariable();
@@ -46,6 +47,10 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
46
47
  }
47
48
  else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
48
49
  && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
50
+ const isShortHand = nameProp.arg?.loc.start.offset === nameProp.exp.loc.start.offset;
51
+ if (isShortHand) {
52
+ ctx.inlayHints.push((0, inlayHints_1.createVBindShorthandInlayHintInfo)(nameProp.exp.loc, 'name'));
53
+ }
49
54
  const slotExpVar = ctx.getInternalVariable();
50
55
  yield `var ${slotExpVar} = `;
51
56
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
@@ -2,6 +2,6 @@ import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentComponent: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined): Generator<Code>;
5
+ export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, currentComponent: CompilerDOM.ElementNode | undefined, prevNode: CompilerDOM.TemplateChildNode | undefined, componentCtxVar: string | undefined, isVForChild?: boolean): Generator<Code>;
6
6
  export declare function getVForNode(node: CompilerDOM.ElementNode): CompilerDOM.ForNode | undefined;
7
7
  export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
@@ -25,7 +25,7 @@ const transformContext = {
25
25
  },
26
26
  expressionPlugins: ['typescript'],
27
27
  };
28
- function* generateTemplateChild(options, ctx, node, currentComponent, prevNode, componentCtxVar) {
28
+ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode, componentCtxVar, isVForChild = false) {
29
29
  if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
30
30
  const commentText = prevNode.content.trim().split(' ')[0];
31
31
  if (commentText.match(/^@vue-skip\b[\s\S]*/)) {
@@ -40,6 +40,10 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
40
40
  }
41
41
  }
42
42
  const shouldInheritRootNodeAttrs = options.inheritAttrs;
43
+ const cur = node;
44
+ if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
45
+ cur.codegenNode = cur.codegenNode.value;
46
+ }
43
47
  if (node.type === CompilerDOM.NodeTypes.ROOT) {
44
48
  let prev;
45
49
  if (shouldInheritRootNodeAttrs && node.children.length === 1 && node.children[0].type === CompilerDOM.NodeTypes.ELEMENT) {
@@ -66,7 +70,7 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
66
70
  }
67
71
  else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
68
72
  || node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
69
- yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar);
73
+ yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar, isVForChild);
70
74
  }
71
75
  else {
72
76
  yield* (0, element_1.generateComponent)(options, ctx, node, currentComponent);
@@ -57,7 +57,7 @@ function* generateVFor(options, ctx, node, currentComponent, componentCtxVar) {
57
57
  }
58
58
  let prev;
59
59
  for (const childNode of node.children) {
60
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar);
60
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentComponent, prev, componentCtxVar, true);
61
61
  prev = childNode;
62
62
  }
63
63
  for (const varName of forBlockVars) {
@@ -9,8 +9,10 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
9
9
  importComponentNames: Set<string>;
10
10
  props: {
11
11
  name?: string;
12
- destructured?: string[];
12
+ destructured?: Set<string>;
13
+ destructuredRest?: string;
13
14
  define?: ReturnType<(node: ts.CallExpression) => TextRange & {
15
+ exp: TextRange;
14
16
  arg?: TextRange;
15
17
  typeArg?: TextRange;
16
18
  }> & {
@@ -24,6 +26,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
24
26
  name?: string;
25
27
  isObjectBindingPattern?: boolean;
26
28
  define?: ReturnType<(node: ts.CallExpression) => TextRange & {
29
+ exp: TextRange;
27
30
  arg?: TextRange;
28
31
  typeArg?: TextRange;
29
32
  }>;
@@ -31,15 +34,18 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
31
34
  emits: {
32
35
  name?: string;
33
36
  define?: ReturnType<(node: ts.CallExpression) => TextRange & {
37
+ exp: TextRange;
34
38
  arg?: TextRange;
35
39
  typeArg?: TextRange;
36
40
  }> & {
41
+ statement: TextRange;
37
42
  hasUnionTypeArg?: boolean;
38
43
  };
39
44
  };
40
45
  expose: {
41
46
  name?: string;
42
47
  define?: ReturnType<(node: ts.CallExpression) => TextRange & {
48
+ exp: TextRange;
43
49
  arg?: TextRange;
44
50
  typeArg?: TextRange;
45
51
  }>;
@@ -49,8 +55,11 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
49
55
  inheritAttrs?: string;
50
56
  };
51
57
  cssModules: {
52
- exp: TextRange;
53
- arg?: TextRange;
58
+ define: ReturnType<(node: ts.CallExpression) => TextRange & {
59
+ exp: TextRange;
60
+ arg?: TextRange;
61
+ typeArg?: TextRange;
62
+ }>;
54
63
  }[];
55
64
  defineProp: {
56
65
  localName: TextRange | undefined;
@@ -64,7 +73,8 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
64
73
  }[];
65
74
  templateRefs: {
66
75
  name?: string;
67
- define?: ReturnType<(node: ts.CallExpression) => TextRange & {
76
+ define: ReturnType<(node: ts.CallExpression) => TextRange & {
77
+ exp: TextRange;
68
78
  arg?: TextRange;
69
79
  typeArg?: TextRange;
70
80
  }>;
@@ -76,6 +76,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
76
76
  function parseDefineFunction(node) {
77
77
  return {
78
78
  ..._getStartEnd(node),
79
+ exp: _getStartEnd(node.expression),
79
80
  arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
80
81
  typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
81
82
  };
@@ -217,7 +218,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
217
218
  }
218
219
  }
219
220
  else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
220
- emits.define = parseDefineFunction(node);
221
+ emits.define = {
222
+ ...parseDefineFunction(node),
223
+ statement: getStatementRange(ts, parents, node, ast)
224
+ };
221
225
  if (ts.isVariableDeclaration(parent)) {
222
226
  emits.name = getNodeText(ts, parent.name, ast);
223
227
  }
@@ -236,30 +240,25 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
236
240
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
237
241
  if (ts.isVariableDeclaration(parent)) {
238
242
  if (ts.isObjectBindingPattern(parent.name)) {
239
- props.destructured = (0, common_1.collectVars)(ts, parent.name, ast, [], false);
243
+ props.destructured = new Set();
244
+ const identifiers = (0, common_1.collectIdentifiers)(ts, parent.name, []);
245
+ for (const [id, isRest] of identifiers) {
246
+ const name = getNodeText(ts, id, ast);
247
+ if (isRest) {
248
+ props.destructuredRest = name;
249
+ }
250
+ else {
251
+ props.destructured.add(name);
252
+ }
253
+ }
240
254
  }
241
255
  else {
242
256
  props.name = getNodeText(ts, parent.name, ast);
243
257
  }
244
258
  }
245
- let statementRange;
246
- for (let i = parents.length - 1; i >= 0; i--) {
247
- if (ts.isStatement(parents[i])) {
248
- const statement = parents[i];
249
- ts.forEachChild(statement, child => {
250
- const range = _getStartEnd(child);
251
- statementRange ??= range;
252
- statementRange.end = range.end;
253
- });
254
- break;
255
- }
256
- }
257
- if (!statementRange) {
258
- statementRange = _getStartEnd(node);
259
- }
260
259
  props.define = {
261
260
  ...parseDefineFunction(node),
262
- statement: statementRange,
261
+ statement: getStatementRange(ts, parents, node, ast),
263
262
  };
264
263
  if (node.arguments.length) {
265
264
  props.define.arg = _getStartEnd(node.arguments[0]);
@@ -298,7 +297,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
298
297
  }
299
298
  else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
300
299
  const define = parseDefineFunction(node);
301
- define.arg = _getStartEnd(node.arguments[0]);
302
300
  let name;
303
301
  if (ts.isVariableDeclaration(parent)) {
304
302
  name = getNodeText(ts, parent.name, ast);
@@ -309,13 +307,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
309
307
  });
310
308
  }
311
309
  else if (vueCompilerOptions.composibles.useCssModule.includes(callText)) {
312
- const module = {
313
- exp: _getStartEnd(node)
314
- };
315
- if (node.arguments.length) {
316
- module.arg = _getStartEnd(node.arguments[0]);
317
- }
318
- cssModules.push(module);
310
+ const define = parseDefineFunction(node);
311
+ cssModules.push({
312
+ define
313
+ });
319
314
  }
320
315
  }
321
316
  ts.forEachChild(node, child => {
@@ -420,4 +415,22 @@ function getNodeText(ts, node, sourceFile) {
420
415
  const { start, end } = getStartEnd(ts, node, sourceFile);
421
416
  return sourceFile.text.substring(start, end);
422
417
  }
418
+ function getStatementRange(ts, parents, node, sourceFile) {
419
+ let statementRange;
420
+ for (let i = parents.length - 1; i >= 0; i--) {
421
+ if (ts.isStatement(parents[i])) {
422
+ const statement = parents[i];
423
+ ts.forEachChild(statement, child => {
424
+ const range = getStartEnd(ts, child, sourceFile);
425
+ statementRange ??= range;
426
+ statementRange.end = range.end;
427
+ });
428
+ break;
429
+ }
430
+ }
431
+ if (!statementRange) {
432
+ statementRange = getStartEnd(ts, node, sourceFile);
433
+ }
434
+ return statementRange;
435
+ }
423
436
  //# sourceMappingURL=scriptSetupRanges.js.map
@@ -1,7 +1,7 @@
1
1
  import type { Mapping } from '@volar/language-core';
2
2
  import type { Code, Sfc, VueLanguagePlugin } from '../types';
3
3
  export declare const tsCodegen: WeakMap<Sfc, {
4
- scriptRanges: () => {
4
+ scriptRanges: import("alien-signals").ISignal<{
5
5
  exportDefault: (import("../types").TextRange & {
6
6
  expression: import("../types").TextRange;
7
7
  args: import("../types").TextRange;
@@ -14,16 +14,18 @@ export declare const tsCodegen: WeakMap<Sfc, {
14
14
  }) | undefined;
15
15
  classBlockEnd: number | undefined;
16
16
  bindings: import("../types").TextRange[];
17
- } | undefined;
18
- scriptSetupRanges: () => {
17
+ } | undefined>;
18
+ scriptSetupRanges: import("alien-signals").ISignal<{
19
19
  leadingCommentEndOffset: number;
20
20
  importSectionEndOffset: number;
21
21
  bindings: import("../types").TextRange[];
22
22
  importComponentNames: Set<string>;
23
23
  props: {
24
24
  name?: string;
25
- destructured?: string[];
25
+ destructured?: Set<string>;
26
+ destructuredRest?: string;
26
27
  define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
28
+ exp: import("../types").TextRange;
27
29
  arg?: import("../types").TextRange;
28
30
  typeArg?: import("../types").TextRange;
29
31
  }> & {
@@ -37,6 +39,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
37
39
  name?: string;
38
40
  isObjectBindingPattern?: boolean;
39
41
  define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
42
+ exp: import("../types").TextRange;
40
43
  arg?: import("../types").TextRange;
41
44
  typeArg?: import("../types").TextRange;
42
45
  }>;
@@ -44,15 +47,18 @@ export declare const tsCodegen: WeakMap<Sfc, {
44
47
  emits: {
45
48
  name?: string;
46
49
  define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
50
+ exp: import("../types").TextRange;
47
51
  arg?: import("../types").TextRange;
48
52
  typeArg?: import("../types").TextRange;
49
53
  }> & {
54
+ statement: import("../types").TextRange;
50
55
  hasUnionTypeArg?: boolean;
51
56
  };
52
57
  };
53
58
  expose: {
54
59
  name?: string;
55
60
  define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
61
+ exp: import("../types").TextRange;
56
62
  arg?: import("../types").TextRange;
57
63
  typeArg?: import("../types").TextRange;
58
64
  }>;
@@ -62,8 +68,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
62
68
  inheritAttrs?: string;
63
69
  };
64
70
  cssModules: {
65
- exp: import("../types").TextRange;
66
- arg?: import("../types").TextRange;
71
+ define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
72
+ exp: import("../types").TextRange;
73
+ arg?: import("../types").TextRange;
74
+ typeArg?: import("../types").TextRange;
75
+ }>;
67
76
  }[];
68
77
  defineProp: {
69
78
  localName: import("../types").TextRange | undefined;
@@ -77,14 +86,15 @@ export declare const tsCodegen: WeakMap<Sfc, {
77
86
  }[];
78
87
  templateRefs: {
79
88
  name?: string;
80
- define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
89
+ define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
90
+ exp: import("../types").TextRange;
81
91
  arg?: import("../types").TextRange;
82
92
  typeArg?: import("../types").TextRange;
83
93
  }>;
84
94
  }[];
85
- } | undefined;
86
- lang: () => string;
87
- generatedScript: () => {
95
+ } | undefined>;
96
+ lang: import("alien-signals").ISignal<string>;
97
+ generatedScript: import("alien-signals").ISignal<{
88
98
  codes: Code[];
89
99
  linkedCodeMappings: Mapping<unknown>[];
90
100
  generatedTemplate: boolean;
@@ -103,9 +113,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
103
113
  readonly TypePropsToOption: string;
104
114
  readonly OmitIndexSignature: string;
105
115
  };
106
- inlayHints: import("../codegen/types").InlayHintInfo[];
107
- };
108
- generatedTemplate: () => {
116
+ inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
117
+ }>;
118
+ generatedTemplate: import("alien-signals").ISignal<{
109
119
  codes: Code[];
110
120
  slots: {
111
121
  name: string;
@@ -141,10 +151,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
141
151
  offset: number;
142
152
  }[];
143
153
  emptyClassOffsets: number[];
144
- inlayHints: import("../codegen/types").InlayHintInfo[];
154
+ inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
145
155
  hasSlot: boolean;
146
156
  inheritedAttrVars: Set<unknown>;
147
- templateRefs: Map<string, [string, number]>;
157
+ templateRefs: Map<string, [varName: string, offset: number]>;
158
+ singleRootElType: string | undefined;
148
159
  singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
149
160
  accessExternalVariable(name: string, offset?: number): void;
150
161
  hasLocalVariable: (name: string) => boolean;
@@ -155,7 +166,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
155
166
  expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
156
167
  resetDirectiveComments: (endStr: string) => Generator<Code>;
157
168
  generateAutoImportCompletion: () => Generator<Code>;
158
- } | undefined;
169
+ } | undefined>;
159
170
  }>;
160
171
  declare const plugin: VueLanguagePlugin;
161
172
  export default plugin;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsCodegen = void 0;
4
- const computeds_1 = require("computeds");
4
+ const alien_signals_1 = require("alien-signals");
5
5
  const path_browserify_1 = require("path-browserify");
6
6
  const script_1 = require("../codegen/script");
7
7
  const template_1 = require("../codegen/template");
@@ -20,15 +20,15 @@ const plugin = ctx => {
20
20
  getEmbeddedCodes(fileName, sfc) {
21
21
  const tsx = useTsx(fileName, sfc);
22
22
  const files = [];
23
- if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
24
- files.push({ id: 'script_' + tsx.lang(), lang: tsx.lang() });
23
+ if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.get())) {
24
+ files.push({ id: 'script_' + tsx.lang.get(), lang: tsx.lang.get() });
25
25
  }
26
26
  return files;
27
27
  },
28
28
  resolveEmbeddedCode(fileName, sfc, embeddedFile) {
29
29
  const _tsx = useTsx(fileName, sfc);
30
30
  if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
31
- const tsx = _tsx.generatedScript();
31
+ const tsx = _tsx.generatedScript.get();
32
32
  if (tsx) {
33
33
  const content = [...tsx.codes];
34
34
  embeddedFile.content = content;
@@ -52,19 +52,19 @@ const plugin = ctx => {
52
52
  exports.default = plugin;
53
53
  function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
54
54
  const ts = ctx.modules.typescript;
55
- const lang = (0, computeds_1.computed)(() => {
55
+ const lang = (0, alien_signals_1.computed)(() => {
56
56
  return !_sfc.script && !_sfc.scriptSetup ? 'ts'
57
57
  : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
58
58
  : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
59
59
  : 'js';
60
60
  });
61
- const scriptRanges = (0, computeds_1.computed)(() => _sfc.script
61
+ const scriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
62
62
  ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
63
63
  : undefined);
64
- const scriptSetupRanges = (0, computeds_1.computed)(() => _sfc.scriptSetup
64
+ const scriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
65
65
  ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
66
66
  : undefined);
67
- const generatedTemplate = (0, computeds_1.computed)(() => {
67
+ const generatedTemplate = (0, alien_signals_1.computed)(() => {
68
68
  if (ctx.vueCompilerOptions.skipTemplateCodegen || !_sfc.template) {
69
69
  return;
70
70
  }
@@ -75,13 +75,14 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
75
75
  vueCompilerOptions: ctx.vueCompilerOptions,
76
76
  template: _sfc.template,
77
77
  edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
78
- scriptSetupBindingNames: scriptSetupBindingNames(),
79
- scriptSetupImportComponentNames: scriptSetupImportComponentNames(),
80
- templateRefNames: templateRefNames(),
81
- hasDefineSlots: hasDefineSlots(),
82
- slotsAssignName: slotsAssignName(),
83
- propsAssignName: propsAssignName(),
84
- inheritAttrs: inheritAttrs(),
78
+ scriptSetupBindingNames: scriptSetupBindingNames.get(),
79
+ scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
80
+ destructuredPropNames: destructuredPropNames.get(),
81
+ templateRefNames: templateRefNames.get(),
82
+ hasDefineSlots: hasDefineSlots.get(),
83
+ slotsAssignName: slotsAssignName.get(),
84
+ propsAssignName: propsAssignName.get(),
85
+ inheritAttrs: inheritAttrs.get(),
85
86
  });
86
87
  let current = codegen.next();
87
88
  while (!current.done) {
@@ -94,9 +95,9 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
94
95
  codes: codes,
95
96
  };
96
97
  });
97
- const scriptSetupBindingNames = (0, computeds_1.computed)(oldNames => {
98
+ const scriptSetupBindingNames = (0, alien_signals_1.computed)(oldNames => {
98
99
  const newNames = new Set();
99
- const bindings = scriptSetupRanges()?.bindings;
100
+ const bindings = scriptSetupRanges.get()?.bindings;
100
101
  if (_sfc.scriptSetup && bindings) {
101
102
  for (const binding of bindings) {
102
103
  newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
@@ -107,15 +108,26 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
107
108
  }
108
109
  return newNames;
109
110
  });
110
- const scriptSetupImportComponentNames = (0, computeds_1.computed)(oldNames => {
111
- const newNames = scriptSetupRanges()?.importComponentNames ?? new Set();
111
+ const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
112
+ const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
112
113
  if (oldNames && twoSetsEqual(newNames, oldNames)) {
113
114
  return oldNames;
114
115
  }
115
116
  return newNames;
116
117
  });
117
- const templateRefNames = (0, computeds_1.computed)(oldNames => {
118
- const newNames = new Set(scriptSetupRanges()?.templateRefs
118
+ const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
119
+ const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
120
+ const rest = scriptSetupRanges.get()?.props.destructuredRest;
121
+ if (rest) {
122
+ newNames.add(rest);
123
+ }
124
+ if (oldNames && twoSetsEqual(newNames, oldNames)) {
125
+ return oldNames;
126
+ }
127
+ return newNames;
128
+ });
129
+ const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
130
+ const newNames = new Set(scriptSetupRanges.get()?.templateRefs
119
131
  .map(({ name }) => name)
120
132
  .filter(name => name !== undefined));
121
133
  if (oldNames && twoSetsEqual(newNames, oldNames)) {
@@ -123,14 +135,14 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
123
135
  }
124
136
  return newNames;
125
137
  });
126
- const hasDefineSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
127
- const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
128
- const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
129
- const inheritAttrs = (0, computeds_1.computed)(() => {
130
- const value = scriptSetupRanges()?.options.inheritAttrs ?? scriptRanges()?.exportDefault?.inheritAttrsOption;
138
+ const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
139
+ const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
140
+ const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
141
+ const inheritAttrs = (0, alien_signals_1.computed)(() => {
142
+ const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
131
143
  return value !== 'false';
132
144
  });
133
- const generatedScript = (0, computeds_1.computed)(() => {
145
+ const generatedScript = (0, alien_signals_1.computed)(() => {
134
146
  const codes = [];
135
147
  const linkedCodeMappings = [];
136
148
  let generatedLength = 0;
@@ -138,10 +150,10 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
138
150
  ts,
139
151
  fileBaseName: path_browserify_1.posix.basename(fileName),
140
152
  sfc: _sfc,
141
- lang: lang(),
142
- scriptRanges: scriptRanges(),
143
- scriptSetupRanges: scriptSetupRanges(),
144
- templateCodegen: generatedTemplate(),
153
+ lang: lang.get(),
154
+ scriptRanges: scriptRanges.get(),
155
+ scriptSetupRanges: scriptSetupRanges.get(),
156
+ templateCodegen: generatedTemplate.get(),
145
157
  compilerOptions: ctx.compilerOptions,
146
158
  vueCompilerOptions: ctx.vueCompilerOptions,
147
159
  edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
package/lib/types.d.ts CHANGED
@@ -45,7 +45,9 @@ export interface VueCompilerOptions {
45
45
  experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
46
46
  experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
47
47
  experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
48
- __setupedGlobalTypes?: boolean;
48
+ __setupedGlobalTypes?: true | {
49
+ absolutePath: string;
50
+ };
49
51
  __test?: boolean;
50
52
  }
51
53
  export declare const validVersions: readonly [2, 2.1];
@@ -1,4 +1,4 @@
1
- export declare function parseCssClassNames(styleContent: string): Generator<{
1
+ export declare function parseCssClassNames(css: string): Generator<{
2
2
  offset: number;
3
3
  text: string;
4
4
  }, void, unknown>;