Skip to content

Commit 8d824a3

Browse files
authored
Merge pull request #525 from webcomponents/update-typescript
Update TypeScript and upstream internal changes.
2 parents d5a4a80 + 2d60e37 commit 8d824a3

File tree

11 files changed

+951
-618
lines changed

11 files changed

+951
-618
lines changed

package-lock.json

Lines changed: 907 additions & 581 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
},
2121
"devDependencies": {
2222
"@gulp-sourcemaps/sources-content": "^1.0.0",
23-
"@typescript-eslint/eslint-plugin": "^4.14.0",
24-
"@typescript-eslint/parser": "^4.14.0",
23+
"@typescript-eslint/eslint-plugin": "^5.37.0",
24+
"@typescript-eslint/parser": "^5.37.0",
2525
"babel-core": "^6.26.3",
2626
"chokidar-cli": "^2.1.0",
2727
"del": "^3.0.0",
28-
"eslint": "^7.18.0",
29-
"eslint-plugin-html": "^6.1.1",
28+
"eslint": "^8.23.1",
29+
"eslint-plugin-html": "^7.1.0",
3030
"google-closure-compiler": "^20210202.0.0",
3131
"gulp": "^4.0.0",
3232
"gulp-babel": "^7.0.1",
@@ -44,7 +44,7 @@
4444
"rollup-plugin-babel": "^3.0.7",
4545
"rollup-plugin-commonjs": "^9.2.0",
4646
"rollup-plugin-license": "^0.8.1",
47-
"typescript": "^4.0.3",
47+
"typescript": "^4.8.3",
4848
"wct-browser-legacy": "^1.0.2",
4949
"web-component-tester": "^6.9.2"
5050
},

packages/custom-elements/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## Unreleased
1111

1212
- Don't write to window.CustomElementsRegistry unless we're also writing to window.customElements. ([#524](https://github.com/webcomponents/polyfills/pull/524))
13+
- Update TypeScript and upstream internal changes.
14+
([#525](https://github.com/webcomponents/polyfills/pull/525))
1315

1416
## [1.5.0] - 2021-08-02
1517

packages/custom-elements/ts_src/CustomElementInternals.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export default class CustomElementInternals {
280280
if (definition) {
281281
this._upgradeAnElement(element, definition);
282282
}
283-
} catch (e) {
283+
} catch (e: unknown) {
284284
this.reportTheException(e);
285285
}
286286
}
@@ -340,7 +340,7 @@ export default class CustomElementInternals {
340340
if (definition.connectedCallback) {
341341
try {
342342
definition.connectedCallback.call(element);
343-
} catch (e) {
343+
} catch (e: unknown) {
344344
this.reportTheException(e);
345345
}
346346
}
@@ -351,7 +351,7 @@ export default class CustomElementInternals {
351351
if (definition.disconnectedCallback) {
352352
try {
353353
definition.disconnectedCallback.call(element);
354-
} catch (e) {
354+
} catch (e: unknown) {
355355
this.reportTheException(e);
356356
}
357357
}
@@ -377,7 +377,7 @@ export default class CustomElementInternals {
377377
newValue,
378378
namespace
379379
);
380-
} catch (e) {
380+
} catch (e: unknown) {
381381
this.reportTheException(e);
382382
}
383383
}
@@ -413,9 +413,7 @@ export default class CustomElementInternals {
413413
return;
414414
}
415415

416-
return (registry as CustomElementRegistry).internal_localNameToDefinition(
417-
localName
418-
);
416+
return registry.internal_localNameToDefinition(localName);
419417
}
420418

421419
/**
@@ -436,7 +434,7 @@ export default class CustomElementInternals {
436434
// Only create custom elements if the document is associated with a
437435
// registry.
438436
if (registry && (namespace === null || namespace === NS_HTML)) {
439-
const definition = (registry as CustomElementRegistry).internal_localNameToDefinition(
437+
const definition = ((registry as unknown) as CustomElementRegistry).internal_localNameToDefinition(
440438
localName
441439
);
442440
if (definition) {
@@ -507,7 +505,7 @@ export default class CustomElementInternals {
507505
}
508506

509507
return result;
510-
} catch (e) {
508+
} catch (e: unknown) {
511509
this.reportTheException(e);
512510

513511
// When construction fails, a new HTMLUnknownElement is produced.
@@ -539,7 +537,7 @@ export default class CustomElementInternals {
539537
*
540538
* @see https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception
541539
*/
542-
reportTheException(errorArg: Error) {
540+
reportTheException(arg: unknown) {
543541
interface ExtendedError extends Error {
544542
// Non-standard Safari properties.
545543
sourceURL?: string;
@@ -552,11 +550,20 @@ export default class CustomElementInternals {
552550
columnNumber?: number;
553551
}
554552

555-
const error = errorArg as ExtendedError;
556-
const message = error.message;
557-
const filename = error.sourceURL || error.fileName || '';
558-
const lineno = error.line || error.lineNumber || 0;
559-
const colno = error.column || error.columnNumber || 0;
553+
let message = '';
554+
let filename = '';
555+
let lineno = 0;
556+
let colno = 0;
557+
558+
if (arg instanceof Error) {
559+
const error = arg as ExtendedError;
560+
message = error.message;
561+
filename = error.sourceURL || error.fileName || '';
562+
lineno = error.line || error.lineNumber || 0;
563+
colno = error.column || error.columnNumber || 0;
564+
} else {
565+
message = `Uncaught ${String(arg)}`;
566+
}
560567

561568
let event: ErrorEvent | undefined = undefined;
562569
if (ErrorEvent.prototype.initErrorEvent === undefined) {
@@ -566,7 +573,7 @@ export default class CustomElementInternals {
566573
filename,
567574
lineno,
568575
colno,
569-
error,
576+
error: arg,
570577
});
571578
} else {
572579
event = document.createEvent('ErrorEvent') as ErrorEvent;
@@ -589,7 +596,7 @@ export default class CustomElementInternals {
589596
configurable: true,
590597
enumerable: true,
591598
get: function () {
592-
return error;
599+
return arg;
593600
},
594601
});
595602
}
@@ -600,7 +607,7 @@ export default class CustomElementInternals {
600607
// console if their associated ErrorEvent isn't handled during dispatch
601608
// (indicated by calling `preventDefault`). In practice, these errors are
602609
// always displayed.
603-
console.error(error);
610+
console.error(arg);
604611
}
605612
}
606613
}

packages/custom-elements/ts_src/CustomElementRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export default class CustomElementRegistry {
335335
this._localNameToConstructorGetter.delete(localName);
336336
try {
337337
return this.internal_reifyDefinition(localName, constructorGetter());
338-
} catch (e) {
338+
} catch (e: unknown) {
339339
this._internals.reportTheException(e);
340340
}
341341
}

packages/custom-elements/ts_src/Patch/HTMLElement.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import AlreadyConstructedMarker from '../AlreadyConstructedMarker.js';
1313
import CustomElementInternals from '../CustomElementInternals.js';
14-
import CustomElementRegistry from '../CustomElementRegistry.js';
1514
import CEState from '../CustomElementState.js';
1615
import * as Native from './Native.js';
1716

@@ -25,9 +24,7 @@ export default function (internals: CustomElementInternals) {
2524

2625
// Always look up the definition from the global registry.
2726
const registry = document.__CE_registry!;
28-
const definition = (registry as CustomElementRegistry).internal_constructorToDefinition(
29-
constructor
30-
);
27+
const definition = registry.internal_constructorToDefinition(constructor);
3128
if (!definition) {
3229
throw new Error(
3330
'Failed to construct a custom element: ' +

packages/custom-elements/ts_src/env.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
* rights grant found at http://polymer.github.io/PATENTS.txt
1010
*/
1111

12-
// When building externally, this file is always assumed to be a module, but by
13-
// default it isn't when building internally, so we need this export statement.
14-
export {};
12+
import CustomElementRegistry from './CustomElementRegistry.js';
1513

1614
declare global {
1715
interface AlreadyConstructedMarkerType {

packages/formdata-event/ts_src/environment/event.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
* additional IP rights grant found at http://polymer.github.io/PATENTS.txt
1010
*/
1111

12-
export const constructor = window.Event;
12+
// Without this explicit type, TS seems to think that `window.Event` is the
13+
// wrapper from `wrappers/event.ts` at this point, which is typed in terms of
14+
// this binding, causing a cycle in its type.
15+
export const constructor: typeof Event = window.Event;
1316

1417
export const prototype = constructor.prototype;
1518

packages/formdata-event/ts_src/wrappers/event.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export const getEventPropagationImmediatelyStopped = (e: Event) => {
3737
// const s = new SpecialEvent("type");
3838
// console.assert(s instanceof SpecialEvent); // fails in Safari 13.1
3939
// ```
40-
export const Event: typeof window.Event = (function Event(
40+
export const Event: typeof EventConstructor = (function Event(
4141
this: Event,
4242
type: string,
4343
eventInit: EventInit = {}
44-
) {
44+
): Event {
4545
let _this;
4646
// When running in a browser where Event isn't constructible (e.g. IE11) this
4747
// throws and we fall back to the old `createEvent` API.
@@ -53,7 +53,7 @@ export const Event: typeof window.Event = (function Event(
5353
}
5454
Object.setPrototypeOf(_this, Object.getPrototypeOf(this));
5555
return _this;
56-
} as Function) as typeof window.Event;
56+
} as unknown) as typeof EventConstructor;
5757

5858
prepareWrapper(Event, EventConstructor, EventPrototype);
5959

packages/webcomponentsjs/ts_src/platform/custom-event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if (!window.Event || (isIE && typeof window.Event !== 'function')) {
6060

6161
// CustomEvent constructor shim
6262
if (!window.CustomEvent || (isIE && typeof window.CustomEvent !== 'function')) {
63-
window['CustomEvent'] = ((<T extends unknown>(
63+
window['CustomEvent'] = ((<T>(
6464
inType: string,
6565
params?: CustomEventInit<T>
6666
) => {

0 commit comments

Comments
 (0)