|
264 | 264 | });
|
265 | 265 | // --- <Specific Traceur Parsing Code> ---
|
266 | 266 |
|
267 |
| - // parse function is used to parse a load record |
268 |
| - // Returns an array of ModuleSpecifiers |
| 267 | + System.traceurOptions = {modules: 'instantiate'}; |
| 268 | + |
| 269 | + // parse function is used to parse a load record |
| 270 | + // Returns an array of ModuleSpecifiers |
269 | 271 | System.parse = function(load) {
|
270 | 272 | if (!traceur) {
|
271 | 273 | if (typeof window == 'undefined')
|
|
278 | 280 |
|
279 | 281 | console.assert(load.source, 'Non-empty source');
|
280 | 282 |
|
281 |
| - var depsList, curSystem, oldSourceMaps, oldModules; |
| 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 | + var depsList; |
282 | 293 | (function () {
|
283 | 294 | try {
|
284 |
| - |
285 |
| - var parser = new traceur.syntax.Parser(new traceur.syntax.SourceFile(load.address, load.source)); |
286 |
| - var body = parser.parseModule(); |
287 |
| - |
288 | 295 | load.kind = 'declarative';
|
289 |
| - depsList = getImports(body); |
290 |
| - |
291 |
| - oldSourceMaps = traceur.options.sourceMaps; |
292 |
| - oldModules = traceur.options.modules; |
293 |
| - |
294 |
| - traceur.options.sourceMaps = true; |
295 |
| - traceur.options.modules = 'instantiate'; |
296 |
| - |
297 |
| - var reporter = new traceur.util.ErrorReporter(); |
298 |
| - |
299 |
| - reporter.reportMessageInternal = function(location, kind, format, args) { |
300 |
| - throw new SyntaxError(kind, location.start && location.start.line_, location.start && location.start.column_); |
301 |
| - } |
302 |
| - |
303 |
| - // traceur expects its version of System |
304 |
| - curSystem = global.System; |
305 |
| - global.System = global.traceurSystem; |
306 | 296 |
|
307 |
| - var tree = (new traceur.codegeneration.module.AttachModuleNameTransformer(load.name)).transformAny(body); |
308 |
| - tree = (new traceur.codegeneration.FromOptionsTransformer(reporter)).transform(tree); |
| 297 | + var compiler = new traceur.Compiler(); |
| 298 | + var options = System.traceurOptions || {}; |
| 299 | + var output = compiler.stringToTree({content: load.source, options: options}); |
| 300 | + checkForErrors(output); |
309 | 301 |
|
310 |
| - var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: load.address }); |
311 |
| - var options = { sourceMapGenerator: sourceMapGenerator }; |
| 302 | + depsList = getImports(output.tree); |
| 303 | + output = compiler.treeToTree(output); |
| 304 | + checkForErrors(output); |
312 | 305 |
|
313 |
| - var source = traceur.outputgeneration.TreeWriter.write(tree, options); |
| 306 | + output = compiler.treeToString(output); |
| 307 | + checkForErrors(output); |
| 308 | + var source = output.js; |
| 309 | + var sourceMap = output.generatedSourceMap; |
314 | 310 |
|
315 |
| - if (global.btoa) |
316 |
| - source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n'; |
| 311 | + if (global.btoa && sourceMap) |
| 312 | + source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(sourceMap))) + '\n'; |
317 | 313 |
|
318 | 314 | __eval(source, global, load);
|
319 | 315 | }
|
320 | 316 | catch(e) {
|
321 | 317 | if (e.name == 'SyntaxError' || e.name == 'TypeError')
|
322 | 318 | e.message = 'Evaluating ' + (load.name || load.address) + '\n\t' + e.message;
|
323 |
| - if (curSystem) |
324 |
| - global.System = curSystem; |
325 |
| - if (oldSourceMaps) |
326 |
| - traceur.options.sourceMaps = oldSourceMaps; |
327 |
| - if (oldModules) |
328 |
| - traceur.options.modules = oldModules; |
329 | 319 | throw e;
|
330 | 320 | }
|
331 | 321 | }());
|
332 |
| - global.System = curSystem; |
333 |
| - traceur.options.sourceMaps = oldSourceMaps; |
334 |
| - traceur.options.modules = oldModules; |
335 | 322 | return depsList;
|
336 | 323 | }
|
337 | 324 |
|
|
385 | 372 | if (typeof exports === 'object')
|
386 | 373 | module.exports = System;
|
387 | 374 |
|
388 |
| - if (global.System && global.traceur) |
389 |
| - global.traceurSystem = global.System; |
390 | 375 | global.System = System;
|
391 | 376 | })();
|
392 | 377 |
|
|
0 commit comments