Index: pkg/compiler/lib/src/patch_parser.dart |
diff --git a/pkg/compiler/lib/src/patch_parser.dart b/pkg/compiler/lib/src/patch_parser.dart |
index 0f3008475c1095209ef5cf8d8f547788361d14dc..1ae480e2ea8242cd49517de0594ed2ac38a94cd2 100644 |
--- a/pkg/compiler/lib/src/patch_parser.dart |
+++ b/pkg/compiler/lib/src/patch_parser.dart |
@@ -304,6 +304,7 @@ void patchElement(Compiler compiler, |
patch, MessageKind.PATCH_NON_EXISTING, {'name': patch.name}); |
return; |
} |
+ |
if (!(origin.isClass || |
origin.isConstructor || |
origin.isFunction || |
@@ -359,6 +360,12 @@ checkNativeAnnotation(Compiler compiler, ClassElement cls) { |
const NativeAnnotationHandler()); |
} |
+checkJsInteropAnnotation(Compiler compiler, element) { |
+ EagerAnnotationHandler.checkAnnotation(compiler, element, |
+ const JsInteropAnnotationHandler()); |
+} |
+ |
+ |
/// Abstract interface for pre-resolution detection of metadata. |
/// |
/// The detection is handled in two steps: |
@@ -394,12 +401,17 @@ abstract class EagerAnnotationHandler<T> { |
if (result != null) { |
// TODO(johnniwinther): Perform this check in |
// [Compiler.onLibrariesLoaded]. |
- compiler.enqueuer.resolution.addDeferredAction(element, () { |
+ actionCallback() { |
annotation.ensureResolved(compiler); |
handler.validate( |
compiler, element, annotation, |
compiler.constants.getConstantValue(annotation.constant)); |
- }); |
+ } |
+ if (compiler.enqueuer.resolution.queueIsClosed) { |
Siggi Cherem (dart-lang)
2015/09/18 20:34:10
this is probably breaking the current enqueuer inv
Jacob
2015/10/01 00:47:33
this is somewhat horrible but somewhat acceptable
|
+ actionCallback(); |
+ } else { |
+ compiler.enqueuer.resolution.addDeferredAction(element, actionCallback); |
Siggi Cherem (dart-lang)
2015/09/18 20:34:10
nit: long line
Jacob
2015/10/01 00:47:33
Done.
|
+ } |
return result; |
} |
} |
@@ -449,6 +461,52 @@ class NativeAnnotationHandler implements EagerAnnotationHandler<String> { |
} |
} |
+/// Annotation handler for pre-resolution detection of `@JsName(...)` |
+/// annotations. |
+class JsInteropAnnotationHandler implements EagerAnnotationHandler<String> { |
+ const JsInteropAnnotationHandler(); |
+ |
+ // TODO(jacobr): this method is pure technical debt. |
+ String dietResolveStringToken(StringToken token) { |
Siggi Cherem (dart-lang)
2015/09/18 20:34:10
could we switch to use the constant evaluation ins
Jacob
2015/10/01 00:47:33
The trouble is getJsNameAnnotation is currently ca
|
+ String value = token.value; |
+ if ((value.startsWith('"') && value.endsWith('"')) || |
+ value.startsWith("'") && value.endsWith("'")) { |
+ return value.substring(1, value.length - 1); |
+ } else { |
+ throw 'Invalid @JsName(...) annotation. Unexpected name: $value'; |
+ } |
+ } |
+ |
+ String getJsNameAnnotation(MetadataAnnotation annotation) { |
+ if (annotation.beginToken != null && |
+ annotation.beginToken.next.value == 'JsName') { |
+ // Skipping '@', 'JsName', and '('. |
+ Token argument = annotation.beginToken.next.next.next; |
+ return (argument is StringToken) ? dietResolveStringToken(argument) : ''; |
+ } |
+ |
+ return null; |
+ } |
+ |
+ String apply(Compiler compiler, |
+ Element element, |
+ MetadataAnnotation annotation) { |
+ String jsName = getJsNameAnnotation(annotation); |
+ if (jsName != null) { |
+ element.setJsInterop(jsName); |
+ element.declaration.setJsInterop(jsName); |
+ } |
+ return jsName; |
+ } |
+ |
+ @override |
+ void validate(Compiler compiler, |
+ Element element, |
+ MetadataAnnotation annotation, |
+ ConstantValue constant) { |
+ } |
+} |
+ |
/// Annotation handler for pre-resolution detection of `@patch` annotations. |
class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { |
const PatchAnnotationHandler(); |