Skip to content

Commit

Permalink
Fixes #494: Forcing named classes in CoffeeScript (named functions) .…
Browse files Browse the repository at this point in the history
….. even in IE.
  • Loading branch information
jashkenas committed Dec 19, 2011
1 parent 8d8c345 commit 1018c51
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/coffee-script/lexer.js

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

61 changes: 60 additions & 1 deletion lib/coffee-script/nodes.js

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

2 changes: 1 addition & 1 deletion lib/coffee-script/optparse.js

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

2 changes: 1 addition & 1 deletion lib/coffee-script/rewriter.js

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

2 changes: 1 addition & 1 deletion lib/coffee-script/scope.js

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

1 change: 1 addition & 0 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ exports.Class = class Class extends Base
@ensureConstructor name
@body.spaced = yes
@body.expressions.unshift @ctor unless @ctor instanceof Code
@body.expressions.unshift new Literal "#{name}.name = '#{name}'" if decl
@body.expressions.push lname
@addBoundFunctions o

Expand Down
12 changes: 11 additions & 1 deletion test/classes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,14 @@ test "#1813: Passing class definitions as expressions", ->
x = 1

eq result, B


test "#494: Named classes", ->

class A
eq A.name, 'A'

class A.B
eq A.B.name, 'B'

class A.B["C"]
ok A.B.C.name isnt 'C'

2 comments on commit 1018c51

@michaelficarra
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. I've wanted this change for a long time.I was 100% behind #1272 and 100% sad when it was turned down. @jashkenas: why the change of heart? We should also probably revert da14538.

/cc @ef4

@jashkenas
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our classes have grown fancier over time. Before they were little more than .prototype = object literal ... now, they're fully executable, with super tricks, static "inheritance" (via copying), named constructors, etc etc. This is just a bit of a further progression towards making them comfy.

It wasn't a strong change of heart -- I liked the previous ticket a lot as well ... just trying to weigh the cost/benefit.

Please sign in to comment.