| 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 dev_compiler.src.codegen.js_codegen; | 5 library dev_compiler.src.codegen.js_codegen; |
| 6 | 6 |
| 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; | 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 var moduleDef = js.statement("dart_library.library(#, #, #, #, #)", [ | 219 var moduleDef = js.statement("dart_library.library(#, #, #, #, #)", [ |
| 220 js.string(jsPath, "'"), | 220 js.string(jsPath, "'"), |
| 221 _jsModuleValue ?? new JS.LiteralNull(), | 221 _jsModuleValue ?? new JS.LiteralNull(), |
| 222 js.commentExpression( | 222 js.commentExpression( |
| 223 "Imports", new JS.ArrayInitializer(imports, multiline: true)), | 223 "Imports", new JS.ArrayInitializer(imports, multiline: true)), |
| 224 js.commentExpression("Lazy imports", | 224 js.commentExpression("Lazy imports", |
| 225 new JS.ArrayInitializer(lazyImports, multiline: true)), | 225 new JS.ArrayInitializer(lazyImports, multiline: true)), |
| 226 module | 226 module |
| 227 ]); | 227 ]); |
| 228 | 228 |
| 229 var jsBin = compiler.options.runnerOptions.v8Binary; | 229 // TODO(jmesserly): scriptTag support. |
| 230 | 230 // Enable this if we know we're targetting command line environment? |
| 231 String scriptTag = null; | 231 // It doesn't work in browser. |
| 232 if (library.library.scriptTag != null) scriptTag = '/usr/bin/env $jsBin'; | 232 // var jsBin = compiler.options.runnerOptions.v8Binary; |
| 233 return new JS.Program(<JS.Statement>[moduleDef], scriptTag: scriptTag); | 233 // String scriptTag = null; |
| 234 // if (library.library.scriptTag != null) scriptTag = '/usr/bin/env $jsBin'; |
| 235 return new JS.Program(<JS.Statement>[moduleDef]); |
| 234 } | 236 } |
| 235 | 237 |
| 236 void _emitModuleItem(AstNode node) { | 238 void _emitModuleItem(AstNode node) { |
| 237 // Attempt to group adjacent fields/properties. | 239 // Attempt to group adjacent fields/properties. |
| 238 if (node is! VariableDeclaration) _flushLazyFields(_moduleItems); | 240 if (node is! VariableDeclaration) _flushLazyFields(_moduleItems); |
| 239 if (node is! FunctionDeclaration) _flushLibraryProperties(_moduleItems); | 241 if (node is! FunctionDeclaration) _flushLibraryProperties(_moduleItems); |
| 240 | 242 |
| 241 var code = _visit(node); | 243 var code = _visit(node); |
| 242 if (code != null) _moduleItems.add(code); | 244 if (code != null) _moduleItems.add(code); |
| 243 } | 245 } |
| (...skipping 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3184 return _privateNames.putIfAbsent( | 3186 return _privateNames.putIfAbsent( |
| 3185 name, () => _initSymbol(new JS.TemporaryId(name)) as JS.TemporaryId); | 3187 name, () => _initSymbol(new JS.TemporaryId(name)) as JS.TemporaryId); |
| 3186 } | 3188 } |
| 3187 | 3189 |
| 3188 if (name == '[]') { | 3190 if (name == '[]') { |
| 3189 name = 'get'; | 3191 name = 'get'; |
| 3190 } else if (name == '[]=') { | 3192 } else if (name == '[]=') { |
| 3191 name = 'set'; | 3193 name = 'set'; |
| 3192 } else if (name == '-' && unary) { | 3194 } else if (name == '-' && unary) { |
| 3193 name = 'unary-'; | 3195 name = 'unary-'; |
| 3196 } else if (name == 'constructor' || name == 'prototype') { |
| 3197 // This uses an illegal (in Dart) character for a member, avoiding the |
| 3198 // conflict. We could use practically any character for this. |
| 3199 name = '+$name'; |
| 3194 } | 3200 } |
| 3195 | 3201 |
| 3196 // Dart "extension" methods. Used for JS Array, Boolean, Number, String. | 3202 // Dart "extension" methods. Used for JS Array, Boolean, Number, String. |
| 3197 if (allowExtensions && | 3203 if (allowExtensions && |
| 3198 _extensionTypes.contains(type.element) && | 3204 _extensionTypes.contains(type.element) && |
| 3199 !_objectMembers.containsKey(name)) { | 3205 !_objectMembers.containsKey(name)) { |
| 3200 return js.call('dartx.#', _propertyName(name)); | 3206 return js.call('dartx.#', _propertyName(name)); |
| 3201 } | 3207 } |
| 3202 | 3208 |
| 3203 return _propertyName(name); | 3209 return _propertyName(name); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3311 | 3317 |
| 3312 /// A special kind of element created by the compiler, signifying a temporary | 3318 /// A special kind of element created by the compiler, signifying a temporary |
| 3313 /// variable. These objects use instance equality, and should be shared | 3319 /// variable. These objects use instance equality, and should be shared |
| 3314 /// everywhere in the tree where they are treated as the same variable. | 3320 /// everywhere in the tree where they are treated as the same variable. |
| 3315 class TemporaryVariableElement extends LocalVariableElementImpl { | 3321 class TemporaryVariableElement extends LocalVariableElementImpl { |
| 3316 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); | 3322 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); |
| 3317 | 3323 |
| 3318 int get hashCode => identityHashCode(this); | 3324 int get hashCode => identityHashCode(this); |
| 3319 bool operator ==(Object other) => identical(this, other); | 3325 bool operator ==(Object other) => identical(this, other); |
| 3320 } | 3326 } |
| OLD | NEW |