diff --git a/.changeset/poor-ways-film.md b/.changeset/poor-ways-film.md new file mode 100644 index 00000000..c25620fd --- /dev/null +++ b/.changeset/poor-ways-film.md @@ -0,0 +1,12 @@ +--- +"dom-accessibility-api": patch +--- + +Reduce over-transpilation + +Switched from + +- for-of to `.forEach` or basic for loop +- `array.push(...otherArray)` to `push.apply(array, otherArray)` + +This removed a bunch of babel junk that wasn't needed. diff --git a/.eslintrc b/.eslintrc index 3e771d18..85f31798 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,7 +26,18 @@ // own implementation. See https://github.com/eps1lon/dom-accessibility-api/blob/eb868428a31a093aecc531bf2dd17e8547bd0c3b/sources/accessible-name.ts#L33 "property": "getComputedStyle" } - ] + ], + "no-restricted-syntax": [ + "error", + { + "selector": "ForOfStatement", + "message": "for-of assumes iterators which require heavy transpilation for es5. Use ArrayFrom(...).forEach instead." + } + ], + // Babel transpiles array spread assuming iterators. + // If we know we have an array we cann use .apply instead. + // TypeScript will validate that claim. + "prefer-spread": "off" }, "overrides": [ { @@ -48,7 +59,10 @@ // disable previous window.getComputedStyles restriction // perf concerns for this aren't applicable to test // since we specifically want to test them - "no-restricted-properties": "off" + "no-restricted-properties": "off", + // disable previous for-of restriction + // over transpilation isn't a concern for tests + "no-restricted-syntax": "off" } } ] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 734231dd..e77f6ace 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -56,11 +56,34 @@ steps: - script: | npm pack mv dom-accessibility-api-*.tgz dom-accessibility-api.tgz - displayName: "Prepare smoke tests of build" + displayName: "Create tarball" - publish: $(System.DefaultWorkingDirectory)/dom-accessibility-api.tgz + displayName: "Publish tarball" artifact: dom-accessibility-api-node-$(node_version) + - task: DownloadPipelineArtifact@2 + displayName: "Download tarball from master" + inputs: + artifact: dom-accessibility-api-node-$(node_version) + path: $(Agent.TempDirectory)/artifacts-master + source: specific + pipeline: $(System.DefinitionId) + project: $(System.TeamProject) + runVersion: latestFromBranch + runBranch: refs/heads/master + + - script: | + mkdir $(Agent.TempDirectory)/published-previous + mkdir $(Agent.TempDirectory)/published-current + tar xfz $(Agent.TempDirectory)/artifacts-master/dom-accessibility-api.tgz --directory $(Agent.TempDirectory)/published-previous + tar xfz $(System.DefaultWorkingDirectory)/dom-accessibility-api.tgz --directory $(Agent.TempDirectory)/published-current + # --no-index implies --exit-code + # This task is informative only. + # Diffs are almost always expected + git --no-pager diff --color --no-index $(Agent.TempDirectory)/published-previous $(Agent.TempDirectory)/published-current || exit 0 + displayName: "Diff tarballs" + - script: yarn start displayName: "kcd-rollup smoke tests of build" workingDirectory: tests/build/fixtures/kcd-rollup diff --git a/sources/accessible-name.ts b/sources/accessible-name.ts index a9674fd7..ea0b400a 100644 --- a/sources/accessible-name.ts +++ b/sources/accessible-name.ts @@ -183,11 +183,12 @@ function querySelectorAllSubtree( element: Element, selectors: string ): Element[] { - const elements = []; + const elements = ArrayFrom(element.querySelectorAll(selectors)); - for (const root of [element, ...idRefs(element, "aria-owns")]) { - elements.push(...ArrayFrom(root.querySelectorAll(selectors))); - } + idRefs(element, "aria-owns").forEach((root) => { + // babel transpiles this assuming an iterator + elements.push.apply(elements, ArrayFrom(root.querySelectorAll(selectors))); + }); return elements; } @@ -314,7 +315,7 @@ export function computeAccessibleName( const childNodes = ArrayFrom(node.childNodes).concat( idRefs(node, "aria-owns") ); - for (const child of childNodes) { + childNodes.forEach((child) => { const result = computeTextAlternative(child, { isEmbeddedInLabel: context.isEmbeddedInLabel, isReferenced: false, @@ -326,7 +327,7 @@ export function computeAccessibleName( createGetComputedStyle(node, options)(node).getPropertyValue("display"); const separator = display !== "inline" ? " " : ""; accumulatedText += `${separator}${result}`; - } + }); if (isElement(node)) { const pseudoAfter = createGetComputedStyle(node, options)(node, ":after"); @@ -366,7 +367,9 @@ export function computeAccessibleName( // https://w3c.github.io/html-aam/#fieldset-and-legend-elements if (isHTMLFieldSetElement(node)) { consultedNodes.add(node); - for (const child of ArrayFrom(node.childNodes)) { + const children = ArrayFrom(node.childNodes); + for (let i = 0; i < children.length; i += 1) { + const child = children[i]; if (isHTMLLegendElement(child)) { return computeTextAlternative(child, { isEmbeddedInLabel: false,