@vue/language-core 2.0.12 → 2.0.14

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 (85) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/codegen/common.d.ts +11 -0
  4. package/lib/codegen/common.js +70 -0
  5. package/lib/codegen/script/component.d.ts +9 -0
  6. package/lib/codegen/script/component.js +101 -0
  7. package/lib/codegen/script/context.d.ts +25 -0
  8. package/lib/codegen/script/context.js +124 -0
  9. package/lib/{generators → codegen/script}/globalTypes.d.ts +1 -1
  10. package/lib/codegen/script/globalTypes.js +135 -0
  11. package/lib/codegen/script/index.d.ts +33 -0
  12. package/lib/codegen/script/index.js +127 -0
  13. package/lib/codegen/script/internalComponent.d.ts +5 -0
  14. package/lib/codegen/script/internalComponent.js +58 -0
  15. package/lib/codegen/script/scriptSetup.d.ts +6 -0
  16. package/lib/codegen/script/scriptSetup.js +338 -0
  17. package/lib/codegen/script/src.d.ts +2 -0
  18. package/lib/codegen/script/src.js +52 -0
  19. package/lib/codegen/script/template.d.ts +5 -0
  20. package/lib/codegen/script/template.js +193 -0
  21. package/lib/codegen/template/camelized.d.ts +2 -0
  22. package/lib/codegen/template/camelized.js +32 -0
  23. package/lib/codegen/template/context.d.ts +44 -0
  24. package/lib/codegen/template/context.js +171 -0
  25. package/lib/codegen/template/element.d.ts +7 -0
  26. package/lib/codegen/template/element.js +325 -0
  27. package/lib/codegen/template/elementChildren.d.ts +5 -0
  28. package/lib/codegen/template/elementChildren.js +21 -0
  29. package/lib/codegen/template/elementDirectives.d.ts +5 -0
  30. package/lib/codegen/template/elementDirectives.js +46 -0
  31. package/lib/codegen/template/elementEvents.d.ts +7 -0
  32. package/lib/codegen/template/elementEvents.js +141 -0
  33. package/lib/codegen/template/elementProps.d.ts +5 -0
  34. package/lib/codegen/template/elementProps.js +250 -0
  35. package/lib/codegen/template/index.d.ts +60 -0
  36. package/lib/codegen/template/index.js +217 -0
  37. package/lib/codegen/template/interpolation.d.ts +6 -0
  38. package/lib/{utils/transform.js → codegen/template/interpolation.js} +76 -46
  39. package/lib/codegen/template/objectProperty.d.ts +4 -0
  40. package/lib/codegen/template/objectProperty.js +31 -0
  41. package/lib/codegen/template/propertyAccess.d.ts +4 -0
  42. package/lib/codegen/template/propertyAccess.js +24 -0
  43. package/lib/codegen/template/slotOutlet.d.ts +5 -0
  44. package/lib/codegen/template/slotOutlet.js +72 -0
  45. package/lib/codegen/template/stringLiteralKey.d.ts +2 -0
  46. package/lib/codegen/template/stringLiteralKey.js +14 -0
  47. package/lib/codegen/template/templateChild.d.ts +7 -0
  48. package/lib/codegen/template/templateChild.js +156 -0
  49. package/lib/codegen/template/vFor.d.ts +12 -0
  50. package/lib/codegen/template/vFor.js +69 -0
  51. package/lib/codegen/template/vIf.d.ts +5 -0
  52. package/lib/codegen/template/vIf.js +53 -0
  53. package/lib/languageModule.d.ts +3 -3
  54. package/lib/languageModule.js +2 -3
  55. package/lib/plugins/shared.d.ts +2 -0
  56. package/lib/plugins/shared.js +12 -0
  57. package/lib/plugins/vue-sfc-customblocks.js +2 -2
  58. package/lib/plugins/vue-sfc-scripts.js +2 -3
  59. package/lib/plugins/vue-sfc-styles.js +3 -3
  60. package/lib/plugins/vue-sfc-template.js +2 -2
  61. package/lib/plugins/vue-template-inline-css.js +34 -2
  62. package/lib/plugins/vue-template-inline-ts.js +10 -8
  63. package/lib/plugins/vue-tsx.d.ts +42 -5
  64. package/lib/plugins/vue-tsx.js +38 -28
  65. package/lib/types.d.ts +1 -3
  66. package/lib/utils/ts.js +0 -29
  67. package/lib/virtualFile/computedFiles.d.ts +1 -1
  68. package/lib/virtualFile/computedFiles.js +22 -12
  69. package/lib/virtualFile/computedMappings.js +3 -3
  70. package/lib/virtualFile/computedSfc.js +22 -1
  71. package/lib/virtualFile/embeddedFile.d.ts +2 -3
  72. package/lib/virtualFile/embeddedFile.js +1 -2
  73. package/lib/virtualFile/vueFile.d.ts +3 -5
  74. package/lib/virtualFile/vueFile.js +6 -8
  75. package/package.json +3 -3
  76. package/lib/generators/globalTypes.js +0 -135
  77. package/lib/generators/inlineCss.d.ts +0 -3
  78. package/lib/generators/inlineCss.js +0 -37
  79. package/lib/generators/script.d.ts +0 -13
  80. package/lib/generators/script.js +0 -981
  81. package/lib/generators/template.d.ts +0 -19
  82. package/lib/generators/template.js +0 -1578
  83. package/lib/generators/utils.d.ts +0 -5
  84. package/lib/generators/utils.js +0 -54
  85. package/lib/utils/transform.d.ts +0 -8
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateVIf = void 0;
4
+ const language_core_1 = require("@volar/language-core");
5
+ const CompilerDOM = require("@vue/compiler-dom");
6
+ const common_1 = require("../common");
7
+ const index_1 = require("./index");
8
+ const interpolation_1 = require("./interpolation");
9
+ const templateChild_1 = require("./templateChild");
10
+ function* generateVIf(options, ctx, node, currentElement, componentCtxVar) {
11
+ let originalBlockConditionsLength = ctx.blockConditions.length;
12
+ for (let i = 0; i < node.branches.length; i++) {
13
+ const branch = node.branches[i];
14
+ if (i === 0) {
15
+ yield `if `;
16
+ }
17
+ else if (branch.condition) {
18
+ yield `else if `;
19
+ }
20
+ else {
21
+ yield `else `;
22
+ }
23
+ let addedBlockCondition = false;
24
+ if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
25
+ const codes = [
26
+ ...(0, interpolation_1.generateInterpolation)(options, ctx, branch.condition.content, branch.condition.loc, branch.condition.loc.start.offset, ctx.codeFeatures.all, '(', ')'),
27
+ ];
28
+ for (const code of codes) {
29
+ yield code;
30
+ }
31
+ ctx.blockConditions.push((0, language_core_1.toString)(codes));
32
+ addedBlockCondition = true;
33
+ yield ` `;
34
+ }
35
+ yield `{${common_1.newLine}`;
36
+ if ((0, index_1.isFragment)(node)) {
37
+ yield* ctx.resetDirectiveComments('end of v-if start');
38
+ }
39
+ let prev;
40
+ for (const childNode of branch.children) {
41
+ yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, currentElement, prev, componentCtxVar);
42
+ prev = childNode;
43
+ }
44
+ yield* ctx.generateAutoImportCompletion();
45
+ yield `}${common_1.newLine}`;
46
+ if (addedBlockCondition) {
47
+ ctx.blockConditions[ctx.blockConditions.length - 1] = `!(${ctx.blockConditions[ctx.blockConditions.length - 1]})`;
48
+ }
49
+ }
50
+ ctx.blockConditions.length = originalBlockConditionsLength;
51
+ }
52
+ exports.generateVIf = generateVIf;
53
+ //# sourceMappingURL=vIf.js.map
@@ -1,10 +1,10 @@
1
1
  import { type LanguagePlugin } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
3
  import type { VueCompilerOptions, VueLanguagePlugin } from './types';
4
- import { VueGeneratedCode } from './virtualFile/vueFile';
5
- interface _Plugin extends LanguagePlugin<VueGeneratedCode> {
4
+ import { VueVirtualCode } from './virtualFile/vueFile';
5
+ interface _Plugin extends LanguagePlugin<VueVirtualCode> {
6
6
  getCanonicalFileName: (fileName: string) => string;
7
7
  pluginContext: Parameters<VueLanguagePlugin>[0];
8
8
  }
9
- export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack?: boolean): _Plugin;
9
+ export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, useCaseSensitiveFileNames: boolean, getProjectVersion: () => string, getScriptFileNames: () => string[] | Set<string>, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): _Plugin;
10
10
  export {};
@@ -35,7 +35,7 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
35
35
  ];
36
36
  return JSON.stringify(values);
37
37
  }
38
- function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions, codegenStack = false) {
38
+ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, getProjectVersion, getScriptFileNames, compilerOptions, vueCompilerOptions) {
39
39
  const allowLanguageIds = new Set(['vue']);
40
40
  const pluginContext = {
41
41
  modules: {
@@ -49,7 +49,6 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
49
49
  },
50
50
  compilerOptions,
51
51
  vueCompilerOptions,
52
- codegenStack,
53
52
  globalTypesHolder: undefined,
54
53
  };
55
54
  const plugins = (0, plugins_1.getDefaultVueLanguagePlugins)(pluginContext);
@@ -85,7 +84,7 @@ function createVueLanguagePlugin(ts, getFileName, useCaseSensitiveFileNames, get
85
84
  return code;
86
85
  }
87
86
  else {
88
- const code = new vueFile_1.VueGeneratedCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
87
+ const code = new vueFile_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
89
88
  fileRegistry.set(fileId, code);
90
89
  return code;
91
90
  }
@@ -0,0 +1,2 @@
1
+ import type { CodeInformation } from '@volar/language-core';
2
+ export declare const allCodeFeatures: CodeInformation;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.allCodeFeatures = void 0;
4
+ exports.allCodeFeatures = {
5
+ verification: true,
6
+ completion: true,
7
+ semantic: true,
8
+ navigation: true,
9
+ structure: true,
10
+ format: true,
11
+ };
12
+ //# sourceMappingURL=shared.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../generators/utils");
3
+ const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
6
  version: 2,
@@ -18,7 +18,7 @@ const plugin = () => {
18
18
  customBlock.content,
19
19
  customBlock.name,
20
20
  0,
21
- (0, utils_1.enableAllFeatures)({}),
21
+ shared_1.allCodeFeatures,
22
22
  ]);
23
23
  }
24
24
  },
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../generators/utils");
4
3
  const plugin = () => {
5
4
  return {
6
5
  version: 2,
@@ -23,10 +22,10 @@ const plugin = () => {
23
22
  script.content,
24
23
  script.name,
25
24
  0,
26
- (0, utils_1.disableAllFeatures)({
25
+ {
27
26
  structure: true,
28
27
  format: true,
29
- }),
28
+ },
30
29
  ]);
31
30
  }
32
31
  },
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../generators/utils");
3
+ const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
6
  version: 2,
@@ -34,7 +34,7 @@ const plugin = () => {
34
34
  cssVar.text,
35
35
  style.name,
36
36
  cssVar.offset,
37
- (0, utils_1.enableAllFeatures)({}),
37
+ shared_1.allCodeFeatures,
38
38
  ], ');\n');
39
39
  }
40
40
  }
@@ -43,7 +43,7 @@ const plugin = () => {
43
43
  style.content,
44
44
  style.name,
45
45
  0,
46
- (0, utils_1.enableAllFeatures)({}),
46
+ shared_1.allCodeFeatures,
47
47
  ]);
48
48
  }
49
49
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../generators/utils");
3
+ const shared_1 = require("./shared");
4
4
  const plugin = () => {
5
5
  return {
6
6
  version: 2,
@@ -19,7 +19,7 @@ const plugin = () => {
19
19
  sfc.template.content,
20
20
  sfc.template.name,
21
21
  0,
22
- (0, utils_1.enableAllFeatures)({}),
22
+ shared_1.allCodeFeatures,
23
23
  ]);
24
24
  }
25
25
  },
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const inlineCss_1 = require("../generators/inlineCss");
3
+ const CompilerDOM = require("@vue/compiler-dom");
4
+ const template_1 = require("../codegen/template");
5
+ const shared_1 = require("./shared");
6
+ const codeFeatures = {
7
+ ...shared_1.allCodeFeatures,
8
+ format: false,
9
+ structure: false,
10
+ };
4
11
  const plugin = () => {
5
12
  return {
6
13
  version: 2,
@@ -15,9 +22,34 @@ const plugin = () => {
15
22
  return;
16
23
  }
17
24
  embeddedFile.parentCodeId = 'template';
18
- embeddedFile.content.push(...(0, inlineCss_1.generate)(sfc.template.ast));
25
+ embeddedFile.content.push(...generate(sfc.template.ast));
19
26
  },
20
27
  };
21
28
  };
22
29
  exports.default = plugin;
30
+ function* generate(templateAst) {
31
+ for (const node of (0, template_1.forEachElementNode)(templateAst)) {
32
+ for (const prop of node.props) {
33
+ if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
34
+ && prop.name === 'bind'
35
+ && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
36
+ && prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
37
+ && prop.arg.content === 'style'
38
+ && prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
39
+ const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
40
+ const start = prop.arg.loc.source.indexOf(endCrt) + 1;
41
+ const end = prop.arg.loc.source.lastIndexOf(endCrt);
42
+ const content = prop.arg.loc.source.substring(start, end);
43
+ yield `x { `;
44
+ yield [
45
+ content,
46
+ 'template',
47
+ prop.arg.loc.start.offset + start,
48
+ codeFeatures,
49
+ ];
50
+ yield ` }\n`;
51
+ }
52
+ }
53
+ }
54
+ }
23
55
  //# sourceMappingURL=vue-template-inline-css.js.map
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const template_1 = require("../generators/template");
4
- const utils_1 = require("../generators/utils");
3
+ const common_1 = require("../codegen/common");
4
+ const elementEvents_1 = require("../codegen/template/elementEvents");
5
+ const templateChild_1 = require("../codegen/template/templateChild");
6
+ const vFor_1 = require("../codegen/template/vFor");
5
7
  const CompilerDOM = require("@vue/compiler-dom");
6
- const codeFeatures = (0, utils_1.disableAllFeatures)({
8
+ const codeFeatures = {
7
9
  format: true,
8
10
  // autoInserts: true, // TODO: support vue-autoinsert-parentheses
9
- });
11
+ };
10
12
  const formatBrackets = {
11
13
  normal: ['`${', '}`;'],
12
14
  if: ['if (', ') { }'],
@@ -73,8 +75,8 @@ const plugin = ctx => {
73
75
  && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
74
76
  ) {
75
77
  if (prop.name === 'on') {
76
- const ast = (0, template_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
77
- addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, template_1.isCompoundExpression)(ctx.modules.typescript, ast)
78
+ const ast = (0, common_1.createTsAst)(ctx.modules.typescript, prop.exp, prop.exp.content);
79
+ addFormatCodes(prop.exp.content, prop.exp.loc.start.offset, (0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)
78
80
  ? formatBrackets.event
79
81
  : formatBrackets.normal);
80
82
  }
@@ -99,7 +101,7 @@ const plugin = ctx => {
99
101
  }
100
102
  }
101
103
  else if (node.type === CompilerDOM.NodeTypes.FOR) {
102
- const { leftExpressionRange, leftExpressionText } = (0, template_1.parseVForNode)(node);
104
+ const { leftExpressionRange, leftExpressionText } = (0, vFor_1.parseVForNode)(node);
103
105
  const { source } = node.parseResult;
104
106
  if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
105
107
  const start = leftExpressionRange.start;
@@ -124,7 +126,7 @@ const plugin = ctx => {
124
126
  }
125
127
  else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
126
128
  // {{ ... }}
127
- const [content, start] = (0, template_1.parseInterpolationNode)(node, templateContent);
129
+ const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, templateContent);
128
130
  const lines = content.split('\n');
129
131
  addFormatCodes(content, start, lines.length <= 1 ? formatBrackets.curly : [
130
132
  lines[0].trim() === '' ? '(' : formatBrackets.curly[0],
@@ -1,4 +1,4 @@
1
- import { Mapping, StackNode } from '@volar/language-core';
1
+ import type { Mapping } from '@volar/language-core';
2
2
  import type { Code, Sfc, VueLanguagePlugin } from '../types';
3
3
  export declare const tsCodegen: WeakMap<Sfc, {
4
4
  scriptRanges: () => {
@@ -62,14 +62,51 @@ export declare const tsCodegen: WeakMap<Sfc, {
62
62
  lang: () => string;
63
63
  generatedScript: () => {
64
64
  codes: Code[];
65
- codeStacks: StackNode[];
66
65
  linkedCodeMappings: Mapping<any>[];
67
66
  };
68
67
  generatedTemplate: () => {
69
68
  codes: Code[];
70
- codeStacks: string[];
71
- tagOffsetsMap: Map<string, number[]>;
72
- accessedGlobalVariables: Set<string>;
69
+ ctx: {
70
+ slots: {
71
+ name: string;
72
+ loc?: number | undefined;
73
+ tagRange: [number, number];
74
+ varName: string;
75
+ nodeLoc: any;
76
+ }[];
77
+ dynamicSlots: {
78
+ expVar: string;
79
+ varName: string;
80
+ }[];
81
+ codeFeatures: {
82
+ all: import("../types").VueCodeInformation;
83
+ verification: import("../types").VueCodeInformation;
84
+ completion: import("../types").VueCodeInformation;
85
+ additionalCompletion: import("../types").VueCodeInformation;
86
+ navigation: import("../types").VueCodeInformation;
87
+ navigationAndCompletion: import("../types").VueCodeInformation;
88
+ withoutHighlight: import("../types").VueCodeInformation;
89
+ withoutHighlightAndCompletion: import("../types").VueCodeInformation;
90
+ withoutHighlightAndCompletionAndNavigation: import("../types").VueCodeInformation;
91
+ };
92
+ accessGlobalVariables: Map<string, Set<number>>;
93
+ hasSlotElements: Set<import("@vue/compiler-dom").ElementNode>;
94
+ blockConditions: string[];
95
+ usedComponentCtxVars: Set<string>;
96
+ scopedClasses: {
97
+ className: string;
98
+ offset: number;
99
+ }[];
100
+ accessGlobalVariable(name: string, offset?: number | undefined): void;
101
+ hasLocalVariable: (name: string) => boolean;
102
+ addLocalVariable: (name: string) => void;
103
+ removeLocalVariable: (name: string) => void;
104
+ getInternalVariable: () => string;
105
+ ignoreError: () => Generator<Code, any, unknown>;
106
+ expectError: (prevNode: import("@vue/compiler-dom").CommentNode) => Generator<Code, any, unknown>;
107
+ resetDirectiveComments: (endStr: string) => Generator<Code, any, unknown>;
108
+ generateAutoImportCompletion: () => Generator<Code, any, unknown>;
109
+ };
73
110
  hasSlot: boolean;
74
111
  } | undefined;
75
112
  }>;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsCodegen = void 0;
4
- const language_core_1 = require("@volar/language-core");
5
4
  const computeds_1 = require("computeds");
6
- const script_1 = require("../generators/script");
7
- const template_1 = require("../generators/template");
5
+ const path = require("path-browserify");
6
+ const script_1 = require("../codegen/script");
7
+ const template_1 = require("../codegen/template");
8
8
  const scriptRanges_1 = require("../parsers/scriptRanges");
9
9
  const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
10
10
  exports.tsCodegen = new WeakMap();
@@ -28,9 +28,8 @@ const plugin = ctx => {
28
28
  if (embeddedFile.id.startsWith('script_')) {
29
29
  const tsx = _tsx.generatedScript();
30
30
  if (tsx) {
31
- const [content, contentStacks] = ctx.codegenStack ? (0, language_core_1.track)([...tsx.codes], [...tsx.codeStacks]) : [[...tsx.codes], [...tsx.codeStacks]];
31
+ const content = [...tsx.codes];
32
32
  embeddedFile.content = content;
33
- embeddedFile.contentStacks = contentStacks;
34
33
  embeddedFile.linkedCodeMappings = [...tsx.linkedCodeMappings];
35
34
  }
36
35
  }
@@ -83,44 +82,56 @@ function createTsx(fileName, _sfc, ctx) {
83
82
  if (!_sfc.template) {
84
83
  return;
85
84
  }
86
- const tsCodes = [];
87
- const tsCodegenStacks = [];
88
- const codegen = (0, template_1.generate)(ts, ctx.compilerOptions, ctx.vueCompilerOptions, _sfc.template, shouldGenerateScopedClasses(), stylesScopedClasses(), hasScriptSetupSlots(), slotsAssignName(), propsAssignName(), ctx.codegenStack);
85
+ const codes = [];
86
+ const codegen = (0, template_1.generateTemplate)({
87
+ ts,
88
+ compilerOptions: ctx.compilerOptions,
89
+ vueCompilerOptions: ctx.vueCompilerOptions,
90
+ template: _sfc.template,
91
+ shouldGenerateScopedClasses: shouldGenerateScopedClasses(),
92
+ stylesScopedClasses: stylesScopedClasses(),
93
+ hasDefineSlots: hasDefineSlots(),
94
+ slotsAssignName: slotsAssignName(),
95
+ propsAssignName: propsAssignName(),
96
+ });
89
97
  let current = codegen.next();
90
98
  while (!current.done) {
91
- const [code, stack] = current.value;
92
- tsCodes.push(code);
93
- if (ctx.codegenStack) {
94
- tsCodegenStacks.push(stack);
95
- }
99
+ const code = current.value;
100
+ codes.push(code);
96
101
  current = codegen.next();
97
102
  }
98
103
  return {
99
104
  ...current.value,
100
- codes: tsCodes,
101
- codeStacks: tsCodegenStacks,
105
+ codes: codes,
102
106
  };
103
107
  });
104
- const hasScriptSetupSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
108
+ const hasDefineSlots = (0, computeds_1.computed)(() => !!scriptSetupRanges()?.slots.define);
105
109
  const slotsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.slots.name);
106
110
  const propsAssignName = (0, computeds_1.computed)(() => scriptSetupRanges()?.props.name);
107
111
  const generatedScript = (0, computeds_1.computed)(() => {
108
112
  const codes = [];
109
- const codeStacks = [];
110
113
  const linkedCodeMappings = [];
111
114
  const _template = generatedTemplate();
112
115
  let generatedLength = 0;
113
- for (const [code, stack] of (0, script_1.generate)(ts, fileName, _sfc.script, _sfc.scriptSetup, _sfc.styles, lang(), scriptRanges(), scriptSetupRanges(), _template ? {
114
- tsCodes: _template.codes,
115
- tsCodegenStacks: _template.codeStacks,
116
- accessedGlobalVariables: _template.accessedGlobalVariables,
117
- hasSlot: _template.hasSlot,
118
- tagNames: new Set(_template.tagOffsetsMap.keys()),
119
- } : undefined, ctx.compilerOptions, ctx.vueCompilerOptions, ctx.globalTypesHolder, () => generatedLength, linkedCodeMappings, ctx.codegenStack)) {
116
+ for (const code of (0, script_1.generateScript)({
117
+ ts,
118
+ fileBaseName: path.basename(fileName),
119
+ globalTypes: ctx.globalTypesHolder === fileName,
120
+ sfc: _sfc,
121
+ lang: lang(),
122
+ scriptRanges: scriptRanges(),
123
+ scriptSetupRanges: scriptSetupRanges(),
124
+ templateCodegen: _template ? {
125
+ tsCodes: _template.codes,
126
+ ctx: _template.ctx,
127
+ hasSlot: _template.hasSlot,
128
+ } : undefined,
129
+ compilerOptions: ctx.compilerOptions,
130
+ vueCompilerOptions: ctx.vueCompilerOptions,
131
+ getGeneratedLength: () => generatedLength,
132
+ linkedCodeMappings,
133
+ })) {
120
134
  codes.push(code);
121
- if (ctx.codegenStack) {
122
- codeStacks.push({ stack, length: 1 });
123
- }
124
135
  generatedLength += typeof code === 'string'
125
136
  ? code.length
126
137
  : code[0].length;
@@ -128,7 +139,6 @@ function createTsx(fileName, _sfc, ctx) {
128
139
  ;
129
140
  return {
130
141
  codes,
131
- codeStacks,
132
142
  linkedCodeMappings,
133
143
  };
134
144
  });
package/lib/types.d.ts CHANGED
@@ -19,8 +19,8 @@ export interface VueCodeInformation extends CodeInformation {
19
19
  paddingLeft?: boolean;
20
20
  };
21
21
  __combineLastMapping?: boolean;
22
+ __combineOffsetMapping?: number;
22
23
  }
23
- export type CodeAndStack = [code: Code, stack: string];
24
24
  export type Code = Segment<VueCodeInformation>;
25
25
  export interface VueCompilerOptions {
26
26
  target: number;
@@ -29,7 +29,6 @@ export interface VueCompilerOptions {
29
29
  jsxSlots: boolean;
30
30
  strictTemplates: boolean;
31
31
  skipTemplateCodegen: boolean;
32
- nativeTags: string[];
33
32
  dataAttributes: string[];
34
33
  htmlAttributes: string[];
35
34
  optionsWrapper: [string, string] | [];
@@ -56,7 +55,6 @@ export type VueLanguagePlugin = (ctx: {
56
55
  };
57
56
  compilerOptions: ts.CompilerOptions;
58
57
  vueCompilerOptions: VueCompilerOptions;
59
- codegenStack: boolean;
60
58
  globalTypesHolder: string | undefined;
61
59
  }) => {
62
60
  version: typeof pluginVersion;
package/lib/utils/ts.js CHANGED
@@ -151,27 +151,6 @@ function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
151
151
  }
152
152
  }
153
153
  }
154
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
155
- const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
156
- 'header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
157
- 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
158
- 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
159
- 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
160
- 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
161
- 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
162
- 'option,output,progress,select,textarea,details,dialog,menu,' +
163
- 'summary,template,blockquote,iframe,tfoot';
164
- // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
165
- const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
166
- 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
167
- 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
168
- 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
169
- 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
170
- 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
171
- 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
172
- 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
173
- 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
174
- 'text,textPath,title,tspan,unknown,use,view';
175
154
  function resolveVueCompilerOptions(vueOptions) {
176
155
  const target = vueOptions.target ?? 3.3;
177
156
  const lib = vueOptions.lib || (target < 2.7 ? '@vue/runtime-dom' : 'vue');
@@ -183,14 +162,6 @@ function resolveVueCompilerOptions(vueOptions) {
183
162
  jsxSlots: vueOptions.jsxSlots ?? false,
184
163
  strictTemplates: vueOptions.strictTemplates ?? false,
185
164
  skipTemplateCodegen: vueOptions.skipTemplateCodegen ?? false,
186
- nativeTags: vueOptions.nativeTags ?? [...new Set([
187
- ...HTML_TAGS.split(','),
188
- ...SVG_TAGS.split(','),
189
- // fix https://github.com/johnsoncodehk/volar/issues/1340
190
- 'hgroup',
191
- 'slot',
192
- 'component',
193
- ])],
194
165
  dataAttributes: vueOptions.dataAttributes ?? [],
195
166
  htmlAttributes: vueOptions.htmlAttributes ?? ['aria-*'],
196
167
  optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7
@@ -1,3 +1,3 @@
1
1
  import { VirtualCode } from '@volar/language-core';
2
2
  import type { Sfc, VueLanguagePlugin } from '../types';
3
- export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc, codegenStack: boolean): () => VirtualCode[];
3
+ export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc): () => VirtualCode[];
@@ -4,7 +4,7 @@ exports.computedFiles = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  const computeds_1 = require("computeds");
6
6
  const embeddedFile_1 = require("./embeddedFile");
7
- function computedFiles(plugins, fileName, sfc, codegenStack) {
7
+ function computedFiles(plugins, fileName, sfc) {
8
8
  const nameToBlock = (0, computeds_1.computed)(() => {
9
9
  const blocks = {};
10
10
  if (sfc.template) {
@@ -24,7 +24,7 @@ function computedFiles(plugins, fileName, sfc, codegenStack) {
24
24
  }
25
25
  return blocks;
26
26
  });
27
- const pluginsResult = plugins.map(plugin => computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack));
27
+ const pluginsResult = plugins.map(plugin => computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock));
28
28
  const flatResult = (0, computeds_1.computed)(() => pluginsResult.map(r => r()).flat());
29
29
  const structuredResult = (0, computeds_1.computed)(() => {
30
30
  const embeddedCodes = [];
@@ -42,7 +42,7 @@ function computedFiles(plugins, fileName, sfc, codegenStack) {
42
42
  return embeddedCodes;
43
43
  function consumeRemain() {
44
44
  for (let i = remain.length - 1; i >= 0; i--) {
45
- const { file, snapshot, mappings, codegenStacks } = remain[i];
45
+ const { file, snapshot, mappings } = remain[i];
46
46
  if (!file.parentCodeId) {
47
47
  embeddedCodes.push({
48
48
  id: file.id,
@@ -50,7 +50,6 @@ function computedFiles(plugins, fileName, sfc, codegenStack) {
50
50
  linkedCodeMappings: file.linkedCodeMappings,
51
51
  snapshot,
52
52
  mappings,
53
- codegenStacks,
54
53
  embeddedCodes: [],
55
54
  });
56
55
  remain.splice(i, 1);
@@ -65,7 +64,6 @@ function computedFiles(plugins, fileName, sfc, codegenStack) {
65
64
  linkedCodeMappings: file.linkedCodeMappings,
66
65
  snapshot,
67
66
  mappings,
68
- codegenStacks,
69
67
  embeddedCodes: [],
70
68
  });
71
69
  remain.splice(i, 1);
@@ -88,7 +86,7 @@ function computedFiles(plugins, fileName, sfc, codegenStack) {
88
86
  return structuredResult;
89
87
  }
90
88
  exports.computedFiles = computedFiles;
91
- function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack) {
89
+ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock) {
92
90
  const embeddedFiles = {};
93
91
  const files = (0, computeds_1.computed)(() => {
94
92
  try {
@@ -104,8 +102,8 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codege
104
102
  for (const fileInfo of fileInfos) {
105
103
  if (!embeddedFiles[fileInfo.id]) {
106
104
  embeddedFiles[fileInfo.id] = (0, computeds_1.computed)(() => {
107
- const [content, stacks] = codegenStack ? (0, language_core_1.track)([]) : [[], []];
108
- const file = new embeddedFile_1.VueEmbeddedCode(fileInfo.id, fileInfo.lang, content, stacks);
105
+ const content = [];
106
+ const file = new embeddedFile_1.VueEmbeddedCode(fileInfo.id, fileInfo.lang, content);
109
107
  for (const plugin of plugins) {
110
108
  if (!plugin.resolveEmbeddedCode) {
111
109
  continue;
@@ -151,8 +149,10 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codege
151
149
  return files().map(_file => {
152
150
  const { file, snapshot } = _file();
153
151
  const mappings = (0, language_core_1.buildMappings)(file.content);
152
+ const newMappings = [];
154
153
  let lastValidMapping;
155
- for (const mapping of mappings) {
154
+ for (let i = 0; i < mappings.length; i++) {
155
+ const mapping = mappings[i];
156
156
  if (mapping.source !== undefined) {
157
157
  const block = nameToBlock()[mapping.source];
158
158
  if (block) {
@@ -163,7 +163,17 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codege
163
163
  }
164
164
  mapping.source = undefined;
165
165
  }
166
- if (mapping.data.__combineLastMapping) {
166
+ if (mapping.data.__combineOffsetMapping !== undefined) {
167
+ const offsetMapping = mappings[i - mapping.data.__combineOffsetMapping];
168
+ if (typeof offsetMapping === 'string' || !offsetMapping) {
169
+ throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: ' + mapping.data.__combineOffsetMapping);
170
+ }
171
+ offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
172
+ offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
173
+ offsetMapping.lengths.push(...mapping.lengths);
174
+ continue;
175
+ }
176
+ else if (mapping.data.__combineLastMapping) {
167
177
  lastValidMapping.sourceOffsets.push(...mapping.sourceOffsets);
168
178
  lastValidMapping.generatedOffsets.push(...mapping.generatedOffsets);
169
179
  lastValidMapping.lengths.push(...mapping.lengths);
@@ -172,12 +182,12 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codege
172
182
  else {
173
183
  lastValidMapping = mapping;
174
184
  }
185
+ newMappings.push(mapping);
175
186
  }
176
187
  return {
177
188
  file,
178
189
  snapshot,
179
- mappings: mappings.filter(mapping => !mapping.data.__combineLastMapping),
180
- codegenStacks: (0, language_core_1.buildStacks)(file.content, file.contentStacks),
190
+ mappings: newMappings,
181
191
  };
182
192
  });
183
193
  });