Skip to content

Commit

Permalink
cast selectors to strings (#1567)
Browse files Browse the repository at this point in the history
* cast selectors to strings

* add some tests

* update expected steps
  • Loading branch information
romainmenke authored May 26, 2023
1 parent 724df43 commit aeee9f8
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 124 deletions.
120 changes: 60 additions & 60 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prettier": {
"useTabs": true
},
"version": "1.1.1",
"version": "1.1.2",
"volta": {
"node": "20.2.0",
"npm": "9.6.7"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-core-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mrhenry/babel-plugin-core-web",
"version": "1.1.1",
"version": "1.1.2",
"description": "browser feature polyfills as a babel plugin",
"main": "lib/index.js",
"author": "Simon Menke <[email protected]>",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@babel/helper-module-imports": "^7.15.4",
"@babel/types": "^7.21.5",
"@mrhenry/core-web": "^1.1.1",
"@mrhenry/core-web": "^1.1.2",
"fast-deep-equal": "^3.1.3"
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-web-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mrhenry/core-web-example",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"scripts": {
"build": "babel src -d lib"
Expand Down
2 changes: 1 addition & 1 deletion packages/core-web-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mrhenry/core-web-generator",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"scripts": {
"clean": "rm -rf ./lib/",
Expand Down
15 changes: 10 additions & 5 deletions packages/core-web-generator/polyfills/~element-qsa-has.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,12 @@

function polyfill(qsa) {
return function (selectors) {
if ((selectors.toLowerCase().indexOf(':has(') === -1) || !pseudoClassHasInnerQuery(selectors)) {
if (!selectors) {
return qsa.apply(this, arguments);
}

var selectorsString = String(selectors);
if (!selectorsString || (selectorsString.toLowerCase().indexOf(':has(') === -1) || !pseudoClassHasInnerQuery(selectorsString)) {
return qsa.apply(this, arguments);
}

Expand All @@ -472,10 +477,10 @@
_focus.setAttribute(scopeAttr, '');

try {
selectors = replaceScopeWithAttr(selectors, scopeAttr);
selectorsString = replaceScopeWithAttr(selectorsString, scopeAttr);

var attrs = [scopeAttr];
var newQuery = replaceAllWithTempAttr(selectors, false, function (inner, attr) {
var newQuery = replaceAllWithTempAttr(selectorsString, false, function (inner, attr) {
attrs.push(attr);

var selectorParts = splitSelector(inner);
Expand Down Expand Up @@ -593,12 +598,12 @@
} catch (dummyError) {
errorMessage = dummyError.message;
if (errorMessage) {
errorMessage = errorMessage.replace(':core-web-does-not-exist', selectors);
errorMessage = errorMessage.replace(':core-web-does-not-exist', selectorsString);
}
}

if (!errorMessage) {
errorMessage = "Failed to execute 'querySelector' on 'Document': '" + selectors + "' is not a valid selector.";
errorMessage = "Failed to execute 'querySelector' on 'Document': '" + selectorsString + "' is not a valid selector.";
}

try {
Expand Down
Loading

0 comments on commit aeee9f8

Please sign in to comment.