|
16 | 16 |
|
17 | 17 | var isBrowser = typeof window != 'undefined';
|
18 | 18 | var Loader = global.Reflect && global.Reflect.Loader || require('./loader');
|
19 |
| - var Promise = global.Promise || require('es6-promise').Promise; |
| 19 | + var Promise = global.Promise || require('when/es6-shim/Promise'); |
20 | 20 |
|
21 | 21 | // Helpers
|
22 | 22 | // Absolute URL parsing, from https://gist.github.com/Yaffle/1088850
|
|
266 | 266 |
|
267 | 267 | System.traceurOptions = {modules: 'instantiate'};
|
268 | 268 |
|
| 269 | + function checkForErrors(output, load) { |
| 270 | + if (output.errors.length) { |
| 271 | + for (var i = 0, l = output.errors.length; i < l; i++) |
| 272 | + console.error(output.errors[i]); |
| 273 | + throw new Error('Parse of ' + load.name + ', ' + load.address + ' failed, ' + output.errors.length); |
| 274 | + } |
| 275 | + } |
| 276 | + |
269 | 277 | // parse function is used to parse a load record
|
270 | 278 | // Returns an array of ModuleSpecifiers
|
271 | 279 | System.parse = function(load) {
|
|
280 | 288 |
|
281 | 289 | console.assert(load.source, 'Non-empty source');
|
282 | 290 |
|
283 |
| - function checkForErrors(output) { |
284 |
| - if (output.errors.length) { |
285 |
| - output.errors.map(function(error) { |
286 |
| - console.error(error); |
287 |
| - }); |
288 |
| - throw new Error('Parse failed, ' + output.errors.length); |
289 |
| - } |
290 |
| - } |
291 |
| - |
292 | 291 | var depsList;
|
293 |
| - (function () { |
294 |
| - try { |
295 |
| - load.kind = 'declarative'; |
296 | 292 |
|
297 |
| - var compiler = new traceur.Compiler(); |
298 |
| - var options = System.traceurOptions || {}; |
299 |
| - var output = compiler.stringToTree({content: load.source, options: options}); |
300 |
| - checkForErrors(output); |
| 293 | + load.kind = 'declarative'; |
301 | 294 |
|
302 |
| - depsList = getImports(output.tree); |
303 |
| - output = compiler.treeToTree(output); |
304 |
| - checkForErrors(output); |
| 295 | + var compiler = new traceur.Compiler(); |
| 296 | + var options = System.traceurOptions || {}; |
| 297 | + var output = compiler.stringToTree({content: load.source, options: options}); |
| 298 | + checkForErrors(output); |
305 | 299 |
|
306 |
| - output = compiler.treeToString(output); |
307 |
| - checkForErrors(output); |
308 |
| - var source = output.js; |
309 |
| - var sourceMap = output.generatedSourceMap; |
| 300 | + depsList = getImports(output.tree); |
| 301 | + output = compiler.treeToTree(output); |
| 302 | + checkForErrors(output); |
310 | 303 |
|
311 |
| - if (global.btoa && sourceMap) |
312 |
| - source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(sourceMap))) + '\n'; |
| 304 | + output = compiler.treeToString(output); |
| 305 | + checkForErrors(output); |
| 306 | + var source = output.js; |
| 307 | + var sourceMap = output.generatedSourceMap; |
| 308 | + |
| 309 | + if (global.btoa && sourceMap) |
| 310 | + source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(sourceMap))) + '\n'; |
| 311 | + |
| 312 | + __eval(source, global, load); |
313 | 313 |
|
314 |
| - __eval(source, global, load); |
315 |
| - } |
316 |
| - catch(e) { |
317 |
| - if (e.name == 'SyntaxError' || e.name == 'TypeError') |
318 |
| - e.message = 'Evaluating ' + (load.name || load.address) + '\n\t' + e.message; |
319 |
| - throw e; |
320 |
| - } |
321 |
| - }()); |
322 | 314 | return depsList;
|
323 | 315 | }
|
324 | 316 |
|
|
384 | 376 | // store the registered declaration as load.declare
|
385 | 377 | load.declare = typeof name == 'string' ? declare : deps;
|
386 | 378 | }
|
387 |
| - eval('var __moduleName = "' + (load.name || '').replace('"', '\"') + '"; (function() { ' + __source + ' \n }).call(__global);'); |
| 379 | + try { |
| 380 | + eval('var __moduleName = "' + (load.name || '').replace('"', '\"') + '"; (function() { ' + __source + ' \n }).call(__global);'); |
| 381 | + } |
| 382 | + catch(e) { |
| 383 | + if (e.name == 'SyntaxError' || e.name == 'TypeError') |
| 384 | + e.message = 'Evaluating ' + (load.name || load.address) + '\n\t' + e.message; |
| 385 | + throw e; |
| 386 | + } |
388 | 387 |
|
389 | 388 | System.register = System.__curRegister;
|
390 | 389 | delete System.__curRegister;
|
|
0 commit comments