src/rules/namespace.js
function ({ body }) {
        function processBodyStatement(declaration) {
          if (declaration.type !== 'ImportDeclaration') return

          if (declaration.specifiers.length === 0) return

          const imports = Exports.get(declaration.source.value, context)
          if (imports == null) return null

          if (imports.errors.length) {
            imports.reportErrors(context, declaration)
            return
          }

          for (const specifier of declaration.specifiers) {
            switch (specifier.type) {
              case 'ImportNamespaceSpecifier':
                if (!imports.size) {
                  context.report(specifier,
                    `No exported names found in module '${declaration.source.value}'.`)
                }
                namespaces.set(specifier.local.name, imports)
                break
              case 'ImportDefaultSpecifier':
              case 'ImportSpecifier': {
                const meta = imports.get(
                  // default to 'default' for default http://i.imgur.com/nj6qAWy.jpg
                  specifier.imported ? specifier.imported.name : 'default')
                if (!meta || !meta.namespace) break
                namespaces.set(specifier.local.name, meta.namespace)
                break
              }
            }
          }
        }
        body.forEach(processBodyStatement)
      }
function ({ body }) {
        function processBodyStatement(declaration) {
          if (declaration.type !== 'ImportDeclaration') return

          if (declaration.specifiers.length === 0) return

          const imports = Exports.get(declaration.source.value, context)
          if (imports == null) return null

          if (imports.errors.length) {
            imports.reportErrors(context, declaration)
            return
          }

          for (const specifier of declaration.specifiers) {
            switch (specifier.type) {
              case 'ImportNamespaceSpecifier':
                if (!imports.size) {
                  context.report(specifier,
                    `No exported names found in module '${declaration.source.value}'.`)
                }
                namespaces.set(specifier.local.name, imports)
                break
              case 'ImportDefaultSpecifier':
              case 'ImportSpecifier': {
                const meta = imports.get(
                  // default to 'default' for default http://i.imgur.com/nj6qAWy.jpg
                  specifier.imported ? specifier.imported.name : 'default')
                if (!meta || !meta.namespace) break
                namespaces.set(specifier.local.name, meta.namespace)
                break
              }
            }
          }
        }
        body.forEach(processBodyStatement)
      }
function ( { body } ) { function processBodyStatement ( declaration ) { if ( declaration . type !== 'ImportDeclaration' ) return if ( declaration . specifiers . length === 0 ) return const imports = Exports . get ( declaration . source . value , context ) if ( imports == null ) return null if ( imports . errors . length ) { imports . reportErrors ( context , declaration ) return } for ( const specifier of declaration . specifiers ) { switch ( specifier . type ) { case 'ImportNamespaceSpecifier' : if ( ! imports . size ) { context . report ( specifier , ` ${ declaration . source . value } ` ) } namespaces . set ( specifier . local . name , imports ) break case 'ImportDefaultSpecifier' : case 'ImportSpecifier' : { const meta = imports . get ( // default to 'default' for default http://i.imgur.com/nj6qAWy.jpg specifier . imported ? specifier . imported . name : 'default' ) if ( ! meta || ! meta . namespace ) break namespaces . set ( specifier . local . name , meta . namespace ) break } } } } body . forEach ( processBodyStatement ) }
pick up all imports at body entry time, to properly respect hoisting
pick up all imports at body entry time to properly respect hoisting