| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.js_emitter.startup_emitter.model_emitter; | 5 library dart2js.js_emitter.startup_emitter.model_emitter; |
| 6 | 6 |
| 7 import 'dart:convert' show JsonEncoder; | 7 import 'dart:convert' show JsonEncoder; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' | 9 import 'package:js_runtime/shared/embedded_names.dart' |
| 10 show | 10 show |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 buildGeneratedBy(), | 259 buildGeneratedBy(), |
| 260 new js.Comment(HOOKS_API_USAGE), | 260 new js.Comment(HOOKS_API_USAGE), |
| 261 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), | 261 isSplit ? buildDeferredInitializerGlobal() : new js.Block.empty(), |
| 262 code | 262 code |
| 263 ]); | 263 ]); |
| 264 | 264 |
| 265 mainOutput.addBuffer( | 265 mainOutput.addBuffer( |
| 266 js.createCodeBuffer(program, compiler, monitor: compiler.dumpInfoTask)); | 266 js.createCodeBuffer(program, compiler, monitor: compiler.dumpInfoTask)); |
| 267 | 267 |
| 268 if (shouldGenerateSourceMap) { | 268 if (shouldGenerateSourceMap) { |
| 269 mainOutput.add(generateSourceMapTag( | 269 mainOutput.add(SourceMapBuilder.generateSourceMapTag( |
| 270 compiler.options.sourceMapUri, compiler.options.outputUri)); | 270 compiler.options.sourceMapUri, compiler.options.outputUri)); |
| 271 } | 271 } |
| 272 | 272 |
| 273 mainOutput.close(); | 273 mainOutput.close(); |
| 274 | 274 |
| 275 if (shouldGenerateSourceMap) { | 275 if (shouldGenerateSourceMap) { |
| 276 outputSourceMap(mainOutput, lineColumnCollector, '', | 276 SourceMapBuilder.outputSourceMap( |
| 277 compiler.options.sourceMapUri, compiler.options.outputUri); | 277 mainOutput, |
| 278 lineColumnCollector, |
| 279 '', |
| 280 compiler.options.sourceMapUri, |
| 281 compiler.options.outputUri, |
| 282 compiler.outputProvider); |
| 278 } | 283 } |
| 279 } | 284 } |
| 280 | 285 |
| 281 // Writes the given [fragment]'s [code] into a file. | 286 // Writes the given [fragment]'s [code] into a file. |
| 282 // | 287 // |
| 283 // Returns the deferred fragment's hash. | 288 // Returns the deferred fragment's hash. |
| 284 // | 289 // |
| 285 // Updates the shared [outputBuffers] field with the output. | 290 // Updates the shared [outputBuffers] field with the output. |
| 286 String writeDeferredFragment(DeferredFragment fragment, js.Expression code) { | 291 String writeDeferredFragment(DeferredFragment fragment, js.Expression code) { |
| 287 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; | 292 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 compiler.options.sourceMapUri.replace(pathSegments: mapSegments); | 349 compiler.options.sourceMapUri.replace(pathSegments: mapSegments); |
| 345 } | 350 } |
| 346 | 351 |
| 347 if (outputUri != null) { | 352 if (outputUri != null) { |
| 348 List<String> partSegments = outputUri.pathSegments.toList(); | 353 List<String> partSegments = outputUri.pathSegments.toList(); |
| 349 partSegments[partSegments.length - 1] = hunkFileName; | 354 partSegments[partSegments.length - 1] = hunkFileName; |
| 350 partUri = | 355 partUri = |
| 351 compiler.options.outputUri.replace(pathSegments: partSegments); | 356 compiler.options.outputUri.replace(pathSegments: partSegments); |
| 352 } | 357 } |
| 353 | 358 |
| 354 output.add(generateSourceMapTag(mapUri, partUri)); | 359 output.add(SourceMapBuilder.generateSourceMapTag(mapUri, partUri)); |
| 355 output.close(); | 360 output.close(); |
| 356 outputSourceMap(output, lineColumnCollector, partName, mapUri, partUri); | 361 SourceMapBuilder.outputSourceMap(output, lineColumnCollector, partName, |
| 362 mapUri, partUri, compiler.outputProvider); |
| 357 } else { | 363 } else { |
| 358 output.close(); | 364 output.close(); |
| 359 } | 365 } |
| 360 | 366 |
| 361 return hash; | 367 return hash; |
| 362 } | 368 } |
| 363 | 369 |
| 364 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { | |
| 365 if (sourceMapUri != null && fileUri != null) { | |
| 366 String sourceMapFileName = relativize(fileUri, sourceMapUri, false); | |
| 367 return ''' | |
| 368 | |
| 369 //# sourceMappingURL=$sourceMapFileName | |
| 370 '''; | |
| 371 } | |
| 372 return ''; | |
| 373 } | |
| 374 | |
| 375 void outputSourceMap( | |
| 376 CodeOutput output, LineColumnProvider lineColumnProvider, String name, | |
| 377 [Uri sourceMapUri, Uri fileUri]) { | |
| 378 if (!shouldGenerateSourceMap) return; | |
| 379 // Create a source file for the compilation output. This allows using | |
| 380 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. | |
| 381 SourceMapBuilder sourceMapBuilder = | |
| 382 new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider); | |
| 383 output.forEachSourceLocation(sourceMapBuilder.addMapping); | |
| 384 String sourceMap = sourceMapBuilder.build(); | |
| 385 compiler.outputProvider(name, 'js.map', OutputType.js_map) | |
| 386 ..add(sourceMap) | |
| 387 ..close(); | |
| 388 } | |
| 389 | |
| 390 /// Writes a mapping from library-name to hunk files. | 370 /// Writes a mapping from library-name to hunk files. |
| 391 /// | 371 /// |
| 392 /// The output is written into a separate file that can be used by outside | 372 /// The output is written into a separate file that can be used by outside |
| 393 /// tools. | 373 /// tools. |
| 394 void writeDeferredMap() { | 374 void writeDeferredMap() { |
| 395 Map<String, dynamic> mapping = new Map<String, dynamic>(); | 375 Map<String, dynamic> mapping = new Map<String, dynamic>(); |
| 396 // Json does not support comments, so we embed the explanation in the | 376 // Json does not support comments, so we embed the explanation in the |
| 397 // data. | 377 // data. |
| 398 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 378 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 399 "needed for a given deferred library import."; | 379 "needed for a given deferred library import."; |
| 400 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 380 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 401 compiler.outputProvider( | 381 compiler.outputProvider( |
| 402 compiler.options.deferredMapUri.path, '', OutputType.info) | 382 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 403 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 383 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 404 ..close(); | 384 ..close(); |
| 405 } | 385 } |
| 406 } | 386 } |
| OLD | NEW |