From a39a1f4b70a28a25b7335415a3fd3c96ed930e19 Mon Sep 17 00:00:00 2001 From: jquense Date: Wed, 14 Oct 2015 07:49:32 -0400 Subject: [PATCH] [fixed] handle empty (null) elements --- lib/compiler.js | 18 ++++++++++++++++-- lib/package.json | 3 ++- lib/utils.js | 21 +++++++++++++++++++++ src/instance-selector.js | 3 ++- test/compiler.js | 2 +- test/selection.js | 2 ++ 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 5f97888..fdfaed7 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -26,7 +26,14 @@ var _utils = require('./utils'); var _cssSelectorParser = require('css-selector-parser'); +var _fnName = require('fn-name'); + +var _fnName2 = _interopRequireDefault(_fnName); + var parser = new _cssSelectorParser.CssSelectorParser(); +var name = function name(type) { + return type.displayName || _fnName2['default'](type) || ''; +}; var prim = function prim(value) { var typ = typeof value; @@ -162,7 +169,14 @@ function create() { values[_key - 1] = arguments[_key]; } - var valueMap = Object.create(null); + if (!Array.isArray(strings)) { + ; + + var _legacySelector$apply = _utils.legacySelector.apply(null, [strings].concat(values)); + + strings = _legacySelector$apply[0]; + values = _legacySelector$apply[1]; + }var valueMap = Object.create(null); var selector = strings.reduce(function (rslt, string, idx) { var noValue = idx >= values.length, @@ -194,7 +208,7 @@ function getTagComparer(rule, values) { if (isStr(tagName)) { tagName = tagName.toUpperCase(); return function (root) { - return isStr(root.type) && root.type.toUpperCase() === tagName; + return isStr(root.type) ? root.type.toUpperCase() === tagName : name(root.type).toUpperCase() === tagName; }; } diff --git a/lib/package.json b/lib/package.json index daddcc9..f759bd7 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,6 +1,6 @@ { "name": "bill", - "version": "1.3.2", + "version": "1.4.0", "description": "css selectors for React Elements", "main": "index.js", "repository": { @@ -23,6 +23,7 @@ }, "dependencies": { "css-selector-parser": "^1.1.0", + "fn-name": "^2.0.1", "lodash": "^3.10.1" } } diff --git a/lib/utils.js b/lib/utils.js index 3ab94df..0ef36bc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,6 +3,7 @@ exports.__esModule = true; exports.anyParent = anyParent; exports.directParent = directParent; +exports.legacySelector = legacySelector; var isTextElement = function isTextElement(element) { return typeof element === 'string'; }; @@ -36,4 +37,24 @@ function anyParent(test, element, parentNode) { function directParent(test, element, parentNode) { element = parentNode().parent; return !!(element && test(element, parentNode().getParent)); +} + +function legacySelector() { + var strings = [], + values = []; + + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + args.forEach(function (arg, idx) { + var isString = typeof arg === 'string'; + + if (isString) strings.push(arg);else { + if (idx === 0) strings.push(''); + values.push(arg); + } + }); + + return [strings, values]; } \ No newline at end of file diff --git a/src/instance-selector.js b/src/instance-selector.js index a9a4527..90c9afc 100644 --- a/src/instance-selector.js +++ b/src/instance-selector.js @@ -42,7 +42,8 @@ export function findAll(inst, test, includeSelf, getParent = ()=> ({ parent: nul var element = inst._currentElement , parent = ()=> ({ parent: element, getParent }); - if (includeSelf && test(element, inst, getParent)) + // ReactEmptyComponents (return null render