vue-component-meta 1.2.1 → 1.2.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/out/index.js +48 -34
  2. package/package.json +4 -4
package/out/index.js CHANGED
@@ -40,7 +40,16 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
40
40
  let projectVersion = 0;
41
41
  const scriptSnapshots = new Map();
42
42
  const scriptVersions = new Map();
43
- const _host = Object.assign(Object.assign({}, ts.sys), { getProjectVersion: () => projectVersion.toString(), getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames, getCompilationSettings: () => parsedCommandLine.options, getScriptFileNames: () => fileNames, getProjectReferences: () => parsedCommandLine.projectReferences, getScriptVersion: (fileName) => { var _a, _b; return (_b = (_a = scriptVersions.get(fileName)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''; }, getScriptSnapshot: (fileName) => {
43
+ const _host = {
44
+ ...ts.sys,
45
+ getProjectVersion: () => projectVersion.toString(),
46
+ getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
47
+ useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
48
+ getCompilationSettings: () => parsedCommandLine.options,
49
+ getScriptFileNames: () => fileNames,
50
+ getProjectReferences: () => parsedCommandLine.projectReferences,
51
+ getScriptVersion: (fileName) => scriptVersions.get(fileName)?.toString() ?? '',
52
+ getScriptSnapshot: (fileName) => {
44
53
  if (!scriptSnapshots.has(fileName)) {
45
54
  const fileText = ts.sys.readFile(fileName);
46
55
  if (fileText !== undefined) {
@@ -48,8 +57,13 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
48
57
  }
49
58
  }
50
59
  return scriptSnapshots.get(fileName);
51
- }, getTypeScriptModule: () => ts, getVueCompilationSettings: () => parsedCommandLine.vueOptions });
52
- return Object.assign(Object.assign({}, baseCreate(_host, checkerOptions, globalComponentName, ts)), { updateFile(fileName, text) {
60
+ },
61
+ getTypeScriptModule: () => ts,
62
+ getVueCompilationSettings: () => parsedCommandLine.vueOptions,
63
+ };
64
+ return {
65
+ ...baseCreate(_host, checkerOptions, globalComponentName, ts),
66
+ updateFile(fileName, text) {
53
67
  fileName = fileName.replace(/\\/g, '/');
54
68
  scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
55
69
  scriptVersions.set(fileName, scriptVersions.has(fileName) ? scriptVersions.get(fileName) + 1 : 1);
@@ -69,7 +83,8 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
69
83
  scriptSnapshots.clear();
70
84
  scriptVersions.clear();
71
85
  projectVersion++;
72
- } });
86
+ },
87
+ };
73
88
  }
74
89
  function baseCreate(_host, checkerOptions, globalComponentName, ts) {
75
90
  const globalComponentSnapshot = ts.ScriptSnapshot.fromString('<script setup lang="ts"></script>');
@@ -156,7 +171,6 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
156
171
  return _getExports(program, typeChecker, componentPath).exports.map(e => e.getName());
157
172
  }
158
173
  function getComponentMeta(componentPath, exportName = 'default') {
159
- var _a;
160
174
  const program = tsLs.getProgram();
161
175
  const typeChecker = program.getTypeChecker();
162
176
  const { symbolNode, exports } = _getExports(program, typeChecker, componentPath);
@@ -165,7 +179,7 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
165
179
  throw `Could not find export ${exportName}`;
166
180
  }
167
181
  const componentType = typeChecker.getTypeOfSymbolAtLocation(_export, symbolNode);
168
- const symbolProperties = (_a = componentType.getProperties()) !== null && _a !== void 0 ? _a : [];
182
+ const symbolProperties = componentType.getProperties() ?? [];
169
183
  return {
170
184
  props: getProps(),
171
185
  events: getEvents(),
@@ -173,7 +187,6 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
173
187
  exposed: getExposed(),
174
188
  };
175
189
  function getProps() {
176
- var _a;
177
190
  const $props = symbolProperties.find(prop => prop.escapedName === '$props');
178
191
  const propEventRegex = /^(on[A-Z])/;
179
192
  let result = [];
@@ -194,13 +207,16 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
194
207
  // fill defaults
195
208
  const printer = ts.createPrinter(checkerOptions.printer);
196
209
  const snapshot = host.getScriptSnapshot(componentPath);
197
- const vueSourceFile = (_a = core.virtualFiles.getSource(componentPath)) === null || _a === void 0 ? void 0 : _a.root;
210
+ const vueSourceFile = core.virtualFiles.getSource(componentPath)?.root;
198
211
  const vueDefaults = vueSourceFile && exportName === 'default'
199
212
  ? (vueSourceFile instanceof vue.VueFile ? readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOptions) : {})
200
213
  : {};
201
214
  const tsDefaults = !vueSourceFile ? readTsComponentDefaultProps(componentPath.substring(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
202
215
  snapshot.getText(0, snapshot.getLength()), exportName, printer, ts) : {};
203
- for (const [propName, defaultExp] of Object.entries(Object.assign(Object.assign({}, vueDefaults), tsDefaults))) {
216
+ for (const [propName, defaultExp] of Object.entries({
217
+ ...vueDefaults,
218
+ ...tsDefaults,
219
+ })) {
204
220
  const prop = result.find(p => p.name === propName);
205
221
  if (prop) {
206
222
  prop.default = defaultExp.default;
@@ -253,8 +269,7 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
253
269
  }
254
270
  }
255
271
  function _getExports(program, typeChecker, componentPath) {
256
- var _a;
257
- const sourceFile = program === null || program === void 0 ? void 0 : program.getSourceFile(getMetaFileName(componentPath));
272
+ const sourceFile = program?.getSourceFile(getMetaFileName(componentPath));
258
273
  if (!sourceFile) {
259
274
  throw 'Could not find main source file';
260
275
  }
@@ -265,7 +280,7 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
265
280
  const exportedSymbols = typeChecker.getExportsOfModule(moduleSymbol);
266
281
  let symbolNode;
267
282
  for (const symbol of exportedSymbols) {
268
- const [declaration] = (_a = symbol.getDeclarations()) !== null && _a !== void 0 ? _a : [];
283
+ const [declaration] = symbol.getDeclarations() ?? [];
269
284
  if (ts.isExportAssignment(declaration)) {
270
285
  symbolNode = declaration.expression;
271
286
  }
@@ -286,7 +301,6 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
286
301
  const visited = new Set();
287
302
  ;
288
303
  function shouldIgnore(subtype) {
289
- var _a;
290
304
  const name = typeChecker.typeToString(subtype);
291
305
  if (name === 'any') {
292
306
  return true;
@@ -295,7 +309,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
295
309
  return true;
296
310
  }
297
311
  if (typeof options === 'object') {
298
- for (const item of (_a = options.ignore) !== null && _a !== void 0 ? _a : []) {
312
+ for (const item of options.ignore ?? []) {
299
313
  if (typeof item === 'function') {
300
314
  const result = item(name, subtype, typeChecker);
301
315
  if (typeof result === 'boolean')
@@ -327,7 +341,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
327
341
  type: typeChecker.typeToString(subtype),
328
342
  rawType: rawType ? subtype : undefined,
329
343
  get schema() {
330
- return schema !== null && schema !== void 0 ? schema : (schema = resolveSchema(subtype));
344
+ return schema ??= resolveSchema(subtype);
331
345
  },
332
346
  };
333
347
  }
@@ -340,7 +354,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
340
354
  rawType: rawType ? subtype : undefined,
341
355
  description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
342
356
  get schema() {
343
- return schema !== null && schema !== void 0 ? schema : (schema = resolveSchema(subtype));
357
+ return schema ??= resolveSchema(subtype);
344
358
  },
345
359
  };
346
360
  }
@@ -353,7 +367,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
353
367
  rawType: rawType ? subtype : undefined,
354
368
  description: ts.displayPartsToString(expose.getDocumentationComment(typeChecker)),
355
369
  get schema() {
356
- return schema !== null && schema !== void 0 ? schema : (schema = resolveSchema(subtype));
370
+ return schema ??= resolveSchema(subtype);
357
371
  },
358
372
  };
359
373
  }
@@ -366,7 +380,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
366
380
  rawType: rawType ? subtype : undefined,
367
381
  signature: typeChecker.signatureToString(call),
368
382
  get schema() {
369
- return schema !== null && schema !== void 0 ? schema : (schema = typeChecker.getTypeArguments(subtype).map(resolveSchema));
383
+ return schema ??= typeChecker.getTypeArguments(subtype).map(resolveSchema);
370
384
  },
371
385
  };
372
386
  }
@@ -376,11 +390,11 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
376
390
  kind: 'event',
377
391
  type: typeChecker.signatureToString(signature),
378
392
  get schema() {
379
- return schema !== null && schema !== void 0 ? schema : (schema = signature.parameters.length > 0
393
+ return schema ??= signature.parameters.length > 0
380
394
  ? typeChecker
381
395
  .getTypeArguments(typeChecker.getTypeOfSymbolAtLocation(signature.parameters[0], symbolNode))
382
396
  .map(resolveSchema)
383
- : undefined);
397
+ : undefined;
384
398
  },
385
399
  };
386
400
  }
@@ -396,7 +410,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
396
410
  kind: 'enum',
397
411
  type,
398
412
  get schema() {
399
- return schema !== null && schema !== void 0 ? schema : (schema = subtype.types.map(resolveSchema));
413
+ return schema ??= subtype.types.map(resolveSchema);
400
414
  },
401
415
  };
402
416
  }
@@ -407,7 +421,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
407
421
  kind: 'array',
408
422
  type,
409
423
  get schema() {
410
- return schema !== null && schema !== void 0 ? schema : (schema = typeChecker.getTypeArguments(subtype).map(resolveSchema));
424
+ return schema ??= typeChecker.getTypeArguments(subtype).map(resolveSchema);
411
425
  },
412
426
  };
413
427
  }
@@ -418,7 +432,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
418
432
  kind: 'object',
419
433
  type,
420
434
  get schema() {
421
- return schema !== null && schema !== void 0 ? schema : (schema = subtype.getProperties().map(resolveNestedProperties).reduce(reducer, {}));
435
+ return schema ??= subtype.getProperties().map(resolveNestedProperties).reduce(reducer, {});
422
436
  },
423
437
  };
424
438
  }
@@ -441,10 +455,9 @@ function readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOpt
441
455
  scriptWorker();
442
456
  return result;
443
457
  function scriptSetupWorker() {
444
- var _a;
445
458
  const descriptor = vueSourceFile.sfc;
446
459
  const scriptSetupRanges = descriptor.scriptSetupAst ? vue.parseScriptSetupRanges(ts, descriptor.scriptSetupAst, vueCompilerOptions) : undefined;
447
- if (descriptor.scriptSetup && (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.withDefaultsArg)) {
460
+ if (descriptor.scriptSetup && scriptSetupRanges?.withDefaultsArg) {
448
461
  const defaultsText = descriptor.scriptSetup.content.substring(scriptSetupRanges.withDefaultsArg.start, scriptSetupRanges.withDefaultsArg.end);
449
462
  const ast = ts.createSourceFile('/tmp.' + descriptor.scriptSetup.lang, '(' + defaultsText + ')', ts.ScriptTarget.Latest);
450
463
  const obj = findObjectLiteralExpression(ast);
@@ -453,7 +466,7 @@ function readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOpt
453
466
  if (ts.isPropertyAssignment(prop)) {
454
467
  const name = prop.name.getText(ast);
455
468
  const expNode = resolveDefaultOptionExpression(prop.initializer, ts);
456
- const expText = (_a = printer === null || printer === void 0 ? void 0 : printer.printNode(ts.EmitHint.Expression, expNode, ast)) !== null && _a !== void 0 ? _a : expNode.getText(ast);
469
+ const expText = printer?.printNode(ts.EmitHint.Expression, expNode, ast) ?? expNode.getText(ast);
457
470
  result[name] = {
458
471
  default: expText,
459
472
  };
@@ -461,12 +474,15 @@ function readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOpt
461
474
  }
462
475
  }
463
476
  }
464
- else if (descriptor.scriptSetup && (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.propsRuntimeArg)) {
477
+ else if (descriptor.scriptSetup && scriptSetupRanges?.propsRuntimeArg) {
465
478
  const defaultsText = descriptor.scriptSetup.content.substring(scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end);
466
479
  const ast = ts.createSourceFile('/tmp.' + descriptor.scriptSetup.lang, '(' + defaultsText + ')', ts.ScriptTarget.Latest);
467
480
  const obj = findObjectLiteralExpression(ast);
468
481
  if (obj) {
469
- result = Object.assign(Object.assign({}, result), resolvePropsOption(ast, obj, printer, ts));
482
+ result = {
483
+ ...result,
484
+ ...resolvePropsOption(ast, obj, printer, ts),
485
+ };
470
486
  }
471
487
  }
472
488
  function findObjectLiteralExpression(node) {
@@ -510,9 +526,8 @@ function readTsComponentDefaultProps(lang, tsFileText, exportName, printer, ts)
510
526
  }
511
527
  else {
512
528
  ast.forEachChild(child => {
513
- var _a;
514
529
  if (ts.isVariableStatement(child)
515
- && ((_a = child.modifiers) === null || _a === void 0 ? void 0 : _a.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword))) {
530
+ && child.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ExportKeyword)) {
516
531
  for (const dec of child.declarationList.declarations) {
517
532
  if (dec.name.getText(ast) === exportName) {
518
533
  result = dec.initializer;
@@ -544,7 +559,7 @@ function readTsComponentDefaultProps(lang, tsFileText, exportName, printer, ts)
544
559
  }
545
560
  function getPropsNode() {
546
561
  const options = getComponentOptionsNode();
547
- const props = options === null || options === void 0 ? void 0 : options.properties.find(prop => { var _a; return ((_a = prop.name) === null || _a === void 0 ? void 0 : _a.getText(ast)) === 'props'; });
562
+ const props = options?.properties.find(prop => prop.name?.getText(ast) === 'props');
548
563
  if (props && ts.isPropertyAssignment(props)) {
549
564
  if (ts.isObjectLiteralExpression(props.initializer)) {
550
565
  return props.initializer;
@@ -553,11 +568,10 @@ function readTsComponentDefaultProps(lang, tsFileText, exportName, printer, ts)
553
568
  }
554
569
  }
555
570
  function resolvePropsOption(ast, props, printer, ts) {
556
- var _a, _b;
557
571
  const result = {};
558
572
  for (const prop of props.properties) {
559
573
  if (ts.isPropertyAssignment(prop)) {
560
- const name = (_a = prop.name) === null || _a === void 0 ? void 0 : _a.getText(ast);
574
+ const name = prop.name?.getText(ast);
561
575
  if (ts.isObjectLiteralExpression(prop.initializer)) {
562
576
  const defaultProp = prop.initializer.properties.find(p => ts.isPropertyAssignment(p) && p.name.getText(ast) === 'default');
563
577
  const requiredProp = prop.initializer.properties.find(p => ts.isPropertyAssignment(p) && p.name.getText(ast) === 'required');
@@ -568,7 +582,7 @@ function resolvePropsOption(ast, props, printer, ts) {
568
582
  }
569
583
  if (defaultProp) {
570
584
  const expNode = resolveDefaultOptionExpression(defaultProp.initializer, ts);
571
- const expText = (_b = printer === null || printer === void 0 ? void 0 : printer.printNode(ts.EmitHint.Expression, expNode, ast)) !== null && _b !== void 0 ? _b : expNode.getText(ast);
585
+ const expText = printer?.printNode(ts.EmitHint.Expression, expNode, ast) ?? expNode.getText(ast);
572
586
  result[name].default = expText;
573
587
  }
574
588
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-component-meta",
3
- "version": "1.2.1",
3
+ "version": "1.2.2-alpha.1",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,12 +13,12 @@
13
13
  "directory": "packages/vue-component-meta"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.3.0-alpha.2",
17
- "@volar/vue-language-core": "1.2.1",
16
+ "@volar/language-core": "1.4.0-alpha.1",
17
+ "@volar/vue-language-core": "1.2.2-alpha.1",
18
18
  "typesafe-path": "^0.2.2"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "typescript": "*"
22
22
  },
23
- "gitHead": "b984fa45fbdb96606abf0d211c76b78f0948139e"
23
+ "gitHead": "ec74b353fe44dc521a0e4048a8f4e18bd99a546f"
24
24
  }