leading `then` is now valid

This commit is contained in:
satyr 2010-10-26 05:36:32 +09:00
parent b2be475f93
commit 426d71cb4f
4 changed files with 12 additions and 3 deletions

View File

@ -228,6 +228,10 @@
return this.scanTokens(function(token, i, tokens) {
var _ref, _ref2, action, condition, indent, outdent, starter, tag;
tag = token[0];
if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') {
tokens.splice(i, 1);
return 0;
}
if (tag === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
tokens.splice.apply(tokens, [i, 0].concat(this.indentation(token)));
return 2;

View File

@ -715,9 +715,8 @@ exports.Class = class Class extends Base
ctor.body.unshift new Literal "this.#{pname} = function() { #{ret} }"
if pvar
access = if prop.context is 'this'
pvar.properties[0]
else
new Accessor pvar, 'proto'
then pvar.properties[0]
else new Accessor pvar, 'proto'
val = new Value variable, [access]
prop = new Assign val, func
props.push prop

View File

@ -194,6 +194,9 @@ class exports.Rewriter
addImplicitIndentation: ->
@scanTokens (token, i, tokens) ->
[tag] = token
if tag is 'TERMINATOR' and @tag(i + 1) is 'THEN'
tokens.splice i, 1
return 0
if tag is 'ELSE' and @tag(i - 1) isnt 'OUTDENT'
tokens.splice i, 0, @indentation(token)...
return 2

View File

@ -131,6 +131,9 @@ result =
ok result is 70
if 'tight formatting with leading `then` is allowed'
then ok 'yay'
else throw 'boo'
# Issue #738
func = if true then -> 1