 # base types only, ends with an error (Boutique builds no symbol table,
 # so it can't resolve any possible inheritance).
 simplifyTypeSpecification = (typeSpec, cb) ->
-  type = typeSpec?.name?.name
-  return cb null, null if not type  # no type? return null...
+  name = findTypeName typeSpec
+  return cb null, null if not name  # no type name? return null...
 
-  ensureBaseType type, (err) ->
-    return cb err if err  # non-base type results in error
-    return cb null, {name: type} if (typeSpec?.nestedTypes?.length or 0) < 1  # no nested types
-
-    # just playing safe, this should be already ensured by MSON parser
-    if type not in ['array', 'enum']
-      return cb new Error "Nested types are allowed only for array and enum types."
-
-    nested = (typeName.name for typeName in typeSpec.nestedTypes)
-    async.map nested, ensureBaseType, (err) ->
-      return cb err if err  # again, non-base types result in error
-      cb null, {name: type, nested}
+  async.waterfall [
+    (next) -> ensureBaseType name, next
+    (next) -> simplifyNestedTypes typeSpec, next
+  ], (err, nested) ->
+    cb err, ({name, nested} unless err)
 
 
 # Helps to identify whether given node is an implicit array.


async = require 'async'


# Listing of all base types as defined in MSON AST spec.

    # just playing safe, this should be already ensured by MSON parser
    cb new Error "Unable to resolve type. Ambiguous implicit type (seems to be both object and inline array)."
  else
    name = ('array' if isArr) or ('object' if isObj) or 'string'

    resolveImplicitNestedTypes name, node, (err, nested) ->
      cb err, ({name, nested} unless err)


# TODO: should be moved to inspect
#
# Finds *typeSpecification* object for given *Named Type* or *Property Member*
# or *Value Member* tree node.
findTypeSpecification = (node) ->
