Skip to content

Commit

Permalink
cleaned up trailing whitespace; merging @geraldalewis's jashkenas#2033
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Jan 16, 2012
1 parent 9a23511 commit e207c98
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,13 @@ exports.Class = class Class extends Base
child.expressions = exps = flatten exps

# `use strict` (and other directives) must be the first expression statement(s)
# of a function body. This method ensures the prologue is correctly positioned
# of a function body. This method ensures the prologue is correctly positioned
# above the `constructor`.
hoistDirectivePrologue: ->
index = 0
{expressions} = @body
++index while (node = expressions[index]) and
node instanceof Comment or
node instanceof Value and
node.isString()
++index while (node = expressions[index]) and node instanceof Comment or
node instanceof Value and node.isString()
@directives = expressions.splice 0, index

# Make sure that a constructor is defined for the class, and properly
Expand Down
14 changes: 7 additions & 7 deletions test/classes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -612,25 +612,25 @@ test "#1966: external constructors should produce their return value", ->
ok (new A) not instanceof A

test "#1980: regression with an inherited class with static function members", ->

class A

class B extends A
@static: => 'value'

eq B.static(), 'value'

test "#1534: class then 'use strict'", ->
# [14.1 Directive Prologues and the Use Strict Directive](http://es5.github.com/#x14.1)
nonce = {}
error = 'do -> ok this'
strictTest = "do ->'use strict';#{error}"
return unless (try CoffeeScript.run strictTest, bare: yes catch e then nonce) is nonce

throws -> CoffeeScript.run "class then 'use strict';#{error}", bare: yes
doesNotThrow -> CoffeeScript.run "class then #{error}", bare: yes
doesNotThrow -> CoffeeScript.run "class then #{error};'use strict'", bare: yes

# comments are ignored in the Directive Prologue
comments = ["""
class
Expand All @@ -652,8 +652,8 @@ test "#1534: class then 'use strict'", ->
### comment 3 ###"""
]
throws (-> CoffeeScript.run comment, bare: yes) for comment in comments
# [ES5](http://es5.github.com/#x14.1) allows for other, implementation-specific, directives

# [ES5 §14.1](http://es5.github.com/#x14.1) allows for other directives
directives = ["""
class
'directive 1'
Expand Down

0 comments on commit e207c98

Please sign in to comment.