Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b28e398

Browse files
authoredMay 6, 2017
[CS2] Docs updates (#4536)
* Docs: named functions and function declarations * No more prototypal `extends`; update docs and example * More comprehensive documentation of the existential operator; closes #1631 * Better document operators, including `from` * No fat arrow class methods anymore * Destructuring shouldn’t say that default values are applied in case of undefined or null * Spinoff generator and async functions into their own sections; reorder things so that the sections on functions come just before classes, and destructuring goes next to the operators (which discuss assignment) * Rewrite “CoffeeScript 2” section, making it less practical and more explanatory; move practical info into “Usage” * Update “Variable Scoping and Lexical Safety” section to remove incorrect reference to Ruby (fixes #2360), add missing details about the safety wrapper, add note about `let`/`const`. * Updated browser compiler * Updated docs * Rewrite Literate CoffeeScript breaking changes * Split apart the “Breaking Changes” and “Unsupported Features” sections into separate sidebar items and files * Add example of `not in`, closes #3281 * Fix words in bold that should be in backticks * Consolidate some breaking changes sections * Add Node API documentation; closes #3551 * Move the chaining documentation out of the changelog into its own section
1 parent eba271d commit b28e398

37 files changed

+941
-700
lines changed
 

‎docs/v2/browser-compiler/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/v2/index.html

+520-329
Large diffs are not rendered by default.

‎docs/v2/test.html

+40-113
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,8 @@ <h1>CoffeeScript Test Suite</h1>
860860
extend = 3
861861
hasProp = 4
862862
value: 5
863-
method: (bind, bind1) => [bind, bind1, extend, hasProp, @value]
864-
{method} = new B
865-
arrayEq [1, 2, 3, 4, 5], method 1, 2
863+
method: (bind, bind1) -> [bind, bind1, extend, hasProp, @value]
864+
arrayEq [1, 2, 3, 4, 5], new B().method 1, 2
866865

867866
modulo = -1 %% 3
868867
eq 2, modulo
@@ -1247,42 +1246,20 @@ <h1>CoffeeScript Test Suite</h1>
12471246
ok instance.name() is 'class'
12481247

12491248

1250-
test "Classes with methods that are pre-bound to the instance, or statically, to the class", ->
1249+
test "Classes with methods that are pre-bound statically, to the class", ->
12511250

12521251
class Dog
12531252
constructor: (name) ->
12541253
@name = name
12551254

1256-
bark: =>
1257-
"#{@name} woofs!"
1258-
12591255
@static = =>
12601256
new this('Dog')
12611257

1262-
spark = new Dog('Spark')
1263-
fido = new Dog('Fido')
1264-
fido.bark = spark.bark
1265-
1266-
ok fido.bark() is 'Spark woofs!'
1267-
12681258
obj = func: Dog.static
12691259

12701260
ok obj.func().name is 'Dog'
12711261

12721262

1273-
test "a bound function in a bound function", ->
1274-
1275-
class Mini
1276-
num: 10
1277-
generate: =>
1278-
for i in [1..3]
1279-
=>
1280-
@num
1281-
1282-
m = new Mini
1283-
eq (func() for func in m.generate()).join(' '), '10 10 10'
1284-
1285-
12861263
test "contructor called with varargs", ->
12871264

12881265
class Connection
@@ -1587,21 +1564,6 @@ <h1>CoffeeScript Test Suite</h1>
15871564
@B: makeFn 2
15881565
constructor: makeFn 3
15891566

1590-
test "#1182: external constructors with bound functions", ->
1591-
fn = ->
1592-
{one: 1}
1593-
this
1594-
class B
1595-
class A
1596-
constructor: fn
1597-
method: => this instanceof A
1598-
ok (new A).method.call(new B)
1599-
1600-
test "#1372: bound class methods with reserved names", ->
1601-
class C
1602-
delete: =>
1603-
ok C::delete
1604-
16051567
test "#1380: `super` with reserved names", ->
16061568
class C
16071569
do: -> super()
@@ -1670,7 +1632,7 @@ <h1>CoffeeScript Test Suite</h1>
16701632
@unbound: ->
16711633
eq this, Store
16721634

1673-
instance: =>
1635+
instance: ->
16741636
ok this instanceof Store
16751637

16761638
Store.bound()
@@ -1833,57 +1795,6 @@ <h1>CoffeeScript Test Suite</h1>
18331795
ok overrideArray instanceof OverrideArray
18341796
eq 'yes!', overrideArray.method()
18351797

1836-
1837-
test "#2782: non-alphanumeric-named bound functions", ->
1838-
class A
1839-
'b:c': =>
1840-
'd'
1841-
1842-
eq (new A)['b:c'](), 'd'
1843-
1844-
1845-
test "#2781: overriding bound functions", ->
1846-
class A
1847-
a: ->
1848-
@b()
1849-
b: =>
1850-
1
1851-
1852-
class B extends A
1853-
b: =>
1854-
2
1855-
1856-
b = (new A).b
1857-
eq b(), 1
1858-
1859-
b = (new B).b
1860-
eq b(), 2
1861-
1862-
1863-
test "#2791: bound function with destructured argument", ->
1864-
class Foo
1865-
method: ({a}) => 'Bar'
1866-
1867-
eq (new Foo).method({a: 'Bar'}), 'Bar'
1868-
1869-
1870-
test "#2796: ditto, ditto, ditto", ->
1871-
answer = null
1872-
1873-
outsideMethod = (func) ->
1874-
func.call message: 'wrong!'
1875-
1876-
class Base
1877-
constructor: ->
1878-
@message = 'right!'
1879-
outsideMethod @echo
1880-
1881-
echo: =>
1882-
answer = @message
1883-
1884-
new Base
1885-
eq answer, 'right!'
1886-
18871798
test "#3063: Class bodies cannot contain pure statements", ->
18881799
throws -> CoffeeScript.compile """
18891800
class extends S
@@ -2095,9 +2006,6 @@ <h1>CoffeeScript Test Suite</h1>
20952006
eq result.super, this
20962007
eq result.param, @param
20972008
eq result.method, @method
2098-
ok result.method isnt Test::method
2099-
2100-
method: =>
21012009

21022010
nonce = {}
21032011
new Test nonce, {}
@@ -2117,8 +2025,6 @@ <h1>CoffeeScript Test Suite</h1>
21172025
super 'not param'
21182026
eq @name, 'not param'
21192027
eq @param, nonce
2120-
ok @method isnt Test::method
2121-
method: =>
21222028
new Test true, nonce
21232029
new Test false, nonce
21242030

@@ -2137,16 +2043,13 @@ <h1>CoffeeScript Test Suite</h1>
21372043
eq (super 'param'), @;
21382044
eq @name, 'param';
21392045
eq @param, nonce;
2140-
ok @method isnt Test::method
21412046
)
21422047
else
21432048
result = (
21442049
eq (super 'not param'), @;
21452050
eq @name, 'not param';
21462051
eq @param, nonce;
2147-
ok @method isnt Test::method
21482052
)
2149-
method: =>
21502053
new Test true, nonce
21512054
new Test false, nonce
21522055

@@ -2348,15 +2251,15 @@ <h1>CoffeeScript Test Suite</h1>
23482251
make: -> "Making a #{@drink}"
23492252

23502253
class B extends A
2351-
make: (@flavor) =>
2254+
make: (@flavor) ->
23522255
super() + " with #{@flavor}"
23532256

23542257
b = new B('Machiato')
23552258
eq b.make('vanilla'), "Making a Machiato with vanilla"
23562259

23572260
# super in a bound function in a bound function
23582261
class C extends A
2359-
make: (@flavor) =>
2262+
make: (@flavor) ->
23602263
func = () =>
23612264
super() + " with #{@flavor}"
23622265
func()
@@ -9638,6 +9541,28 @@ <h1>CoffeeScript Test Suite</h1>
96389541
};"""
96399542
eq toJS(input), output
96409543

9544+
test "export default implicit object", ->
9545+
input = "export default foo: 'bar', baz: 'qux'"
9546+
output = """
9547+
export default {
9548+
foo: 'bar',
9549+
baz: 'qux'
9550+
};"""
9551+
eq toJS(input), output
9552+
9553+
test "export default multiline implicit object", ->
9554+
input = """
9555+
export default
9556+
foo: 'bar',
9557+
baz: 'qux'
9558+
"""
9559+
output = """
9560+
export default {
9561+
foo: 'bar',
9562+
baz: 'qux'
9563+
};"""
9564+
eq toJS(input), output
9565+
96419566
test "export default assignment expression", ->
96429567
input = "export default foo = 'bar'"
96439568
output = """
@@ -10855,6 +10780,18 @@ <h1>CoffeeScript Test Suite</h1>
1085510780
eq 1, obj[1]
1085610781
eq 2, obj.a
1085710782

10783+
test "#1263: Braceless object return", ->
10784+
fn = ->
10785+
return
10786+
a: 1
10787+
b: 2
10788+
c: -> 3
10789+
10790+
obj = fn()
10791+
eq 1, obj.a
10792+
eq 2, obj.b
10793+
eq 3, obj.c()
10794+
1085810795
</script>
1085910796
<script type="text/x-coffeescript" class="test" id="operators">
1086010797
# Operators
@@ -12115,16 +12052,6 @@ <h1>CoffeeScript Test Suite</h1>
1211512052
ret
1211612053
eq (new B).foo(), 10
1211712054

12118-
test "#2331: bound super regression", ->
12119-
class A
12120-
@value = 'A'
12121-
method: -> @constructor.value
12122-
12123-
class B extends A
12124-
method: => super()
12125-
12126-
eq (new B).method(), 'A'
12127-
1212812055
test "#3259: leak with @-params within destructured parameters", ->
1212912056
fn = ({@foo}, [@bar], [{@baz}]) ->
1213012057
foo = bar = baz = false
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1+
# Helper functions
2+
hasProp = {}.hasOwnProperty
3+
extend = (child, parent) ->
4+
ctor = ->
5+
@constructor = child
6+
return
7+
for key of parent
8+
if hasProp.call(parent, key)
9+
child[key] = parent[key]
10+
ctor.prototype = parent.prototype
11+
child.prototype = new ctor
12+
child
13+
14+
115
A = ->
216
B = ->
3-
B extends A
17+
extend B, A
418
B.prototype.foo = -> A::foo.apply this, arguments

‎documentation/examples/do.coffee

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
for filename in list
22
do (filename) ->
3-
fs.readFile filename, (err, contents) ->
4-
compile filename, contents.toString()
3+
if filename not in ['.DS_Store', 'Thumbs.db', 'ehthumbs.db']
4+
fs.readFile filename, (err, contents) ->
5+
compile filename, contents.toString()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
major = 'Computer Science'
2+
3+
unless major?
4+
signUpForClass 'Introduction to Wines'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if window?
2+
environment = 'browser (probably)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Async Functions
2+
3+
ES2017’s [async functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) are supported through the `await` keyword. Like with generators, there's no need for an `async` keyword; an async function in CoffeeScript is simply a function that awaits.
4+
5+
Similar to how `yield return` forces a generator, `await return` may be used to force a function to be async.
6+
7+
```
8+
codeFor('async', true)
9+
```

0 commit comments

Comments
 (0)
Please sign in to comment.