@vue/language-core 3.1.7 → 3.2.0

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 (64) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +25 -3
  3. package/lib/codegen/codeFeatures.d.ts +18 -84
  4. package/lib/codegen/names.d.ts +2 -5
  5. package/lib/codegen/names.js +3 -6
  6. package/lib/codegen/script/component.js +38 -18
  7. package/lib/codegen/script/index.d.ts +4 -12
  8. package/lib/codegen/script/index.js +132 -71
  9. package/lib/codegen/script/scriptSetup.js +52 -14
  10. package/lib/codegen/script/template.d.ts +1 -1
  11. package/lib/codegen/script/template.js +73 -50
  12. package/lib/codegen/style/index.d.ts +10 -13
  13. package/lib/codegen/style/modules.js +34 -1
  14. package/lib/codegen/template/context.d.ts +8 -11
  15. package/lib/codegen/template/context.js +36 -2
  16. package/lib/codegen/template/element.js +146 -159
  17. package/lib/codegen/template/elementDirectives.js +36 -3
  18. package/lib/codegen/template/elementEvents.d.ts +1 -1
  19. package/lib/codegen/template/elementEvents.js +39 -6
  20. package/lib/codegen/template/elementProps.js +35 -2
  21. package/lib/codegen/template/index.d.ts +11 -14
  22. package/lib/codegen/template/index.js +34 -1
  23. package/lib/codegen/template/interpolation.d.ts +4 -3
  24. package/lib/codegen/template/interpolation.js +37 -4
  25. package/lib/codegen/template/slotOutlet.js +35 -2
  26. package/lib/codegen/template/templateChild.js +45 -16
  27. package/lib/codegen/template/vFor.js +37 -4
  28. package/lib/codegen/template/vIf.js +34 -1
  29. package/lib/codegen/template/vSlot.d.ts +1 -1
  30. package/lib/codegen/template/vSlot.js +52 -25
  31. package/lib/codegen/utils/index.js +4 -2
  32. package/lib/compilerOptions.d.ts +7 -11
  33. package/lib/compilerOptions.js +48 -89
  34. package/lib/languagePlugin.js +34 -1
  35. package/lib/parsers/scriptRanges.d.ts +27 -15
  36. package/lib/parsers/scriptRanges.js +66 -62
  37. package/lib/parsers/scriptSetupRanges.d.ts +19 -24
  38. package/lib/parsers/scriptSetupRanges.js +13 -15
  39. package/lib/parsers/utils.d.ts +3 -6
  40. package/lib/parsers/utils.js +4 -0
  41. package/lib/plugins/vue-script-js.js +1 -1
  42. package/lib/plugins/vue-template-inline-css.js +34 -1
  43. package/lib/plugins/vue-template-inline-ts.js +34 -1
  44. package/lib/plugins/vue-tsx.d.ts +38 -117
  45. package/lib/plugins/vue-tsx.js +62 -33
  46. package/lib/plugins.js +17 -14
  47. package/lib/types.d.ts +8 -8
  48. package/lib/utils/collectBindings.d.ts +1 -1
  49. package/lib/utils/forEachTemplateNode.js +34 -1
  50. package/lib/utils/parseSfc.js +34 -1
  51. package/lib/utils/shared.d.ts +1 -1
  52. package/lib/utils/shared.js +2 -1
  53. package/lib/virtualCode/embeddedCodes.js +6 -2
  54. package/lib/virtualCode/index.js +10 -1
  55. package/lib/virtualCode/ir.js +34 -1
  56. package/lib/virtualCode/normalize.js +37 -2
  57. package/package.json +4 -12
  58. package/types/props-fallback.d.ts +5 -0
  59. package/types/template-helpers.d.ts +146 -0
  60. package/types/vue-3.4-shims.d.ts +6 -0
  61. package/lib/codegen/globalTypes.d.ts +0 -3
  62. package/lib/codegen/globalTypes.js +0 -163
  63. package/lib/codegen/script/src.d.ts +0 -2
  64. package/lib/codegen/script/src.js +0 -38
@@ -4,11 +4,8 @@ exports.CompilerOptionsResolver = void 0;
4
4
  exports.createParsedCommandLineByJson = createParsedCommandLineByJson;
5
5
  exports.createParsedCommandLine = createParsedCommandLine;
6
6
  exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
7
- exports.createGlobalTypesWriter = createGlobalTypesWriter;
8
- exports.writeGlobalTypes = writeGlobalTypes;
9
7
  const shared_1 = require("@vue/shared");
10
8
  const path_browserify_1 = require("path-browserify");
11
- const globalTypes_1 = require("./codegen/globalTypes");
12
9
  const shared_2 = require("./utils/shared");
13
10
  function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName) {
14
11
  const extendedPaths = new Set();
@@ -26,7 +23,7 @@ function createParsedCommandLineByJson(ts, host, rootDir, json, configFileName)
26
23
  };
27
24
  const config = ts.readJsonConfigFile(rootDir, () => JSON.stringify(json));
28
25
  const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, rootDir, {}, configFileName);
29
- const resolver = new CompilerOptionsResolver(host.fileExists);
26
+ const resolver = new CompilerOptionsResolver(ts, host.readFile);
30
27
  for (const extendPath of [...extendedPaths].reverse()) {
31
28
  try {
32
29
  const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
@@ -59,7 +56,7 @@ function createParsedCommandLine(ts, host, configFileName) {
59
56
  };
60
57
  const config = ts.readJsonConfigFile(configFileName, proxyHost.readFile);
61
58
  const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost, path_browserify_1.posix.dirname(configFileName), {}, configFileName);
62
- const resolver = new CompilerOptionsResolver(host.fileExists);
59
+ const resolver = new CompilerOptionsResolver(ts, host.readFile);
63
60
  for (const extendPath of [...extendedPaths].reverse()) {
64
61
  try {
65
62
  const configFile = ts.readJsonConfigFile(extendPath, host.readFile);
@@ -82,32 +79,51 @@ function createParsedCommandLine(ts, host, configFileName) {
82
79
  };
83
80
  }
84
81
  class CompilerOptionsResolver {
85
- constructor(fileExists) {
86
- this.fileExists = fileExists;
87
- this.options = {};
88
- this.plugins = [];
82
+ ts;
83
+ readFile;
84
+ options = {};
85
+ target;
86
+ typesRoot;
87
+ plugins = [];
88
+ constructor(ts, readFile) {
89
+ this.ts = ts;
90
+ this.readFile = readFile;
89
91
  }
90
92
  addConfig(options, rootDir) {
91
93
  for (const key in options) {
92
94
  switch (key) {
93
95
  case 'target':
94
96
  if (options[key] === 'auto') {
95
- this.target = findVueVersion(rootDir);
97
+ this.target = this.resolveVueVersion(rootDir);
96
98
  }
97
99
  else {
98
100
  this.target = options[key];
99
101
  }
100
102
  break;
101
- case 'globalTypesPath':
103
+ case 'strictTemplates':
104
+ const strict = !!options.strictTemplates;
105
+ this.options.strictVModel ??= strict;
106
+ this.options.checkUnknownProps ??= strict;
107
+ this.options.checkUnknownEvents ??= strict;
108
+ this.options.checkUnknownDirectives ??= strict;
109
+ this.options.checkUnknownComponents ??= strict;
110
+ break;
111
+ case 'typesRoot':
102
112
  if (options[key] !== undefined) {
103
- this.globalTypesPath = path_browserify_1.posix.join(rootDir, options[key]);
113
+ if (path_browserify_1.posix.isAbsolute(options[key])) {
114
+ this.typesRoot = options[key];
115
+ }
116
+ else {
117
+ this.typesRoot = path_browserify_1.posix.join(rootDir, options[key]);
118
+ }
104
119
  }
105
120
  break;
106
121
  case 'plugins':
107
122
  this.plugins = (options.plugins ?? [])
108
123
  .flatMap((pluginPath) => {
109
124
  try {
110
- const resolvedPath = resolvePath(pluginPath, rootDir);
125
+ const resolve = require?.resolve;
126
+ const resolvedPath = resolve?.(pluginPath, { paths: [rootDir] });
111
127
  if (resolvedPath) {
112
128
  const plugin = require(resolvedPath);
113
129
  plugin.__moduleName = pluginPath;
@@ -130,11 +146,10 @@ class CompilerOptionsResolver {
130
146
  }
131
147
  }
132
148
  if (options.target === undefined) {
133
- this.target ??= findVueVersion(rootDir);
149
+ this.target ??= this.resolveVueVersion(rootDir);
134
150
  }
135
151
  }
136
- build(defaults) {
137
- defaults ??= getDefaultCompilerOptions(this.target, this.options.lib, this.options.strictTemplates);
152
+ build(defaults = getDefaultCompilerOptions(this.target, this.options.lib, undefined, this.typesRoot)) {
138
153
  const resolvedOptions = {
139
154
  ...defaults,
140
155
  ...this.options,
@@ -155,75 +170,37 @@ class CompilerOptionsResolver {
155
170
  // https://vuejs.org/guide/essentials/forms.html#form-input-bindings
156
171
  experimentalModelPropName: Object.fromEntries(Object.entries(this.options.experimentalModelPropName ?? defaults.experimentalModelPropName).map(([k, v]) => [(0, shared_1.camelize)(k), v])),
157
172
  };
158
- if (resolvedOptions.globalTypesPath === shared_1.NOOP) {
159
- if (this.fileExists && this.globalTypesPath === undefined) {
160
- const fileDirToGlobalTypesPath = new Map();
161
- resolvedOptions.globalTypesPath = fileName => {
162
- const fileDir = path_browserify_1.posix.dirname(fileName);
163
- if (fileDirToGlobalTypesPath.has(fileDir)) {
164
- return fileDirToGlobalTypesPath.get(fileDir);
165
- }
166
- const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib);
167
- const result = root
168
- ? path_browserify_1.posix.join(root, 'node_modules', '.vue-global-types', (0, globalTypes_1.getGlobalTypesFileName)(resolvedOptions))
169
- : undefined;
170
- fileDirToGlobalTypesPath.set(fileDir, result);
171
- return result;
172
- };
173
- }
174
- else {
175
- resolvedOptions.globalTypesPath = () => this.globalTypesPath;
176
- }
177
- }
178
173
  return resolvedOptions;
179
174
  }
180
- findNodeModulesRoot(dir, lib) {
181
- while (!this.fileExists(path_browserify_1.posix.join(dir, 'node_modules', lib, 'package.json'))) {
182
- const parentDir = path_browserify_1.posix.dirname(dir);
183
- if (dir === parentDir) {
184
- return;
185
- }
186
- dir = parentDir;
187
- }
188
- return dir;
189
- }
190
- }
191
- exports.CompilerOptionsResolver = CompilerOptionsResolver;
192
- function findVueVersion(rootDir) {
193
- const resolvedPath = resolvePath('vue/package.json', rootDir);
194
- if (resolvedPath) {
195
- const vuePackageJson = require(resolvedPath);
196
- const versionNumbers = vuePackageJson.version.split('.');
197
- return Number(versionNumbers[0] + '.' + versionNumbers[1]);
198
- }
199
- else {
200
- // console.warn('Load vue/package.json failed from', folder);
201
- }
202
- }
203
- function resolvePath(scriptPath, root) {
204
- try {
205
- if (require?.resolve) {
206
- return require.resolve(scriptPath, { paths: [root] });
175
+ resolveVueVersion(folder) {
176
+ const packageJsonPath = this.ts.findConfigFile(folder, fileName => this.readFile(fileName) !== undefined, 'node_modules/vue/package.json');
177
+ if (!packageJsonPath) {
178
+ return;
207
179
  }
208
- else {
209
- // console.warn('failed to resolve path:', scriptPath, 'require.resolve is not supported in web');
180
+ const packageJsonContent = this.readFile(packageJsonPath);
181
+ if (!packageJsonContent) {
182
+ return;
210
183
  }
211
- }
212
- catch {
213
- // console.warn(error);
184
+ const packageJson = JSON.parse(packageJsonContent);
185
+ const version = packageJson.version;
186
+ const [majorVersion, minorVersion] = version.split('.');
187
+ return Number(majorVersion + '.' + minorVersion);
214
188
  }
215
189
  }
216
- function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = false) {
190
+ exports.CompilerOptionsResolver = CompilerOptionsResolver;
191
+ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = false, typesRoot = typeof __dirname !== 'undefined'
192
+ ? path_browserify_1.posix.join(__dirname.replace(/\\/g, '/'), '..', 'types')
193
+ : '@vue/language-core/types') {
217
194
  return {
218
195
  target,
219
196
  lib,
220
- globalTypesPath: shared_1.NOOP,
197
+ typesRoot,
221
198
  extensions: ['.vue'],
222
199
  vitePressExtensions: [],
223
200
  petiteVueExtensions: [],
224
201
  jsxSlots: false,
225
- strictVModel: strictTemplates,
226
202
  strictCssModules: false,
203
+ strictVModel: strictTemplates,
227
204
  checkUnknownProps: strictTemplates,
228
205
  checkUnknownEvents: strictTemplates,
229
206
  checkUnknownDirectives: strictTemplates,
@@ -275,22 +252,4 @@ function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTemplates = f
275
252
  },
276
253
  };
277
254
  }
278
- function createGlobalTypesWriter(vueOptions, writeFile) {
279
- const writed = new Set();
280
- const { globalTypesPath } = vueOptions;
281
- return (fileName) => {
282
- const result = globalTypesPath(fileName);
283
- if (result && !writed.has(result)) {
284
- writed.add(result);
285
- writeFile(result, (0, globalTypes_1.generateGlobalTypes)(vueOptions));
286
- }
287
- return result;
288
- };
289
- }
290
- /**
291
- * @deprecated use `createGlobalTypesWriter` instead
292
- */
293
- function writeGlobalTypes(vueOptions, writeFile) {
294
- vueOptions.globalTypesPath = createGlobalTypesWriter(vueOptions, writeFile);
295
- }
296
255
  //# sourceMappingURL=compilerOptions.js.map
@@ -1,10 +1,43 @@
1
1
  "use strict";
2
2
  /// <reference types="@volar/typescript" />
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
3
36
  Object.defineProperty(exports, "__esModule", { value: true });
4
37
  exports.createVueLanguagePlugin = createVueLanguagePlugin;
5
38
  exports.getAllExtensions = getAllExtensions;
6
39
  const language_core_1 = require("@volar/language-core");
7
- const CompilerDOM = require("@vue/compiler-dom");
40
+ const CompilerDOM = __importStar(require("@vue/compiler-dom"));
8
41
  const plugins_1 = require("./plugins");
9
42
  const virtualCode_1 = require("./virtualCode");
10
43
  const fileRegistries = {};
@@ -2,20 +2,32 @@ import type * as ts from 'typescript';
2
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, vueCompilerOptions: VueCompilerOptions): {
6
- exportDefault: (TextRange & {
7
- expression: TextRange;
5
+ export declare function parseScriptRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
6
+ exportDefault: (TextRange<ts.Node> & {
7
+ expression: TextRange<ts.Expression>;
8
+ isObjectLiteral: boolean;
9
+ options?: {
10
+ isObjectLiteral: boolean;
11
+ expression: TextRange<ts.Node>;
12
+ args: TextRange<ts.ObjectLiteralExpression>;
13
+ components: TextRange<ts.ObjectLiteralExpression> | undefined;
14
+ directives: TextRange<ts.Node> | undefined;
15
+ name: TextRange<ts.StringLiteral> | undefined;
16
+ inheritAttrs: string | undefined;
17
+ } | undefined;
8
18
  }) | undefined;
9
- componentOptions: {
10
- expression: TextRange;
11
- args: TextRange;
12
- argsNode: ts.ObjectLiteralExpression;
13
- components: TextRange | undefined;
14
- componentsNode: ts.ObjectLiteralExpression | undefined;
15
- directives: TextRange | undefined;
16
- name: TextRange | undefined;
17
- inheritAttrs: string | undefined;
18
- } | undefined;
19
- bindings: TextRange[];
20
- components: TextRange[];
19
+ bindings: TextRange<ts.Node>[];
20
+ components: TextRange<ts.Node>[];
21
21
  };
22
+ export declare function parseOptionsFromExtression(ts: typeof import('typescript'), exp: ts.Node, sourceFile: ts.SourceFile): {
23
+ isObjectLiteral: boolean;
24
+ expression: TextRange<ts.Node>;
25
+ args: TextRange<ts.ObjectLiteralExpression>;
26
+ argsNode: ts.ObjectLiteralExpression;
27
+ components: TextRange<ts.ObjectLiteralExpression> | undefined;
28
+ componentsNode: ts.ObjectLiteralExpression | undefined;
29
+ directives: TextRange<ts.ObjectLiteralExpression> | undefined;
30
+ name: TextRange<ts.StringLiteral> | undefined;
31
+ nameNode: ts.StringLiteral | undefined;
32
+ inheritAttrs: string | undefined;
33
+ } | undefined;
@@ -1,86 +1,90 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseScriptRanges = parseScriptRanges;
4
+ exports.parseOptionsFromExtression = parseOptionsFromExtression;
4
5
  const shared_1 = require("../utils/shared");
5
6
  const utils_1 = require("./utils");
6
- function parseScriptRanges(ts, ast, vueCompilerOptions) {
7
+ function parseScriptRanges(ts, sourceFile, vueCompilerOptions) {
7
8
  let exportDefault;
8
- let componentOptions;
9
- const { bindings, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
10
- ts.forEachChild(ast, raw => {
11
- if (ts.isExportAssignment(raw)) {
9
+ const { bindings, components } = (0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions);
10
+ ts.forEachChild(sourceFile, child => {
11
+ if (ts.isExportAssignment(child)) {
12
12
  exportDefault = {
13
- ..._getStartEnd(raw),
14
- expression: _getStartEnd(raw.expression),
13
+ ...(0, shared_1.getStartEnd)(ts, child, sourceFile),
14
+ expression: (0, shared_1.getStartEnd)(ts, child.expression, sourceFile),
15
+ isObjectLiteral: ts.isObjectLiteralExpression(child.expression),
16
+ options: parseOptionsFromExtression(ts, child.expression, sourceFile),
15
17
  };
16
- const comment = (0, utils_1.getClosestMultiLineCommentRange)(ts, raw, [], ast);
18
+ const comment = (0, utils_1.getClosestMultiLineCommentRange)(ts, child, [], sourceFile);
17
19
  if (comment) {
18
20
  exportDefault.start = comment.start;
19
21
  }
20
- let node = raw;
21
- while (isAsExpression(node.expression) || ts.isParenthesizedExpression(node.expression)) { // fix https://github.com/vuejs/language-tools/issues/1882
22
- node = node.expression;
23
- }
24
- let obj;
25
- if (ts.isObjectLiteralExpression(node.expression)) {
26
- obj = node.expression;
27
- }
28
- else if (ts.isCallExpression(node.expression) && node.expression.arguments.length) {
29
- const arg0 = node.expression.arguments[0];
30
- if (ts.isObjectLiteralExpression(arg0)) {
31
- obj = arg0;
32
- }
33
- }
34
- if (obj) {
35
- let componentsOptionNode;
36
- let directivesOptionNode;
37
- let nameOptionNode;
38
- let inheritAttrsOption;
39
- ts.forEachChild(obj, node => {
40
- if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
41
- const name = _getNodeText(node.name);
42
- if (name === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
43
- componentsOptionNode = node.initializer;
44
- }
45
- else if (name === 'directives' && ts.isObjectLiteralExpression(node.initializer)) {
46
- directivesOptionNode = node.initializer;
47
- }
48
- else if (name === 'name') {
49
- nameOptionNode = node.initializer;
50
- }
51
- else if (name === 'inheritAttrs') {
52
- inheritAttrsOption = _getNodeText(node.initializer);
53
- }
54
- }
55
- });
56
- componentOptions = {
57
- expression: _getStartEnd(node.expression),
58
- args: _getStartEnd(obj),
59
- argsNode: obj,
60
- components: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
61
- componentsNode: componentsOptionNode,
62
- directives: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
63
- name: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
64
- inheritAttrs: inheritAttrsOption,
65
- };
66
- }
67
22
  }
68
23
  });
69
24
  return {
70
25
  exportDefault,
71
- componentOptions,
72
26
  bindings,
73
27
  components,
74
28
  };
29
+ }
30
+ function parseOptionsFromExtression(ts, exp, sourceFile) {
31
+ let obj;
32
+ while (isAsExpression(ts, exp) || ts.isParenthesizedExpression(exp)) { // fix https://github.com/vuejs/language-tools/issues/1882
33
+ exp = exp.expression;
34
+ }
35
+ if (ts.isObjectLiteralExpression(exp)) {
36
+ obj = exp;
37
+ }
38
+ else if (ts.isCallExpression(exp) && exp.arguments.length) {
39
+ const arg0 = exp.arguments[0];
40
+ if (ts.isObjectLiteralExpression(arg0)) {
41
+ obj = arg0;
42
+ }
43
+ }
44
+ if (obj) {
45
+ let componentsOptionNode;
46
+ let directivesOptionNode;
47
+ let nameOptionNode;
48
+ let inheritAttrsOption;
49
+ ts.forEachChild(obj, node => {
50
+ if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
51
+ const name = _getNodeText(node.name);
52
+ if (name === 'components' && ts.isObjectLiteralExpression(node.initializer)) {
53
+ componentsOptionNode = node.initializer;
54
+ }
55
+ else if (name === 'directives' && ts.isObjectLiteralExpression(node.initializer)) {
56
+ directivesOptionNode = node.initializer;
57
+ }
58
+ else if (name === 'name' && ts.isStringLiteral(node.initializer)) {
59
+ nameOptionNode = node.initializer;
60
+ }
61
+ else if (name === 'inheritAttrs') {
62
+ inheritAttrsOption = _getNodeText(node.initializer);
63
+ }
64
+ }
65
+ });
66
+ return {
67
+ isObjectLiteral: ts.isObjectLiteralExpression(exp),
68
+ expression: _getStartEnd(exp),
69
+ args: _getStartEnd(obj),
70
+ argsNode: obj,
71
+ components: componentsOptionNode ? _getStartEnd(componentsOptionNode) : undefined,
72
+ componentsNode: componentsOptionNode,
73
+ directives: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined,
74
+ name: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined,
75
+ nameNode: nameOptionNode,
76
+ inheritAttrs: inheritAttrsOption,
77
+ };
78
+ }
75
79
  function _getStartEnd(node) {
76
- return (0, shared_1.getStartEnd)(ts, node, ast);
80
+ return (0, shared_1.getStartEnd)(ts, node, sourceFile);
77
81
  }
78
82
  function _getNodeText(node) {
79
- return (0, shared_1.getNodeText)(ts, node, ast);
80
- }
81
- // isAsExpression is missing in tsc
82
- function isAsExpression(node) {
83
- return node.kind === ts.SyntaxKind.AsExpression;
83
+ return (0, shared_1.getNodeText)(ts, node, sourceFile);
84
84
  }
85
85
  }
86
+ // isAsExpression is missing in tsc
87
+ function isAsExpression(ts, node) {
88
+ return node.kind === ts.SyntaxKind.AsExpression;
89
+ }
86
90
  //# sourceMappingURL=scriptRanges.js.map
@@ -1,12 +1,13 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { TextRange, VueCompilerOptions } from '../types';
3
- type CallExpressionRange = {
3
+ export interface CallExpressionRange {
4
4
  callExp: TextRange;
5
5
  exp: TextRange;
6
6
  arg?: TextRange;
7
7
  typeArg?: TextRange;
8
- };
9
- type DefineModel = {
8
+ }
9
+ export interface DefineModel {
10
+ arg?: TextRange;
10
11
  localName?: TextRange;
11
12
  name?: TextRange;
12
13
  type?: TextRange;
@@ -15,44 +16,39 @@ type DefineModel = {
15
16
  defaultValue?: TextRange;
16
17
  required?: boolean;
17
18
  comments?: TextRange;
18
- argNode?: ts.Expression;
19
- };
20
- type DefineProps = CallExpressionRange & {
19
+ }
20
+ export interface DefineProps extends CallExpressionRange {
21
21
  name?: string;
22
22
  destructured?: Map<string, ts.Expression | undefined>;
23
23
  destructuredRest?: string;
24
24
  statement: TextRange;
25
- argNode?: ts.Expression;
26
- };
27
- type WithDefaults = Omit<CallExpressionRange, 'typeArg'> & {
28
- argNode?: ts.Expression;
29
- };
30
- type DefineEmits = CallExpressionRange & {
25
+ }
26
+ export interface DefineEmits extends CallExpressionRange {
31
27
  name?: string;
32
28
  hasUnionTypeArg?: boolean;
33
29
  statement: TextRange;
34
- };
35
- type DefineSlots = CallExpressionRange & {
30
+ }
31
+ export interface DefineSlots extends CallExpressionRange {
36
32
  name?: string;
37
33
  statement: TextRange;
38
- };
39
- type DefineOptions = {
34
+ }
35
+ export interface DefineOptions {
40
36
  name?: string;
41
37
  inheritAttrs?: string;
42
- };
43
- type UseTemplateRef = CallExpressionRange & {
38
+ }
39
+ export interface UseTemplateRef extends CallExpressionRange {
44
40
  name?: string;
45
- };
41
+ }
46
42
  export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> {
47
43
  }
48
- export declare function parseScriptSetupRanges(ts: typeof import('typescript'), ast: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
44
+ export declare function parseScriptSetupRanges(ts: typeof import('typescript'), sourceFile: ts.SourceFile, vueCompilerOptions: VueCompilerOptions): {
49
45
  leadingCommentEndOffset: number;
50
46
  importSectionEndOffset: number;
51
- bindings: TextRange[];
52
- components: TextRange[];
47
+ bindings: TextRange<ts.Node>[];
48
+ components: TextRange<ts.Node>[];
53
49
  defineModel: DefineModel[];
54
50
  defineProps: DefineProps | undefined;
55
- withDefaults: WithDefaults | undefined;
51
+ withDefaults: CallExpressionRange | undefined;
56
52
  defineEmits: DefineEmits | undefined;
57
53
  defineSlots: DefineSlots | undefined;
58
54
  defineExpose: CallExpressionRange | undefined;
@@ -62,4 +58,3 @@ export declare function parseScriptSetupRanges(ts: typeof import('typescript'),
62
58
  useSlots: CallExpressionRange[];
63
59
  useTemplateRef: UseTemplateRef[];
64
60
  };
65
- export {};
@@ -5,7 +5,7 @@ const collectBindings_1 = require("../utils/collectBindings");
5
5
  const shared_1 = require("../utils/shared");
6
6
  const utils_1 = require("./utils");
7
7
  const tsCheckReg = /^\/\/\s*@ts-(?:no)?check(?:$|\s)/;
8
- function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
8
+ function parseScriptSetupRanges(ts, sourceFile, vueCompilerOptions) {
9
9
  const defineModel = [];
10
10
  let defineProps;
11
11
  let withDefaults;
@@ -17,13 +17,13 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
17
17
  const useCssModule = [];
18
18
  const useSlots = [];
19
19
  const useTemplateRef = [];
20
- const text = ast.text;
20
+ const text = sourceFile.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, components } = (0, utils_1.parseBindingRanges)(ts, ast, vueCompilerOptions.extensions);
23
+ let { bindings, components } = (0, utils_1.parseBindingRanges)(ts, sourceFile, vueCompilerOptions.extensions);
24
24
  let foundNonImportExportNode = false;
25
25
  let importSectionEndOffset = 0;
26
- ts.forEachChild(ast, node => {
26
+ ts.forEachChild(sourceFile, node => {
27
27
  if (foundNonImportExportNode
28
28
  || ts.isImportDeclaration(node)
29
29
  || ts.isExportDeclaration(node)
@@ -42,11 +42,11 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
42
42
  importSectionEndOffset = commentRange.pos;
43
43
  }
44
44
  else {
45
- importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, ast).start;
45
+ importSectionEndOffset = (0, shared_1.getStartEnd)(ts, node, sourceFile).start;
46
46
  }
47
47
  foundNonImportExportNode = true;
48
48
  });
49
- ts.forEachChild(ast, node => visitNode(node, [ast]));
49
+ ts.forEachChild(sourceFile, node => visitNode(node, [sourceFile]));
50
50
  const templateRefNames = new Set(useTemplateRef.map(ref => ref.name));
51
51
  bindings = bindings.filter(range => {
52
52
  const name = text.slice(range.start, range.end);
@@ -135,15 +135,14 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
135
135
  runtimeType,
136
136
  defaultValue,
137
137
  required,
138
- comments: (0, utils_1.getClosestMultiLineCommentRange)(ts, node, parents, ast),
139
- argNode: options,
138
+ comments: (0, utils_1.getClosestMultiLineCommentRange)(ts, node, parents, sourceFile),
139
+ arg: _getStartEnd(node),
140
140
  });
141
141
  }
142
142
  else if (vueCompilerOptions.macros.defineProps.includes(callText)) {
143
143
  defineProps = {
144
144
  ...parseCallExpressionAssignment(node, parent),
145
- statement: getStatementRange(ts, parents, node, ast),
146
- argNode: node.arguments[0],
145
+ statement: getStatementRange(ts, parents, node, sourceFile),
147
146
  };
148
147
  if (ts.isVariableDeclaration(parent) && ts.isObjectBindingPattern(parent.name)) {
149
148
  defineProps.destructured = new Map();
@@ -172,13 +171,12 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
172
171
  callExp: _getStartEnd(node),
173
172
  exp: _getStartEnd(node.expression),
174
173
  arg: arg ? _getStartEnd(arg) : undefined,
175
- argNode: arg,
176
174
  };
177
175
  }
178
176
  else if (vueCompilerOptions.macros.defineEmits.includes(callText)) {
179
177
  defineEmits = {
180
178
  ...parseCallExpressionAssignment(node, parent),
181
- statement: getStatementRange(ts, parents, node, ast),
179
+ statement: getStatementRange(ts, parents, node, sourceFile),
182
180
  };
183
181
  if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
184
182
  for (const member of node.typeArguments[0].members) {
@@ -195,7 +193,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
195
193
  else if (vueCompilerOptions.macros.defineSlots.includes(callText)) {
196
194
  defineSlots = {
197
195
  ...parseCallExpressionAssignment(node, parent),
198
- statement: getStatementRange(ts, parents, node, ast),
196
+ statement: getStatementRange(ts, parents, node, sourceFile),
199
197
  };
200
198
  }
201
199
  else if (vueCompilerOptions.macros.defineExpose.includes(callText)) {
@@ -258,10 +256,10 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
258
256
  };
259
257
  }
260
258
  function _getStartEnd(node) {
261
- return (0, shared_1.getStartEnd)(ts, node, ast);
259
+ return (0, shared_1.getStartEnd)(ts, node, sourceFile);
262
260
  }
263
261
  function _getNodeText(node) {
264
- return (0, shared_1.getNodeText)(ts, node, ast);
262
+ return (0, shared_1.getNodeText)(ts, node, sourceFile);
265
263
  }
266
264
  }
267
265
  function getStatementRange(ts, parents, node, ast) {
@@ -1,10 +1,7 @@
1
1
  import type * as ts from 'typescript';
2
2
  import type { TextRange } from '../types';
3
3
  export declare function parseBindingRanges(ts: typeof import('typescript'), ast: ts.SourceFile, componentExtsensions: string[]): {
4
- bindings: TextRange[];
5
- components: TextRange[];
4
+ bindings: TextRange<ts.Node>[];
5
+ components: TextRange<ts.Node>[];
6
6
  };
7
- export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): {
8
- start: number;
9
- end: number;
10
- } | undefined;
7
+ export declare function getClosestMultiLineCommentRange(ts: typeof import('typescript'), node: ts.Node, parents: ts.Node[], ast: ts.SourceFile): TextRange | undefined;