prop-types(symbols): rewrite isSymbol to be simpler 1) If it is a native Symbol 2) If it is spec-compliant 3) Try to match non-spec compliant polyfill by a instanceof check on Symbol if it exists in the global namespace
prop-types(symbols): rewrite isSymbol to be simpler 1) If it is a native Symbol 2) If it is spec-compliant 3) Try to match non-spec compliant polyfill by a instanceof check on Symbol if it exists in the global namespace
Raito Bezarius committed
Apr 2, 2016 at 14:27 UTC
4239f8ac3bf3dcbcc8554e3b821f562831eeb663
1 file changed
+9
-13
src/isomorphic/classic/types/ReactPropTypes.js
+9
-13
@@ -408,23 +408,19 @@ function isNode(propValue) {
408
}
409
410
function isSymbol(propType, propValue) {
411
+ // Native Symbol.
412
if (propType === 'symbol') {
412
- return true; // This is a native Symbol.
413
+ return true;
414
}
415
415
- if (typeof Symbol === 'undefined') {
416
- // No Symbol is available in the global namespace.
417
- // We need to check if it has some spec-defined method (duck typing).
418
-
419
- if (propValue['@@toStringTag'] === 'Symbol') {
420
- return true;
421
- }
416
+ // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
417
+ if (propValue['@@toStringTag'] === 'Symbol') {
418
+ return true;
419
+ }
420
423
- if (propValue.__key__ && propValue.prototype.__key__ === undefined) {
424
- return propValue.toString() === 'Symbol'
425
- }
426
- } else {
427
- return propValue instanceof Symbol; // This is a polyfilled Symbol.
421
+ // Fallback for non-spec compliant Symbols which are polyfilled.
422
+ if (typeof Symbol !== 'undefined' && propValue instanceof Symbol) {
423
+ return true;
424
}
425
426
return false;