Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/ast.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Chain, Call, List, Obj, Prop, Arr, Unary, Binary, Assign, Import, Of, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, While, For, Try, Switch, Case, If, Label, Pipe, JS, Util, Vars, DECLS, ref$, UTILS, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, slice$ = [].slice, replace$ = ''.replace;
var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Chain, Call, List, Obj, Prop, Arr, Unary, Binary, Assign, Import, Of, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, ReturnVoid, While, For, Try, Switch, Case, If, Label, Pipe, JS, Util, Vars, DECLS, ref$, UTILS, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, slice$ = [].slice, replace$ = ''.replace;
(Node = function(){
throw Error('unimplemented');
}).prototype = {
Expand Down Expand Up @@ -2623,6 +2623,23 @@ exports.Return = Return = (function(superclass){
};
return Return;
}(Jump));
exports.ReturnVoid = ReturnVoid = (function(superclass){
ReturnVoid.displayName = 'ReturnVoid';
var prototype = extend$(ReturnVoid, superclass).prototype, constructor = ReturnVoid;
function ReturnVoid(it){
var this$ = this instanceof ctor$ ? this : new ctor$;
this$.it = it;
return this$;
} function ctor$(){} ctor$.prototype = prototype;
prototype.getJump = THIS;
prototype.compileNode = function(o){
if (!this.it) {
this.carp("Can't hush a return without a value");
}
return "return void " + this.it.compile(o, LEVEL_PAREN) + ";";
};
return ReturnVoid;
}(Jump));
exports.While = While = (function(superclass){
While.displayName = 'While';
var prototype = extend$(While, superclass).prototype, constructor = While;
Expand Down
7 changes: 6 additions & 1 deletion lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@ exports.doID = function(code, index){
return input.length;
}
switch (id) {
case 'void':
if (last[0] === 'HURL' && last[1] === 'return') {
last[1] = 'returnvoid';
return 4;
}
// fallthrough
case 'true':
case 'false':
case 'null':
case 'void':
case 'arguments':
case 'debugger':
tag = 'LITERAL';
Expand Down
3 changes: 2 additions & 1 deletion lib/parser.js

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

11 changes: 11 additions & 0 deletions src/ast.co
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,17 @@ class exports.Return extends Jump
compileNode: (o) ->
"return#{ if @it then ' ' + that.compile o, LEVEL_PAREN else '' };"

#### Return void
class exports.ReturnVoid extends Jump
(@it) ~>

getJump: THIS

compileNode: (o) ->
@carp "Can't hush a return without a value" unless @it
"return void #{ @it.compile o, LEVEL_PAREN };"


#### While
# The traditional `while`/`for`/`do` loop.
# Returns an array of values collected from the last expression when requested.
Expand Down
7 changes: 6 additions & 1 deletion src/lexer.co
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ exports import
return input.length
# keywords
switch id
case \true \false \null \void \arguments \debugger then tag = \LITERAL
case \void
if last.0 is \HURL and last.1 is \return
last.1 = \returnvoid
return 4
fallthrough
case \true \false \null \arguments \debugger then tag = \LITERAL
case \new \do \typeof \delete then tag = \UNARY
case \return \throw then tag = \HURL
case \break \continue then tag = \JUMP
Expand Down
3 changes: 3 additions & 0 deletions test/compilation.co
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,6 @@ Coco.compile 'class A; class B; class C'

# [livescript#279](https://github.com/gkz/LiveScript/issues/279)
Coco.compile \################################################################

# Can't hush an empty return
compileThrows "Can't hush a return without a value" 1 '-> return void'
4 changes: 4 additions & 0 deletions test/function.co
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,7 @@ let
eq a, b
eq c, d
eq e, f


### can hush a return
eq void, do -> return void true