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

Commit

Permalink
Merge pull request #151 from webcomponents/reenable-typescript
Browse files Browse the repository at this point in the history
Reenable the TypeScript tests with updated compiler output
  • Loading branch information
dfreedm authored May 22, 2018
2 parents 7f4b0c9 + 1d0c47f commit 7e4892e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion custom-elements.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion custom-elements.min.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/Patch/HTMLElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export default function(internals) {
}

HTMLElement.prototype = Native.HTMLElement.prototype;
// Safari 9 has `writable: false` on the propertyDescriptor
// Make it writable so that TypeScript can patch up the
// constructor in the ES5 compiled code.
Object.defineProperty(HTMLElement.prototype, 'constructor', {
writable: true,
configurable: true,
enumerable: false,
value: HTMLElement
});

return HTMLElement;
})();
Expand Down
51 changes: 33 additions & 18 deletions tests/js/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

/*
Original TypeScript source code used in this test suite:
class XTypescript extends HTMLElement {}
class XTypescript2 extends HTMLElement {}
*/
suite('TypeScript ES5 Output', function() {

customElements.enableFlush = true;

// Fails because the XTypescript constructor does not return the result of
// the super call. See: https://github.com/Microsoft/TypeScript/issues/7574
test.skip('TypeScript generated ES5 works via new()', function() {
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var XTypescript = (function (_super) {
test('TypeScript generated ES5 works via new()', function() {
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var XTypescript = /** @class */ (function (_super) {
__extends(XTypescript, _super);
function XTypescript() {
_super.call(this);
return _super !== null && _super.apply(this, arguments) || this;
}
return XTypescript;
}(HTMLElement));
Expand All @@ -38,16 +48,21 @@ suite('TypeScript ES5 Output', function() {
assert.instanceOf(e, XTypescript);
});

test.skip('TypeScript generated ES5 works via createElement', function() {
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var XTypescript2 = (function (_super) {
test('TypeScript generated ES5 works via createElement', function() {
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var XTypescript2 = /** @class */ (function (_super) {
__extends(XTypescript2, _super);
function XTypescript2() {
_super.call(this);
return _super !== null && _super.apply(this, arguments) || this;
}
return XTypescript2;
}(HTMLElement));
Expand Down

0 comments on commit 7e4892e

Please sign in to comment.