| 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 import 'package:analyzer/analyzer.dart' as analyzer; | 5 import 'package:analyzer/analyzer.dart' as analyzer; |
| 6 import 'package:analyzer/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
| 7 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 7 import 'package:analyzer/dart/element/type.dart' show DartType; | 8 import 'package:analyzer/dart/element/type.dart' show DartType; |
| 8 import 'package:analyzer/src/dart/ast/ast.dart' show FunctionBodyImpl; | 9 import 'package:analyzer/src/dart/ast/ast.dart' show FunctionBodyImpl; |
| 9 import 'package:analyzer/src/dart/ast/utilities.dart' show NodeReplacer; | 10 import 'package:analyzer/src/dart/ast/utilities.dart' show NodeReplacer; |
| 10 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; | 11 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; |
| 11 import 'package:analyzer/src/generated/parser.dart' show ResolutionCopier; | 12 import 'package:analyzer/src/generated/parser.dart' show ResolutionCopier; |
| 12 import 'package:analyzer/src/task/strong/ast_properties.dart' as ast_properties; | 13 import 'package:analyzer/src/task/strong/ast_properties.dart' as ast_properties; |
| 13 import 'package:logging/logging.dart' as logger; | 14 import 'package:logging/logging.dart' as logger; |
| 14 | 15 |
| 15 import 'ast_builder.dart' show AstBuilder, RawAstBuilder; | 16 import 'ast_builder.dart' show AstBuilder, RawAstBuilder; |
| 16 import 'element_helpers.dart' show isInlineJS; | 17 import 'element_helpers.dart' show isInlineJS; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 33 | 34 |
| 34 /// Returns true if the `as` [node] was created by this class. | 35 /// Returns true if the `as` [node] was created by this class. |
| 35 // TODO(sra): Find a better way to recognize reified coercion, since we | 36 // TODO(sra): Find a better way to recognize reified coercion, since we |
| 36 // can't set the isSynthetic attribute. | 37 // can't set the isSynthetic attribute. |
| 37 static bool isImplicitCast(AsExpression node) => node.asOperator.offset == 0; | 38 static bool isImplicitCast(AsExpression node) => node.asOperator.offset == 0; |
| 38 | 39 |
| 39 /// Creates an implicit cast for expression [e] to [toType]. | 40 /// Creates an implicit cast for expression [e] to [toType]. |
| 40 static Expression castExpression(Expression e, DartType toType) { | 41 static Expression castExpression(Expression e, DartType toType) { |
| 41 // We use an empty name in the AST, because the JS code generator only cares | 42 // We use an empty name in the AST, because the JS code generator only cares |
| 42 // about the target type. It does not look at the AST name. | 43 // about the target type. It does not look at the AST name. |
| 43 var typeName = new TypeName(AstBuilder.identifierFromString(''), null); | 44 var typeName = |
| 45 astFactory.typeName(AstBuilder.identifierFromString(''), null); |
| 44 typeName.type = toType; | 46 typeName.type = toType; |
| 45 var cast = AstBuilder.asExpression(e, typeName); | 47 var cast = AstBuilder.asExpression(e, typeName); |
| 46 cast.staticType = toType; | 48 cast.staticType = toType; |
| 47 return cast; | 49 return cast; |
| 48 } | 50 } |
| 49 | 51 |
| 50 @override | 52 @override |
| 51 CompilationUnit visitCompilationUnit(CompilationUnit node) { | 53 CompilationUnit visitCompilationUnit(CompilationUnit node) { |
| 52 if (ast_properties.hasImplicitCasts(node)) { | 54 if (ast_properties.hasImplicitCasts(node)) { |
| 53 // Clone compilation unit, so we don't modify the originals. | 55 // Clone compilation unit, so we don't modify the originals. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 173 |
| 172 // TODO(jmesserly): workaround for | 174 // TODO(jmesserly): workaround for |
| 173 // https://github.com/dart-lang/sdk/issues/26368 | 175 // https://github.com/dart-lang/sdk/issues/26368 |
| 174 @override | 176 @override |
| 175 TypeName visitTypeName(TypeName node) { | 177 TypeName visitTypeName(TypeName node) { |
| 176 var clone = super.visitTypeName(node); | 178 var clone = super.visitTypeName(node); |
| 177 clone.type = node.type; | 179 clone.type = node.type; |
| 178 return clone; | 180 return clone; |
| 179 } | 181 } |
| 180 } | 182 } |
| OLD | NEW |