• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Haixing-Hu / vue3-class-component / 7c8a3f3e-046f-4ced-b630-a0c6636a0ccb

09 Jun 2025 08:22AM UTC coverage: 100.0%. Remained the same
7c8a3f3e-046f-4ced-b630-a0c6636a0ccb

push

circleci

Haixing-Hu
chore: update yarn.lock after dependency changes

151 of 151 branches covered (100.0%)

Branch coverage included in aggregate %.

222 of 222 relevant lines covered (100.0%)

19.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/impl/collect-method.js
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
//    Copyright (c) 2022 - 2024.
4
//    Haixing Hu, Qubit Co. Ltd.
5
//
6
//    All rights reserved.
7
//
8
////////////////////////////////////////////////////////////////////////////////
9
import { VUE_LIFECYCLE_HOOKS, VUE_SPECIAL_FUNCTIONS } from './vue-options-api';
10

11
/**
12
 * Collects a class method or setter/getter and modify the existing Vue component
13
 * options object.
14
 *
15
 * @param obj
16
 *     the object, which usually be the prototype of a class or a instance of
17
 *     a class.
18
 * @param key
19
 *     the name of the method or setter/getter.
20
 * @param options
21
 *     the Vue component options object.
22
 * @private
23
 * @author Haixing Hu
24
 */
25
function collectMethod(obj, key, options) {
26
  if (key === 'constructor') {
119✔
27
    return;
43✔
28
  }
29
  if (VUE_LIFECYCLE_HOOKS.includes(key) || VUE_SPECIAL_FUNCTIONS.includes(key)) {
76✔
30
    if (typeof obj[key] !== 'function') {
14✔
31
      throw new Error(`The property "${key}" of the class must be a Vue component function.`);
1✔
32
    }
33
    options[key] = obj[key];
13✔
34
  } else {
35
    const descriptor = Object.getOwnPropertyDescriptor(obj, key);
62✔
36
    if (typeof descriptor.value === 'function') { // deal with class methods
62✔
37
      options.methods[key] = descriptor.value;
50✔
38
    } else if (descriptor.value === undefined) {  // deal with computed properties
12✔
39
      options.computed[key] = {
11✔
40
        get: descriptor.get,
41
        set: descriptor.set,
42
      };
43
    } else {                                      // deal with class fields
44
      options.fields[key] = descriptor.value;
1✔
45
    }
46
  }
47
}
48

49
export default collectMethod;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc