@vue/language-core 1.7.7 → 1.7.9

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.
@@ -56,7 +56,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
56
56
  WithTemplateSlots: false,
57
57
  PropsChildren: false,
58
58
  };
59
- codes.push('/* __vue_virtual_code_placeholder__ */\n');
59
+ codes.push(`/* ${Object.entries(vueCompilerOptions).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(', ')} */\n`);
60
60
  let generatedTemplate = false;
61
61
  generateSrc();
62
62
  generateScriptSetupImports();
@@ -281,73 +281,62 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
281
281
  codes.push(';\n');
282
282
  //#endregion
283
283
  //#region props
284
- if (scriptSetupRanges.propsRuntimeArg
285
- || scriptSetupRanges.defineProp.length) {
286
- if (scriptSetupRanges.propsRuntimeArg) {
287
- codes.push(`const __VLS_props = (new __VLS_publicComponent()).$props;\n`);
288
- }
289
- else if (scriptSetupRanges.defineProp.length) {
290
- codes.push(`const __VLS_defaults = {\n`);
291
- for (const defineProp of scriptSetupRanges.defineProp) {
292
- if (defineProp.defaultValue) {
293
- if (defineProp.name) {
294
- codes.push(sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end));
295
- }
296
- else {
297
- codes.push('modelValue');
298
- }
299
- codes.push(`: `);
300
- codes.push(sfc.scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end));
301
- codes.push(`,\n`);
302
- }
303
- }
304
- codes.push(`};\n`);
305
- codes.push(`let __VLS_props!: {\n`);
306
- for (const defineProp of scriptSetupRanges.defineProp) {
307
- let propName = 'modelValue';
284
+ if (scriptSetupRanges.defineProp.length) {
285
+ codes.push(`const __VLS_defaults = {\n`);
286
+ for (const defineProp of scriptSetupRanges.defineProp) {
287
+ if (defineProp.defaultValue) {
308
288
  if (defineProp.name) {
309
- propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
310
- const propMirrorStart = muggle.getLength(codes);
311
- definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length];
312
- }
313
- codes.push(`${propName}${defineProp.required ? '' : '?'}: `);
314
- if (defineProp.type) {
315
- codes.push(sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end));
316
- }
317
- else if (defineProp.defaultValue) {
318
- codes.push(`typeof __VLS_defaults['`);
319
- codes.push(propName);
320
- codes.push(`']`);
289
+ codes.push(sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end));
321
290
  }
322
291
  else {
323
- codes.push(`any`);
292
+ codes.push('modelValue');
324
293
  }
325
- codes.push(',\n');
294
+ codes.push(`: `);
295
+ codes.push(sfc.scriptSetup.content.substring(defineProp.defaultValue.start, defineProp.defaultValue.end));
296
+ codes.push(`,\n`);
326
297
  }
327
- codes.push(`};\n`);
328
- }
329
- if (scriptSetupRanges.slotsTypeArg && vueCompilerOptions.jsxSlots) {
330
- usedHelperTypes.PropsChildren = true;
331
- codes.push(` & __VLS_PropsChildren<`);
332
- addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
333
- codes.push(`>`);
334
298
  }
335
- codes.push(`;\n`);
299
+ codes.push(`};\n`);
336
300
  }
337
- else {
338
- codes.push(`const __VLS_props: {}`);
339
- if (scriptSetupRanges.slotsTypeArg && vueCompilerOptions.jsxSlots) {
340
- usedHelperTypes.PropsChildren = true;
341
- codes.push(` & __VLS_PropsChildren<`);
342
- addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
343
- codes.push(`>`);
344
- }
345
- if (scriptSetupRanges.propsTypeArg) {
346
- codes.push(' & ');
347
- addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
301
+ codes.push(`let __VLS_props!: {}`);
302
+ if (scriptSetupRanges.propsRuntimeArg) {
303
+ codes.push(` & InstanceType<typeof __VLS_publicComponent>['$props']`);
304
+ }
305
+ if (scriptSetupRanges.propsTypeArg) {
306
+ codes.push(` & `);
307
+ addVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
308
+ }
309
+ if (scriptSetupRanges.defineProp.length) {
310
+ codes.push(` & {\n`);
311
+ for (const defineProp of scriptSetupRanges.defineProp) {
312
+ let propName = 'modelValue';
313
+ if (defineProp.name) {
314
+ propName = sfc.scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
315
+ const propMirrorStart = muggle.getLength(codes);
316
+ definePropMirrors[propName] = [propMirrorStart, propMirrorStart + propName.length];
317
+ }
318
+ codes.push(`${propName}${defineProp.required ? '' : '?'}: `);
319
+ if (defineProp.type) {
320
+ codes.push(sfc.scriptSetup.content.substring(defineProp.type.start, defineProp.type.end));
321
+ }
322
+ else if (defineProp.defaultValue) {
323
+ codes.push(`typeof __VLS_defaults['`);
324
+ codes.push(propName);
325
+ codes.push(`']`);
326
+ }
327
+ else {
328
+ codes.push(`any`);
329
+ }
330
+ codes.push(',\n');
348
331
  }
349
- codes.push(`;\n`);
332
+ codes.push(`}`);
333
+ }
334
+ if (scriptSetupRanges.slotsTypeArg && vueCompilerOptions.jsxSlots) {
335
+ usedHelperTypes.PropsChildren = true;
336
+ codes.push(` & __VLS_PropsChildren<`);
337
+ addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
350
338
  }
339
+ codes.push(`;\n`);
351
340
  //#endregion
352
341
  //#region emits
353
342
  codes.push(`const __VLS_emit = `);
@@ -439,17 +428,8 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
439
428
  addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.withDefaultsArg.start, scriptSetupRanges.withDefaultsArg.end);
440
429
  codes.push(`);\n`);
441
430
  }
442
- if (scriptRanges?.exportDefault && scriptRanges.exportDefault.expression.start !== scriptRanges.exportDefault.args.start) {
443
- // use defineComponent() from user space code if it exist
444
- codes.push(`const __VLS_publicComponent = `);
445
- addVirtualCode('script', scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.args.start);
446
- codes.push(`{\n`);
447
- }
448
- else {
449
- codes.push(`const __VLS_publicComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
450
- }
451
- if (scriptSetupRanges.defineProp.length) {
452
- codes.push(`props: {} as {\n`);
431
+ if (!functional && scriptSetupRanges.defineProp.length) {
432
+ codes.push(`let __VLS_propsOption_defineProp!: {\n`);
453
433
  for (const defineProp of scriptSetupRanges.defineProp) {
454
434
  let propName = 'modelValue';
455
435
  if (defineProp.name && defineProp.nameIsString) {
@@ -480,14 +460,28 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
480
460
  codes.push(`import('${vueCompilerOptions.lib}').PropType<${type}>,\n`);
481
461
  }
482
462
  }
483
- codes.push(`},\n`);
463
+ codes.push(`};\n`);
464
+ }
465
+ if (scriptRanges?.exportDefault && scriptRanges.exportDefault.expression.start !== scriptRanges.exportDefault.args.start) {
466
+ // use defineComponent() from user space code if it exist
467
+ codes.push(`const __VLS_publicComponent = `);
468
+ addVirtualCode('script', scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.args.start);
469
+ codes.push(`{\n`);
470
+ }
471
+ else {
472
+ codes.push(`const __VLS_publicComponent = (await import('${vueCompilerOptions.lib}')).defineComponent({\n`);
484
473
  }
485
474
  if (!bypassDefineComponent) {
486
- if (scriptSetupRanges.propsRuntimeArg || scriptSetupRanges.propsTypeArg) {
487
- codes.push(`props: (`);
475
+ if (scriptSetupRanges.propsRuntimeArg || scriptSetupRanges.propsTypeArg || (!functional && scriptSetupRanges.defineProp.length)) {
476
+ codes.push(`props: {\n`);
477
+ if (scriptSetupRanges.propsRuntimeArg) {
478
+ codes.push('...');
479
+ addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
480
+ codes.push(',\n');
481
+ }
488
482
  if (scriptSetupRanges.propsTypeArg) {
489
483
  usedHelperTypes.DefinePropsToOptions = true;
490
- codes.push(`{} as `);
484
+ codes.push('...{} as ');
491
485
  if (scriptSetupRanges.withDefaultsArg) {
492
486
  usedHelperTypes.mergePropDefaults = true;
493
487
  codes.push(`__VLS_WithDefaults<`);
@@ -504,11 +498,12 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
504
498
  codes.push(`, typeof __VLS_withDefaultsArg`);
505
499
  codes.push(`>`);
506
500
  }
501
+ codes.push(',\n');
507
502
  }
508
- else if (scriptSetupRanges.propsRuntimeArg) {
509
- addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
503
+ if (!functional && scriptSetupRanges.defineProp.length) {
504
+ codes.push(`...__VLS_propsOption_defineProp,\n`);
510
505
  }
511
- codes.push(`),\n`);
506
+ codes.push(`},\n`);
512
507
  }
513
508
  if (scriptSetupRanges.emitsTypeArg) {
514
509
  usedHelperTypes.ConstructorOverloads = true;
@@ -144,7 +144,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
144
144
  }
145
145
  function generateComponentVars() {
146
146
  const data = {};
147
- codes.push(`let __VLS_templateComponents!: {}\n`);
147
+ codes.push(`let __VLS_templateComponents!: __VLS_IntrinsicElements\n`);
148
148
  for (const tagName in tagNames) {
149
149
  const isNamespacedTag = tagName.indexOf('.') >= 0;
150
150
  if (isNamespacedTag)
@@ -287,7 +287,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
287
287
  shouldReport: () => errors === 0,
288
288
  },
289
289
  },
290
- ], '\n{};\n');
290
+ ], '\n;\n');
291
291
  expectedErrorStart = undefined;
292
292
  expectedErrorNode = undefined;
293
293
  }
@@ -302,7 +302,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
302
302
  else if (commentText === '@vue-ignore') {
303
303
  ignoreStart = codes.length;
304
304
  }
305
- else if (commentText === '@vue-expected-error') {
305
+ else if (commentText === '@vue-expect-error') {
306
306
  expectedErrorStart = codes.length;
307
307
  expectedErrorNode = prevNode;
308
308
  }
@@ -605,7 +605,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
605
605
  'default',
606
606
  'template',
607
607
  [slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#') ? '#'.length : slotDir.loc.source.startsWith('v-slot:') ? 'v-slot:'.length : 0)],
608
- capabilitiesPresets.slotName,
608
+ { ...capabilitiesPresets.slotName, completion: false },
609
609
  ])), ['', 'template', (slotDir.arg ?? slotDir).loc.end.offset, capabilitiesPresets.diagnosticOnly]);
610
610
  if (hasProps) {
611
611
  codes.push(')');
@@ -1,5 +1,6 @@
1
1
  import type { Language } from '@volar/language-core';
2
+ import { VueFile } from './sourceFile';
2
3
  import { VueCompilerOptions } from './types';
3
4
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
- export declare function createLanguage(compilerOptions?: ts.CompilerOptions, _vueCompilerOptions?: Partial<VueCompilerOptions>, ts?: typeof import('typescript/lib/tsserverlibrary'), codegenStack?: boolean): Language;
5
+ export declare function createLanguage(compilerOptions?: ts.CompilerOptions, _vueCompilerOptions?: Partial<VueCompilerOptions>, ts?: typeof import('typescript/lib/tsserverlibrary'), codegenStack?: boolean): Language<VueFile>;
5
6
  export declare function createLanguages(compilerOptions?: ts.CompilerOptions, vueCompilerOptions?: Partial<VueCompilerOptions>, ts?: typeof import('typescript/lib/tsserverlibrary'), codegenStack?: boolean): Language[];
@@ -10,7 +10,6 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
10
10
  const vueCompilerOptions = (0, ts_1.resolveVueCompilerOptions)(_vueCompilerOptions);
11
11
  patchResolveModuleNames(ts, vueCompilerOptions);
12
12
  const vueLanguagePlugin = (0, plugins_1.getDefaultVueLanguagePlugins)(ts, compilerOptions, vueCompilerOptions, codegenStack);
13
- const sharedTypesSnapshot = ts.ScriptSnapshot.fromString(sharedTypes.getTypesCode(vueCompilerOptions));
14
13
  const languageModule = {
15
14
  createVirtualFile(fileName, snapshot, languageId) {
16
15
  if (languageId === 'vue'
@@ -23,31 +22,18 @@ function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = req
23
22
  sourceFile.update(snapshot);
24
23
  },
25
24
  resolveHost(host) {
25
+ const sharedTypesSnapshot = ts.ScriptSnapshot.fromString(sharedTypes.getTypesCode(vueCompilerOptions));
26
+ const sharedTypesFileName = path_1.posix.join(host.getCurrentDirectory(), sharedTypes.baseName);
26
27
  return {
27
28
  ...host,
28
- fileExists(fileName) {
29
- const basename = path_1.posix.basename(fileName);
30
- if (basename === sharedTypes.baseName) {
31
- return true;
32
- }
33
- return host.fileExists(fileName);
34
- },
35
29
  getScriptFileNames() {
36
30
  return [
37
- path_1.posix.join(host.getCurrentDirectory(), sharedTypes.baseName),
31
+ sharedTypesFileName,
38
32
  ...host.getScriptFileNames(),
39
33
  ];
40
34
  },
41
- getScriptVersion(fileName) {
42
- const basename = path_1.posix.basename(fileName);
43
- if (basename === sharedTypes.baseName) {
44
- return '';
45
- }
46
- return host.getScriptVersion(fileName);
47
- },
48
35
  getScriptSnapshot(fileName) {
49
- const basename = path_1.posix.basename(fileName);
50
- if (basename === sharedTypes.baseName) {
36
+ if (fileName === sharedTypesFileName) {
51
37
  return sharedTypesSnapshot;
52
38
  }
53
39
  return host.getScriptSnapshot(fileName);
@@ -5,7 +5,10 @@ const plugin = ({ modules }) => {
5
5
  compileSFCTemplate(lang, template, options) {
6
6
  if (lang === 'html') {
7
7
  const compiler = modules['@vue/compiler-dom'];
8
- return compiler.compile(template, options);
8
+ return compiler.compile(template, {
9
+ ...options,
10
+ comments: true,
11
+ });
9
12
  }
10
13
  },
11
14
  updateSFCTemplate(oldResult, change) {
@@ -62,12 +62,10 @@ declare function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
62
62
 
63
63
  type __VLS_SelfComponent<N, C> = string extends N ? {} : N extends string ? { [P in N]: C } : {};
64
64
  type __VLS_WithComponent<N0 extends string, Components, N1 extends string, N2 extends string, N3 extends string> =
65
- __VLS_IsAny<__VLS_IntrinsicElements[N0]> extends true ? (
66
- N1 extends keyof Components ? N1 extends N0 ? Pick<Components, N0> : { [K in N0]: Components[N1] } :
67
- N2 extends keyof Components ? N2 extends N0 ? Pick<Components, N0> : { [K in N0]: Components[N2] } :
68
- N3 extends keyof Components ? N3 extends N0 ? Pick<Components, N0> : { [K in N0]: Components[N3] } :
69
- ${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: any }'}
70
- ) : Pick<__VLS_IntrinsicElements, N0>;
65
+ N1 extends keyof Components ? N1 extends N0 ? Pick<Components, N0> : { [K in N0]: Components[N1] } :
66
+ N2 extends keyof Components ? N2 extends N0 ? Pick<Components, N0> : { [K in N0]: Components[N2] } :
67
+ N3 extends keyof Components ? N3 extends N0 ? Pick<Components, N0> : { [K in N0]: Components[N3] } :
68
+ ${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
71
69
 
72
70
  type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
73
71
  type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
@@ -100,7 +98,7 @@ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any)
100
98
  }) => JSX.Element & { __ctx?: typeof ctx & { props?: typeof props; expose?(exposed: K): void; } }
101
99
  : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
102
100
  : T extends (...args: any) => any ? T
103
- : (_: T extends import('${vueCompilerOptions.lib}').VNode | import('${vueCompilerOptions.lib}').VNode[] | string ? {}: T & Record<string, unknown>, ctx?: any) => { __ctx?: { attrs?: unknown, expose?: unknown, slots?: unknown, emit?: unknown, props?: T & Record<string, unknown> } }; // IntrinsicElement
101
+ : (_: T extends import('${vueCompilerOptions.lib}').VNode | import('${vueCompilerOptions.lib}').VNode[] | string ? {}: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } }; // IntrinsicElement
104
102
  declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
105
103
  declare function __VLS_pickEvent<Emit, K, E>(emit: Emit, emitKey: K, event: E): __VLS_FillingEventArg<
106
104
  __VLS_PickNotAny<
package/out/utils/ts.js CHANGED
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveVueCompilerOptions = exports.createParsedCommandLine = exports.createParsedCommandLineByJson = void 0;
4
4
  const path = require("path");
5
5
  function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json) {
6
- const tsConfigPath = path.join(rootDir, 'jsconfig.json');
7
6
  const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
8
- ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, tsConfigPath);
7
+ ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, rootDir + '/jsconfig.json');
9
8
  let vueOptions = {};
10
9
  for (const extendPath of proxyHost.extendConfigPaths.reverse()) {
11
10
  try {
@@ -16,7 +15,7 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json) {
16
15
  }
17
16
  catch (err) { }
18
17
  }
19
- const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, (vueOptions.extensions ?? ['.vue']).map(extension => ({
18
+ const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, rootDir + '/jsconfig.json', undefined, (vueOptions.extensions ?? ['.vue']).map(extension => ({
20
19
  extension: extension.slice(1),
21
20
  isMixedContent: true,
22
21
  scriptKind: ts.ScriptKind.Deferred,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.7.7",
3
+ "version": "1.7.9",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,8 +13,8 @@
13
13
  "directory": "packages/vue-language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.6.9",
17
- "@volar/source-map": "1.6.9",
16
+ "@volar/language-core": "1.7.3",
17
+ "@volar/source-map": "1.7.3",
18
18
  "@vue/compiler-dom": "^3.3.0",
19
19
  "@vue/reactivity": "^3.3.0",
20
20
  "@vue/shared": "^3.3.0",
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "0e9411252a4fa30cc999e30acc5db0d126c33daf"
37
+ "gitHead": "70f9ebedbc55a8d342ec425cc483dfe39c4b7489"
38
38
  }