Minor cleanup

This commit is contained in:
Geoffrey Booth
2016-09-24 23:23:24 -07:00
parent 568a0c7b4e
commit 1d230fe055
3 changed files with 7 additions and 8 deletions

View File

@@ -225,11 +225,10 @@ grammar =
]
# The **Code** node is the function literal. It's defined by an indented block
# of **Block** preceded by a function arrow, with an optional parameter
# list.
# of **Block** preceded by a function arrow, with an optional parameter list.
Code: [
o 'PARAM_START ParamList PARAM_END FuncGlyph Block', -> new Code $2, $5, $4
o 'FuncGlyph Block', -> new Code [], $2, $1
o 'FuncGlyph Block', -> new Code [], $2, $1
]
# CoffeeScript has two different symbols for functions. `->` is for ordinary

View File

@@ -1661,8 +1661,8 @@ exports.Code = class Code extends Base
params[i] = p.compileToFragments o
o.scope.parameter fragmentsToText params[i]
uniqs = []
@eachParamName (name, node) ->
node.error "multiple parameters named #{name}" if name in uniqs
@eachParamName (name, node) =>
node.error "multiple parameters named '#{name}'" if name in uniqs
uniqs.push name
@body.makeReturn() unless wasEmpty or @noReturn
code = 'function'
@@ -1729,7 +1729,7 @@ exports.Param = class Param extends Base
# The `iterator` function will be called as `iterator(name, node)` where
# `name` is the name of the parameter and `node` is the AST node corresponding
# to that name.
eachName: (iterator, name = @name)->
eachName: (iterator, name = @name) ->
atParam = (obj) -> iterator "@#{obj.properties[0].name.value}", obj
# * simple literals `foo`
return iterator name.value, name if name instanceof Literal

View File

@@ -642,14 +642,14 @@ test "duplicate function arguments", ->
assertErrorFormat '''
(foo, bar, foo) ->
''', '''
[stdin]:1:12: error: multiple parameters named foo
[stdin]:1:12: error: multiple parameters named 'foo'
(foo, bar, foo) ->
^^^
'''
assertErrorFormat '''
(@foo, bar, @foo) ->
''', '''
[stdin]:1:13: error: multiple parameters named @foo
[stdin]:1:13: error: multiple parameters named '@foo'
(@foo, bar, @foo) ->
^^^^
'''