Skip to content

Commit

Permalink
done refactoring Class for now...
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Nov 13, 2010
1 parent 9a5546c commit 6f47364
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Cakefile
Expand Up @@ -149,7 +149,7 @@ runTests = (CoffeeScript) ->
CoffeeScript.run code.toString(), {fileName}
catch err
failedTests += 1
log "failed #{fileName}", red, '\n' + err.stack.toString()
log "failed #{fileName}", red, '\n' + err.stack?.toString()


task 'test', 'run the CoffeeScript language test suite', ->
Expand Down
51 changes: 19 additions & 32 deletions lib/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 13 additions & 18 deletions src/nodes.coffee
Expand Up @@ -712,24 +712,19 @@ exports.Class = class Class extends Base

# Walk the body of the class, looking for prototype properties to be converted.
walkBody: (name) ->
for node, i in exps = @body.expressions
if node instanceof Value and node.isObject(true)
exps[i] = compact @addProperties node, name
else if node instanceof Code
if @ctor
throw new Error 'cannot define more than one constructor in a class'
if node.bound
throw new Error 'cannot define a constructor as a bound function'
@ctor = node
exps[i] = null
else
node.traverseChildren false, (n2) =>
if n2 instanceof Expressions
for expr2, j in n2.expressions
if expr2 instanceof Value and expr2.isObject(true)
n2.expressions[j] = compact @addProperties expr2, name
n2.expressions = flatten n2.expressions
@body.expressions = exps = compact flatten exps
@traverseChildren false, (child) =>
if child instanceof Expressions
for node, i in exps = child.expressions
if node instanceof Value and node.isObject(true)
exps[i] = compact @addProperties node, name
else if node instanceof Code
if @ctor
throw new Error 'cannot define more than one constructor in a class'
if node.bound
throw new Error 'cannot define a constructor as a bound function'
@ctor = node
exps[i] = null
child.expressions = exps = compact flatten exps

# Make sure that a constructor is defined for the class, and properly
# configured.
Expand Down

0 comments on commit 6f47364

Please sign in to comment.