@vue/language-core 2.0.29 → 2.1.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 (72) hide show
  1. package/index.d.ts +4 -3
  2. package/index.js +4 -3
  3. package/lib/codegen/common.d.ts +2 -1
  4. package/lib/codegen/common.js +16 -5
  5. package/lib/codegen/globalTypes.d.ts +1 -0
  6. package/lib/codegen/globalTypes.js +123 -0
  7. package/lib/codegen/localTypes.d.ts +14 -0
  8. package/lib/codegen/localTypes.js +120 -0
  9. package/lib/codegen/script/component.d.ts +1 -4
  10. package/lib/codegen/script/component.js +112 -63
  11. package/lib/codegen/script/context.d.ts +14 -10
  12. package/lib/codegen/script/context.js +5 -107
  13. package/lib/codegen/script/index.d.ts +3 -2
  14. package/lib/codegen/script/index.js +37 -53
  15. package/lib/codegen/script/internalComponent.d.ts +1 -1
  16. package/lib/codegen/script/internalComponent.js +13 -5
  17. package/lib/codegen/script/scriptSetup.js +144 -62
  18. package/lib/codegen/script/template.d.ts +3 -0
  19. package/lib/codegen/script/template.js +80 -79
  20. package/lib/codegen/template/context.d.ts +6 -1
  21. package/lib/codegen/template/context.js +9 -2
  22. package/lib/codegen/template/element.d.ts +1 -1
  23. package/lib/codegen/template/element.js +214 -92
  24. package/lib/codegen/template/elementChildren.js +1 -0
  25. package/lib/codegen/template/elementDirectives.js +8 -4
  26. package/lib/codegen/template/elementEvents.js +13 -14
  27. package/lib/codegen/template/elementProps.js +43 -22
  28. package/lib/codegen/template/index.d.ts +3 -0
  29. package/lib/codegen/template/index.js +29 -41
  30. package/lib/codegen/template/interpolation.d.ts +1 -1
  31. package/lib/codegen/template/interpolation.js +24 -15
  32. package/lib/codegen/template/objectProperty.d.ts +1 -1
  33. package/lib/codegen/template/objectProperty.js +7 -2
  34. package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
  35. package/lib/codegen/template/styleScopedClasses.js +72 -0
  36. package/lib/codegen/template/templateChild.js +5 -1
  37. package/lib/codegen/types.d.ts +9 -0
  38. package/lib/codegen/types.js +3 -0
  39. package/lib/languagePlugin.d.ts +2 -4
  40. package/lib/languagePlugin.js +4 -57
  41. package/lib/parsers/scriptRanges.d.ts +1 -0
  42. package/lib/parsers/scriptRanges.js +5 -0
  43. package/lib/parsers/scriptSetupRanges.d.ts +17 -3
  44. package/lib/parsers/scriptSetupRanges.js +127 -44
  45. package/lib/plugins/file-md.js +9 -6
  46. package/lib/plugins/vue-root-tags.js +51 -0
  47. package/lib/plugins/vue-tsx.d.ts +40 -3
  48. package/lib/plugins/vue-tsx.js +17 -4
  49. package/lib/plugins.js +2 -0
  50. package/lib/types.d.ts +14 -10
  51. package/lib/utils/findDestructuredProps.js +3 -0
  52. package/lib/utils/parseCssClassNames.js +4 -6
  53. package/lib/utils/parseCssVars.js +5 -7
  54. package/lib/utils/parseSfc.js +4 -1
  55. package/lib/utils/ts.js +10 -4
  56. package/lib/virtualFile/{computedFiles.d.ts → computedEmbeddedCodes.d.ts} +1 -1
  57. package/lib/virtualFile/{computedFiles.js → computedEmbeddedCodes.js} +3 -3
  58. package/lib/virtualFile/computedSfc.d.ts +1 -1
  59. package/lib/virtualFile/computedSfc.js +14 -3
  60. package/lib/virtualFile/vueFile.d.ts +13 -3
  61. package/lib/virtualFile/vueFile.js +17 -9
  62. package/package.json +4 -4
  63. package/lib/codegen/script/globalTypes.d.ts +0 -2
  64. package/lib/codegen/script/globalTypes.js +0 -134
  65. package/lib/codegen/template/objectKey.js +0 -34
  66. package/lib/languageModule.d.ts +0 -5
  67. package/lib/languageModule.js +0 -159
  68. package/lib/plugins/file-dot-setup.js +0 -34
  69. package/lib/virtualFile/computedMappings.d.ts +0 -4
  70. package/lib/virtualFile/computedMappings.js +0 -65
  71. /package/lib/plugins/{file-dot-setup.d.ts → vue-root-tags.d.ts} +0 -0
  72. /package/lib/{codegen/template/objectKey.d.ts → utils/findDestructuredProps.d.ts} +0 -0
@@ -8,8 +8,9 @@ const context_1 = require("./context");
8
8
  const element_1 = require("./element");
9
9
  const objectProperty_1 = require("./objectProperty");
10
10
  const templateChild_1 = require("./templateChild");
11
+ const styleScopedClasses_1 = require("./styleScopedClasses");
11
12
  function* generateTemplate(options) {
12
- const ctx = (0, context_1.createTemplateCodegenContext)(options.scriptSetupBindingNames);
13
+ const ctx = (0, context_1.createTemplateCodegenContext)(options);
13
14
  if (options.slotsAssignName) {
14
15
  ctx.addLocalVariable(options.slotsAssignName);
15
16
  }
@@ -20,14 +21,26 @@ function* generateTemplate(options) {
20
21
  if (options.template.ast) {
21
22
  yield* (0, templateChild_1.generateTemplateChild)(options, ctx, options.template.ast, undefined, undefined, undefined);
22
23
  }
23
- yield* generateStyleScopedClasses();
24
+ yield* (0, styleScopedClasses_1.generateStyleScopedClasses)(ctx);
24
25
  if (!options.hasDefineSlots) {
25
26
  yield `var __VLS_slots!:`;
26
27
  yield* generateSlotsType();
27
28
  yield common_1.endOfLine;
28
29
  }
30
+ yield* generateInheritedAttrs();
29
31
  yield* ctx.generateAutoImportCompletion();
32
+ yield* generateRefs();
30
33
  return ctx;
34
+ function* generateRefs() {
35
+ for (const [, validId] of options.templateRefNames) {
36
+ yield `let ${validId}${common_1.newLine}`;
37
+ }
38
+ yield `const __VLS_refs = {${common_1.newLine}`;
39
+ for (const [name, validId] of options.templateRefNames) {
40
+ yield `'${name}': ${validId}!,${common_1.newLine}`;
41
+ }
42
+ yield `}${common_1.endOfLine}`;
43
+ }
31
44
  function* generateSlotsType() {
32
45
  for (const { expVar, varName } of ctx.dynamicSlots) {
33
46
  ctx.hasSlot = true;
@@ -46,53 +59,28 @@ function* generateTemplate(options) {
46
59
  }
47
60
  yield `}`;
48
61
  }
49
- function* generateStyleScopedClasses() {
50
- yield `if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {${common_1.newLine}`;
51
- for (const offset of ctx.emptyClassOffsets) {
52
- yield `__VLS_styleScopedClasses['`;
53
- yield [
54
- '',
55
- 'template',
56
- offset,
57
- ctx.codeFeatures.additionalCompletion,
58
- ];
59
- yield `']${common_1.endOfLine}`;
62
+ function* generateInheritedAttrs() {
63
+ yield 'var __VLS_inheritedAttrs!: {}';
64
+ for (const varName of ctx.inheritedAttrVars) {
65
+ yield ` & typeof ${varName}`;
60
66
  }
61
- for (const { className, offset } of ctx.scopedClasses) {
62
- yield `__VLS_styleScopedClasses[`;
63
- yield [
64
- '',
65
- 'template',
66
- offset,
67
- ctx.codeFeatures.navigationWithoutRename,
68
- ];
69
- yield `'`;
70
- yield [
71
- className,
72
- 'template',
73
- offset,
74
- ctx.codeFeatures.navigationAndAdditionalCompletion,
75
- ];
76
- yield `'`;
77
- yield [
78
- '',
79
- 'template',
80
- offset + className.length,
81
- ctx.codeFeatures.navigationWithoutRename,
82
- ];
83
- yield `]${common_1.endOfLine}`;
84
- }
85
- yield `}${common_1.newLine}`;
67
+ yield common_1.endOfLine;
86
68
  }
87
69
  function* generatePreResolveComponents() {
88
- yield `let __VLS_resolvedLocalAndGlobalComponents!: {}`;
70
+ yield `let __VLS_resolvedLocalAndGlobalComponents!: Required<{}`;
89
71
  if (options.template.ast) {
72
+ const components = new Set();
90
73
  for (const node of forEachElementNode(options.template.ast)) {
91
74
  if (node.tagType === CompilerDOM.ElementTypes.COMPONENT
92
75
  && node.tag.toLowerCase() !== 'component'
93
76
  && !node.tag.includes('.') // namespace tag
94
77
  ) {
95
- yield ` & __VLS_WithComponent<'${(0, element_1.getCanonicalComponentName)(node.tag)}', typeof __VLS_localComponents, `;
78
+ if (components.has(node.tag)) {
79
+ continue;
80
+ }
81
+ components.add(node.tag);
82
+ yield common_1.newLine;
83
+ yield ` & __VLS_WithComponent<'${(0, element_1.getCanonicalComponentName)(node.tag)}', typeof __VLS_components, `;
96
84
  yield (0, element_1.getPossibleOriginalComponentNames)(node.tag, false)
97
85
  .map(name => `"${name}"`)
98
86
  .join(', ');
@@ -100,7 +88,7 @@ function* generateTemplate(options) {
100
88
  }
101
89
  }
102
90
  }
103
- yield common_1.endOfLine;
91
+ yield `>${common_1.endOfLine}`;
104
92
  }
105
93
  }
106
94
  function* forEachElementNode(node) {
@@ -2,5 +2,5 @@ import type * as ts from 'typescript';
2
2
  import type { Code, VueCodeInformation } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
- export declare function generateInterpolation(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, _code: string, astHolder: any, start: number | undefined, data: VueCodeInformation | (() => VueCodeInformation) | undefined, prefix: string, suffix: string): Generator<Code>;
5
+ export declare function generateInterpolation(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, _code: string, astHolder: any, start: number | undefined, data: VueCodeInformation | ((offset: number) => VueCodeInformation) | undefined, prefix: string, suffix: string): Generator<Code>;
6
6
  export declare function forEachInterpolationSegment(ts: typeof import('typescript'), ctx: TemplateCodegenContext, code: string, offset: number | undefined, ast: ts.SourceFile): Generator<[fragment: string, offset: number | undefined, isJustForErrorMapping?: boolean]>;
@@ -33,7 +33,7 @@ function* generateInterpolation(options, ctx, _code, astHolder, start, data, pre
33
33
  start + offset,
34
34
  onlyError
35
35
  ? ctx.codeFeatures.verification
36
- : typeof data === 'function' ? data() : data,
36
+ : typeof data === 'function' ? data(start + offset) : data,
37
37
  ];
38
38
  }
39
39
  else {
@@ -124,20 +124,7 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
124
124
  }
125
125
  }
126
126
  else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
127
- const functionArgs = [];
128
- for (const param of node.parameters) {
129
- (0, common_1.collectVars)(ts, param.name, ast, functionArgs);
130
- if (param.type) {
131
- walkIdentifiers(ts, param.type, ast, cb, ctx, blockVars, false);
132
- }
133
- }
134
- for (const varName of functionArgs) {
135
- ctx.addLocalVariable(varName);
136
- }
137
- walkIdentifiers(ts, node.body, ast, cb, ctx, blockVars, false);
138
- for (const varName of functionArgs) {
139
- ctx.removeLocalVariable(varName);
140
- }
127
+ processFunction(ts, node, ast, cb, ctx);
141
128
  }
142
129
  else if (ts.isObjectLiteralExpression(node)) {
143
130
  for (const prop of node.properties) {
@@ -157,6 +144,10 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
157
144
  // TODO: cannot report "Spread types may only be created from object types.ts(2698)"
158
145
  walkIdentifiers(ts, prop.expression, ast, cb, ctx, blockVars, false);
159
146
  }
147
+ // fix https://github.com/vuejs/language-tools/issues/4604
148
+ else if (ts.isFunctionLike(prop) && prop.body) {
149
+ processFunction(ts, prop, ast, cb, ctx);
150
+ }
160
151
  }
161
152
  }
162
153
  else if (ts.isTypeReferenceNode(node)) {
@@ -182,6 +173,24 @@ function walkIdentifiers(ts, node, ast, cb, ctx, blockVars = [], isRoot = true)
182
173
  }
183
174
  }
184
175
  }
176
+ function processFunction(ts, node, ast, cb, ctx) {
177
+ const functionArgs = [];
178
+ for (const param of node.parameters) {
179
+ (0, common_1.collectVars)(ts, param.name, ast, functionArgs);
180
+ if (param.type) {
181
+ walkIdentifiers(ts, param.type, ast, cb, ctx);
182
+ }
183
+ }
184
+ for (const varName of functionArgs) {
185
+ ctx.addLocalVariable(varName);
186
+ }
187
+ if (node.body) {
188
+ walkIdentifiers(ts, node.body, ast, cb, ctx);
189
+ }
190
+ for (const varName of functionArgs) {
191
+ ctx.removeLocalVariable(varName);
192
+ }
193
+ }
185
194
  function walkIdentifiersInTypeReference(ts, node, cb) {
186
195
  if (ts.isTypeQueryNode(node) && ts.isIdentifier(node.exprName)) {
187
196
  cb(node.exprName, false);
@@ -1,4 +1,4 @@
1
1
  import type { Code, VueCodeInformation } from '../../types';
2
2
  import type { TemplateCodegenContext } from './context';
3
3
  import type { TemplateCodegenOptions } from './index';
4
- export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation, astHolder?: any, shouldCamelize?: boolean): Generator<Code>;
4
+ export declare function generateObjectProperty(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, code: string, offset: number, features: VueCodeInformation, astHolder?: any, shouldCamelize?: boolean, shouldBeConstant?: boolean): Generator<Code>;
@@ -6,9 +6,14 @@ const common_1 = require("../common");
6
6
  const camelized_1 = require("./camelized");
7
7
  const interpolation_1 = require("./interpolation");
8
8
  const stringLiteralKey_1 = require("./stringLiteralKey");
9
- function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false) {
9
+ function* generateObjectProperty(options, ctx, code, offset, features, astHolder, shouldCamelize = false, shouldBeConstant = false) {
10
10
  if (code.startsWith('[') && code.endsWith(']') && astHolder) {
11
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
11
+ if (shouldBeConstant) {
12
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, code.slice(1, -1), astHolder, offset + 1, features, `[__VLS_tryAsConstant(`, `)]`);
13
+ }
14
+ else {
15
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, code, astHolder, offset, features, '', '');
16
+ }
12
17
  }
13
18
  else if (shouldCamelize) {
14
19
  if (common_1.variableNameRegex.test((0, shared_1.camelize)(code))) {
@@ -0,0 +1,3 @@
1
+ import type { Code } from '../../types';
2
+ import type { TemplateCodegenContext } from './context';
3
+ export declare function generateStyleScopedClasses(ctx: TemplateCodegenContext, withDot?: boolean): Generator<Code>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStyleScopedClasses = generateStyleScopedClasses;
4
+ const common_1 = require("../common");
5
+ function* generateStyleScopedClasses(ctx, withDot = false) {
6
+ for (const offset of ctx.emptyClassOffsets) {
7
+ yield `__VLS_styleScopedClasses['`;
8
+ yield [
9
+ '',
10
+ 'template',
11
+ offset,
12
+ ctx.codeFeatures.additionalCompletion,
13
+ ];
14
+ yield `']${common_1.endOfLine}`;
15
+ }
16
+ for (const { source, className, offset } of ctx.scopedClasses) {
17
+ yield `__VLS_styleScopedClasses[`;
18
+ yield [
19
+ '',
20
+ source,
21
+ offset - (withDot ? 1 : 0),
22
+ ctx.codeFeatures.navigation,
23
+ ];
24
+ yield `'`;
25
+ // fix https://github.com/vuejs/language-tools/issues/4537
26
+ yield* escapeString(source, className, offset, ['\\', '\'']);
27
+ yield `'`;
28
+ yield [
29
+ '',
30
+ source,
31
+ offset + className.length,
32
+ ctx.codeFeatures.navigationWithoutRename,
33
+ ];
34
+ yield `]${common_1.endOfLine}`;
35
+ }
36
+ yield common_1.newLine;
37
+ function* escapeString(source, className, offset, escapeTargets) {
38
+ let count = 0;
39
+ const currentEscapeTargets = [...escapeTargets];
40
+ const firstEscapeTarget = currentEscapeTargets.shift();
41
+ const splitted = className.split(firstEscapeTarget);
42
+ for (let i = 0; i < splitted.length; i++) {
43
+ const part = splitted[i];
44
+ const partLength = part.length;
45
+ if (escapeTargets.length > 0) {
46
+ yield* escapeString(source, part, offset + count, [...currentEscapeTargets]);
47
+ }
48
+ else {
49
+ yield [
50
+ part,
51
+ source,
52
+ offset + count,
53
+ ctx.codeFeatures.navigationAndAdditionalCompletion,
54
+ ];
55
+ }
56
+ if (i !== splitted.length - 1) {
57
+ yield '\\';
58
+ yield [
59
+ firstEscapeTarget,
60
+ source,
61
+ offset + count + partLength,
62
+ ctx.codeFeatures.navigationAndAdditionalCompletion,
63
+ ];
64
+ count += partLength + 1;
65
+ }
66
+ else {
67
+ count += partLength;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ //# sourceMappingURL=styleScopedClasses.js.map
@@ -39,8 +39,12 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
39
39
  yield* ctx.expectError(prevNode);
40
40
  }
41
41
  }
42
+ const shouldInheritRootNodeAttrs = options.inheritAttrs;
42
43
  if (node.type === CompilerDOM.NodeTypes.ROOT) {
43
44
  let prev;
45
+ if (shouldInheritRootNodeAttrs && node.children.length === 1 && node.children[0].type === CompilerDOM.NodeTypes.ELEMENT) {
46
+ ctx.singleRootNode = node.children[0];
47
+ }
44
48
  for (const childNode of node.children) {
45
49
  yield* generateTemplateChild(options, ctx, childNode, currentComponent, prev, componentCtxVar);
46
50
  prev = childNode;
@@ -65,7 +69,7 @@ function* generateTemplateChild(options, ctx, node, currentComponent, prevNode,
65
69
  yield* (0, element_1.generateElement)(options, ctx, node, currentComponent, componentCtxVar);
66
70
  }
67
71
  else {
68
- yield* (0, element_1.generateComponent)(options, ctx, node, currentComponent, componentCtxVar);
72
+ yield* (0, element_1.generateComponent)(options, ctx, node, currentComponent);
69
73
  }
70
74
  }
71
75
  }
@@ -0,0 +1,9 @@
1
+ export interface InlayHintInfo {
2
+ blockName: string;
3
+ offset: number;
4
+ setting: string;
5
+ label: string;
6
+ tooltip?: string;
7
+ paddingRight?: boolean;
8
+ paddingLeft?: boolean;
9
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -1,8 +1,6 @@
1
- import { type LanguagePlugin } from '@volar/language-core';
1
+ import { LanguagePlugin } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
3
  import type { VueCompilerOptions } from './types';
4
4
  import { VueVirtualCode } from './virtualFile/vueFile';
5
- export declare function createRootFileChecker(getProjectVersion: (() => string) | undefined, getRootFileNames: () => string[], caseSensitive: boolean): (fileName: string) => boolean;
6
- export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), asFileName: (scriptId: T) => string, _getProjectVersion: (() => string) | undefined, isRootFile: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): LanguagePlugin<T, VueVirtualCode>;
7
- export declare function createVueLanguagePlugin2<T>(ts: typeof import('typescript'), asFileName: (scriptId: T) => string, isRootFile: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): LanguagePlugin<T, VueVirtualCode>;
5
+ export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, asFileName: (scriptId: T) => string): LanguagePlugin<T, VueVirtualCode>;
8
6
  export declare function getAllExtensions(options: VueCompilerOptions): string[];
@@ -1,19 +1,15 @@
1
1
  "use strict";
2
2
  /// <reference types="@volar/typescript" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createRootFileChecker = createRootFileChecker;
5
4
  exports.createVueLanguagePlugin = createVueLanguagePlugin;
6
- exports.createVueLanguagePlugin2 = createVueLanguagePlugin2;
7
5
  exports.getAllExtensions = getAllExtensions;
8
6
  const language_core_1 = require("@volar/language-core");
9
7
  const CompilerDOM = require("@vue/compiler-dom");
10
8
  const plugins_1 = require("./plugins");
11
9
  const CompilerVue2 = require("./utils/vue2TemplateCompiler");
12
10
  const vueFile_1 = require("./virtualFile/vueFile");
13
- const normalFileRegistries = [];
14
- const holderFileRegistries = [];
15
- function getVueFileRegistry(isGlobalTypesHolder, key, plugins) {
16
- const fileRegistries = isGlobalTypesHolder ? holderFileRegistries : normalFileRegistries;
11
+ const fileRegistries = [];
12
+ function getVueFileRegistry(key, plugins) {
17
13
  let fileRegistry = fileRegistries.find(r => r.key === key
18
14
  && r.plugins.length === plugins.length
19
15
  && r.plugins.every(plugin => plugins.includes(plugin)))?.files;
@@ -39,25 +35,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
39
35
  ];
40
36
  return JSON.stringify(values);
41
37
  }
42
- function createRootFileChecker(getProjectVersion, getRootFileNames, caseSensitive) {
43
- const fileNames = new language_core_1.FileMap(caseSensitive);
44
- let projectVersion;
45
- return (fileName) => {
46
- if (!getProjectVersion || projectVersion !== getProjectVersion()) {
47
- projectVersion = getProjectVersion?.();
48
- fileNames.clear();
49
- for (const rootFileName of getRootFileNames()) {
50
- fileNames.set(rootFileName, undefined);
51
- }
52
- }
53
- return fileNames.has(fileName);
54
- };
55
- }
56
- // TODO: replace `createVueLanguagePlugin` with `createVueLanguagePlugin2` in 2.1
57
- function createVueLanguagePlugin(ts, asFileName, _getProjectVersion, isRootFile, compilerOptions, vueCompilerOptions) {
58
- return createVueLanguagePlugin2(ts, asFileName, isRootFile, compilerOptions, vueCompilerOptions);
59
- }
60
- function createVueLanguagePlugin2(ts, asFileName, isRootFile, compilerOptions, vueCompilerOptions) {
38
+ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
61
39
  const pluginContext = {
62
40
  modules: {
63
41
  '@vue/compiler-dom': vueCompilerOptions.target < 3
@@ -70,9 +48,9 @@ function createVueLanguagePlugin2(ts, asFileName, isRootFile, compilerOptions, v
70
48
  },
71
49
  compilerOptions,
72
50
  vueCompilerOptions,
73
- globalTypesHolder: undefined,
74
51
  };
75
52
  const plugins = (0, plugins_1.createPlugins)(pluginContext);
53
+ const fileRegistry = getVueFileRegistry(getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins), vueCompilerOptions.plugins);
76
54
  return {
77
55
  getLanguageId(scriptId) {
78
56
  const fileName = asFileName(scriptId);
@@ -86,10 +64,6 @@ function createVueLanguagePlugin2(ts, asFileName, isRootFile, compilerOptions, v
86
64
  createVirtualCode(scriptId, languageId, snapshot) {
87
65
  const fileName = asFileName(scriptId);
88
66
  if (plugins.some(plugin => plugin.isValidFile?.(fileName, languageId))) {
89
- if (!pluginContext.globalTypesHolder && isRootFile(fileName)) {
90
- pluginContext.globalTypesHolder = fileName;
91
- }
92
- const fileRegistry = getFileRegistry(pluginContext.globalTypesHolder === fileName);
93
67
  const code = fileRegistry.get(fileName);
94
68
  if (code) {
95
69
  code.update(snapshot);
@@ -106,30 +80,6 @@ function createVueLanguagePlugin2(ts, asFileName, isRootFile, compilerOptions, v
106
80
  code.update(snapshot);
107
81
  return code;
108
82
  },
109
- // TODO: when global types holder deleted, move global types to another file
110
- // disposeVirtualCode(fileId, code) {
111
- // const isGlobalTypesHolder = code.fileName === pluginContext.globalTypesHolder;
112
- // const fileRegistry = getFileRegistry(isGlobalTypesHolder);
113
- // fileRegistry.delete(fileId);
114
- // if (isGlobalTypesHolder) {
115
- // pluginContext.globalTypesHolder = undefined;
116
- // const fileRegistry2 = getFileRegistry(false);
117
- // for (const [fileId, code] of fileRegistry2) {
118
- // if (isValidGlobalTypesHolder(code.fileName)) {
119
- // pluginContext.globalTypesHolder = code.fileName;
120
- // fileRegistry2.delete(fileId);
121
- // // force dirty
122
- // files?.delete(fileId);
123
- // files?.set(
124
- // fileId,
125
- // code.languageId,
126
- // code.snapshot,
127
- // );
128
- // break;
129
- // }
130
- // }
131
- // }
132
- // },
133
83
  typescript: {
134
84
  extraFileExtensions: getAllExtensions(vueCompilerOptions)
135
85
  .map(ext => ({
@@ -154,9 +104,6 @@ function createVueLanguagePlugin2(ts, asFileName, isRootFile, compilerOptions, v
154
104
  },
155
105
  },
156
106
  };
157
- function getFileRegistry(isGlobalTypesHolder) {
158
- return getVueFileRegistry(isGlobalTypesHolder, getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins), vueCompilerOptions.plugins);
159
- }
160
107
  }
161
108
  function getAllExtensions(options) {
162
109
  const result = new Set();
@@ -10,6 +10,7 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
10
10
  componentsOption: TextRange | undefined;
11
11
  componentsOptionNode: ts.ObjectLiteralExpression | undefined;
12
12
  nameOption: TextRange | undefined;
13
+ inheritAttrsOption: string | undefined;
13
14
  }) | undefined;
14
15
  classBlockEnd: number | undefined;
15
16
  bindings: TextRange[];
@@ -25,6 +25,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
25
25
  if (obj) {
26
26
  let componentsOptionNode;
27
27
  let nameOptionNode;
28
+ let inheritAttrsOption;
28
29
  ts.forEachChild(obj, node => {
29
30
  if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
30
31
  const name = (0, scriptSetupRanges_1.getNodeText)(ts, node.name, ast);
@@ -34,6 +35,9 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
34
35
  if (name === 'name') {
35
36
  nameOptionNode = node.initializer;
36
37
  }
38
+ if (name === 'inheritAttrs') {
39
+ inheritAttrsOption = (0, scriptSetupRanges_1.getNodeText)(ts, node.initializer, ast);
40
+ }
37
41
  }
38
42
  });
39
43
  exportDefault = {
@@ -44,6 +48,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
44
48
  componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
45
49
  componentsOptionNode: withNode ? componentsOptionNode : undefined,
46
50
  nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
51
+ inheritAttrsOption,
47
52
  };
48
53
  }
49
54
  }
@@ -9,6 +9,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
9
9
  importComponentNames: Set<string>;
10
10
  props: {
11
11
  name?: string;
12
+ destructured?: string[];
12
13
  define?: ReturnType<(node: ts.CallExpression) => TextRange & {
13
14
  arg?: TextRange;
14
15
  typeArg?: TextRange;
@@ -43,18 +44,31 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
43
44
  typeArg?: TextRange;
44
45
  }>;
45
46
  };
47
+ options: {
48
+ name?: string;
49
+ inheritAttrs?: string;
50
+ };
51
+ cssModules: {
52
+ exp: TextRange;
53
+ arg?: TextRange;
54
+ }[];
46
55
  defineProp: {
56
+ localName: TextRange | undefined;
47
57
  name: TextRange | undefined;
48
- nameIsString: boolean;
49
58
  type: TextRange | undefined;
50
59
  modifierType?: TextRange | undefined;
60
+ runtimeType: TextRange | undefined;
51
61
  defaultValue: TextRange | undefined;
52
62
  required: boolean;
53
63
  isModel?: boolean;
54
64
  }[];
55
- options: {
65
+ templateRefs: {
56
66
  name?: string;
57
- };
67
+ define?: ReturnType<(node: ts.CallExpression) => TextRange & {
68
+ arg?: TextRange;
69
+ typeArg?: TextRange;
70
+ }>;
71
+ }[];
58
72
  };
59
73
  export declare function parseBindingRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile): TextRange[];
60
74
  export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, sourceFile: ts.SourceFile): TextRange[];