@vue/language-core 2.1.8 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/lib/codegen/globalTypes.js +12 -5
  2. package/lib/codegen/localTypes.js +3 -3
  3. package/lib/codegen/script/component.js +42 -42
  4. package/lib/codegen/script/componentSelf.js +14 -13
  5. package/lib/codegen/script/context.js +2 -2
  6. package/lib/codegen/script/index.d.ts +5 -3
  7. package/lib/codegen/script/index.js +24 -37
  8. package/lib/codegen/script/scriptSetup.js +240 -193
  9. package/lib/codegen/script/src.js +6 -6
  10. package/lib/codegen/script/styleModulesType.js +5 -5
  11. package/lib/codegen/script/template.d.ts +1 -1
  12. package/lib/codegen/script/template.js +89 -99
  13. package/lib/codegen/template/context.d.ts +13 -3
  14. package/lib/codegen/template/context.js +21 -12
  15. package/lib/codegen/template/element.d.ts +2 -4
  16. package/lib/codegen/template/element.js +132 -105
  17. package/lib/codegen/template/elementChildren.d.ts +1 -1
  18. package/lib/codegen/template/elementChildren.js +8 -8
  19. package/lib/codegen/template/elementDirectives.d.ts +1 -0
  20. package/lib/codegen/template/elementDirectives.js +28 -22
  21. package/lib/codegen/template/elementEvents.d.ts +2 -2
  22. package/lib/codegen/template/elementEvents.js +32 -65
  23. package/lib/codegen/template/elementProps.d.ts +3 -2
  24. package/lib/codegen/template/elementProps.js +119 -122
  25. package/lib/codegen/template/index.js +52 -60
  26. package/lib/codegen/template/interpolation.d.ts +5 -3
  27. package/lib/codegen/template/interpolation.js +18 -19
  28. package/lib/codegen/template/objectProperty.js +8 -8
  29. package/lib/codegen/template/propertyAccess.js +4 -4
  30. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  31. package/lib/codegen/template/slotOutlet.js +13 -13
  32. package/lib/codegen/template/styleScopedClasses.d.ts +1 -1
  33. package/lib/codegen/template/styleScopedClasses.js +11 -8
  34. package/lib/codegen/template/templateChild.d.ts +1 -1
  35. package/lib/codegen/template/templateChild.js +31 -19
  36. package/lib/codegen/template/vFor.d.ts +1 -1
  37. package/lib/codegen/template/vFor.js +11 -11
  38. package/lib/codegen/template/vIf.d.ts +1 -1
  39. package/lib/codegen/template/vIf.js +6 -6
  40. package/lib/codegen/{template → utils}/camelized.js +2 -2
  41. package/lib/codegen/{common.d.ts → utils/index.d.ts} +1 -2
  42. package/lib/codegen/{common.js → utils/index.js} +4 -15
  43. package/lib/codegen/{template → utils}/stringLiteralKey.js +3 -3
  44. package/lib/codegen/utils/unicode.d.ts +2 -0
  45. package/lib/codegen/utils/unicode.js +25 -0
  46. package/lib/languagePlugin.js +1 -1
  47. package/lib/parsers/scriptRanges.d.ts +7 -2
  48. package/lib/parsers/scriptSetupRanges.d.ts +67 -81
  49. package/lib/parsers/scriptSetupRanges.js +195 -166
  50. package/lib/parsers/vueCompilerOptions.d.ts +2 -0
  51. package/lib/parsers/vueCompilerOptions.js +23 -0
  52. package/lib/plugins/file-html.js +4 -3
  53. package/lib/plugins/file-md.js +1 -1
  54. package/lib/plugins/file-vue.js +4 -4
  55. package/lib/plugins/vue-root-tags.js +2 -2
  56. package/lib/plugins/vue-template-html.js +6 -2
  57. package/lib/plugins/vue-template-inline-css.js +1 -1
  58. package/lib/plugins/vue-template-inline-ts.js +13 -5
  59. package/lib/plugins/vue-tsx.d.ts +101 -72
  60. package/lib/plugins/vue-tsx.js +65 -69
  61. package/lib/types.d.ts +19 -10
  62. package/lib/utils/buildMappings.d.ts +1 -1
  63. package/lib/utils/parseSfc.d.ts +5 -0
  64. package/lib/utils/parseSfc.js +7 -2
  65. package/lib/utils/ts.d.ts +1 -1
  66. package/lib/utils/ts.js +38 -24
  67. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -2
  68. package/lib/virtualFile/computedSfc.js +23 -12
  69. package/lib/virtualFile/computedVueSfc.d.ts +1 -1
  70. package/lib/virtualFile/vueFile.d.ts +3 -3
  71. package/package.json +5 -5
  72. package/lib/codegen/types.d.ts +0 -9
  73. package/lib/codegen/types.js +0 -3
  74. package/lib/utils/findDestructuredProps.d.ts +0 -1
  75. package/lib/utils/findDestructuredProps.js +0 -3
  76. /package/lib/codegen/{template → utils}/camelized.d.ts +0 -0
  77. /package/lib/codegen/{template → utils}/stringLiteralKey.d.ts +0 -0
@@ -155,6 +155,10 @@ const plugin = ({ modules }) => {
155
155
  if (node.isStatic) {
156
156
  return false;
157
157
  }
158
+ else if (!node.loc.source) {
159
+ // :class="..." -> :class=""
160
+ return false;
161
+ }
158
162
  else {
159
163
  node.content = node.loc.source;
160
164
  }
@@ -168,9 +172,9 @@ const plugin = ({ modules }) => {
168
172
  delete loc.__endOffset;
169
173
  if (withinChangeRange(loc)) {
170
174
  loc.source =
171
- loc.source.substring(0, change.start - loc.start.offset)
175
+ loc.source.slice(0, change.start - loc.start.offset)
172
176
  + change.newText
173
- + loc.source.substring(change.end - loc.start.offset);
177
+ + loc.source.slice(change.end - loc.start.offset);
174
178
  loc.__endOffset = loc.end.offset;
175
179
  loc.end.offset += lengthDiff;
176
180
  return true;
@@ -39,7 +39,7 @@ function* generate(templateAst) {
39
39
  const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
40
40
  const start = prop.arg.loc.source.indexOf(endCrt) + 1;
41
41
  const end = prop.arg.loc.source.lastIndexOf(endCrt);
42
- const content = prop.arg.loc.source.substring(start, end);
42
+ const content = prop.arg.loc.source.slice(start, end);
43
43
  yield `x { `;
44
44
  yield [
45
45
  content,
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const common_1 = require("../codegen/common");
3
+ const CompilerDOM = require("@vue/compiler-dom");
4
4
  const elementEvents_1 = require("../codegen/template/elementEvents");
5
5
  const templateChild_1 = require("../codegen/template/templateChild");
6
6
  const vFor_1 = require("../codegen/template/vFor");
7
- const CompilerDOM = require("@vue/compiler-dom");
7
+ const utils_1 = require("../codegen/utils");
8
8
  const codeFeatures = {
9
9
  format: true,
10
10
  };
@@ -18,6 +18,7 @@ const formatBrackets = {
18
18
  // fix https://github.com/vuejs/language-tools/issues/2305
19
19
  curly: ['0 +', '+ 0;'],
20
20
  event: ['() => ', ';'],
21
+ generic: ['<', '>() => {};'],
21
22
  };
22
23
  const plugin = ctx => {
23
24
  const parseds = new WeakMap();
@@ -58,7 +59,14 @@ const plugin = ctx => {
58
59
  sfc.template.ast.children.forEach(visit);
59
60
  return data;
60
61
  function visit(node) {
61
- if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
62
+ if (node.type === CompilerDOM.NodeTypes.COMMENT) {
63
+ const match = node.loc.source.match(/^<!--\s*@vue-generic\b\s*\{(?<content>[^}]*)\}/);
64
+ if (match) {
65
+ const { content } = match.groups ?? {};
66
+ addFormatCodes(content, node.loc.start.offset + match[0].indexOf(content), formatBrackets.generic);
67
+ }
68
+ }
69
+ else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
62
70
  for (const prop of node.props) {
63
71
  if (prop.type !== CompilerDOM.NodeTypes.DIRECTIVE) {
64
72
  continue;
@@ -74,7 +82,7 @@ const plugin = ctx => {
74
82
  && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
75
83
  ) {
76
84
  if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
77
- const ast = (0, common_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
85
+ const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
78
86
  addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)
79
87
  ? formatBrackets.event
80
88
  : formatBrackets.normal);
@@ -105,7 +113,7 @@ const plugin = ctx => {
105
113
  if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
106
114
  const start = leftExpressionRange.start;
107
115
  const end = source.loc.start.offset + source.content.length;
108
- addFormatCodes(templateContent.substring(start, end), start, formatBrackets.for);
116
+ addFormatCodes(templateContent.slice(start, end), start, formatBrackets.for);
109
117
  }
110
118
  for (const child of node.children) {
111
119
  visit(child);
@@ -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").ISignal<{
4
+ scriptRanges: import("alien-signals").Computed<{
5
5
  exportDefault: (import("../types").TextRange & {
6
6
  expression: import("../types").TextRange;
7
7
  args: import("../types").TextRange;
@@ -13,88 +13,107 @@ export declare const tsCodegen: WeakMap<Sfc, {
13
13
  inheritAttrsOption: string | undefined;
14
14
  }) | undefined;
15
15
  classBlockEnd: number | undefined;
16
- bindings: import("../types").TextRange[];
16
+ bindings: {
17
+ range: import("../types").TextRange;
18
+ moduleName?: string;
19
+ isDefaultImport?: boolean;
20
+ isNamespace?: boolean;
21
+ }[];
17
22
  } | undefined>;
18
- scriptSetupRanges: import("alien-signals").ISignal<{
23
+ scriptSetupRanges: import("alien-signals").Computed<{
19
24
  leadingCommentEndOffset: number;
20
25
  importSectionEndOffset: number;
21
- bindings: import("../types").TextRange[];
22
- importComponentNames: Set<string>;
23
- props: {
26
+ bindings: {
27
+ range: import("../types").TextRange;
28
+ moduleName?: string;
29
+ isDefaultImport?: boolean;
30
+ isNamespace?: boolean;
31
+ }[];
32
+ defineProp: {
33
+ localName?: import("../types").TextRange;
34
+ name?: import("../types").TextRange;
35
+ type?: import("../types").TextRange;
36
+ modifierType?: import("../types").TextRange;
37
+ runtimeType?: import("../types").TextRange;
38
+ defaultValue?: import("../types").TextRange;
39
+ required?: boolean;
40
+ isModel?: boolean;
41
+ }[];
42
+ defineProps: ({
43
+ callExp: import("../types").TextRange;
44
+ exp: import("../types").TextRange;
45
+ arg?: import("../types").TextRange;
46
+ typeArg?: import("../types").TextRange;
47
+ } & {
24
48
  name?: string;
25
49
  destructured?: Set<string>;
26
50
  destructuredRest?: string;
27
- define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
28
- exp: import("../types").TextRange;
29
- arg?: import("../types").TextRange;
30
- typeArg?: import("../types").TextRange;
31
- }> & {
32
- statement: import("../types").TextRange;
33
- };
34
- withDefaults?: import("../types").TextRange & {
35
- arg?: import("../types").TextRange;
36
- };
37
- };
38
- slots: {
39
- name?: string;
40
- isObjectBindingPattern?: boolean;
41
- define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
42
- exp: import("../types").TextRange;
43
- arg?: import("../types").TextRange;
44
- typeArg?: import("../types").TextRange;
45
- }>;
46
- };
47
- emits: {
51
+ statement: import("../types").TextRange;
52
+ }) | undefined;
53
+ withDefaults: {
54
+ callExp: import("../types").TextRange;
55
+ exp: import("../types").TextRange;
56
+ arg?: import("../types").TextRange | undefined;
57
+ } | undefined;
58
+ defineEmits: ({
59
+ callExp: import("../types").TextRange;
60
+ exp: import("../types").TextRange;
61
+ arg?: import("../types").TextRange;
62
+ typeArg?: import("../types").TextRange;
63
+ } & {
48
64
  name?: string;
49
- define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
50
- exp: import("../types").TextRange;
51
- arg?: import("../types").TextRange;
52
- typeArg?: import("../types").TextRange;
53
- }> & {
54
- statement: import("../types").TextRange;
55
- hasUnionTypeArg?: boolean;
56
- };
57
- };
58
- expose: {
65
+ hasUnionTypeArg?: boolean;
66
+ statement: import("../types").TextRange;
67
+ }) | undefined;
68
+ defineSlots: ({
69
+ callExp: import("../types").TextRange;
70
+ exp: import("../types").TextRange;
71
+ arg?: import("../types").TextRange;
72
+ typeArg?: import("../types").TextRange;
73
+ } & {
59
74
  name?: string;
60
- define?: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
61
- exp: import("../types").TextRange;
62
- arg?: import("../types").TextRange;
63
- typeArg?: import("../types").TextRange;
64
- }>;
65
- };
66
- options: {
75
+ isObjectBindingPattern?: boolean;
76
+ statement: import("../types").TextRange;
77
+ }) | undefined;
78
+ defineExpose: {
79
+ callExp: import("../types").TextRange;
80
+ exp: import("../types").TextRange;
81
+ arg?: import("../types").TextRange;
82
+ typeArg?: import("../types").TextRange;
83
+ } | undefined;
84
+ defineOptions: {
67
85
  name?: string;
68
86
  inheritAttrs?: string;
69
- };
70
- cssModules: {
71
- define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
72
- exp: import("../types").TextRange;
73
- arg?: import("../types").TextRange;
74
- typeArg?: import("../types").TextRange;
75
- }>;
87
+ } | undefined;
88
+ useAttrs: {
89
+ callExp: import("../types").TextRange;
90
+ exp: import("../types").TextRange;
91
+ arg?: import("../types").TextRange;
92
+ typeArg?: import("../types").TextRange;
76
93
  }[];
77
- defineProp: {
78
- localName: import("../types").TextRange | undefined;
79
- name: import("../types").TextRange | undefined;
80
- type: import("../types").TextRange | undefined;
81
- modifierType?: import("../types").TextRange | undefined;
82
- runtimeType: import("../types").TextRange | undefined;
83
- defaultValue: import("../types").TextRange | undefined;
84
- required: boolean;
85
- isModel?: boolean;
94
+ useCssModule: {
95
+ callExp: import("../types").TextRange;
96
+ exp: import("../types").TextRange;
97
+ arg?: import("../types").TextRange;
98
+ typeArg?: import("../types").TextRange;
86
99
  }[];
87
- templateRefs: {
88
- name?: string;
89
- define: ReturnType<(node: import("typescript").CallExpression) => import("../types").TextRange & {
90
- exp: import("../types").TextRange;
91
- arg?: import("../types").TextRange;
92
- typeArg?: import("../types").TextRange;
93
- }>;
100
+ useSlots: {
101
+ callExp: import("../types").TextRange;
102
+ exp: import("../types").TextRange;
103
+ arg?: import("../types").TextRange;
104
+ typeArg?: import("../types").TextRange;
94
105
  }[];
106
+ useTemplateRef: ({
107
+ callExp: import("../types").TextRange;
108
+ exp: import("../types").TextRange;
109
+ arg?: import("../types").TextRange;
110
+ typeArg?: import("../types").TextRange;
111
+ } & {
112
+ name?: string;
113
+ })[];
95
114
  } | undefined>;
96
- lang: import("alien-signals").ISignal<string>;
97
- generatedScript: import("alien-signals").ISignal<{
115
+ lang: import("alien-signals").Computed<string>;
116
+ generatedScript: import("alien-signals").Computed<{
98
117
  codes: Code[];
99
118
  linkedCodeMappings: Mapping<unknown>[];
100
119
  generatedTemplate: boolean;
@@ -115,7 +134,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
115
134
  };
116
135
  inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
117
136
  }>;
118
- generatedTemplate: import("alien-signals").ISignal<{
137
+ generatedTemplate: import("alien-signals").Computed<{
119
138
  codes: Code[];
120
139
  slots: {
121
140
  name: string;
@@ -137,14 +156,18 @@ export declare const tsCodegen: WeakMap<Sfc, {
137
156
  navigationWithoutRename: import("../types").VueCodeInformation;
138
157
  navigationAndCompletion: import("../types").VueCodeInformation;
139
158
  navigationAndAdditionalCompletion: import("../types").VueCodeInformation;
159
+ withoutNavigation: import("../types").VueCodeInformation;
140
160
  withoutHighlight: import("../types").VueCodeInformation;
141
161
  withoutHighlightAndCompletion: import("../types").VueCodeInformation;
142
162
  withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
143
163
  };
144
164
  accessExternalVariables: Map<string, Set<number>>;
165
+ lastGenericComment: {
166
+ content: string;
167
+ offset: number;
168
+ } | undefined;
145
169
  hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
146
170
  blockConditions: string[];
147
- usedComponentCtxVars: Set<string>;
148
171
  scopedClasses: {
149
172
  source: string;
150
173
  className: string;
@@ -153,8 +176,14 @@ export declare const tsCodegen: WeakMap<Sfc, {
153
176
  emptyClassOffsets: number[];
154
177
  inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
155
178
  hasSlot: boolean;
156
- inheritedAttrVars: Set<unknown>;
179
+ bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
180
+ inheritedAttrVars: Set<string>;
157
181
  templateRefs: Map<string, [varName: string, offset: number]>;
182
+ currentComponent: {
183
+ node: import("@vue/compiler-dom").ElementNode;
184
+ ctxVar: string;
185
+ used: boolean;
186
+ } | undefined;
158
187
  singleRootElType: string | undefined;
159
188
  singleRootNode: import("@vue/compiler-dom").ElementNode | undefined;
160
189
  accessExternalVariable(name: string, offset?: number): void;
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsCodegen = void 0;
4
4
  const alien_signals_1 = require("alien-signals");
5
- const path_browserify_1 = require("path-browserify");
6
5
  const script_1 = require("../codegen/script");
7
6
  const template_1 = require("../codegen/template");
8
7
  const scriptRanges_1 = require("../parsers/scriptRanges");
9
8
  const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
9
+ const vueCompilerOptions_1 = require("../parsers/vueCompilerOptions");
10
+ const ts_1 = require("../utils/ts");
10
11
  exports.tsCodegen = new WeakMap();
11
12
  const fileEditTimes = new Map();
12
13
  const plugin = ctx => {
@@ -30,8 +31,7 @@ const plugin = ctx => {
30
31
  if (/script_(js|jsx|ts|tsx)/.test(embeddedFile.id)) {
31
32
  const tsx = _tsx.generatedScript.get();
32
33
  if (tsx) {
33
- const content = [...tsx.codes];
34
- embeddedFile.content = content;
34
+ embeddedFile.content = [...tsx.codes];
35
35
  embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
36
36
  }
37
37
  }
@@ -58,23 +58,75 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
58
58
  : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
59
59
  : 'js';
60
60
  });
61
+ const vueCompilerOptions = (0, alien_signals_1.computed)(() => {
62
+ const options = (0, vueCompilerOptions_1.parseVueCompilerOptions)(_sfc.comments);
63
+ return options
64
+ ? (0, ts_1.resolveVueCompilerOptions)(options, ctx.vueCompilerOptions)
65
+ : ctx.vueCompilerOptions;
66
+ });
61
67
  const scriptRanges = (0, alien_signals_1.computed)(() => _sfc.script
62
68
  ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
63
69
  : undefined);
64
70
  const scriptSetupRanges = (0, alien_signals_1.computed)(() => _sfc.scriptSetup
65
- ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
71
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, vueCompilerOptions.get())
66
72
  : undefined);
73
+ const scriptSetupBindingNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
74
+ const newNames = new Set();
75
+ const bindings = scriptSetupRanges.get()?.bindings;
76
+ if (_sfc.scriptSetup && bindings) {
77
+ for (const { range } of bindings) {
78
+ newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
79
+ }
80
+ }
81
+ return newNames;
82
+ }));
83
+ const scriptSetupImportComponentNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
84
+ const newNames = new Set();
85
+ const bindings = scriptSetupRanges.get()?.bindings;
86
+ if (_sfc.scriptSetup && bindings) {
87
+ for (const { range, moduleName, isDefaultImport, isNamespace } of bindings) {
88
+ if (moduleName
89
+ && isDefaultImport
90
+ && !isNamespace
91
+ && ctx.vueCompilerOptions.extensions.some(ext => moduleName.endsWith(ext))) {
92
+ newNames.add(_sfc.scriptSetup.content.slice(range.start, range.end));
93
+ }
94
+ }
95
+ }
96
+ return newNames;
97
+ }));
98
+ const destructuredPropNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
99
+ const newNames = new Set(scriptSetupRanges.get()?.defineProps?.destructured);
100
+ const rest = scriptSetupRanges.get()?.defineProps?.destructuredRest;
101
+ if (rest) {
102
+ newNames.add(rest);
103
+ }
104
+ return newNames;
105
+ }));
106
+ const templateRefNames = alien_signals_1.unstable.computedSet((0, alien_signals_1.computed)(() => {
107
+ const newNames = new Set(scriptSetupRanges.get()?.useTemplateRef
108
+ .map(({ name }) => name)
109
+ .filter(name => name !== undefined));
110
+ return newNames;
111
+ }));
112
+ const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.defineSlots);
113
+ const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.defineSlots?.name);
114
+ const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.defineProps?.name);
115
+ const inheritAttrs = (0, alien_signals_1.computed)(() => {
116
+ const value = scriptSetupRanges.get()?.defineOptions?.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
117
+ return value !== 'false';
118
+ });
67
119
  const generatedTemplate = (0, alien_signals_1.computed)(() => {
68
- if (ctx.vueCompilerOptions.skipTemplateCodegen || !_sfc.template) {
120
+ if (vueCompilerOptions.get().skipTemplateCodegen || !_sfc.template) {
69
121
  return;
70
122
  }
71
123
  const codes = [];
72
124
  const codegen = (0, template_1.generateTemplate)({
73
125
  ts,
74
126
  compilerOptions: ctx.compilerOptions,
75
- vueCompilerOptions: ctx.vueCompilerOptions,
127
+ vueCompilerOptions: vueCompilerOptions.get(),
76
128
  template: _sfc.template,
77
- edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
129
+ edited: vueCompilerOptions.get().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
78
130
  scriptSetupBindingNames: scriptSetupBindingNames.get(),
79
131
  scriptSetupImportComponentNames: scriptSetupImportComponentNames.get(),
80
132
  destructuredPropNames: destructuredPropNames.get(),
@@ -95,68 +147,23 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
95
147
  codes: codes,
96
148
  };
97
149
  });
98
- const scriptSetupBindingNames = (0, alien_signals_1.computed)(oldNames => {
99
- const newNames = new Set();
100
- const bindings = scriptSetupRanges.get()?.bindings;
101
- if (_sfc.scriptSetup && bindings) {
102
- for (const binding of bindings) {
103
- newNames.add(_sfc.scriptSetup?.content.substring(binding.start, binding.end));
104
- }
105
- }
106
- if (newNames && oldNames && twoSetsEqual(newNames, oldNames)) {
107
- return oldNames;
108
- }
109
- return newNames;
110
- });
111
- const scriptSetupImportComponentNames = (0, alien_signals_1.computed)(oldNames => {
112
- const newNames = scriptSetupRanges.get()?.importComponentNames ?? new Set();
113
- if (oldNames && twoSetsEqual(newNames, oldNames)) {
114
- return oldNames;
115
- }
116
- return newNames;
117
- });
118
- const destructuredPropNames = (0, alien_signals_1.computed)(oldNames => {
119
- const newNames = scriptSetupRanges.get()?.props.destructured ?? new Set();
120
- const rest = scriptSetupRanges.get()?.props.destructuredRest;
121
- if (rest) {
122
- newNames.add(rest);
123
- }
124
- if (oldNames && twoSetsEqual(newNames, oldNames)) {
125
- return oldNames;
126
- }
127
- return newNames;
128
- });
129
- const templateRefNames = (0, alien_signals_1.computed)(oldNames => {
130
- const newNames = new Set(scriptSetupRanges.get()?.templateRefs
131
- .map(({ name }) => name)
132
- .filter(name => name !== undefined));
133
- if (oldNames && twoSetsEqual(newNames, oldNames)) {
134
- return oldNames;
135
- }
136
- return newNames;
137
- });
138
- const hasDefineSlots = (0, alien_signals_1.computed)(() => !!scriptSetupRanges.get()?.slots.define);
139
- const slotsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.slots.name);
140
- const propsAssignName = (0, alien_signals_1.computed)(() => scriptSetupRanges.get()?.props.name);
141
- const inheritAttrs = (0, alien_signals_1.computed)(() => {
142
- const value = scriptSetupRanges.get()?.options.inheritAttrs ?? scriptRanges.get()?.exportDefault?.inheritAttrsOption;
143
- return value !== 'false';
144
- });
145
150
  const generatedScript = (0, alien_signals_1.computed)(() => {
146
151
  const codes = [];
147
152
  const linkedCodeMappings = [];
148
153
  let generatedLength = 0;
149
154
  const codegen = (0, script_1.generateScript)({
150
155
  ts,
151
- fileBaseName: path_browserify_1.posix.basename(fileName),
156
+ compilerOptions: ctx.compilerOptions,
157
+ vueCompilerOptions: vueCompilerOptions.get(),
152
158
  sfc: _sfc,
159
+ edited: vueCompilerOptions.get().__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
160
+ fileName,
153
161
  lang: lang.get(),
154
162
  scriptRanges: scriptRanges.get(),
155
163
  scriptSetupRanges: scriptSetupRanges.get(),
156
164
  templateCodegen: generatedTemplate.get(),
157
- compilerOptions: ctx.compilerOptions,
158
- vueCompilerOptions: ctx.vueCompilerOptions,
159
- edited: ctx.vueCompilerOptions.__test || (fileEditTimes.get(fileName) ?? 0) >= 2,
165
+ destructuredPropNames: destructuredPropNames.get(),
166
+ templateRefNames: templateRefNames.get(),
160
167
  getGeneratedLength: () => generatedLength,
161
168
  linkedCodeMappings,
162
169
  appendGlobalTypes,
@@ -185,15 +192,4 @@ function createTsx(fileName, _sfc, ctx, appendGlobalTypes) {
185
192
  generatedTemplate,
186
193
  };
187
194
  }
188
- function twoSetsEqual(a, b) {
189
- if (a.size !== b.size) {
190
- return false;
191
- }
192
- for (const file of a) {
193
- if (!b.has(file)) {
194
- return false;
195
- }
196
- }
197
- return true;
198
- }
199
195
  //# sourceMappingURL=vue-tsx.js.map
package/lib/types.d.ts CHANGED
@@ -37,8 +37,10 @@ export interface VueCompilerOptions {
37
37
  defineOptions: string[];
38
38
  withDefaults: string[];
39
39
  };
40
- composibles: {
40
+ composables: {
41
+ useAttrs: string[];
41
42
  useCssModule: string[];
43
+ useSlots: string[];
42
44
  useTemplateRef: string[];
43
45
  };
44
46
  plugins: VueLanguagePlugin[];
@@ -81,8 +83,8 @@ export type VueLanguagePluginReturn = {
81
83
  };
82
84
  export type VueLanguagePlugin = (ctx: {
83
85
  modules: {
84
- typescript: typeof import('typescript');
85
- '@vue/compiler-dom': typeof import('@vue/compiler-dom');
86
+ typescript: typeof ts;
87
+ '@vue/compiler-dom': typeof CompilerDOM;
86
88
  };
87
89
  compilerOptions: ts.CompilerOptions;
88
90
  vueCompilerOptions: VueCompilerOptions;
@@ -97,14 +99,9 @@ export interface SfcBlock {
97
99
  content: string;
98
100
  attrs: Record<string, string | true>;
99
101
  }
100
- export interface SFCStyleOverride {
101
- module?: {
102
- name: string;
103
- offset?: number;
104
- };
105
- }
106
102
  export interface Sfc {
107
103
  content: string;
104
+ comments: string[];
108
105
  template: SfcBlock & {
109
106
  ast: CompilerDOM.RootNode | undefined;
110
107
  errors: CompilerDOM.CompilerError[];
@@ -120,8 +117,12 @@ export interface Sfc {
120
117
  genericOffset: number;
121
118
  ast: ts.SourceFile;
122
119
  } | undefined;
123
- styles: readonly (SfcBlock & SFCStyleOverride & {
120
+ styles: readonly (SfcBlock & {
124
121
  scoped: boolean;
122
+ module?: {
123
+ name: string;
124
+ offset?: number;
125
+ };
125
126
  cssVars: {
126
127
  text: string;
127
128
  offset: number;
@@ -135,6 +136,14 @@ export interface Sfc {
135
136
  type: string;
136
137
  })[];
137
138
  }
139
+ declare module '@vue/compiler-sfc' {
140
+ interface SFCStyleBlock {
141
+ __module?: {
142
+ name: string;
143
+ offset?: number;
144
+ };
145
+ }
146
+ }
138
147
  export interface TextRange {
139
148
  start: number;
140
149
  end: number;
@@ -1,3 +1,3 @@
1
- import type { Segment } from 'muggle-string';
2
1
  import type { Mapping } from '@volar/language-core';
2
+ import type { Segment } from 'muggle-string';
3
3
  export declare function buildMappings<T>(chunks: Segment<T>[]): Mapping<T>[];
@@ -1,2 +1,7 @@
1
1
  import type { SFCParseResult } from '@vue/compiler-sfc';
2
+ declare module '@vue/compiler-sfc' {
3
+ interface SFCDescriptor {
4
+ comments: string[];
5
+ }
6
+ }
2
7
  export declare function parse(source: string): SFCParseResult;
@@ -18,6 +18,7 @@ function parse(source) {
18
18
  const descriptor = {
19
19
  filename: 'anonymous.vue',
20
20
  source,
21
+ comments: [],
21
22
  template: null,
22
23
  script: null,
23
24
  scriptSetup: null,
@@ -28,7 +29,11 @@ function parse(source) {
28
29
  shouldForceReload: () => false,
29
30
  };
30
31
  ast.children.forEach(node => {
31
- if (node.type !== compiler.NodeTypes.ELEMENT) {
32
+ if (node.type === compiler.NodeTypes.COMMENT) {
33
+ descriptor.comments.push(node.content);
34
+ return;
35
+ }
36
+ else if (node.type !== compiler.NodeTypes.ELEMENT) {
32
37
  return;
33
38
  }
34
39
  switch (node.tag) {
@@ -107,7 +112,7 @@ function createBlock(node, source) {
107
112
  block.scoped = true;
108
113
  }
109
114
  else if (p.name === 'module') {
110
- block.module = {
115
+ block.__module = {
111
116
  name: p.value?.content ?? '$style',
112
117
  offset: p.value?.content ? p.value?.loc.start.offset - node.loc.start.offset : undefined
113
118
  };
package/lib/utils/ts.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare function createParsedCommandLineByJson(ts: typeof import('typescr
7
7
  writeFile?(path: string, data: string): void;
8
8
  }, rootDir: string, json: any, configFileName?: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
9
9
  export declare function createParsedCommandLine(ts: typeof import('typescript'), parseConfigHost: ts.ParseConfigHost, tsConfigPath: string, skipGlobalTypesSetup?: boolean): ParsedCommandLine;
10
- export declare function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions>): VueCompilerOptions;
10
+ export declare function resolveVueCompilerOptions(options: Partial<VueCompilerOptions>, defaults?: VueCompilerOptions): VueCompilerOptions;
11
11
  export declare function setupGlobalTypes(rootDir: string, vueOptions: VueCompilerOptions, host: {
12
12
  fileExists(path: string): boolean;
13
13
  writeFile?(path: string, data: string): void;