3 Object.defineProperty(exports, '__esModule', {
6 exports.test = exports.serialize = undefined;
8 var _markup = require('./lib/markup');
11 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
13 * This source code is licensed under the MIT license found in the
14 * LICENSE file in the root directory of this source tree.
19 const elementSymbol = Symbol.for('react.element');
20 const fragmentSymbol = Symbol.for('react.fragment');
21 const forwardRefSymbol = Symbol.for('react.forward_ref');
22 const providerSymbol = Symbol.for('react.provider');
23 const contextSymbol = Symbol.for('react.context');
25 // Given element.props.children, or subtree during recursive traversal,
26 // return flattened array of children.
27 const getChildren = function(arg) {
29 arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
31 if (Array.isArray(arg)) {
33 getChildren(item, children);
35 } else if (arg != null && arg !== false) {
41 const getType = element => {
42 const type = element.type;
43 if (typeof type === 'string') {
46 if (typeof type === 'function') {
47 return type.displayName || type.name || 'Unknown';
49 if (type === fragmentSymbol) {
50 return 'React.Fragment';
52 if (typeof type === 'object' && type !== null) {
53 if (type.$$typeof === providerSymbol) {
54 return 'Context.Provider';
57 if (type.$$typeof === contextSymbol) {
58 return 'Context.Consumer';
61 if (type.$$typeof === forwardRefSymbol) {
62 const functionName = type.render.displayName || type.render.name || '';
64 return functionName !== ''
65 ? 'ForwardRef(' + functionName + ')'
72 const getPropKeys = element => {
73 const props = element.props;
75 return Object.keys(props)
76 .filter(key => key !== 'children' && props[key] !== undefined)
80 const serialize = (exports.serialize = (
88 ++depth > config.maxDepth
89 ? (0, _markup.printElementAsLeaf)(getType(element), config)
90 : (0, _markup.printElement)(
92 (0, _markup.printProps)(
96 indentation + config.indent,
101 (0, _markup.printChildren)(
102 getChildren(element.props.children),
104 indentation + config.indent,
113 const test = (exports.test = val => val && val.$$typeof === elementSymbol);
115 exports.default = {serialize: serialize, test: test};