From f6d63776c3de2d4ab955bf4fa310a878f9a76a01 Mon Sep 17 00:00:00 2001
From: Geoffrey Booth
Date: Tue, 26 Mar 2019 23:55:31 -0700
Subject: [PATCH] ES module version of compiler for use in browsers; dynamic
import() docs; revised Stage 3 policy (#5177)
* Build both a legacy and modern browser compiler
* Dynamic import example and documentation
* Update the docs to use the modern browser compiler if the browser supports it
* Update policy regarding Stage 3 features
* This never made sense, and assigning a string to index 0 *of a string* throws in Module mode (and silently does nothing in Script mode) so remove this unneeded code that throws when compiling `fn for i from from iterable` in Module mode
* Have browser-based tests use the ES module version if supported
* Simplify building logic
* Update output
* For the ES module version of the browser compiler, don't automatically attach the runScripts event handler
* Consistent comments
* Fix comment
---
Cakefile | 44 +-
docs/browser-compiler-modern | 1 +
docs/v2/annotated-source/browser.html | 17 +-
docs/v2/annotated-source/coffeescript.html | 136 +-
docs/v2/annotated-source/grammar.html | 4 +-
docs/v2/annotated-source/index.html | 8 +-
docs/v2/annotated-source/lexer.html | 170 +-
docs/v2/annotated-source/nodes.html | 25 +-
.../browser-compiler-modern/coffeescript.js | 11224 ++++++++++++++++
docs/v2/browser-compiler/coffeescript.js | 2 +-
docs/v2/index.html | 80 +-
docs/v2/test.html | 89 +-
documentation/examples/dynamic_import.coffee | 10 +
documentation/examples/modules.coffee | 2 +-
documentation/sections/contributing.md | 4 +-
documentation/sections/modules.md | 6 +
documentation/site/scripts.html | 11 +-
documentation/site/test.html | 7 +-
lib/coffeescript/browser.js | 18 +-
lib/coffeescript/lexer.js | 7 +-
package.json | 1 +
src/browser.coffee | 15 +-
src/lexer.coffee | 6 +-
23 files changed, 11668 insertions(+), 219 deletions(-)
create mode 120000 docs/browser-compiler-modern
create mode 100644 docs/v2/browser-compiler-modern/coffeescript.js
create mode 100644 documentation/examples/dynamic_import.coffee
diff --git a/Cakefile b/Cakefile
index 5e9c6adf..00ddfc45 100644
--- a/Cakefile
+++ b/Cakefile
@@ -66,15 +66,18 @@ build = (callback) ->
buildParser()
buildExceptParser callback
-transpile = (code) ->
+transpile = (code, options = {}) ->
+ options.minify = process.env.MINIFY isnt 'false'
+ options.transform = process.env.TRANSFORM isnt 'false'
babel = require '@babel/core'
presets = []
# Exclude the `modules` plugin in order to not break the `}(this));`
# at the end of the `build:browser` code block.
- presets.push ['@babel/env', {modules: no}] unless process.env.TRANSFORM is 'false'
- presets.push ['minify', {mangle: no, evaluate: no, removeUndefined: no}] unless process.env.MINIFY is 'false'
+ presets.push ['@babel/env', {modules: no}] if options.transform
+ presets.push ['minify', {mangle: no, evaluate: no, removeUndefined: no}] if options.minify
babelOptions =
- compact: process.env.MINIFY isnt 'false'
+ compact: not options.minify
+ comments: not options.minify
presets: presets
sourceType: 'script'
{ code } = babel.transform code, babelOptions unless presets.length is 0
@@ -140,13 +143,18 @@ task 'build:browser', 'merge the built scripts into a single file for use in a b
return module.exports;
})();
"""
+ # From here, we generate two outputs: a legacy script output for all browsers
+ # and a module output for browsers that support `
+
-
-
+
+
+
diff --git a/docs/v2/test.html b/docs/v2/test.html
index e9ff2bf1..587fffe6 100644
--- a/docs/v2/test.html
+++ b/docs/v2/test.html
@@ -3,7 +3,12 @@