According to Types of Source Code, there's Global Code (treated as Source; what was known as Program in ES5, AFAIU, — sequence of Statement's and/or Declaration's) and then there's Module Code (treated as ModuleBody).
As per syntax productions, only Module is allowed to have ExportDeclaration's and ImportDeclarations but both Global Code and Module Code can have regular Statement's and Declaration's.
What I can't tell from the spec is how ES implementation decides whether to parse something as Module Code or as Global Code.
In this article on modules, Axel mentions that:
Given the synchronicity of scripts, it is obvious that you can’t simply add import and export capability and turn them into modules. There must be a way to handle module code differently. Therefore, there will be a new tag <module> for modules that replaces the <script> tag and is completely asynchronous:
But what about non-browser environments?
I'm interested in this mainly because I'm trying to understand how one would test for module import/export support. We can't use "export ..." as part of a FunctionBody, for example, but what about as part of Global Code/Script?
How do we tell engine to parse something as ModuleBody?