Merge branch 'master' of git://github.com/jashkenas/coffee-script into improved-error-messages

Conflicts:
	lib/coffee-script/coffee-script.js
	lib/coffee-script/command.js
	lib/coffee-script/helpers.js
	lib/coffee-script/lexer.js
	lib/coffee-script/nodes.js
	lib/coffee-script/repl.js
	src/coffee-script.coffee
	src/command.coffee
	src/helpers.coffee
	src/lexer.coffee
	src/nodes.coffee
	test/helpers.coffee
This commit is contained in:
Demian Ferreiro
2013-03-10 20:29:36 -03:00
25 changed files with 570 additions and 357 deletions

View File

@@ -730,13 +730,52 @@ test "#2359: extending native objects that use other typed constructors requires
eq 'yes!', workingArray.method()
test "#2489: removing __bind", ->
test "#2782: non-alphanumeric-named bound functions", ->
class A
'b:c': =>
'd'
class Thing
foo: (a, b, c) ->
bar: (a, b, c) =>
eq (new A)['b:c'](), 'd'
thing = new Thing
eq thing.foo.length, 3
eq thing.bar.length, 3
test "#2781: overriding bound functions", ->
class A
a: ->
@b()
b: =>
1
class B extends A
b: =>
2
b = (new A).b
eq b(), 1
b = (new B).b
eq b(), 2
test "#2791: bound function with destructured argument", ->
class Foo
method: ({a}) => 'Bar'
eq (new Foo).method({a: 'Bar'}), 'Bar'
test "#2796: ditto, ditto, ditto", ->
answer = null
outsideMethod = (func) ->
func.call message: 'wrong!'
class Base
constructor: ->
@message = 'right!'
outsideMethod @echo
echo: =>
answer = @message
new Base
eq answer, 'right!'

View File

@@ -70,3 +70,9 @@ test "#1106: __proto__ compilation", ->
test "reference named hasOwnProperty", ->
CoffeeScript.compile 'hasOwnProperty = 0; a = 1'
test "#1055: invalid keys in real (but not work-product) objects", ->
cantCompile "@key: value"
test "#1066: interpolated strings are not implicit functions", ->
cantCompile '"int#{er}polated" arg'

View File

@@ -2,7 +2,7 @@
# -------
# pull the helpers from `CoffeeScript.helpers` into local variables
{starts, ends, repeat, compact, count, merge, extend, flatten, del, last} = CoffeeScript.helpers
{starts, ends, repeat, compact, count, merge, extend, flatten, del, last, baseFileName} = CoffeeScript.helpers
# `starts`
@@ -103,3 +103,33 @@ test "the `last` helper returns the last item of an array-like object", ->
test "the `last` helper allows one to specify an optional offset", ->
ary = [0, 1, 2, 3, 4]
eq 2, last(ary, 2)
# `baseFileName`
test "the `baseFileName` helper returns the file name to write to", ->
ext = '.js'
sourceToCompiled =
'.coffee': ext
'a.coffee': 'a' + ext
'b.coffee': 'b' + ext
'coffee.coffee': 'coffee' + ext
'.litcoffee': ext
'a.litcoffee': 'a' + ext
'b.litcoffee': 'b' + ext
'coffee.litcoffee': 'coffee' + ext
'.lit': ext
'a.lit': 'a' + ext
'b.lit': 'b' + ext
'coffee.lit': 'coffee' + ext
'.coffee.md': ext
'a.coffee.md': 'a' + ext
'b.coffee.md': 'b' + ext
'coffee.coffee.md': 'coffee' + ext
for sourceFileName, expectedFileName of sourceToCompiled
name = baseFileName sourceFileName, yes
filename = name + ext
eq filename, expectedFileName

View File

@@ -36,8 +36,12 @@ test "SourceMap tests", ->
map.addMapping [1, 9], [2, 8]
map.addMapping [3, 0], [3, 4]
eqJson (sourcemap.generateV3SourceMap map, "source.coffee", "source.js"), '{"version":3,"file":"source.js","sourceRoot":"","sources":["source.coffee"],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
eqJson (sourcemap.generateV3SourceMap map), '{"version":3,"file":null,"sourceRoot":"","sources":[],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
testWithFilenames = sourcemap.generateV3SourceMap map, {
sourceRoot: "",
sourceFiles: ["source.coffee"],
generatedFile: "source.js"}
eqJson testWithFilenames, '{"version":3,"file":"source.js","sourceRoot":"","sources":["source.coffee"],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
eqJson (sourcemap.generateV3SourceMap map), '{"version":3,"file":"","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
# Look up a generated column - should get back the original source position.
arrayEq map.getSourcePosition([2,8]), [1,9]