jashkenas--coffeescript/documentation/sections/modules.md

14 lines
1013 B
Markdown
Raw Normal View History

Docs improvements: content in Markdown, organization into subtemplates, fixed tests (#4401) * Replace tiny bitmaps with base64-encoded URIs * Optimize SVGs; replace logo PNG with SVG * Modernize favicon * Embed CSS; a bit unorthodox, but we’re a single page so there’s no point in separate .css files and their separate HTTP requests * Documentation is now markdown, converted to HTML on compilation * Render the examples when we’re rendering index.html; they compile so quickly that there’s no need to pre-render them and save the intermediate .js files * Split apart index.html into components that Cakefile assembles, so that we can add in logic to include different files for v1 versus v2 * Split building index.html and building test.html into two tasks; collapse the parts of `releaseHeader` into one compact function * Move include logic into templates * Get error messages tests to work in the browser * Update output index.html * Split body into nav and body * Watch subtemplates * Revert "Split body into nav and body" This reverts commit ec9e559ec0c3f350bd009afd437652347789b180. * Add marked * Update gitignore * Use idiomatic markdown output for code blocks (<pre><code>) * Handle ids within the template, not in the Cakefile; remove marked’s auto-generated and conflicting ids * Move the `codeFor` function into versioned folders, so that v1 and v2 docs can have different example code blocks/editors * Update packages, including new highlight.js which supports our newer keywords and triple backticks (docs output is unchanged)
2016-12-16 00:05:44 -05:00
## Modules
ES2015 modules are supported in CoffeeScript, with very similar `import` and `export` syntax:
```
codeFor('modules')
```
<div id="modules-note" class="bookmark"></div>
Docs improvements: content in Markdown, organization into subtemplates, fixed tests (#4401) * Replace tiny bitmaps with base64-encoded URIs * Optimize SVGs; replace logo PNG with SVG * Modernize favicon * Embed CSS; a bit unorthodox, but we’re a single page so there’s no point in separate .css files and their separate HTTP requests * Documentation is now markdown, converted to HTML on compilation * Render the examples when we’re rendering index.html; they compile so quickly that there’s no need to pre-render them and save the intermediate .js files * Split apart index.html into components that Cakefile assembles, so that we can add in logic to include different files for v1 versus v2 * Split building index.html and building test.html into two tasks; collapse the parts of `releaseHeader` into one compact function * Move include logic into templates * Get error messages tests to work in the browser * Update output index.html * Split body into nav and body * Watch subtemplates * Revert "Split body into nav and body" This reverts commit ec9e559ec0c3f350bd009afd437652347789b180. * Add marked * Update gitignore * Use idiomatic markdown output for code blocks (<pre><code>) * Handle ids within the template, not in the Cakefile; remove marked’s auto-generated and conflicting ids * Move the `codeFor` function into versioned folders, so that v1 and v2 docs can have different example code blocks/editors * Update packages, including new highlight.js which supports our newer keywords and triple backticks (docs output is unchanged)
2016-12-16 00:05:44 -05:00
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 attach another transpiler, such as [Traceur Compiler](https://github.com/google/traceur-compiler), [Babel](http://babeljs.io/) or [Rollup](https://github.com/rollup/rollup), to convert 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.