Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add AbstractVirtualNode for linting #1627

Merged
merged 4 commits into from
Jun 12, 2019
Merged

Conversation

straker
Copy link
Contributor

@straker straker commented Jun 10, 2019

Adds a new AbstractVirtualNode class that just throws on all required properties and functions. This ensures anyone who implements a VirtualNode has everything needed to run it through axe.runVirtualRule. I wanted to have it in its own file in the public directory but since the VirtualNode class extends it it needed to be available before declaring the VirtualNode class.

This allows a JSX styled VirtualNode implementation such as:

class VirtualNode extends axe.AbstractVirtualNode {
  constructor(jsxAST, parent) {

    if (jsxAST.type === 'JSXText') {
      this.props = {
        nodeType: 3
      };
      return;
    }

    this.children = [];

    this._attrs = {};
    jsxAST.openingElement.attributes.forEach(attr => {
      this._attrs[attr.name.name] = attr.value.value;
    });

    this.shadowId = undefined;
    this.parent = parent;
    this.props = {
      nodeType: 1,
      nodeName: jsxAST.openingElement.name.name.toLowerCase(),
      id: this._attrs.id,
      type: this._attrs.type
    };
  }

  attr(attrName) {
    return this._attrs[attrName];
  }

  hasAttr(attrName) {
    return !!this._attrs[attrName];
  }

  hasClass(className) {
     // ...
  }
}

NOTE: by throwing in all required properties and functions, any changes that add new properties or functions could potentially break any libraries who have their own VirtualNode implementation which extends the AbstractVirtualNode. Those libraries should be encouraged to pin to specific versions of axe-core in order to not break on new releases to the AbstractVirtualNode class.

Linked issue: #1551

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Has documentation updated, a DU ticket, or requires no documentation change
  • Includes new tests, or was unnecessary
  • Code is reviewed for security by: Stephen

@straker straker requested a review from a team as a code owner June 10, 2019 21:19
axe.d.ts Outdated Show resolved Hide resolved
lib/core/base/virtual-node.js Outdated Show resolved Hide resolved
Copy link
Member

@stephenmathieson stephenmathieson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TS stuff is still incorrect.

Why don't we remove the TypeScript stuff for now so we can cut a 3.3 release and add it back later on in a patch (eg 3.3.1)?

axe.d.ts Outdated Show resolved Hide resolved
axe.d.ts Outdated Show resolved Hide resolved
axe.d.ts Outdated Show resolved Hide resolved
lib/core/base/virtual-node.js Show resolved Hide resolved
@straker straker dismissed stephenmathieson’s stale review June 12, 2019 17:02

Removed tyepscript

@straker straker merged commit a072ed2 into develop Jun 12, 2019
@straker straker deleted the abstractVirtualNode branch June 12, 2019 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants