diff --git a/Cakefile b/Cakefile index c9a675fd49..dbd21b0226 100644 --- a/Cakefile +++ b/Cakefile @@ -54,6 +54,9 @@ codeFor = -> js = js.replace /^\/\/ generated.*?\n/i, '' cshtml = "
#{hljs.highlight('coffeescript', cs).value}
" + # Temporary fix until highlight.js adds support for newer CoffeeScript reserved words + if file is 'modules' + cshtml = cshtml.replace /(import|export|from|as|default) /g, '$1 ' jshtml = "
#{hljs.highlight('javascript', js).value}
" append = if executable is yes then '' else "alert(#{executable});" if executable and executable != yes diff --git a/bower.json b/bower.json index da638df6cb..327b2d8110 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,7 @@ "devDependencies": { "uglify-js": "~2.2", "jison": ">=0.2.0", - "highlight.js": "~8.0.0", + "highlight.js": "~9.6.0", "underscore": "~1.5.2", "docco": "~0.6.2" }, diff --git a/documentation/coffee/modules.coffee b/documentation/coffee/modules.coffee new file mode 100644 index 0000000000..9e383ae286 --- /dev/null +++ b/documentation/coffee/modules.coffee @@ -0,0 +1,23 @@ +import 'local-file.coffee' +import 'coffee-script' + +import _ from 'underscore' +import * as underscore from 'underscore' + +import { now } from 'underscore' +import { now as currentTimestamp } from 'underscore' +import { first, last } from 'underscore' +import utilityBelt, { each } from 'underscore' + +export default Math +export square = (x) -> x * x +export class Mathematics + least: (x, y) -> if x < y then x else y + +export { sqrt } +export { sqrt as squareRoot } +export { Mathematics as default, sqrt as squareRoot } + +export * from 'underscore' +export { max, min } from 'underscore' + diff --git a/documentation/index.html.js b/documentation/index.html.js index 7ada8e1125..cd11a0b6bc 100644 --- a/documentation/index.html.js +++ b/documentation/index.html.js @@ -41,6 +41,7 @@ Chained Comparisons String Interpolation, Block Strings, and Block Comments Block Regular Expressions + Modules Cake, and Cakefiles Source Maps "text/coffeescript" Script Tags @@ -467,10 +468,11 @@ Expressions

If you'd like to create top-level variables for other scripts to use, - attach them as properties on window, or on the exports - object in CommonJS. The existential operator (covered below), gives you a - reliable way to figure out where to add them; if you're targeting both - CommonJS and the browser: exports ? this + attach them as properties on window; attach them as properties on the + exports object in CommonJS; or use an export + statement. If you’re targeting both CommonJS and the browser, the + existential operator (covered below), gives you a + reliable way to figure out where to add them: exports ? this

@@ -937,6 +939,29 @@ Expressions

<%= codeFor('heregexes') %> +

+ + Modules + ES2015 modules are supported in CoffeeScript, with very similar import + and export syntax: +

+ <%= codeFor('modules') %> +

+ 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, + Babel or + 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; + in other words, importing or exporting modules will automatically trigger + bare mode for that file. This is because per the ES2015 spec, + import or export statements must occur at the topmost scope.

diff --git a/documentation/js/modules.js b/documentation/js/modules.js new file mode 100644 index 0000000000..9fdfcd9a00 --- /dev/null +++ b/documentation/js/modules.js @@ -0,0 +1,66 @@ +// Generated by CoffeeScript 1.10.0 +import 'local-file.coffee'; + +import 'coffee-script'; + +import _ from 'underscore'; + +import * as underscore from 'underscore'; + +import { + now +} from 'underscore'; + +import { + now as currentTimestamp +} from 'underscore'; + +import { + first, + last +} from 'underscore'; + +import utilityBelt, { + each +} from 'underscore'; + +export default Math; + +export var square = function(x) { + return x * x; +}; + +export var Mathematics = (function() { + function Mathematics() {} + + Mathematics.prototype.least = function(x, y) { + if (x < y) { + return x; + } else { + return y; + } + }; + + return Mathematics; + +})(); + +export { + sqrt +}; + +export { + sqrt as squareRoot +}; + +export { + Mathematics as default, + sqrt as squareRoot +}; + +export * from 'underscore'; + +export { + max, + min +} from 'underscore'; diff --git a/package.json b/package.json index 5dda687b21..526d5a6376 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "devDependencies": { "uglify-js": "~2.2", "jison": ">=0.2.0", - "highlight.js": "~8.0.0", + "highlight.js": "~9.6.0", "underscore": "~1.5.2", "docco": "~0.7.0" }