Skip to content

Commit

Permalink
fix: Ensure certain babel helpers aren't required (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 3, 2021
1 parent 47ac468 commit 0485441
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .changeset/ninety-suits-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"dom-accessibility-api": patch
---

Ensure certain babel helpers aren't required

Source:

```diff
-const [item] = list;
+const item = list[0];
```

Transpiled:

```diff
-var _trim$split = list.trim().split(" "),
-_trim$split2 = _slicedToArray(_trim$split, 1),
-item = _trim$split2[0]
+var item = list[0];
```
10 changes: 6 additions & 4 deletions sources/getRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ function getImplicitRole(element: Element): string | null {
}

function getExplicitRole(element: Element): string | null {
if (element.hasAttribute("role")) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute check
const [explicitRole] = element.getAttribute("role")!.trim().split(" ");
if (explicitRole !== undefined && explicitRole.length > 0) {
const role = element.getAttribute("role");
if (role !== null) {
const explicitRole = role.trim().split(" ")[0];
// String.prototype.split(sep, limit) will always return an array with at least one member
// as long as limit is either undefined or > 0
if (explicitRole.length > 0) {
return explicitRole;
}
}
Expand Down

0 comments on commit 0485441

Please sign in to comment.