public override bool Walk(ObjectLiteral node) {
     if (_typedChar == '}' && node.GetEndIndex(_tree.LocationResolver) == _position) {
         Span = node.GetSpan(_tree.LocationResolver);
         return false;
     }
     return base.Walk(node);
 }
Example #2
0
        public override bool Walk(ObjectLiteral node) {
            bool isMultiLine = ContainsLineFeed(node.GetStartIndex(_tree.LocationResolver), node.GetEndIndex(_tree.LocationResolver));

            // Body.
            if (node.Properties.Length != 0) {
                Indent();
                if (isMultiLine) {
                    // multiline block statement, make sure the 1st statement
                    // starts on a new line
                    EnsureNewLineFollowing(node.GetStartIndex(_tree.LocationResolver) + "{".Length);
                }

                WalkStatements(node, node.Properties, isMultiLine);

                Dedent();
            }

            // Format the indentation of the block along with whitespace.
            if (isMultiLine) {
                ReplacePreceedingIncludingNewLines(node.GetEndIndex(_tree.LocationResolver) - 1, ReplaceWith.InsertNewLineAndIndentation, replaceOnNewLine: true);
            } else if (node.Properties.Length == 0) {
                ReplacePreceedingWhiteSpace(node.GetEndIndex(_tree.LocationResolver) - 1, "");
            } else {
                ReplacePreceedingWhiteSpace(node.GetEndIndex(_tree.LocationResolver) - 1, " ");
            }

            return false;
        }