Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2905223002: Cherry-picks of multiple html CLs
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/dev_compiler/lib/sdk/ddc_sdk.sum ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 6015 matching lines...) Expand 10 before | Expand all | Expand 10 after
6026 } 6026 }
6027 // TODO(vsm): This is not necessarily unique if '__' appears in a file name. 6027 // TODO(vsm): This is not necessarily unique if '__' appears in a file name.
6028 var encodedSeparator = '__'; 6028 var encodedSeparator = '__';
6029 String qualifiedPath; 6029 String qualifiedPath;
6030 if (uri.scheme == 'package') { 6030 if (uri.scheme == 'package') {
6031 // Strip the package name. 6031 // Strip the package name.
6032 // TODO(vsm): This is not unique if an escaped '/'appears in a filename. 6032 // TODO(vsm): This is not unique if an escaped '/'appears in a filename.
6033 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide. 6033 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide.
6034 qualifiedPath = uri.pathSegments.skip(1).join(encodedSeparator); 6034 qualifiedPath = uri.pathSegments.skip(1).join(encodedSeparator);
6035 } else if (isWithin(libraryRoot, uri.toFilePath())) { 6035 } else if (isWithin(libraryRoot, uri.toFilePath())) {
6036 qualifiedPath = uri.path 6036 qualifiedPath = relative(uri.toFilePath(), from: libraryRoot)
6037 .substring(libraryRoot.length)
6038 .replaceAll(separator, encodedSeparator); 6037 .replaceAll(separator, encodedSeparator);
6039 } else { 6038 } else {
6040 // We don't have a unique name. 6039 // We don't have a unique name.
6041 throw 'Invalid library root. $libraryRoot does not contain ${uri 6040 throw 'Invalid library root. $libraryRoot does not contain ${uri
6042 .toFilePath()}'; 6041 .toFilePath()}';
6043 } 6042 }
6044 return pathToJSIdentifier(qualifiedPath); 6043 return pathToJSIdentifier(qualifiedPath);
6045 } 6044 }
6046 6045
6047 /// Debugger friendly name for a Dart Library. 6046 /// Debugger friendly name for a Dart Library.
6048 String jsLibraryDebuggerName(String libraryRoot, LibraryElement library) { 6047 String jsLibraryDebuggerName(String libraryRoot, LibraryElement library) {
6049 var uri = library.source.uri; 6048 var uri = library.source.uri;
6050 // For package: and dart: uris show the entire 6049 // For package: and dart: uris show the entire
6051 if (uri.scheme == 'dart' || uri.scheme == 'package') return uri.toString(); 6050 if (uri.scheme == 'dart' || uri.scheme == 'package') return uri.toString();
6052 6051
6053 var filePath = uri.toFilePath(); 6052 var filePath = uri.toFilePath();
6054 if (!isWithin(libraryRoot, filePath)) { 6053 if (!isWithin(libraryRoot, filePath)) {
6055 throw 'Invalid library root. $libraryRoot does not contain ${uri 6054 throw 'Invalid library root. $libraryRoot does not contain ${uri
6056 .toFilePath()}'; 6055 .toFilePath()}';
6057 } 6056 }
6058 // Relative path to the library. 6057 // Relative path to the library.
6059 return relative(filePath, from: libraryRoot); 6058 return relative(filePath, from: libraryRoot);
6060 } 6059 }
6061 6060
6062 String jsDebuggingLibraryName(String libraryRoot, LibraryElement library) {
6063 var uri = library.source.uri;
6064 if (uri.scheme == 'dart') {
6065 return uri.path;
6066 }
6067 // TODO(vsm): This is not necessarily unique if '__' appears in a file name.
6068 var separator = '__';
6069 String qualifiedPath;
6070 if (uri.scheme == 'package') {
6071 // Strip the package name.
6072 // TODO(vsm): This is not unique if an escaped '/'appears in a filename.
6073 // E.g., "foo/bar.dart" and "foo$47bar.dart" would collide.
6074 qualifiedPath = uri.pathSegments.skip(1).join(separator);
6075 } else if (uri.toFilePath().startsWith(libraryRoot)) {
6076 qualifiedPath =
6077 uri.path.substring(libraryRoot.length).replaceAll('/', separator);
6078 } else {
6079 // We don't have a unique name.
6080 throw 'Invalid library root. $libraryRoot does not contain ${uri
6081 .toFilePath()}';
6082 }
6083 return pathToJSIdentifier(qualifiedPath);
6084 }
6085
6086 /// Shorthand for identifier-like property names. 6061 /// Shorthand for identifier-like property names.
6087 /// For now, we emit them as strings and the printer restores them to 6062 /// For now, we emit them as strings and the printer restores them to
6088 /// identifiers if it can. 6063 /// identifiers if it can.
6089 // TODO(jmesserly): avoid the round tripping through quoted form. 6064 // TODO(jmesserly): avoid the round tripping through quoted form.
6090 JS.LiteralString _propertyName(String name) => js.string(name, "'"); 6065 JS.LiteralString _propertyName(String name) => js.string(name, "'");
6091 6066
6092 // TODO(jacobr): we would like to do something like the following 6067 // TODO(jacobr): we would like to do something like the following
6093 // but we don't have summary support yet. 6068 // but we don't have summary support yet.
6094 // bool _supportJsExtensionMethod(AnnotatedNode node) => 6069 // bool _supportJsExtensionMethod(AnnotatedNode node) =>
6095 // _getAnnotation(node, "SupportJsExtensionMethod") != null; 6070 // _getAnnotation(node, "SupportJsExtensionMethod") != null;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
6128 if (targetIdentifier.staticElement is! PrefixElement) return false; 6103 if (targetIdentifier.staticElement is! PrefixElement) return false;
6129 var prefix = targetIdentifier.staticElement as PrefixElement; 6104 var prefix = targetIdentifier.staticElement as PrefixElement;
6130 6105
6131 // The library the prefix is referring to must come from a deferred import. 6106 // The library the prefix is referring to must come from a deferred import.
6132 var containingLibrary = resolutionMap 6107 var containingLibrary = resolutionMap
6133 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 6108 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
6134 .library; 6109 .library;
6135 var imports = containingLibrary.getImportsWithPrefix(prefix); 6110 var imports = containingLibrary.getImportsWithPrefix(prefix);
6136 return imports.length == 1 && imports[0].isDeferred; 6111 return imports.length == 1 && imports[0].isDeferred;
6137 } 6112 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/sdk/ddc_sdk.sum ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698