| 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; | 7 import 'dart:collection' show HashSet, HashMap; |
| 8 import 'dart:io' show Directory, File; | 8 import 'dart:io' show Directory, File; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 326 |
| 327 var name = node.name.name; | 327 var name = node.name.name; |
| 328 var heritage = | 328 var heritage = |
| 329 js.call('dart.mixin(#)', [_visitList(node.withClause.mixinTypes)]); | 329 js.call('dart.mixin(#)', [_visitList(node.withClause.mixinTypes)]); |
| 330 var classDecl = new JS.ClassDeclaration( | 330 var classDecl = new JS.ClassDeclaration( |
| 331 new JS.ClassExpression(new JS.Identifier(name), heritage, [])); | 331 new JS.ClassExpression(new JS.Identifier(name), heritage, [])); |
| 332 | 332 |
| 333 return _finishClassDef(type, classDecl); | 333 return _finishClassDef(type, classDecl); |
| 334 } | 334 } |
| 335 | 335 |
| 336 JS.Statement _emitJsType(ClassDeclaration node, Annotation jsName) { |
| 337 var dartName = node.name.name; |
| 338 var jsTypeName = _getLiteralStringNamedArg(jsName, 'name'); |
| 339 |
| 340 if (jsTypeName != null && jsTypeName != dartName) { |
| 341 // We export the JS type as if it was a Dart type. For example this allows |
| 342 // `dom.InputElement` to actually be HTMLInputElement. |
| 343 // TODO(jmesserly): if we had the JsName on the Element, we could just |
| 344 // generate it correctly when we refer to it. |
| 345 if (isPublic(dartName)) _addExport(dartName); |
| 346 return js.statement('let # = #;', [dartName, jsTypeName]); |
| 347 } |
| 348 return null; |
| 349 } |
| 350 |
| 336 @override | 351 @override |
| 337 JS.Statement visitClassDeclaration(ClassDeclaration node) { | 352 JS.Statement visitClassDeclaration(ClassDeclaration node) { |
| 338 // If we've already emitted this class, skip it. | 353 // If we've already emitted this class, skip it. |
| 339 var type = node.element.type; | 354 var type = node.element.type; |
| 340 if (_pendingClasses.remove(node.element) == null) return null; | 355 if (_pendingClasses.remove(node.element) == null) return null; |
| 341 if (_getJsNameAnnotation(node) != null) return null; | 356 |
| 357 var jsName = _getJsNameAnnotation(node); |
| 358 if (jsName != null) return _emitJsType(node, jsName); |
| 342 | 359 |
| 343 currentClass = node; | 360 currentClass = node; |
| 344 | 361 |
| 345 var ctors = <ConstructorDeclaration>[]; | 362 var ctors = <ConstructorDeclaration>[]; |
| 346 var fields = <FieldDeclaration>[]; | 363 var fields = <FieldDeclaration>[]; |
| 347 var staticFields = <FieldDeclaration>[]; | 364 var staticFields = <FieldDeclaration>[]; |
| 348 for (var member in node.members) { | 365 for (var member in node.members) { |
| 349 if (member is ConstructorDeclaration) { | 366 if (member is ConstructorDeclaration) { |
| 350 ctors.add(member); | 367 ctors.add(member); |
| 351 } else if (member is FieldDeclaration) { | 368 } else if (member is FieldDeclaration) { |
| (...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2569 if (parent is MethodInvocation && | 2586 if (parent is MethodInvocation && |
| 2570 identical(parent.methodName, node)) return; | 2587 identical(parent.methodName, node)) return; |
| 2571 if (parent is ConstructorName) return; | 2588 if (parent is ConstructorName) return; |
| 2572 if (parent is Label) return; | 2589 if (parent is Label) return; |
| 2573 | 2590 |
| 2574 if (node.inSetterContext() && node.staticElement == _variable) { | 2591 if (node.inSetterContext() && node.staticElement == _variable) { |
| 2575 _potentiallyMutated = true; | 2592 _potentiallyMutated = true; |
| 2576 } | 2593 } |
| 2577 } | 2594 } |
| 2578 } | 2595 } |
| 2596 |
| 2597 String _getLiteralStringNamedArg(Annotation annotation, String argName) { |
| 2598 if (annotation.arguments != null) { |
| 2599 var args = annotation.arguments.arguments; |
| 2600 if (args.isNotEmpty && args[0] is NamedExpression) { |
| 2601 NamedExpression named = args[0]; |
| 2602 if (named.name.label.name == argName && |
| 2603 named.expression is StringLiteral) { |
| 2604 return (named.expression as StringLiteral).stringValue; |
| 2605 } |
| 2606 } |
| 2607 } |
| 2608 return null; |
| 2609 } |
| OLD | NEW |