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 '../../common.dart'; | 9 import '../../common.dart'; |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // The full code that is written to each hunk part-file. | 79 // The full code that is written to each hunk part-file. |
80 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; | 80 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; |
81 | 81 |
82 | 82 |
83 JavaScriptBackend get backend => compiler.backend; | 83 JavaScriptBackend get backend => compiler.backend; |
84 | 84 |
85 /// For deferred loading we communicate the initializers via this global var. | 85 /// For deferred loading we communicate the initializers via this global var. |
86 static const String deferredInitializersGlobal = | 86 static const String deferredInitializersGlobal = |
87 r"$__dart_deferred_initializers__"; | 87 r"$__dart_deferred_initializers__"; |
88 | 88 |
| 89 static const String partExtension = "part"; |
89 static const String deferredExtension = "part.js"; | 90 static const String deferredExtension = "part.js"; |
90 | 91 |
91 static const String typeNameProperty = r"builtin$cls"; | 92 static const String typeNameProperty = r"builtin$cls"; |
92 | 93 |
93 ModelEmitter(Compiler compiler, Namer namer, this.nativeEmitter, | 94 ModelEmitter(Compiler compiler, Namer namer, this.nativeEmitter, |
94 this.shouldGenerateSourceMap) | 95 this.shouldGenerateSourceMap) |
95 : this.compiler = compiler, | 96 : this.compiler = compiler, |
96 this.namer = namer { | 97 this.namer = namer { |
97 this.constantEmitter = new ConstantEmitter( | 98 this.constantEmitter = new ConstantEmitter( |
98 compiler, namer, this.generateConstantReference, | 99 compiler, namer, this.generateConstantReference, |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 273 |
273 if (shouldGenerateSourceMap) { | 274 if (shouldGenerateSourceMap) { |
274 mainOutput.add( | 275 mainOutput.add( |
275 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); | 276 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); |
276 } | 277 } |
277 | 278 |
278 mainOutput.close(); | 279 mainOutput.close(); |
279 | 280 |
280 if (shouldGenerateSourceMap) { | 281 if (shouldGenerateSourceMap) { |
281 outputSourceMap(mainOutput, lineColumnCollector, '', | 282 outputSourceMap(mainOutput, lineColumnCollector, '', |
282 compiler.sourceMapUri, compiler.outputUri); | 283 compiler.sourceMapUri, compiler.outputUri); |
283 } | 284 } |
284 } | 285 } |
285 | 286 |
286 // Writes the given [fragment]'s [code] into a file. | 287 // Writes the given [fragment]'s [code] into a file. |
287 // | 288 // |
288 // Returns the deferred fragment's hash. | 289 // Returns the deferred fragment's hash. |
289 // | 290 // |
290 // Updates the shared [outputBuffers] field with the output. | 291 // Updates the shared [outputBuffers] field with the output. |
291 String writeDeferredFragment(DeferredFragment fragment, js.Expression code) { | 292 String writeDeferredFragment(DeferredFragment fragment, js.Expression code) { |
292 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; | 293 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 String hash = hasher.getHash(); | 330 String hash = hasher.getHash(); |
330 | 331 |
331 // Now we copy the deferredInitializer.current into its correct hash. | 332 // Now we copy the deferredInitializer.current into its correct hash. |
332 output.add('\n${deferredInitializersGlobal}["$hash"] = ' | 333 output.add('\n${deferredInitializersGlobal}["$hash"] = ' |
333 '${deferredInitializersGlobal}.current'); | 334 '${deferredInitializersGlobal}.current'); |
334 | 335 |
335 if (shouldGenerateSourceMap) { | 336 if (shouldGenerateSourceMap) { |
336 Uri mapUri, partUri; | 337 Uri mapUri, partUri; |
337 Uri sourceMapUri = compiler.sourceMapUri; | 338 Uri sourceMapUri = compiler.sourceMapUri; |
338 Uri outputUri = compiler.outputUri; | 339 Uri outputUri = compiler.outputUri; |
| 340 String partName = "$hunkPrefix.$partExtension"; |
| 341 String hunkFileName = "$hunkPrefix.$deferredExtension"; |
339 | 342 |
340 if (sourceMapUri != null) { | 343 if (sourceMapUri != null) { |
341 String mapFileName = | 344 String mapFileName = hunkFileName + ".map"; |
342 hunkPrefix + deferredExtension + ".map"; | |
343 List<String> mapSegments = sourceMapUri.pathSegments.toList(); | 345 List<String> mapSegments = sourceMapUri.pathSegments.toList(); |
344 mapSegments[mapSegments.length - 1] = mapFileName; | 346 mapSegments[mapSegments.length - 1] = mapFileName; |
345 mapUri = compiler.sourceMapUri.replace(pathSegments: mapSegments); | 347 mapUri = compiler.sourceMapUri.replace(pathSegments: mapSegments); |
346 } | 348 } |
347 | 349 |
348 if (outputUri != null) { | 350 if (outputUri != null) { |
349 String hunkFileName = hunkPrefix + deferredExtension; | |
350 List<String> partSegments = outputUri.pathSegments.toList(); | 351 List<String> partSegments = outputUri.pathSegments.toList(); |
351 partSegments[partSegments.length - 1] = hunkFileName; | 352 partSegments[partSegments.length - 1] = hunkFileName; |
352 partUri = compiler.outputUri.replace(pathSegments: partSegments); | 353 partUri = compiler.outputUri.replace(pathSegments: partSegments); |
353 } | 354 } |
354 | 355 |
355 output.add(generateSourceMapTag(mapUri, partUri)); | 356 output.add(generateSourceMapTag(mapUri, partUri)); |
356 output.close(); | 357 output.close(); |
357 outputSourceMap(output, lineColumnCollector, hunkPrefix, mapUri, partUri); | 358 outputSourceMap(output, lineColumnCollector, partName, mapUri, partUri); |
358 } else { | 359 } else { |
359 output.close(); | 360 output.close(); |
360 } | 361 } |
361 | 362 |
362 return hash; | 363 return hash; |
363 } | 364 } |
364 | 365 |
365 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { | 366 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { |
366 if (sourceMapUri != null && fileUri != null) { | 367 if (sourceMapUri != null && fileUri != null) { |
367 String sourceMapFileName = relativize(fileUri, sourceMapUri, false); | 368 String sourceMapFileName = relativize(fileUri, sourceMapUri, false); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // Json does not support comments, so we embed the explanation in the | 401 // Json does not support comments, so we embed the explanation in the |
401 // data. | 402 // data. |
402 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 403 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
403 "needed for a given deferred library import."; | 404 "needed for a given deferred library import."; |
404 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 405 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
405 compiler.outputProvider(compiler.deferredMapUri.path, 'deferred_map') | 406 compiler.outputProvider(compiler.deferredMapUri.path, 'deferred_map') |
406 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 407 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
407 ..close(); | 408 ..close(); |
408 } | 409 } |
409 } | 410 } |
OLD | NEW |