Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
feat(dom): Convert JS to TypeScript (#4269)
Browse files Browse the repository at this point in the history
Refs #4225
  • Loading branch information
acdvorak authored Jan 19, 2019
1 parent 1600b54 commit 66c8d81
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/material-components-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as base from '@material/base/index.ts';
import * as checkbox from '@material/checkbox/index';
import * as chips from '@material/chips/index';
import * as dialog from '@material/dialog/index';
import * as dom from '@material/dom/index';
import * as dom from '@material/dom/index.ts';
import * as drawer from '@material/drawer/index';
import * as floatingLabel from '@material/floating-label/index';
import * as formField from '@material/form-field/index';
Expand Down
File renamed without changes.
22 changes: 8 additions & 14 deletions packages/mdc-dom/ponyfill.js → packages/mdc-dom/ponyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
* This makes ponyfills safer than traditional polyfills, especially for libraries like MDC.
*/

/**
* @param {!Element} element
* @param {string} selector
* @return {?Element}
*/
function closest(element, selector) {
interface MsElement extends Element {
msMatchesSelector(selector: string): boolean;
}

function closest(element: Element, selector: string): Element | null {
if (element.closest) {
return element.closest(selector);
}
Expand All @@ -46,15 +45,10 @@ function closest(element, selector) {
return null;
}

/**
* @param {!Element} element
* @param {string} selector
* @return {boolean}
*/
function matches(element, selector) {
function matches(element: Element, selector: string): boolean {
const nativeMatches = element.matches
|| element.webkitMatchesSelector
|| element.msMatchesSelector;
|| element.webkitMatchesSelector
|| (element as MsElement).msMatchesSelector;
return nativeMatches.call(element, selector);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/webpack/js-bundle-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class JsBundleFactory {
checkbox: getAbsolutePath('/packages/mdc-checkbox/index.js'),
chips: getAbsolutePath('/packages/mdc-chips/index.js'),
dialog: getAbsolutePath('/packages/mdc-dialog/index.js'),
dom: getAbsolutePath('/packages/mdc-dom/index.js'),
dom: getAbsolutePath('/packages/mdc-dom/index.ts'),
drawer: getAbsolutePath('/packages/mdc-drawer/index.js'),
floatingLabel: getAbsolutePath('/packages/mdc-floating-label/index.js'),
formField: getAbsolutePath('/packages/mdc-form-field/index.js'),
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mdc-dom/ponyfill.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {assert} from 'chai';
import bel from 'bel';
import td from 'testdouble';

import {closest, matches} from '../../../packages/mdc-dom/ponyfill';
import {closest, matches} from '../../../packages/mdc-dom/ponyfill.ts';

suite('MDCDom - ponyfill');

Expand Down

0 comments on commit 66c8d81

Please sign in to comment.