mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #1662 from geraldalewis/1195_trailing_semicolons
#1195 Ignore trailing semicolons
This commit is contained in:
@@ -275,6 +275,9 @@
|
||||
}
|
||||
}
|
||||
if (dent) this.outdebt -= moveOut;
|
||||
while (this.value() === ';') {
|
||||
this.tokens.pop();
|
||||
}
|
||||
if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
|
||||
this.token('TERMINATOR', '\n');
|
||||
}
|
||||
@@ -294,6 +297,9 @@
|
||||
}
|
||||
};
|
||||
Lexer.prototype.newlineToken = function() {
|
||||
while (this.value() === ';') {
|
||||
this.tokens.pop();
|
||||
}
|
||||
if (this.tag() !== 'TERMINATOR') this.token('TERMINATOR', '\n');
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -279,6 +279,7 @@ exports.Lexer = class Lexer
|
||||
@outdebt = 0
|
||||
@token 'OUTDENT', dent
|
||||
@outdebt -= moveOut if dent
|
||||
@tokens.pop() while @value() is ';'
|
||||
@token 'TERMINATOR', '\n' unless @tag() is 'TERMINATOR' or noNewlines
|
||||
this
|
||||
|
||||
@@ -293,6 +294,7 @@ exports.Lexer = class Lexer
|
||||
|
||||
# Generate a newline token. Consecutive newlines get merged together.
|
||||
newlineToken: ->
|
||||
@tokens.pop() while @value() is ';'
|
||||
@token 'TERMINATOR', '\n' unless @tag() is 'TERMINATOR'
|
||||
this
|
||||
|
||||
|
||||
@@ -121,3 +121,16 @@ test "indented heredoc", ->
|
||||
test "#1492: Nested blocks don't cause double semicolons", ->
|
||||
js = CoffeeScript.compile '(0;0)'
|
||||
eq -1, js.indexOf ';;'
|
||||
|
||||
test "#1195 Ignore trailing semicolons (before newlines or as the last char in a program)", ->
|
||||
preNewline = (numSemicolons) ->
|
||||
"""
|
||||
nonce = {}; nonce2 = {}
|
||||
f = -> nonce#{Array(numSemicolons+1).join(';')}
|
||||
nonce2
|
||||
unless f() is nonce then throw new Error('; before linebreak should = newline')
|
||||
"""
|
||||
CoffeeScript.run(preNewline(n), bare: true) for n in [1,2,3]
|
||||
|
||||
lastChar = '-> lastChar;'
|
||||
doesNotThrow -> CoffeeScript.compile lastChar, bare: true
|
||||
|
||||
Reference in New Issue
Block a user