@asamuzakjp/dom-selector 0.15.5 → 0.15.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -42,5 +42,5 @@
42
42
  "test": "c8 --reporter=text mocha --exit test/**/*.test.js",
43
43
  "tsc": "npx tsc"
44
44
  },
45
- "version": "0.15.5"
45
+ "version": "0.15.6"
46
46
  }
package/src/js/matcher.js CHANGED
@@ -73,14 +73,16 @@ const isNamespaceDeclared = (ns = '', node = {}) => {
73
73
  if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {
74
74
  const attr = `xmlns:${ns}`;
75
75
  const root = node.ownerDocument.documentElement;
76
- while (node) {
77
- if (node.hasAttribute(attr)) {
76
+ let parent = node;
77
+ while (parent) {
78
+ if (typeof parent.hasAttribute === 'function' &&
79
+ parent.hasAttribute(attr)) {
78
80
  res = true;
79
81
  break;
80
- } else if (node === root) {
82
+ } else if (parent === root) {
81
83
  break;
82
84
  }
83
- node = node.parentNode;
85
+ parent = parent.parentNode;
84
86
  }
85
87
  }
86
88
  return !!res;
@@ -600,13 +602,13 @@ const matchAttributeSelector = (ast = {}, node = {}) => {
600
602
  flags: astFlags, matcher: astMatcher, name: astName, type: astType,
601
603
  value: astValue
602
604
  } = ast;
605
+ if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {
606
+ throw new DOMException('invalid attribute selector', 'SyntaxError');
607
+ }
603
608
  const { attributes, nodeType } = node;
604
609
  let res;
605
610
  if (astType === ATTRIBUTE_SELECTOR && nodeType === ELEMENT_NODE &&
606
611
  attributes?.length) {
607
- if (typeof astFlags === 'string' && !/^[is]$/i.test(astFlags)) {
608
- throw new DOMException('invalid attribute selector', 'SyntaxError');
609
- }
610
612
  const caseInsensitive =
611
613
  !(typeof astFlags === 'string' && /^s$/i.test(astFlags));
612
614
  const attrValues = [];
package/src/js/parser.js CHANGED
@@ -82,6 +82,8 @@ const parseSelector = selector => {
82
82
  } catch (e) {
83
83
  if (e.message === '"]" is expected' && !selector.endsWith(']')) {
84
84
  res = parseSelector(`${selector}]`);
85
+ } else if (e.message === '")" is expected' && !selector.endsWith(')')) {
86
+ res = parseSelector(`${selector})`);
85
87
  } else {
86
88
  throw new DOMException(e.message, 'SyntaxError');
87
89
  }