Regular expressions s (dotAll) flag (#4880)

* Support ES2018 regex dotall flag

* Test in Node 9

* Alphabetize regex flags

* Split regex dotall test into its own file, use new feature detection method of loading it

* Update docs to explain compatibility for ES2018 and newer Node features

* Remove unnecessary paragraph
This commit is contained in:
Geoffrey Booth
2018-03-30 15:25:41 -07:00
committed by GitHub
parent 195a46ab77
commit 47c491ffa1
7 changed files with 18 additions and 5 deletions

View File

@@ -452,6 +452,7 @@ runTests = (CoffeeScript) ->
skipUnless 'async () => {}', ['async.coffee', 'async_iterators.coffee']
skipUnless 'async function* generator() { yield 42; }', ['async_iterators.coffee']
skipUnless 'var a = 2 ** 2; a **= 3', ['exponentiation.coffee']
skipUnless '/foo.bar/s.test("foo\tbar")', ['regex_dotall.coffee']
files = fs.readdirSync('test').filter (filename) ->
filename not in testFilesToSkip

View File

@@ -1,5 +1,10 @@
### Compatibility
With the exception of [modules](#modules) (`import` and `export` statements) and [JSX](#jsx), all the modern JavaScript features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScripts output without any further processing required. You can [run the tests in your browser](test.html) to see if your browser can do the same. For older browsers or older versions of Node, however, [transpilation](#transpilation) is required.
Most modern JavaScript features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScripts output without any further processing required. Here are some notable exceptions:
Support for modern JavaScript syntax is important to ensure compatibility with frameworks that assume modern features. Now that CoffeeScript compiles classes to the `class` keyword, its possible to `extend` a JavaScript class; that wasnt possible in CoffeeScript 1. Parity in how language features work is also important on its own; CoffeeScript “is just JavaScript,” and so things like [function parameter default values](#breaking-changes-default-values) should behave the same in CoffeeScript as in JavaScript. Some such features behave slightly differently in JavaScript than they did in CoffeeScript 1; in such cases we are conforming with the JavaScript spec, and weve documented the differences as [breaking changes](#breaking-changes).
* [JSX](#jsx) always requires transpilation.
* [Modules](#modules) (`import` and `export` statements) are supported by Node 10+, provided you specify an output filename with an `.mjs` extension (or rename the extensions of the generated `.js` files) and execute such files via `node`, not `coffee`.
* [Splats, a.k.a. object rest/spread syntax, for objects](http://coffeescript.org/#splats) are supported by Node 8.6+.
* The [regular expression `s` (dotall) flag](https://github.com/tc39/proposal-regexp-dotall-flag) is supported by Node 9+.
This list may be incomplete, and excludes versions of Node that support newer features behind flags; please refer to [node.green](http://node.green/) for full details. You can [run the tests in your browser](test.html) to see what your browser supports. It is your responsibility to ensure that your runtime supports the modern features you use; or that you [transpile](#transpilation) your code. When in doubt, transpile.

View File

@@ -8,6 +8,6 @@ codeFor('modules')
<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 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.
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, unless you know that your code will be executed by a runtime that supports [ES modules](https://nodejs.org/api/esm.html). Node supports such modules only for files with `.mjs` extensions; you can generate such an extension via the `coffee` command for a single file via `--output`, as in `coffee --compile --output index.mjs index.coffee`. When compiling folders or globs, it is your responsibility to rename the generated `.js` files as needed.
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.

View File

@@ -1610,7 +1610,7 @@
REGEX_FLAGS = /^\w*/;
VALID_FLAGS = /^(?!.*(.).*\1)[imguy]*$/;
VALID_FLAGS = /^(?!.*(.).*\1)[gimsuy]*$/;
// Match any character, except those that need special handling below.
// Match `\` followed by any character.

View File

@@ -1261,7 +1261,7 @@ REGEX = /// ^
///
REGEX_FLAGS = /^\w*/
VALID_FLAGS = /^(?!.*(.).*\1)[imguy]*$/
VALID_FLAGS = /^(?!.*(.).*\1)[gimsuy]*$/
HEREGEX = /// ^
(?:

7
test/regex_dotall.coffee Normal file
View File

@@ -0,0 +1,7 @@
# Regex “dotall” flag, or `s`, is only supported in Node 9+, so put tests for
# the feature in their own file. The feature detection in `Cakefile` that
# causes this test to load is adapted from
# https://github.com/tc39/proposal-regexp-dotall-flag#proposed-solution.
test "dotall flag", ->
doesNotThrow -> /a.b/s.test 'a\nb'