@vue/language-core 3.1.5 → 3.1.7

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 (106) 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 +12 -18
  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 +7 -16
  28. package/lib/codegen/template/context.js +81 -93
  29. package/lib/codegen/template/element.js +153 -55
  30. package/lib/codegen/template/elementDirectives.js +32 -12
  31. package/lib/codegen/template/elementEvents.js +27 -28
  32. package/lib/codegen/template/elementProps.d.ts +2 -2
  33. package/lib/codegen/template/elementProps.js +49 -23
  34. package/lib/codegen/template/index.d.ts +8 -19
  35. package/lib/codegen/template/index.js +85 -80
  36. package/lib/codegen/template/interpolation.d.ts +3 -3
  37. package/lib/codegen/template/interpolation.js +90 -136
  38. package/lib/codegen/template/objectProperty.js +8 -4
  39. package/lib/codegen/template/propertyAccess.d.ts +1 -1
  40. package/lib/codegen/template/propertyAccess.js +5 -7
  41. package/lib/codegen/template/slotOutlet.js +25 -8
  42. package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
  43. package/lib/codegen/template/styleScopedClasses.js +23 -149
  44. package/lib/codegen/template/templateChild.d.ts +0 -1
  45. package/lib/codegen/template/templateChild.js +11 -68
  46. package/lib/codegen/template/vFor.js +10 -13
  47. package/lib/codegen/template/vIf.js +5 -3
  48. package/lib/codegen/template/vSlot.js +20 -15
  49. package/lib/codegen/utils/boundary.d.ts +3 -0
  50. package/lib/codegen/utils/boundary.js +13 -0
  51. package/lib/codegen/utils/camelized.js +3 -3
  52. package/lib/codegen/utils/escaped.js +4 -2
  53. package/lib/codegen/utils/index.d.ts +4 -5
  54. package/lib/codegen/utils/index.js +49 -21
  55. package/lib/codegen/utils/merge.d.ts +2 -2
  56. package/lib/codegen/utils/merge.js +9 -9
  57. package/lib/codegen/utils/stringLiteralKey.js +6 -3
  58. package/lib/codegen/utils/transform.d.ts +8 -0
  59. package/lib/codegen/utils/transform.js +27 -0
  60. package/lib/codegen/utils/unicode.js +4 -2
  61. package/lib/compilerOptions.d.ts +5 -2
  62. package/lib/compilerOptions.js +67 -44
  63. package/lib/languagePlugin.d.ts +1 -1
  64. package/lib/languagePlugin.js +5 -6
  65. package/lib/parsers/scriptRanges.d.ts +4 -8
  66. package/lib/parsers/scriptRanges.js +3 -2
  67. package/lib/parsers/scriptSetupRanges.d.ts +2 -6
  68. package/lib/parsers/scriptSetupRanges.js +3 -2
  69. package/lib/parsers/utils.d.ts +4 -6
  70. package/lib/parsers/utils.js +22 -27
  71. package/lib/plugins/vue-template-inline-css.js +2 -6
  72. package/lib/plugins/vue-template-inline-ts.js +12 -14
  73. package/lib/plugins/vue-tsx.d.ts +14 -32
  74. package/lib/plugins/vue-tsx.js +114 -72
  75. package/lib/plugins.js +1 -1
  76. package/lib/types.d.ts +5 -4
  77. package/lib/utils/parseSfc.js +7 -3
  78. package/lib/utils/shared.d.ts +1 -1
  79. package/lib/utils/shared.js +7 -6
  80. package/lib/utils/signals.d.ts +2 -2
  81. package/lib/utils/signals.js +8 -6
  82. package/lib/virtualCode/embeddedCodes.d.ts +12 -0
  83. package/lib/virtualCode/embeddedCodes.js +249 -0
  84. package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
  85. package/lib/virtualCode/index.js +81 -0
  86. package/lib/virtualCode/ir.d.ts +4 -0
  87. package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +59 -94
  88. package/lib/virtualCode/normalize.d.ts +2 -0
  89. package/lib/virtualCode/normalize.js +170 -0
  90. package/package.json +4 -4
  91. package/lib/codegen/style/classProperty.d.ts +0 -2
  92. package/lib/codegen/style/classProperty.js +0 -18
  93. package/lib/codegen/style/imports.d.ts +0 -2
  94. package/lib/codegen/style/imports.js +0 -27
  95. package/lib/codegen/template/elementChildren.d.ts +0 -5
  96. package/lib/codegen/template/elementChildren.js +0 -12
  97. package/lib/codegen/utils/wrapWith.d.ts +0 -2
  98. package/lib/codegen/utils/wrapWith.js +0 -15
  99. package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
  100. package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
  101. package/lib/virtualFile/computedSfc.d.ts +0 -6
  102. package/lib/virtualFile/computedVueSfc.d.ts +0 -4
  103. package/lib/virtualFile/computedVueSfc.js +0 -41
  104. package/lib/virtualFile/embeddedFile.d.ts +0 -11
  105. package/lib/virtualFile/embeddedFile.js +0 -14
  106. package/lib/virtualFile/vueFile.js +0 -49
@@ -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)('template', 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)('template', 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];
@@ -1,10 +1,12 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from './types';
3
+ interface ParseConfigHost extends Omit<ts.ParseConfigHost, 'readDirectory'> {
4
+ }
3
5
  export interface ParsedCommandLine extends Omit<ts.ParsedCommandLine, 'fileNames'> {
4
6
  vueOptions: VueCompilerOptions;
5
7
  }
6
- export declare const createParsedCommandLineByJson: (ts: typeof import("typescript"), host: Omit<ts.ParseConfigHost, "readDirectory">, rootDir: string, json: any, configFileName?: string | undefined) => ParsedCommandLine;
7
- export declare const createParsedCommandLine: (ts: typeof import("typescript"), host: Omit<ts.ParseConfigHost, "readDirectory">, configFileName: string) => ParsedCommandLine;
8
+ export declare function createParsedCommandLineByJson(ts: typeof import('typescript'), host: ParseConfigHost, rootDir: string, json: any, configFileName?: string): ParsedCommandLine;
9
+ export declare function createParsedCommandLine(ts: typeof import('typescript'), host: ParseConfigHost, configFileName: string): ParsedCommandLine;
8
10
  export declare class CompilerOptionsResolver {
9
11
  fileExists?: ((path: string) => boolean) | undefined;
10
12
  options: Omit<RawVueCompilerOptions, 'target' | 'globalTypesPath' | 'plugins'>;
@@ -22,3 +24,4 @@ export declare function createGlobalTypesWriter(vueOptions: VueCompilerOptions,
22
24
  * @deprecated use `createGlobalTypesWriter` instead
23
25
  */
24
26
  export declare function writeGlobalTypes(vueOptions: VueCompilerOptions, writeFile: (fileName: string, data: string) => void): void;
27
+ export {};
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CompilerOptionsResolver = exports.createParsedCommandLine = exports.createParsedCommandLineByJson = void 0;
3
+ exports.CompilerOptionsResolver = void 0;
4
+ exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
5
+ exports.createParsedCommandLine = createParsedCommandLine;
4
6
  exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
5
7
  exports.createGlobalTypesWriter = createGlobalTypesWriter;
6
8
  exports.writeGlobalTypes = writeGlobalTypes;
@@ -8,54 +10,75 @@ const shared_1 = require("@vue/shared");
8
10
  const path_browserify_1 = require("path-browserify");
9
11
  const globalTypes_1 = require("./codegen/globalTypes");
10
12
  const shared_2 = require("./utils/shared");
11
- exports.createParsedCommandLineByJson = create((ts, host, rootDir, json, configFileName) => {
12
- // `parseJsonConfigFileContent` is missing in tsc
13
- return 'parseJsonConfigFileContent' in ts
14
- ? ts.parseJsonConfigFileContent(json, host, rootDir, {}, configFileName)
15
- : ts.parseJsonSourceFileConfigFileContent(ts.parseJsonText(configFileName ?? 'tsconfig.json', JSON.stringify(json)), host, rootDir, {}, configFileName);
16
- });
17
- exports.createParsedCommandLine = create((ts, host, configFileName) => {
18
- const config = ts.readJsonConfigFile(configFileName, host.readFile);
19
- return ts.parseJsonSourceFileConfigFileContent(config, host, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
20
- });
21
- function create(getParsedCommandLine) {
22
- return (ts, host, ...args) => {
13
+ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName) {
14
+ const extendedPaths = new Set();
15
+ const proxyHost = {
16
+ ...host,
17
+ readFile(fileName) {
18
+ if (!fileName.endsWith('/package.json')) {
19
+ extendedPaths.add(fileName);
20
+ }
21
+ return host.readFile(fileName);
22
+ },
23
+ readDirectory() {
24
+ return [];
25
+ },
26
+ };
27
+ const config = ts.readJsonConfigFile(rootDir, () => JSON.stringify(json));
28
+ const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, rootDir, {}, configFileName);
29
+ const resolver = new CompilerOptionsResolver(host.fileExists);
30
+ for (const extendPath of [...extendedPaths].reverse()) {
23
31
  try {
24
- const extendedPaths = new Set();
25
- const proxyHost = {
26
- ...host,
27
- readFile(fileName) {
28
- if (!fileName.endsWith('/package.json')) {
29
- extendedPaths.add(fileName);
30
- }
31
- return host.readFile(fileName);
32
- },
33
- readDirectory() {
34
- return [];
35
- },
36
- };
37
- const parsed = getParsedCommandLine(ts, proxyHost, ...args);
38
- const resolver = new CompilerOptionsResolver(host.fileExists);
39
- for (const extendPath of [...extendedPaths].reverse()) {
40
- try {
41
- const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
42
- const obj = ts.convertToObject(configFile, []);
43
- const rawOptions = obj?.vueCompilerOptions ?? {};
44
- resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
32
+ const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
33
+ const obj = ts.convertToObject(configFile, []);
34
+ const rawOptions = obj?.vueCompilerOptions ?? {};
35
+ resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
36
+ }
37
+ catch { }
38
+ }
39
+ resolver.addConfig(json?.vueCompilerOptions ?? {}, rootDir);
40
+ return {
41
+ ...parsed,
42
+ vueOptions: resolver.build(),
43
+ };
44
+ }
45
+ function createParsedCommandLine(ts, host, configFileName) {
46
+ try {
47
+ const extendedPaths = new Set();
48
+ const proxyHost = {
49
+ ...host,
50
+ readFile(fileName) {
51
+ if (!fileName.endsWith('/package.json')) {
52
+ extendedPaths.add(fileName);
45
53
  }
46
- catch { }
54
+ return host.readFile(fileName);
55
+ },
56
+ readDirectory() {
57
+ return [];
58
+ },
59
+ };
60
+ const config = ts.readJsonConfigFile(configFileName, proxyHost.readFile);
61
+ const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
62
+ const resolver = new CompilerOptionsResolver(host.fileExists);
63
+ for (const extendPath of [...extendedPaths].reverse()) {
64
+ try {
65
+ const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
66
+ const obj = ts.convertToObject(configFile, []);
67
+ const rawOptions = obj?.vueCompilerOptions ?? {};
68
+ resolver.addConfig(rawOptions, path_browserify_1.posix.dirname(configFile.fileName));
47
69
  }
48
- return {
49
- ...parsed,
50
- vueOptions: resolver.build(),
51
- };
70
+ catch { }
52
71
  }
53
- catch { }
54
72
  return {
55
- options: {},
56
- errors: [],
57
- vueOptions: getDefaultCompilerOptions(),
73
+ ...parsed,
74
+ vueOptions: resolver.build(),
58
75
  };
76
+ }
77
+ catch { }
78
+ return {
79
+ options: {},
80
+ errors: [],
81
+ vueOptions: getDefaultCompilerOptions(),
59
82
  };
60
83
  }
61
84
  class CompilerOptionsResolver {
@@ -128,7 +151,7 @@ class CompilerOptionsResolver {
128
151
  ...defaults.fallthroughComponentNames,
129
152
  ...this.options.fallthroughComponentNames ?? [],
130
153
  ].map(shared_2.hyphenateTag),
131
- // 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
132
155
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
133
156
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
134
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,7 +6,7 @@ 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");
9
+ const virtualCode_1 = require("./virtualCode");
10
10
  const fileRegistries = {};
11
11
  function getVueFileRegistry(compilerOptions, vueCompilerOptions, plugins) {
12
12
  const key = JSON.stringify([
@@ -47,14 +47,14 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
47
47
  createVirtualCode(scriptId, languageId, snapshot) {
48
48
  const fileName = asFileName(scriptId);
49
49
  if (plugins.some(plugin => plugin.isValidFile?.(fileName, languageId))) {
50
- const code = fileRegistry.get(fileName);
50
+ const code = fileRegistry.get(String(scriptId));
51
51
  if (code) {
52
52
  code.update(snapshot);
53
53
  return code;
54
54
  }
55
55
  else {
56
- const code = new vueFile_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
57
- fileRegistry.set(fileName, code);
56
+ const code = new virtualCode_1.VueVirtualCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts);
57
+ fileRegistry.set(String(scriptId), code);
58
58
  return code;
59
59
  }
60
60
  }
@@ -64,8 +64,7 @@ function createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFile
64
64
  return code;
65
65
  },
66
66
  disposeVirtualCode(scriptId) {
67
- const fileName = asFileName(scriptId);
68
- fileRegistry.delete(fileName);
67
+ fileRegistry.delete(String(scriptId));
69
68
  },
70
69
  typescript: {
71
70
  extraFileExtensions: getAllExtensions(vueCompilerOptions)
@@ -1,8 +1,8 @@
1
1
  import type * as ts from 'typescript';
2
- import type { TextRange } from '../types';
2
+ import type { TextRange, VueCompilerOptions } from '../types';
3
3
  export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> {
4
4
  }
5
- export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, hasScriptSetup: boolean): {
5
+ export declare function parseScriptRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
6
6
  exportDefault: (TextRange & {
7
7
  expression: TextRange;
8
8
  }) | undefined;
@@ -16,10 +16,6 @@ export declare function parseScriptRanges(ts: typeof import('typescript'), ast:
16
16
  name: TextRange | undefined;
17
17
  inheritAttrs: string | undefined;
18
18
  } | undefined;
19
- bindings: {
20
- range: TextRange;
21
- moduleName?: string;
22
- isDefaultImport?: boolean;
23
- isNamespace?: boolean;
24
- }[];
19
+ bindings: TextRange[];
20
+ components: TextRange[];
25
21
  };
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptRanges = parseScriptRanges;
4
4
  const shared_1 = require("../utils/shared");
5
5
  const utils_1 = require("./utils");
6
- function parseScriptRanges(ts, ast, hasScriptSetup) {
6
+ function parseScriptRanges(ts, ast, vueCompilerOptions) {
7
7
  let exportDefault;
8
8
  let componentOptions;
9
- const bindings = hasScriptSetup ? (0, utils_1.parseBindingRanges)(ts, ast) : [];
9
+ const { bindings, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
10
10
  ts.forEachChild(ast, raw => {
11
11
  if (ts.isExportAssignment(raw)) {
12
12
  exportDefault = {
@@ -70,6 +70,7 @@ function parseScriptRanges(ts, ast, hasScriptSetup) {
70
70
  exportDefault,
71
71
  componentOptions,
72
72
  bindings,
73
+ components,
73
74
  };
74
75
  function _getStartEnd(node) {
75
76
  return (0, shared_1.getStartEnd)(ts, node, ast);
@@ -48,12 +48,8 @@ export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRan
48
48
  export declare function parseScriptSetupRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
49
49
  leadingCommentEndOffset: number;
50
50
  importSectionEndOffset: number;
51
- bindings: {
52
- range: TextRange;
53
- moduleName?: string;
54
- isDefaultImport?: boolean;
55
- isNamespace?: boolean;
56
- }[];
51
+ bindings: TextRange[];
52
+ components: TextRange[];
57
53
  defineModel: DefineModel[];
58
54
  defineProps: DefineProps | undefined;
59
55
  withDefaults: WithDefaults | undefined;
@@ -20,7 +20,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
20
20
  const text = ast.text;
21
21
  const leadingCommentRanges = ts.getLeadingCommentRanges(text, 0)?.reverse() ?? [];
22
22
  const leadingCommentEndOffset = leadingCommentRanges.find(range => tsCheckReg.test(text.slice(range.pos, range.end)))?.end ?? 0;
23
- let bindings = (0, utils_1.parseBindingRanges)(ts, ast);
23
+ let { bindings, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
24
24
  let foundNonImportExportNode = false;
25
25
  let importSectionEndOffset = 0;
26
26
  ts.forEachChild(ast, node => {
@@ -48,7 +48,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
48
48
  });
49
49
  ts.forEachChild(ast, node => visitNode(node, [ast]));
50
50
  const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
51
- bindings = bindings.filter(({ range }) => {
51
+ bindings = bindings.filter(range => {
52
52
  const name = text.slice(range.start, range.end);
53
53
  return !templateRefNames.has(name);
54
54
  });
@@ -56,6 +56,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
56
56
  leadingCommentEndOffset,
57
57
  importSectionEndOffset,
58
58
  bindings,
59
+ components,
59
60
  defineModel,
60
61
  defineProps,
61
62
  withDefaults,
@@ -1,11 +1,9 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { TextRange } from '../types';
3
- export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile): {
4
- range: TextRange;
5
- moduleName?: string;
6
- isDefaultImport?: boolean;
7
- isNamespace?: boolean;
8
- }[];
3
+ export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile, componentExtsensions: string[]): {
4
+ bindings: TextRange[];
5
+ components: TextRange[];
6
+ };
9
7
  export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
10
8
  start: number;
11
9
  end: number;
@@ -4,44 +4,37 @@ exports.parseBindingRanges = parseBindingRanges;
4
4
  exports.getClosestMultiLineCommentRange = getClosestMultiLineCommentRange;
5
5
  const collectBindings_1 = require("../utils/collectBindings");
6
6
  const shared_1 = require("../utils/shared");
7
- function parseBindingRanges(ts, ast) {
7
+ function parseBindingRanges(ts, ast, componentExtsensions) {
8
8
  const bindings = [];
9
+ const components = [];
9
10
  ts.forEachChild(ast, node => {
10
11
  if (ts.isVariableStatement(node)) {
11
12
  for (const decl of node.declarationList.declarations) {
12
13
  const ranges = (0, collectBindings_1.collectBindingRanges)(ts, decl.name, ast);
13
- bindings.push(...ranges.map(range => ({ range })));
14
+ bindings.push(...ranges);
14
15
  }
15
16
  }
16
17
  else if (ts.isFunctionDeclaration(node)) {
17
18
  if (node.name && ts.isIdentifier(node.name)) {
18
- bindings.push({
19
- range: _getStartEnd(node.name),
20
- });
19
+ bindings.push(_getStartEnd(node.name));
21
20
  }
22
21
  }
23
22
  else if (ts.isClassDeclaration(node)) {
24
23
  if (node.name) {
25
- bindings.push({
26
- range: _getStartEnd(node.name),
27
- });
24
+ bindings.push(_getStartEnd(node.name));
28
25
  }
29
26
  }
30
27
  else if (ts.isEnumDeclaration(node)) {
31
- bindings.push({
32
- range: _getStartEnd(node.name),
33
- });
28
+ bindings.push(_getStartEnd(node.name));
34
29
  }
35
30
  if (ts.isImportDeclaration(node)) {
36
31
  const moduleName = _getNodeText(node.moduleSpecifier).slice(1, -1);
37
32
  if (node.importClause && !node.importClause.isTypeOnly) {
38
33
  const { name, namedBindings } = node.importClause;
39
34
  if (name) {
40
- bindings.push({
41
- range: _getStartEnd(name),
42
- moduleName,
43
- isDefaultImport: true,
44
- });
35
+ if (componentExtsensions.some(ext => moduleName.endsWith(ext))) {
36
+ components.push(_getStartEnd(name));
37
+ }
45
38
  }
46
39
  if (namedBindings) {
47
40
  if (ts.isNamedImports(namedBindings)) {
@@ -49,25 +42,27 @@ function parseBindingRanges(ts, ast) {
49
42
  if (element.isTypeOnly) {
50
43
  continue;
51
44
  }
52
- bindings.push({
53
- range: _getStartEnd(element.name),
54
- moduleName,
55
- isDefaultImport: element.propertyName?.text === 'default',
56
- });
45
+ if (element.propertyName
46
+ && _getNodeText(element.propertyName) === 'default'
47
+ && componentExtsensions.some(ext => moduleName.endsWith(ext))) {
48
+ components.push(_getStartEnd(element.name));
49
+ }
50
+ else {
51
+ bindings.push(_getStartEnd(element.name));
52
+ }
57
53
  }
58
54
  }
59
55
  else {
60
- bindings.push({
61
- range: _getStartEnd(namedBindings.name),
62
- moduleName,
63
- isNamespace: true,
64
- });
56
+ bindings.push(_getStartEnd(namedBindings.name));
65
57
  }
66
58
  }
67
59
  }
68
60
  }
69
61
  });
70
- return bindings;
62
+ return {
63
+ bindings,
64
+ components,
65
+ };
71
66
  function _getStartEnd(node) {
72
67
  return (0, shared_1.getStartEnd)(ts, node, ast);
73
68
  }
@@ -35,12 +35,8 @@ function* generate(templateAst) {
35
35
  && prop.name === 'style'
36
36
  && prop.value) {
37
37
  yield `x { `;
38
- yield [
39
- prop.value.content,
40
- 'template',
41
- (0, shared_1.getAttributeValueOffset)(prop.value),
42
- codeFeatures,
43
- ];
38
+ const [content, offset] = (0, shared_1.normalizeAttributeValue)(prop.value);
39
+ yield [content, 'template', offset, codeFeatures];
44
40
  yield ` }\n`;
45
41
  }
46
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,