Files
coffeescript/documentation/sections/modules.md
Geoffrey Booth c09d8fbedb Release 2.4.0 (#5182)
* cake doc:site:watch should also watch the changelog files

* Changelog for 2.4.0

* 2.4.0 output
2019-03-30 11:31:22 -07:00

22 lines
1.1 KiB
Markdown

## Modules
ES2015 modules are supported in CoffeeScript, with very similar `import` and `export` syntax:
```
codeFor('modules')
```
<div id="dynamic-import" class="bookmark"></div>
[Dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports) is also supported, with mandatory parentheses:
```
codeFor('dynamic_import', true)
```
<div id="modules-note" class="bookmark"></div>
Note that the CoffeeScript compiler **does not resolve modules**; writing an `import` or `export` statement in CoffeeScript will produce an `import` or `export` statement in the resulting output. It is your responsibility to [transpile](#transpilation) this ES2015 syntax into code that will work in your target runtimes.
Also note that any file with an `import` or `export` statement will be output without a [top-level function safety wrapper](#lexical-scope); in other words, importing or exporting modules will automatically trigger [bare](#usage) mode for that file. This is because per the ES2015 spec, `import` or `export` statements must occur at the topmost scope.