Fix #1069. Non-callable literals shouldn't compile

This commit is contained in:
Michal Srb
2013-04-23 04:28:45 +02:00
parent 4b4f6ac222
commit fd61476106
4 changed files with 67 additions and 10 deletions

View File

@@ -9,6 +9,9 @@
# shared identity function
id = (_) -> if arguments.length is 1 then _ else [arguments...]
# helper to assert that a string should fail compilation
cantCompile = (code) ->
throws -> CoffeeScript.compile code
test "basic argument passing", ->
@@ -649,3 +652,25 @@ test "Loose tokens inside of explicit call lists", ->
bar = first( first
one: 1)
eq bar.one, 1
test "Non-callable literals shouldn't compile", ->
cantCompile '1(2)'
cantCompile '1 2'
cantCompile '/t/(2)'
cantCompile '/t/ 2'
cantCompile '///t///(2)'
cantCompile '///t/// 2'
cantCompile "''(2)"
cantCompile "'' 2"
cantCompile '""(2)'
cantCompile '"" 2'
cantCompile '""""""(2)'
cantCompile '"""""" 2'
cantCompile '{}(2)'
cantCompile '{} 2'
cantCompile '[](2)'
cantCompile '[] 2'
cantCompile '[2..9] 2'
cantCompile '[2..9](2)'
cantCompile '[1..10][2..9] 2'
cantCompile '[1..10][2..9](2)'

View File

@@ -130,5 +130,5 @@ test "soaked constructor invocations with caching and property access", ->
eq 1, semaphore
test "soaked function invocation safe on non-functions", ->
eq undefined, 0?(1)
eq undefined, 0? 1, 2
eq undefined, (0)?(1)
eq undefined, (0)? 1, 2