@vue/language-core 1.9.0-alpha.3 → 2.0.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 (93) hide show
  1. package/index.d.ts +13 -0
  2. package/{out/index.js → index.js} +12 -14
  3. package/lib/generators/script.d.ts +13 -0
  4. package/lib/generators/script.js +1060 -0
  5. package/lib/generators/template.d.ts +9 -0
  6. package/lib/generators/template.js +1567 -0
  7. package/lib/generators/utils.d.ts +6 -0
  8. package/lib/generators/utils.js +58 -0
  9. package/lib/languageModule.d.ts +5 -0
  10. package/lib/languageModule.js +114 -0
  11. package/{out → lib}/parsers/scriptRanges.d.ts +2 -3
  12. package/{out → lib}/parsers/scriptRanges.js +11 -6
  13. package/{out → lib}/parsers/scriptSetupRanges.d.ts +17 -9
  14. package/{out → lib}/parsers/scriptSetupRanges.js +42 -35
  15. package/lib/plugins/file-html.d.ts +3 -0
  16. package/{out → lib}/plugins/file-html.js +1 -1
  17. package/lib/plugins/file-md.d.ts +3 -0
  18. package/{out → lib}/plugins/file-md.js +8 -8
  19. package/lib/plugins/file-vue.d.ts +3 -0
  20. package/{out → lib}/plugins/file-vue.js +9 -2
  21. package/lib/plugins/vue-sfc-customblocks.d.ts +3 -0
  22. package/lib/plugins/vue-sfc-customblocks.js +28 -0
  23. package/lib/plugins/vue-sfc-scripts.d.ts +3 -0
  24. package/lib/plugins/vue-sfc-scripts.js +36 -0
  25. package/lib/plugins/vue-sfc-styles.d.ts +3 -0
  26. package/lib/plugins/vue-sfc-styles.js +28 -0
  27. package/lib/plugins/vue-sfc-template.d.ts +3 -0
  28. package/lib/plugins/vue-sfc-template.js +29 -0
  29. package/lib/plugins/vue-template-html.d.ts +3 -0
  30. package/{out → lib}/plugins/vue-template-html.js +12 -12
  31. package/{out → lib}/plugins/vue-tsx.d.ts +25 -18
  32. package/lib/plugins/vue-tsx.js +212 -0
  33. package/{out → lib}/plugins.d.ts +19 -7
  34. package/{out → lib}/plugins.js +24 -18
  35. package/{out → lib}/types.d.ts +26 -9
  36. package/lib/types.js +5 -0
  37. package/{out → lib}/utils/parseCssClassNames.d.ts +0 -1
  38. package/{out → lib}/utils/parseCssVars.d.ts +0 -1
  39. package/{out → lib}/utils/parseSfc.d.ts +0 -1
  40. package/{out → lib}/utils/parseSfc.js +4 -18
  41. package/{out → lib}/utils/shared.d.ts +0 -1
  42. package/lib/utils/transform.d.ts +8 -0
  43. package/{out → lib}/utils/transform.js +62 -62
  44. package/{out → lib}/utils/ts.d.ts +3 -4
  45. package/{out → lib}/utils/ts.js +0 -12
  46. package/lib/utils/vue2TemplateCompiler.d.ts +2 -0
  47. package/{out → lib}/utils/vue2TemplateCompiler.js +5 -2
  48. package/{out → lib}/virtualFile/computedFiles.d.ts +2 -3
  49. package/{out → lib}/virtualFile/computedFiles.js +55 -42
  50. package/lib/virtualFile/computedMappings.d.ts +4 -0
  51. package/{out → lib}/virtualFile/computedMappings.js +9 -12
  52. package/lib/virtualFile/computedSfc.d.ts +4 -0
  53. package/{out → lib}/virtualFile/computedSfc.js +3 -3
  54. package/{out → lib}/virtualFile/computedVueSfc.d.ts +2 -3
  55. package/lib/virtualFile/embeddedFile.d.ts +12 -0
  56. package/lib/virtualFile/embeddedFile.js +15 -0
  57. package/lib/virtualFile/vueFile.d.ts +25 -0
  58. package/{out → lib}/virtualFile/vueFile.js +11 -21
  59. package/package.json +8 -11
  60. package/out/generators/script.d.ts +0 -15
  61. package/out/generators/script.js +0 -887
  62. package/out/generators/template.d.ts +0 -21
  63. package/out/generators/template.js +0 -1506
  64. package/out/index.d.ts +0 -16
  65. package/out/languageModule.d.ts +0 -10
  66. package/out/languageModule.js +0 -99
  67. package/out/plugins/file-html.d.ts +0 -4
  68. package/out/plugins/file-md.d.ts +0 -4
  69. package/out/plugins/file-vue.d.ts +0 -4
  70. package/out/plugins/vue-sfc-customblocks.d.ts +0 -4
  71. package/out/plugins/vue-sfc-customblocks.js +0 -33
  72. package/out/plugins/vue-sfc-scripts.d.ts +0 -4
  73. package/out/plugins/vue-sfc-scripts.js +0 -42
  74. package/out/plugins/vue-sfc-styles.d.ts +0 -4
  75. package/out/plugins/vue-sfc-styles.js +0 -33
  76. package/out/plugins/vue-sfc-template.d.ts +0 -4
  77. package/out/plugins/vue-sfc-template.js +0 -29
  78. package/out/plugins/vue-template-html.d.ts +0 -4
  79. package/out/plugins/vue-tsx.js +0 -159
  80. package/out/types.js +0 -3
  81. package/out/utils/globalTypes.d.ts +0 -4
  82. package/out/utils/globalTypes.js +0 -135
  83. package/out/utils/transform.d.ts +0 -9
  84. package/out/utils/vue2TemplateCompiler.d.ts +0 -3
  85. package/out/virtualFile/computedMappings.d.ts +0 -6
  86. package/out/virtualFile/computedSfc.d.ts +0 -5
  87. package/out/virtualFile/embeddedFile.d.ts +0 -13
  88. package/out/virtualFile/embeddedFile.js +0 -16
  89. package/out/virtualFile/vueFile.d.ts +0 -28
  90. /package/{out → lib}/utils/parseCssClassNames.js +0 -0
  91. /package/{out → lib}/utils/parseCssVars.js +0 -0
  92. /package/{out → lib}/utils/shared.js +0 -0
  93. /package/{out → lib}/virtualFile/computedVueSfc.js +0 -0
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../generators/utils");
4
+ const plugin = () => {
5
+ return {
6
+ version: 2,
7
+ getEmbeddedCodes(_fileName, sfc) {
8
+ const names = [];
9
+ if (sfc.script) {
10
+ names.push({ id: 'scriptFormat', lang: sfc.script.lang });
11
+ }
12
+ if (sfc.scriptSetup) {
13
+ names.push({ id: 'scriptSetupFormat', lang: sfc.scriptSetup.lang });
14
+ }
15
+ return names;
16
+ },
17
+ resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
18
+ const script = embeddedFile.id === 'scriptFormat' ? sfc.script
19
+ : embeddedFile.id === 'scriptSetupFormat' ? sfc.scriptSetup
20
+ : undefined;
21
+ if (script) {
22
+ embeddedFile.content.push([
23
+ script.content,
24
+ script.name,
25
+ 0,
26
+ (0, utils_1.disableAllFeatures)({
27
+ structure: true,
28
+ format: true,
29
+ }),
30
+ ]);
31
+ }
32
+ },
33
+ };
34
+ };
35
+ exports.default = plugin;
36
+ //# sourceMappingURL=vue-sfc-scripts.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../generators/utils");
4
+ const plugin = () => {
5
+ return {
6
+ version: 2,
7
+ getEmbeddedCodes(_fileName, sfc) {
8
+ return sfc.styles.map((style, i) => ({
9
+ id: 'style_' + i,
10
+ lang: style.lang,
11
+ }));
12
+ },
13
+ resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
14
+ if (embeddedFile.id.startsWith('style_')) {
15
+ const index = parseInt(embeddedFile.id.slice('style_'.length));
16
+ const style = sfc.styles[index];
17
+ embeddedFile.content.push([
18
+ style.content,
19
+ style.name,
20
+ 0,
21
+ (0, utils_1.enableAllFeatures)({}),
22
+ ]);
23
+ }
24
+ },
25
+ };
26
+ };
27
+ exports.default = plugin;
28
+ //# sourceMappingURL=vue-sfc-styles.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../generators/utils");
4
+ const plugin = () => {
5
+ return {
6
+ version: 2,
7
+ getEmbeddedCodes(_fileName, sfc) {
8
+ if (sfc.template) {
9
+ return [{
10
+ id: 'template',
11
+ lang: sfc.template.lang,
12
+ }];
13
+ }
14
+ return [];
15
+ },
16
+ resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
17
+ if (embeddedFile.id === 'template' && sfc.template) {
18
+ embeddedFile.content.push([
19
+ sfc.template.content,
20
+ sfc.template.name,
21
+ 0,
22
+ (0, utils_1.enableAllFeatures)({}),
23
+ ]);
24
+ }
25
+ },
26
+ };
27
+ };
28
+ exports.default = plugin;
29
+ //# sourceMappingURL=vue-sfc-template.js.map
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export default plugin;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plugin = ({ modules }) => {
4
4
  return {
5
- version: 1,
5
+ version: 2,
6
6
  compileSFCTemplate(lang, template, options) {
7
7
  if (lang === 'html') {
8
8
  const compiler = modules['@vue/compiler-dom'];
@@ -19,7 +19,7 @@ const plugin = ({ modules }) => {
19
19
  if (tryUpdateNode(oldResult.ast) && hitNodes.length) {
20
20
  hitNodes = hitNodes.sort((a, b) => a.loc.source.length - b.loc.source.length);
21
21
  const hitNode = hitNodes[0];
22
- if (hitNode.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
22
+ if (hitNode.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
23
23
  return oldResult;
24
24
  }
25
25
  }
@@ -28,14 +28,14 @@ const plugin = ({ modules }) => {
28
28
  hitNodes.push(node);
29
29
  }
30
30
  if (tryUpdateNodeLoc(node.loc)) {
31
- if (node.type === 0 /* CompilerDOM.NodeTypes.ROOT */) {
31
+ if (node.type === CompilerDOM.NodeTypes.ROOT) {
32
32
  for (const child of node.children) {
33
33
  if (!tryUpdateNode(child)) {
34
34
  return false;
35
35
  }
36
36
  }
37
37
  }
38
- else if (node.type === 1 /* CompilerDOM.NodeTypes.ELEMENT */) {
38
+ else if (node.type === CompilerDOM.NodeTypes.ELEMENT) {
39
39
  if (withinChangeRange(node.loc)) {
40
40
  // if not self closing, should not hit tag name
41
41
  const start = node.loc.start.offset + 2;
@@ -55,12 +55,12 @@ const plugin = ({ modules }) => {
55
55
  }
56
56
  }
57
57
  }
58
- else if (node.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */) {
58
+ else if (node.type === CompilerDOM.NodeTypes.ATTRIBUTE) {
59
59
  if (node.value && !tryUpdateNode(node.value)) {
60
60
  return false;
61
61
  }
62
62
  }
63
- else if (node.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */) {
63
+ else if (node.type === CompilerDOM.NodeTypes.DIRECTIVE) {
64
64
  if (node.arg && withinChangeRange(node.arg.loc) && node.name === 'slot') {
65
65
  return false;
66
66
  }
@@ -74,12 +74,12 @@ const plugin = ({ modules }) => {
74
74
  return false;
75
75
  }
76
76
  }
77
- else if (node.type === 12 /* CompilerDOM.NodeTypes.TEXT_CALL */) {
77
+ else if (node.type === CompilerDOM.NodeTypes.TEXT_CALL) {
78
78
  if (!tryUpdateNode(node.content)) {
79
79
  return false;
80
80
  }
81
81
  }
82
- else if (node.type === 8 /* CompilerDOM.NodeTypes.COMPOUND_EXPRESSION */) {
82
+ else if (node.type === CompilerDOM.NodeTypes.COMPOUND_EXPRESSION) {
83
83
  for (const childNode of node.children) {
84
84
  if (typeof childNode === 'object') {
85
85
  if (!tryUpdateNode(childNode)) {
@@ -88,7 +88,7 @@ const plugin = ({ modules }) => {
88
88
  }
89
89
  }
90
90
  }
91
- else if (node.type === 9 /* CompilerDOM.NodeTypes.IF */) {
91
+ else if (node.type === CompilerDOM.NodeTypes.IF) {
92
92
  for (const branch of node.branches) {
93
93
  if (branch.condition && !tryUpdateNode(branch.condition)) {
94
94
  return false;
@@ -100,7 +100,7 @@ const plugin = ({ modules }) => {
100
100
  }
101
101
  }
102
102
  }
103
- else if (node.type === 11 /* CompilerDOM.NodeTypes.FOR */) {
103
+ else if (node.type === CompilerDOM.NodeTypes.FOR) {
104
104
  for (const child of [
105
105
  node.parseResult.source,
106
106
  node.parseResult.value,
@@ -117,12 +117,12 @@ const plugin = ({ modules }) => {
117
117
  }
118
118
  }
119
119
  }
120
- else if (node.type === 5 /* CompilerDOM.NodeTypes.INTERPOLATION */) {
120
+ else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
121
121
  if (!tryUpdateNode(node.content)) {
122
122
  return false;
123
123
  }
124
124
  }
125
- else if (node.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
125
+ else if (node.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
126
126
  if (withinChangeRange(node.loc)) { // TODO: review this (slot name?)
127
127
  if (node.isStatic) {
128
128
  return false;
@@ -1,13 +1,13 @@
1
- import { Sfc, VueLanguagePlugin } from '../types';
2
- import * as muggle from 'muggle-string';
1
+ import { Mapping, StackNode } from '@volar/language-core';
2
+ import type { Code, Sfc, VueLanguagePlugin } from '../types';
3
3
  export declare const tsCodegen: WeakMap<Sfc, {
4
4
  scriptRanges: () => {
5
5
  exportDefault: (import("../types").TextRange & {
6
6
  expression: import("../types").TextRange;
7
7
  args: import("../types").TextRange;
8
- argsNode: import("typescript/lib/tsserverlibrary").ObjectLiteralExpression | undefined;
8
+ argsNode: import("typescript").ObjectLiteralExpression | undefined;
9
9
  componentsOption: import("../types").TextRange | undefined;
10
- componentsOptionNode: import("typescript/lib/tsserverlibrary").ObjectLiteralExpression | undefined;
10
+ componentsOptionNode: import("typescript").ObjectLiteralExpression | undefined;
11
11
  nameOption: import("../types").TextRange | undefined;
12
12
  }) | undefined;
13
13
  bindings: import("../types").TextRange[];
@@ -19,9 +19,10 @@ export declare const tsCodegen: WeakMap<Sfc, {
19
19
  props: {
20
20
  name?: string | undefined;
21
21
  define?: (import("../types").TextRange & {
22
- statement: import("../types").TextRange;
23
22
  arg?: import("../types").TextRange | undefined;
24
23
  typeArg?: import("../types").TextRange | undefined;
24
+ } & {
25
+ statement: import("../types").TextRange;
25
26
  }) | undefined;
26
27
  withDefaults?: (import("../types").TextRange & {
27
28
  arg?: import("../types").TextRange | undefined;
@@ -29,11 +30,17 @@ export declare const tsCodegen: WeakMap<Sfc, {
29
30
  };
30
31
  slots: {
31
32
  name?: string | undefined;
32
- define?: import("../types").TextRange | undefined;
33
+ define?: (import("../types").TextRange & {
34
+ arg?: import("../types").TextRange | undefined;
35
+ typeArg?: import("../types").TextRange | undefined;
36
+ }) | undefined;
33
37
  };
34
38
  emits: {
35
39
  name?: string | undefined;
36
- define?: import("../types").TextRange | undefined;
40
+ define?: (import("../types").TextRange & {
41
+ arg?: import("../types").TextRange | undefined;
42
+ typeArg?: import("../types").TextRange | undefined;
43
+ }) | undefined;
37
44
  };
38
45
  expose: {
39
46
  name?: string | undefined;
@@ -48,26 +55,26 @@ export declare const tsCodegen: WeakMap<Sfc, {
48
55
  type: import("../types").TextRange | undefined;
49
56
  defaultValue: import("../types").TextRange | undefined;
50
57
  required: boolean;
58
+ isModel?: boolean | undefined;
51
59
  }[];
52
60
  } | undefined;
53
61
  lang: () => string;
54
62
  generatedScript: () => {
55
- codes: muggle.Segment<import("@volar/language-core").FileRangeCapabilities>[];
56
- codeStacks: muggle.StackNode[];
57
- mirrorBehaviorMappings: import("@volar/source-map").Mapping<[import("@volar/language-core").MirrorBehaviorCapabilities, import("@volar/language-core").MirrorBehaviorCapabilities]>[];
63
+ codes: Code[];
64
+ codeStacks: StackNode[];
65
+ linkedCodeMappings: Mapping<any>[];
58
66
  };
59
67
  generatedTemplate: () => {
60
- codes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
61
- codeStacks: muggle.StackNode[];
62
- formatCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
63
- formatCodeStacks: muggle.StackNode[];
64
- cssCodes: (string | [string, string | undefined, number | [number, number], import("@volar/language-core").FileRangeCapabilities])[];
65
- cssCodeStacks: muggle.StackNode[];
66
- tagNames: Record<string, number[]>;
68
+ codes: Code[];
69
+ codeStacks: string[];
70
+ formatCodes: Code[];
71
+ formatCodeStacks: string[];
72
+ cssCodes: Code[];
73
+ cssCodeStacks: string[];
74
+ tagOffsetsMap: Map<string, number[]>;
67
75
  accessedGlobalVariables: Set<string>;
68
76
  hasSlot: boolean;
69
77
  } | undefined;
70
78
  }>;
71
79
  declare const plugin: VueLanguagePlugin;
72
80
  export default plugin;
73
- //# sourceMappingURL=vue-tsx.d.ts.map
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsCodegen = void 0;
4
+ const language_core_1 = require("@volar/language-core");
5
+ const computeds_1 = require("computeds");
6
+ const script_1 = require("../generators/script");
7
+ const template_1 = require("../generators/template");
8
+ const utils_1 = require("../generators/utils");
9
+ const scriptRanges_1 = require("../parsers/scriptRanges");
10
+ const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
11
+ exports.tsCodegen = new WeakMap();
12
+ const plugin = (ctx) => {
13
+ return {
14
+ version: 2,
15
+ requiredCompilerOptions: [
16
+ 'noPropertyAccessFromIndexSignature',
17
+ 'exactOptionalPropertyTypes',
18
+ ],
19
+ getEmbeddedCodes(fileName, sfc) {
20
+ const tsx = useTsx(fileName, sfc);
21
+ const files = [];
22
+ if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang())) {
23
+ files.push({ id: 'script_' + tsx.lang(), lang: tsx.lang() });
24
+ }
25
+ if (sfc.template) {
26
+ files.push({ id: 'template_format', lang: 'ts' });
27
+ files.push({ id: 'template_style', lang: 'css' });
28
+ }
29
+ return files;
30
+ },
31
+ resolveEmbeddedCode(fileName, sfc, embeddedFile) {
32
+ const _tsx = useTsx(fileName, sfc);
33
+ if (embeddedFile.id.startsWith('script_')) {
34
+ const tsx = _tsx.generatedScript();
35
+ if (tsx) {
36
+ const [content, contentStacks] = ctx.codegenStack ? (0, language_core_1.track)([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
37
+ content.forEach(code => {
38
+ if (typeof code !== 'string') {
39
+ code[3].structure = false;
40
+ code[3].format = false;
41
+ }
42
+ });
43
+ embeddedFile.content = content;
44
+ embeddedFile.contentStacks = contentStacks;
45
+ embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
46
+ }
47
+ }
48
+ else if (embeddedFile.id === 'template_format') {
49
+ embeddedFile.parentCodeId = 'template';
50
+ const template = _tsx.generatedTemplate();
51
+ if (template) {
52
+ const [content, contentStacks] = ctx.codegenStack
53
+ ? (0, language_core_1.track)([...template.formatCodes], template.formatCodeStacks.map(stack => ({ stack, length: 1 })))
54
+ : [[...template.formatCodes], template.formatCodeStacks.map(stack => ({ stack, length: 1 }))];
55
+ embeddedFile.content = content;
56
+ embeddedFile.contentStacks = contentStacks;
57
+ }
58
+ for (const style of sfc.styles) {
59
+ embeddedFile.content.push('\n\n');
60
+ for (const cssVar of style.cssVars) {
61
+ embeddedFile.content.push('(');
62
+ embeddedFile.content.push([
63
+ cssVar.text,
64
+ style.name,
65
+ cssVar.offset,
66
+ (0, utils_1.enableAllFeatures)({}),
67
+ ]);
68
+ embeddedFile.content.push(');\n');
69
+ }
70
+ }
71
+ }
72
+ else if (embeddedFile.id === 'template_style') {
73
+ embeddedFile.parentCodeId = 'template';
74
+ const template = _tsx.generatedTemplate();
75
+ if (template) {
76
+ const [content, contentStacks] = ctx.codegenStack
77
+ ? (0, language_core_1.track)([...template.cssCodes], template.cssCodeStacks.map(stack => ({ stack, length: 1 })))
78
+ : [[...template.cssCodes], template.cssCodeStacks.map(stack => ({ stack, length: 1 }))];
79
+ embeddedFile.content = content;
80
+ embeddedFile.contentStacks = contentStacks;
81
+ }
82
+ }
83
+ },
84
+ };
85
+ function useTsx(fileName, sfc) {
86
+ if (!exports.tsCodegen.has(sfc)) {
87
+ exports.tsCodegen.set(sfc, createTsx(fileName, sfc, ctx));
88
+ }
89
+ return exports.tsCodegen.get(sfc);
90
+ }
91
+ };
92
+ exports.default = plugin;
93
+ function createTsx(fileName, _sfc, ctx) {
94
+ const ts = ctx.modules.typescript;
95
+ const lang = (0, computeds_1.computed)(() => {
96
+ return !_sfc.script && !_sfc.scriptSetup ? 'ts'
97
+ : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
98
+ : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
99
+ : 'js';
100
+ });
101
+ const scriptRanges = (0, computeds_1.computed)(() => _sfc.script
102
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.script.ast, !!_sfc.scriptSetup, false)
103
+ : undefined);
104
+ const scriptSetupRanges = (0, computeds_1.computed)(() => _sfc.scriptSetup
105
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetup.ast, ctx.vueCompilerOptions)
106
+ : undefined);
107
+ const shouldGenerateScopedClasses = (0, computeds_1.computed)(() => {
108
+ const option = ctx.vueCompilerOptions.experimentalResolveStyleCssClasses;
109
+ return _sfc.styles.some(s => {
110
+ return option === 'always' || (option === 'scoped' && s.scoped);
111
+ });
112
+ });
113
+ const stylesScopedClasses = (0, computeds_1.computedSet)(() => {
114
+ const classes = new Set();
115
+ if (!shouldGenerateScopedClasses()) {
116
+ return classes;
117
+ }
118
+ for (const style of _sfc.styles) {
119
+ const option = ctx.vueCompilerOptions.experimentalResolveStyleCssClasses;
120
+ if (option === 'always' || (option === 'scoped' && style.scoped)) {
121
+ for (const className of style.classNames) {
122
+ classes.add(className.text.substring(1));
123
+ }
124
+ }
125
+ }
126
+ return classes;
127
+ });
128
+ const generatedTemplate = (0, computeds_1.computed)(() => {
129
+ if (!_sfc.template)
130
+ return;
131
+ const tsCodes = [];
132
+ const tsFormatCodes = [];
133
+ const inlineCssCodes = [];
134
+ const tsCodegenStacks = [];
135
+ const tsFormatCodegenStacks = [];
136
+ const inlineCssCodegenStacks = [];
137
+ const codegen = (0, template_1.generate)(ts, ctx.compilerOptions, ctx.vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), ctx.codegenStack);
138
+ let current = codegen.next();
139
+ while (!current.done) {
140
+ const [type, code, stack] = current.value;
141
+ if (type === 'ts') {
142
+ tsCodes.push(code);
143
+ }
144
+ else if (type === 'tsFormat') {
145
+ tsFormatCodes.push(code);
146
+ }
147
+ else if (type === 'inlineCss') {
148
+ inlineCssCodes.push(code);
149
+ }
150
+ if (ctx.codegenStack) {
151
+ if (type === 'ts') {
152
+ tsCodegenStacks.push(stack);
153
+ }
154
+ else if (type === 'tsFormat') {
155
+ tsFormatCodegenStacks.push(stack);
156
+ }
157
+ else if (type === 'inlineCss') {
158
+ inlineCssCodegenStacks.push(stack);
159
+ }
160
+ }
161
+ current = codegen.next();
162
+ }
163
+ return {
164
+ ...current.value,
165
+ codes: tsCodes,
166
+ codeStacks: tsCodegenStacks,
167
+ formatCodes: tsFormatCodes,
168
+ formatCodeStacks: tsFormatCodegenStacks,
169
+ cssCodes: inlineCssCodes,
170
+ cssCodeStacks: inlineCssCodegenStacks,
171
+ };
172
+ });
173
+ const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
174
+ const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
175
+ const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
176
+ const generatedScript = (0, computeds_1.computed)(() => {
177
+ const codes = [];
178
+ const codeStacks = [];
179
+ const linkedCodeMappings = [];
180
+ const _template = generatedTemplate();
181
+ let generatedLength = 0;
182
+ for (const [code, stack] of (0, script_1.generate)(ts, fileName, _sfc.script, _sfc.scriptSetup, _sfc.styles, lang(), scriptRanges(), scriptSetupRanges(), _template ? {
183
+ tsCodes: _template.codes,
184
+ tsCodegenStacks: _template.codeStacks,
185
+ accessedGlobalVariables: _template.accessedGlobalVariables,
186
+ hasSlot: _template.hasSlot,
187
+ tagNames: new Set(_template.tagOffsetsMap.keys()),
188
+ } : undefined, ctx.compilerOptions, ctx.vueCompilerOptions, ctx.globalTypesHolder, () => generatedLength, linkedCodeMappings, ctx.codegenStack)) {
189
+ codes.push(code);
190
+ if (ctx.codegenStack) {
191
+ codeStacks.push({ stack, length: 1 });
192
+ }
193
+ generatedLength += typeof code === 'string'
194
+ ? code.length
195
+ : code[0].length;
196
+ }
197
+ ;
198
+ return {
199
+ codes,
200
+ codeStacks,
201
+ linkedCodeMappings,
202
+ };
203
+ });
204
+ return {
205
+ scriptRanges,
206
+ scriptSetupRanges,
207
+ lang,
208
+ generatedScript,
209
+ generatedTemplate,
210
+ };
211
+ }
212
+ //# sourceMappingURL=vue-tsx.js.map
@@ -1,8 +1,18 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import { VueCompilerOptions } from './types';
3
1
  import * as CompilerDOM from '@vue/compiler-dom';
4
- export declare function getDefaultVueLanguagePlugins(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean): {
5
- version: 1;
2
+ import type * as ts from 'typescript';
3
+ import { type VueCompilerOptions, type VueLanguagePlugin } from './types';
4
+ export declare function createPluginContext(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean, globalTypesHolder: string | undefined): {
5
+ modules: {
6
+ typescript: typeof import("typescript");
7
+ '@vue/compiler-dom': typeof CompilerDOM;
8
+ };
9
+ compilerOptions: ts.CompilerOptions;
10
+ vueCompilerOptions: VueCompilerOptions;
11
+ codegenStack: boolean;
12
+ globalTypesHolder: string | undefined;
13
+ };
14
+ export declare function getDefaultVueLanguagePlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): {
15
+ version: 2;
6
16
  name?: string | undefined;
7
17
  order?: number | undefined;
8
18
  requiredCompilerOptions?: string[] | undefined;
@@ -19,7 +29,9 @@ export declare function getDefaultVueLanguagePlugins(ts: typeof import('typescri
19
29
  end: number;
20
30
  newText: string;
21
31
  }): CompilerDOM.CodegenResult | undefined;
22
- getEmbeddedFileNames?(fileName: string, sfc: import("./types").Sfc): string[];
23
- resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./virtualFile/embeddedFile").VueEmbeddedFile): void;
32
+ getEmbeddedCodes?(fileName: string, sfc: import("./types").Sfc): {
33
+ id: string;
34
+ lang: string;
35
+ }[];
36
+ resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./virtualFile/embeddedFile").VueEmbeddedCode): void;
24
37
  }[];
25
- //# sourceMappingURL=plugins.d.ts.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultVueLanguagePlugins = void 0;
3
+ exports.getDefaultVueLanguagePlugins = exports.createPluginContext = void 0;
4
+ const CompilerDOM = require("@vue/compiler-dom");
4
5
  const file_html_1 = require("./plugins/file-html");
5
6
  const file_md_1 = require("./plugins/file-md");
6
7
  const file_vue_1 = require("./plugins/file-vue");
@@ -10,21 +11,9 @@ const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
10
11
  const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
11
12
  const vue_template_html_1 = require("./plugins/vue-template-html");
12
13
  const vue_tsx_1 = require("./plugins/vue-tsx");
13
- const CompilerDOM = require("@vue/compiler-dom");
14
+ const types_1 = require("./types");
14
15
  const CompilerVue2 = require("./utils/vue2TemplateCompiler");
15
- function getDefaultVueLanguagePlugins(ts, compilerOptions, vueCompilerOptions, codegenStack) {
16
- const plugins = [
17
- file_md_1.default,
18
- file_html_1.default,
19
- file_vue_1.default,
20
- vue_template_html_1.default,
21
- vue_sfc_styles_1.default,
22
- vue_sfc_customblocks_1.default,
23
- vue_sfc_scripts_1.default,
24
- vue_sfc_template_1.default,
25
- vue_tsx_1.default,
26
- ...vueCompilerOptions.plugins,
27
- ];
16
+ function createPluginContext(ts, compilerOptions, vueCompilerOptions, codegenStack, globalTypesHolder) {
28
17
  const pluginCtx = {
29
18
  modules: {
30
19
  '@vue/compiler-dom': vueCompilerOptions.target < 3
@@ -38,18 +27,35 @@ function getDefaultVueLanguagePlugins(ts, compilerOptions, vueCompilerOptions, c
38
27
  compilerOptions,
39
28
  vueCompilerOptions,
40
29
  codegenStack,
30
+ globalTypesHolder,
41
31
  };
32
+ return pluginCtx;
33
+ }
34
+ exports.createPluginContext = createPluginContext;
35
+ function getDefaultVueLanguagePlugins(pluginContext) {
36
+ const plugins = [
37
+ file_md_1.default, // .md for VitePress
38
+ file_html_1.default, // .html for PetiteVue
39
+ file_vue_1.default, // .vue and others for Vue
40
+ vue_template_html_1.default,
41
+ vue_sfc_styles_1.default,
42
+ vue_sfc_customblocks_1.default,
43
+ vue_sfc_scripts_1.default,
44
+ vue_sfc_template_1.default,
45
+ vue_tsx_1.default,
46
+ ...pluginContext.vueCompilerOptions.plugins,
47
+ ];
42
48
  const pluginInstances = plugins
43
- .map(plugin => plugin(pluginCtx))
49
+ .map(plugin => plugin(pluginContext))
44
50
  .sort((a, b) => {
45
51
  const aOrder = a.order ?? 0;
46
52
  const bOrder = b.order ?? 0;
47
53
  return aOrder - bOrder;
48
54
  });
49
55
  return pluginInstances.filter((plugin) => {
50
- const valid = plugin.version >= 1 && plugin.version < 2;
56
+ const valid = plugin.version === types_1.pluginVersion;
51
57
  if (!valid) {
52
- console.warn(`Plugin ${JSON.stringify(plugin.name)} API version incompatible, expected 1.x but got ${JSON.stringify(plugin.version)}`);
58
+ console.warn(`Plugin ${JSON.stringify(plugin.name)} API version incompatible, expected ${JSON.stringify(types_1.pluginVersion)} but got ${JSON.stringify(plugin.version)}`);
53
59
  }
54
60
  return valid;
55
61
  });