lib/rules/sort-object-props.js
function nodeToString(node) {
    switch (node.type) {
        case ("BinaryExpression"): {
            return nodeToString(node.left) + node.operator.toString() + nodeToString(node.right);
        }
        case ("CallExpression"): {
            var args = node.arguments.map(function(arg) {
                return nodeToString(arg);
            }).toString();
            return nodeToString(node.callee) + "(" + args + ")";
        }
        case ("ConditionalExpression"): {
            return nodeToString(node.test) + "?" + nodeToString(node.consequent) + ":" + nodeToString(node.alternate);
        }
        case ("Identifier"): {
            return node.name.toString();
        }
        case ("Literal"): {
            return node.value.toString();
        }
        case ("MemberExpression"): {
            return nodeToString(node.object) + "[" + nodeToString(node.property) + "]";
        }
        case ("TemplateElement"): {
            return node.value.raw.toString();
        }
        case ("TemplateLiteral"): {
            // interleave quasis with expressions
            var s = [];
            node.quasis.forEach(function(quasi, i) {
                if (quasi.value.raw) {
                    s.push(nodeToString(quasi));
                }
                var expression = node.expressions[i];
                if (expression) {
                    s.push(nodeToString(expression));
                }
            });
            return s.join("");
        }
        default: {
            // Silently ignore Nodes with types we don't handle
            return "";
        }
    }
}
function nodeToString(node) {
    switch (node.type) {
        case ("BinaryExpression"): {
            return nodeToString(node.left) + node.operator.toString() + nodeToString(node.right);
        }
        case ("CallExpression"): {
            var args = node.arguments.map(function(arg) {
                return nodeToString(arg);
            }).toString();
            return nodeToString(node.callee) + "(" + args + ")";
        }
        case ("ConditionalExpression"): {
            return nodeToString(node.test) + "?" + nodeToString(node.consequent) + ":" + nodeToString(node.alternate);
        }
        case ("Identifier"): {
            return node.name.toString();
        }
        case ("Literal"): {
            return node.value.toString();
        }
        case ("MemberExpression"): {
            return nodeToString(node.object) + "[" + nodeToString(node.property) + "]";
        }
        case ("TemplateElement"): {
            return node.value.raw.toString();
        }
        case ("TemplateLiteral"): {
            // interleave quasis with expressions
            var s = [];
            node.quasis.forEach(function(quasi, i) {
                if (quasi.value.raw) {
                    s.push(nodeToString(quasi));
                }
                var expression = node.expressions[i];
                if (expression) {
                    s.push(nodeToString(expression));
                }
            });
            return s.join("");
        }
        default: {
            // Silently ignore Nodes with types we don't handle
            return "";
        }
    }
}
function nodeToString ( node ) { switch ( node . type ) { case ( "BinaryExpression" ) : { return nodeToString ( node . left ) + node . operator . toString ( ) + nodeToString ( node . right ) ; } case ( "CallExpression" ) : { var args = node . arguments . map ( function ( arg ) { return nodeToString ( arg ) ; } ) . toString ( ) ; return nodeToString ( node . callee ) + "(" + args + ")" ; } case ( "ConditionalExpression" ) : { return nodeToString ( node . test ) + "?" + nodeToString ( node . consequent ) + ":" + nodeToString ( node . alternate ) ; } case ( "Identifier" ) : { return node . name . toString ( ) ; } case ( "Literal" ) : { return node . value . toString ( ) ; } case ( "MemberExpression" ) : { return nodeToString ( node . object ) + "[" + nodeToString ( node . property ) + "]" ; } case ( "TemplateElement" ) : { return node . value . raw . toString ( ) ; } case ( "TemplateLiteral" ) : { // interleave quasis with expressions var s = [ ] ; node . quasis . forEach ( function ( quasi , i ) { if ( quasi . value . raw ) { s . push ( nodeToString ( quasi ) ) ; } var expression = node . expressions [ i ] ; if ( expression ) { s . push ( nodeToString ( expression ) ) ; } } ) ; return s . join ( "" ) ; } default : { // Silently ignore Nodes with types we don't handle return "" ; } } }
Recursively converts Nodes to strings so they can be sorted
@param {Node} node: Babel AST Node
@returns {String} Node value as a string
Recursively converts Nodes to strings so they can be sorted