Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: lib/src/utils.dart

Issue 1612083002: Initial --modules=es6 support (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: addressed comments (legacy, doc) + test enum utils Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/options.dart ('k') | test/all_tests.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 0a0e2c68c7ccc323804d8ad8375f307a80a11d2c..f6b0ab1893978b674a773df1b35fad055fc9e54d 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -433,3 +433,20 @@ bool isDartMathMinMax(Element e) =>
e is FunctionElement &&
e.library.source.uri.toString() == 'dart:math' &&
(e.name == 'min' || e.name == 'max');
+
+/// Parses an enum value out of a string.
+// TODO(ochafik): generic signature.
+dynamic parseEnum(String s, List enumValues) =>
+ enumValues.firstWhere((v) => s == getEnumName(v),
+ orElse: () => throw new ArgumentError(
+ 'Unknown enum value: $s '
+ '(expected one of ${enumValues.map(getEnumName)})'));
+
+/// Gets the "simple" name of an enum value.
+getEnumName(v) {
+ var parts = '$v'.split('.');
+ if (parts.length != 2 || !parts.every((p) => p.isNotEmpty)) {
+ throw new ArgumentError('Invalid enum value: $v');
+ }
+ return parts[1];
+}
« no previous file with comments | « lib/src/options.dart ('k') | test/all_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698