Skip to content

Commit 27f7ef0

Browse files
committed
allow leading newlines in coffee scripts
1 parent 9a61bbf commit 27f7ef0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/coffee_script/rewriter.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Rewriter
3535
def rewrite(tokens)
3636
@tokens = tokens
3737
adjust_comments
38+
remove_leading_newlines
3839
remove_mid_expression_newlines
3940
move_commas_outside_outdents
4041
add_implicit_indentation
@@ -82,6 +83,12 @@ def adjust_comments
8283
end
8384
end
8485

86+
# Leading newlines would introduce an ambiguity in the grammar, so we
87+
# dispatch them here.
88+
def remove_leading_newlines
89+
@tokens.shift if @tokens[0][0] == "\n"
90+
end
91+
8592
# Some blocks occur in the middle of expressions -- when we're expecting
8693
# this, remove their trailing newlines.
8794
def remove_mid_expression_newlines

0 commit comments

Comments
 (0)