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 /// Holds a couple utility functions used at various places in the system. | 5 /// Holds a couple utility functions used at various places in the system. |
6 library dev_compiler.src.utils; | 6 library dev_compiler.src.utils; |
7 | 7 |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
11 import 'package:analyzer/src/generated/ast.dart' | 11 import 'package:analyzer/src/generated/ast.dart' |
12 show | 12 show |
13 ImportDirective, | 13 ImportDirective, |
14 ExportDirective, | 14 ExportDirective, |
15 PartDirective, | 15 PartDirective, |
16 CompilationUnit, | 16 CompilationUnit, |
17 Identifier, | 17 Identifier, |
18 AnnotatedNode, | 18 AnnotatedNode, |
19 AstNode, | 19 AstNode, |
20 Expression, | 20 Expression, |
21 SimpleIdentifier, | 21 SimpleIdentifier, |
22 MethodInvocation; | 22 MethodInvocation; |
23 import 'package:analyzer/src/generated/constant.dart' show DartObject; | 23 import 'package:analyzer/src/generated/constant.dart' show DartObject; |
24 import 'package:analyzer/src/generated/element.dart'; | 24 import 'package:analyzer/src/generated/element.dart'; |
25 import 'package:analyzer/src/generated/engine.dart' | 25 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
26 show ParseDartTask, AnalysisContext; | |
27 import 'package:analyzer/src/generated/error.dart' show ErrorCode; | 26 import 'package:analyzer/src/generated/error.dart' show ErrorCode; |
| 27 import 'package:analyzer/src/task/dart.dart' show ParseDartTask; |
28 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 28 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
29 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; | 29 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; |
30 import 'package:analyzer/analyzer.dart' show parseDirectives; | 30 import 'package:analyzer/analyzer.dart' show parseDirectives; |
31 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; | 31 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; |
32 import 'package:source_span/source_span.dart'; | 32 import 'package:source_span/source_span.dart'; |
33 | 33 |
34 import 'codegen/js_names.dart' show invalidVariableName; | 34 import 'codegen/js_names.dart' show invalidVariableName; |
35 | 35 |
36 bool isDartPrivateLibrary(LibraryElement library) { | 36 bool isDartPrivateLibrary(LibraryElement library) { |
37 var uri = library.source.uri; | 37 var uri = library.source.uri; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 int lineEnd = endLoc.offset; | 401 int lineEnd = endLoc.offset; |
402 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; | 402 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; |
403 while (lineEnd < content.length && | 403 while (lineEnd < content.length && |
404 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); | 404 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); |
405 | 405 |
406 var text = content.substring(start, end); | 406 var text = content.substring(start, end); |
407 var lineText = content.substring(lineStart, lineEnd); | 407 var lineText = content.substring(lineStart, lineEnd); |
408 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); | 408 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); |
409 } | 409 } |
410 | 410 |
| 411 String _strongModeErrorPrefix = 'STRONG_MODE'; |
| 412 |
| 413 bool isStrongModeError(ErrorCode errorCode) { |
| 414 return errorCode.name.startsWith(_strongModeErrorPrefix); |
| 415 } |
| 416 |
411 String errorCodeName(ErrorCode errorCode) { | 417 String errorCodeName(ErrorCode errorCode) { |
412 var name = errorCode.name; | 418 if (isStrongModeError(errorCode)) { |
413 final prefix = 'dev_compiler.'; | 419 return errorCode.name.substring(_strongModeErrorPrefix.length + 1); |
414 if (name.startsWith(prefix)) { | |
415 return name.substring(prefix.length); | |
416 } else { | 420 } else { |
417 // TODO(jmesserly): this is for backwards compat, but not sure it's very | 421 // TODO(jmesserly): this is for backwards compat, but not sure it's very |
418 // useful to log this. | 422 // useful to log this. |
419 return 'AnalyzerMessage'; | 423 return 'AnalyzerMessage'; |
420 } | 424 } |
421 } | 425 } |
422 | 426 |
423 bool isInlineJS(Element e) => e is FunctionElement && | 427 bool isInlineJS(Element e) => |
| 428 e is FunctionElement && |
424 e.library.source.uri.toString() == 'dart:_foreign_helper' && | 429 e.library.source.uri.toString() == 'dart:_foreign_helper' && |
425 e.name == 'JS'; | 430 e.name == 'JS'; |
426 | 431 |
427 bool isDartMathMinMax(Element e) => e is FunctionElement && | 432 bool isDartMathMinMax(Element e) => |
| 433 e is FunctionElement && |
428 e.library.source.uri.toString() == 'dart:math' && | 434 e.library.source.uri.toString() == 'dart:math' && |
429 (e.name == 'min' || e.name == 'max'); | 435 (e.name == 'min' || e.name == 'max'); |
OLD | NEW |