Permalink
Browse files

Merge pull request #42 from paulcuth/dev

Fixes issue with return statements in do blocks being ignored.
  • Loading branch information...
paulcuth committed Jul 31, 2016
2 parents 37ff96f + 98a433b commit 5d6cab36fc3f013f0039a3ec525ac42784dd3392
Showing with 30 additions and 2 deletions.
  1. +1 −1 package.json
  2. +2 −1 src/build-tools/common/code-generator.js
  3. +27 −0 test/lua/control-structures.lua
View
@@ -1,7 +1,7 @@
{
"name": "starlight",
"description": "A Lua -> ES6 transpiler",
"version": "0.3.0",
"version": "0.3.1",
"author": {
"name": "Paul Cuthbertson"
},
@@ -129,7 +129,8 @@ const GENERATORS = {
DoStatement(node, outerScope) {
let { scope, scopeDef } = extendScope(outerScope);
let body = this.Chunk(node, scope);
return `(()=>{\n${scopeDef}\n${body}\n})()`;
scopeDef = scopeDef.replace(',', ';');
return `${scopeDef}\n${body}\n$=$${outerScope};`;
},
@@ -212,3 +212,30 @@ end
assertEqual (b, 'THIS SHOULD EXECUTE', 'If clause with function call should only use first returned value. [2]')
-- do block
local a = 1
local b = 10
do
local a = 2
b = 20
assertEqual (a, 2, 'Do block should use local variables')
assertEqual (b, 20, 'Do block should set upvalues')
end
assertEqual (a, 1, 'Do block should create its own local variable scope')
assertEqual (b, 20, 'Do block should update upvalues')
a = '1'
function testReturn()
a = a..'2'
do
a = a..'3'
return
end
a = a..'X'
end
testReturn()
assertEqual (a, '123', 'Do block containing return should return from parent function')

0 comments on commit 5d6cab3

Please sign in to comment.