Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Commit 7e4892e

Browse files
authored
Merge pull request #151 from webcomponents/reenable-typescript
Reenable the TypeScript tests with updated compiler output
2 parents 7f4b0c9 + 1d0c47f commit 7e4892e

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

custom-elements.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

custom-elements.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Patch/HTMLElement.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ export default function(internals) {
4848
}
4949

5050
HTMLElement.prototype = Native.HTMLElement.prototype;
51+
// Safari 9 has `writable: false` on the propertyDescriptor
52+
// Make it writable so that TypeScript can patch up the
53+
// constructor in the ES5 compiled code.
54+
Object.defineProperty(HTMLElement.prototype, 'constructor', {
55+
writable: true,
56+
configurable: true,
57+
enumerable: false,
58+
value: HTMLElement
59+
});
5160

5261
return HTMLElement;
5362
})();

tests/js/typescript.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@
88
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
99
*/
1010

11+
/*
12+
Original TypeScript source code used in this test suite:
13+
14+
class XTypescript extends HTMLElement {}
15+
class XTypescript2 extends HTMLElement {}
16+
17+
*/
1118
suite('TypeScript ES5 Output', function() {
1219

1320
customElements.enableFlush = true;
1421

15-
// Fails because the XTypescript constructor does not return the result of
16-
// the super call. See: https://github.com/Microsoft/TypeScript/issues/7574
17-
test.skip('TypeScript generated ES5 works via new()', function() {
18-
var __extends = (this && this.__extends) || function (d, b) {
19-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
20-
function __() { this.constructor = d; }
21-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22-
};
23-
var XTypescript = (function (_super) {
22+
test('TypeScript generated ES5 works via new()', function() {
23+
var __extends = (this && this.__extends) || (function () {
24+
var extendStatics = Object.setPrototypeOf ||
25+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
27+
return function (d, b) {
28+
extendStatics(d, b);
29+
function __() { this.constructor = d; }
30+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31+
};
32+
})();
33+
var XTypescript = /** @class */ (function (_super) {
2434
__extends(XTypescript, _super);
2535
function XTypescript() {
26-
_super.call(this);
36+
return _super !== null && _super.apply(this, arguments) || this;
2737
}
2838
return XTypescript;
2939
}(HTMLElement));
@@ -38,16 +48,21 @@ suite('TypeScript ES5 Output', function() {
3848
assert.instanceOf(e, XTypescript);
3949
});
4050

41-
test.skip('TypeScript generated ES5 works via createElement', function() {
42-
var __extends = (this && this.__extends) || function (d, b) {
43-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
44-
function __() { this.constructor = d; }
45-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
46-
};
47-
var XTypescript2 = (function (_super) {
51+
test('TypeScript generated ES5 works via createElement', function() {
52+
var __extends = (this && this.__extends) || (function () {
53+
var extendStatics = Object.setPrototypeOf ||
54+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
55+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
56+
return function (d, b) {
57+
extendStatics(d, b);
58+
function __() { this.constructor = d; }
59+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
60+
};
61+
})();
62+
var XTypescript2 = /** @class */ (function (_super) {
4863
__extends(XTypescript2, _super);
4964
function XTypescript2() {
50-
_super.call(this);
65+
return _super !== null && _super.apply(this, arguments) || this;
5166
}
5267
return XTypescript2;
5368
}(HTMLElement));

0 commit comments

Comments
 (0)