|
17 | 17 | local _obj_0 = require("moonscript.transform.statements") |
18 | 18 | Run, transform_last_stm, last_stm, chain_is_stub = _obj_0.Run, _obj_0.transform_last_stm, _obj_0.last_stm, _obj_0.chain_is_stub |
19 | 19 | end |
| 20 | +local Transformer |
| 21 | +Transformer = require("moonscript.transform.transformer").Transformer |
20 | 22 | local destructure = require("moonscript.transform.destructure") |
21 | 23 | local NOOP = { |
22 | 24 | "noop" |
23 | 25 | } |
24 | | -local is_singular, extract_declarations, expand_elseif_assign, constructor_name, with_continue_listener, Transformer, construct_comprehension, Statement, Accumulator, default_accumulator, implicitly_return, Value |
| 26 | +local is_singular, extract_declarations, expand_elseif_assign, constructor_name, with_continue_listener, construct_comprehension, Statement, Accumulator, default_accumulator, implicitly_return, Value |
25 | 27 | is_singular = function(body) |
26 | 28 | if #body ~= 1 then |
27 | 29 | return false |
@@ -170,74 +172,6 @@ with_continue_listener = function(body) |
170 | 172 | end) |
171 | 173 | } |
172 | 174 | end |
173 | | -do |
174 | | - local _class_0 |
175 | | - local _base_0 = { |
176 | | - transform_once = function(self, scope, node, ...) |
177 | | - if self.seen_nodes[node] then |
178 | | - return node |
179 | | - end |
180 | | - self.seen_nodes[node] = true |
181 | | - local transformer = self.transformers[ntype(node)] |
182 | | - if transformer then |
183 | | - return transformer(scope, node, ...) or node |
184 | | - else |
185 | | - return node |
186 | | - end |
187 | | - end, |
188 | | - transform = function(self, scope, node, ...) |
189 | | - if self.seen_nodes[node] then |
190 | | - return node |
191 | | - end |
192 | | - self.seen_nodes[node] = true |
193 | | - while true do |
194 | | - local transformer = self.transformers[ntype(node)] |
195 | | - local res |
196 | | - if transformer then |
197 | | - res = transformer(scope, node, ...) or node |
198 | | - else |
199 | | - res = node |
200 | | - end |
201 | | - if res == node then |
202 | | - return node |
203 | | - end |
204 | | - node = res |
205 | | - end |
206 | | - return node |
207 | | - end, |
208 | | - bind = function(self, scope) |
209 | | - return function(...) |
210 | | - return self:transform(scope, ...) |
211 | | - end |
212 | | - end, |
213 | | - __call = function(self, ...) |
214 | | - return self:transform(...) |
215 | | - end, |
216 | | - can_transform = function(self, node) |
217 | | - return self.transformers[ntype(node)] ~= nil |
218 | | - end |
219 | | - } |
220 | | - _base_0.__index = _base_0 |
221 | | - _class_0 = setmetatable({ |
222 | | - __init = function(self, transformers) |
223 | | - self.transformers = transformers |
224 | | - self.seen_nodes = setmetatable({ }, { |
225 | | - __mode = "k" |
226 | | - }) |
227 | | - end, |
228 | | - __base = _base_0, |
229 | | - __name = "Transformer" |
230 | | - }, { |
231 | | - __index = _base_0, |
232 | | - __call = function(cls, ...) |
233 | | - local _self_0 = setmetatable({}, _base_0) |
234 | | - cls.__init(_self_0, ...) |
235 | | - return _self_0 |
236 | | - end |
237 | | - }) |
238 | | - _base_0.__class = _class_0 |
239 | | - Transformer = _class_0 |
240 | | -end |
241 | 175 | construct_comprehension = function(inner, clauses) |
242 | 176 | local current_stms = inner |
243 | 177 | for _, clause in reversed(clauses) do |
@@ -1135,60 +1069,60 @@ Statement = Transformer({ |
1135 | 1069 | "__parent" |
1136 | 1070 | } |
1137 | 1071 | } |
1138 | | - if chain then |
1139 | | - local chain_tail = { |
1140 | | - unpack(chain, 3) |
| 1072 | + if not (chain) then |
| 1073 | + return relative_parent |
| 1074 | + end |
| 1075 | + local chain_tail = { |
| 1076 | + unpack(chain, 3) |
| 1077 | + } |
| 1078 | + local head = chain_tail[1] |
| 1079 | + if head == nil then |
| 1080 | + return relative_parent |
| 1081 | + end |
| 1082 | + local new_chain = relative_parent |
| 1083 | + local _exp_1 = head[1] |
| 1084 | + if "call" == _exp_1 then |
| 1085 | + local calling_name = block:get("current_block") |
| 1086 | + assert(calling_name, "missing calling name") |
| 1087 | + chain_tail[1] = { |
| 1088 | + "call", |
| 1089 | + { |
| 1090 | + "self", |
| 1091 | + unpack(head[2]) |
| 1092 | + } |
1141 | 1093 | } |
1142 | | - local head = chain_tail[1] |
1143 | | - if head == nil then |
1144 | | - return relative_parent |
| 1094 | + if ntype(calling_name) == "key_literal" then |
| 1095 | + insert(new_chain, { |
| 1096 | + "dot", |
| 1097 | + calling_name[2] |
| 1098 | + }) |
| 1099 | + else |
| 1100 | + insert(new_chain, { |
| 1101 | + "index", |
| 1102 | + calling_name |
| 1103 | + }) |
1145 | 1104 | end |
1146 | | - local new_chain = relative_parent |
1147 | | - local _exp_1 = head[1] |
1148 | | - if "call" == _exp_1 then |
1149 | | - local calling_name = block:get("current_block") |
| 1105 | + elseif "colon" == _exp_1 then |
| 1106 | + local call = chain_tail[2] |
| 1107 | + if call and call[1] == "call" then |
1150 | 1108 | chain_tail[1] = { |
| 1109 | + "dot", |
| 1110 | + head[2] |
| 1111 | + } |
| 1112 | + chain_tail[2] = { |
1151 | 1113 | "call", |
1152 | 1114 | { |
1153 | 1115 | "self", |
1154 | | - unpack(head[2]) |
| 1116 | + unpack(call[2]) |
1155 | 1117 | } |
1156 | 1118 | } |
1157 | | - if ntype(calling_name) == "key_literal" then |
1158 | | - insert(new_chain, { |
1159 | | - "dot", |
1160 | | - calling_name[2] |
1161 | | - }) |
1162 | | - else |
1163 | | - insert(new_chain, { |
1164 | | - "index", |
1165 | | - calling_name |
1166 | | - }) |
1167 | | - end |
1168 | | - elseif "colon" == _exp_1 then |
1169 | | - local call = chain_tail[2] |
1170 | | - if call and call[1] == "call" then |
1171 | | - chain_tail[1] = { |
1172 | | - "dot", |
1173 | | - head[2] |
1174 | | - } |
1175 | | - chain_tail[2] = { |
1176 | | - "call", |
1177 | | - { |
1178 | | - "self", |
1179 | | - unpack(call[2]) |
1180 | | - } |
1181 | | - } |
1182 | | - end |
1183 | 1119 | end |
1184 | | - for _index_0 = 1, #chain_tail do |
1185 | | - local item = chain_tail[_index_0] |
1186 | | - insert(new_chain, item) |
1187 | | - end |
1188 | | - return new_chain |
1189 | | - else |
1190 | | - return relative_parent |
1191 | 1120 | end |
| 1121 | + for _index_0 = 1, #chain_tail do |
| 1122 | + local item = chain_tail[_index_0] |
| 1123 | + insert(new_chain, item) |
| 1124 | + end |
| 1125 | + return new_chain |
1192 | 1126 | end) |
1193 | 1127 | end), |
1194 | 1128 | { |
|
0 commit comments