|
7 | 7 | */
|
8 | 8 | import { tags } from '@angular-devkit/core';
|
9 | 9 | import { transformJavascript } from '../helpers/transform-javascript';
|
10 |
| -import { getPrefixClassesTransformer, testPrefixClasses } from './prefix-classes'; |
| 10 | +import { getPrefixClassesTransformer } from './prefix-classes'; |
11 | 11 |
|
12 | 12 |
|
13 | 13 | const transform = (content: string) => transformJavascript(
|
14 | 14 | { content, getTransforms: [getPrefixClassesTransformer] }).content;
|
15 | 15 |
|
16 | 16 | describe('prefix-classes', () => {
|
17 |
| - it('prefix downleveled classes with /*@__PURE__*/', () => { |
| 17 | + it('prefix TS 2.0 - 2.4 downlevel class', () => { |
18 | 18 | const input = tags.stripIndent`
|
19 |
| - var ReplayEvent = (function () { |
20 |
| - function ReplayEvent(time, value) { |
21 |
| - this.time = time; |
22 |
| - this.value = value; |
23 |
| - } |
24 |
| - return ReplayEvent; |
| 19 | + var BasicTestCase = (function () { |
| 20 | + function BasicTestCase() { |
| 21 | + } |
| 22 | + return BasicTestCase; |
25 | 23 | }());
|
26 | 24 | `;
|
27 | 25 | const output = tags.stripIndent`
|
28 |
| - var ReplayEvent = /*@__PURE__*/ (function () { |
29 |
| - function ReplayEvent(time, value) { |
30 |
| - this.time = time; |
31 |
| - this.value = value; |
32 |
| - } |
33 |
| - return ReplayEvent; |
| 26 | + var BasicTestCase = /*@__PURE__*/ (function () { |
| 27 | + function BasicTestCase() { |
| 28 | + } |
| 29 | + return BasicTestCase; |
34 | 30 | }());
|
35 | 31 | `;
|
36 | 32 |
|
37 |
| - expect(testPrefixClasses(input)).toBeTruthy(); |
38 | 33 | expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
|
39 | 34 | });
|
40 | 35 |
|
41 |
| - // tslint:disable:max-line-length |
42 |
| - it('prefix downleveled classes that extend another class with /*@__PURE__*/', () => { |
| 36 | + // NOTE: TS 2.1+ uses a standalone export after the variable statement |
| 37 | + it('prefix TS 2.0 exported downlevel class with ES2015 modules', () => { |
43 | 38 | const input = tags.stripIndent`
|
44 |
| - var TakeUntilSubscriber = (function (_super) { |
45 |
| - __extends(TakeUntilSubscriber, _super); |
46 |
| - function TakeUntilSubscriber(destination, notifier) { |
47 |
| - _super.call(this, destination); |
48 |
| - this.notifier = notifier; |
49 |
| - this.add(subscribeToResult_1.subscribeToResult(this, notifier)); |
50 |
| - } |
51 |
| - TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { |
52 |
| - this.complete(); |
53 |
| - }; |
54 |
| - TakeUntilSubscriber.prototype.notifyComplete = function () { |
55 |
| - // noop |
56 |
| - }; |
57 |
| - return TakeUntilSubscriber; |
58 |
| - }(OuterSubscriber_1.OuterSubscriber)); |
| 39 | + export var OuterSubscriber = (function (_super) { |
| 40 | + __extends(OuterSubscriber, _super); |
| 41 | + function OuterSubscriber() { |
| 42 | + _super.apply(this, arguments); |
| 43 | + } |
| 44 | + return OuterSubscriber; |
| 45 | + }()); |
| 46 | + `; |
| 47 | + const output = tags.stripIndent` |
| 48 | + export var OuterSubscriber = /*@__PURE__*/ (function (_super) { |
| 49 | + __extends(OuterSubscriber, _super); |
| 50 | + function OuterSubscriber() { |
| 51 | + _super.apply(this, arguments); |
| 52 | + } |
| 53 | + return OuterSubscriber; |
| 54 | + }()); |
| 55 | + `; |
| 56 | + |
| 57 | + expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`); |
| 58 | + }); |
| 59 | + |
| 60 | + it('prefix TS 2.0 downlevel class with extends', () => { |
| 61 | + const input = tags.stripIndent` |
| 62 | + var ExtendedClass = (function (_super) { |
| 63 | + __extends(ExtendedClass, _super); |
| 64 | + function ExtendedClass() { |
| 65 | + _super.apply(this, arguments); |
| 66 | + } |
| 67 | + return ExtendedClass; |
| 68 | + }(StaticTestCase)); |
59 | 69 | `;
|
60 | 70 | const output = tags.stripIndent`
|
61 |
| - var TakeUntilSubscriber = /*@__PURE__*/ (function (_super) { |
62 |
| - __extends(TakeUntilSubscriber, _super); |
63 |
| - function TakeUntilSubscriber(destination, notifier) { |
64 |
| - _super.call(this, destination); |
65 |
| - this.notifier = notifier; |
66 |
| - this.add(subscribeToResult_1.subscribeToResult(this, notifier)); |
67 |
| - } |
68 |
| - TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { |
69 |
| - this.complete(); |
70 |
| - }; |
71 |
| - TakeUntilSubscriber.prototype.notifyComplete = function () { |
72 |
| - // noop |
73 |
| - }; |
74 |
| - return TakeUntilSubscriber; |
75 |
| - }(OuterSubscriber_1.OuterSubscriber)); |
76 |
| - `; |
77 |
| - |
78 |
| - expect(testPrefixClasses(input)).toBeTruthy(); |
| 71 | + var ExtendedClass = /*@__PURE__*/ (function (_super) { |
| 72 | + __extends(ExtendedClass, _super); |
| 73 | + function ExtendedClass() { |
| 74 | + _super.apply(this, arguments); |
| 75 | + } |
| 76 | + return ExtendedClass; |
| 77 | + }(StaticTestCase)); |
| 78 | + `; |
| 79 | + |
79 | 80 | expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
|
80 | 81 | });
|
81 |
| - // tslint:enable:max-line-length |
| 82 | + |
| 83 | + it('prefix TS 2.1 - 2.3 downlevel class with static variable', () => { |
| 84 | + const input = tags.stripIndent` |
| 85 | + var StaticTestCase = (function () { |
| 86 | + function StaticTestCase() { |
| 87 | + } |
| 88 | + return StaticTestCase; |
| 89 | + }()); |
| 90 | + StaticTestCase.StaticTest = true; |
| 91 | + `; |
| 92 | + const output = tags.stripIndent` |
| 93 | + var StaticTestCase = /*@__PURE__*/ (function () { |
| 94 | + function StaticTestCase() { |
| 95 | + } |
| 96 | + return StaticTestCase; |
| 97 | + }()); |
| 98 | + StaticTestCase.StaticTest = true; |
| 99 | + `; |
| 100 | + |
| 101 | + expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`); |
| 102 | + }); |
| 103 | + |
| 104 | + it('prefix TS 2.1 - 2.4 downlevel class with extends', () => { |
| 105 | + const input = tags.stripIndent` |
| 106 | + var ExtendedClass = (function (_super) { |
| 107 | + __extends(ExtendedClass, _super); |
| 108 | + function ExtendedClass() { |
| 109 | + return _super !== null && _super.apply(this, arguments) || this; |
| 110 | + } |
| 111 | + return ExtendedClass; |
| 112 | + }(StaticTestCase)); |
| 113 | + `; |
| 114 | + const output = tags.stripIndent` |
| 115 | + var ExtendedClass = /*@__PURE__*/ (function (_super) { |
| 116 | + __extends(ExtendedClass, _super); |
| 117 | + function ExtendedClass() { |
| 118 | + return _super !== null && _super.apply(this, arguments) || this; |
| 119 | + } |
| 120 | + return ExtendedClass; |
| 121 | + }(StaticTestCase)); |
| 122 | + `; |
| 123 | + |
| 124 | + expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`); |
| 125 | + }); |
| 126 | + |
| 127 | + it('prefix TS 2.0 & 2.4 downlevel class with static variable', () => { |
| 128 | + const input = tags.stripIndent` |
| 129 | + var StaticTestCase = (function () { |
| 130 | + function StaticTestCase() { |
| 131 | + } |
| 132 | + StaticTestCase.StaticTest = true; |
| 133 | + return StaticTestCase; |
| 134 | + }()); |
| 135 | + `; |
| 136 | + const output = tags.stripIndent` |
| 137 | + var StaticTestCase = /*@__PURE__*/ (function () { |
| 138 | + function StaticTestCase() { |
| 139 | + } |
| 140 | + StaticTestCase.StaticTest = true; |
| 141 | + return StaticTestCase; |
| 142 | + }()); |
| 143 | + `; |
| 144 | + |
| 145 | + expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`); |
| 146 | + }); |
| 147 | + |
| 148 | + it('prefix TS 2.5 downlevel class', () => { |
| 149 | + const input = tags.stripIndent` |
| 150 | + var BasicTestCase = /** @class */ (function () { |
| 151 | + function BasicTestCase() { |
| 152 | + } |
| 153 | + return BasicTestCase; |
| 154 | + }()); |
| 155 | + `; |
| 156 | + const output = tags.stripIndent` |
| 157 | + var BasicTestCase = /*@__PURE__*/ (function () { |
| 158 | + function BasicTestCase() { |
| 159 | + } |
| 160 | + return BasicTestCase; |
| 161 | + }()); |
| 162 | + `; |
| 163 | + |
| 164 | + expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`); |
| 165 | + }); |
| 166 | + |
| 167 | + it('prefix TS 2.5 downlevel class with static variable', () => { |
| 168 | + const input = tags.stripIndent` |
| 169 | + var StaticTestCase = /** @class */ (function () { |
| 170 | + function StaticTestCase() { |
| 171 | + } |
| 172 | + StaticTestCase.StaticTest = true; |
| 173 | + return StaticTestCase; |
| 174 | + }()); |
| 175 | + `; |
| 176 | + const output = tags.stripIndent` |
| 177 | + var StaticTestCase = /*@__PURE__*/ (function () { |
| 178 | + function StaticTestCase() { |
| 179 | + } |
| 180 | + StaticTestCase.StaticTest = true; |
| 181 | + return StaticTestCase; |
| 182 | + }()); |
| 183 | + `; |
| 184 | + |
| 185 | + expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`); |
| 186 | + }); |
| 187 | + |
| 188 | + it('prefix TS 2.5 downlevel class with extends', () => { |
| 189 | + const input = tags.stripIndent` |
| 190 | + var ExtendedClass = /** @class */ (function (_super) { |
| 191 | + __extends(ExtendedClass, _super); |
| 192 | + function ExtendedClass() { |
| 193 | + return _super !== null && _super.apply(this, arguments) || this; |
| 194 | + } |
| 195 | + return ExtendedClass; |
| 196 | + }(StaticTestCase)); |
| 197 | + `; |
| 198 | + const output = tags.stripIndent` |
| 199 | + var ExtendedClass = /*@__PURE__*/ (function (_super) { |
| 200 | + __extends(ExtendedClass, _super); |
| 201 | + function ExtendedClass() { |
| 202 | + return _super !== null && _super.apply(this, arguments) || this; |
| 203 | + } |
| 204 | + return ExtendedClass; |
| 205 | + }(StaticTestCase)); |
| 206 | + `; |
| 207 | + |
| 208 | + expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`); |
| 209 | + }); |
| 210 | + |
82 | 211 | });
|
0 commit comments