@vue/language-core 2.2.2 → 2.2.6

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 (90) hide show
  1. package/lib/codegen/globalTypes.js +21 -34
  2. package/lib/codegen/script/component.js +11 -9
  3. package/lib/codegen/script/componentSelf.js +4 -11
  4. package/lib/codegen/script/context.d.ts +0 -1
  5. package/lib/codegen/script/context.js +0 -1
  6. package/lib/codegen/script/index.d.ts +1 -4
  7. package/lib/codegen/script/index.js +8 -12
  8. package/lib/codegen/script/scriptSetup.js +90 -70
  9. package/lib/codegen/script/src.d.ts +2 -2
  10. package/lib/codegen/script/src.js +36 -37
  11. package/lib/codegen/script/styleModulesType.d.ts +1 -1
  12. package/lib/codegen/script/styleModulesType.js +2 -2
  13. package/lib/codegen/script/template.d.ts +1 -2
  14. package/lib/codegen/script/template.js +5 -53
  15. package/lib/codegen/style/classProperty.d.ts +2 -0
  16. package/lib/codegen/style/classProperty.js +18 -0
  17. package/lib/codegen/style/modules.d.ts +3 -0
  18. package/lib/codegen/style/modules.js +34 -0
  19. package/lib/codegen/style/scopedClasses.d.ts +4 -0
  20. package/lib/codegen/style/scopedClasses.js +32 -0
  21. package/lib/codegen/template/context.d.ts +106 -5
  22. package/lib/codegen/template/context.js +131 -6
  23. package/lib/codegen/template/element.d.ts +1 -1
  24. package/lib/codegen/template/element.js +74 -97
  25. package/lib/codegen/template/elementChildren.d.ts +1 -1
  26. package/lib/codegen/template/elementChildren.js +1 -13
  27. package/lib/codegen/template/elementDirectives.js +8 -6
  28. package/lib/codegen/template/elementEvents.d.ts +2 -1
  29. package/lib/codegen/template/elementEvents.js +52 -28
  30. package/lib/codegen/template/elementProps.d.ts +1 -1
  31. package/lib/codegen/template/elementProps.js +23 -20
  32. package/lib/codegen/template/index.js +29 -14
  33. package/lib/codegen/template/interpolation.js +5 -5
  34. package/lib/codegen/template/objectProperty.js +5 -4
  35. package/lib/codegen/template/propertyAccess.js +1 -1
  36. package/lib/codegen/template/slotOutlet.js +13 -11
  37. package/lib/codegen/template/styleScopedClasses.js +8 -58
  38. package/lib/codegen/template/templateChild.js +60 -28
  39. package/lib/codegen/template/vFor.js +2 -2
  40. package/lib/codegen/template/vIf.js +4 -8
  41. package/lib/codegen/template/vSlot.d.ts +1 -0
  42. package/lib/codegen/template/vSlot.js +14 -1
  43. package/lib/codegen/utils/camelized.d.ts +1 -1
  44. package/lib/codegen/utils/camelized.js +6 -6
  45. package/lib/codegen/utils/escaped.d.ts +2 -0
  46. package/lib/codegen/utils/escaped.js +23 -0
  47. package/lib/codegen/utils/index.d.ts +3 -3
  48. package/lib/codegen/utils/index.js +19 -15
  49. package/lib/codegen/utils/objectProperty.d.ts +3 -0
  50. package/lib/codegen/utils/objectProperty.js +41 -0
  51. package/lib/codegen/utils/stringLiteralKey.js +2 -1
  52. package/lib/codegen/utils/unicode.js +2 -2
  53. package/lib/codegen/utils/wrapWith.d.ts +3 -0
  54. package/lib/codegen/utils/wrapWith.js +24 -0
  55. package/lib/parsers/scriptSetupRanges.d.ts +2 -0
  56. package/lib/parsers/scriptSetupRanges.js +84 -106
  57. package/lib/plugins/file-md.js +3 -0
  58. package/lib/plugins/vue-template-inline-ts.js +3 -3
  59. package/lib/plugins/vue-tsx.d.ts +11 -8
  60. package/lib/plugins/vue-tsx.js +19 -28
  61. package/lib/types.d.ts +24 -14
  62. package/lib/utils/parseSfc.js +40 -16
  63. package/lib/utils/ts.js +17 -0
  64. package/lib/virtualFile/computedEmbeddedCodes.js +18 -11
  65. package/lib/virtualFile/computedSfc.js +21 -28
  66. package/lib/virtualFile/vueFile.d.ts +7 -10
  67. package/lib/virtualFile/vueFile.js +10 -4
  68. package/package.json +2 -2
  69. package/lib/codeFeatures.d.ts +0 -1
  70. package/lib/codeFeatures.js +0 -3
  71. package/lib/codegen/common.d.ts +0 -12
  72. package/lib/codegen/common.js +0 -79
  73. package/lib/codegen/script/binding.d.ts +0 -4
  74. package/lib/codegen/script/binding.js +0 -41
  75. package/lib/codegen/template/camelized.d.ts +0 -2
  76. package/lib/codegen/template/camelized.js +0 -31
  77. package/lib/codegen/utils/src.d.ts +0 -2
  78. package/lib/codegen/utils/src.js +0 -19
  79. package/lib/plugins/vue-style-class-names.d.ts +0 -5
  80. package/lib/plugins/vue-style-class-names.js +0 -32
  81. package/lib/plugins/vue-style-reference-link.d.ts +0 -1
  82. package/lib/plugins/vue-style-reference-link.js +0 -3
  83. package/lib/plugins/vue-style-reference-links.d.ts +0 -3
  84. package/lib/plugins/vue-style-reference-links.js +0 -26
  85. package/lib/plugins/vue-vine.d.ts +0 -3
  86. package/lib/plugins/vue-vine.js +0 -35
  87. package/lib/utils/findDestructuredProps.d.ts +0 -1
  88. package/lib/utils/findDestructuredProps.js +0 -3
  89. package/lib/utils/parseCssImports.d.ts +0 -4
  90. package/lib/utils/parseCssImports.js +0 -19
@@ -7,7 +7,7 @@ const utils_1 = require("../utils");
7
7
  const interpolation_1 = require("./interpolation");
8
8
  const templateChild_1 = require("./templateChild");
9
9
  function* generateVIf(options, ctx, node) {
10
- let originalBlockConditionsLength = ctx.blockConditions.length;
10
+ const originalBlockConditionsLength = ctx.blockConditions.length;
11
11
  for (let i = 0; i < node.branches.length; i++) {
12
12
  const branch = node.branches[i];
13
13
  if (i === 0) {
@@ -21,12 +21,8 @@ function* generateVIf(options, ctx, node) {
21
21
  }
22
22
  let addedBlockCondition = false;
23
23
  if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
24
- const codes = [
25
- ...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, branch.condition.loc, '(', ')'),
26
- ];
27
- for (const code of codes) {
28
- yield code;
29
- }
24
+ const codes = [...(0, interpolation_1.generateInterpolation)(options, ctx, 'template', ctx.codeFeatures.all, branch.condition.content, branch.condition.loc.start.offset, branch.condition.loc, `(`, `)`)];
25
+ yield* codes;
30
26
  ctx.blockConditions.push((0, muggle_string_1.toString)(codes));
31
27
  addedBlockCondition = true;
32
28
  yield ` `;
@@ -43,7 +39,7 @@ function* generateVIf(options, ctx, node) {
43
39
  yield* ctx.generateAutoImportCompletion();
44
40
  yield `}${utils_1.newLine}`;
45
41
  if (addedBlockCondition) {
46
- ctx.blockConditions[ctx.blockConditions.length - 1] = `!(${ctx.blockConditions[ctx.blockConditions.length - 1]})`;
42
+ ctx.blockConditions[ctx.blockConditions.length - 1] = `!${ctx.blockConditions[ctx.blockConditions.length - 1]}`;
47
43
  }
48
44
  }
49
45
  ctx.blockConditions.length = originalBlockConditionsLength;
@@ -3,3 +3,4 @@ import type { Code } from '../../types';
3
3
  import type { TemplateCodegenContext } from './context';
4
4
  import type { TemplateCodegenOptions } from './index';
5
5
  export declare function generateVSlot(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode, slotDir: CompilerDOM.DirectiveNode): Generator<Code>;
6
+ export declare function generateImplicitDefaultSlot(ctx: TemplateCodegenContext, node: CompilerDOM.ElementNode): Generator<Code, void, any>;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateVSlot = generateVSlot;
4
+ exports.generateImplicitDefaultSlot = generateImplicitDefaultSlot;
4
5
  const CompilerDOM = require("@vue/compiler-dom");
5
6
  const utils_1 = require("../utils");
7
+ const wrapWith_1 = require("../utils/wrapWith");
6
8
  const objectProperty_1 = require("./objectProperty");
7
9
  const templateChild_1 = require("./templateChild");
8
10
  function* generateVSlot(options, ctx, node, slotDir) {
@@ -17,7 +19,7 @@ function* generateVSlot(options, ctx, node, slotDir) {
17
19
  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, false, true);
18
20
  }
19
21
  else {
20
- yield* (0, utils_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
22
+ yield* (0, wrapWith_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.rawName?.length ?? 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`);
21
23
  }
22
24
  yield `: __VLS_thisSlot } = ${ctx.currentComponent.ctxVar}.slots!${utils_1.endOfLine}`;
23
25
  if (slotDir.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
@@ -77,4 +79,15 @@ function* generateVSlot(options, ctx, node, slotDir) {
77
79
  yield* ctx.generateAutoImportCompletion();
78
80
  yield `}${utils_1.newLine}`;
79
81
  }
82
+ function* generateImplicitDefaultSlot(ctx, node) {
83
+ if (!ctx.currentComponent) {
84
+ return;
85
+ }
86
+ if (node.children.length) {
87
+ ctx.currentComponent.used = true;
88
+ yield `${ctx.currentComponent.ctxVar}.slots!.`;
89
+ yield* (0, wrapWith_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
90
+ yield utils_1.endOfLine;
91
+ }
92
+ }
80
93
  //# sourceMappingURL=vSlot.js.map
@@ -1,2 +1,2 @@
1
1
  import type { Code, VueCodeInformation } from '../../types';
2
- export declare function generateCamelized(code: string, offset: number, info: VueCodeInformation): Generator<Code>;
2
+ export declare function generateCamelized(code: string, source: string, offset: number, features: VueCodeInformation): Generator<Code>;
@@ -2,26 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateCamelized = generateCamelized;
4
4
  const shared_1 = require("@vue/shared");
5
- const index_1 = require("./index");
6
- function* generateCamelized(code, offset, info) {
5
+ function* generateCamelized(code, source, offset, features) {
7
6
  const parts = code.split('-');
7
+ const startCombineOffset = features.__combineOffset ?? 0;
8
8
  for (let i = 0; i < parts.length; i++) {
9
9
  const part = parts[i];
10
10
  if (part !== '') {
11
11
  if (i === 0) {
12
12
  yield [
13
13
  part,
14
- 'template',
14
+ source,
15
15
  offset,
16
- info,
16
+ features,
17
17
  ];
18
18
  }
19
19
  else {
20
20
  yield [
21
21
  (0, shared_1.capitalize)(part),
22
- 'template',
22
+ source,
23
23
  offset,
24
- index_1.combineLastMapping,
24
+ { __combineOffset: startCombineOffset + i },
25
25
  ];
26
26
  }
27
27
  }
@@ -0,0 +1,2 @@
1
+ import type { Code, VueCodeInformation } from "../../types";
2
+ export declare function generateEscaped(text: string, source: string, offset: number, features: VueCodeInformation, escapeTarget: RegExp): Generator<Code>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEscaped = generateEscaped;
4
+ function* generateEscaped(text, source, offset, features, escapeTarget) {
5
+ const parts = text.split(escapeTarget);
6
+ const startCombineOffset = features.__combineOffset ?? 0;
7
+ let isEscapeTarget = false;
8
+ for (let i = 0; i < parts.length; i++) {
9
+ const part = parts[i];
10
+ if (isEscapeTarget) {
11
+ yield `\\`;
12
+ }
13
+ yield [
14
+ part,
15
+ source,
16
+ offset,
17
+ i === 0 ? features : { __combineOffset: startCombineOffset + i },
18
+ ];
19
+ offset += part.length;
20
+ isEscapeTarget = !isEscapeTarget;
21
+ }
22
+ }
23
+ //# sourceMappingURL=escaped.js.map
@@ -1,11 +1,10 @@
1
1
  import * as CompilerDOM from '@vue/compiler-dom';
2
2
  import type * as ts from 'typescript';
3
- import type { Code, SfcBlock, VueCodeInformation } from '../../types';
3
+ import type { Code, SfcBlock, SfcBlockAttr, VueCodeInformation } from '../../types';
4
4
  export declare const newLine = "\n";
5
5
  export declare const endOfLine = ";\n";
6
6
  export declare const combineLastMapping: VueCodeInformation;
7
- export declare const variableNameRegex: RegExp;
8
- export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
7
+ export declare const identifierRegex: RegExp;
9
8
  export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
10
9
  export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: {
11
10
  id: ts.Identifier;
@@ -19,3 +18,4 @@ export declare function collectIdentifiers(ts: typeof import('typescript'), node
19
18
  export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number];
20
19
  export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
21
20
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
21
+ export declare function generateSfcBlockAttrValue(src: SfcBlockAttr & object, text: string, features: VueCodeInformation): Generator<Code>;
@@ -1,28 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.variableNameRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
4
- exports.wrapWith = wrapWith;
3
+ exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
5
4
  exports.collectVars = collectVars;
6
5
  exports.collectIdentifiers = collectIdentifiers;
7
6
  exports.normalizeAttributeValue = normalizeAttributeValue;
8
7
  exports.createTsAst = createTsAst;
9
8
  exports.generateSfcBlockSection = generateSfcBlockSection;
9
+ exports.generateSfcBlockAttrValue = generateSfcBlockAttrValue;
10
10
  const scriptSetupRanges_1 = require("../../parsers/scriptSetupRanges");
11
11
  exports.newLine = `\n`;
12
12
  exports.endOfLine = `;${exports.newLine}`;
13
- exports.combineLastMapping = { __combineLastMapping: true };
14
- exports.variableNameRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
15
- function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
16
- yield ['', 'template', startOffset, features];
17
- let offset = 1;
18
- for (const wrapCode of wrapCodes) {
19
- if (typeof wrapCode !== 'string') {
20
- offset++;
21
- }
22
- yield wrapCode;
23
- }
24
- yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
25
- }
13
+ exports.combineLastMapping = { __combineOffset: 1 };
14
+ exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
26
15
  function collectVars(ts, node, ast, results = []) {
27
16
  const identifiers = collectIdentifiers(ts, node, []);
28
17
  for (const { id } of identifiers) {
@@ -76,4 +65,19 @@ function generateSfcBlockSection(block, start, end, features) {
76
65
  features,
77
66
  ];
78
67
  }
68
+ function* generateSfcBlockAttrValue(src, text, features) {
69
+ const { offset, quotes } = src;
70
+ if (!quotes) {
71
+ yield [``, 'main', offset, { verification: true }];
72
+ }
73
+ yield [
74
+ `'${text}'`,
75
+ 'main',
76
+ quotes ? offset - 1 : offset,
77
+ features
78
+ ];
79
+ if (!quotes) {
80
+ yield [``, 'main', offset + text.length, { __combineOffset: 2 }];
81
+ }
82
+ }
79
83
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import type { Code, VueCodeInformation } from '../../types';
2
+ export declare function getObjectProperty(code: string): string;
3
+ export declare function generateObjectProperty(code: string, source: string, offset: number, features: VueCodeInformation, hasQuotes?: boolean, shouldCamelize?: boolean): Generator<Code>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getObjectProperty = getObjectProperty;
4
+ exports.generateObjectProperty = generateObjectProperty;
5
+ const shared_1 = require("@vue/shared");
6
+ const utils_1 = require("../utils");
7
+ const camelized_1 = require("../utils/camelized");
8
+ const stringLiteralKey_1 = require("../utils/stringLiteralKey");
9
+ function getObjectProperty(code) {
10
+ if (utils_1.identifierRegex.test(code)) {
11
+ return code;
12
+ }
13
+ else {
14
+ return `'${code}'`;
15
+ }
16
+ }
17
+ function* generateObjectProperty(code, source, offset, features, hasQuotes = false, shouldCamelize = false) {
18
+ const start = offset;
19
+ const end = offset + code.length;
20
+ if (hasQuotes) {
21
+ code = code.slice(1, -1);
22
+ offset++;
23
+ }
24
+ if (shouldCamelize) {
25
+ if (utils_1.identifierRegex.test((0, shared_1.camelize)(code))) {
26
+ yield* (0, camelized_1.generateCamelized)(code, source, offset, features);
27
+ }
28
+ else {
29
+ yield* (0, utils_1.wrapWith)(start, end, source, features, `'`, ...(0, camelized_1.generateCamelized)(code, source, offset, features), `'`);
30
+ }
31
+ }
32
+ else {
33
+ if (utils_1.identifierRegex.test(code)) {
34
+ yield [code, source, offset, features];
35
+ }
36
+ else {
37
+ yield* (0, stringLiteralKey_1.generateStringLiteralKey)(code, source, offset, features);
38
+ }
39
+ }
40
+ }
41
+ //# sourceMappingURL=objectProperty.js.map
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStringLiteralKey = generateStringLiteralKey;
4
4
  const index_1 = require("./index");
5
+ const wrapWith_1 = require("./wrapWith");
5
6
  function* generateStringLiteralKey(code, offset, info) {
6
7
  if (offset === undefined || !info) {
7
8
  yield `'${code}'`;
8
9
  }
9
10
  else {
10
- yield* (0, index_1.wrapWith)(offset, offset + code.length, info, `'`, [code, 'template', offset, index_1.combineLastMapping], `'`);
11
+ yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, info, `'`, [code, 'template', offset, index_1.combineLastMapping], `'`);
11
12
  }
12
13
  }
13
14
  //# sourceMappingURL=stringLiteralKey.js.map
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateUnicode = generateUnicode;
4
- const index_1 = require("./index");
4
+ const wrapWith_1 = require("./wrapWith");
5
5
  function* generateUnicode(code, offset, info) {
6
6
  if (needToUnicode(code)) {
7
- yield* (0, index_1.wrapWith)(offset, offset + code.length, info, toUnicode(code));
7
+ yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, info, toUnicode(code));
8
8
  }
9
9
  else {
10
10
  yield [code, 'template', offset, info];
@@ -0,0 +1,3 @@
1
+ import type { Code, VueCodeInformation } from "../../types";
2
+ export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
3
+ export declare function wrapWith(startOffset: number, endOffset: number, source: string, features: VueCodeInformation, ...codes: Code[]): Generator<Code>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapWith = wrapWith;
4
+ function* wrapWith(startOffset, endOffset, ...args) {
5
+ let source = 'template';
6
+ let features;
7
+ let codes;
8
+ if (typeof args[0] === 'string') {
9
+ [source, features, ...codes] = args;
10
+ }
11
+ else {
12
+ [features, ...codes] = args;
13
+ }
14
+ yield ['', source, startOffset, features];
15
+ let offset = 1;
16
+ for (const code of codes) {
17
+ if (typeof code !== 'string') {
18
+ offset++;
19
+ }
20
+ yield code;
21
+ }
22
+ yield ['', source, endOffset, { __combineOffset: offset }];
23
+ }
24
+ //# sourceMappingURL=wrapWith.js.map
@@ -15,6 +15,8 @@ type DefineProp = {
15
15
  defaultValue?: TextRange;
16
16
  required?: boolean;
17
17
  isModel?: boolean;
18
+ comments?: TextRange;
19
+ argNode?: ts.Expression;
18
20
  };
19
21
  type DefineProps = CallExpressionRange & {
20
22
  name?: string;
@@ -74,91 +74,48 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
74
74
  if (ts.isCallExpression(node)
75
75
  && ts.isIdentifier(node.expression)) {
76
76
  const callText = _getNodeText(node.expression);
77
- if (vueCompilerOptions.macros.defineModel.includes(callText)) {
77
+ const isDefineModel = vueCompilerOptions.macros.defineModel.includes(callText);
78
+ if (isDefineModel || callText === 'defineProp') {
78
79
  let localName;
79
80
  let propName;
80
81
  let options;
82
+ let type;
83
+ let modifierType;
84
+ let runtimeType;
85
+ let defaultValue;
86
+ let required = false;
81
87
  if (ts.isVariableDeclaration(parent) &&
82
88
  ts.isIdentifier(parent.name)) {
83
89
  localName = _getStartEnd(parent.name);
84
90
  }
85
- if (node.arguments.length >= 2) {
86
- propName = _getStartEnd(node.arguments[0]);
87
- options = node.arguments[1];
88
- }
89
- else if (node.arguments.length >= 1) {
90
- if (ts.isStringLiteralLike(node.arguments[0])) {
91
- propName = _getStartEnd(node.arguments[0]);
91
+ if (node.typeArguments) {
92
+ if (node.typeArguments.length >= 1) {
93
+ type = _getStartEnd(node.typeArguments[0]);
92
94
  }
93
- else {
94
- options = node.arguments[0];
95
+ if (node.typeArguments.length >= 2) {
96
+ modifierType = _getStartEnd(node.typeArguments[1]);
95
97
  }
96
98
  }
97
- let runtimeType;
98
- let defaultValue;
99
- let required = false;
100
- if (options && ts.isObjectLiteralExpression(options)) {
101
- for (const property of options.properties) {
102
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
103
- continue;
104
- }
105
- const text = _getNodeText(property.name);
106
- if (text === 'type') {
107
- runtimeType = _getStartEnd(property.initializer);
99
+ if (isDefineModel) {
100
+ if (node.arguments.length >= 2) {
101
+ propName = node.arguments[0];
102
+ options = node.arguments[1];
103
+ }
104
+ else if (node.arguments.length >= 1) {
105
+ if (ts.isStringLiteralLike(node.arguments[0])) {
106
+ propName = node.arguments[0];
108
107
  }
109
- else if (text === 'default') {
110
- defaultValue = _getStartEnd(property.initializer);
111
- }
112
- else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
113
- required = true;
108
+ else {
109
+ options = node.arguments[0];
114
110
  }
115
111
  }
116
112
  }
117
- defineProp.push({
118
- localName,
119
- name: propName,
120
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
121
- modifierType: node.typeArguments && node.typeArguments?.length >= 2 ? _getStartEnd(node.typeArguments[1]) : undefined,
122
- runtimeType,
123
- defaultValue,
124
- required,
125
- isModel: true,
126
- });
127
- }
128
- else if (callText === 'defineProp') {
129
- let localName;
130
- let propName;
131
- let options;
132
- if (ts.isVariableDeclaration(parent) &&
133
- ts.isIdentifier(parent.name)) {
134
- localName = _getStartEnd(parent.name);
135
- }
136
- let runtimeType;
137
- let defaultValue;
138
- let required = false;
139
- if (definePropProposalA) {
113
+ else if (definePropProposalA) {
140
114
  if (node.arguments.length >= 2) {
141
115
  options = node.arguments[1];
142
116
  }
143
117
  if (node.arguments.length >= 1) {
144
- propName = _getStartEnd(node.arguments[0]);
145
- }
146
- if (options && ts.isObjectLiteralExpression(options)) {
147
- for (const property of options.properties) {
148
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
149
- continue;
150
- }
151
- const text = _getNodeText(property.name);
152
- if (text === 'type') {
153
- runtimeType = _getStartEnd(property.initializer);
154
- }
155
- else if (text === 'default') {
156
- defaultValue = _getStartEnd(property.initializer);
157
- }
158
- else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
159
- required = true;
160
- }
161
- }
118
+ propName = node.arguments[0];
162
119
  }
163
120
  }
164
121
  else if (definePropProposalB) {
@@ -173,49 +130,58 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
173
130
  if (node.arguments.length >= 1) {
174
131
  defaultValue = _getStartEnd(node.arguments[0]);
175
132
  }
176
- if (options && ts.isObjectLiteralExpression(options)) {
177
- for (const property of options.properties) {
178
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
179
- continue;
180
- }
181
- const text = _getNodeText(property.name);
182
- if (text === 'type') {
183
- runtimeType = _getStartEnd(property.initializer);
184
- }
133
+ }
134
+ if (options && ts.isObjectLiteralExpression(options)) {
135
+ for (const property of options.properties) {
136
+ if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
137
+ continue;
138
+ }
139
+ const text = _getNodeText(property.name);
140
+ if (text === 'type') {
141
+ runtimeType = _getStartEnd(property.initializer);
142
+ }
143
+ else if (text === 'default') {
144
+ defaultValue = _getStartEnd(property.initializer);
145
+ }
146
+ else if (text === 'required' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
147
+ required = true;
185
148
  }
186
149
  }
187
150
  }
151
+ let name;
152
+ if (propName && ts.isStringLiteralLike(propName)) {
153
+ name = _getStartEnd(propName);
154
+ }
188
155
  defineProp.push({
189
156
  localName,
190
- name: propName,
191
- type: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
157
+ name,
158
+ type,
159
+ modifierType,
192
160
  runtimeType,
193
161
  defaultValue,
194
162
  required,
163
+ isModel: isDefineModel,
164
+ comments: getCommentsRange(ts, node, parents, ast),
165
+ argNode: options,
195
166
  });
196
167
  }
197
168
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
198
169
  defineProps = {
199
- ...parseCallExpression(node),
170
+ ...parseCallExpressionAssignment(node, parent),
200
171
  statement: getStatementRange(ts, parents, node, ast),
201
172
  argNode: node.arguments[0]
202
173
  };
203
- if (ts.isVariableDeclaration(parent)) {
204
- if (ts.isObjectBindingPattern(parent.name)) {
205
- defineProps.destructured = new Map();
206
- const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
207
- for (const { id, isRest, initializer } of identifiers) {
208
- const name = _getNodeText(id);
209
- if (isRest) {
210
- defineProps.destructuredRest = name;
211
- }
212
- else {
213
- defineProps.destructured.set(name, initializer);
214
- }
174
+ if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
175
+ defineProps.destructured = new Map();
176
+ const identifiers = (0, utils_1.collectIdentifiers)(ts, parent.name, []);
177
+ for (const { id, isRest, initializer } of identifiers) {
178
+ const name = _getNodeText(id);
179
+ if (isRest) {
180
+ defineProps.destructuredRest = name;
181
+ }
182
+ else {
183
+ defineProps.destructured.set(name, initializer);
215
184
  }
216
- }
217
- else {
218
- defineProps.name = _getNodeText(parent.name);
219
185
  }
220
186
  }
221
187
  else if (ts.isCallExpression(parent)
@@ -237,12 +203,9 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
237
203
  }
238
204
  else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
239
205
  defineEmits = {
240
- ...parseCallExpression(node),
206
+ ...parseCallExpressionAssignment(node, parent),
241
207
  statement: getStatementRange(ts, parents, node, ast)
242
208
  };
243
- if (ts.isVariableDeclaration(parent)) {
244
- defineEmits.name = _getNodeText(parent.name);
245
- }
246
209
  if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
247
210
  for (const member of node.typeArguments[0].members) {
248
211
  if (ts.isCallSignatureDeclaration(member)) {
@@ -257,12 +220,9 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
257
220
  }
258
221
  else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
259
222
  defineSlots = {
260
- ...parseCallExpression(node),
223
+ ...parseCallExpressionAssignment(node, parent),
261
224
  statement: getStatementRange(ts, parents, node, ast)
262
225
  };
263
- if (ts.isVariableDeclaration(parent)) {
264
- defineSlots.name = _getNodeText(parent.name);
265
- }
266
226
  }
267
227
  else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
268
228
  defineExpose = parseCallExpression(node);
@@ -295,10 +255,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
295
255
  }
296
256
  else if (vueCompilerOptions.composables.useTemplateRef.includes(callText)
297
257
  && !node.typeArguments?.length) {
298
- useTemplateRef.push({
299
- name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
300
- ...parseCallExpression(node)
301
- });
258
+ useTemplateRef.push(parseCallExpressionAssignment(node, parent));
302
259
  }
303
260
  }
304
261
  ts.forEachChild(node, child => {
@@ -318,6 +275,12 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
318
275
  typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
319
276
  };
320
277
  }
278
+ function parseCallExpressionAssignment(node, parent) {
279
+ return {
280
+ name: ts.isVariableDeclaration(parent) ? _getNodeText(parent.name) : undefined,
281
+ ...parseCallExpression(node),
282
+ };
283
+ }
321
284
  function _getStartEnd(node) {
322
285
  return getStartEnd(ts, node, ast);
323
286
  }
@@ -459,4 +422,19 @@ function getStatementRange(ts, parents, node, ast) {
459
422
  }
460
423
  return statementRange;
461
424
  }
425
+ function getCommentsRange(ts, node, parents, ast) {
426
+ for (let i = parents.length - 1; i >= 0; i--) {
427
+ if (ts.isStatement(node)) {
428
+ break;
429
+ }
430
+ node = parents[i];
431
+ }
432
+ const comments = ts.getLeadingCommentRanges(ast.text, node.pos);
433
+ if (comments?.length) {
434
+ return {
435
+ start: comments[0].pos,
436
+ end: comments.at(-1).end,
437
+ };
438
+ }
439
+ }
462
440
  //# sourceMappingURL=scriptSetupRanges.js.map
@@ -6,6 +6,7 @@ const buildMappings_1 = require("../utils/buildMappings");
6
6
  const parseSfc_1 = require("../utils/parseSfc");
7
7
  const codeblockReg = /(`{3,})[\s\S]+?\1/g;
8
8
  const inlineCodeblockReg = /`[^\n`]+?`/g;
9
+ const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
9
10
  const scriptSetupReg = /\\\<[\s\S]+?\>\n?/g;
10
11
  const sfcBlockReg = /\<(script|style)\b[\s\S]*?\>([\s\S]*?)\<\/\1\>/g;
11
12
  const angleBracketReg = /\<\S*\:\S*\>/g;
@@ -31,6 +32,8 @@ const plugin = ({ vueCompilerOptions }) => {
31
32
  .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
32
33
  // inline code block
33
34
  .replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
35
+ // latex block
36
+ .replace(latexBlockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
34
37
  // # \<script setup>
35
38
  .replace(scriptSetupReg, match => ' '.repeat(match.length))
36
39
  // <<< https://vitepress.dev/guide/markdown#import-code-snippets
@@ -60,10 +60,10 @@ const plugin = ctx => {
60
60
  return data;
61
61
  function visit(node) {
62
62
  if (node.type === CompilerDOM.NodeTypes.COMMENT) {
63
- const match = node.loc.source.match(/^<!--\s*@vue-generic\b\s*\{(?<content>[^}]*)\}/);
63
+ const match = node.loc.source.match(/^<!--\s*@vue-generic\s*\{(?<content>[\s\S]*)\}\s*-->$/);
64
64
  if (match) {
65
- const { content } = match.groups ?? {};
66
- addFormatCodes(content, node.loc.start.offset + match[0].indexOf(content), formatBrackets.generic);
65
+ const { content } = match.groups;
66
+ addFormatCodes(content, node.loc.start.offset + node.loc.source.indexOf('{') + 1, formatBrackets.generic);
67
67
  }
68
68
  }
69
69
  else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {