@vue/language-core 2.0.26 → 2.0.28

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 (41) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/script/component.js +1 -1
  4. package/lib/codegen/script/globalTypes.js +2 -8
  5. package/lib/codegen/script/index.js +11 -1
  6. package/lib/codegen/script/scriptSetup.js +40 -20
  7. package/lib/codegen/template/element.js +25 -26
  8. package/lib/codegen/template/elementChildren.js +1 -1
  9. package/lib/codegen/template/elementEvents.js +10 -1
  10. package/lib/codegen/template/elementProps.js +1 -1
  11. package/lib/codegen/template/objectKey.d.ts +1 -0
  12. package/lib/codegen/template/objectKey.js +34 -0
  13. package/lib/languageModule.js +4 -3
  14. package/lib/languagePlugin.d.ts +8 -0
  15. package/lib/languagePlugin.js +175 -0
  16. package/lib/plugins/file-dot-setup.d.ts +3 -0
  17. package/lib/plugins/file-dot-setup.js +34 -0
  18. package/lib/plugins/file-html.js +14 -3
  19. package/lib/plugins/file-md.js +14 -3
  20. package/lib/plugins/file-vue.js +14 -3
  21. package/lib/plugins/vue-script-js.js +1 -1
  22. package/lib/plugins/vue-sfc-customblocks.js +1 -1
  23. package/lib/plugins/vue-sfc-scripts.js +1 -1
  24. package/lib/plugins/vue-sfc-styles.js +1 -1
  25. package/lib/plugins/vue-sfc-template.js +1 -1
  26. package/lib/plugins/vue-template-html.js +1 -1
  27. package/lib/plugins/vue-template-inline-css.js +1 -1
  28. package/lib/plugins/vue-template-inline-ts.js +1 -1
  29. package/lib/plugins/vue-tsx.js +1 -1
  30. package/lib/plugins.d.ts +2 -26
  31. package/lib/plugins.js +24 -10
  32. package/lib/types.d.ts +15 -11
  33. package/lib/types.js +2 -2
  34. package/lib/utils/ts.js +7 -20
  35. package/lib/virtualFile/computedFiles.d.ts +2 -2
  36. package/lib/virtualFile/computedSfc.d.ts +2 -2
  37. package/lib/virtualFile/computedVueSfc.d.ts +2 -2
  38. package/lib/virtualFile/computedVueSfc.js +3 -2
  39. package/lib/virtualFile/vueFile.d.ts +3 -3
  40. package/lib/virtualFile/vueFile.js +1 -1
  41. package/package.json +4 -4
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './lib/codegen/template';
2
- export * from './lib/languageModule';
2
+ export * from './lib/languagePlugin';
3
3
  export * from './lib/parsers/scriptSetupRanges';
4
4
  export * from './lib/plugins';
5
5
  export * from './lib/virtualFile/vueFile';
package/index.js CHANGED
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.tsCodegen = exports.scriptRanges = void 0;
18
18
  __exportStar(require("./lib/codegen/template"), exports);
19
- __exportStar(require("./lib/languageModule"), exports);
19
+ __exportStar(require("./lib/languagePlugin"), exports);
20
20
  __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
21
21
  __exportStar(require("./lib/plugins"), exports);
22
22
  __exportStar(require("./lib/virtualFile/vueFile"), exports);
@@ -60,7 +60,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges) {
60
60
  if (options.vueCompilerOptions.target >= 3.5 && ctx.generatedPropsType) {
61
61
  yield `__typeProps: {} as __VLS_PublicProps,${common_1.newLine}`;
62
62
  }
63
- else {
63
+ if (options.vueCompilerOptions.target < 3.5 || !ctx.generatedPropsType || scriptSetupRanges.props.withDefaults) {
64
64
  const codegens = [];
65
65
  if (ctx.generatedPropsType) {
66
66
  codegens.push(function* () {
@@ -16,15 +16,8 @@ declare global {
16
16
  ? `import('${vueCompilerOptions.lib}/jsx-runtime').JSX.Element;`
17
17
  : `globalThis.JSX.Element;`}
18
18
  type __VLS_GlobalComponents = ${vueCompilerOptions.target >= 3.5
19
- ? `import('${vueCompilerOptions.lib}').GlobalComponents`
19
+ ? `import('${vueCompilerOptions.lib}').GlobalComponents;`
20
20
  : `import('${vueCompilerOptions.lib}').GlobalComponents & Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`}
21
- type __VLS_BuiltInPublicProps = ${vueCompilerOptions.target >= 3.4
22
- ? `import('${vueCompilerOptions.lib}').PublicProps;`
23
- : vueCompilerOptions.target >= 3.0
24
- ? `import('${vueCompilerOptions.lib}').VNodeProps
25
- & import('${vueCompilerOptions.lib}').AllowedComponentProps
26
- & import('${vueCompilerOptions.lib}').ComponentCustomProps;`
27
- : `globalThis.JSX.IntrinsicAttributes;`}
28
21
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
29
22
  type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
30
23
 
@@ -64,6 +57,7 @@ declare global {
64
57
  : T;
65
58
  function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
66
59
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
60
+ function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
67
61
 
68
62
  type __VLS_SelfComponent<N, C> = string extends N ? {} : N extends string ? { [P in N]: C } : {};
69
63
  type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
@@ -105,7 +105,17 @@ function* generateScript(options) {
105
105
  yield* generateDefineProp(options, options.sfc.scriptSetup);
106
106
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
107
107
  }
108
- yield common_1.endOfLine;
108
+ yield `;`;
109
+ if (options.sfc.scriptSetup) {
110
+ // #4569
111
+ yield [
112
+ '',
113
+ 'scriptSetup',
114
+ options.sfc.scriptSetup.content.length,
115
+ exports.codeFeatures.verification,
116
+ ];
117
+ }
118
+ yield common_1.newLine;
109
119
  if (options.globalTypes) {
110
120
  yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
111
121
  }
@@ -19,6 +19,15 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
19
19
  const definePropMirrors = new Map();
20
20
  if (scriptSetup.generic) {
21
21
  if (!options.scriptRanges?.exportDefault) {
22
+ if (options.sfc.scriptSetup) {
23
+ // #4569
24
+ yield [
25
+ '',
26
+ 'scriptSetup',
27
+ options.sfc.scriptSetup.content.length,
28
+ index_1.codeFeatures.verification,
29
+ ];
30
+ }
22
31
  yield `export default `;
23
32
  }
24
33
  yield `(<`;
@@ -32,8 +41,8 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
32
41
  yield `,`;
33
42
  }
34
43
  yield `>(${common_1.newLine}`
35
- + ` __VLS_props: Awaited<typeof __VLS_setup>['props'],${common_1.newLine}`
36
- + ` __VLS_ctx?: ${ctx.helperTypes.Prettify.name}<Pick<Awaited<typeof __VLS_setup>, 'attrs' | 'emit' | 'slots'>>,${common_1.newLine}` // use __VLS_Prettify for less dts code
44
+ + ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${common_1.newLine}`
45
+ + ` __VLS_ctx?: ${ctx.helperTypes.Prettify.name}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${common_1.newLine}` // use __VLS_Prettify for less dts code
37
46
  + ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${common_1.newLine}`
38
47
  + ` __VLS_setup = (async () => {${common_1.newLine}`;
39
48
  yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
@@ -233,6 +242,14 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
233
242
  }
234
243
  yield* (0, component_1.generateEmitsOption)(options, scriptSetup, scriptSetupRanges);
235
244
  yield `})${common_1.endOfLine}`;
245
+ yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
246
+ ? `import('${options.vueCompilerOptions.lib}').PublicProps;`
247
+ : options.vueCompilerOptions.target >= 3.0
248
+ ? `import('${options.vueCompilerOptions.lib}').VNodeProps
249
+ & import('${options.vueCompilerOptions.lib}').AllowedComponentProps
250
+ & import('${options.vueCompilerOptions.lib}').ComponentCustomProps;`
251
+ : `globalThis.JSX.IntrinsicAttributes;`}`;
252
+ yield common_1.endOfLine;
236
253
  yield `let __VLS_functionalComponentProps!: `;
237
254
  yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
238
255
  yield common_1.endOfLine;
@@ -272,6 +289,8 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
272
289
  if (defineProp.name && defineProp.nameIsString) {
273
290
  // renaming support
274
291
  yield (0, common_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, index_1.codeFeatures.navigation);
292
+ propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
293
+ propName = propName.replace(/['"]+/g, '');
275
294
  }
276
295
  else if (defineProp.name) {
277
296
  propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
@@ -284,18 +303,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
284
303
  yield defineProp.required
285
304
  ? `: `
286
305
  : `?: `;
287
- if (defineProp.type) {
288
- yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
289
- }
290
- else if (!defineProp.nameIsString) {
291
- yield `NonNullable<typeof ${propName}['value']>`;
292
- }
293
- else if (defineProp.defaultValue) {
294
- yield `typeof __VLS_defaults['${propName}']`;
295
- }
296
- else {
297
- yield `any`;
298
- }
306
+ yield* generateDefinePropType(scriptSetup, propName, defineProp);
299
307
  yield `,${common_1.newLine}`;
300
308
  if (defineProp.modifierType) {
301
309
  let propModifierName = 'modelModifiers';
@@ -339,12 +347,7 @@ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
339
347
  propName = propName.replace(/['"]+/g, '');
340
348
  }
341
349
  yield `'update:${propName}': [${propName}:`;
342
- if (defineProp.type) {
343
- yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
344
- }
345
- else {
346
- yield `any`;
347
- }
350
+ yield* generateDefinePropType(scriptSetup, propName, defineProp);
348
351
  yield `]${common_1.endOfLine}`;
349
352
  }
350
353
  yield `}`;
@@ -357,4 +360,21 @@ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
357
360
  }
358
361
  yield common_1.endOfLine;
359
362
  }
363
+ function* generateDefinePropType(scriptSetup, propName, defineProp) {
364
+ if (defineProp.type) {
365
+ // Infer from defineProp<T>
366
+ yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
367
+ }
368
+ else if ((defineProp.name && defineProp.nameIsString) || !defineProp.nameIsString) {
369
+ // Infer from actual prop declaration code
370
+ yield `NonNullable<typeof ${propName}['value']>`;
371
+ }
372
+ else if (defineProp.defaultValue) {
373
+ // Infer from defineProp({default: T})
374
+ yield `typeof __VLS_defaults['${propName}']`;
375
+ }
376
+ else {
377
+ yield `any`;
378
+ }
379
+ }
360
380
  //# sourceMappingURL=scriptSetup.js.map
@@ -16,6 +16,7 @@ const elementProps_1 = require("./elementProps");
16
16
  const interpolation_1 = require("./interpolation");
17
17
  const propertyAccess_1 = require("./propertyAccess");
18
18
  const templateChild_1 = require("./templateChild");
19
+ const objectProperty_1 = require("./objectProperty");
19
20
  const colonReg = /:/g;
20
21
  function* generateComponent(options, ctx, node, currentComponent, componentCtxVar) {
21
22
  const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
@@ -168,6 +169,13 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
168
169
  yield* generateVScope(options, ctx, node, props);
169
170
  ctx.usedComponentCtxVars.add(componentCtxVar);
170
171
  const usedComponentEventsVar = yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEmit, var_componentEvents);
172
+ if (var_defineComponentCtx && ctx.usedComponentCtxVars.has(var_defineComponentCtx)) {
173
+ yield `const ${componentCtxVar} = __VLS_nonNullable(__VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance}))${common_1.endOfLine}`;
174
+ }
175
+ if (usedComponentEventsVar) {
176
+ yield `let ${var_componentEmit}!: typeof ${componentCtxVar}.emit${common_1.endOfLine}`;
177
+ yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${common_1.endOfLine}`;
178
+ }
171
179
  const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
172
180
  if (slotDir) {
173
181
  yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
@@ -175,13 +183,6 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
175
183
  else {
176
184
  yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
177
185
  }
178
- if (var_defineComponentCtx && ctx.usedComponentCtxVars.has(var_defineComponentCtx)) {
179
- yield `const ${componentCtxVar} = __VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!${common_1.endOfLine}`;
180
- }
181
- if (usedComponentEventsVar) {
182
- yield `let ${var_componentEmit}!: typeof ${componentCtxVar}.emit${common_1.endOfLine}`;
183
- yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${common_1.endOfLine}`;
184
- }
185
186
  }
186
187
  function* generateElement(options, ctx, node, currentComponent, componentCtxVar) {
187
188
  const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
@@ -271,11 +272,23 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
271
272
  ctx.hasSlotElements.add(currentComponent);
272
273
  }
273
274
  const slotBlockVars = [];
274
- let hasProps = false;
275
+ yield `const {`;
276
+ if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
277
+ 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);
278
+ yield ': __VLS_thisSlot';
279
+ }
280
+ else {
281
+ yield `default: `;
282
+ yield* (0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
283
+ ? '#'.length
284
+ : slotDir.loc.source.startsWith('v-slot:')
285
+ ? 'v-slot:'.length
286
+ : 0), ctx.codeFeatures.withoutHighlightAndCompletion, `__VLS_thisSlot`);
287
+ }
288
+ yield `} = __VLS_nonNullable(${componentCtxVar}.slots)${common_1.endOfLine}`;
275
289
  if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
276
290
  const slotAst = (0, common_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
277
291
  (0, common_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
278
- hasProps = true;
279
292
  if (!slotDir.exp.content.includes(':')) {
280
293
  yield `const [`;
281
294
  yield [
@@ -284,7 +297,7 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
284
297
  slotDir.exp.loc.start.offset,
285
298
  ctx.codeFeatures.all,
286
299
  ];
287
- yield `] = __VLS_getSlotParams(`;
300
+ yield `] = __VLS_getSlotParams(__VLS_thisSlot)${common_1.endOfLine}`;
288
301
  }
289
302
  else {
290
303
  yield `const `;
@@ -294,23 +307,9 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
294
307
  slotDir.exp.loc.start.offset,
295
308
  ctx.codeFeatures.all,
296
309
  ];
297
- yield ` = __VLS_getSlotParam(`;
310
+ yield ` = __VLS_getSlotParam(__VLS_thisSlot)${common_1.endOfLine}`;
298
311
  }
299
312
  }
300
- yield* (0, common_1.wrapWith)((slotDir.arg ?? slotDir).loc.start.offset, (slotDir.arg ?? slotDir).loc.end.offset, ctx.codeFeatures.verification, `(${componentCtxVar}.slots!)`, ...(slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content
301
- ? (0, propertyAccess_1.generatePropertyAccess)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc)
302
- : [
303
- `.`,
304
- ...(0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
305
- ? '#'.length
306
- : slotDir.loc.source.startsWith('v-slot:')
307
- ? 'v-slot:'.length
308
- : 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`)
309
- ]));
310
- if (hasProps) {
311
- yield `)`;
312
- }
313
- yield common_1.endOfLine;
314
313
  for (const varName of slotBlockVars) {
315
314
  ctx.addLocalVariable(varName);
316
315
  }
@@ -328,7 +327,7 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
328
327
  isStatic = slotDir.arg.isStatic;
329
328
  }
330
329
  if (isStatic && slotDir && !slotDir.arg) {
331
- yield `${componentCtxVar}.slots!['`;
330
+ yield `__VLS_nonNullable(${componentCtxVar}.slots)['`;
332
331
  yield [
333
332
  '',
334
333
  'template',
@@ -18,7 +18,7 @@ function* generateElementChildren(options, ctx, node, currentComponent, componen
18
18
  && node.children.length
19
19
  && node.tagType !== CompilerDOM.ElementTypes.ELEMENT
20
20
  && node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
21
- yield `(${componentCtxVar}.slots!).`;
21
+ yield `__VLS_nonNullable(${componentCtxVar}.slots).`;
22
22
  yield* (0, common_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
23
23
  yield common_1.endOfLine;
24
24
  }
@@ -144,7 +144,7 @@ function isCompoundExpression(ts, ast) {
144
144
  if (ts.isArrowFunction(child_2)) {
145
145
  result = false;
146
146
  }
147
- else if (ts.isIdentifier(child_2)) {
147
+ else if (isPropertyAccessOrId(ts, child_2)) {
148
148
  result = false;
149
149
  }
150
150
  });
@@ -156,4 +156,13 @@ function isCompoundExpression(ts, ast) {
156
156
  }
157
157
  return result;
158
158
  }
159
+ function isPropertyAccessOrId(ts, node) {
160
+ if (ts.isIdentifier(node)) {
161
+ return true;
162
+ }
163
+ if (ts.isPropertyAccessExpression(node)) {
164
+ return isPropertyAccessOrId(ts, node.expression);
165
+ }
166
+ return false;
167
+ }
159
168
  //# sourceMappingURL=elementEvents.js.map
@@ -86,7 +86,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
86
86
  }
87
87
  : false,
88
88
  }, prop.loc.name_2 ?? (prop.loc.name_2 = {}), shouldCamelize)
89
- : [propName]), `: (`, ...genereatePropExp(options, ctx, prop.exp, ctx.codeFeatures.all, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
89
+ : (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...genereatePropExp(options, ctx, prop.exp, ctx.codeFeatures.all, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
90
90
  if (!enableCodeFeatures) {
91
91
  yield (0, muggle_string_1.toString)([...codes]);
92
92
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // import type { Code, VueCodeInformation } from '../../types';
3
+ // import type { TemplateCodegenContext } from './context';
4
+ // import type { TemplateCodegenOptions } from './index';
5
+ // import { generateInterpolation } from './interpolation';
6
+ // import { generateStringLiteralKey } from './stringLiteralKey';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ // export function* generateObjectKey(
9
+ // options: TemplateCodegenOptions,
10
+ // ctx: TemplateCodegenContext,
11
+ // code: string,
12
+ // offset: number,
13
+ // features: VueCodeInformation,
14
+ // astHolder?: any
15
+ // ): Generator<Code> {
16
+ // yield `[`;
17
+ // if (code.startsWith('[') && code.endsWith(']')) {
18
+ // yield* generateInterpolation(
19
+ // options,
20
+ // ctx,
21
+ // code.slice(1, -1),
22
+ // astHolder,
23
+ // offset + 1,
24
+ // features,
25
+ // '',
26
+ // ''
27
+ // );
28
+ // }
29
+ // else {
30
+ // yield* generateStringLiteralKey(code, offset, features)
31
+ // }
32
+ // yield `]`;
33
+ // }
34
+ //# sourceMappingURL=objectKey.js.map
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
+ /// <reference types="@volar/typescript" />
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.createVueLanguagePlugin = createVueLanguagePlugin;
4
5
  const language_core_1 = require("@volar/language-core");
5
- const plugins_1 = require("./plugins");
6
- const vueFile_1 = require("./virtualFile/vueFile");
7
6
  const CompilerDOM = require("@vue/compiler-dom");
8
- const CompilerVue2 = require("./utils/vue2TemplateCompiler");
7
+ const plugins_1 = require("./plugins");
9
8
  const file_html_1 = require("./plugins/file-html");
10
9
  const file_md_1 = require("./plugins/file-md");
11
10
  const file_vue_1 = require("./plugins/file-vue");
11
+ const CompilerVue2 = require("./utils/vue2TemplateCompiler");
12
+ const vueFile_1 = require("./virtualFile/vueFile");
12
13
  const normalFileRegistries = [];
13
14
  const holderFileRegistries = [];
14
15
  function getVueFileRegistry(isGlobalTypesHolder, key, plugins) {
@@ -0,0 +1,8 @@
1
+ import { type LanguagePlugin } from '@volar/language-core';
2
+ import type * as ts from 'typescript';
3
+ import type { VueCompilerOptions } from './types';
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>;
8
+ export declare function getAllExtensions(options: VueCompilerOptions): string[];
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ /// <reference types="@volar/typescript" />
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createRootFileChecker = createRootFileChecker;
5
+ exports.createVueLanguagePlugin = createVueLanguagePlugin;
6
+ exports.createVueLanguagePlugin2 = createVueLanguagePlugin2;
7
+ exports.getAllExtensions = getAllExtensions;
8
+ const language_core_1 = require("@volar/language-core");
9
+ const CompilerDOM = require("@vue/compiler-dom");
10
+ const plugins_1 = require("./plugins");
11
+ const CompilerVue2 = require("./utils/vue2TemplateCompiler");
12
+ const vueFile_1 = require("./virtualFile/vueFile");
13
+ const normalFileRegistries = [];
14
+ const holderFileRegistries = [];
15
+ function getVueFileRegistry(isGlobalTypesHolder, key, plugins) {
16
+ const fileRegistries = isGlobalTypesHolder ? holderFileRegistries : normalFileRegistries;
17
+ let fileRegistry = fileRegistries.find(r => r.key === key
18
+ && r.plugins.length === plugins.length
19
+ && r.plugins.every(plugin => plugins.includes(plugin)))?.files;
20
+ if (!fileRegistry) {
21
+ fileRegistry = new Map();
22
+ fileRegistries.push({
23
+ key: key,
24
+ plugins: plugins,
25
+ files: fileRegistry,
26
+ });
27
+ }
28
+ return fileRegistry;
29
+ }
30
+ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
31
+ const values = [
32
+ ...Object.keys(vueCompilerOptions)
33
+ .sort()
34
+ .filter(key => key !== 'plugins')
35
+ .map(key => [key, vueCompilerOptions[key]]),
36
+ [...new Set(plugins.map(plugin => plugin.requiredCompilerOptions ?? []).flat())]
37
+ .sort()
38
+ .map(key => [key, compilerOptions[key]]),
39
+ ];
40
+ return JSON.stringify(values);
41
+ }
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) {
61
+ const pluginContext = {
62
+ modules: {
63
+ '@vue/compiler-dom': vueCompilerOptions.target < 3
64
+ ? {
65
+ ...CompilerDOM,
66
+ compile: CompilerVue2.compile,
67
+ }
68
+ : CompilerDOM,
69
+ typescript: ts,
70
+ },
71
+ compilerOptions,
72
+ vueCompilerOptions,
73
+ globalTypesHolder: undefined,
74
+ };
75
+ const plugins = (0, plugins_1.createPlugins)(pluginContext);
76
+ return {
77
+ getLanguageId(scriptId) {
78
+ const fileName = asFileName(scriptId);
79
+ for (const plugin of plugins) {
80
+ const languageId = plugin.getLanguageId?.(fileName);
81
+ if (languageId) {
82
+ return languageId;
83
+ }
84
+ }
85
+ },
86
+ createVirtualCode(scriptId, languageId, snapshot) {
87
+ const fileName = asFileName(scriptId);
88
+ 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
+ const code = fileRegistry.get(fileName);
94
+ if (code) {
95
+ code.update(snapshot);
96
+ return code;
97
+ }
98
+ else {
99
+ const code = new vueFile_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
100
+ fileRegistry.set(fileName, code);
101
+ return code;
102
+ }
103
+ }
104
+ },
105
+ updateVirtualCode(_fileId, code, snapshot) {
106
+ code.update(snapshot);
107
+ return code;
108
+ },
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
+ typescript: {
134
+ extraFileExtensions: getAllExtensions(vueCompilerOptions)
135
+ .map(ext => ({
136
+ extension: ext.slice(1),
137
+ isMixedContent: true,
138
+ scriptKind: 7,
139
+ })),
140
+ getServiceScript(root) {
141
+ for (const code of (0, language_core_1.forEachEmbeddedCode)(root)) {
142
+ if (/script_(js|jsx|ts|tsx)/.test(code.id)) {
143
+ const lang = code.id.substring('script_'.length);
144
+ return {
145
+ code,
146
+ extension: '.' + lang,
147
+ scriptKind: lang === 'js' ? ts.ScriptKind.JS
148
+ : lang === 'jsx' ? ts.ScriptKind.JSX
149
+ : lang === 'tsx' ? ts.ScriptKind.TSX
150
+ : ts.ScriptKind.TS,
151
+ };
152
+ }
153
+ }
154
+ },
155
+ },
156
+ };
157
+ function getFileRegistry(isGlobalTypesHolder) {
158
+ return getVueFileRegistry(isGlobalTypesHolder, getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins), vueCompilerOptions.plugins);
159
+ }
160
+ }
161
+ function getAllExtensions(options) {
162
+ const result = new Set();
163
+ for (const key in options) {
164
+ if (key === 'extensions' || key.endsWith('Extensions')) {
165
+ const value = options[key];
166
+ if (Array.isArray(value) && value.every(v => typeof v === 'string')) {
167
+ for (const ext of value) {
168
+ result.add(ext);
169
+ }
170
+ }
171
+ }
172
+ }
173
+ return [...result];
174
+ }
175
+ //# sourceMappingURL=languagePlugin.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parseSfc_1 = require("../utils/parseSfc");
4
+ const jsxWrapper = ['<script setup lang="jsx">\n', '\n</script>'];
5
+ const tsxWrapper = ['<script setup lang="tsx">\n', '\n</script>'];
6
+ const plugin = _ctx => {
7
+ return {
8
+ version: 2.1,
9
+ isValidFile(fileName) {
10
+ return fileName.endsWith('.setup.jsx') || fileName.endsWith('.setup.tsx');
11
+ },
12
+ parseSFC2(fileName, _languageId, content) {
13
+ if (fileName.endsWith('.setup.jsx')) {
14
+ console.log('[Vue] parseSFC2', fileName);
15
+ return patchSFC((0, parseSfc_1.parse)(`${jsxWrapper[0]}${content}${jsxWrapper[1]}`));
16
+ }
17
+ if (fileName.endsWith('.setup.tsx')) {
18
+ console.log('[Vue] parseSFC2', fileName);
19
+ return patchSFC((0, parseSfc_1.parse)(`${tsxWrapper[0]}${content}${tsxWrapper[1]}`));
20
+ }
21
+ },
22
+ };
23
+ };
24
+ exports.default = plugin;
25
+ function patchSFC(sfc) {
26
+ sfc.descriptor.scriptSetup.loc.start.column -= jsxWrapper[0].length;
27
+ sfc.descriptor.scriptSetup.loc.start.offset -= jsxWrapper[0].length;
28
+ sfc.descriptor.scriptSetup.loc.end.offset -= jsxWrapper[0].length;
29
+ if (sfc.descriptor.scriptSetup.loc.end.line === sfc.descriptor.scriptSetup.loc.start.line) {
30
+ sfc.descriptor.scriptSetup.loc.end.column -= jsxWrapper[0].length;
31
+ }
32
+ return sfc;
33
+ }
34
+ //# sourceMappingURL=file-dot-setup.js.map
@@ -2,10 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const sfcBlockReg = /\<(script|style)\b([\s\S]*?)\>([\s\S]*?)\<\/\1\>/g;
4
4
  const langReg = /\blang\s*=\s*(['\"]?)(\S*)\b\1/;
5
- const plugin = () => {
5
+ const plugin = ({ vueCompilerOptions }) => {
6
6
  return {
7
- version: 2,
8
- parseSFC(fileName, content) {
7
+ version: 2.1,
8
+ getLanguageId(fileName) {
9
+ if (vueCompilerOptions.petiteVueExtensions.some(ext => fileName.endsWith(ext))) {
10
+ return 'html';
11
+ }
12
+ },
13
+ isValidFile(_fileName, languageId) {
14
+ return languageId === 'html';
15
+ },
16
+ parseSFC2(fileName, languageId, content) {
17
+ if (languageId !== 'html') {
18
+ return;
19
+ }
9
20
  let sfc = {
10
21
  descriptor: {
11
22
  filename: fileName,
@@ -11,10 +11,21 @@ const sfcBlockReg = /\<(script|style)\b[\s\S]*?\>([\s\S]*?)\<\/\1\>/g;
11
11
  const angleBracketReg = /\<\S*\:\S*\>/g;
12
12
  const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
13
13
  const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
14
- const plugin = () => {
14
+ const plugin = ({ vueCompilerOptions }) => {
15
15
  return {
16
- version: 2,
17
- parseSFC(_fileName, content) {
16
+ version: 2.1,
17
+ getLanguageId(fileName) {
18
+ if (vueCompilerOptions.vitePressExtensions.some(ext => fileName.endsWith(ext))) {
19
+ return 'markdown';
20
+ }
21
+ },
22
+ isValidFile(_fileName, languageId) {
23
+ return languageId === 'markdown';
24
+ },
25
+ parseSFC2(_fileName, languageId, content) {
26
+ if (languageId !== 'markdown') {
27
+ return;
28
+ }
18
29
  content = content
19
30
  // code block
20
31
  .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
@@ -1,10 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const parseSfc_1 = require("../utils/parseSfc");
4
- const plugin = _ctx => {
4
+ const plugin = ({ vueCompilerOptions }) => {
5
5
  return {
6
- version: 2,
7
- parseSFC(_fileName, content) {
6
+ version: 2.1,
7
+ getLanguageId(fileName) {
8
+ if (vueCompilerOptions.extensions.some(ext => fileName.endsWith(ext))) {
9
+ return 'vue';
10
+ }
11
+ },
12
+ isValidFile(_fileName, languageId) {
13
+ return languageId === 'vue';
14
+ },
15
+ parseSFC2(_fileName, languageId, content) {
16
+ if (languageId !== 'vue') {
17
+ return;
18
+ }
8
19
  return (0, parseSfc_1.parse)(content);
9
20
  },
10
21
  updateSFC(sfc, change) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = ({ modules }) => {
4
4
  return {
5
- version: 2,
5
+ version: 2.1,
6
6
  compileSFCScript(lang, script) {
7
7
  if (lang === 'js' || lang === 'ts' || lang === 'jsx' || lang === 'tsx') {
8
8
  const ts = modules.typescript;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
- version: 2,
6
+ version: 2.1,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
8
  return sfc.customBlocks.map((customBlock, i) => ({
9
9
  id: 'custom_block_' + i,
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = () => {
4
4
  return {
5
- version: 2,
5
+ version: 2.1,
6
6
  getEmbeddedCodes(_fileName, sfc) {
7
7
  const names = [];
8
8
  if (sfc.script) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
- version: 2,
6
+ version: 2.1,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
8
  const result = [];
9
9
  for (let i = 0; i < sfc.styles.length; i++) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
- version: 2,
6
+ version: 2.1,
7
7
  getEmbeddedCodes(_fileName, sfc) {
8
8
  if (sfc.template) {
9
9
  return [{
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = ({ modules }) => {
4
4
  return {
5
- version: 2,
5
+ version: 2.1,
6
6
  compileSFCTemplate(lang, template, options) {
7
7
  if (lang === 'html' || lang === 'md') {
8
8
  const compiler = modules['@vue/compiler-dom'];
@@ -10,7 +10,7 @@ const codeFeatures = {
10
10
  };
11
11
  const plugin = () => {
12
12
  return {
13
- version: 2,
13
+ version: 2.1,
14
14
  getEmbeddedCodes(_fileName, sfc) {
15
15
  if (!sfc.template?.ast) {
16
16
  return [];
@@ -22,7 +22,7 @@ const formatBrackets = {
22
22
  const plugin = ctx => {
23
23
  const parseds = new WeakMap();
24
24
  return {
25
- version: 2,
25
+ version: 2.1,
26
26
  getEmbeddedCodes(_fileName, sfc) {
27
27
  if (!sfc.template?.ast) {
28
28
  return [];
@@ -10,7 +10,7 @@ const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
10
10
  exports.tsCodegen = new WeakMap();
11
11
  const plugin = ctx => {
12
12
  return {
13
- version: 2,
13
+ version: 2.1,
14
14
  requiredCompilerOptions: [
15
15
  'noPropertyAccessFromIndexSignature',
16
16
  'exactOptionalPropertyTypes',
package/lib/plugins.d.ts CHANGED
@@ -1,27 +1,3 @@
1
- import { pluginVersion, type VueLanguagePlugin } from './types';
1
+ import { VueLanguagePlugin } from './types';
2
2
  export * from './plugins/shared';
3
- export declare function getBasePlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): {
4
- version: typeof pluginVersion;
5
- name?: string;
6
- order?: number;
7
- requiredCompilerOptions?: string[];
8
- parseSFC?(fileName: string, content: string): import("@vue/compiler-sfc").SFCParseResult | undefined;
9
- updateSFC?(oldResult: import("@vue/compiler-sfc").SFCParseResult, textChange: {
10
- start: number;
11
- end: number;
12
- newText: string;
13
- }): import("@vue/compiler-sfc").SFCParseResult | undefined;
14
- resolveTemplateCompilerOptions?(options: import("@vue/compiler-dom").CompilerOptions): import("@vue/compiler-dom").CompilerOptions;
15
- compileSFCScript?(lang: string, script: string): import("typescript").SourceFile | undefined;
16
- compileSFCTemplate?(lang: string, template: string, options: import("@vue/compiler-dom").CompilerOptions): import("@vue/compiler-dom").CodegenResult | undefined;
17
- updateSFCTemplate?(oldResult: import("@vue/compiler-dom").CodegenResult, textChange: {
18
- start: number;
19
- end: number;
20
- newText: string;
21
- }): import("@vue/compiler-dom").CodegenResult | undefined;
22
- getEmbeddedCodes?(fileName: string, sfc: import("./types").Sfc): {
23
- id: string;
24
- lang: string;
25
- }[];
26
- resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./types").VueEmbeddedCode): void;
27
- }[];
3
+ export declare function createPlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): import("./types").VueLanguagePluginReturn[];
package/lib/plugins.js CHANGED
@@ -14,20 +14,26 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getBasePlugins = getBasePlugins;
17
+ exports.createPlugins = createPlugins;
18
+ const file_html_1 = require("./plugins/file-html");
19
+ const file_md_1 = require("./plugins/file-md");
20
+ const file_vue_1 = require("./plugins/file-vue");
21
+ const vue_script_js_1 = require("./plugins/vue-script-js");
18
22
  const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
19
23
  const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
20
24
  const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
21
25
  const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
22
- const vue_script_js_1 = require("./plugins/vue-script-js");
23
26
  const vue_template_html_1 = require("./plugins/vue-template-html");
24
27
  const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
25
28
  const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
26
29
  const vue_tsx_1 = require("./plugins/vue-tsx");
27
30
  const types_1 = require("./types");
28
31
  __exportStar(require("./plugins/shared"), exports);
29
- function getBasePlugins(pluginContext) {
32
+ function createPlugins(pluginContext) {
30
33
  const plugins = [
34
+ file_vue_1.default,
35
+ file_md_1.default,
36
+ file_html_1.default,
31
37
  vue_script_js_1.default,
32
38
  vue_template_html_1.default,
33
39
  vue_template_inline_css_1.default,
@@ -40,28 +46,36 @@ function getBasePlugins(pluginContext) {
40
46
  ...pluginContext.vueCompilerOptions.plugins,
41
47
  ];
42
48
  const pluginInstances = plugins
43
- .map(plugin => {
49
+ .flatMap(plugin => {
44
50
  try {
45
51
  const instance = plugin(pluginContext);
46
- instance.name ??= plugin.__moduleName;
52
+ const moduleName = plugin.__moduleName;
53
+ if (Array.isArray(instance)) {
54
+ for (let i = 0; i < instance.length; i++) {
55
+ instance[i].name ??= `${moduleName} (${i})`;
56
+ }
57
+ }
58
+ else {
59
+ instance.name ??= moduleName;
60
+ }
47
61
  return instance;
48
62
  }
49
63
  catch (err) {
50
64
  console.warn('[Vue] Failed to create plugin', err);
51
65
  }
52
66
  })
53
- .filter((plugin) => !!plugin)
67
+ .filter(plugin => !!plugin)
54
68
  .sort((a, b) => {
55
69
  const aOrder = a.order ?? 0;
56
70
  const bOrder = b.order ?? 0;
57
71
  return aOrder - bOrder;
58
72
  });
59
73
  return pluginInstances.filter(plugin => {
60
- const valid = plugin.version === types_1.pluginVersion;
61
- if (!valid) {
62
- console.warn(`[Vue] Plugin ${JSON.stringify(plugin.name)} API version incompatible, expected "${types_1.pluginVersion}" but got "${plugin.version}".`);
74
+ if (!types_1.validVersions.includes(plugin.version)) {
75
+ console.warn(`[Vue] Plugin ${plugin.name} is not compatible with the current Vue language tools version. (version: ${plugin.version}, supported versions: ${JSON.stringify(types_1.validVersions)})`);
76
+ return false;
63
77
  }
64
- return valid;
78
+ return true;
65
79
  });
66
80
  }
67
81
  //# sourceMappingURL=plugins.js.map
package/lib/types.d.ts CHANGED
@@ -48,21 +48,16 @@ export interface VueCompilerOptions {
48
48
  experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
49
49
  experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
50
50
  }
51
- export declare const pluginVersion = 2;
52
- export type VueLanguagePlugin = (ctx: {
53
- modules: {
54
- typescript: typeof import('typescript');
55
- '@vue/compiler-dom': typeof import('@vue/compiler-dom');
56
- };
57
- compilerOptions: ts.CompilerOptions;
58
- vueCompilerOptions: VueCompilerOptions;
59
- globalTypesHolder: string | undefined;
60
- }) => {
61
- version: typeof pluginVersion;
51
+ export declare const validVersions: readonly [2, 2.1];
52
+ export type VueLanguagePluginReturn = {
53
+ version: typeof validVersions[number];
62
54
  name?: string;
63
55
  order?: number;
64
56
  requiredCompilerOptions?: string[];
57
+ getLanguageId?(fileName: string): string | undefined;
58
+ isValidFile?(fileName: string, languageId: string): boolean;
65
59
  parseSFC?(fileName: string, content: string): SFCParseResult | undefined;
60
+ parseSFC2?(fileName: string, languageId: string, content: string): SFCParseResult | undefined;
66
61
  updateSFC?(oldResult: SFCParseResult, textChange: {
67
62
  start: number;
68
63
  end: number;
@@ -82,6 +77,15 @@ export type VueLanguagePlugin = (ctx: {
82
77
  }[];
83
78
  resolveEmbeddedCode?(fileName: string, sfc: Sfc, embeddedFile: VueEmbeddedCode): void;
84
79
  };
80
+ export type VueLanguagePlugin = (ctx: {
81
+ modules: {
82
+ typescript: typeof import('typescript');
83
+ '@vue/compiler-dom': typeof import('@vue/compiler-dom');
84
+ };
85
+ compilerOptions: ts.CompilerOptions;
86
+ vueCompilerOptions: VueCompilerOptions;
87
+ globalTypesHolder: string | undefined;
88
+ }) => VueLanguagePluginReturn | VueLanguagePluginReturn[];
85
89
  export interface SfcBlock {
86
90
  name: string;
87
91
  start: number;
package/lib/types.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluginVersion = void 0;
4
- exports.pluginVersion = 2;
3
+ exports.validVersions = void 0;
4
+ exports.validVersions = [2, 2.1];
5
5
  //# sourceMappingURL=types.js.map
package/lib/utils/ts.js CHANGED
@@ -4,6 +4,7 @@ exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
4
4
  exports.createParsedCommandLine = createParsedCommandLine;
5
5
  exports.resolveVueCompilerOptions = resolveVueCompilerOptions;
6
6
  const path = require("path-browserify");
7
+ const languagePlugin_1 = require("../languagePlugin");
7
8
  function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, configFileName = rootDir + '/jsconfig.json') {
8
9
  const proxyHost = proxyParseConfigHostForExtendConfigPaths(parseConfigHost);
9
10
  ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName);
@@ -18,11 +19,8 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
18
19
  catch (err) { }
19
20
  }
20
21
  const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
21
- const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, [
22
- ...resolvedVueOptions.extensions,
23
- ...resolvedVueOptions.vitePressExtensions,
24
- ...resolvedVueOptions.petiteVueExtensions,
25
- ].map(extension => ({
22
+ const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
23
+ .map(extension => ({
26
24
  extension: extension.slice(1),
27
25
  isMixedContent: true,
28
26
  scriptKind: ts.ScriptKind.Deferred,
@@ -52,11 +50,8 @@ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
52
50
  catch (err) { }
53
51
  }
54
52
  const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
55
- const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, [
56
- ...resolvedVueOptions.extensions,
57
- ...resolvedVueOptions.vitePressExtensions,
58
- ...resolvedVueOptions.petiteVueExtensions,
59
- ].map(extension => ({
53
+ const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, (0, languagePlugin_1.getAllExtensions)(resolvedVueOptions)
54
+ .map(extension => ({
60
55
  extension: extension.slice(1),
61
56
  isMixedContent: true,
62
57
  scriptKind: ts.ScriptKind.Deferred,
@@ -129,14 +124,7 @@ function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
129
124
  const resolvedPath = resolvePath(pluginPath);
130
125
  if (resolvedPath) {
131
126
  const plugin = require(resolvedPath);
132
- if (Array.isArray(plugin)) {
133
- for (let i = 0; i < plugin.length; i++) {
134
- plugin[i].__moduleName = `${pluginPath} (${i})`;
135
- }
136
- }
137
- else {
138
- plugin.__moduleName = pluginPath;
139
- }
127
+ plugin.__moduleName = pluginPath;
140
128
  return plugin;
141
129
  }
142
130
  else {
@@ -147,8 +135,7 @@ function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
147
135
  console.warn('[Vue] Resolve plugin path failed:', pluginPath, error);
148
136
  }
149
137
  return [];
150
- })
151
- .flat(Infinity);
138
+ });
152
139
  result.plugins = plugins;
153
140
  }
154
141
  return result;
@@ -1,4 +1,4 @@
1
1
  import type { VirtualCode } from '@volar/language-core';
2
- import type { Sfc, VueLanguagePlugin } from '../types';
3
- export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc): () => VirtualCode[];
2
+ import type { Sfc, VueLanguagePluginReturn } from '../types';
3
+ export declare function computedFiles(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[];
4
4
  export declare function resolveCommonLanguageId(lang: string): string;
@@ -1,4 +1,4 @@
1
1
  import type { SFCParseResult } from '@vue/compiler-sfc';
2
2
  import type * as ts from 'typescript';
3
- import type { Sfc, VueLanguagePlugin } from '../types';
4
- export declare function computedSfc(ts: typeof import('typescript'), plugins: ReturnType<VueLanguagePlugin>[], fileName: string, snapshot: () => ts.IScriptSnapshot, parsed: () => SFCParseResult | undefined): Sfc;
3
+ import type { Sfc, VueLanguagePluginReturn } from '../types';
4
+ export declare function computedSfc(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, snapshot: () => ts.IScriptSnapshot, parsed: () => SFCParseResult | undefined): Sfc;
@@ -1,4 +1,4 @@
1
1
  import type { SFCParseResult } from '@vue/compiler-sfc';
2
2
  import type * as ts from 'typescript';
3
- import type { VueLanguagePlugin } from '../types';
4
- export declare function computedVueSfc(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, snapshot: () => ts.IScriptSnapshot): () => SFCParseResult | undefined;
3
+ import type { VueLanguagePluginReturn } from '../types';
4
+ export declare function computedVueSfc(plugins: VueLanguagePluginReturn[], fileName: string, languageId: string, snapshot: () => ts.IScriptSnapshot): () => SFCParseResult | undefined;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.computedVueSfc = computedVueSfc;
4
4
  const computeds_1 = require("computeds");
5
- function computedVueSfc(plugins, fileName, snapshot) {
5
+ function computedVueSfc(plugins, fileName, languageId, snapshot) {
6
6
  let cache;
7
7
  return (0, computeds_1.computed)(() => {
8
8
  // incremental update
@@ -23,7 +23,8 @@ function computedVueSfc(plugins, fileName, snapshot) {
23
23
  }
24
24
  }
25
25
  for (const plugin of plugins) {
26
- const sfc = plugin.parseSFC?.(fileName, snapshot().getText(0, snapshot().getLength()));
26
+ const sfc = plugin.parseSFC?.(fileName, snapshot().getText(0, snapshot().getLength()))
27
+ ?? plugin.parseSFC2?.(fileName, languageId, snapshot().getText(0, snapshot().getLength()));
27
28
  if (sfc) {
28
29
  if (!sfc.errors.length) {
29
30
  cache = {
@@ -1,13 +1,13 @@
1
1
  import type { VirtualCode } from '@volar/language-core';
2
2
  import { Signal } from 'computeds';
3
3
  import type * as ts from 'typescript';
4
- import type { VueCompilerOptions, VueLanguagePlugin } from '../types';
4
+ import type { VueCompilerOptions, VueLanguagePluginReturn } from '../types';
5
5
  export declare class VueVirtualCode implements VirtualCode {
6
6
  fileName: string;
7
7
  languageId: string;
8
8
  initSnapshot: ts.IScriptSnapshot;
9
9
  vueCompilerOptions: VueCompilerOptions;
10
- plugins: ReturnType<VueLanguagePlugin>[];
10
+ plugins: VueLanguagePluginReturn[];
11
11
  ts: typeof import('typescript');
12
12
  id: string;
13
13
  _snapshot: Signal<ts.IScriptSnapshot>;
@@ -18,6 +18,6 @@ export declare class VueVirtualCode implements VirtualCode {
18
18
  get embeddedCodes(): VirtualCode[];
19
19
  get snapshot(): ts.IScriptSnapshot;
20
20
  get mappings(): import("@volar/language-core").CodeMapping[];
21
- constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript'));
21
+ constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: VueLanguagePluginReturn[], ts: typeof import('typescript'));
22
22
  update(newSnapshot: ts.IScriptSnapshot): void;
23
23
  }
@@ -27,7 +27,7 @@ class VueVirtualCode {
27
27
  // sources
28
28
  this.id = 'main';
29
29
  // computeds
30
- this.getVueSfc = (0, computedVueSfc_1.computedVueSfc)(this.plugins, this.fileName, () => this._snapshot());
30
+ this.getVueSfc = (0, computedVueSfc_1.computedVueSfc)(this.plugins, this.fileName, this.languageId, () => this._snapshot());
31
31
  this.sfc = (0, computedSfc_1.computedSfc)(this.ts, this.plugins, this.fileName, () => this._snapshot(), this.getVueSfc);
32
32
  this.getMappings = (0, computedMappings_1.computedMappings)(() => this._snapshot(), this.sfc);
33
33
  this.getEmbeddedCodes = (0, computedFiles_1.computedFiles)(this.plugins, this.fileName, this.sfc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.0.26",
3
+ "version": "2.0.28",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-core"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "~2.4.0-alpha.15",
15
+ "@volar/language-core": "~2.4.0-alpha.18",
16
16
  "@vue/compiler-dom": "^3.4.0",
17
17
  "@vue/shared": "^3.4.0",
18
18
  "computeds": "^0.0.1",
@@ -25,7 +25,7 @@
25
25
  "@types/minimatch": "^5.1.2",
26
26
  "@types/node": "latest",
27
27
  "@types/path-browserify": "^1.0.1",
28
- "@volar/typescript": "~2.4.0-alpha.15",
28
+ "@volar/typescript": "~2.4.0-alpha.18",
29
29
  "@vue/compiler-sfc": "^3.4.0"
30
30
  },
31
31
  "peerDependencies": {
@@ -36,5 +36,5 @@
36
36
  "optional": true
37
37
  }
38
38
  },
39
- "gitHead": "47924f61e9409501d11ab04e9d3417cc5c86232c"
39
+ "gitHead": "0cdbd70996f4fc7ac8d511b0d9fdbe20b7a4f6a3"
40
40
  }