diff options
| author | Li Jin <dragon-fly@qq.com> | 2024-03-25 08:25:06 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2024-03-25 08:25:06 +0800 |
| commit | 21004f1fb9b2f6129a231a6c8d99179f0d6e3edf (patch) | |
| tree | d94c69b9758e0e8ff38dc5f23bc888d084846110 /src | |
| parent | 4e3656da3711fd045fdf90dec7084bd4556c5b7f (diff) | |
| download | yuescript-21004f1fb9b2f6129a231a6c8d99179f0d6e3edf.tar.gz yuescript-21004f1fb9b2f6129a231a6c8d99179f0d6e3edf.tar.bz2 yuescript-21004f1fb9b2f6129a231a6c8d99179f0d6e3edf.zip | |
remove one more redundant 'do' block from destructuring.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 14cb3e6..9208d5d 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -2170,7 +2170,7 @@ private: | |||
| 2170 | if (!destruct.inlineAssignment && destruct.items.size() == 1) { | 2170 | if (!destruct.inlineAssignment && destruct.items.size() == 1) { |
| 2171 | auto& pair = destruct.items.front(); | 2171 | auto& pair = destruct.items.front(); |
| 2172 | if (pair.targetVar.empty() && pair.defVal) { | 2172 | if (pair.targetVar.empty() && pair.defVal) { |
| 2173 | extraScope = true; | 2173 | if (needScope) extraScope = true; |
| 2174 | auto objVar = getUnusedName("_tmp_"sv); | 2174 | auto objVar = getUnusedName("_tmp_"sv); |
| 2175 | auto objExp = toAst<Exp_t>(objVar, pair.target); | 2175 | auto objExp = toAst<Exp_t>(objVar, pair.target); |
| 2176 | leftPairs.push_back({pair.target, objExp.get()}); | 2176 | leftPairs.push_back({pair.target, objExp.get()}); |
| @@ -2221,8 +2221,10 @@ private: | |||
| 2221 | if (isLocalValue) { | 2221 | if (isLocalValue) { |
| 2222 | objVar = destruct.valueVar; | 2222 | objVar = destruct.valueVar; |
| 2223 | } else { | 2223 | } else { |
| 2224 | temp.push_back(indent() + "do"s + nll(x)); | 2224 | if (needScope) { |
| 2225 | pushScope(); | 2225 | temp.push_back(indent() + "do"s + nll(x)); |
| 2226 | pushScope(); | ||
| 2227 | } | ||
| 2226 | objVar = getUnusedName("_obj_"sv); | 2228 | objVar = getUnusedName("_obj_"sv); |
| 2227 | auto newAssignment = assignmentFrom(toAst<Exp_t>(objVar, x), destruct.value, x); | 2229 | auto newAssignment = assignmentFrom(toAst<Exp_t>(objVar, x), destruct.value, x); |
| 2228 | transformAssignment(newAssignment, temp); | 2230 | transformAssignment(newAssignment, temp); |
| @@ -2234,9 +2236,11 @@ private: | |||
| 2234 | auto newAssignment = assignmentFrom(pair.target, valueExp, x); | 2236 | auto newAssignment = assignmentFrom(pair.target, valueExp, x); |
| 2235 | transformAssignment(newAssignment, temp, optionalDestruct); | 2237 | transformAssignment(newAssignment, temp, optionalDestruct); |
| 2236 | if (!isLocalValue) { | 2238 | if (!isLocalValue) { |
| 2237 | popScope(); | 2239 | if (needScope) { |
| 2238 | _buf << indent() << "end"sv << nlr(x); | 2240 | popScope(); |
| 2239 | temp.push_back(clearBuf()); | 2241 | _buf << indent() << "end"sv << nlr(x); |
| 2242 | temp.push_back(clearBuf()); | ||
| 2243 | } | ||
| 2240 | } | 2244 | } |
| 2241 | } else { | 2245 | } else { |
| 2242 | str_list defs; | 2246 | str_list defs; |
| @@ -2249,7 +2253,7 @@ private: | |||
| 2249 | defs.push_back(item.targetVar); | 2253 | defs.push_back(item.targetVar); |
| 2250 | } | 2254 | } |
| 2251 | } else if (item.defVal) { | 2255 | } else if (item.defVal) { |
| 2252 | extraScope = true; | 2256 | if (needScope) extraScope = true; |
| 2253 | auto objVar = getUnusedName("_tmp_"sv); | 2257 | auto objVar = getUnusedName("_tmp_"sv); |
| 2254 | addToScope(objVar); | 2258 | addToScope(objVar); |
| 2255 | auto objExp = toAst<Exp_t>(objVar, item.target); | 2259 | auto objExp = toAst<Exp_t>(objVar, item.target); |
| @@ -2285,9 +2289,11 @@ private: | |||
| 2285 | } | 2289 | } |
| 2286 | temp.push_back(indent() + "local "s + join(defs, ", "sv) + nll(x)); | 2290 | temp.push_back(indent() + "local "s + join(defs, ", "sv) + nll(x)); |
| 2287 | } | 2291 | } |
| 2288 | extraScope = true; | 2292 | if (needScope) { |
| 2289 | temp.push_back(indent() + "do"s + nll(x)); | 2293 | extraScope = true; |
| 2290 | pushScope(); | 2294 | temp.push_back(indent() + "do"s + nll(x)); |
| 2295 | pushScope(); | ||
| 2296 | } | ||
| 2291 | auto valVar = getUnusedName("_obj_"sv); | 2297 | auto valVar = getUnusedName("_obj_"sv); |
| 2292 | auto targetVar = toAst<Exp_t>(valVar, destruct.value); | 2298 | auto targetVar = toAst<Exp_t>(valVar, destruct.value); |
| 2293 | auto newAssignment = assignmentFrom(targetVar, destruct.value, destruct.value); | 2299 | auto newAssignment = assignmentFrom(targetVar, destruct.value, destruct.value); |
| @@ -2298,7 +2304,7 @@ private: | |||
| 2298 | } | 2304 | } |
| 2299 | } | 2305 | } |
| 2300 | if (destruct.inlineAssignment) { | 2306 | if (destruct.inlineAssignment) { |
| 2301 | if (!extraScope) { | 2307 | if (needScope && !extraScope) { |
| 2302 | extraScope = true; | 2308 | extraScope = true; |
| 2303 | temp.push_back(indent() + "do"s + nll(x)); | 2309 | temp.push_back(indent() + "do"s + nll(x)); |
| 2304 | pushScope(); | 2310 | pushScope(); |
