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 | 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:async'; |
6 import 'dart:collection' show HashMap, HashSet; | 7 import 'dart:collection' show HashMap, HashSet; |
7 import 'dart:math' show min, max; | 8 import 'dart:math' show min, max; |
8 | 9 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
11 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 12 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
12 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; | 13 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
13 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 14 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
14 import 'package:analyzer/dart/element/element.dart'; | 15 import 'package:analyzer/dart/element/element.dart'; |
15 import 'package:analyzer/dart/element/type.dart'; | 16 import 'package:analyzer/dart/element/type.dart'; |
| 17 import 'package:analyzer/src/dart/analysis/driver.dart'; |
16 import 'package:analyzer/src/dart/ast/token.dart' show StringToken; | 18 import 'package:analyzer/src/dart/ast/token.dart' show StringToken; |
17 import 'package:analyzer/src/dart/element/element.dart' | 19 import 'package:analyzer/src/dart/element/element.dart' |
18 show FieldElementImpl, LocalVariableElementImpl; | 20 show FieldElementImpl, LocalVariableElementImpl; |
19 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; | 21 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; |
20 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 22 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
21 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 23 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
22 import 'package:analyzer/src/generated/resolver.dart' | 24 import 'package:analyzer/src/generated/resolver.dart' |
23 show TypeProvider, NamespaceBuilder; | 25 show NamespaceBuilder, TypeProvider, TypeProviderImpl; |
24 import 'package:analyzer/src/generated/type_system.dart' | 26 import 'package:analyzer/src/generated/type_system.dart' |
25 show StrongTypeSystemImpl; | 27 show StrongTypeSystemImpl; |
26 import 'package:analyzer/src/summary/idl.dart' show UnlinkedUnit; | 28 import 'package:analyzer/src/summary/idl.dart' show UnlinkedUnit; |
27 import 'package:analyzer/src/summary/link.dart' as summary_link; | 29 import 'package:analyzer/src/summary/link.dart' as summary_link; |
28 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 30 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
29 import 'package:analyzer/src/summary/summarize_ast.dart' | 31 import 'package:analyzer/src/summary/summarize_ast.dart' |
30 show serializeAstUnlinked; | 32 show serializeAstUnlinked; |
31 import 'package:analyzer/src/summary/summarize_elements.dart' | 33 import 'package:analyzer/src/summary/summarize_elements.dart' |
32 show PackageBundleAssembler; | 34 show PackageBundleAssembler; |
33 import 'package:analyzer/src/summary/summary_sdk.dart'; | 35 import 'package:analyzer/src/summary/summary_sdk.dart'; |
(...skipping 15 matching lines...) Expand all Loading... |
49 import 'js_names.dart' as JS; | 51 import 'js_names.dart' as JS; |
50 import 'js_typeref_codegen.dart' show JsTypeRefCodegen; | 52 import 'js_typeref_codegen.dart' show JsTypeRefCodegen; |
51 import 'module_builder.dart' show pathToJSIdentifier; | 53 import 'module_builder.dart' show pathToJSIdentifier; |
52 import 'nullable_type_inference.dart' show NullableTypeInference; | 54 import 'nullable_type_inference.dart' show NullableTypeInference; |
53 import 'reify_coercions.dart' show CoercionReifier; | 55 import 'reify_coercions.dart' show CoercionReifier; |
54 import 'side_effect_analysis.dart' show ConstFieldVisitor, isStateless; | 56 import 'side_effect_analysis.dart' show ConstFieldVisitor, isStateless; |
55 import 'type_utilities.dart'; | 57 import 'type_utilities.dart'; |
56 | 58 |
57 class CodeGenerator extends GeneralizingAstVisitor | 59 class CodeGenerator extends GeneralizingAstVisitor |
58 with ClosureAnnotator, JsTypeRefCodegen, NullableTypeInference { | 60 with ClosureAnnotator, JsTypeRefCodegen, NullableTypeInference { |
59 final AnalysisContext context; | 61 final AnalysisDriver driver; |
60 final SummaryDataStore summaryData; | 62 final SummaryDataStore summaryData; |
61 | 63 |
62 final CompilerOptions options; | 64 final CompilerOptions options; |
63 final StrongTypeSystemImpl rules; | 65 StrongTypeSystemImpl rules; |
64 | 66 |
65 /// The set of libraries we are currently compiling, and the temporaries used | 67 /// The set of libraries we are currently compiling, and the temporaries used |
66 /// to refer to them. | 68 /// to refer to them. |
67 /// | 69 /// |
68 /// We sometimes special case codegen for a single library, as it simplifies | 70 /// We sometimes special case codegen for a single library, as it simplifies |
69 /// name scoping requirements. | 71 /// name scoping requirements. |
70 final _libraries = new Map<LibraryElement, JS.Identifier>(); | 72 final _libraries = new Map<LibraryElement, JS.Identifier>(); |
71 | 73 |
72 /// Imported libraries, and the temporaries used to refer to them. | 74 /// Imported libraries, and the temporaries used to refer to them. |
73 final _imports = new Map<LibraryElement, JS.TemporaryId>(); | 75 final _imports = new Map<LibraryElement, JS.TemporaryId>(); |
(...skipping 27 matching lines...) Expand all Loading... |
101 | 103 |
102 JS.Identifier _extensionSymbolsModule; | 104 JS.Identifier _extensionSymbolsModule; |
103 JS.Identifier _runtimeModule; | 105 JS.Identifier _runtimeModule; |
104 final namedArgumentTemp = new JS.TemporaryId('opts'); | 106 final namedArgumentTemp = new JS.TemporaryId('opts'); |
105 | 107 |
106 final _hasDeferredSupertype = new HashSet<ClassElement>(); | 108 final _hasDeferredSupertype = new HashSet<ClassElement>(); |
107 | 109 |
108 final _eagerTopLevelFields = new HashSet<Element>.identity(); | 110 final _eagerTopLevelFields = new HashSet<Element>.identity(); |
109 | 111 |
110 /// The type provider from the current Analysis [context]. | 112 /// The type provider from the current Analysis [context]. |
111 final TypeProvider types; | 113 TypeProvider types; |
112 | 114 |
113 final LibraryElement dartCoreLibrary; | 115 LibraryElement dartCoreLibrary; |
114 final LibraryElement dartJSLibrary; | 116 LibraryElement dartJSLibrary; |
115 | 117 |
116 /// The dart:async `StreamIterator<>` type. | 118 /// The dart:async `StreamIterator<>` type. |
117 final InterfaceType _asyncStreamIterator; | 119 InterfaceType _asyncStreamIterator; |
118 | 120 |
119 /// The dart:_interceptors JSArray element. | 121 /// The dart:_interceptors JSArray element. |
120 final ClassElement _jsArray; | 122 ClassElement _jsArray; |
121 | 123 |
122 final ClassElement boolClass; | 124 ClassElement boolClass; |
123 final ClassElement intClass; | 125 ClassElement intClass; |
124 final ClassElement interceptorClass; | 126 ClassElement interceptorClass; |
125 final ClassElement nullClass; | 127 ClassElement nullClass; |
126 final ClassElement numClass; | 128 ClassElement numClass; |
127 final ClassElement objectClass; | 129 ClassElement objectClass; |
128 final ClassElement stringClass; | 130 ClassElement stringClass; |
129 final ClassElement functionClass; | 131 ClassElement functionClass; |
130 final ClassElement privateSymbolClass; | 132 ClassElement privateSymbolClass; |
131 | 133 |
132 ConstFieldVisitor _constants; | 134 ConstFieldVisitor _constants; |
133 | 135 |
134 /// The current function body being compiled. | 136 /// The current function body being compiled. |
135 FunctionBody _currentFunction; | 137 FunctionBody _currentFunction; |
136 | 138 |
137 /// Helper class for emitting elements in the proper order to allow | 139 /// Helper class for emitting elements in the proper order to allow |
138 /// JS to load the module. | 140 /// JS to load the module. |
139 ElementLoader _loader; | 141 ElementLoader _loader; |
140 | 142 |
141 BuildUnit _buildUnit; | 143 BuildUnit _buildUnit; |
142 | 144 |
143 String _libraryRoot; | 145 String _libraryRoot; |
144 | 146 |
145 bool _superAllowed = true; | 147 bool _superAllowed = true; |
146 | 148 |
147 List<JS.TemporaryId> _superHelperSymbols = <JS.TemporaryId>[]; | 149 List<JS.TemporaryId> _superHelperSymbols = <JS.TemporaryId>[]; |
148 List<JS.Method> _superHelpers = <JS.Method>[]; | 150 List<JS.Method> _superHelpers = <JS.Method>[]; |
149 | 151 |
150 List<TypeParameterType> _typeParamInConst = null; | 152 List<TypeParameterType> _typeParamInConst = null; |
151 | 153 |
152 /// Whether we are currently generating code for the body of a `JS()` call. | 154 /// Whether we are currently generating code for the body of a `JS()` call. |
153 bool _isInForeignJS = false; | 155 bool _isInForeignJS = false; |
154 | 156 |
155 /// Information about virtual and overridden fields/getters/setters in the | 157 /// Information about virtual and overridden fields/getters/setters in the |
156 /// class we're currently compiling, or `null` if we aren't compiling a class. | 158 /// class we're currently compiling, or `null` if we aren't compiling a class. |
157 ClassPropertyModel _classProperties; | 159 ClassPropertyModel _classProperties; |
158 | 160 |
159 CodeGenerator( | 161 CodeGenerator._( |
160 AnalysisContext c, this.summaryData, this.options, this._extensionTypes) | 162 this.driver, this.summaryData, this.options, this._extensionTypes); |
161 : context = c, | 163 |
162 rules = new StrongTypeSystemImpl(c.typeProvider), | 164 static Future<CodeGenerator> create( |
163 types = c.typeProvider, | 165 AnalysisDriver driver, |
164 _asyncStreamIterator = | 166 SummaryDataStore summaryData, |
165 _getLibrary(c, 'dart:async').getType('StreamIterator').type, | 167 CompilerOptions options, |
166 _jsArray = _getLibrary(c, 'dart:_interceptors').getType('JSArray'), | 168 ExtensionTypeSet extensionTypes) async { |
167 interceptorClass = | 169 CodeGenerator codeGenerator = |
168 _getLibrary(c, 'dart:_interceptors').getType('Interceptor'), | 170 new CodeGenerator._(driver, summaryData, options, extensionTypes); |
169 dartCoreLibrary = _getLibrary(c, 'dart:core'), | 171 await codeGenerator._initialize(); |
170 boolClass = _getLibrary(c, 'dart:core').getType('bool'), | 172 return codeGenerator; |
171 intClass = _getLibrary(c, 'dart:core').getType('int'), | 173 } |
172 numClass = _getLibrary(c, 'dart:core').getType('num'), | 174 |
173 nullClass = _getLibrary(c, 'dart:core').getType('Null'), | 175 Future<Null> _initialize() async { |
174 objectClass = _getLibrary(c, 'dart:core').getType('Object'), | 176 var coreLibrary = await _computeLibraryByUri('dart:core'); |
175 stringClass = _getLibrary(c, 'dart:core').getType('String'), | 177 var asyncLibrary = await _computeLibraryByUri('dart:async'); |
176 functionClass = _getLibrary(c, 'dart:core').getType('Function'), | 178 |
177 privateSymbolClass = | 179 types = new TypeProviderImpl(coreLibrary, asyncLibrary); |
178 _getLibrary(c, 'dart:_internal').getType('PrivateSymbol'), | 180 rules = new StrongTypeSystemImpl(types); |
179 dartJSLibrary = _getLibrary(c, 'dart:js'); | 181 |
| 182 _asyncStreamIterator = asyncLibrary.getType('StreamIterator').type; |
| 183 |
| 184 var interceptorsLibrary = await _computeLibraryByUri('dart:_interceptors'); |
| 185 _jsArray = interceptorsLibrary.getType('JSArray'); |
| 186 interceptorClass = interceptorsLibrary.getType('Interceptor'); |
| 187 |
| 188 dartCoreLibrary = coreLibrary; |
| 189 boolClass = coreLibrary.getType('bool'); |
| 190 intClass = coreLibrary.getType('int'); |
| 191 numClass = coreLibrary.getType('num'); |
| 192 nullClass = coreLibrary.getType('Null'); |
| 193 objectClass = coreLibrary.getType('Object'); |
| 194 stringClass = coreLibrary.getType('String'); |
| 195 functionClass = coreLibrary.getType('Function'); |
| 196 |
| 197 var internalLibrary = await _computeLibraryByUri('dart:_internal'); |
| 198 privateSymbolClass = internalLibrary.getType('PrivateSymbol'); |
| 199 |
| 200 dartJSLibrary = await _computeLibraryByUri('dart:js'); |
| 201 } |
180 | 202 |
181 LibraryElement get currentLibrary => _loader.currentElement.library; | 203 LibraryElement get currentLibrary => _loader.currentElement.library; |
182 | 204 |
183 /// The main entry point to JavaScript code generation. | 205 /// The main entry point to JavaScript code generation. |
184 /// | 206 /// |
185 /// Takes the metadata for the build unit, as well as resolved trees and | 207 /// Takes the metadata for the build unit, as well as resolved trees and |
186 /// errors, and computes the output module code and optionally the source map. | 208 /// errors, and computes the output module code and optionally the source map. |
187 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, | 209 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, |
188 List<String> errors) { | 210 List<String> errors) { |
189 _buildUnit = unit; | 211 _buildUnit = unit; |
190 _libraryRoot = _buildUnit.libraryRoot; | 212 _libraryRoot = _buildUnit.libraryRoot; |
191 if (!_libraryRoot.endsWith(separator)) { | 213 if (!_libraryRoot.endsWith(separator)) { |
192 _libraryRoot += separator; | 214 _libraryRoot += separator; |
193 } | 215 } |
194 | 216 |
195 var module = _emitModule(compilationUnits, unit.name); | 217 var module = _emitModule(compilationUnits, unit.name); |
196 var dartApiSummary = _summarizeModule(compilationUnits); | 218 var dartApiSummary = _summarizeModule(compilationUnits); |
197 | 219 |
198 return new JSModuleFile(unit.name, errors, options, module, dartApiSummary); | 220 return new JSModuleFile(unit.name, errors, options, module, dartApiSummary); |
199 } | 221 } |
200 | 222 |
201 List<int> _summarizeModule(List<CompilationUnit> units) { | 223 List<int> _summarizeModule(List<CompilationUnit> units) { |
202 if (!options.summarizeApi) return null; | 224 if (!options.summarizeApi) return null; |
203 | 225 |
204 if (!units.any((u) => resolutionMap | 226 if (!units.any((u) => resolutionMap |
205 .elementDeclaredByCompilationUnit(u) | 227 .elementDeclaredByCompilationUnit(u) |
206 .librarySource | 228 .librarySource |
207 .isInSystemLibrary)) { | 229 .isInSystemLibrary)) { |
208 var sdk = context.sourceFactory.dartSdk; | 230 var sdk = driver.sourceFactory.dartSdk; |
209 summaryData.addBundle( | 231 summaryData.addBundle( |
210 null, | 232 null, |
211 sdk is SummaryBasedDartSdk | 233 sdk is SummaryBasedDartSdk |
212 ? sdk.bundle | 234 ? sdk.bundle |
213 : (sdk as FolderBasedDartSdk).getSummarySdkBundle(true)); | 235 : (sdk as FolderBasedDartSdk).getSummarySdkBundle(true)); |
214 } | 236 } |
215 | 237 |
216 var assembler = new PackageBundleAssembler(); | 238 var assembler = new PackageBundleAssembler(); |
217 assembler.recordDependencies(summaryData); | 239 assembler.recordDependencies(summaryData); |
218 | 240 |
219 var uriToUnit = new Map<String, UnlinkedUnit>.fromIterable(units, | 241 var uriToUnit = new Map<String, UnlinkedUnit>.fromIterable(units, |
220 key: (u) => u.element.source.uri.toString(), value: (unit) { | 242 key: (u) => u.element.source.uri.toString(), value: (unit) { |
221 var unlinked = serializeAstUnlinked(unit); | 243 var unlinked = serializeAstUnlinked(unit); |
222 assembler.addUnlinkedUnit(unit.element.source, unlinked); | 244 assembler.addUnlinkedUnit(unit.element.source, unlinked); |
223 return unlinked; | 245 return unlinked; |
224 }); | 246 }); |
225 | 247 |
226 summary_link | 248 summary_link |
227 .link( | 249 .link( |
228 uriToUnit.keys.toSet(), | 250 uriToUnit.keys.toSet(), |
229 (uri) => summaryData.linkedMap[uri], | 251 (uri) => summaryData.linkedMap[uri], |
230 (uri) => summaryData.unlinkedMap[uri] ?? uriToUnit[uri], | 252 (uri) => summaryData.unlinkedMap[uri] ?? uriToUnit[uri], |
231 context.declaredVariables.get, | 253 driver.declaredVariables.get, |
232 true) | 254 true) |
233 .forEach(assembler.addLinkedLibrary); | 255 .forEach(assembler.addLinkedLibrary); |
234 | 256 |
235 var bundle = assembler.assemble(); | 257 var bundle = assembler.assemble(); |
236 // Preserve only API-level information in the summary. | 258 // Preserve only API-level information in the summary. |
237 bundle.flushInformative(); | 259 bundle.flushInformative(); |
238 return bundle.toBuffer(); | 260 return bundle.toBuffer(); |
239 } | 261 } |
240 | 262 |
241 JS.Program _emitModule(List<CompilationUnit> compilationUnits, String name) { | 263 JS.Program _emitModule(List<CompilationUnit> compilationUnits, String name) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // dart:_runtime has a magic module that holds extension method symbols. | 298 // dart:_runtime has a magic module that holds extension method symbols. |
277 // TODO(jmesserly): find a cleaner design for this. | 299 // TODO(jmesserly): find a cleaner design for this. |
278 if (_isDartRuntime(library)) { | 300 if (_isDartRuntime(library)) { |
279 items.add(new JS.ExportDeclaration(js | 301 items.add(new JS.ExportDeclaration(js |
280 .call('const # = Object.create(null)', [_extensionSymbolsModule]))); | 302 .call('const # = Object.create(null)', [_extensionSymbolsModule]))); |
281 } | 303 } |
282 } | 304 } |
283 | 305 |
284 // Collect all Element -> Node mappings, in case we need to forward declare | 306 // Collect all Element -> Node mappings, in case we need to forward declare |
285 // any nodes. | 307 // any nodes. |
286 var nodes = new HashMap<Element, AstNode>.identity(); | 308 var nodes = new HashMap<Element, AstNode>(); |
287 var sdkBootstrappingFns = new List<FunctionElement>(); | 309 var sdkBootstrappingFns = new List<FunctionElement>(); |
288 for (var unit in compilationUnits) { | 310 for (var unit in compilationUnits) { |
289 if (_isDartRuntime( | 311 if (_isDartRuntime( |
290 resolutionMap.elementDeclaredByCompilationUnit(unit).library)) { | 312 resolutionMap.elementDeclaredByCompilationUnit(unit).library)) { |
291 sdkBootstrappingFns.addAll( | 313 sdkBootstrappingFns.addAll( |
292 resolutionMap.elementDeclaredByCompilationUnit(unit).functions); | 314 resolutionMap.elementDeclaredByCompilationUnit(unit).functions); |
293 } | 315 } |
294 _collectElements(unit, nodes); | 316 _collectElements(unit, nodes); |
295 } | 317 } |
296 _loader = new ElementLoader(nodes); | 318 _loader = new ElementLoader(nodes); |
297 if (compilationUnits.isNotEmpty) { | 319 if (compilationUnits.isNotEmpty) { |
298 _constants = new ConstFieldVisitor(context, | 320 _constants = new ConstFieldVisitor(types, driver.declaredVariables, |
299 dummySource: resolutionMap | 321 dummySource: resolutionMap |
300 .elementDeclaredByCompilationUnit(compilationUnits.first) | 322 .elementDeclaredByCompilationUnit(compilationUnits.first) |
301 .source); | 323 .source); |
302 } | 324 } |
303 | 325 |
304 // Add implicit dart:core dependency so it is first. | 326 // Add implicit dart:core dependency so it is first. |
305 emitLibraryName(dartCoreLibrary); | 327 emitLibraryName(dartCoreLibrary); |
306 | 328 |
307 // Emit SDK bootstrapping functions first, if any. | 329 // Emit SDK bootstrapping functions first, if any. |
308 sdkBootstrappingFns.forEach(_emitDeclaration); | 330 sdkBootstrappingFns.forEach(_emitDeclaration); |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 lookup = classElem.type.lookUpInheritedGetter; | 1880 lookup = classElem.type.lookUpInheritedGetter; |
1859 tMember = node.isStatic ? tStaticGetters : tInstanceGetters; | 1881 tMember = node.isStatic ? tStaticGetters : tInstanceGetters; |
1860 } else if (node.isSetter) { | 1882 } else if (node.isSetter) { |
1861 elementToType = (ExecutableElement element) => element.type; | 1883 elementToType = (ExecutableElement element) => element.type; |
1862 getOverride = classElem.lookUpInheritedConcreteSetter; | 1884 getOverride = classElem.lookUpInheritedConcreteSetter; |
1863 lookup = classElem.type.lookUpInheritedSetter; | 1885 lookup = classElem.type.lookUpInheritedSetter; |
1864 tMember = node.isStatic ? tStaticSetters : tInstanceSetters; | 1886 tMember = node.isStatic ? tStaticSetters : tInstanceSetters; |
1865 } else { | 1887 } else { |
1866 // Method | 1888 // Method |
1867 // Swap in "Object" for parameter types that are covariant overrides. | 1889 // Swap in "Object" for parameter types that are covariant overrides. |
1868 var objectType = context.typeProvider.objectType; | 1890 var objectType = types.objectType; |
1869 elementToType = | 1891 elementToType = |
1870 (MethodElement element) => element.getReifiedType(objectType); | 1892 (MethodElement element) => element.getReifiedType(objectType); |
1871 getOverride = classElem.lookUpInheritedConcreteMethod; | 1893 getOverride = classElem.lookUpInheritedConcreteMethod; |
1872 lookup = classElem.type.lookUpInheritedMethod; | 1894 lookup = classElem.type.lookUpInheritedMethod; |
1873 tMember = node.isStatic ? tStaticMethods : tInstanceMethods; | 1895 tMember = node.isStatic ? tStaticMethods : tInstanceMethods; |
1874 } | 1896 } |
1875 | 1897 |
1876 DartType reifiedType = elementToType(element); | 1898 DartType reifiedType = elementToType(element); |
1877 // Don't add redundant signatures for inherited methods whose signature | 1899 // Don't add redundant signatures for inherited methods whose signature |
1878 // did not change. If we are not overriding, or if the thing we are | 1900 // did not change. If we are not overriding, or if the thing we are |
(...skipping 4036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5915 return whitelisted.contains(name); | 5937 return whitelisted.contains(name); |
5916 } | 5938 } |
5917 } | 5939 } |
5918 | 5940 |
5919 // Dynamic calls are less risky so there is no need to whitelist at the | 5941 // Dynamic calls are less risky so there is no need to whitelist at the |
5920 // method level. | 5942 // method level. |
5921 if (isCall && _uncheckedWhitelistCalls.contains(filename)) return true; | 5943 if (isCall && _uncheckedWhitelistCalls.contains(filename)) return true; |
5922 | 5944 |
5923 return path.endsWith(".template.dart"); | 5945 return path.endsWith(".template.dart"); |
5924 } | 5946 } |
| 5947 |
| 5948 Future<LibraryElement> _computeLibraryByUri(String libraryUri) async { |
| 5949 return await driver.resynthesizeLibrary(libraryUri); |
| 5950 } |
5925 } | 5951 } |
5926 | 5952 |
5927 /// Choose a canonical name from the [library] element. | 5953 /// Choose a canonical name from the [library] element. |
5928 /// | 5954 /// |
5929 /// This never uses the library's name (the identifier in the `library` | 5955 /// This never uses the library's name (the identifier in the `library` |
5930 /// declaration) as it doesn't have any meaningful rules enforced. | 5956 /// declaration) as it doesn't have any meaningful rules enforced. |
5931 String jsLibraryName(String libraryRoot, LibraryElement library) { | 5957 String jsLibraryName(String libraryRoot, LibraryElement library) { |
5932 var uri = library.source.uri; | 5958 var uri = library.source.uri; |
5933 if (uri.scheme == 'dart') { | 5959 if (uri.scheme == 'dart') { |
5934 return uri.path; | 5960 return uri.path; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6038 if (targetIdentifier.staticElement is! PrefixElement) return false; | 6064 if (targetIdentifier.staticElement is! PrefixElement) return false; |
6039 var prefix = targetIdentifier.staticElement as PrefixElement; | 6065 var prefix = targetIdentifier.staticElement as PrefixElement; |
6040 | 6066 |
6041 // The library the prefix is referring to must come from a deferred import. | 6067 // The library the prefix is referring to must come from a deferred import. |
6042 var containingLibrary = resolutionMap | 6068 var containingLibrary = resolutionMap |
6043 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 6069 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
6044 .library; | 6070 .library; |
6045 var imports = containingLibrary.getImportsWithPrefix(prefix); | 6071 var imports = containingLibrary.getImportsWithPrefix(prefix); |
6046 return imports.length == 1 && imports[0].isDeferred; | 6072 return imports.length == 1 && imports[0].isDeferred; |
6047 } | 6073 } |
OLD | NEW |