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

IgniteUI / igniteui-cli / 10055681579

23 Jul 2024 08:42AM UTC coverage: 70.793% (+4.0%) from 66.802%
10055681579

push

github

web-flow
Merge pull request #1243 from IgniteUI/bpenkov/angular-ts-file-update

Add an AngularTypeScriptFileUpdate

1135 of 1677 branches covered (67.68%)

Branch coverage included in aggregate %.

348 of 415 new or added lines in 19 files covered. (83.86%)

76 existing lines in 39 files now uncovered.

4687 of 6547 relevant lines covered (71.59%)

170.47 hits per line

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

34.62
/packages/core/typescript/TypeScriptExpressionCollector.ts
1
import * as ts from 'typescript';
12✔
2

3
export class TypeScriptExpressionCollector {
12✔
4
  /**
5
   * Collects unique expressions from a list of expressions.
6
   * @param expressions List of expressions to collect unique expressions from.
7
   */
8
  public collectUniqueExpressions(
9
    expressions: ts.Expression[]
10
  ): ts.Expression[] {
11
    const uniqueExpressions: ts.Expression[] = [];
40✔
12
    for (const expr of expressions) {
40✔
13
      let isUnique = true;
98✔
14
      for (const uniqueExpr of uniqueExpressions) {
98✔
15
        if (this.compareExpressions(expr, uniqueExpr)) {
78✔
16
          isUnique = false;
12✔
17
          break;
12✔
18
        }
19
      }
20
      if (isUnique) {
98✔
21
        uniqueExpressions.push(expr);
86✔
22
      }
23
    }
24

25
    return uniqueExpressions;
40✔
26
  }
27

28
  /**
29
   * Compares two `ts.Expression` objects for equality.
30
   */
31
  private compareExpressions(
32
    expr1: ts.Expression,
33
    expr2: ts.Expression
34
  ): boolean {
35
    if (
78✔
36
      ts.isObjectLiteralExpression(expr1) &&
80✔
37
      ts.isObjectLiteralExpression(expr2)
38
    ) {
39
      return this.compareObjectLiterals(expr1, expr2);
2✔
40
    } else if (
76!
41
      ts.isArrayLiteralExpression(expr1) &&
76!
42
      ts.isArrayLiteralExpression(expr2)
43
    ) {
NEW
44
      return this.compareArrayLiterals(expr1, expr2);
×
45
    } else if (ts.isLiteralExpression(expr1) && ts.isLiteralExpression(expr2)) {
76!
NEW
46
      return expr1.text === expr2.text;
×
47
    } else if (ts.isIdentifier(expr1) && ts.isIdentifier(expr2)) {
76!
48
      return expr1.text === expr2.text;
76✔
49
    }
NEW
50
    return false;
×
51
  }
52

53
  /**
54
   * Compares two `ts.ObjectLiteralExpression` objects for equality.
55
   */
56
  private compareObjectLiterals(
57
    obj1: ts.ObjectLiteralExpression,
58
    obj2: ts.ObjectLiteralExpression
59
  ): boolean {
60
    if (obj1.properties.length !== obj2.properties.length) {
2!
61
      return false;
2✔
62
    }
63

NEW
64
    const namesComparer = (
×
65
      a: ts.ObjectLiteralElementLike,
66
      b: ts.ObjectLiteralElementLike
67
    ) =>
NEW
68
      ts.isIdentifier(a.name) &&
×
69
      ts.isIdentifier(b.name) &&
70
      a.name.text.localeCompare(b.name.text);
NEW
71
    const sortedProps1 = obj1.properties.slice().sort(namesComparer);
×
NEW
72
    const sortedProps2 = obj2.properties.slice().sort(namesComparer);
×
73

NEW
74
    for (let i = 0; i < sortedProps1.length; i++) {
×
NEW
75
      const prop1 = sortedProps1[i];
×
NEW
76
      const prop2 = sortedProps2[i];
×
77

78
      // compare prop names
NEW
79
      if (
×
80
        ts.isIdentifier(prop1.name) &&
×
81
        ts.isIdentifier(prop2.name) &&
82
        prop1.name.text !== prop2.name.text
83
      ) {
NEW
84
        return false;
×
85
      }
86

87
      // compare prop values, only consider literal expressions and identifiers for the moment (alt: use lodash?)
NEW
88
      if (
×
89
        ts.isPropertyAssignment(prop1) &&
×
90
        ts.isPropertyAssignment(prop2) &&
91
        (!ts.isLiteralExpression(prop1.initializer) ||
92
          !ts.isLiteralExpression(prop2.initializer))
93
      ) {
NEW
94
        return false;
×
95
      }
96

NEW
97
      if (
×
98
        ts.isPropertyAssignment(prop1) &&
×
99
        ts.isPropertyAssignment(prop2) &&
100
        ts.isIdentifier(prop1.initializer) &&
101
        ts.isIdentifier(prop2.initializer) &&
102
        prop1.initializer.text !== prop2.initializer.text
103
      ) {
NEW
104
        return false;
×
105
      }
106
    }
107

NEW
108
    return true;
×
109
  }
110

111
  /**
112
   * Compares two `ts.ArrayLiteralExpression` objects for equality.
113
   */
114
  private compareArrayLiterals(
115
    arr1: ts.ArrayLiteralExpression,
116
    arr2: ts.ArrayLiteralExpression
117
  ): boolean {
NEW
118
    if (arr1.elements.length !== arr2.elements.length) {
×
NEW
119
      return false;
×
120
    }
121

NEW
122
    for (let i = 0; i < arr1.elements.length; i++) {
×
NEW
123
      const elem1 = arr1.elements[i];
×
NEW
124
      const elem2 = arr2.elements[i];
×
NEW
125
      if (
×
126
        ts.isObjectLiteralExpression(elem1) &&
×
127
        ts.isObjectLiteralExpression(elem2)
128
      ) {
NEW
129
        return this.compareObjectLiterals(elem1, elem2);
×
NEW
130
      } else if (
×
131
        ts.isLiteralExpression(elem1) &&
×
132
        ts.isLiteralExpression(elem2)
133
      ) {
NEW
134
        if (elem1.text !== elem2.text) {
×
NEW
135
          return false;
×
136
        }
137
      } else {
NEW
138
        return false;
×
139
      }
140
    }
141

NEW
142
    return true;
×
143
  }
144
}
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

© 2025 Coveralls, Inc