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: deprecate axe.imports and upgrade to css-selector-parser 3 #4264

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 28 additions & 2 deletions lib/core/imports/index.js
@@ -1,4 +1,4 @@
import { CssSelectorParser } from 'css-selector-parser';
import { createParser } from 'css-selector-parser';
import doT from '@deque/dot';
import emojiRegexText from 'emoji-regex';
import memoize from 'memoizee';
Expand Down Expand Up @@ -40,10 +40,36 @@ if (window.Uint32Array) {
}
}

/**
* @deprecated
*/
class CSSSelectorParser {
Copy link
Contributor

Choose a reason for hiding this comment

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

This class isn't a 1:1 back compatible wrapper. The return of CssSelectorParser was a class, but the class also had additional functions that were used to configure the parser (registerSelectorPseudos, registerNestingOperators, etc.). In order to fully be back compatible, this class would need to implement those functions and probably then call createParser in the parse function with all the settings the user has set using the configuration functions.

constructor() {
this.parser = createParser({
syntax: {
pseudoClasses: {
definitions: {
Selector: ['is', 'not']
}
},
combinators: ['>'],
attributes: {
operators: ['^=', '$=', '*=', '~=']
}
}
});
}

parse(selector) {
return this.parser.parse(selector);
}
}

/**
* Namespace `axe.imports` which holds required external dependencies
*
* @namespace imports
* @deprecated
* @memberof axe
*/
export { CssSelectorParser, doT, emojiRegexText, memoize, Color as Colorjs };
export { CSSSelectorParser, doT, emojiRegexText, memoize, Color as Colorjs };
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't update the casing of CSS otherwise this is a breaking change

Suggested change
export { CSSSelectorParser, doT, emojiRegexText, memoize, Color as Colorjs };
export { CssSelectorParser, doT, emojiRegexText, memoize, Color as Colorjs };

22 changes: 15 additions & 7 deletions lib/core/utils/css-parser.js
@@ -1,9 +1,17 @@
import { CssSelectorParser } from 'css-selector-parser';
import { createParser } from 'css-selector-parser';

const parser = new CssSelectorParser();
parser.registerSelectorPseudos('not');
parser.registerSelectorPseudos('is');
parser.registerNestingOperators('>');
parser.registerAttrEqualityMods('^', '$', '*', '~');
const parse = createParser({
syntax: {
pseudoClasses: {
definitions: {
Selector: ['is', 'not']
}
},
combinators: ['>'],
attributes: {
operators: ['^=', '$=', '*=', '~=']
}
}
});

export default parser;
export default { parse };
Copy link
Contributor

Choose a reason for hiding this comment

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

This changed the export to a named export so you'll also need to update the import in matches.

28 changes: 19 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -125,7 +125,7 @@
"colorjs.io": "^0.4.3",
"conventional-commits-parser": "^5.0.0",
"core-js": "^3.27.1",
"css-selector-parser": "^1.4.1",
"css-selector-parser": "^3.0.2",
"emoji-regex": "^10.2.1",
"es6-promise": "^4.2.8",
"esbuild": "^0.10.x",
Expand Down