2010-12-30 22:48:31 -05:00
|
|
|
# Compilation
|
|
|
|
# -----------
|
|
|
|
|
|
|
|
# helper to assert that a string should fail compilation
|
|
|
|
cantCompile = (code) ->
|
|
|
|
throws -> CoffeeScript.compile code
|
|
|
|
|
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
test "ensure that carriage returns don't break compilation on Windows", ->
|
|
|
|
doesNotThrow -> CoffeeScript.compile 'one\r\ntwo', bare: on
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2013-10-20 15:21:06 -04:00
|
|
|
test "#3089 - don't mutate passed in options to compile", ->
|
|
|
|
opts = {}
|
|
|
|
CoffeeScript.compile '1 + 1', opts
|
|
|
|
ok !opts.scope
|
|
|
|
|
2011-04-29 15:53:30 -04:00
|
|
|
test "--bare", ->
|
|
|
|
eq -1, CoffeeScript.compile('x = y', bare: on).indexOf 'function'
|
2011-03-11 21:59:17 -05:00
|
|
|
ok 'passed' is CoffeeScript.eval '"passed"', bare: on, filename: 'test'
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2012-01-10 12:54:21 -05:00
|
|
|
test "header (#1778)", ->
|
|
|
|
header = "// Generated by CoffeeScript #{CoffeeScript.VERSION}\n"
|
|
|
|
eq 0, CoffeeScript.compile('x = y', header: on).indexOf header
|
|
|
|
|
2012-01-10 14:03:48 -05:00
|
|
|
test "header is disabled by default", ->
|
|
|
|
header = "// Generated by CoffeeScript #{CoffeeScript.VERSION}\n"
|
|
|
|
eq -1, CoffeeScript.compile('x = y').indexOf header
|
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
test "multiple generated references", ->
|
2010-12-30 22:48:31 -05:00
|
|
|
a = {b: []}
|
|
|
|
a.b[true] = -> this == a.b
|
|
|
|
c = 0
|
|
|
|
d = []
|
|
|
|
ok a.b[0<++c<2] d...
|
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
test "splat on a line by itself is invalid", ->
|
|
|
|
cantCompile "x 'a'\n...\n"
|
|
|
|
|
|
|
|
test "Issue 750", ->
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
cantCompile 'f(->'
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
cantCompile 'a = (break)'
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
cantCompile 'a = (return 5 for item in list)'
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
cantCompile 'a = (return 5 while condition)'
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
cantCompile 'a = for x in y\n return 5'
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2011-03-11 21:59:17 -05:00
|
|
|
test "Issue #986: Unicode identifiers", ->
|
|
|
|
λ = 5
|
|
|
|
eq λ, 5
|
2010-12-30 22:48:31 -05:00
|
|
|
|
|
|
|
test "don't accidentally stringify keywords", ->
|
|
|
|
ok (-> this == 'this')() is false
|
2011-01-10 23:19:31 -05:00
|
|
|
|
|
|
|
test "#1026", ->
|
|
|
|
cantCompile '''
|
|
|
|
if a
|
|
|
|
b
|
|
|
|
else
|
|
|
|
c
|
|
|
|
else
|
|
|
|
d
|
|
|
|
'''
|
2011-01-18 23:10:09 -05:00
|
|
|
|
|
|
|
test "#1050", ->
|
2011-03-11 22:44:18 -05:00
|
|
|
cantCompile "### */ ###"
|
2011-04-27 21:36:29 -04:00
|
|
|
|
2013-11-27 07:58:14 -05:00
|
|
|
test "#1273: escaping quotes at the end of heredocs", ->
|
|
|
|
cantCompile '"""\\"""' # """\"""
|
2013-11-28 10:46:00 -05:00
|
|
|
cantCompile '"""\\\\\\"""' # """\\\"""
|
2013-11-27 07:58:14 -05:00
|
|
|
|
2011-04-27 21:36:29 -04:00
|
|
|
test "#1106: __proto__ compilation", ->
|
|
|
|
object = eq
|
2011-04-27 21:57:22 -04:00
|
|
|
@["__proto__"] = true
|
2011-04-27 21:36:29 -04:00
|
|
|
ok __proto__
|
2011-11-14 11:18:45 -05:00
|
|
|
|
|
|
|
test "reference named hasOwnProperty", ->
|
|
|
|
CoffeeScript.compile 'hasOwnProperty = 0; a = 1'
|
2013-03-05 03:10:56 -05:00
|
|
|
|
2013-03-05 03:28:29 -05:00
|
|
|
test "#1055: invalid keys in real (but not work-product) objects", ->
|
2013-03-05 03:10:56 -05:00
|
|
|
cantCompile "@key: value"
|
2013-03-05 03:28:29 -05:00
|
|
|
|
|
|
|
test "#1066: interpolated strings are not implicit functions", ->
|
|
|
|
cantCompile '"int#{er}polated" arg'
|
2013-03-25 13:56:24 -04:00
|
|
|
|
|
|
|
test "#2846: while with empty body", ->
|
2013-04-21 06:27:30 -04:00
|
|
|
CoffeeScript.compile 'while 1 then', {sourceMap: true}
|
|
|
|
|
|
|
|
test "#2944: implicit call with a regex argument", ->
|
2013-05-25 18:29:26 -04:00
|
|
|
CoffeeScript.compile 'o[key] /regex/'
|
|
|
|
|
|
|
|
test "#3001: `own` shouldn't be allowed in a `for`-`in` loop", ->
|
2013-07-30 11:24:46 -04:00
|
|
|
cantCompile "a for own b in c"
|
|
|
|
|
|
|
|
test "#2994: single-line `if` requires `then`", ->
|
|
|
|
cantCompile "if b else x"
|