From 4fd04d207220346c65f226ca4326702990313faa Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 31 Mar 2016 13:39:39 +0200 Subject: [PATCH 1/3] prop-types(react): add Symbol type check --- .../classic/types/ReactPropTypes.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/isomorphic/classic/types/ReactPropTypes.js b/src/isomorphic/classic/types/ReactPropTypes.js index 99c036496aaba..4d420ec820cbf 100644 --- a/src/isomorphic/classic/types/ReactPropTypes.js +++ b/src/isomorphic/classic/types/ReactPropTypes.js @@ -83,6 +83,7 @@ var ReactPropTypes = { oneOf: createEnumTypeChecker, oneOfType: createUnionTypeChecker, shape: createShapeTypeChecker, + symbol: createSymbolTypeChecker(), }; /** @@ -359,6 +360,26 @@ function createShapeTypeChecker(shapeTypes) { return createChainableTypeChecker(validate); } +function createSymbolTypeChecker() { + function validate(props, propName, componentName, location, propFullName) { + var propValue = props[propName]; + var propType = getPropType(propValue) + + // If it behaves like a Symbol, it is a Symbol. + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol + if ((propType !== 'symbol') && (propValue['@@toStringTag'] !== 'Symbol')) { + return new Error( + `Invalid ${locationName} \`${propFullName}\` of type \`${propType}\` ` + + `supplied to \`${componentName}\`, expected \`symbol\`.` + ); + } + + return null; + } + return createChainableTypeChecker(validate); +} + + function isNode(propValue) { switch (typeof propValue) { case 'number': From 64c85a972332d3533e5063fd24805b835e4879ba Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 31 Mar 2016 16:23:01 +0200 Subject: [PATCH 2/3] prop-types(react,lint): fix missing semicolon --- src/isomorphic/classic/types/ReactPropTypes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/isomorphic/classic/types/ReactPropTypes.js b/src/isomorphic/classic/types/ReactPropTypes.js index 4d420ec820cbf..b30cf40126a0e 100644 --- a/src/isomorphic/classic/types/ReactPropTypes.js +++ b/src/isomorphic/classic/types/ReactPropTypes.js @@ -363,7 +363,7 @@ function createShapeTypeChecker(shapeTypes) { function createSymbolTypeChecker() { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; - var propType = getPropType(propValue) + var propType = getPropType(propValue); // If it behaves like a Symbol, it is a Symbol. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol From 9097b516bc8ec6a261059ff1a4c59a1bbac92b86 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 31 Mar 2016 16:23:20 +0200 Subject: [PATCH 3/3] prop-types(react,typo): it should be location rather than locationName --- src/isomorphic/classic/types/ReactPropTypes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/isomorphic/classic/types/ReactPropTypes.js b/src/isomorphic/classic/types/ReactPropTypes.js index b30cf40126a0e..d82ac8c678ca2 100644 --- a/src/isomorphic/classic/types/ReactPropTypes.js +++ b/src/isomorphic/classic/types/ReactPropTypes.js @@ -369,7 +369,7 @@ function createSymbolTypeChecker() { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol if ((propType !== 'symbol') && (propValue['@@toStringTag'] !== 'Symbol')) { return new Error( - `Invalid ${locationName} \`${propFullName}\` of type \`${propType}\` ` + + `Invalid ${location} \`${propFullName}\` of type \`${propType}\` ` + `supplied to \`${componentName}\`, expected \`symbol\`.` ); }