Regular expressions `s` (dotAll) flag (#4880) · jashkenas/coffeescript@47c491f

7 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -452,6 +452,7 @@ runTests = (CoffeeScript) ->

452452

skipUnless 'async () => {}', ['async.coffee', 'async_iterators.coffee']

453453

skipUnless 'async function* generator() { yield 42; }', ['async_iterators.coffee']

454454

skipUnless 'var a = 2 ** 2; a **= 3', ['exponentiation.coffee']

455+

skipUnless '/foo.bar/s.test("foo\tbar")', ['regex_dotall.coffee']

455456

files = fs.readdirSync('test').filter (filename) ->

456457

filename not in testFilesToSkip

457458
Original file line numberDiff line numberDiff line change

@@ -1,5 +1,10 @@

11

### Compatibility

22
3-

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 CoffeeScript’s 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.

3+

Most modern JavaScript features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScript’s output without any further processing required. Here are some notable exceptions:

44
5-

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, it’s possible to `extend` a JavaScript class; that wasn’t 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 we’ve documented the differences as [breaking changes](#breaking-changes).

5+

* [JSX](#jsx) always requires transpilation.

6+

* [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`.

7+

* [Splats, a.k.a. object rest/spread syntax, for objects](http://coffeescript.org/#splats) are supported by Node 8.6+.

8+

* The [regular expression `s` (dotall) flag](https://github.com/tc39/proposal-regexp-dotall-flag) is supported by Node 9+.

9+
10+

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.

Original file line numberDiff line numberDiff line change

@@ -8,6 +8,6 @@ codeFor('modules')

88
99

<div id="modules-note" class="bookmark"></div>

1010
11-

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.

11+

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.

1212
1313

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.

Original file line numberDiff line numberDiff line change

@@ -1261,7 +1261,7 @@ REGEX = /// ^

12611261

///

12621262
12631263

REGEX_FLAGS = /^\w*/

1264-

VALID_FLAGS = /^(?!.*(.).*\1)[imguy]*$/

1264+

VALID_FLAGS = /^(?!.*(.).*\1)[gimsuy]*$/

12651265
12661266

HEREGEX = /// ^

12671267

(?:

File renamed without changes.

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,7 @@

1+

# Regex “dotall” flag, or `s`, is only supported in Node 9+, so put tests for

2+

# the feature in their own file. The feature detection in `Cakefile` that

3+

# causes this test to load is adapted from

4+

# https://github.com/tc39/proposal-regexp-dotall-flag#proposed-solution.

5+
6+

test "dotall flag", ->

7+

doesNotThrow -> /a.b/s.test 'a\nb'