diff options
| -rw-r--r-- | spec/outputs/test/with_statement_spec.lua | 16 | ||||
| -rw-r--r-- | spec/outputs/with.lua | 2 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 9 |
3 files changed, 11 insertions, 16 deletions
diff --git a/spec/outputs/test/with_statement_spec.lua b/spec/outputs/test/with_statement_spec.lua index e6f64e8..8031364 100644 --- a/spec/outputs/test/with_statement_spec.lua +++ b/spec/outputs/test/with_statement_spec.lua | |||
| @@ -201,16 +201,12 @@ return describe("with statement", function() | |||
| 201 | local result | 201 | local result |
| 202 | do | 202 | do |
| 203 | local _with_0 = nil | 203 | local _with_0 = nil |
| 204 | do | 204 | repeat |
| 205 | local _accum_0 = { } | 205 | if _with_0 ~= nil then |
| 206 | repeat | 206 | result = _with_0.value |
| 207 | if _with_0 ~= nil then | 207 | break |
| 208 | result = _with_0.value | 208 | end |
| 209 | break | 209 | until true |
| 210 | end | ||
| 211 | until true | ||
| 212 | result = _accum_0 | ||
| 213 | end | ||
| 214 | end | 210 | end |
| 215 | return assert.same(result, nil) | 211 | return assert.same(result, nil) |
| 216 | end) | 212 | end) |
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index ce0e495..a9126be 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua | |||
| @@ -212,14 +212,12 @@ do | |||
| 212 | local _val_0 | 212 | local _val_0 |
| 213 | while true do | 213 | while true do |
| 214 | local _with_0 = tb | 214 | local _with_0 = tb |
| 215 | local _accum_0 = { } | ||
| 216 | repeat | 215 | repeat |
| 217 | if _with_0 ~= nil then | 216 | if _with_0 ~= nil then |
| 218 | _val_0 = 1 | 217 | _val_0 = 1 |
| 219 | break | 218 | break |
| 220 | end | 219 | end |
| 221 | until true | 220 | until true |
| 222 | _val_0 = _accum_0 | ||
| 223 | break | 221 | break |
| 224 | end | 222 | end |
| 225 | a = _val_0 | 223 | a = _val_0 |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index bd52d33..caeee53 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -10391,6 +10391,10 @@ private: | |||
| 10391 | if (breakWithVar.empty()) { | 10391 | if (breakWithVar.empty()) { |
| 10392 | transformIf(ifNode, temp, ExpUsage::Common); | 10392 | transformIf(ifNode, temp, ExpUsage::Common); |
| 10393 | } else { | 10393 | } else { |
| 10394 | if (extraBreakVar) { | ||
| 10395 | addToScope(breakWithVar); | ||
| 10396 | temp.push_back(indent() + "local "s + breakWithVar + nl(with)); | ||
| 10397 | } | ||
| 10394 | auto simpleValue = x->new_ptr<SimpleValue_t>(); | 10398 | auto simpleValue = x->new_ptr<SimpleValue_t>(); |
| 10395 | simpleValue->value.set(ifNode); | 10399 | simpleValue->value.set(ifNode); |
| 10396 | auto exp = newExp(simpleValue, x); | 10400 | auto exp = newExp(simpleValue, x); |
| @@ -10404,10 +10408,7 @@ private: | |||
| 10404 | auto block = x->new_ptr<Block_t>(); | 10408 | auto block = x->new_ptr<Block_t>(); |
| 10405 | block->statementOrComments.push_back(stmt); | 10409 | block->statementOrComments.push_back(stmt); |
| 10406 | repeatNode->body.set(block); | 10410 | repeatNode->body.set(block); |
| 10407 | auto sVal = x->new_ptr<SimpleValue_t>(); | 10411 | transformRepeat(repeatNode, temp); |
| 10408 | sVal->value.set(repeatNode); | ||
| 10409 | auto asmt = assignmentFrom(toAst<Exp_t>(breakWithVar, x), newExp(sVal, x), x); | ||
| 10410 | transformAssignment(asmt, temp); | ||
| 10411 | } | 10412 | } |
| 10412 | } else { | 10413 | } else { |
| 10413 | bool transformed = false; | 10414 | bool transformed = false; |
