@vue/language-core 2.2.8 → 3.0.0-alpha.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 (47) hide show
  1. package/index.d.ts +1 -2
  2. package/index.js +1 -1
  3. package/lib/codegen/globalTypes.js +3 -9
  4. package/lib/codegen/script/component.js +21 -9
  5. package/lib/codegen/script/index.d.ts +0 -1
  6. package/lib/codegen/script/index.js +1 -4
  7. package/lib/codegen/script/scriptSetup.js +1 -10
  8. package/lib/codegen/script/src.js +1 -20
  9. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  10. package/lib/codegen/script/styleModulesType.js +2 -2
  11. package/lib/codegen/script/template.js +4 -1
  12. package/lib/codegen/template/context.d.ts +26 -17
  13. package/lib/codegen/template/context.js +89 -53
  14. package/lib/codegen/template/element.d.ts +2 -2
  15. package/lib/codegen/template/element.js +24 -57
  16. package/lib/codegen/template/elementChildren.d.ts +1 -1
  17. package/lib/codegen/template/elementChildren.js +4 -6
  18. package/lib/codegen/template/elementDirectives.js +1 -11
  19. package/lib/codegen/template/elementEvents.d.ts +1 -0
  20. package/lib/codegen/template/elementEvents.js +39 -17
  21. package/lib/codegen/template/elementProps.js +4 -8
  22. package/lib/codegen/template/index.d.ts +0 -1
  23. package/lib/codegen/template/index.js +22 -10
  24. package/lib/codegen/template/interpolation.d.ts +1 -1
  25. package/lib/codegen/template/interpolation.js +53 -53
  26. package/lib/codegen/template/slotOutlet.js +1 -2
  27. package/lib/codegen/template/styleScopedClasses.js +2 -2
  28. package/lib/codegen/template/templateChild.d.ts +1 -1
  29. package/lib/codegen/template/templateChild.js +12 -46
  30. package/lib/codegen/template/vFor.js +5 -10
  31. package/lib/codegen/template/vIf.js +2 -10
  32. package/lib/codegen/template/vSlot.d.ts +1 -2
  33. package/lib/codegen/template/vSlot.js +84 -62
  34. package/lib/codegen/utils/index.js +2 -2
  35. package/lib/parsers/scriptRanges.js +7 -3
  36. package/lib/parsers/scriptSetupRanges.d.ts +0 -3
  37. package/lib/parsers/scriptSetupRanges.js +18 -28
  38. package/lib/plugins/vue-tsx.d.ts +24 -15
  39. package/lib/plugins/vue-tsx.js +31 -23
  40. package/lib/types.d.ts +2 -2
  41. package/lib/utils/forEachElementNode.d.ts +1 -0
  42. package/lib/utils/forEachElementNode.js +3 -0
  43. package/lib/utils/shared.d.ts +5 -1
  44. package/lib/utils/shared.js +16 -4
  45. package/lib/utils/ts.d.ts +0 -4
  46. package/lib/utils/ts.js +1 -10
  47. package/package.json +2 -2
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStyleScopedClassReferences = generateStyleScopedClassReferences;
4
4
  exports.collectStyleScopedClassReferences = collectStyleScopedClassReferences;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
- const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
6
+ const shared_1 = require("../../utils/shared");
7
7
  const utils_1 = require("../utils");
8
8
  const escaped_1 = require("../utils/escaped");
9
9
  const wrapWith_1 = require("../utils/wrapWith");
@@ -126,7 +126,7 @@ function collectStyleScopedClassReferences(options, ctx, node) {
126
126
  }
127
127
  }
128
128
  function walkIdentifier(node) {
129
- const text = (0, scriptSetupRanges_1.getNodeText)(ts, node, ast);
129
+ const text = (0, shared_1.getNodeText)(ts, node, ast);
130
130
  ctx.scopedClasses.push({
131
131
  source: 'template',
132
132
  className: text,
@@ -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, prevNode: CompilerDOM.TemplateChildNode | undefined, isVForChild?: boolean): Generator<Code>;
5
+ export declare function generateTemplateChild(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode, enterNode?: 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];
@@ -7,12 +7,12 @@ const CompilerDOM = require("@vue/compiler-dom");
7
7
  const shared_1 = require("../../utils/shared");
8
8
  const utils_1 = require("../utils");
9
9
  const element_1 = require("./element");
10
+ const elementChildren_1 = require("./elementChildren");
10
11
  const interpolation_1 = require("./interpolation");
11
12
  const slotOutlet_1 = require("./slotOutlet");
12
13
  const vFor_1 = require("./vFor");
13
14
  const vIf_1 = require("./vIf");
14
15
  const vSlot_1 = require("./vSlot");
15
- const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)-->$/;
16
16
  // @ts-ignore
17
17
  const transformContext = {
18
18
  onError: () => { },
@@ -28,36 +28,9 @@ const transformContext = {
28
28
  },
29
29
  expressionPlugins: ['typescript'],
30
30
  };
31
- function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = false) {
32
- if (prevNode?.type === CompilerDOM.NodeTypes.COMMENT) {
33
- const match = prevNode.loc.source.match(commentDirectiveRegex);
34
- if (match) {
35
- const { name, content } = match.groups;
36
- switch (name) {
37
- case 'skip': {
38
- yield `// @vue-skip${utils_1.newLine}`;
39
- return;
40
- }
41
- case 'ignore': {
42
- yield* ctx.ignoreError();
43
- break;
44
- }
45
- case 'expect-error': {
46
- yield* ctx.expectError(prevNode);
47
- break;
48
- }
49
- case 'generic': {
50
- const text = content.trim();
51
- if (text.startsWith('{') && text.endsWith('}')) {
52
- ctx.lastGenericComment = {
53
- content: text.slice(1, -1),
54
- offset: prevNode.loc.start.offset + prevNode.loc.source.indexOf('{') + 1,
55
- };
56
- }
57
- break;
58
- }
59
- }
60
- }
31
+ function* generateTemplateChild(options, ctx, node, enterNode = true) {
32
+ if (enterNode && !ctx.enter(node)) {
33
+ return;
61
34
  }
62
35
  const cur = node;
63
36
  if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
@@ -67,12 +40,7 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
67
40
  for (const item of collectSingleRootNodes(options, node.children)) {
68
41
  ctx.singleRootNodes.add(item);
69
42
  }
70
- let prev;
71
- for (const childNode of node.children) {
72
- yield* generateTemplateChild(options, ctx, childNode, prev);
73
- prev = childNode;
74
- }
75
- yield* ctx.resetDirectiveComments('end of root');
43
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
76
44
  }
77
45
  else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
78
46
  const vForNode = getVForNode(node);
@@ -95,32 +63,27 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
95
63
  }
96
64
  else if (node.tagType === CompilerDOM.ElementTypes.ELEMENT
97
65
  || node.tagType === CompilerDOM.ElementTypes.TEMPLATE) {
98
- yield* (0, element_1.generateElement)(options, ctx, node, isVForChild);
66
+ yield* (0, element_1.generateElement)(options, ctx, node);
99
67
  }
100
68
  else {
101
69
  const { currentComponent } = ctx;
102
- yield* (0, element_1.generateComponent)(options, ctx, node, isVForChild);
70
+ yield* (0, element_1.generateComponent)(options, ctx, node);
103
71
  ctx.currentComponent = currentComponent;
104
72
  }
105
73
  }
106
74
  }
107
75
  else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
108
76
  // {{ var }}
109
- yield* generateTemplateChild(options, ctx, node.content, undefined);
77
+ yield* generateTemplateChild(options, ctx, node.content, false);
110
78
  }
111
79
  else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
112
80
  // {{ ... }} {{ ... }}
113
- for (const childNode of node.children) {
114
- if (typeof childNode === 'object') {
115
- yield* generateTemplateChild(options, ctx, childNode, undefined);
116
- }
117
- }
81
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children.filter(child => typeof child === 'object'), false);
118
82
  }
119
83
  else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
120
84
  // {{ ... }}
121
85
  const [content, start] = parseInterpolationNode(node, options.template.content);
122
86
  yield* (0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, content, start, node.content.loc, `(`, `)${utils_1.endOfLine}`);
123
- yield* ctx.resetDirectiveComments('end of INTERPOLATION');
124
87
  }
125
88
  else if (node.type === CompilerDOM.NodeTypes.IF) {
126
89
  // v-if / v-else-if / v-else
@@ -133,6 +96,9 @@ function* generateTemplateChild(options, ctx, node, prevNode, isVForChild = fals
133
96
  else if (node.type === CompilerDOM.NodeTypes.TEXT) {
134
97
  // not needed progress
135
98
  }
99
+ if (enterNode) {
100
+ yield* ctx.exit();
101
+ }
136
102
  }
137
103
  function* collectSingleRootNodes(options, children) {
138
104
  if (children.length !== 1) {
@@ -4,8 +4,8 @@ exports.generateVFor = generateVFor;
4
4
  exports.parseVForNode = parseVForNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
6
  const utils_1 = require("../utils");
7
+ const elementChildren_1 = require("./elementChildren");
7
8
  const interpolation_1 = require("./interpolation");
8
- const templateChild_1 = require("./templateChild");
9
9
  function* generateVFor(options, ctx, node) {
10
10
  const { source } = node.parseResult;
11
11
  const { leftExpressionRange, leftExpressionText } = parseVForNode(node);
@@ -52,18 +52,13 @@ function* generateVFor(options, ctx, node) {
52
52
  }
53
53
  }
54
54
  }
55
- if (isFragment) {
56
- yield* ctx.resetDirectiveComments('end of v-for start');
57
- }
58
- let prev;
59
- for (const childNode of node.children) {
60
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev, true);
61
- prev = childNode;
62
- }
55
+ const { inVFor } = ctx;
56
+ ctx.inVFor = true;
57
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children, isFragment);
58
+ ctx.inVFor = inVFor;
63
59
  for (const varName of forBlockVars) {
64
60
  ctx.removeLocalVariable(varName);
65
61
  }
66
- yield* ctx.generateAutoImportCompletion();
67
62
  yield `}${utils_1.newLine}`;
68
63
  }
69
64
  function parseVForNode(node) {
@@ -4,8 +4,8 @@ exports.generateVIf = generateVIf;
4
4
  const CompilerDOM = require("@vue/compiler-dom");
5
5
  const muggle_string_1 = require("muggle-string");
6
6
  const utils_1 = require("../utils");
7
+ const elementChildren_1 = require("./elementChildren");
7
8
  const interpolation_1 = require("./interpolation");
8
- const templateChild_1 = require("./templateChild");
9
9
  function* generateVIf(options, ctx, node) {
10
10
  const originalBlockConditionsLength = ctx.blockConditions.length;
11
11
  for (let i = 0; i < node.branches.length; i++) {
@@ -28,15 +28,7 @@ function* generateVIf(options, ctx, node) {
28
28
  yield ` `;
29
29
  }
30
30
  yield `{${utils_1.newLine}`;
31
- if (isFragment(node)) {
32
- yield* ctx.resetDirectiveComments('end of v-if start');
33
- }
34
- let prev;
35
- for (const childNode of branch.children) {
36
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
37
- prev = childNode;
38
- }
39
- yield* ctx.generateAutoImportCompletion();
31
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, branch.children, isFragment(node));
40
32
  yield `}${utils_1.newLine}`;
41
33
  if (addedBlockCondition) {
42
34
  ctx.blockConditions[ctx.blockConditions.length - 1] = `!${ctx.blockConditions[ctx.blockConditions.length - 1]}`;
@@ -2,5 +2,4 @@ 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 generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode): Generator<Code>;
6
- export declare function generateImplicitDefaultSlot(ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code, void, any>;
5
+ export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode | undefined): Generator<Code>;
@@ -1,93 +1,115 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVSlot = generateVSlot;
4
- exports.generateImplicitDefaultSlot = generateImplicitDefaultSlot;
5
4
  const CompilerDOM = require("@vue/compiler-dom");
5
+ const shared_1 = require("../../utils/shared");
6
6
  const utils_1 = require("../utils");
7
7
  const wrapWith_1 = require("../utils/wrapWith");
8
+ const elementChildren_1 = require("./elementChildren");
8
9
  const objectProperty_1 = require("./objectProperty");
9
- const templateChild_1 = require("./templateChild");
10
10
  function* generateVSlot(options, ctx, node, slotDir) {
11
11
  if (!ctx.currentComponent) {
12
12
  return;
13
13
  }
14
- ctx.currentComponent.used = true;
15
14
  const slotBlockVars = [];
16
- yield `{${utils_1.newLine}`;
17
- yield `const { `;
18
- if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
19
- 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);
15
+ const slotVar = ctx.getInternalVariable();
16
+ if (slotDir) {
17
+ yield `{${utils_1.newLine}`;
20
18
  }
21
- else {
22
- yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
19
+ if (slotDir || node.children.length) {
20
+ ctx.currentComponent.used = true;
21
+ yield `const { `;
22
+ if (slotDir) {
23
+ if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
24
+ 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);
25
+ }
26
+ else {
27
+ yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
28
+ }
29
+ }
30
+ else {
31
+ yield* (0, wrapWith_1.wrapWith)(node.children[0].loc.start.offset, node.children.at(-1).loc.end.offset, ctx.codeFeatures.navigation, `default`);
32
+ }
33
+ yield `: ${slotVar} } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
23
34
  }
24
- yield `: __VLS_thisSlot } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
25
- if (slotDir.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
35
+ if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
26
36
  const slotAst = (0, utils_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
27
37
  (0, utils_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
28
- if (!slotDir.exp.content.includes(':')) {
29
- yield `const [`;
30
- yield [
31
- slotDir.exp.content,
32
- 'template',
33
- slotDir.exp.loc.start.offset,
34
- ctx.codeFeatures.all,
35
- ];
36
- yield `] = __VLS_getSlotParams(__VLS_thisSlot)${utils_1.endOfLine}`;
38
+ yield* generateSlotParameters(options, ctx, slotAst, slotDir.exp, slotVar);
39
+ }
40
+ for (const varName of slotBlockVars) {
41
+ ctx.addLocalVariable(varName);
42
+ }
43
+ yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node.children);
44
+ for (const varName of slotBlockVars) {
45
+ ctx.removeLocalVariable(varName);
46
+ }
47
+ if (slotDir) {
48
+ let isStatic = true;
49
+ if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
50
+ isStatic = slotDir.arg.isStatic;
37
51
  }
38
- else {
39
- yield `const `;
52
+ if (isStatic && !slotDir.arg) {
53
+ yield `${ctx.currentComponent.ctxVar}.slots!['`;
40
54
  yield [
41
- slotDir.exp.content,
55
+ '',
42
56
  'template',
43
- slotDir.exp.loc.start.offset,
44
- ctx.codeFeatures.all,
57
+ slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
58
+ ? '#'.length
59
+ : slotDir.loc.source.startsWith('v-slot:')
60
+ ? 'v-slot:'.length
61
+ : 0),
62
+ ctx.codeFeatures.completion,
45
63
  ];
46
- yield ` = __VLS_getSlotParam(__VLS_thisSlot)${utils_1.endOfLine}`;
64
+ yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
47
65
  }
66
+ yield `}${utils_1.newLine}`;
48
67
  }
49
- for (const varName of slotBlockVars) {
50
- ctx.addLocalVariable(varName);
68
+ }
69
+ function* generateSlotParameters(options, ctx, ast, exp, slotVar) {
70
+ const { ts } = options;
71
+ const statement = ast.statements[0];
72
+ if (!ts.isExpressionStatement(statement) || !ts.isArrowFunction(statement.expression)) {
73
+ return;
51
74
  }
52
- yield* ctx.resetDirectiveComments('end of slot children start');
53
- let prev;
54
- for (const childNode of node.children) {
55
- yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, prev);
56
- prev = childNode;
75
+ const { expression } = statement;
76
+ const startOffset = exp.loc.start.offset - 1;
77
+ const modifies = [];
78
+ const types = [];
79
+ for (const { name, type } of expression.parameters) {
80
+ if (type) {
81
+ modifies.push([
82
+ [``],
83
+ name.end,
84
+ type.end,
85
+ ]);
86
+ types.push(chunk((0, shared_1.getStartEnd)(ts, type, ast).start, type.end));
87
+ }
88
+ else {
89
+ types.push(null);
90
+ }
57
91
  }
58
- for (const varName of slotBlockVars) {
59
- ctx.removeLocalVariable(varName);
92
+ yield `const [`;
93
+ let nextStart = 1;
94
+ for (const [codes, start, end] of modifies) {
95
+ yield chunk(nextStart, start);
96
+ yield* codes;
97
+ nextStart = end;
60
98
  }
61
- let isStatic = true;
62
- if (slotDir.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
63
- isStatic = slotDir.arg.isStatic;
99
+ yield chunk(nextStart, expression.equalsGreaterThanToken.pos - 1);
100
+ yield `] = __VLS_getSlotParameters(${slotVar}`;
101
+ if (types.some(t => t)) {
102
+ yield `, `;
103
+ yield* (0, wrapWith_1.wrapWith)(exp.loc.start.offset, exp.loc.end.offset, ctx.codeFeatures.verification, `(`, ...types.flatMap(type => type ? [`_: `, type, `, `] : `_, `), `) => [] as any`);
64
104
  }
65
- if (isStatic && !slotDir.arg) {
66
- yield `${ctx.currentComponent.ctxVar}.slots!['`;
67
- yield [
68
- '',
105
+ yield `)${utils_1.endOfLine}`;
106
+ function chunk(start, end) {
107
+ return [
108
+ ast.text.slice(start, end),
69
109
  'template',
70
- slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
71
- ? '#'.length
72
- : slotDir.loc.source.startsWith('v-slot:')
73
- ? 'v-slot:'.length
74
- : 0),
75
- ctx.codeFeatures.completion,
110
+ startOffset + start,
111
+ ctx.codeFeatures.all,
76
112
  ];
77
- yield `'/* empty slot name completion */]${utils_1.endOfLine}`;
78
- }
79
- yield* ctx.generateAutoImportCompletion();
80
- yield `}${utils_1.newLine}`;
81
- }
82
- function* generateImplicitDefaultSlot(ctx, node) {
83
- if (!ctx.currentComponent) {
84
- return;
85
- }
86
- if (node.children.length) {
87
- ctx.currentComponent.used = true;
88
- yield `${ctx.currentComponent.ctxVar}.slots!.`;
89
- yield* (0, wrapWith_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
90
- yield utils_1.endOfLine;
91
113
  }
92
114
  }
93
115
  //# sourceMappingURL=vSlot.js.map
@@ -7,7 +7,7 @@ exports.normalizeAttributeValue = normalizeAttributeValue;
7
7
  exports.createTsAst = createTsAst;
8
8
  exports.generateSfcBlockSection = generateSfcBlockSection;
9
9
  exports.generateSfcBlockAttrValue = generateSfcBlockAttrValue;
10
- const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
10
+ const shared_1 = require("../../utils/shared");
11
11
  exports.newLine = `\n`;
12
12
  exports.endOfLine = `;${exports.newLine}`;
13
13
  exports.combineLastMapping = { __combineOffset: 1 };
@@ -15,7 +15,7 @@ exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
15
15
  function collectVars(ts, node, ast, results = []) {
16
16
  const identifiers = collectIdentifiers(ts, node, []);
17
17
  for (const { id } of identifiers) {
18
- results.push((0, scriptSetupRanges_1.getNodeText)(ts, id, ast));
18
+ results.push((0, shared_1.getNodeText)(ts, id, ast));
19
19
  }
20
20
  return results;
21
21
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptRanges = parseScriptRanges;
4
+ const shared_1 = require("../utils/shared");
4
5
  const scriptSetupRanges_1 = require("./scriptSetupRanges");
5
6
  function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
6
7
  let exportDefault;
@@ -29,7 +30,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
29
30
  let inheritAttrsOption;
30
31
  ts.forEachChild(obj, node => {
31
32
  if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
32
- const name = (0, scriptSetupRanges_1.getNodeText)(ts, node.name, ast);
33
+ const name = _getNodeText(node.name);
33
34
  if (name === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
34
35
  componentsOptionNode = node.initializer;
35
36
  }
@@ -40,7 +41,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
40
41
  nameOptionNode = node.initializer;
41
42
  }
42
43
  else if (name === 'inheritAttrs') {
43
- inheritAttrsOption = (0, scriptSetupRanges_1.getNodeText)(ts, node.initializer, ast);
44
+ inheritAttrsOption = _getNodeText(node.initializer);
44
45
  }
45
46
  }
46
47
  });
@@ -69,7 +70,10 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
69
70
  bindings,
70
71
  };
71
72
  function _getStartEnd(node) {
72
- return (0, scriptSetupRanges_1.getStartEnd)(ts, node, ast);
73
+ return (0, shared_1.getStartEnd)(ts, node, ast);
74
+ }
75
+ function _getNodeText(node) {
76
+ return (0, shared_1.getNodeText)(ts, node, ast);
73
77
  }
74
78
  // isAsExpression is missing in tsc
75
79
  function isAsExpression(node) {
@@ -73,7 +73,4 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
73
73
  isDefaultImport?: boolean;
74
74
  isNamespace?: boolean;
75
75
  }[];
76
- export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
77
- export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
78
- export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
79
76
  export {};
@@ -2,10 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
4
  exports.parseBindingRanges = parseBindingRanges;
5
- exports.findBindingVars = findBindingVars;
6
- exports.getStartEnd = getStartEnd;
7
- exports.getNodeText = getNodeText;
8
5
  const utils_1 = require("../codegen/utils");
6
+ const shared_1 = require("../utils/shared");
9
7
  const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
10
8
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
11
9
  const defineProp = [];
@@ -42,7 +40,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
42
40
  importSectionEndOffset = commentRange.pos;
43
41
  }
44
42
  else {
45
- importSectionEndOffset = getStartEnd(ts, node, ast).start;
43
+ importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, ast).start;
46
44
  }
47
45
  foundNonImportExportNode = true;
48
46
  }
@@ -161,7 +159,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
161
159
  defaultValue,
162
160
  required,
163
161
  isModel: isDefineModel,
164
- comments: getCommentsRange(ts, node, parents, ast),
162
+ comments: getClosestMultiLineCommentRange(ts, node, parents, ast),
165
163
  argNode: options,
166
164
  });
167
165
  }
@@ -282,10 +280,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
282
280
  };
283
281
  }
284
282
  function _getStartEnd(node) {
285
- return getStartEnd(ts, node, ast);
283
+ return (0, shared_1.getStartEnd)(ts, node, ast);
286
284
  }
287
285
  function _getNodeText(node) {
288
- return getNodeText(ts, node, ast);
286
+ return (0, shared_1.getNodeText)(ts, node, ast);
289
287
  }
290
288
  }
291
289
  function parseBindingRanges(ts, ast) {
@@ -353,10 +351,10 @@ function parseBindingRanges(ts, ast) {
353
351
  });
354
352
  return bindings;
355
353
  function _getStartEnd(node) {
356
- return getStartEnd(ts, node, ast);
354
+ return (0, shared_1.getStartEnd)(ts, node, ast);
357
355
  }
358
356
  function _getNodeText(node) {
359
- return getNodeText(ts, node, ast);
357
+ return (0, shared_1.getNodeText)(ts, node, ast);
360
358
  }
361
359
  function _findBindingVars(left) {
362
360
  return findBindingVars(ts, left, ast);
@@ -368,7 +366,7 @@ function findBindingVars(ts, left, ast) {
368
366
  return vars;
369
367
  function worker(node) {
370
368
  if (ts.isIdentifier(node)) {
371
- vars.push(getStartEnd(ts, node, ast));
369
+ vars.push((0, shared_1.getStartEnd)(ts, node, ast));
372
370
  }
373
371
  // { ? } = ...
374
372
  // [ ? ] = ...
@@ -385,7 +383,7 @@ function findBindingVars(ts, left, ast) {
385
383
  }
386
384
  // { foo } = ...
387
385
  else if (ts.isShorthandPropertyAssignment(node)) {
388
- vars.push(getStartEnd(ts, node.name, ast));
386
+ vars.push((0, shared_1.getStartEnd)(ts, node.name, ast));
389
387
  }
390
388
  // { ...? } = ...
391
389
  // [ ...? ] = ...
@@ -394,23 +392,13 @@ function findBindingVars(ts, left, ast) {
394
392
  }
395
393
  }
396
394
  }
397
- function getStartEnd(ts, node, ast) {
398
- return {
399
- start: ts.getTokenPosOfNode(node, ast),
400
- end: node.end,
401
- };
402
- }
403
- function getNodeText(ts, node, ast) {
404
- const { start, end } = getStartEnd(ts, node, ast);
405
- return ast.text.slice(start, end);
406
- }
407
395
  function getStatementRange(ts, parents, node, ast) {
408
396
  let statementRange;
409
397
  for (let i = parents.length - 1; i >= 0; i--) {
410
398
  if (ts.isStatement(parents[i])) {
411
399
  const statement = parents[i];
412
400
  ts.forEachChild(statement, child => {
413
- const range = getStartEnd(ts, child, ast);
401
+ const range = (0, shared_1.getStartEnd)(ts, child, ast);
414
402
  statementRange ??= range;
415
403
  statementRange.end = range.end;
416
404
  });
@@ -418,22 +406,24 @@ function getStatementRange(ts, parents, node, ast) {
418
406
  }
419
407
  }
420
408
  if (!statementRange) {
421
- statementRange = getStartEnd(ts, node, ast);
409
+ statementRange = (0, shared_1.getStartEnd)(ts, node, ast);
422
410
  }
423
411
  return statementRange;
424
412
  }
425
- function getCommentsRange(ts, node, parents, ast) {
413
+ function getClosestMultiLineCommentRange(ts, node, parents, ast) {
426
414
  for (let i = parents.length - 1; i >= 0; i--) {
427
415
  if (ts.isStatement(node)) {
428
416
  break;
429
417
  }
430
418
  node = parents[i];
431
419
  }
432
- const comments = ts.getLeadingCommentRanges(ast.text, node.pos);
433
- if (comments?.length) {
420
+ const comment = ts.getLeadingCommentRanges(ast.text, node.pos)
421
+ ?.reverse()
422
+ .find(range => range.kind === 3);
423
+ if (comment) {
434
424
  return {
435
- start: comments[0].pos,
436
- end: comments.at(-1).end,
425
+ start: comment.pos,
426
+ end: comment.end,
437
427
  };
438
428
  }
439
429
  }
@@ -138,6 +138,17 @@ export declare const tsCodegen: WeakMap<Sfc, {
138
138
  };
139
139
  getGeneratedTemplate: () => {
140
140
  codes: Code[];
141
+ currentInfo: {
142
+ ignoreError?: boolean;
143
+ expectError?: {
144
+ token: number;
145
+ node: import("@vue/compiler-dom").CommentNode;
146
+ };
147
+ generic?: {
148
+ content: string;
149
+ offset: number;
150
+ };
151
+ };
141
152
  codeFeatures: {
142
153
  all: import("../types").VueCodeInformation;
143
154
  none: import("../types").VueCodeInformation;
@@ -157,6 +168,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
157
168
  withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
158
169
  };
159
170
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
171
+ inVFor: boolean;
160
172
  slots: {
161
173
  name: string;
162
174
  offset?: number;
@@ -170,10 +182,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
170
182
  }[];
171
183
  dollarVars: Set<string>;
172
184
  accessExternalVariables: Map<string, Set<number>>;
173
- lastGenericComment: {
174
- content: string;
175
- offset: number;
176
- } | undefined;
177
185
  blockConditions: string[];
178
186
  scopedClasses: {
179
187
  source: string;
@@ -187,24 +195,25 @@ export declare const tsCodegen: WeakMap<Sfc, {
187
195
  templateRefs: Map<string, {
188
196
  typeExp: string;
189
197
  offset: number;
190
- }>;
198
+ }[]>;
191
199
  currentComponent: {
192
200
  ctxVar: string;
193
201
  used: boolean;
194
202
  } | undefined;
195
203
  singleRootElTypes: string[];
196
204
  singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
205
+ addTemplateRef(name: string, typeExp: string, offset: number): void;
197
206
  accessExternalVariable(name: string, offset?: number): void;
198
- hasLocalVariable: (name: string) => boolean;
199
- addLocalVariable: (name: string) => void;
200
- removeLocalVariable: (name: string) => void;
201
- getInternalVariable: () => string;
202
- getHoistVariable: (originalVar: string) => string;
203
- generateHoistVariables: () => Generator<string, void, unknown>;
204
- ignoreError: () => Generator<Code>;
205
- expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code>;
206
- resetDirectiveComments: (endStr: string) => Generator<Code>;
207
- generateAutoImportCompletion: () => Generator<Code>;
207
+ hasLocalVariable(name: string): boolean;
208
+ addLocalVariable(name: string): void;
209
+ removeLocalVariable(name: string): void;
210
+ getInternalVariable(): string;
211
+ getHoistVariable(originalVar: string): string;
212
+ generateHoistVariables(): Generator<string, void, unknown>;
213
+ generateConditionGuards(): Generator<string, void, unknown>;
214
+ generateAutoImportCompletion(): Generator<Code>;
215
+ enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
216
+ exit(): Generator<Code>;
208
217
  } | undefined;
209
218
  }>;
210
219
  declare const plugin: VueLanguagePlugin;