|
214 | 214 | } |
215 | 215 |
|
216 | 216 | win.require = name => this.require(name) |
| 217 | + win.module = {exports: {}} |
| 218 | + win.exports = win.module.exports |
217 | 219 | } |
218 | 220 |
|
219 | 221 | resizeFrame() { |
|
293 | 295 | ForInStatement: loop, |
294 | 296 | WhileStatement: loop, |
295 | 297 | DoWhileStatement: loop, |
| 298 | + CallExpression(node) { |
| 299 | + if (node.callee.type == "Identifier" && node.callee.name == "require" && |
| 300 | + node.arguments.length == 1 && node.arguments[0].type == "Literal" && |
| 301 | + typeof node.arguments[0].value == "string" && !dependencies.includes(node.arguments[0].value)) |
| 302 | + dependencies.push(node.arguments[0].value) |
| 303 | + }, |
296 | 304 | ImportDeclaration(node) { |
297 | 305 | dependencies.push(node.source.value) |
298 | 306 | let req = "require(" + node.source.raw + ")", text |
|
318 | 326 | } |
319 | 327 | patches.push({from: node.start, to: node.end, text: text + ";"}) |
320 | 328 | }, |
321 | | - CallExpression(node) { |
322 | | - if (node.callee.type == "Identifier" && node.callee.name == "require" && |
323 | | - node.arguments.length == 1 && node.arguments[0].type == "Literal" && |
324 | | - typeof node.arguments[0].value == "string" && !dependencies.includes(node.arguments[0].value)) |
325 | | - dependencies.push(node.arguments[0].value) |
| 329 | + ExportNamedDeclaration(node) { |
| 330 | + if (node.source || !node.declaration) |
| 331 | + patches.push({from: node.start, to: node.end, text: ""}) |
| 332 | + else |
| 333 | + patches.push({from: node.start, to: node.declaration.start, text: ""}) |
| 334 | + }, |
| 335 | + ExportDefaultDeclaration(node) { |
| 336 | + if (/Declaration/.test(node.declaration.type)) { |
| 337 | + patches.push({from: node.start, to: node.declaration.start, text: ""}) |
| 338 | + } else { |
| 339 | + patches.push({from: node.start, to: node.declaration.start, text: ";("}, |
| 340 | + {from: node.declaration.end, text: ")"}) |
| 341 | + } |
| 342 | + }, |
| 343 | + ExportAllDeclaration: function(node) { |
| 344 | + patches.push({from: node.start, to: node.end, text: ""}) |
326 | 345 | } |
327 | 346 | }) |
328 | 347 |
|
|
349 | 368 | pos = patch.to || patch.from |
350 | 369 | } |
351 | 370 | out += code.slice(pos, code.length) |
352 | | - console.log(out) |
353 | 371 | out += "\n//# sourceURL=code" + randomID() |
354 | 372 | return {code: (strict ? '"use strict";' : "") + out, dependencies} |
355 | 373 | } |
|
0 commit comments