@vue/language-core 2.2.0 → 2.2.2

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 (84) hide show
  1. package/index.d.ts +0 -1
  2. package/index.js +1 -2
  3. package/lib/codeFeatures.d.ts +1 -0
  4. package/lib/codeFeatures.js +3 -0
  5. package/lib/codegen/codeFeatures.d.ts +83 -0
  6. package/lib/codegen/codeFeatures.js +71 -0
  7. package/lib/codegen/common.d.ts +12 -0
  8. package/lib/codegen/common.js +79 -0
  9. package/lib/codegen/globalTypes.d.ts +3 -1
  10. package/lib/codegen/globalTypes.js +30 -14
  11. package/lib/codegen/localTypes.d.ts +1 -1
  12. package/lib/codegen/localTypes.js +4 -4
  13. package/lib/codegen/script/binding.d.ts +4 -0
  14. package/lib/codegen/script/binding.js +41 -0
  15. package/lib/codegen/script/component.d.ts +1 -1
  16. package/lib/codegen/script/component.js +7 -7
  17. package/lib/codegen/script/componentSelf.d.ts +1 -1
  18. package/lib/codegen/script/componentSelf.js +2 -2
  19. package/lib/codegen/script/context.d.ts +1 -1
  20. package/lib/codegen/script/index.d.ts +1 -8
  21. package/lib/codegen/script/index.js +15 -39
  22. package/lib/codegen/script/scriptSetup.d.ts +1 -1
  23. package/lib/codegen/script/scriptSetup.js +46 -58
  24. package/lib/codegen/script/src.js +2 -2
  25. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  26. package/lib/codegen/script/styleModulesType.js +2 -2
  27. package/lib/codegen/script/template.d.ts +1 -1
  28. package/lib/codegen/script/template.js +11 -32
  29. package/lib/codegen/template/camelized.d.ts +2 -0
  30. package/lib/codegen/template/camelized.js +31 -0
  31. package/lib/codegen/template/context.d.ts +17 -13
  32. package/lib/codegen/template/context.js +35 -89
  33. package/lib/codegen/template/element.js +32 -252
  34. package/lib/codegen/template/elementChildren.d.ts +1 -1
  35. package/lib/codegen/template/elementChildren.js +3 -4
  36. package/lib/codegen/template/elementDirectives.js +18 -11
  37. package/lib/codegen/template/elementProps.d.ts +2 -1
  38. package/lib/codegen/template/elementProps.js +22 -26
  39. package/lib/codegen/template/index.d.ts +1 -0
  40. package/lib/codegen/template/index.js +39 -33
  41. package/lib/codegen/template/interpolation.js +13 -9
  42. package/lib/codegen/template/slotOutlet.js +39 -17
  43. package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
  44. package/lib/codegen/template/styleScopedClasses.js +141 -0
  45. package/lib/codegen/template/templateChild.js +9 -2
  46. package/lib/codegen/template/vSlot.d.ts +5 -0
  47. package/lib/codegen/template/vSlot.js +80 -0
  48. package/lib/codegen/utils/index.d.ts +11 -1
  49. package/lib/codegen/utils/index.js +15 -4
  50. package/lib/codegen/utils/src.d.ts +2 -0
  51. package/lib/codegen/utils/src.js +19 -0
  52. package/lib/parsers/scriptSetupRanges.d.ts +5 -3
  53. package/lib/parsers/scriptSetupRanges.js +8 -11
  54. package/lib/parsers/vueCompilerOptions.d.ts +2 -2
  55. package/lib/plugins/vue-style-class-names.d.ts +5 -0
  56. package/lib/plugins/vue-style-class-names.js +32 -0
  57. package/lib/plugins/vue-style-reference-link.d.ts +1 -0
  58. package/lib/plugins/vue-style-reference-link.js +3 -0
  59. package/lib/plugins/vue-style-reference-links.d.ts +3 -0
  60. package/lib/plugins/vue-style-reference-links.js +26 -0
  61. package/lib/plugins/vue-template-inline-ts.js +53 -12
  62. package/lib/plugins/vue-tsx.d.ts +35 -28
  63. package/lib/plugins/vue-tsx.js +75 -55
  64. package/lib/plugins/vue-vine.d.ts +3 -0
  65. package/lib/plugins/vue-vine.js +35 -0
  66. package/lib/types.d.ts +6 -2
  67. package/lib/utils/findDestructuredProps.d.ts +1 -0
  68. package/lib/utils/findDestructuredProps.js +3 -0
  69. package/lib/utils/parseCssImports.d.ts +4 -0
  70. package/lib/utils/parseCssImports.js +19 -0
  71. package/lib/utils/parseSfc.js +4 -3
  72. package/lib/utils/signals.d.ts +2 -0
  73. package/lib/utils/signals.js +54 -0
  74. package/lib/utils/ts.d.ts +14 -2
  75. package/lib/utils/ts.js +117 -88
  76. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
  77. package/lib/virtualFile/computedEmbeddedCodes.js +11 -11
  78. package/lib/virtualFile/computedSfc.d.ts +1 -2
  79. package/lib/virtualFile/computedSfc.js +79 -82
  80. package/lib/virtualFile/computedVueSfc.d.ts +1 -2
  81. package/lib/virtualFile/computedVueSfc.js +7 -7
  82. package/lib/virtualFile/vueFile.d.ts +5 -5
  83. package/lib/virtualFile/vueFile.js +6 -6
  84. package/package.json +4 -4
@@ -10,6 +10,7 @@ const interpolation_1 = require("./interpolation");
10
10
  const slotOutlet_1 = require("./slotOutlet");
11
11
  const vFor_1 = require("./vFor");
12
12
  const vIf_1 = require("./vIf");
13
+ const vSlot_1 = require("./vSlot");
13
14
  // @ts-ignore
14
15
  const transformContext = {
15
16
  onError: () => { },
@@ -74,9 +75,15 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
74
75
  else if (vIfNode) {
75
76
  yield* (0, vIf_1.generateVIf)(options, ctx, vIfNode);
76
77
  }
78
+ else if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
79
+ yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node);
80
+ }
77
81
  else {
78
- if (node.tagType === CompilerDOM.ElementTypes.SLOT) {
79
- yield* (0, slotOutlet_1.generateSlotOutlet)(options, ctx, node);
82
+ const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
83
+ if (node.tagType === CompilerDOM.ElementTypes.TEMPLATE
84
+ && ctx.currentComponent
85
+ && slotDir) {
86
+ yield* (0, vSlot_1.generateVSlot)(options, ctx, node, slotDir);
80
87
  }
81
88
  else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
82
89
  || node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
@@ -0,0 +1,5 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
2
+ import type { Code } from '../../types';
3
+ import type { TemplateCodegenContext } from './context';
4
+ import type { TemplateCodegenOptions } from './index';
5
+ export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode): Generator<Code>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateVSlot = generateVSlot;
4
+ const CompilerDOM = require("@vue/compiler-dom");
5
+ const utils_1 = require("../utils");
6
+ const objectProperty_1 = require("./objectProperty");
7
+ const templateChild_1 = require("./templateChild");
8
+ function* generateVSlot(options, ctx, node, slotDir) {
9
+ if (!ctx.currentComponent) {
10
+ return;
11
+ }
12
+ ctx.currentComponent.used = true;
13
+ const slotBlockVars = [];
14
+ yield `{${utils_1.newLine}`;
15
+ yield `const { `;
16
+ if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
17
+ yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc, false, true);
18
+ }
19
+ else {
20
+ yield* (0, utils_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
21
+ }
22
+ yield `: __VLS_thisSlot } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
23
+ if (slotDir.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
24
+ const slotAst = (0, utils_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
25
+ (0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
26
+ if (!slotDir.exp.content.includes(':')) {
27
+ yield `const [`;
28
+ yield [
29
+ slotDir.exp.content,
30
+ 'template',
31
+ slotDir.exp.loc.start.offset,
32
+ ctx.codeFeatures.all,
33
+ ];
34
+ yield `] = __VLS_getSlotParams(__VLS_thisSlot)${utils_1.endOfLine}`;
35
+ }
36
+ else {
37
+ yield `const `;
38
+ yield [
39
+ slotDir.exp.content,
40
+ 'template',
41
+ slotDir.exp.loc.start.offset,
42
+ ctx.codeFeatures.all,
43
+ ];
44
+ yield ` = __VLS_getSlotParam(__VLS_thisSlot)${utils_1.endOfLine}`;
45
+ }
46
+ }
47
+ for (const varName of slotBlockVars) {
48
+ ctx.addLocalVariable(varName);
49
+ }
50
+ yield* ctx.resetDirectiveComments('end of slot children start');
51
+ let prev;
52
+ for (const childNode of node.children) {
53
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
54
+ prev = childNode;
55
+ }
56
+ for (const varName of slotBlockVars) {
57
+ ctx.removeLocalVariable(varName);
58
+ }
59
+ let isStatic = true;
60
+ if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
61
+ isStatic = slotDir.arg.isStatic;
62
+ }
63
+ if (isStatic && !slotDir.arg) {
64
+ yield `${ctx.currentComponent.ctxVar}.slots!['`;
65
+ yield [
66
+ '',
67
+ 'template',
68
+ slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
69
+ ? '#'.length
70
+ : slotDir.loc.source.startsWith('v-slot:')
71
+ ? 'v-slot:'.length
72
+ : 0),
73
+ ctx.codeFeatures.completion,
74
+ ];
75
+ yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
76
+ }
77
+ yield* ctx.generateAutoImportCompletion();
78
+ yield `}${utils_1.newLine}`;
79
+ }
80
+ //# sourceMappingURL=vSlot.js.map
@@ -1,3 +1,4 @@
1
+ import * as CompilerDOM from '@vue/compiler-dom';
1
2
  import type * as ts from 'typescript';
2
3
  import type { Code, SfcBlock, VueCodeInformation } from '../../types';
3
4
  export declare const newLine = "\n";
@@ -6,6 +7,15 @@ export declare const combineLastMapping: VueCodeInformation;
6
7
  export declare const variableNameRegex: RegExp;
7
8
  export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
8
9
  export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
9
- export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: [id: ts.Identifier, isRest: boolean][], isRest?: boolean): [id: ts.Identifier, isRest: boolean][];
10
+ export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
11
+ id: ts.Identifier;
12
+ isRest: boolean;
13
+ initializer: ts.Expression | undefined;
14
+ }[], isRest?: boolean, initializer?: ts.Expression | undefined): {
15
+ id: ts.Identifier;
16
+ isRest: boolean;
17
+ initializer: ts.Expression | undefined;
18
+ }[];
19
+ export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
10
20
  export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
11
21
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
@@ -4,6 +4,7 @@ exports.variableNameRegex = exports.combineLastMapping = exports.endOfLine = exp
4
4
  exports.wrapWith = wrapWith;
5
5
  exports.collectVars = collectVars;
6
6
  exports.collectIdentifiers = collectIdentifiers;
7
+ exports.normalizeAttributeValue = normalizeAttributeValue;
7
8
  exports.createTsAst = createTsAst;
8
9
  exports.generateSfcBlockSection = generateSfcBlockSection;
9
10
  const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
@@ -24,18 +25,18 @@ function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
24
25
  }
25
26
  function collectVars(ts, node, ast, results = []) {
26
27
  const identifiers = collectIdentifiers(ts, node, []);
27
- for (const [id] of identifiers) {
28
+ for (const { id } of identifiers) {
28
29
  results.push((0, scriptSetupRanges_1.getNodeText)(ts, id, ast));
29
30
  }
30
31
  return results;
31
32
  }
32
- function collectIdentifiers(ts, node, results = [], isRest = false) {
33
+ function collectIdentifiers(ts, node, results = [], isRest = false, initializer = undefined) {
33
34
  if (ts.isIdentifier(node)) {
34
- results.push([node, isRest]);
35
+ results.push({ id: node, isRest, initializer });
35
36
  }
36
37
  else if (ts.isObjectBindingPattern(node)) {
37
38
  for (const el of node.elements) {
38
- collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
39
+ collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken, el.initializer);
39
40
  }
40
41
  }
41
42
  else if (ts.isArrayBindingPattern(node)) {
@@ -50,6 +51,16 @@ function collectIdentifiers(ts, node, results = [], isRest = false) {
50
51
  }
51
52
  return results;
52
53
  }
54
+ function normalizeAttributeValue(node) {
55
+ let offset = node.loc.start.offset;
56
+ let content = node.loc.source;
57
+ if ((content.startsWith(`'`) && content.endsWith(`'`))
58
+ || (content.startsWith(`"`) && content.endsWith(`"`))) {
59
+ offset++;
60
+ content = content.slice(1, -1);
61
+ }
62
+ return [content, offset];
63
+ }
53
64
  function createTsAst(ts, astHolder, text) {
54
65
  if (astHolder.__volar_ast_text !== text) {
55
66
  astHolder.__volar_ast_text = text;
@@ -0,0 +1,2 @@
1
+ import { Code, SfcBlockAttr, VueCodeInformation } from "../../types";
2
+ export declare function generateSfcBlockSrc(src: SfcBlockAttr & object, text: string, features: VueCodeInformation): Generator<Code>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateSfcBlockSrc = generateSfcBlockSrc;
4
+ function* generateSfcBlockSrc(src, text, features) {
5
+ const { offset, quotes } = src;
6
+ if (!quotes) {
7
+ yield [``, 'main', offset, { verification: true }];
8
+ }
9
+ yield [
10
+ quotes ? text : `'${text}'`,
11
+ 'main',
12
+ quotes ? offset : offset - 1,
13
+ features
14
+ ];
15
+ if (!quotes) {
16
+ yield [``, 'main', offset + text.length, { __combineOffsetMapping: 2 }];
17
+ }
18
+ }
19
+ //# sourceMappingURL=src.js.map
@@ -18,11 +18,14 @@ type DefineProp = {
18
18
  };
19
19
  type DefineProps = CallExpressionRange & {
20
20
  name?: string;
21
- destructured?: Set<string>;
21
+ destructured?: Map<string, ts.Expression | undefined>;
22
22
  destructuredRest?: string;
23
23
  statement: TextRange;
24
+ argNode?: ts.Expression;
25
+ };
26
+ type WithDefaults = Omit<CallExpressionRange, 'typeArg'> & {
27
+ argNode?: ts.Expression;
24
28
  };
25
- type WithDefaults = Pick<CallExpressionRange, 'callExp' | 'exp' | 'arg'>;
26
29
  type DefineEmits = CallExpressionRange & {
27
30
  name?: string;
28
31
  hasUnionTypeArg?: boolean;
@@ -30,7 +33,6 @@ type DefineEmits = CallExpressionRange & {
30
33
  };
31
34
  type DefineSlots = CallExpressionRange & {
32
35
  name?: string;
33
- isObjectBindingPattern?: boolean;
34
36
  statement: TextRange;
35
37
  };
36
38
  type DefineOptions = {
@@ -197,19 +197,20 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
197
197
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
198
198
  defineProps = {
199
199
  ...parseCallExpression(node),
200
- statement: getStatementRange(ts, parents, node, ast)
200
+ statement: getStatementRange(ts, parents, node, ast),
201
+ argNode: node.arguments[0]
201
202
  };
202
203
  if (ts.isVariableDeclaration(parent)) {
203
204
  if (ts.isObjectBindingPattern(parent.name)) {
204
- defineProps.destructured = new Set();
205
+ defineProps.destructured = new Map();
205
206
  const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
206
- for (const [id, isRest] of identifiers) {
207
+ for (const { id, isRest, initializer } of identifiers) {
207
208
  const name = _getNodeText(id);
208
209
  if (isRest) {
209
210
  defineProps.destructuredRest = name;
210
211
  }
211
212
  else {
212
- defineProps.destructured.add(name);
213
+ defineProps.destructured.set(name, initializer);
213
214
  }
214
215
  }
215
216
  }
@@ -230,7 +231,8 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
230
231
  withDefaults = {
231
232
  callExp: _getStartEnd(node),
232
233
  exp: _getStartEnd(node.expression),
233
- arg: arg ? _getStartEnd(arg) : undefined
234
+ arg: arg ? _getStartEnd(arg) : undefined,
235
+ argNode: arg
234
236
  };
235
237
  }
236
238
  else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
@@ -259,12 +261,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
259
261
  statement: getStatementRange(ts, parents, node, ast)
260
262
  };
261
263
  if (ts.isVariableDeclaration(parent)) {
262
- if (ts.isIdentifier(parent.name)) {
263
- defineSlots.name = _getNodeText(parent.name);
264
- }
265
- else {
266
- defineSlots.isObjectBindingPattern = ts.isObjectBindingPattern(parent.name);
267
- }
264
+ defineSlots.name = _getNodeText(parent.name);
268
265
  }
269
266
  }
270
267
  else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
@@ -1,2 +1,2 @@
1
- import type { VueCompilerOptions } from '../types';
2
- export declare function parseVueCompilerOptions(comments: string[]): Partial<VueCompilerOptions> | undefined;
1
+ import type { RawVueCompilerOptions } from '../types';
2
+ export declare function parseVueCompilerOptions(comments: string[]): RawVueCompilerOptions | undefined;
@@ -0,0 +1,5 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ export declare const commentReg: RegExp;
3
+ declare const plugin: VueLanguagePlugin;
4
+ export default plugin;
5
+ export declare function fillBlank(css: string, ...regs: RegExp[]): string;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commentReg = void 0;
4
+ exports.fillBlank = fillBlank;
5
+ exports.commentReg = /(?<=\/\*)[\s\S]*?(?=\*\/)|(?<=\/\/)[\s\S]*?(?=\n)/g;
6
+ const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#)[{])/gi;
7
+ const fragmentReg = /(?<={)[^{]*(?=(?<!\\);)/g;
8
+ const plugin = () => {
9
+ return {
10
+ version: 2.1,
11
+ resolveStyleReferenceLinks(block) {
12
+ const result = [];
13
+ const content = fillBlank(block.content, exports.commentReg, fragmentReg);
14
+ const matches = content.matchAll(cssClassNameReg);
15
+ for (const match of matches) {
16
+ const matchText = match[1];
17
+ if (matchText) {
18
+ result.push({ text: matchText, offset: match.index });
19
+ }
20
+ }
21
+ return result;
22
+ },
23
+ };
24
+ };
25
+ exports.default = plugin;
26
+ function fillBlank(css, ...regs) {
27
+ for (const reg of regs) {
28
+ css = css.replace(reg, match => ' '.repeat(match.length));
29
+ }
30
+ return css;
31
+ }
32
+ //# sourceMappingURL=vue-style-class-names.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=vue-style-reference-link.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
4
+ const plugin = () => {
5
+ return {
6
+ version: 2.1,
7
+ resolveStyleReferenceLinks(block) {
8
+ const result = [];
9
+ const matches = block.content.matchAll(cssImportReg);
10
+ for (const match of matches) {
11
+ let text = match[0];
12
+ let offset = match.index;
13
+ if (text.startsWith('\'') || text.startsWith('"')) {
14
+ text = text.slice(1, -1);
15
+ offset += 1;
16
+ }
17
+ if (text) {
18
+ result.push({ text, offset });
19
+ }
20
+ }
21
+ return result;
22
+ },
23
+ };
24
+ };
25
+ exports.default = plugin;
26
+ //# sourceMappingURL=vue-style-reference-links.js.map
@@ -76,19 +76,37 @@ const plugin = ctx => {
76
76
  continue;
77
77
  }
78
78
  if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
79
- addFormatCodes(prop.arg.content, prop.arg.loc.start.offset, formatBrackets.normal);
79
+ addFormatCodes(prop.arg.loc.source, prop.arg.loc.start.offset, formatBrackets.normal);
80
80
  }
81
81
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
82
82
  && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
83
83
  ) {
84
84
  if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
85
85
  const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
86
- addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)
87
- ? formatBrackets.event
88
- : formatBrackets.normal);
86
+ if ((0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)) {
87
+ addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.event);
88
+ }
89
+ else {
90
+ const lines = prop.exp.content.split('\n');
91
+ const firstLineEmpty = lines[0].trim() === '';
92
+ const lastLineEmpty = lines[lines.length - 1].trim() === '';
93
+ if (lines.length <= 1 || (!firstLineEmpty && !lastLineEmpty)) {
94
+ addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.normal);
95
+ }
96
+ else {
97
+ addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, ['(', ');']);
98
+ }
99
+ }
100
+ }
101
+ else if (prop.name === 'slot') {
102
+ addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.params);
103
+ }
104
+ else if (prop.rawName === 'v-for') {
105
+ // #2586
106
+ addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.for);
89
107
  }
90
108
  else {
91
- addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal);
109
+ addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.normal);
92
110
  }
93
111
  }
94
112
  }
@@ -100,7 +118,7 @@ const plugin = ctx => {
100
118
  for (let i = 0; i < node.branches.length; i++) {
101
119
  const branch = node.branches[i];
102
120
  if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
103
- addFormatCodes(branch.condition.content, branch.condition.loc.start.offset, formatBrackets.if);
121
+ addFormatCodes(branch.condition.loc.source, branch.condition.loc.start.offset, formatBrackets.if);
104
122
  }
105
123
  for (const childNode of branch.children) {
106
124
  visit(childNode);
@@ -111,8 +129,14 @@ const plugin = ctx => {
111
129
  const { leftExpressionRange, leftExpressionText } = (0, vFor_1.parseVForNode)(node);
112
130
  const { source } = node.parseResult;
113
131
  if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
114
- const start = leftExpressionRange.start;
115
- const end = source.loc.start.offset + source.content.length;
132
+ let start = leftExpressionRange.start;
133
+ let end = source.loc.start.offset + source.content.length;
134
+ while (templateContent[start - 1] === ' ' || templateContent[start - 1] === '(') {
135
+ start--;
136
+ }
137
+ while (templateContent[end] === ' ' || templateContent[end] === ')') {
138
+ end++;
139
+ }
116
140
  addFormatCodes(templateContent.slice(start, end), start, formatBrackets.for);
117
141
  }
118
142
  for (const child of node.children) {
@@ -135,10 +159,27 @@ const plugin = ctx => {
135
159
  // {{ ... }}
136
160
  const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, templateContent);
137
161
  const lines = content.split('\n');
138
- addFormatCodes(content, start, lines.length <= 1 ? formatBrackets.curly : [
139
- lines[0].trim() === '' ? '(' : formatBrackets.curly[0],
140
- lines[lines.length - 1].trim() === '' ? ');' : formatBrackets.curly[1],
141
- ]);
162
+ const firstLineEmpty = lines[0].trim() === '';
163
+ const lastLineEmpty = lines[lines.length - 1].trim() === '';
164
+ if (content.includes('=>')) { // arrow function
165
+ if (lines.length <= 1 || (!firstLineEmpty && !lastLineEmpty)) {
166
+ addFormatCodes(content, start, formatBrackets.normal);
167
+ }
168
+ else {
169
+ addFormatCodes(content, start, ['(', ');']);
170
+ }
171
+ }
172
+ else {
173
+ if (lines.length <= 1 || (!firstLineEmpty && !lastLineEmpty)) {
174
+ addFormatCodes(content, start, formatBrackets.curly);
175
+ }
176
+ else {
177
+ addFormatCodes(content, start, [
178
+ firstLineEmpty ? '(' : '(0 +',
179
+ lastLineEmpty ? ');' : '+ 0);'
180
+ ]);
181
+ }
182
+ }
142
183
  }
143
184
  }
144
185
  function addFormatCodes(code, offset, wrapper) {
@@ -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: import("alien-signals").Computed<{
4
+ getScriptRanges: () => {
5
5
  exportDefault: (import("../types").TextRange & {
6
6
  expression: import("../types").TextRange;
7
7
  args: import("../types").TextRange;
@@ -19,8 +19,8 @@ export declare const tsCodegen: WeakMap<Sfc, {
19
19
  isDefaultImport?: boolean;
20
20
  isNamespace?: boolean;
21
21
  }[];
22
- } | undefined>;
23
- scriptSetupRanges: import("alien-signals").Computed<{
22
+ } | undefined;
23
+ getScriptSetupRanges: () => {
24
24
  leadingCommentEndOffset: number;
25
25
  importSectionEndOffset: number;
26
26
  bindings: {
@@ -46,15 +46,19 @@ export declare const tsCodegen: WeakMap<Sfc, {
46
46
  typeArg?: import("../types").TextRange;
47
47
  } & {
48
48
  name?: string;
49
- destructured?: Set<string>;
49
+ destructured?: Map<string, import("typescript").Expression | undefined>;
50
50
  destructuredRest?: string;
51
51
  statement: import("../types").TextRange;
52
+ argNode?: import("typescript").Expression;
52
53
  }) | undefined;
53
- withDefaults: {
54
+ withDefaults: (Omit<{
54
55
  callExp: import("../types").TextRange;
55
56
  exp: import("../types").TextRange;
56
- arg?: import("../types").TextRange | undefined;
57
- } | undefined;
57
+ arg?: import("../types").TextRange;
58
+ typeArg?: import("../types").TextRange;
59
+ }, "typeArg"> & {
60
+ argNode?: import("typescript").Expression;
61
+ }) | undefined;
58
62
  defineEmits: ({
59
63
  callExp: import("../types").TextRange;
60
64
  exp: import("../types").TextRange;
@@ -72,7 +76,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
72
76
  typeArg?: import("../types").TextRange;
73
77
  } & {
74
78
  name?: string;
75
- isObjectBindingPattern?: boolean;
76
79
  statement: import("../types").TextRange;
77
80
  }) | undefined;
78
81
  defineExpose: {
@@ -111,9 +114,9 @@ export declare const tsCodegen: WeakMap<Sfc, {
111
114
  } & {
112
115
  name?: string;
113
116
  })[];
114
- } | undefined>;
115
- lang: import("alien-signals").Computed<string>;
116
- generatedScript: import("alien-signals").Computed<{
117
+ } | undefined;
118
+ getLang: () => string;
119
+ getGeneratedScript: () => {
117
120
  codes: Code[];
118
121
  linkedCodeMappings: Mapping<unknown>[];
119
122
  generatedTemplate: boolean;
@@ -127,46 +130,51 @@ export declare const tsCodegen: WeakMap<Sfc, {
127
130
  readonly PrettifyLocal: string;
128
131
  readonly OmitKeepDiscriminatedUnion: string;
129
132
  readonly WithDefaults: string;
130
- readonly WithTemplateSlots: string;
133
+ readonly WithSlots: string;
131
134
  readonly PropsChildren: string;
132
135
  readonly TypePropsToOption: string;
133
136
  readonly OmitIndexSignature: string;
134
137
  };
135
138
  inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
136
- }>;
137
- generatedTemplate: import("alien-signals").Computed<{
139
+ };
140
+ getGeneratedTemplate: () => {
138
141
  codes: Code[];
139
- slots: {
140
- name: string;
141
- loc?: number;
142
- tagRange: [number, number];
143
- varName: string;
144
- nodeLoc: any;
145
- }[];
146
- dynamicSlots: {
147
- expVar: string;
148
- varName: string;
149
- }[];
150
142
  codeFeatures: {
151
143
  all: import("../types").VueCodeInformation;
144
+ none: import("../types").VueCodeInformation;
152
145
  verification: import("../types").VueCodeInformation;
153
146
  completion: import("../types").VueCodeInformation;
154
147
  additionalCompletion: import("../types").VueCodeInformation;
148
+ withoutCompletion: import("../types").VueCodeInformation;
155
149
  navigation: import("../types").VueCodeInformation;
156
150
  navigationWithoutRename: import("../types").VueCodeInformation;
157
151
  navigationAndCompletion: import("../types").VueCodeInformation;
158
152
  navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
153
+ navigationAndVerification: import("../types").VueCodeInformation;
159
154
  withoutNavigation: import("../types").VueCodeInformation;
160
155
  withoutHighlight: import("../types").VueCodeInformation;
156
+ withoutHighlightAndNavigation: import("../types").VueCodeInformation;
161
157
  withoutHighlightAndCompletion: import("../types").VueCodeInformation;
162
158
  withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
163
159
  };
160
+ resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
161
+ slots: {
162
+ name: string;
163
+ offset?: number;
164
+ tagRange: [number, number];
165
+ nodeLoc: any;
166
+ propsVar: string;
167
+ }[];
168
+ dynamicSlots: {
169
+ expVar: string;
170
+ propsVar: string;
171
+ }[];
172
+ specialVars: Set<string>;
164
173
  accessExternalVariables: Map<string, Set<number>>;
165
174
  lastGenericComment: {
166
175
  content: string;
167
176
  offset: number;
168
177
  } | undefined;
169
- hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
170
178
  blockConditions: string[];
171
179
  scopedClasses: {
172
180
  source: string;
@@ -180,7 +188,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
180
188
  inheritedAttrVars: Set<string>;
181
189
  templateRefs: Map<string, [varName: string, offset: number]>;
182
190
  currentComponent: {
183
- node: import("@vue/compiler-dom").ElementNode;
184
191
  ctxVar: string;
185
192
  used: boolean;
186
193
  } | undefined;
@@ -195,7 +202,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
195
202
  expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
196
203
  resetDirectiveComments: (endStr: string) => Generator<Code>;
197
204
  generateAutoImportCompletion: () => Generator<Code>;
198
- } | undefined>;
205
+ } | undefined;
199
206
  }>;
200
207
  declare const plugin: VueLanguagePlugin;
201
208
  export default plugin;