@vue/language-core 3.0.0-alpha.6 → 3.0.0-beta.1

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 (38) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/codegen/codeFeatures.d.ts +5 -0
  4. package/lib/codegen/codeFeatures.js +5 -0
  5. package/lib/codegen/globalTypes.js +2 -5
  6. package/lib/codegen/localTypes.js +1 -2
  7. package/lib/codegen/script/component.js +1 -1
  8. package/lib/codegen/script/index.js +1 -14
  9. package/lib/codegen/script/scriptSetup.js +40 -79
  10. package/lib/codegen/style/imports.d.ts +2 -0
  11. package/lib/codegen/style/imports.js +27 -0
  12. package/lib/codegen/style/modules.js +10 -2
  13. package/lib/codegen/style/scopedClasses.js +6 -2
  14. package/lib/codegen/template/context.d.ts +1 -0
  15. package/lib/codegen/template/element.js +1 -3
  16. package/lib/codegen/template/elementProps.js +2 -6
  17. package/lib/codegen/template/index.js +2 -4
  18. package/lib/codegen/template/interpolation.js +3 -1
  19. package/lib/languagePlugin.js +1 -7
  20. package/lib/parsers/scriptRanges.d.ts +2 -3
  21. package/lib/parsers/scriptRanges.js +3 -10
  22. package/lib/parsers/scriptSetupRanges.d.ts +3 -3
  23. package/lib/parsers/scriptSetupRanges.js +32 -56
  24. package/lib/plugins/file-md.js +3 -0
  25. package/lib/plugins/vue-tsx.d.ts +3 -4
  26. package/lib/plugins/vue-tsx.js +1 -1
  27. package/lib/types.d.ts +10 -4
  28. package/lib/utils/parseCssImports.d.ts +4 -0
  29. package/lib/utils/parseCssImports.js +19 -0
  30. package/lib/utils/shared.d.ts +0 -1
  31. package/lib/utils/shared.js +0 -4
  32. package/lib/utils/ts.js +5 -6
  33. package/lib/virtualFile/computedSfc.js +9 -4
  34. package/package.json +6 -8
  35. package/lib/plugins/vue-style-css.d.ts +0 -3
  36. package/lib/plugins/vue-style-css.js +0 -18
  37. package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
  38. package/lib/utils/vue2TemplateCompiler.js +0 -89
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './lib/codegen/globalTypes';
2
2
  export * from './lib/codegen/template';
3
+ export * from './lib/codegen/utils';
3
4
  export * from './lib/languagePlugin';
4
5
  export * from './lib/parsers/scriptSetupRanges';
5
6
  export * from './lib/plugins';
package/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.tsCodegen = void 0;
18
18
  __exportStar(require("./lib/codegen/globalTypes"), exports);
19
19
  __exportStar(require("./lib/codegen/template"), exports);
20
+ __exportStar(require("./lib/codegen/utils"), exports);
20
21
  __exportStar(require("./lib/languagePlugin"), exports);
21
22
  __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
22
23
  __exportStar(require("./lib/plugins"), exports);
@@ -78,6 +78,11 @@ declare const raw: {
78
78
  };
79
79
  verification: true;
80
80
  };
81
+ withoutSemantic: {
82
+ verification: true;
83
+ navigation: true;
84
+ completion: true;
85
+ };
81
86
  };
82
87
  export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
83
88
  export {};
@@ -66,6 +66,11 @@ const raw = {
66
66
  semantic: { shouldHighlight: () => false },
67
67
  verification: true,
68
68
  },
69
+ withoutSemantic: {
70
+ verification: true,
71
+ navigation: true,
72
+ completion: true,
73
+ },
69
74
  };
70
75
  exports.codeFeatures = raw;
71
76
  //# sourceMappingURL=codeFeatures.js.map
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGlobalTypesFileName = getGlobalTypesFileName;
4
4
  exports.generateGlobalTypes = generateGlobalTypes;
5
- const shared_1 = require("../utils/shared");
6
5
  function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
7
6
  return [
8
7
  lib,
@@ -62,7 +61,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
62
61
  type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
63
62
  __ctx?: {
64
63
  attrs?: any,
65
- slots?: T extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : Record<string, any>,
64
+ slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>,
66
65
  emit?: T extends { $emit: infer Emit } ? Emit : {},
67
66
  props?: ${fnPropsType},
68
67
  expose?: (exposed: T) => void,
@@ -150,9 +149,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
150
149
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
151
150
  function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
152
151
  T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
153
- : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>${(target === 2.7
154
- ? `: T extends import('${lib}').AsyncComponent ? (props: {}, ctx?: any) => any`
155
- : ``)}
152
+ : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
156
153
  : T extends (...args: any) => any ? T
157
154
  : __VLS_FunctionalComponent<{}>;
158
155
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLocalTypesGenerator = getLocalTypesGenerator;
4
- const shared_1 = require("../utils/shared");
5
4
  const utils_1 = require("./utils");
6
5
  function getLocalTypesGenerator(vueCompilerOptions) {
7
6
  const used = new Set();
@@ -21,7 +20,7 @@ type __VLS_WithDefaults<P, D> = {
21
20
  const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
22
21
  type __VLS_WithSlots<T, S> = T & {
23
22
  new(): {
24
- ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;
23
+ $slots: S;
25
24
  ${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
26
25
  }
27
26
  };
@@ -60,7 +60,7 @@ function* generateComponentSetupReturns(scriptSetupRanges) {
60
60
  }
61
61
  function* generateEmitsOption(options, scriptSetupRanges) {
62
62
  const codes = [];
63
- if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
63
+ if (scriptSetupRanges.defineModel.length) {
64
64
  codes.push({
65
65
  optionExp: `{} as __VLS_NormalizeEmits<typeof __VLS_modelEmit>`,
66
66
  typeOptionType: `__VLS_ModelEmit`,
@@ -36,7 +36,7 @@ function* generateScript(options) {
36
36
  yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
37
37
  }
38
38
  if (options.sfc.script && options.scriptRanges) {
39
- const { exportDefault, classBlockEnd } = options.scriptRanges;
39
+ const { exportDefault } = options.scriptRanges;
40
40
  const isExportRawObject = exportDefault
41
41
  && options.sfc.script.content[exportDefault.expression.start] === '{';
42
42
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
@@ -77,19 +77,6 @@ function* generateScript(options) {
77
77
  yield options.vueCompilerOptions.optionsWrapper[1];
78
78
  yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
79
79
  }
80
- else if (classBlockEnd !== undefined) {
81
- if (options.vueCompilerOptions.skipTemplateCodegen) {
82
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
83
- }
84
- else {
85
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, codeFeatures_1.codeFeatures.all);
86
- yield `__VLS_template = () => {${utils_1.newLine}`;
87
- const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
88
- yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
89
- yield `}${utils_1.endOfLine}`;
90
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
91
- }
92
- }
93
80
  else {
94
81
  yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
95
82
  yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
@@ -50,7 +50,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
50
50
  if (scriptSetupRanges.defineEmits) {
51
51
  emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'}`);
52
52
  }
53
- if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
53
+ if (scriptSetupRanges.defineModel.length) {
54
54
  emitTypes.push(`typeof __VLS_modelEmit`);
55
55
  }
56
56
  yield `return {} as {${utils_1.newLine}`
@@ -187,7 +187,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
187
187
  const templateRefType = arg
188
188
  ? [
189
189
  `__VLS_TemplateRefs[`,
190
- (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
190
+ (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic),
191
191
  `]`
192
192
  ]
193
193
  : [`unknown`];
@@ -235,7 +235,6 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
235
235
  yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
236
236
  yield* (0, index_1.generateScriptSectionPartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
237
237
  yield* generateMacros(options, ctx);
238
- yield* generateDefineProp(options);
239
238
  if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
240
239
  // fix https://github.com/vuejs/language-tools/issues/1187
241
240
  yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
@@ -276,22 +275,6 @@ function* generateMacros(options, ctx) {
276
275
  yield `}: typeof import('${options.vueCompilerOptions.lib}')${utils_1.endOfLine}`;
277
276
  }
278
277
  }
279
- function* generateDefineProp(options) {
280
- const definePropProposalA = options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
281
- const definePropProposalB = options.vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
282
- if (definePropProposalA || definePropProposalB) {
283
- yield `type __VLS_PropOptions<T> = Exclude<import('${options.vueCompilerOptions.lib}').Prop<T>, import('${options.vueCompilerOptions.lib}').PropType<T>>${utils_1.endOfLine}`;
284
- if (definePropProposalA) {
285
- yield `declare function defineProp<T>(name: string, options: ({ required: true } | { default: T }) & __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${utils_1.endOfLine}`;
286
- yield `declare function defineProp<T>(name?: string, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${utils_1.endOfLine}`;
287
- }
288
- if (definePropProposalB) {
289
- yield `declare function defineProp<T>(value: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${utils_1.endOfLine}`;
290
- yield `declare function defineProp<T>(value: T | (() => T) | undefined, required: true, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T>${utils_1.endOfLine}`;
291
- yield `declare function defineProp<T>(value?: T | (() => T), required?: boolean, options?: __VLS_PropOptions<T>): import('${options.vueCompilerOptions.lib}').ComputedRef<T | undefined>${utils_1.endOfLine}`;
292
- }
293
- }
294
- }
295
278
  function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
296
279
  if (typeArg) {
297
280
  yield [[
@@ -340,34 +323,23 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
340
323
  yield `})${utils_1.endOfLine}`;
341
324
  yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
342
325
  ? `import('${options.vueCompilerOptions.lib}').PublicProps`
343
- : options.vueCompilerOptions.target >= 3.0
344
- ? `import('${options.vueCompilerOptions.lib}').VNodeProps`
345
- + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
346
- + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
347
- : `globalThis.JSX.IntrinsicAttributes`}`;
326
+ : `import('${options.vueCompilerOptions.lib}').VNodeProps`
327
+ + ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
328
+ + ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`}`;
348
329
  yield utils_1.endOfLine;
349
330
  yield `type __VLS_OwnProps = `;
350
331
  yield `${ctx.localTypes.OmitKeepDiscriminatedUnion}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
351
332
  yield utils_1.endOfLine;
352
333
  }
353
- if (scriptSetupRanges.defineProp.length) {
334
+ if (scriptSetupRanges.defineModel.length) {
354
335
  yield `const __VLS_defaults = {${utils_1.newLine}`;
355
- for (const defineProp of scriptSetupRanges.defineProp) {
356
- if (!defineProp.defaultValue) {
357
- continue;
358
- }
359
- const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
360
- if (defineProp.name || defineProp.isModel) {
361
- yield `'${propName}'`;
362
- }
363
- else if (defineProp.localName) {
364
- yield localName;
365
- }
366
- else {
336
+ for (const defineModel of scriptSetupRanges.defineModel) {
337
+ if (!defineModel.defaultValue) {
367
338
  continue;
368
339
  }
369
- yield `: `;
370
- yield getRangeText(scriptSetup, defineProp.defaultValue);
340
+ const [propName] = getPropAndLocalName(scriptSetup, defineModel);
341
+ yield `'${propName}': `;
342
+ yield getRangeText(scriptSetup, defineModel.defaultValue);
371
343
  yield `,${utils_1.newLine}`;
372
344
  }
373
345
  yield `}${utils_1.endOfLine}`;
@@ -387,38 +359,30 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
387
359
  ctx.generatedPropsType = true;
388
360
  yield `__VLS_Props`;
389
361
  }
390
- if (scriptSetupRanges.defineProp.length) {
362
+ if (scriptSetupRanges.defineModel.length) {
391
363
  if (ctx.generatedPropsType) {
392
364
  yield ` & `;
393
365
  }
394
366
  ctx.generatedPropsType = true;
395
367
  yield `{${utils_1.newLine}`;
396
- for (const defineProp of scriptSetupRanges.defineProp) {
397
- const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
398
- if (defineProp.comments) {
399
- yield scriptSetup.content.slice(defineProp.comments.start, defineProp.comments.end);
368
+ for (const defineModel of scriptSetupRanges.defineModel) {
369
+ const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
370
+ if (defineModel.comments) {
371
+ yield scriptSetup.content.slice(defineModel.comments.start, defineModel.comments.end);
400
372
  yield utils_1.newLine;
401
373
  }
402
- if (defineProp.isModel && !defineProp.name) {
403
- yield propName;
404
- }
405
- else if (defineProp.name) {
406
- yield* (0, camelized_1.generateCamelized)(getRangeText(scriptSetup, defineProp.name), scriptSetup.name, defineProp.name.start, codeFeatures_1.codeFeatures.navigation);
407
- }
408
- else if (defineProp.localName) {
409
- yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end, codeFeatures_1.codeFeatures.navigation);
374
+ if (defineModel.name) {
375
+ yield* (0, camelized_1.generateCamelized)(getRangeText(scriptSetup, defineModel.name), scriptSetup.name, defineModel.name.start, codeFeatures_1.codeFeatures.navigation);
410
376
  }
411
377
  else {
412
- continue;
378
+ yield propName;
413
379
  }
414
- yield defineProp.required
415
- ? `: `
416
- : `?: `;
417
- yield* generateDefinePropType(scriptSetup, propName, localName, defineProp);
380
+ yield defineModel.required ? `: ` : `?: `;
381
+ yield* generateDefineModelType(scriptSetup, propName, localName, defineModel);
418
382
  yield `,${utils_1.newLine}`;
419
- if (defineProp.modifierType) {
420
- const modifierName = `${defineProp.name ? propName : 'model'}Modifiers`;
421
- const modifierType = getRangeText(scriptSetup, defineProp.modifierType);
383
+ if (defineModel.modifierType) {
384
+ const modifierName = `${defineModel.name ? propName : 'model'}Modifiers`;
385
+ const modifierType = getRangeText(scriptSetup, defineModel.modifierType);
422
386
  yield `'${modifierName}'?: Partial<Record<${modifierType}, true>>,${utils_1.newLine}`;
423
387
  }
424
388
  }
@@ -430,13 +394,12 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
430
394
  yield utils_1.endOfLine;
431
395
  }
432
396
  function* generateModelEmit(scriptSetup, scriptSetupRanges) {
433
- const defineModels = scriptSetupRanges.defineProp.filter(p => p.isModel);
434
- if (defineModels.length) {
397
+ if (scriptSetupRanges.defineModel.length) {
435
398
  yield `type __VLS_ModelEmit = {${utils_1.newLine}`;
436
- for (const defineModel of defineModels) {
399
+ for (const defineModel of scriptSetupRanges.defineModel) {
437
400
  const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
438
401
  yield `'update:${propName}': [value: `;
439
- yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
402
+ yield* generateDefineModelType(scriptSetup, propName, localName, defineModel);
440
403
  if (!defineModel.required && !defineModel.defaultValue) {
441
404
  yield ` | undefined`;
442
405
  }
@@ -446,32 +409,30 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
446
409
  yield `const __VLS_modelEmit = defineEmits<__VLS_ModelEmit>()${utils_1.endOfLine}`;
447
410
  }
448
411
  }
449
- function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
450
- if (defineProp.type) {
451
- // Infer from defineProp<T>
452
- yield getRangeText(scriptSetup, defineProp.type);
412
+ function* generateDefineModelType(scriptSetup, propName, localName, defineModel) {
413
+ if (defineModel.type) {
414
+ // Infer from defineModel<T>
415
+ yield getRangeText(scriptSetup, defineModel.type);
453
416
  }
454
- else if (defineProp.runtimeType && localName) {
417
+ else if (defineModel.runtimeType && localName) {
455
418
  // Infer from actual prop declaration code
456
419
  yield `typeof ${localName}['value']`;
457
420
  }
458
- else if (defineProp.defaultValue && propName) {
459
- // Infer from defineProp({default: T})
421
+ else if (defineModel.defaultValue && propName) {
422
+ // Infer from defineModel({default: T})
460
423
  yield `typeof __VLS_defaults['${propName}']`;
461
424
  }
462
425
  else {
463
426
  yield `any`;
464
427
  }
465
428
  }
466
- function getPropAndLocalName(scriptSetup, defineProp) {
467
- const localName = defineProp.localName
468
- ? getRangeText(scriptSetup, defineProp.localName)
429
+ function getPropAndLocalName(scriptSetup, defineModel) {
430
+ const localName = defineModel.localName
431
+ ? getRangeText(scriptSetup, defineModel.localName)
469
432
  : undefined;
470
- const propName = defineProp.name
471
- ? (0, shared_1.camelize)(getRangeText(scriptSetup, defineProp.name).slice(1, -1))
472
- : defineProp.isModel
473
- ? 'modelValue'
474
- : localName;
433
+ const propName = defineModel.name
434
+ ? (0, shared_1.camelize)(getRangeText(scriptSetup, defineModel.name).slice(1, -1))
435
+ : 'modelValue';
475
436
  return [propName, localName];
476
437
  }
477
438
  function getRangeText(scriptSetup, range) {
@@ -0,0 +1,2 @@
1
+ import type { Code, Sfc } from '../../types';
2
+ export declare function generateStyleImports(style: Sfc['styles'][number]): Generator<Code>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStyleImports = generateStyleImports;
4
+ const utils_1 = require("../utils");
5
+ const wrapWith_1 = require("../utils/wrapWith");
6
+ function* generateStyleImports(style) {
7
+ const features = {
8
+ navigation: true,
9
+ verification: true
10
+ };
11
+ if (typeof style.src === 'object') {
12
+ yield `${utils_1.newLine} & typeof import(`;
13
+ yield* (0, wrapWith_1.wrapWith)(style.src.offset, style.src.offset + style.src.text.length, 'main', features, `'`, [style.src.text, 'main', style.src.offset, utils_1.combineLastMapping], `'`);
14
+ yield `).default`;
15
+ }
16
+ for (const { text, offset } of style.imports) {
17
+ yield `${utils_1.newLine} & typeof import('`;
18
+ yield [
19
+ text,
20
+ style.name,
21
+ offset,
22
+ features
23
+ ];
24
+ yield `').default`;
25
+ }
26
+ }
27
+ //# sourceMappingURL=imports.js.map
@@ -4,6 +4,7 @@ exports.generateStyleModules = generateStyleModules;
4
4
  const codeFeatures_1 = require("../codeFeatures");
5
5
  const utils_1 = require("../utils");
6
6
  const classProperty_1 = require("./classProperty");
7
+ const imports_1 = require("./imports");
7
8
  function* generateStyleModules(options) {
8
9
  const styles = options.sfc.styles.map((style, i) => [style, i]).filter(([style]) => style.module);
9
10
  if (!styles.length && !options.scriptSetupRanges?.useCssModule.length) {
@@ -20,10 +21,17 @@ function* generateStyleModules(options) {
20
21
  text,
21
22
  'main',
22
23
  offset,
23
- codeFeatures_1.codeFeatures.withoutHighlight
24
+ codeFeatures_1.codeFeatures.navigation,
24
25
  ];
25
26
  }
26
- yield `: Record<string, string> & __VLS_PrettifyGlobal<{}`;
27
+ yield `: `;
28
+ if (!options.vueCompilerOptions.strictCssModules) {
29
+ yield `Record<string, string> & `;
30
+ }
31
+ yield `__VLS_PrettifyGlobal<{}`;
32
+ if (options.vueCompilerOptions.resolveStyleImports) {
33
+ yield* (0, imports_1.generateStyleImports)(style);
34
+ }
27
35
  for (const className of style.classNames) {
28
36
  yield* (0, classProperty_1.generateClassProperty)(i, className.text, className.offset, 'string');
29
37
  }
@@ -3,17 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStyleScopedClasses = generateStyleScopedClasses;
4
4
  const utils_1 = require("../utils");
5
5
  const classProperty_1 = require("./classProperty");
6
+ const imports_1 = require("./imports");
6
7
  function* generateStyleScopedClasses(options, ctx) {
7
- const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
8
+ const option = options.vueCompilerOptions.resolveStyleClassNames;
8
9
  const styles = options.sfc.styles
9
10
  .map((style, i) => [style, i])
10
- .filter(([style]) => option === 'always' || (option === 'scoped' && style.scoped));
11
+ .filter(([style]) => option === true || (option === 'scoped' && style.scoped));
11
12
  if (!styles.length) {
12
13
  return;
13
14
  }
14
15
  const firstClasses = new Set();
15
16
  yield `type __VLS_StyleScopedClasses = {}`;
16
17
  for (const [style, i] of styles) {
18
+ if (options.vueCompilerOptions.resolveStyleImports) {
19
+ yield* (0, imports_1.generateStyleImports)(style);
20
+ }
17
21
  for (const className of style.classNames) {
18
22
  if (firstClasses.has(className.text)) {
19
23
  ctx.scopedClasses.push({
@@ -129,6 +129,7 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
129
129
  withoutHighlightAndNavigation: VueCodeInformation;
130
130
  withoutHighlightAndCompletion: VueCodeInformation;
131
131
  withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
132
+ withoutSemantic: VueCodeInformation;
132
133
  };
133
134
  resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
134
135
  inVFor: boolean;
@@ -103,9 +103,7 @@ function* generateComponent(options, ctx, node) {
103
103
  else if (!isComponentTag) {
104
104
  yield `const ${componentOriginalVar} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
105
105
  if (options.selfComponentName && possibleOriginalNames.includes(options.selfComponentName)) {
106
- yield `typeof __VLS_self & (new () => { `
107
- + (0, shared_2.getSlotsPropertyName)(options.vueCompilerOptions.target)
108
- + `: __VLS_Slots }), `;
106
+ yield `typeof __VLS_self & (new () => { $slots: __VLS_Slots }), `;
109
107
  }
110
108
  else {
111
109
  yield `void, `;
@@ -111,11 +111,7 @@ function* generateElementProps(options, ctx, node, props, strictPropsCheck, enab
111
111
  }
112
112
  }
113
113
  else if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
114
- if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))
115
- // Vue 2 Transition doesn't support "persisted" property but `@vue/compiler-dom` always adds it (#3881)
116
- || (options.vueCompilerOptions.target < 3
117
- && prop.name === 'persisted'
118
- && node.tag.toLowerCase() === 'transition')) {
114
+ if (options.vueCompilerOptions.dataAttributes.some(pattern => (0, minimatch_1.minimatch)(prop.name, pattern))) {
119
115
  continue;
120
116
  }
121
117
  const shouldSpread = prop.name === 'style' || prop.name === 'class';
@@ -272,6 +268,6 @@ function getModelPropName(node, vueCompilerOptions) {
272
268
  }
273
269
  }
274
270
  }
275
- return vueCompilerOptions.target < 3 ? 'value' : 'modelValue';
271
+ return 'modelValue';
276
272
  }
277
273
  //# sourceMappingURL=elementProps.js.map
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTemplate = generateTemplate;
4
4
  exports.forEachElementNode = forEachElementNode;
5
5
  const CompilerDOM = require("@vue/compiler-dom");
6
- const shared_1 = require("../../utils/shared");
7
6
  const utils_1 = require("../utils");
8
7
  const wrapWith_1 = require("../utils/wrapWith");
9
8
  const context_1 = require("./context");
@@ -18,9 +17,8 @@ function* generateTemplate(options) {
18
17
  if (options.propsAssignName) {
19
18
  ctx.addLocalVariable(options.propsAssignName);
20
19
  }
21
- const slotsPropertyName = (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target);
22
20
  if (options.vueCompilerOptions.inferTemplateDollarSlots) {
23
- ctx.dollarVars.add(slotsPropertyName);
21
+ ctx.dollarVars.add('$slots');
24
22
  }
25
23
  if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
26
24
  ctx.dollarVars.add('$attrs');
@@ -37,7 +35,7 @@ function* generateTemplate(options) {
37
35
  yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(ctx);
38
36
  yield* ctx.generateHoistVariables();
39
37
  const speicalTypes = [
40
- [slotsPropertyName, yield* generateSlots(options, ctx)],
38
+ ['$slots', yield* generateSlots(options, ctx)],
41
39
  ['$attrs', yield* generateInheritedAttrs(options, ctx)],
42
40
  ['$refs', yield* generateTemplateRefs(options, ctx)],
43
41
  ['$el', yield* generateRootEl(ctx)]
@@ -114,7 +114,9 @@ function* generateVar(templateRefNames, ctx, code, offset, curVar) {
114
114
  if (ctx.dollarVars.has(curVar.text)) {
115
115
  yield [`__VLS_dollars.`, undefined];
116
116
  }
117
- yield [`__VLS_ctx.`, undefined];
117
+ else {
118
+ yield [`__VLS_ctx.`, undefined];
119
+ }
118
120
  yield [code.slice(curVar.offset, curVar.offset + curVar.text.length), curVar.offset];
119
121
  }
120
122
  }
@@ -6,7 +6,6 @@ exports.getAllExtensions = getAllExtensions;
6
6
  const language_core_1 = require("@volar/language-core");
7
7
  const CompilerDOM = require("@vue/compiler-dom");
8
8
  const plugins_1 = require("./plugins");
9
- const CompilerVue2 = require("./utils/vue2TemplateCompiler");
10
9
  const vueFile_1 = require("./virtualFile/vueFile");
11
10
  const fileRegistries = [];
12
11
  function getVueFileRegistry(key, plugins) {
@@ -38,12 +37,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
38
37
  function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
39
38
  const pluginContext = {
40
39
  modules: {
41
- '@vue/compiler-dom': vueCompilerOptions.target < 3
42
- ? {
43
- ...CompilerDOM,
44
- compile: CompilerVue2.compile,
45
- }
46
- : CompilerDOM,
40
+ '@vue/compiler-dom': CompilerDOM,
47
41
  typescript: ts,
48
42
  },
49
43
  compilerOptions,
@@ -2,18 +2,17 @@ import type * as ts from 'typescript';
2
2
  import type { TextRange } from '../types';
3
3
  export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
4
4
  }
5
- export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean, withNode: boolean): {
5
+ export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean): {
6
6
  exportDefault: (TextRange & {
7
7
  expression: TextRange;
8
8
  args: TextRange;
9
- argsNode: ts.ObjectLiteralExpression | undefined;
9
+ argsNode: ts.ObjectLiteralExpression;
10
10
  componentsOption: TextRange | undefined;
11
11
  componentsOptionNode: ts.ObjectLiteralExpression | undefined;
12
12
  directivesOption: TextRange | undefined;
13
13
  nameOption: TextRange | undefined;
14
14
  inheritAttrsOption: string | undefined;
15
15
  }) | undefined;
16
- classBlockEnd: number | undefined;
17
16
  bindings: {
18
17
  range: TextRange;
19
18
  moduleName?: string;
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptRanges = parseScriptRanges;
4
4
  const shared_1 = require("../utils/shared");
5
5
  const scriptSetupRanges_1 = require("./scriptSetupRanges");
6
- function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
6
+ function parseScriptRanges(ts, ast, hasScriptSetup) {
7
7
  let exportDefault;
8
- let classBlockEnd;
9
8
  const bindings = hasScriptSetup ? (0, scriptSetupRanges_1.parseBindingRanges)(ts, ast) : [];
10
9
  ts.forEachChild(ast, raw => {
11
10
  if (ts.isExportAssignment(raw)) {
@@ -49,24 +48,18 @@ function parseScriptRanges(ts, ast, hasScriptSetup, withNode) {
49
48
  ..._getStartEnd(raw),
50
49
  expression: _getStartEnd(node.expression),
51
50
  args: _getStartEnd(obj),
52
- argsNode: withNode ? obj : undefined,
51
+ argsNode: obj,
53
52
  componentsOption: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
54
- componentsOptionNode: withNode ? componentsOptionNode : undefined,
53
+ componentsOptionNode,
55
54
  directivesOption: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
56
55
  nameOption: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
57
56
  inheritAttrsOption,
58
57
  };
59
58
  }
60
59
  }
61
- if (ts.isClassDeclaration(raw)
62
- && raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)
63
- && raw.modifiers?.some(mod => mod.kind === ts.SyntaxKind.DefaultKeyword)) {
64
- classBlockEnd = raw.end - 1;
65
- }
66
60
  });
67
61
  return {
68
62
  exportDefault,
69
- classBlockEnd,
70
63
  bindings,
71
64
  };
72
65
  function _getStartEnd(node) {
@@ -6,7 +6,7 @@ type CallExpressionRange = {
6
6
  arg?: TextRange;
7
7
  typeArg?: TextRange;
8
8
  };
9
- type DefineProp = {
9
+ type DefineModel = {
10
10
  localName?: TextRange;
11
11
  name?: TextRange;
12
12
  type?: TextRange;
@@ -14,7 +14,6 @@ type DefineProp = {
14
14
  runtimeType?: TextRange;
15
15
  defaultValue?: TextRange;
16
16
  required?: boolean;
17
- isModel?: boolean;
18
17
  comments?: TextRange;
19
18
  argNode?: ts.Expression;
20
19
  };
@@ -55,7 +54,7 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
55
54
  isDefaultImport?: boolean;
56
55
  isNamespace?: boolean;
57
56
  }[];
58
- defineProp: DefineProp[];
57
+ defineModel: DefineModel[];
59
58
  defineProps: DefineProps | undefined;
60
59
  withDefaults: WithDefaults | undefined;
61
60
  defineEmits: DefineEmits | undefined;
@@ -73,4 +72,5 @@ export declare function parseBindingRanges(ts: typeof import('typescript'), ast:
73
72
  isDefaultImport?: boolean;
74
73
  isNamespace?: boolean;
75
74
  }[];
75
+ export declare function findBindingVars(ts: typeof import('typescript'), left: ts.BindingName, ast: ts.SourceFile): TextRange[];
76
76
  export {};
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptSetupRanges = parseScriptSetupRanges;
4
4
  exports.parseBindingRanges = parseBindingRanges;
5
+ exports.findBindingVars = findBindingVars;
5
6
  const utils_1 = require("../codegen/utils");
6
7
  const shared_1 = require("../utils/shared");
7
8
  const tsCheckReg = /^\/\/\s*@ts-(?:no)?check($|\s)/;
8
9
  function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
9
- const defineProp = [];
10
+ const defineModel = [];
10
11
  let defineProps;
11
12
  let withDefaults;
12
13
  let defineEmits;
@@ -17,8 +18,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
17
18
  const useCssModule = [];
18
19
  const useSlots = [];
19
20
  const useTemplateRef = [];
20
- const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
21
- const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
22
21
  const text = ast.text;
23
22
  const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
24
23
  const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
@@ -26,24 +25,27 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
26
25
  let foundNonImportExportNode = false;
27
26
  let importSectionEndOffset = 0;
28
27
  ts.forEachChild(ast, node => {
29
- const isTypeExport = (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node))
30
- && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
31
- if (!foundNonImportExportNode
32
- && !ts.isImportDeclaration(node)
33
- && !isTypeExport
34
- && !ts.isEmptyStatement(node)
28
+ if (foundNonImportExportNode
29
+ || ts.isImportDeclaration(node)
30
+ || ts.isExportDeclaration(node)
31
+ || ts.isEmptyStatement(node)
35
32
  // fix https://github.com/vuejs/language-tools/issues/1223
36
- && !ts.isImportEqualsDeclaration(node)) {
37
- const commentRanges = ts.getLeadingCommentRanges(text, node.pos);
38
- if (commentRanges?.length) {
39
- const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
40
- importSectionEndOffset = commentRange.pos;
41
- }
42
- else {
43
- importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, ast).start;
44
- }
45
- foundNonImportExportNode = true;
33
+ || ts.isImportEqualsDeclaration(node)) {
34
+ return;
35
+ }
36
+ if ((ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node))
37
+ && node.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)) {
38
+ return;
39
+ }
40
+ const commentRanges = ts.getLeadingCommentRanges(text, node.pos);
41
+ if (commentRanges?.length) {
42
+ const commentRange = commentRanges.sort((a, b) => a.pos - b.pos)[0];
43
+ importSectionEndOffset = commentRange.pos;
44
+ }
45
+ else {
46
+ importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, ast).start;
46
47
  }
48
+ foundNonImportExportNode = true;
47
49
  });
48
50
  ts.forEachChild(ast, node => visitNode(node, [ast]));
49
51
  const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
@@ -55,7 +57,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
55
57
  leadingCommentEndOffset,
56
58
  importSectionEndOffset,
57
59
  bindings,
58
- defineProp,
60
+ defineModel,
59
61
  defineProps,
60
62
  withDefaults,
61
63
  defineEmits,
@@ -72,8 +74,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
72
74
  if (ts.isCallExpression(node)
73
75
  && ts.isIdentifier(node.expression)) {
74
76
  const callText = _getNodeText(node.expression);
75
- const isDefineModel = vueCompilerOptions.macros.defineModel.includes(callText);
76
- if (isDefineModel || callText === 'defineProp') {
77
+ if (vueCompilerOptions.macros.defineModel.includes(callText)) {
77
78
  let localName;
78
79
  let propName;
79
80
  let options;
@@ -82,8 +83,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
82
83
  let runtimeType;
83
84
  let defaultValue;
84
85
  let required = false;
85
- if (ts.isVariableDeclaration(parent) &&
86
- ts.isIdentifier(parent.name)) {
86
+ if (ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
87
87
  localName = _getStartEnd(parent.name);
88
88
  }
89
89
  if (node.typeArguments) {
@@ -94,39 +94,16 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
94
94
  modifierType = _getStartEnd(node.typeArguments[1]);
95
95
  }
96
96
  }
97
- if (isDefineModel) {
98
- if (node.arguments.length >= 2) {
99
- propName = node.arguments[0];
100
- options = node.arguments[1];
101
- }
102
- else if (node.arguments.length >= 1) {
103
- if (ts.isStringLiteralLike(node.arguments[0])) {
104
- propName = node.arguments[0];
105
- }
106
- else {
107
- options = node.arguments[0];
108
- }
109
- }
97
+ if (node.arguments.length >= 2) {
98
+ propName = node.arguments[0];
99
+ options = node.arguments[1];
110
100
  }
111
- else if (definePropProposalA) {
112
- if (node.arguments.length >= 2) {
113
- options = node.arguments[1];
114
- }
115
- if (node.arguments.length >= 1) {
101
+ else if (node.arguments.length >= 1) {
102
+ if (ts.isStringLiteralLike(node.arguments[0])) {
116
103
  propName = node.arguments[0];
117
104
  }
118
- }
119
- else if (definePropProposalB) {
120
- if (node.arguments.length >= 3) {
121
- options = node.arguments[2];
122
- }
123
- if (node.arguments.length >= 2) {
124
- if (node.arguments[1].kind === ts.SyntaxKind.TrueKeyword) {
125
- required = true;
126
- }
127
- }
128
- if (node.arguments.length >= 1) {
129
- defaultValue = _getStartEnd(node.arguments[0]);
105
+ else {
106
+ options = node.arguments[0];
130
107
  }
131
108
  }
132
109
  if (options && ts.isObjectLiteralExpression(options)) {
@@ -150,7 +127,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
150
127
  if (propName && ts.isStringLiteralLike(propName)) {
151
128
  name = _getStartEnd(propName);
152
129
  }
153
- defineProp.push({
130
+ defineModel.push({
154
131
  localName,
155
132
  name,
156
133
  type,
@@ -158,7 +135,6 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
158
135
  runtimeType,
159
136
  defaultValue,
160
137
  required,
161
- isModel: isDefineModel,
162
138
  comments: getClosestMultiLineCommentRange(ts, node, parents, ast),
163
139
  argNode: options,
164
140
  });
@@ -4,6 +4,7 @@ const language_core_1 = require("@volar/language-core");
4
4
  const muggle_string_1 = require("muggle-string");
5
5
  const buildMappings_1 = require("../utils/buildMappings");
6
6
  const parseSfc_1 = require("../utils/parseSfc");
7
+ const frontmatterReg = /^---[\s\S]*?\n---(?:\r?\n|$)/;
7
8
  const codeblockReg = /(`{3,})[\s\S]+?\1/g;
8
9
  const inlineCodeblockReg = /`[^\n`]+?`/g;
9
10
  const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
@@ -28,6 +29,8 @@ const plugin = ({ vueCompilerOptions }) => {
28
29
  return;
29
30
  }
30
31
  content = content
32
+ // frontmatter
33
+ .replace(frontmatterReg, match => ' '.repeat(match.length))
31
34
  // code block
32
35
  .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
33
36
  // inline code block
@@ -4,14 +4,13 @@ export declare const tsCodegen: WeakMap<Sfc, {
4
4
  exportDefault: (import("../types").TextRange & {
5
5
  expression: import("../types").TextRange;
6
6
  args: import("../types").TextRange;
7
- argsNode: import("typescript").ObjectLiteralExpression | undefined;
7
+ argsNode: import("typescript").ObjectLiteralExpression;
8
8
  componentsOption: import("../types").TextRange | undefined;
9
9
  componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
10
10
  directivesOption: import("../types").TextRange | undefined;
11
11
  nameOption: import("../types").TextRange | undefined;
12
12
  inheritAttrsOption: string | undefined;
13
13
  }) | undefined;
14
- classBlockEnd: number | undefined;
15
14
  bindings: {
16
15
  range: import("../types").TextRange;
17
16
  moduleName?: string;
@@ -28,7 +27,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
28
27
  isDefaultImport?: boolean;
29
28
  isNamespace?: boolean;
30
29
  }[];
31
- defineProp: {
30
+ defineModel: {
32
31
  localName?: import("../types").TextRange;
33
32
  name?: import("../types").TextRange;
34
33
  type?: import("../types").TextRange;
@@ -36,7 +35,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
36
35
  runtimeType?: import("../types").TextRange;
37
36
  defaultValue?: import("../types").TextRange;
38
37
  required?: boolean;
39
- isModel?: boolean;
40
38
  comments?: import("../types").TextRange;
41
39
  argNode?: import("typescript").Expression;
42
40
  }[];
@@ -166,6 +164,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
166
164
  withoutHighlightAndNavigation: import("../types").VueCodeInformation;
167
165
  withoutHighlightAndCompletion: import("../types").VueCodeInformation;
168
166
  withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
167
+ withoutSemantic: import("../types").VueCodeInformation;
169
168
  };
170
169
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
171
170
  inVFor: boolean;
@@ -81,7 +81,7 @@ function createTsx(fileName, sfc, ctx, appendGlobalTypes) {
81
81
  return ctx.vueCompilerOptions;
82
82
  });
83
83
  const getScriptRanges = (0, alien_signals_1.computed)(() => sfc.script && validLangs.has(sfc.script.lang)
84
- ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup, false)
84
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, sfc.script.ast, !!sfc.scriptSetup)
85
85
  : undefined);
86
86
  const getScriptSetupRanges = (0, alien_signals_1.computed)(() => sfc.scriptSetup && validLangs.has(sfc.scriptSetup.lang)
87
87
  ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, sfc.scriptSetup.ast, getResolvedOptions())
package/lib/types.d.ts CHANGED
@@ -8,7 +8,7 @@ export type { SFCParseResult } from '@vue/compiler-sfc';
8
8
  export { VueEmbeddedCode };
9
9
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
10
10
  strictTemplates?: boolean;
11
- target?: 'auto' | 2 | 2.7 | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
11
+ target?: 'auto' | 3 | 3.3 | 3.5 | 3.6 | 99 | number;
12
12
  plugins?: string[];
13
13
  };
14
14
  export interface VueCodeInformation extends CodeInformation {
@@ -25,6 +25,7 @@ export interface VueCompilerOptions {
25
25
  jsxSlots: boolean;
26
26
  strictSlotChildren: boolean;
27
27
  strictVModel: boolean;
28
+ strictCssModules: boolean;
28
29
  checkUnknownProps: boolean;
29
30
  checkUnknownEvents: boolean;
30
31
  checkUnknownDirectives: boolean;
@@ -37,6 +38,8 @@ export interface VueCompilerOptions {
37
38
  inferTemplateDollarSlots: boolean;
38
39
  skipTemplateCodegen: boolean;
39
40
  fallthroughAttributes: boolean;
41
+ resolveStyleImports: boolean;
42
+ resolveStyleClassNames: boolean | 'scoped';
40
43
  fallthroughComponentNames: string[];
41
44
  dataAttributes: string[];
42
45
  htmlAttributes: string[];
@@ -57,8 +60,6 @@ export interface VueCompilerOptions {
57
60
  useTemplateRef: string[];
58
61
  };
59
62
  plugins: VueLanguagePlugin[];
60
- experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
61
- experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
62
63
  experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
63
64
  __setupedGlobalTypes?: true | {
64
65
  absolutePath: string;
@@ -133,8 +134,13 @@ export interface Sfc {
133
134
  ast: ts.SourceFile;
134
135
  } | undefined;
135
136
  styles: readonly (SfcBlock & {
137
+ src: SfcBlockAttr | undefined;
138
+ module: SfcBlockAttr | undefined;
136
139
  scoped: boolean;
137
- module?: SfcBlockAttr | undefined;
140
+ imports: {
141
+ text: string;
142
+ offset: number;
143
+ }[];
138
144
  cssVars: {
139
145
  text: string;
140
146
  offset: number;
@@ -0,0 +1,4 @@
1
+ export declare function parseCssImports(css: string): Generator<{
2
+ text: string;
3
+ offset: number;
4
+ }, void, unknown>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCssImports = parseCssImports;
4
+ const cssImportReg = /(?<=@import\s+url\()(["']?).*?\1(?=\))|(?<=@import\b\s*)(["']).*?\2/g;
5
+ function* parseCssImports(css) {
6
+ const matches = css.matchAll(cssImportReg);
7
+ for (const match of matches) {
8
+ let text = match[0];
9
+ let offset = match.index;
10
+ if (text.startsWith('\'') || text.startsWith('"')) {
11
+ text = text.slice(1, -1);
12
+ offset += 1;
13
+ }
14
+ if (text) {
15
+ yield { text, offset };
16
+ }
17
+ }
18
+ }
19
+ //# sourceMappingURL=parseCssImports.js.map
@@ -2,6 +2,5 @@ import type * as ts from 'typescript';
2
2
  import type { TextRange } from '../types';
3
3
  export { hyphenate as hyphenateTag } from '@vue/shared';
4
4
  export declare function hyphenateAttr(str: string): string;
5
- export declare function getSlotsPropertyName(vueVersion: number): "$scopedSlots" | "$slots";
6
5
  export declare function getStartEnd(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): TextRange;
7
6
  export declare function getNodeText(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile): string;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hyphenateTag = void 0;
4
4
  exports.hyphenateAttr = hyphenateAttr;
5
- exports.getSlotsPropertyName = getSlotsPropertyName;
6
5
  exports.getStartEnd = getStartEnd;
7
6
  exports.getNodeText = getNodeText;
8
7
  const shared_1 = require("@vue/shared");
@@ -16,9 +15,6 @@ function hyphenateAttr(str) {
16
15
  }
17
16
  return hyphencase;
18
17
  }
19
- function getSlotsPropertyName(vueVersion) {
20
- return vueVersion < 3 ? '$scopedSlots' : '$slots';
21
- }
22
18
  function getStartEnd(ts, node, ast) {
23
19
  return {
24
20
  start: ts.getTokenPosOfNode(node, ast),
package/lib/utils/ts.js CHANGED
@@ -131,7 +131,7 @@ class CompilerOptionsResolver {
131
131
  break;
132
132
  case 'plugins':
133
133
  this.plugins = (options.plugins ?? [])
134
- .map((pluginPath) => {
134
+ .flatMap((pluginPath) => {
135
135
  try {
136
136
  const resolvedPath = resolvePath(pluginPath, rootDir);
137
137
  if (resolvedPath) {
@@ -219,6 +219,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
219
219
  jsxSlots: false,
220
220
  strictSlotChildren: strictTemplates,
221
221
  strictVModel: strictTemplates,
222
+ strictCssModules: false,
222
223
  checkUnknownProps: strictTemplates,
223
224
  checkUnknownEvents: strictTemplates,
224
225
  checkUnknownDirectives: strictTemplates,
@@ -231,6 +232,8 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
231
232
  inferTemplateDollarSlots: false,
232
233
  skipTemplateCodegen: false,
233
234
  fallthroughAttributes: false,
235
+ resolveStyleImports: false,
236
+ resolveStyleClassNames: 'scoped',
234
237
  fallthroughComponentNames: [
235
238
  'Transition',
236
239
  'KeepAlive',
@@ -239,9 +242,7 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
239
242
  ],
240
243
  dataAttributes: [],
241
244
  htmlAttributes: ['aria-*'],
242
- optionsWrapper: target >= 2.7
243
- ? [`(await import('${lib}')).defineComponent(`, `)`]
244
- : [`(await import('${lib}')).default.extend(`, `)`],
245
+ optionsWrapper: [`(await import('${lib}')).defineComponent(`, `)`],
245
246
  macros: {
246
247
  defineProps: ['defineProps'],
247
248
  defineSlots: ['defineSlots'],
@@ -258,8 +259,6 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
258
259
  useTemplateRef: ['useTemplateRef', 'templateRef'],
259
260
  },
260
261
  plugins: [],
261
- experimentalDefinePropProposal: false,
262
- experimentalResolveStyleCssClasses: 'scoped',
263
262
  experimentalModelPropName: {
264
263
  '': {
265
264
  input: true
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.computedSfc = computedSfc;
4
4
  const alien_signals_1 = require("alien-signals");
5
5
  const parseCssClassNames_1 = require("../utils/parseCssClassNames");
6
+ const parseCssImports_1 = require("../utils/parseCssImports");
6
7
  const parseCssVars_1 = require("../utils/parseCssVars");
7
8
  const signals_1 = require("../utils/signals");
8
9
  function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
9
10
  const getUntrackedSnapshot = () => {
10
- (0, alien_signals_1.pauseTracking)();
11
+ const pausedSub = (0, alien_signals_1.setCurrentSub)(undefined);
11
12
  const res = getSnapshot();
12
- (0, alien_signals_1.resumeTracking)();
13
+ (0, alien_signals_1.setCurrentSub)(pausedSub);
13
14
  return res;
14
15
  };
15
16
  const getContent = (0, alien_signals_1.computed)(() => {
@@ -86,13 +87,17 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
86
87
  });
87
88
  const styles = (0, signals_1.computedArray)((0, alien_signals_1.computed)(() => getParseResult()?.descriptor.styles ?? []), (getBlock, i) => {
88
89
  const base = computedSfcBlock('style_' + i, 'css', getBlock);
90
+ const getSrc = computedAttrValue('__src', base, getBlock);
89
91
  const getModule = computedAttrValue('__module', base, getBlock);
90
92
  const getScoped = (0, alien_signals_1.computed)(() => !!getBlock().scoped);
93
+ const getImports = (0, signals_1.computedItems)(() => [...(0, parseCssImports_1.parseCssImports)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
91
94
  const getCssVars = (0, signals_1.computedItems)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
92
95
  const getClassNames = (0, signals_1.computedItems)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
93
96
  return () => mergeObject(base, {
97
+ get src() { return getSrc(); },
94
98
  get module() { return getModule(); },
95
99
  get scoped() { return getScoped(); },
100
+ get imports() { return getImports(); },
96
101
  get cssVars() { return getCssVars(); },
97
102
  get classNames() { return getClassNames(); },
98
103
  });
@@ -127,9 +132,9 @@ function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
127
132
  if (cache?.plugin.updateSFCTemplate) {
128
133
  const change = getUntrackedSnapshot().getChangeRange(cache.snapshot);
129
134
  if (change) {
130
- (0, alien_signals_1.pauseTracking)();
135
+ const pausedSub = (0, alien_signals_1.setCurrentSub)(undefined);
131
136
  const templateOffset = base.startTagEnd;
132
- (0, alien_signals_1.resumeTracking)();
137
+ (0, alien_signals_1.setCurrentSub)(pausedSub);
133
138
  const newText = getUntrackedSnapshot().getText(change.span.start, change.span.start + change.newLength);
134
139
  const newResult = cache.plugin.updateSFCTemplate(cache.result, {
135
140
  start: change.span.start - templateOffset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0-beta.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,20 +13,18 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "~2.4.13",
16
+ "@volar/language-core": "2.4.14",
17
17
  "@vue/compiler-dom": "^3.5.0",
18
- "@vue/compiler-vue2": "^2.7.16",
19
18
  "@vue/shared": "^3.5.0",
20
- "alien-signals": "^1.0.3",
21
- "minimatch": "^9.0.3",
19
+ "alien-signals": "^2.0.5",
20
+ "minimatch": "^10.0.1",
22
21
  "muggle-string": "^0.4.1",
23
22
  "path-browserify": "^1.0.1"
24
23
  },
25
24
  "devDependencies": {
26
- "@types/minimatch": "^5.1.2",
27
25
  "@types/node": "^22.10.4",
28
26
  "@types/path-browserify": "^1.0.1",
29
- "@volar/typescript": "~2.4.13",
27
+ "@volar/typescript": "2.4.14",
30
28
  "@vue/compiler-sfc": "^3.5.0"
31
29
  },
32
30
  "peerDependencies": {
@@ -37,5 +35,5 @@
37
35
  "optional": true
38
36
  }
39
37
  },
40
- "gitHead": "a7b5649ab4957cd2228f4bbc9205b2008bff58a2"
38
+ "gitHead": "7a2ea48123679387d7095a81ac49cfc667aeeabb"
41
39
  }
@@ -1,3 +0,0 @@
1
- import type { VueLanguagePlugin } from '../types';
2
- declare const plugin: VueLanguagePlugin;
3
- export default plugin;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const css = require("css-tree");
4
- const plugin = () => {
5
- return {
6
- version: 2.1,
7
- compileSFCStyle(lang, style) {
8
- if (lang === 'css' || lang === 'scss' || lang === 'sass' || lang === 'less') {
9
- return css.parse(style, {
10
- filename: 'test.' + lang,
11
- positions: true,
12
- });
13
- }
14
- },
15
- };
16
- };
17
- exports.default = plugin;
18
- //# sourceMappingURL=vue-style-css.js.map
@@ -1,2 +0,0 @@
1
- import * as CompilerDOM from '@vue/compiler-dom';
2
- export declare const compile: typeof CompilerDOM.compile;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compile = void 0;
4
- const CompilerDOM = require("@vue/compiler-dom");
5
- const Vue2TemplateCompiler = require('@vue/compiler-vue2/build');
6
- const compile = (template, options = {}) => {
7
- if (typeof template !== 'string') {
8
- throw new Error(`[@vue/language-core] compile() first argument must be string.`);
9
- }
10
- const onError = options.onError;
11
- const onWarn = options.onWarn;
12
- options.onError = error => {
13
- if (error.code === 33 // :key binding allowed in v-for template child in vue 2
14
- || error.code === 29 // fix https://github.com/vuejs/language-tools/issues/1638
15
- ) {
16
- return;
17
- }
18
- if (onError) {
19
- onError(error);
20
- }
21
- else {
22
- throw error;
23
- }
24
- };
25
- const vue2Result = Vue2TemplateCompiler.compile(template, { outputSourceRange: true });
26
- for (const error of vue2Result.errors) {
27
- onError?.({
28
- code: 'vue-template-compiler',
29
- name: '',
30
- message: error.msg,
31
- loc: {
32
- source: '',
33
- start: { column: -1, line: -1, offset: error.start },
34
- end: { column: -1, line: -1, offset: error.end ?? error.start },
35
- },
36
- });
37
- }
38
- for (const error of vue2Result.tips) {
39
- onWarn?.({
40
- code: 'vue-template-compiler',
41
- name: '',
42
- message: error.msg,
43
- loc: {
44
- source: '',
45
- start: { column: -1, line: -1, offset: error.start },
46
- end: { column: -1, line: -1, offset: error.end ?? error.start },
47
- },
48
- });
49
- }
50
- return baseCompile(template, Object.assign({}, CompilerDOM.parserOptions, options, {
51
- nodeTransforms: [
52
- ...CompilerDOM.DOMNodeTransforms,
53
- ...(options.nodeTransforms || [])
54
- ],
55
- directiveTransforms: Object.assign({}, CompilerDOM.DOMDirectiveTransforms, options.directiveTransforms || {}),
56
- }));
57
- };
58
- exports.compile = compile;
59
- function baseCompile(template, options = {}) {
60
- const onError = options.onError || (error => { throw error; });
61
- const isModuleMode = options.mode === 'module';
62
- const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
63
- if (!prefixIdentifiers && options.cacheHandlers) {
64
- onError(CompilerDOM.createCompilerError(49));
65
- }
66
- if (options.scopeId && !isModuleMode) {
67
- onError(CompilerDOM.createCompilerError(50));
68
- }
69
- const ast = CompilerDOM.baseParse(template, options);
70
- const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset(prefixIdentifiers);
71
- // v-for > v-if in vue 2
72
- const transformIf = nodeTransforms[1];
73
- const transformFor = nodeTransforms[3];
74
- nodeTransforms[1] = transformFor;
75
- nodeTransforms[3] = transformIf;
76
- CompilerDOM.transform(ast, Object.assign({}, options, {
77
- prefixIdentifiers,
78
- nodeTransforms: [
79
- ...nodeTransforms,
80
- ...(options.nodeTransforms || []) // user transforms
81
- ],
82
- directiveTransforms: Object.assign({}, directiveTransforms, options.directiveTransforms || {} // user transforms
83
- )
84
- }));
85
- return CompilerDOM.generate(ast, Object.assign({}, options, {
86
- prefixIdentifiers
87
- }));
88
- }
89
- //# sourceMappingURL=vue2TemplateCompiler.js.map