@vue/language-core 3.1.4 → 3.1.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 (101) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +3 -2
  3. package/lib/codegen/codeFeatures.d.ts +5 -9
  4. package/lib/codegen/codeFeatures.js +5 -5
  5. package/lib/codegen/globalTypes.js +15 -20
  6. package/lib/codegen/localTypes.d.ts +1 -1
  7. package/lib/codegen/localTypes.js +6 -6
  8. package/lib/codegen/names.d.ts +30 -0
  9. package/lib/codegen/names.js +34 -0
  10. package/lib/codegen/script/component.js +45 -54
  11. package/lib/codegen/script/context.d.ts +2 -5
  12. package/lib/codegen/script/context.js +1 -7
  13. package/lib/codegen/script/index.d.ts +10 -12
  14. package/lib/codegen/script/index.js +74 -73
  15. package/lib/codegen/script/scriptSetup.d.ts +3 -2
  16. package/lib/codegen/script/scriptSetup.js +209 -283
  17. package/lib/codegen/script/src.js +9 -3
  18. package/lib/codegen/script/template.js +64 -108
  19. package/lib/codegen/style/common.d.ts +3 -0
  20. package/lib/codegen/style/common.js +43 -0
  21. package/lib/codegen/style/index.d.ts +63 -0
  22. package/lib/codegen/style/index.js +38 -0
  23. package/lib/codegen/style/modules.d.ts +3 -2
  24. package/lib/codegen/style/modules.js +12 -11
  25. package/lib/codegen/style/scopedClasses.d.ts +2 -3
  26. package/lib/codegen/style/scopedClasses.js +23 -21
  27. package/lib/codegen/template/context.d.ts +10 -19
  28. package/lib/codegen/template/context.js +82 -94
  29. package/lib/codegen/template/element.js +174 -65
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.d.ts +1 -1
  32. package/lib/codegen/template/elementEvents.js +30 -35
  33. package/lib/codegen/template/elementProps.d.ts +3 -3
  34. package/lib/codegen/template/elementProps.js +64 -83
  35. package/lib/codegen/template/index.d.ts +11 -22
  36. package/lib/codegen/template/index.js +85 -80
  37. package/lib/codegen/template/interpolation.d.ts +3 -3
  38. package/lib/codegen/template/interpolation.js +108 -155
  39. package/lib/codegen/template/objectProperty.js +8 -4
  40. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  41. package/lib/codegen/template/propertyAccess.js +5 -7
  42. package/lib/codegen/template/slotOutlet.js +26 -14
  43. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  44. package/lib/codegen/template/styleScopedClasses.js +23 -149
  45. package/lib/codegen/template/templateChild.d.ts +0 -1
  46. package/lib/codegen/template/templateChild.js +11 -68
  47. package/lib/codegen/template/vFor.js +10 -13
  48. package/lib/codegen/template/vIf.js +5 -3
  49. package/lib/codegen/template/vSlot.js +20 -16
  50. package/lib/codegen/utils/boundary.d.ts +3 -0
  51. package/lib/codegen/utils/boundary.js +13 -0
  52. package/lib/codegen/utils/camelized.js +3 -3
  53. package/lib/codegen/utils/escaped.js +4 -2
  54. package/lib/codegen/utils/index.d.ts +3 -6
  55. package/lib/codegen/utils/index.js +41 -26
  56. package/lib/codegen/utils/merge.d.ts +2 -2
  57. package/lib/codegen/utils/merge.js +9 -9
  58. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  59. package/lib/codegen/utils/transform.d.ts +8 -0
  60. package/lib/codegen/utils/transform.js +27 -0
  61. package/lib/codegen/utils/unicode.js +4 -2
  62. package/lib/compilerOptions.js +4 -4
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +18 -25
  65. package/lib/plugins/vue-template-html.js +12 -9
  66. package/lib/plugins/vue-template-inline-css.js +8 -18
  67. package/lib/plugins/vue-template-inline-ts.js +12 -14
  68. package/lib/plugins/vue-tsx.d.ts +14 -23
  69. package/lib/plugins/vue-tsx.js +121 -69
  70. package/lib/plugins.js +1 -1
  71. package/lib/types.d.ts +5 -4
  72. package/lib/utils/parseSfc.js +10 -11
  73. package/lib/utils/shared.d.ts +1 -0
  74. package/lib/utils/shared.js +9 -0
  75. package/lib/utils/signals.d.ts +2 -2
  76. package/lib/utils/signals.js +8 -6
  77. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  78. package/lib/virtualCode/embeddedCodes.js +249 -0
  79. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  80. package/lib/virtualCode/index.js +81 -0
  81. package/lib/virtualCode/ir.d.ts +4 -0
  82. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +65 -96
  83. package/lib/virtualCode/normalize.d.ts +2 -0
  84. package/lib/virtualCode/normalize.js +170 -0
  85. package/package.json +4 -4
  86. package/lib/codegen/style/classProperty.d.ts +0 -2
  87. package/lib/codegen/style/classProperty.js +0 -18
  88. package/lib/codegen/style/imports.d.ts +0 -2
  89. package/lib/codegen/style/imports.js +0 -27
  90. package/lib/codegen/template/elementChildren.d.ts +0 -5
  91. package/lib/codegen/template/elementChildren.js +0 -12
  92. package/lib/codegen/utils/wrapWith.d.ts +0 -3
  93. package/lib/codegen/utils/wrapWith.js +0 -24
  94. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  95. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  96. package/lib/virtualFile/computedSfc.d.ts +0 -6
  97. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  98. package/lib/virtualFile/computedVueSfc.js +0 -41
  99. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  100. package/lib/virtualFile/embeddedFile.js +0 -14
  101. package/lib/virtualFile/vueFile.js +0 -49
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateEscaped = generateEscaped;
4
4
  function* generateEscaped(text, source, offset, features, escapeTarget) {
5
5
  const parts = text.split(escapeTarget);
6
- const startCombineOffset = features.__combineOffset ?? 0;
6
+ const combineToken = features.__combineToken ?? Symbol();
7
7
  let isEscapeTarget = false;
8
8
  for (let i = 0; i < parts.length; i++) {
9
9
  const part = parts[i];
@@ -14,7 +14,9 @@ function* generateEscaped(text, source, offset, features, escapeTarget) {
14
14
  part,
15
15
  source,
16
16
  offset,
17
- i === 0 ? features : { __combineOffset: startCombineOffset + i },
17
+ i === 0
18
+ ? { ...features, __combineToken: combineToken }
19
+ : { __combineToken: combineToken },
18
20
  ];
19
21
  offset += part.length;
20
22
  isEscapeTarget = !isEscapeTarget;
@@ -1,11 +1,8 @@
1
- import type * as CompilerDOM from '@vue/compiler-dom';
2
1
  import type * as ts from 'typescript';
3
2
  import type { Code, SfcBlock, VueCodeInformation } from '../../types';
4
3
  export declare const newLine = "\n";
5
4
  export declare const endOfLine = ";\n";
6
- export declare const combineLastMapping: VueCodeInformation;
7
5
  export declare const identifierRegex: RegExp;
8
- export declare function normalizeAttributeValue(node: CompilerDOM.TextNode): readonly [string, number];
9
- export declare function createTsAst(ts: typeof import('typescript'), inlineTsAsts: Map<string, ts.SourceFile> | undefined, text: string): ts.SourceFile;
10
- export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
11
- export declare function generatePartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
6
+ export declare function getTypeScriptAST(ts: typeof import('typescript'), block: SfcBlock, text: string): ts.SourceFile;
7
+ export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation, partiallyEnd?: boolean): Generator<Code>;
8
+ export declare function forEachNode(ts: typeof import('typescript'), node: ts.Node): Generator<ts.Node>;
@@ -1,45 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.identifierRegex = exports.combineLastMapping = exports.endOfLine = exports.newLine = void 0;
4
- exports.normalizeAttributeValue = normalizeAttributeValue;
5
- exports.createTsAst = createTsAst;
3
+ exports.identifierRegex = exports.endOfLine = exports.newLine = void 0;
4
+ exports.getTypeScriptAST = getTypeScriptAST;
6
5
  exports.generateSfcBlockSection = generateSfcBlockSection;
7
- exports.generatePartiallyEnding = generatePartiallyEnding;
6
+ exports.forEachNode = forEachNode;
8
7
  const codeFeatures_1 = require("../codeFeatures");
9
8
  exports.newLine = `\n`;
10
9
  exports.endOfLine = `;${exports.newLine}`;
11
- exports.combineLastMapping = { __combineOffset: 1 };
12
10
  exports.identifierRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
13
- function normalizeAttributeValue(node) {
14
- let offset = node.loc.start.offset;
15
- let content = node.loc.source;
16
- if ((content.startsWith(`'`) && content.endsWith(`'`))
17
- || (content.startsWith(`"`) && content.endsWith(`"`))) {
18
- offset++;
19
- content = content.slice(1, -1);
11
+ const cacheMaps = new Map();
12
+ function getTypeScriptAST(ts, block, text) {
13
+ if (!cacheMaps.has(block)) {
14
+ cacheMaps.set(block, [block.content, new Map()]);
20
15
  }
21
- return [content, offset];
22
- }
23
- function createTsAst(ts, inlineTsAsts, text) {
24
- let ast = inlineTsAsts?.get(text);
25
- if (!ast) {
26
- ast = ts.createSourceFile('/a.ts', text, 99);
27
- inlineTsAsts?.set(text, ast);
16
+ const cacheMap = cacheMaps.get(block);
17
+ if (cacheMap[0] !== block.content) {
18
+ cacheMap[0] = block.content;
19
+ for (const [key, info] of cacheMap[1]) {
20
+ if (info[1]) {
21
+ info[1] = 0;
22
+ }
23
+ else {
24
+ cacheMap[1].delete(key);
25
+ }
26
+ }
27
+ }
28
+ const cache = cacheMap[1].get(text);
29
+ if (cache) {
30
+ cache[1]++;
31
+ return cache[0];
28
32
  }
29
- ast.__volar_used = true;
33
+ const ast = ts.createSourceFile('/dummy.ts', text, 99);
34
+ cacheMap[1].set(text, [ast, 1]);
30
35
  return ast;
31
36
  }
32
- function generateSfcBlockSection(block, start, end, features) {
33
- return [
37
+ function* generateSfcBlockSection(block, start, end, features, partiallyEnd = false) {
38
+ yield [
34
39
  block.content.slice(start, end),
35
40
  block.name,
36
41
  start,
37
42
  features,
38
43
  ];
44
+ // #3632
45
+ if (partiallyEnd) {
46
+ yield `;`;
47
+ yield ['', block.name, end, codeFeatures_1.codeFeatures.verification];
48
+ yield exports.newLine;
49
+ }
39
50
  }
40
- function* generatePartiallyEnding(source, end, mark, delimiter = 'debugger') {
41
- yield delimiter;
42
- yield [``, source, end, codeFeatures_1.codeFeatures.verification];
43
- yield `/* PartiallyEnd: ${mark} */${exports.newLine}`;
51
+ function* forEachNode(ts, node) {
52
+ const children = [];
53
+ ts.forEachChild(node, child => {
54
+ children.push(child);
55
+ });
56
+ for (const child of children) {
57
+ yield child;
58
+ }
44
59
  }
45
60
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
1
  import type { Code } from '../../types';
2
- export declare function generateIntersectMerge(codes: Code[]): Generator<Code>;
3
- export declare function generateSpreadMerge(codes: Code[]): Generator<Code>;
2
+ export declare function generateIntersectMerge(generates: Iterable<Code>[]): Generator<Code>;
3
+ export declare function generateSpreadMerge(generates: Iterable<Code>[]): Generator<Code>;
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateIntersectMerge = generateIntersectMerge;
4
4
  exports.generateSpreadMerge = generateSpreadMerge;
5
5
  const index_1 = require("./index");
6
- function* generateIntersectMerge(codes) {
7
- yield codes[0];
8
- for (let i = 1; i < codes.length; i++) {
6
+ function* generateIntersectMerge(generates) {
7
+ yield* generates[0];
8
+ for (let i = 1; i < generates.length; i++) {
9
9
  yield ` & `;
10
- yield codes[i];
10
+ yield* generates[i];
11
11
  }
12
12
  }
13
- function* generateSpreadMerge(codes) {
14
- if (codes.length === 1) {
15
- yield codes[0];
13
+ function* generateSpreadMerge(generates) {
14
+ if (generates.length === 1) {
15
+ yield* generates[0];
16
16
  }
17
17
  else {
18
18
  yield `{${index_1.newLine}`;
19
- for (const code of codes) {
19
+ for (const generate of generates) {
20
20
  yield `...`;
21
- yield code;
21
+ yield* generate;
22
22
  yield `,${index_1.newLine}`;
23
23
  }
24
24
  yield `}`;
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStringLiteralKey = generateStringLiteralKey;
4
- const index_1 = require("./index");
5
- const wrapWith_1 = require("./wrapWith");
4
+ const boundary_1 = require("./boundary");
6
5
  function* generateStringLiteralKey(code, offset, info) {
7
6
  if (offset === undefined || !info) {
8
7
  yield `'${code}'`;
9
8
  }
10
9
  else {
11
- yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, info, `'`, [code, 'template', offset, index_1.combineLastMapping], `'`);
10
+ const token = yield* (0, boundary_1.startBoundary)('template', offset, info);
11
+ yield `'`;
12
+ yield [code, 'template', offset, { __combineToken: token }];
13
+ yield `'`;
14
+ yield (0, boundary_1.endBoundary)(token, offset + code.length);
12
15
  }
13
16
  }
14
17
  //# sourceMappingURL=stringLiteralKey.js.map
@@ -0,0 +1,8 @@
1
+ import type { Code } from '../../types';
2
+ export interface CodeTransform {
3
+ range: [start: number, end: number];
4
+ generate(): Iterable<Code>;
5
+ }
6
+ export declare function replace(start: number, end: number, replacement: () => Iterable<Code>): CodeTransform;
7
+ export declare function insert(position: number, insertion: () => Iterable<Code>): CodeTransform;
8
+ export declare function generateCodeWithTransforms(start: number, end: number, transforms: CodeTransform[], section: (start: number, end: number) => Iterable<Code>): Generator<Code>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replace = replace;
4
+ exports.insert = insert;
5
+ exports.generateCodeWithTransforms = generateCodeWithTransforms;
6
+ function replace(start, end, replacement) {
7
+ return {
8
+ range: [start, end],
9
+ generate: replacement,
10
+ };
11
+ }
12
+ function insert(position, insertion) {
13
+ return {
14
+ range: [position, position],
15
+ generate: insertion,
16
+ };
17
+ }
18
+ function* generateCodeWithTransforms(start, end, transforms, section) {
19
+ const sortedTransforms = transforms.sort((a, b) => a.range[0] - b.range[0]);
20
+ for (const { range, generate } of sortedTransforms) {
21
+ yield* section(start, range[0]);
22
+ yield* generate();
23
+ start = range[1];
24
+ }
25
+ yield* section(start, end);
26
+ }
27
+ //# sourceMappingURL=transform.js.map
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateUnicode = generateUnicode;
4
- const wrapWith_1 = require("./wrapWith");
4
+ const boundary_1 = require("./boundary");
5
5
  function* generateUnicode(code, offset, info) {
6
6
  if (needToUnicode(code)) {
7
- yield* (0, wrapWith_1.wrapWith)(offset, offset + code.length, info, toUnicode(code));
7
+ const token = yield* (0, boundary_1.startBoundary)('template', offset, info);
8
+ yield toUnicode(code);
9
+ yield (0, boundary_1.endBoundary)(token, offset + code.length);
8
10
  }
9
11
  else {
10
12
  yield [code, 'template', offset, info];
@@ -24,7 +24,8 @@ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName)
24
24
  return [];
25
25
  },
26
26
  };
27
- const parsed = ts.parseJsonConfigFileContent(json, proxyHost, rootDir, {}, configFileName);
27
+ const config = ts.readJsonConfigFile(rootDir, () => JSON.stringify(json));
28
+ const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, rootDir, {}, configFileName);
28
29
  const resolver = new CompilerOptionsResolver(host.fileExists);
29
30
  for (const extendPath of [...extendedPaths].reverse()) {
30
31
  try {
@@ -35,8 +36,7 @@ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName)
35
36
  }
36
37
  catch { }
37
38
  }
38
- // ensure the rootDir is added to the config roots
39
- resolver.addConfig({}, rootDir);
39
+ resolver.addConfig(json?.vueCompilerOptions ?? {}, rootDir);
40
40
  return {
41
41
  ...parsed,
42
42
  vueOptions: resolver.build(),
@@ -151,7 +151,7 @@ class CompilerOptionsResolver {
151
151
  ...defaults.fallthroughComponentNames,
152
152
  ...this.options.fallthroughComponentNames ?? [],
153
153
  ].map(shared_2.hyphenateTag),
154
- // https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
154
+ // https://github.com/vuejs/core/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
155
155
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
156
156
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
157
157
  };
@@ -1,6 +1,6 @@
1
1
  import { type LanguagePlugin } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
3
  import type { VueCompilerOptions } from './types';
4
- import { VueVirtualCode } from './virtualFile/vueFile';
4
+ import { VueVirtualCode } from './virtualCode';
5
5
  export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, asFileName: (scriptId: T) => string): LanguagePlugin<T, VueVirtualCode>;
6
6
  export declare function getAllExtensions(options: VueCompilerOptions): string[];
@@ -6,33 +6,22 @@ exports.getAllExtensions = getAllExtensions;
6
6
  const language_core_1 = require("@volar/language-core");
7
7
  const CompilerDOM = require("@vue/compiler-dom");
8
8
  const plugins_1 = require("./plugins");
9
- const vueFile_1 = require("./virtualFile/vueFile");
10
- const fileRegistries = [];
11
- function getVueFileRegistry(key, plugins) {
12
- let fileRegistry = fileRegistries.find(r => r.key === key
13
- && r.plugins.length === plugins.length
14
- && r.plugins.every(plugin => plugins.includes(plugin)))?.files;
15
- if (!fileRegistry) {
16
- fileRegistry = new Map();
17
- fileRegistries.push({
18
- key: key,
19
- plugins: plugins,
20
- files: fileRegistry,
21
- });
22
- }
23
- return fileRegistry;
24
- }
25
- function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
26
- const values = [
9
+ const virtualCode_1 = require("./virtualCode");
10
+ const fileRegistries = {};
11
+ function getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins) {
12
+ const key = JSON.stringify([
13
+ ...plugins.map(plugin => plugin.name)
14
+ .filter(name => typeof name === 'string')
15
+ .sort(),
27
16
  ...Object.keys(vueCompilerOptions)
28
- .sort()
29
17
  .filter(key => key !== 'plugins')
18
+ .sort()
30
19
  .map(key => [key, vueCompilerOptions[key]]),
31
- [...new Set(plugins.map(plugin => plugin.requiredCompilerOptions ?? []).flat())]
20
+ ...[...new Set(plugins.flatMap(plugin => plugin.requiredCompilerOptions ?? []))]
32
21
  .sort()
33
22
  .map(key => [key, compilerOptions[key]]),
34
- ];
35
- return JSON.stringify(values);
23
+ ]);
24
+ return fileRegistries[key] ??= new Map();
36
25
  }
37
26
  function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) {
38
27
  const pluginContext = {
@@ -44,7 +33,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
44
33
  vueCompilerOptions,
45
34
  };
46
35
  const plugins = (0, plugins_1.createPlugins)(pluginContext);
47
- const fileRegistry = getVueFileRegistry(getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins), vueCompilerOptions.plugins);
36
+ const fileRegistry = getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins);
48
37
  return {
49
38
  getLanguageId(scriptId) {
50
39
  const fileName = asFileName(scriptId);
@@ -64,16 +53,20 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
64
53
  return code;
65
54
  }
66
55
  else {
67
- const code = new vueFile_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
56
+ const code = new virtualCode_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
68
57
  fileRegistry.set(fileName, code);
69
58
  return code;
70
59
  }
71
60
  }
72
61
  },
73
- updateVirtualCode(_fileId, code, snapshot) {
62
+ updateVirtualCode(_scriptId, code, snapshot) {
74
63
  code.update(snapshot);
75
64
  return code;
76
65
  },
66
+ disposeVirtualCode(scriptId) {
67
+ const fileName = asFileName(scriptId);
68
+ fileRegistry.delete(fileName);
69
+ },
77
70
  typescript: {
78
71
  extraFileExtensions: getAllExtensions(vueCompilerOptions)
79
72
  .map(ext => ({
@@ -2,38 +2,41 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shouldAddSuffix = /(?<=<[^>/]+)$/;
4
4
  const plugin = ({ modules }) => {
5
+ const CompilerDOM = modules['@vue/compiler-dom'];
5
6
  return {
6
7
  version: 2.2,
7
8
  compileSFCTemplate(lang, template, options) {
8
9
  if (lang === 'html' || lang === 'md') {
9
- const compiler = modules['@vue/compiler-dom'];
10
10
  let addedSuffix = false;
11
11
  // #4583
12
12
  if (shouldAddSuffix.test(template)) {
13
13
  template += '>';
14
14
  addedSuffix = true;
15
15
  }
16
- const result = compiler.compile(template, {
16
+ const ast = CompilerDOM.parse(template, {
17
17
  ...options,
18
18
  comments: true,
19
19
  });
20
- // @ts-expect-error
21
- result.__addedSuffix = addedSuffix;
22
- return result;
20
+ CompilerDOM.transform(ast, options);
21
+ return {
22
+ ast,
23
+ code: '',
24
+ preamble: '',
25
+ __addedSuffix: addedSuffix,
26
+ };
23
27
  }
24
28
  },
25
29
  updateSFCTemplate(oldResult, change) {
26
- oldResult.code = oldResult.code.slice(0, change.start)
30
+ const newSource = oldResult.ast.source.slice(0, change.start)
27
31
  + change.newText
28
- + oldResult.code.slice(change.end);
32
+ + oldResult.ast.source.slice(change.end);
29
33
  // @ts-expect-error
30
34
  if (oldResult.__addedSuffix) {
31
- const originalTemplate = oldResult.code.slice(0, -1); // remove added '>'
35
+ const originalTemplate = newSource.slice(0, -1); // remove added '>'
32
36
  if (!shouldAddSuffix.test(originalTemplate)) {
33
37
  return undefined;
34
38
  }
35
39
  }
36
- const CompilerDOM = modules['@vue/compiler-dom'];
37
40
  const lengthDiff = change.newText.length - (change.end - change.start);
38
41
  let hitNodes = [];
39
42
  if (tryUpdateNode(oldResult.ast) && hitNodes.length) {
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const CompilerDOM = require("@vue/compiler-dom");
4
4
  const forEachTemplateNode_1 = require("../utils/forEachTemplateNode");
5
- const shared_1 = require("./shared");
5
+ const shared_1 = require("../utils/shared");
6
+ const shared_2 = require("./shared");
6
7
  const codeFeatures = {
7
- ...shared_1.allCodeFeatures,
8
+ ...shared_2.allCodeFeatures,
8
9
  format: false,
9
10
  structure: false,
10
11
  };
@@ -30,23 +31,12 @@ exports.default = plugin;
30
31
  function* generate(templateAst) {
31
32
  for (const node of (0, forEachTemplateNode_1.forEachElementNode)(templateAst)) {
32
33
  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.slice(start, end);
34
+ if (prop.type === CompilerDOM.NodeTypes.ATTRIBUTE
35
+ && prop.name === 'style'
36
+ && prop.value) {
43
37
  yield `x { `;
44
- yield [
45
- content,
46
- 'template',
47
- prop.arg.loc.start.offset + start,
48
- codeFeatures,
49
- ];
38
+ const [content, offset] = (0, shared_1.normalizeAttributeValue)(prop.value);
39
+ yield [content, 'template', offset, codeFeatures];
50
40
  yield ` }\n`;
51
41
  }
52
42
  }
@@ -5,7 +5,6 @@ const elementEvents_1 = require("../codegen/template/elementEvents");
5
5
  const templateChild_1 = require("../codegen/template/templateChild");
6
6
  const vFor_1 = require("../codegen/template/vFor");
7
7
  const utils_1 = require("../codegen/utils");
8
- const computedSfc_1 = require("../virtualFile/computedSfc");
9
8
  const codeFeatures = {
10
9
  format: true,
11
10
  };
@@ -21,7 +20,7 @@ const formatBrackets = {
21
20
  event: ['() => ', ';'],
22
21
  generic: ['<', '>() => {};'],
23
22
  };
24
- const plugin = ctx => {
23
+ const plugin = ({ modules: { typescript: ts } }) => {
25
24
  const parseds = new WeakMap();
26
25
  return {
27
26
  version: 2.2,
@@ -54,15 +53,14 @@ const plugin = ctx => {
54
53
  },
55
54
  };
56
55
  function parse(sfc) {
57
- const data = new Map();
56
+ const result = new Map();
58
57
  if (!sfc.template?.ast) {
59
- return data;
58
+ return result;
60
59
  }
61
- const templateContent = sfc.template.content;
62
- const inlineTsAsts = computedSfc_1.templateInlineTsAsts.get(sfc.template.ast);
60
+ const template = sfc.template;
63
61
  let i = 0;
64
62
  sfc.template.ast.children.forEach(visit);
65
- return data;
63
+ return result;
66
64
  function visit(node) {
67
65
  if (node.type === CompilerDOM.NodeTypes.COMMENT) {
68
66
  const match = node.loc.source.match(/^<!--\s*@vue-generic\s*\{(?<content>[\s\S]*)\}\s*-->$/);
@@ -87,8 +85,8 @@ const plugin = ctx => {
87
85
  && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY // style='z-index: 2' will compile to {'z-index':'2'}
88
86
  ) {
89
87
  if (prop.name === 'on' && prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
90
- const ast = (0, utils_1.createTsAst)(ctx.modules.typescript, inlineTsAsts, prop.exp.content);
91
- if ((0, elementEvents_1.isCompoundExpression)(ctx.modules.typescript, ast)) {
88
+ const ast = (0, utils_1.getTypeScriptAST)(ts, template, prop.exp.content);
89
+ if ((0, elementEvents_1.isCompoundExpression)(ts, ast)) {
92
90
  addFormatCodes(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.event);
93
91
  }
94
92
  else {
@@ -135,13 +133,13 @@ const plugin = ctx => {
135
133
  if (leftExpressionRange && leftExpressionText && source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
136
134
  let start = leftExpressionRange.start;
137
135
  let end = source.loc.start.offset + source.content.length;
138
- while (templateContent[start - 1] === ' ' || templateContent[start - 1] === '(') {
136
+ while (template.content[start - 1] === ' ' || template.content[start - 1] === '(') {
139
137
  start--;
140
138
  }
141
- while (templateContent[end] === ' ' || templateContent[end] === ')') {
139
+ while (template.content[end] === ' ' || template.content[end] === ')') {
142
140
  end++;
143
141
  }
144
- addFormatCodes(templateContent.slice(start, end), start, formatBrackets.for);
142
+ addFormatCodes(template.content.slice(start, end), start, formatBrackets.for);
145
143
  }
146
144
  for (const child of node.children) {
147
145
  visit(child);
@@ -161,7 +159,7 @@ const plugin = ctx => {
161
159
  }
162
160
  else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
163
161
  // {{ ... }}
164
- const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, templateContent);
162
+ const [content, start] = (0, templateChild_1.parseInterpolationNode)(node, template.content);
165
163
  const lines = content.split('\n');
166
164
  const firstLineEmpty = lines[0].trim() === '';
167
165
  const lastLineEmpty = lines[lines.length - 1].trim() === '';
@@ -188,7 +186,7 @@ const plugin = ctx => {
188
186
  }
189
187
  function addFormatCodes(code, offset, wrapper) {
190
188
  const id = 'template_inline_ts_' + i++;
191
- data.set(id, [
189
+ result.set(id, [
192
190
  wrapper[0],
193
191
  [
194
192
  code,
@@ -1,6 +1,5 @@
1
1
  import type { Sfc, VueLanguagePlugin } from '../types';
2
2
  export declare const tsCodegen: WeakMap<Sfc, {
3
- getLang: () => string;
4
3
  getScriptRanges: () => {
5
4
  exportDefault: (import("../types").TextRange & {
6
5
  expression: import("../types").TextRange;
@@ -121,14 +120,11 @@ export declare const tsCodegen: WeakMap<Sfc, {
121
120
  getSetupSlotsAssignName: () => string | undefined;
122
121
  getGeneratedScript: () => {
123
122
  codes: import("../types").Code[];
124
- generatedTemplate: boolean;
125
- generatedPropsType: boolean;
126
- bypassDefineComponent: boolean;
127
- bindingNames: Set<string>;
123
+ generatedTypes: Set<string>;
128
124
  localTypes: {
129
125
  generate: () => Generator<string, void, unknown>;
130
126
  readonly PrettifyLocal: string;
131
- readonly WithDefaultsLocal: string;
127
+ readonly WithDefaults: string;
132
128
  readonly WithSlots: string;
133
129
  readonly PropsChildren: string;
134
130
  readonly TypePropsToOption: string;
@@ -138,6 +134,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
138
134
  };
139
135
  getGeneratedTemplate: () => {
140
136
  codes: import("../types").Code[];
137
+ generatedTypes: Set<string>;
141
138
  currentInfo: {
142
139
  ignoreError?: boolean;
143
140
  expectError?: {
@@ -150,7 +147,6 @@ export declare const tsCodegen: WeakMap<Sfc, {
150
147
  };
151
148
  };
152
149
  resolveCodeFeatures: (features: import("../types").VueCodeInformation) => import("../types").VueCodeInformation;
153
- inlineTsAsts: Map<string, import("typescript").SourceFile> | undefined;
154
150
  inVFor: boolean;
155
151
  slots: {
156
152
  name: string;
@@ -164,40 +160,35 @@ export declare const tsCodegen: WeakMap<Sfc, {
164
160
  propsVar: string;
165
161
  }[];
166
162
  dollarVars: Set<string>;
167
- accessExternalVariables: Map<string, Set<number>>;
163
+ componentAccessMap: Map<string, Map<string, Set<number>>>;
168
164
  blockConditions: string[];
169
- scopedClasses: {
170
- source: string;
171
- className: string;
172
- offset: number;
173
- }[];
174
- emptyClassOffsets: number[];
175
165
  inlayHints: import("../codegen/inlayHints").InlayHintInfo[];
176
- bindingAttrLocs: import("@vue/compiler-dom").SourceLocation[];
177
166
  inheritedAttrVars: Set<string>;
178
167
  templateRefs: Map<string, {
179
168
  typeExp: string;
180
169
  offset: number;
181
170
  }[]>;
182
171
  currentComponent: {
183
- ctxVar: string;
184
- used: boolean;
172
+ get ctxVar(): string;
173
+ get propsVar(): string;
185
174
  } | undefined;
186
- singleRootElTypes: string[];
175
+ singleRootElTypes: Set<string>;
187
176
  singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
188
177
  addTemplateRef(name: string, typeExp: string, offset: number): void;
189
- accessExternalVariable(name: string, offset?: number): void;
190
- hasLocalVariable(name: string): boolean;
191
- addLocalVariable(name: string): void;
192
- removeLocalVariable(name: string): void;
178
+ recordComponentAccess(source: string, name: string, offset?: number): void;
179
+ scopes: Set<string>[];
180
+ declare(...varNames: string[]): void;
181
+ startScope(): () => Generator<import("../types").Code, any, any>;
193
182
  getInternalVariable(): string;
194
183
  getHoistVariable(originalVar: string): string;
195
184
  generateHoistVariables(): Generator<string, void, unknown>;
196
185
  generateConditionGuards(): Generator<string, void, unknown>;
197
- generateAutoImportCompletion(): Generator<import("../types").Code>;
198
186
  enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
199
187
  exit(): Generator<import("../types").Code>;
200
188
  } | undefined;
189
+ getImportComponentNames: () => Set<string>;
190
+ getSetupExposed: () => Set<string>;
191
+ getSetupConsts: () => Set<string>;
201
192
  }>;
202
193
  declare const plugin: VueLanguagePlugin;
203
194
  export default plugin;