@vue/language-core 2.0.7 → 2.0.11

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eachElementNode = exports.generate = void 0;
3
+ exports.forEachElementNode = exports.parseVForNode = exports.parseInterpolationNode = exports.isCompoundExpression = exports.createTsAst = exports.generate = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const shared_1 = require("@vue/shared");
@@ -36,15 +36,6 @@ const presetInfos = {
36
36
  slotNameExport: (0, utils_1.disableAllFeatures)({ semantic: { shouldHighlight: () => false }, verification: true, navigation: true, /* __navigationCodeLens: true */ }),
37
37
  refAttr: (0, utils_1.disableAllFeatures)({ navigation: true }),
38
38
  };
39
- const formatBrackets = {
40
- normal: ['`${', '}`;'],
41
- // fix https://github.com/vuejs/language-tools/issues/3572
42
- params: ['(', ') => {}'],
43
- // fix https://github.com/vuejs/language-tools/issues/1210
44
- // fix https://github.com/vuejs/language-tools/issues/2305
45
- curly: ['0 +', '+ 0;'],
46
- event: ['() => ', ';'],
47
- };
48
39
  const validTsVarReg = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
49
40
  const colonReg = /:/g;
50
41
  // @ts-ignore
@@ -64,41 +55,39 @@ const transformContext = {
64
55
  };
65
56
  function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGenerateScopedClasses, stylesScopedClasses, hasScriptSetupSlots, slotsAssignName, propsAssignName, codegenStack) {
66
57
  const processDirectiveComment = (code) => {
67
- if (ignoreError && typeof code !== 'string') {
68
- const data = code[3];
69
- if (data.verification) {
70
- code[3] = {
71
- ...data,
72
- verification: false,
73
- };
58
+ if (typeof code !== 'string') {
59
+ if (ignoreError) {
60
+ const data = code[3];
61
+ if (data.verification) {
62
+ code[3] = {
63
+ ...data,
64
+ verification: false,
65
+ };
66
+ }
74
67
  }
75
- }
76
- if (expectErrorToken && typeof code !== 'string') {
77
- const token = expectErrorToken;
78
- const data = code[3];
79
- if (data.verification) {
80
- code[3] = {
81
- ...data,
82
- verification: {
83
- shouldReport: () => {
84
- token.errors++;
85
- return false;
68
+ if (expectErrorToken) {
69
+ const token = expectErrorToken;
70
+ const data = code[3];
71
+ if (data.verification && (typeof data.verification !== 'object' || !data.verification.shouldReport)) {
72
+ code[3] = {
73
+ ...data,
74
+ verification: {
75
+ shouldReport: () => {
76
+ token.errors++;
77
+ return false;
78
+ },
86
79
  },
87
- },
88
- };
80
+ };
81
+ }
89
82
  }
83
+ code[3].structure = false;
84
+ code[3].format = false;
90
85
  }
91
86
  return code;
92
87
  };
93
88
  const _ts = codegenStack
94
- ? (code) => ['ts', processDirectiveComment(code), (0, utils_1.getStack)()]
95
- : (code) => ['ts', processDirectiveComment(code), ''];
96
- const _tsFormat = codegenStack
97
- ? (code) => ['tsFormat', code, (0, utils_1.getStack)()]
98
- : (code) => ['tsFormat', code, ''];
99
- const _inlineCss = codegenStack
100
- ? (code) => ['inlineCss', code, (0, utils_1.getStack)()]
101
- : (code) => ['inlineCss', code, ''];
89
+ ? (code) => [processDirectiveComment(code), (0, utils_1.getStack)()]
90
+ : (code) => [processDirectiveComment(code), ''];
102
91
  const nativeTags = new Set(vueCompilerOptions.nativeTags);
103
92
  const slots = new Map();
104
93
  const slotExps = new Map();
@@ -113,7 +102,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
113
102
  let hasSlot = false;
114
103
  let ignoreError = false;
115
104
  let expectErrorToken;
116
- let expectedErrorNode;
117
105
  let elementIndex = 0;
118
106
  if (slotsAssignName) {
119
107
  localVars.set(slotsAssignName, 1);
@@ -142,7 +130,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
142
130
  if (!template.ast) {
143
131
  return tagOffsetsMap;
144
132
  }
145
- for (const node of eachElementNode(template.ast)) {
133
+ for (const node of forEachElementNode(template.ast)) {
146
134
  if (node.tag === 'slot') {
147
135
  // ignore
148
136
  }
@@ -177,13 +165,13 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
177
165
  }
178
166
  return tagOffsetsMap;
179
167
  }
180
- function* generateExpectErrorComment() {
181
- if (expectErrorToken && expectedErrorNode) {
168
+ function* resetDirectiveComments(endStr) {
169
+ if (expectErrorToken) {
182
170
  const token = expectErrorToken;
183
171
  yield _ts([
184
172
  '',
185
173
  'template',
186
- expectedErrorNode.loc.start.offset,
174
+ expectErrorToken.node.loc.start.offset,
187
175
  (0, utils_1.disableAllFeatures)({
188
176
  verification: {
189
177
  shouldReport: () => token.errors === 0,
@@ -194,14 +182,17 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
194
182
  yield _ts([
195
183
  '',
196
184
  'template',
197
- expectedErrorNode.loc.end.offset,
185
+ expectErrorToken.node.loc.end.offset,
198
186
  (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }),
199
187
  ]);
200
188
  yield _ts('\n;\n');
189
+ expectErrorToken = undefined;
190
+ yield _ts(`// @vue-expect-error ${endStr}\n`);
191
+ }
192
+ if (ignoreError) {
193
+ ignoreError = false;
194
+ yield _ts(`// @vue-ignore ${endStr}\n`);
201
195
  }
202
- ignoreError = false;
203
- expectErrorToken = undefined;
204
- expectedErrorNode = undefined;
205
196
  }
206
197
  function* generateCanonicalComponentName(tagText, offset, info) {
207
198
  if (validTsVarReg.test(tagText)) {
@@ -303,18 +294,22 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
303
294
  }
304
295
  }
305
296
  function* generateAstNode(node, parentEl, prevNode, componentCtxVar) {
306
- yield* generateExpectErrorComment();
307
297
  if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
308
298
  const commentText = prevNode.content.trim().split(' ')[0];
309
299
  if (commentText.match(/^@vue-skip\b[\s\S]*/)) {
300
+ yield _ts('// @vue-skip\n');
310
301
  return;
311
302
  }
312
- else if (commentText.match(/^@vue-ignore\b[\s\S]*/)) {
303
+ else if (commentText.match(/^@vue-ignore\b[\s\S]*/) && !ignoreError) {
313
304
  ignoreError = true;
305
+ yield _ts('// @vue-ignore start\n');
314
306
  }
315
- else if (commentText.match(/^@vue-expect-error\b[\s\S]*/)) {
316
- expectErrorToken = { errors: 0 };
317
- expectedErrorNode = prevNode;
307
+ else if (commentText.match(/^@vue-expect-error\b[\s\S]*/) && !expectErrorToken) {
308
+ expectErrorToken = {
309
+ errors: 0,
310
+ node: prevNode,
311
+ };
312
+ yield _ts('// @vue-expect-error start\n');
318
313
  }
319
314
  }
320
315
  if (node.type === CompilerDOM.NodeTypes.ROOT) {
@@ -323,7 +318,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
323
318
  yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
324
319
  prev = childNode;
325
320
  }
326
- yield* generateExpectErrorComment();
321
+ yield* resetDirectiveComments('end of root');
327
322
  }
328
323
  else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
329
324
  const vForNode = getVForNode(node);
@@ -352,24 +347,9 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
352
347
  }
353
348
  else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
354
349
  // {{ ... }}
355
- let content = node.content.loc.source;
356
- let start = node.content.loc.start.offset;
357
- let leftCharacter;
358
- let rightCharacter;
359
- // fix https://github.com/vuejs/language-tools/issues/1787
360
- while ((leftCharacter = template.content.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
361
- start--;
362
- content = leftCharacter + content;
363
- }
364
- while ((rightCharacter = template.content.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
365
- content = content + rightCharacter;
366
- }
350
+ const [content, start] = parseInterpolationNode(node, template.content);
367
351
  yield* generateInterpolation(content, node.content.loc, start, presetInfos.all, '(', ');\n');
368
- const lines = content.split('\n');
369
- yield* generateTsFormat(content, start, lines.length <= 1 ? formatBrackets.curly : [
370
- lines[0].trim() === '' ? '(' : formatBrackets.curly[0],
371
- lines[lines.length - 1].trim() === '' ? ')' : formatBrackets.curly[1],
372
- ]);
352
+ yield* resetDirectiveComments('end of INTERPOLATION');
373
353
  }
374
354
  else if (node.type === CompilerDOM.NodeTypes.IF) {
375
355
  // v-if / v-else-if / v-else
@@ -401,17 +381,16 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
401
381
  yield _ts(` `);
402
382
  yield* generateInterpolation(branch.condition.content, branch.condition.loc, branch.condition.loc.start.offset, presetInfos.all, '(', ')');
403
383
  blockConditions.push((0, language_core_1.toString)([...generateInterpolation(branch.condition.content, branch.condition.loc, undefined, undefined, '(', ')')]
404
- .map(code => code[1])));
384
+ .map(([code]) => code)));
405
385
  addedBlockCondition = true;
406
- yield* generateTsFormat(branch.condition.content, branch.condition.loc.start.offset, formatBrackets.normal);
407
386
  }
408
387
  yield _ts(` {\n`);
388
+ yield* resetDirectiveComments('end of v-if start');
409
389
  let prev;
410
390
  for (const childNode of branch.children) {
411
391
  yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
412
392
  prev = childNode;
413
393
  }
414
- yield* generateExpectErrorComment();
415
394
  yield* generateExtraAutoImport();
416
395
  yield _ts('}\n');
417
396
  if (addedBlockCondition) {
@@ -421,19 +400,17 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
421
400
  blockConditions.length = originalBlockConditionsLength;
422
401
  }
423
402
  function* generateVFor(node, parentEl, componentCtxVar) {
424
- const { source, value, key, index } = node.parseResult;
425
- const leftExpressionRange = value ? { start: (value ?? key ?? index).loc.start.offset, end: (index ?? key ?? value).loc.end.offset } : undefined;
426
- const leftExpressionText = leftExpressionRange ? node.loc.source.substring(leftExpressionRange.start - node.loc.start.offset, leftExpressionRange.end - node.loc.start.offset) : undefined;
403
+ const { source } = node.parseResult;
404
+ const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
427
405
  const forBlockVars = [];
428
406
  yield _ts(`for (const [`);
429
407
  if (leftExpressionRange && leftExpressionText) {
430
- const collectAst = createTsAst(node.parseResult, `const [${leftExpressionText}]`);
408
+ const collectAst = createTsAst(ts, node.parseResult, `const [${leftExpressionText}]`);
431
409
  (0, transform_1.collectVars)(ts, collectAst, collectAst, forBlockVars);
432
410
  for (const varName of forBlockVars) {
433
411
  localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
434
412
  }
435
413
  yield _ts([leftExpressionText, 'template', leftExpressionRange.start, presetInfos.all]);
436
- yield* generateTsFormat(leftExpressionText, leftExpressionRange.start, formatBrackets.normal);
437
414
  }
438
415
  yield _ts(`] of __VLS_getVForSourceType`);
439
416
  if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -441,15 +418,14 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
441
418
  yield* generateInterpolation(source.content, source.loc, source.loc.start.offset, presetInfos.all, '(', ')');
442
419
  yield _ts('!)'); // #3102
443
420
  yield _ts(') {\n');
421
+ yield* resetDirectiveComments('end of v-for start');
444
422
  let prev;
445
423
  for (const childNode of node.children) {
446
424
  yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
447
425
  prev = childNode;
448
426
  }
449
- yield* generateExpectErrorComment();
450
427
  yield* generateExtraAutoImport();
451
428
  yield _ts('}\n');
452
- yield* generateTsFormat(source.content, source.loc.start.offset, formatBrackets.normal);
453
429
  }
454
430
  for (const varName of forBlockVars) {
455
431
  localVars.set(varName, localVars.get(varName) - 1);
@@ -595,12 +571,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
595
571
  for (const failedExp of propsFailedExps) {
596
572
  yield* generateInterpolation(failedExp.loc.source, failedExp.loc, failedExp.loc.start.offset, presetInfos.all, '(', ')');
597
573
  yield _ts(';\n');
598
- const fb = formatBrackets.normal;
599
- if (fb) {
600
- yield* generateTsFormat(failedExp.loc.source, failedExp.loc.start.offset, fb);
601
- }
602
574
  }
603
- yield* generateInlineCss(props);
604
575
  const vScope = props.find(prop => prop.type === CompilerDOM.NodeTypes.DIRECTIVE && (prop.name === 'scope' || prop.name === 'data'));
605
576
  let inScope = false;
606
577
  let originalConditionsNum = blockConditions.length;
@@ -644,10 +615,10 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
644
615
  }
645
616
  const slotBlockVars = [];
646
617
  yield _ts(`{\n`);
618
+ yield* resetDirectiveComments('end of element slot start');
647
619
  let hasProps = false;
648
620
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
649
- yield* generateTsFormat(slotDir.exp.content, slotDir.exp.loc.start.offset, formatBrackets.params);
650
- const slotAst = createTsAst(slotDir, `(${slotDir.exp.content}) => {}`);
621
+ const slotAst = createTsAst(ts, slotDir, `(${slotDir.exp.content}) => {}`);
651
622
  (0, transform_1.collectVars)(ts, slotAst, slotAst, slotBlockVars);
652
623
  hasProps = true;
653
624
  if (slotDir.exp.content.indexOf(':') === -1) {
@@ -695,8 +666,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
695
666
  yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
696
667
  prev = childNode;
697
668
  }
698
- yield* generateExpectErrorComment();
699
- yield* generateExtraAutoImport();
700
669
  slotBlockVars.forEach(varName => {
701
670
  localVars.set(varName, localVars.get(varName) - 1);
702
671
  });
@@ -717,15 +686,16 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
717
686
  ]);
718
687
  yield _ts(`'/* empty slot name completion */]\n`);
719
688
  }
689
+ yield* generateExtraAutoImport();
720
690
  yield _ts(`}\n`);
721
691
  }
722
692
  else {
693
+ yield* resetDirectiveComments('end of element children start');
723
694
  let prev;
724
695
  for (const childNode of node.children) {
725
696
  yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
726
697
  prev = childNode;
727
698
  }
728
- yield* generateExpectErrorComment();
729
699
  // fix https://github.com/vuejs/language-tools/issues/932
730
700
  if (!hasSlotElements.has(node) && node.children.length) {
731
701
  yield _ts(`(${componentCtxVar}.slots!).`);
@@ -813,35 +783,17 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
813
783
  // https://github.com/johnsoncodehk/vue-tsc/issues/67
814
784
  yield* generateInterpolation(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, presetInfos.all, '$event => {(', ')}');
815
785
  yield _ts(';\n');
816
- yield* generateTsFormat(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal);
817
786
  }
818
787
  }
819
788
  }
820
789
  function* appendExpressionNode(prop) {
821
790
  if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
822
- const ast = createTsAst(prop.exp, prop.exp.content);
823
- let isCompoundExpression = true;
824
- if (ast.statements.length === 1) {
825
- ts.forEachChild(ast, child_1 => {
826
- if (ts.isExpressionStatement(child_1)) {
827
- ts.forEachChild(child_1, child_2 => {
828
- if (ts.isArrowFunction(child_2)) {
829
- isCompoundExpression = false;
830
- }
831
- else if (ts.isIdentifier(child_2)) {
832
- isCompoundExpression = false;
833
- }
834
- });
835
- }
836
- else if (ts.isFunctionDeclaration(child_1)) {
837
- isCompoundExpression = false;
838
- }
839
- });
840
- }
841
791
  let prefix = '(';
842
792
  let suffix = ')';
843
793
  let isFirstMapping = true;
844
- if (isCompoundExpression) {
794
+ const ast = createTsAst(ts, prop.exp, prop.exp.content);
795
+ const _isCompoundExpression = isCompoundExpression(ts, ast);
796
+ if (_isCompoundExpression) {
845
797
  yield _ts('$event => {\n');
846
798
  localVars.set('$event', (localVars.get('$event') ?? 0) + 1);
847
799
  prefix = '';
@@ -851,19 +803,18 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
851
803
  }
852
804
  }
853
805
  yield* generateInterpolation(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, () => {
854
- if (isCompoundExpression && isFirstMapping) {
806
+ if (_isCompoundExpression && isFirstMapping) {
855
807
  isFirstMapping = false;
856
808
  return presetInfos.allWithHiddenParam;
857
809
  }
858
810
  return presetInfos.all;
859
811
  }, prefix, suffix);
860
- if (isCompoundExpression) {
812
+ if (_isCompoundExpression) {
861
813
  localVars.set('$event', localVars.get('$event') - 1);
862
814
  yield _ts(';\n');
863
815
  yield* generateExtraAutoImport();
864
816
  yield _ts('}\n');
865
817
  }
866
- yield* generateTsFormat(prop.exp.content, prop.exp.loc.start.offset, isCompoundExpression ? formatBrackets.event : formatBrackets.normal);
867
818
  }
868
819
  else {
869
820
  yield _ts(`() => {}`);
@@ -942,9 +893,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
942
893
  const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset; // vue 3.4+
943
894
  if (!isShorthand) {
944
895
  yield* generateInterpolation(prop.exp.loc.source, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')');
945
- if (mode === 'normal') {
946
- yield* generateTsFormat(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.normal);
947
- }
948
896
  }
949
897
  else {
950
898
  const propVariableName = (0, shared_1.camelize)(prop.exp.loc.source);
@@ -1033,9 +981,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1033
981
  yield* generateInterpolation(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')');
1034
982
  yield _ts(['', 'template', prop.exp.loc.end.offset, presetInfos.diagnosticOnly]);
1035
983
  yield _ts(', ');
1036
- if (mode === 'normal') {
1037
- yield* generateTsFormat(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal);
1038
- }
1039
984
  }
1040
985
  else {
1041
986
  // comment this line to avoid affecting comments in prop expressions
@@ -1043,32 +988,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1043
988
  }
1044
989
  }
1045
990
  }
1046
- function* generateInlineCss(props) {
1047
- for (const prop of props) {
1048
- if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
1049
- && prop.name === 'bind'
1050
- && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
1051
- && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
1052
- && prop.arg.content === 'style'
1053
- && prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
1054
- const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
1055
- const start = prop.arg.loc.source.indexOf(endCrt) + 1;
1056
- const end = prop.arg.loc.source.lastIndexOf(endCrt);
1057
- const content = prop.arg.loc.source.substring(start, end);
1058
- yield _inlineCss(`x { `);
1059
- yield _inlineCss([
1060
- content,
1061
- 'template',
1062
- prop.arg.loc.start.offset + start,
1063
- (0, utils_1.enableAllFeatures)({
1064
- format: false,
1065
- structure: false,
1066
- }),
1067
- ]);
1068
- yield _inlineCss(` }\n`);
1069
- }
1070
- }
1071
- }
1072
991
  function* generateDirectives(node) {
1073
992
  for (const prop of node.props) {
1074
993
  if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
@@ -1081,7 +1000,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1081
1000
  if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
1082
1001
  yield* generateInterpolation(prop.arg.content, prop.arg.loc, prop.arg.loc.start.offset + prop.arg.loc.source.indexOf(prop.arg.content), presetInfos.all, '(', ')');
1083
1002
  yield _ts(';\n');
1084
- yield* generateTsFormat(prop.arg.content, prop.arg.loc.start.offset, formatBrackets.normal);
1085
1003
  }
1086
1004
  yield _ts(['', 'template', prop.loc.start.offset, presetInfos.diagnosticOnly]);
1087
1005
  yield _ts(`__VLS_directiveFunction(__VLS_ctx.`);
@@ -1101,7 +1019,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1101
1019
  yield _ts(['', 'template', prop.exp.loc.start.offset, presetInfos.diagnosticOnly]);
1102
1020
  yield* generateInterpolation(prop.exp.content, prop.exp.loc, prop.exp.loc.start.offset, presetInfos.all, '(', ')');
1103
1021
  yield _ts(['', 'template', prop.exp.loc.end.offset, presetInfos.diagnosticOnly]);
1104
- yield* generateTsFormat(prop.exp.content, prop.exp.loc.start.offset, formatBrackets.normal);
1105
1022
  }
1106
1023
  else {
1107
1024
  yield _ts('undefined');
@@ -1277,8 +1194,13 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1277
1194
  }
1278
1195
  yield _ts('// @ts-ignore\n'); // #2304
1279
1196
  yield _ts('[');
1197
+ const visited = new Set();
1280
1198
  for (const _vars of tempVars) {
1281
1199
  for (const v of _vars) {
1200
+ if (visited.has(v.offset)) {
1201
+ continue;
1202
+ }
1203
+ visited.add(v.offset);
1282
1204
  yield _ts([
1283
1205
  v.text,
1284
1206
  'template',
@@ -1332,20 +1254,6 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1332
1254
  offset += part.length + 1;
1333
1255
  }
1334
1256
  }
1335
- function* generateTsFormat(code, offset, formatWrapper) {
1336
- yield _tsFormat(formatWrapper[0]);
1337
- yield _tsFormat([
1338
- code,
1339
- 'template',
1340
- offset,
1341
- (0, utils_1.mergeFeatureSettings)(presetInfos.disabledAll, {
1342
- format: true,
1343
- // autoInserts: true, // TODO: support vue-autoinsert-parentheses
1344
- }),
1345
- ]);
1346
- yield _tsFormat(formatWrapper[1]);
1347
- yield _tsFormat('\n');
1348
- }
1349
1257
  function* generateObjectProperty(code, offset, info, astHolder, shouldCamelize = false) {
1350
1258
  if (code.startsWith('[') && code.endsWith(']') && astHolder) {
1351
1259
  yield* generateInterpolation(code, astHolder, offset, info, '', '');
@@ -1373,7 +1281,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1373
1281
  }
1374
1282
  function* generateInterpolation(_code, astHolder, start, data, prefix, suffix) {
1375
1283
  const code = prefix + _code + suffix;
1376
- const ast = createTsAst(astHolder, code);
1284
+ const ast = createTsAst(ts, astHolder, code);
1377
1285
  const vars = [];
1378
1286
  for (let [section, offset, onlyError] of (0, transform_1.eachInterpolationSegment)(ts, code, ast, localVars, accessedGlobalVariables, vueCompilerOptions, vars)) {
1379
1287
  if (offset === undefined) {
@@ -1445,15 +1353,74 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1445
1353
  yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1446
1354
  }
1447
1355
  }
1448
- function createTsAst(astHolder, text) {
1449
- if (astHolder.__volar_ast_text !== text) {
1450
- astHolder.__volar_ast_text = text;
1451
- astHolder.__volar_ast = ts.createSourceFile('/a.ts', text, 99);
1452
- }
1453
- return astHolder.__volar_ast;
1454
- }
1455
1356
  }
1456
1357
  exports.generate = generate;
1358
+ function createTsAst(ts, astHolder, text) {
1359
+ if (astHolder.__volar_ast_text !== text) {
1360
+ astHolder.__volar_ast_text = text;
1361
+ astHolder.__volar_ast = ts.createSourceFile('/a.ts', text, 99);
1362
+ }
1363
+ return astHolder.__volar_ast;
1364
+ }
1365
+ exports.createTsAst = createTsAst;
1366
+ function isCompoundExpression(ts, ast) {
1367
+ let result = true;
1368
+ if (ast.statements.length === 1) {
1369
+ ts.forEachChild(ast, child_1 => {
1370
+ if (ts.isExpressionStatement(child_1)) {
1371
+ ts.forEachChild(child_1, child_2 => {
1372
+ if (ts.isArrowFunction(child_2)) {
1373
+ result = false;
1374
+ }
1375
+ else if (ts.isIdentifier(child_2)) {
1376
+ result = false;
1377
+ }
1378
+ });
1379
+ }
1380
+ else if (ts.isFunctionDeclaration(child_1)) {
1381
+ result = false;
1382
+ }
1383
+ });
1384
+ }
1385
+ return result;
1386
+ }
1387
+ exports.isCompoundExpression = isCompoundExpression;
1388
+ function parseInterpolationNode(node, template) {
1389
+ let content = node.content.loc.source;
1390
+ let start = node.content.loc.start.offset;
1391
+ let leftCharacter;
1392
+ let rightCharacter;
1393
+ // fix https://github.com/vuejs/language-tools/issues/1787
1394
+ while ((leftCharacter = template.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
1395
+ start--;
1396
+ content = leftCharacter + content;
1397
+ }
1398
+ while ((rightCharacter = template.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
1399
+ content = content + rightCharacter;
1400
+ }
1401
+ return [
1402
+ content,
1403
+ start,
1404
+ ];
1405
+ }
1406
+ exports.parseInterpolationNode = parseInterpolationNode;
1407
+ function parseVForNode(node) {
1408
+ const { value, key, index } = node.parseResult;
1409
+ const leftExpressionRange = (value || key || index)
1410
+ ? {
1411
+ start: (value ?? key ?? index).loc.start.offset,
1412
+ end: (index ?? key ?? value).loc.end.offset,
1413
+ }
1414
+ : undefined;
1415
+ const leftExpressionText = leftExpressionRange
1416
+ ? node.loc.source.substring(leftExpressionRange.start - node.loc.start.offset, leftExpressionRange.end - node.loc.start.offset)
1417
+ : undefined;
1418
+ return {
1419
+ leftExpressionRange,
1420
+ leftExpressionText,
1421
+ };
1422
+ }
1423
+ exports.parseVForNode = parseVForNode;
1457
1424
  function getCanonicalComponentName(tagText) {
1458
1425
  return validTsVarReg.test(tagText)
1459
1426
  ? tagText
@@ -1467,21 +1434,21 @@ function getPossibleOriginalComponentNames(tagText) {
1467
1434
  tagText,
1468
1435
  ])];
1469
1436
  }
1470
- function* eachElementNode(node) {
1437
+ function* forEachElementNode(node) {
1471
1438
  if (node.type === CompilerDOM.NodeTypes.ROOT) {
1472
1439
  for (const child of node.children) {
1473
- yield* eachElementNode(child);
1440
+ yield* forEachElementNode(child);
1474
1441
  }
1475
1442
  }
1476
1443
  else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
1477
1444
  const patchForNode = getVForNode(node);
1478
1445
  if (patchForNode) {
1479
- yield* eachElementNode(patchForNode);
1446
+ yield* forEachElementNode(patchForNode);
1480
1447
  }
1481
1448
  else {
1482
1449
  yield node;
1483
1450
  for (const child of node.children) {
1484
- yield* eachElementNode(child);
1451
+ yield* forEachElementNode(child);
1485
1452
  }
1486
1453
  }
1487
1454
  }
@@ -1490,18 +1457,18 @@ function* eachElementNode(node) {
1490
1457
  for (let i = 0; i < node.branches.length; i++) {
1491
1458
  const branch = node.branches[i];
1492
1459
  for (const childNode of branch.children) {
1493
- yield* eachElementNode(childNode);
1460
+ yield* forEachElementNode(childNode);
1494
1461
  }
1495
1462
  }
1496
1463
  }
1497
1464
  else if (node.type === CompilerDOM.NodeTypes.FOR) {
1498
1465
  // v-for
1499
1466
  for (const child of node.children) {
1500
- yield* eachElementNode(child);
1467
+ yield* forEachElementNode(child);
1501
1468
  }
1502
1469
  }
1503
1470
  }
1504
- exports.eachElementNode = eachElementNode;
1471
+ exports.forEachElementNode = forEachElementNode;
1505
1472
  function needToUnicode(str) {
1506
1473
  return str.indexOf('\\') >= 0 || str.indexOf('\n') >= 0;
1507
1474
  }
@@ -1,5 +1,4 @@
1
- import type { Code, CodeAndStack, VueCodeInformation } from '../types';
2
- export declare function withStack(code: Code): CodeAndStack;
1
+ import type { VueCodeInformation } from '../types';
3
2
  export declare function getStack(): string;
4
3
  export declare function disableAllFeatures(override: Partial<VueCodeInformation>): VueCodeInformation;
5
4
  export declare function enableAllFeatures(override: Partial<VueCodeInformation>): VueCodeInformation;
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeFeatureSettings = exports.enableAllFeatures = exports.disableAllFeatures = exports.getStack = exports.withStack = void 0;
4
- function withStack(code) {
5
- return [code, getStack()];
6
- }
7
- exports.withStack = withStack;
3
+ exports.mergeFeatureSettings = exports.enableAllFeatures = exports.disableAllFeatures = exports.getStack = void 0;
8
4
  // TODO: import from muggle-string
9
5
  function getStack() {
10
6
  const stack = new Error().stack;
@@ -1,5 +1,10 @@
1
1
  import { type LanguagePlugin } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
- import type { VueCompilerOptions } from './types';
3
+ import type { VueCompilerOptions, VueLanguagePlugin } from './types';
4
4
  import { VueGeneratedCode } from './virtualFile/vueFile';
5
- export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, isValidGlobalTypesHolder: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack?: boolean): LanguagePlugin<VueGeneratedCode>;
5
+ interface _Plugin extends LanguagePlugin<VueGeneratedCode> {
6
+ getCanonicalFileName: (fileName: string) => string;
7
+ pluginContext: Parameters<VueLanguagePlugin>[0];
8
+ }
9
+ export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack?: boolean): _Plugin;
10
+ export {};