               
               # If we need to close an autoinserted socket,
               # close it.
-              if mark.token.block is autoinsertStack?[autoinsertStack.length - 1]
+              if mark.token.block is autoinsertStack[autoinsertStack.length - 1]
                 autoinsertStack.pop()
                 head = head.append stack.pop().end
 
             when 'socketEnd'
               unless mark.token.socket is stack[stack.length - 1]
                 throw new Error 'Improper parser: socket ended too early.'
-              
+
               # Update stack
               stack.pop()
 
               head = head.append mark.token
+
+              if mark.token.socket is autoinsertStack[autoinsertStack.length - 1]
+                autoinsertStack.pop()
+                head = head.append stack.pop().end
 
           lastIndex = mark.location.column
       

              head = head.append mark.token

            when 'blockEnd'
              unless mark.token.block is stack?[stack.length - 1]
                throw new Error 'Improper parser: block ended too early.'
              
              # Update stack

            # its corresponding Start token; if it is not,
            # we throw.
            when 'indentEnd'
              unless mark.token.indent is stack[stack.length - 1]
                throw new Error 'Improper parser: indent ended too early.'
              
              # Update stack and indent depth
