| Index: pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
|
| diff --git a/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart b/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
|
| index 15916f90251c72b06ad98013aa606395eb009d3c..65a49c860c848a5b5a6176a510fee0ef5095984a 100644
|
| --- a/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
|
| +++ b/pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
|
| @@ -23,6 +23,7 @@ import '../elements/elements.dart'
|
| FieldElement,
|
| FunctionElement,
|
| LibraryElement,
|
| + ParameterElement,
|
| MetadataAnnotation;
|
|
|
| import '../js/js.dart' as jsAst;
|
| @@ -83,11 +84,39 @@ class JsInteropAnalysis {
|
| }
|
| }
|
|
|
| + bool hasAnonymousAnnotation(Element element) {
|
| + if (backend.helpers.jsAnonymousClass == null) return false;
|
| + return element.metadata.any((MetadataAnnotation annotation) {
|
| + ConstantValue constant = backend.compiler.constants.getConstantValue(
|
| + annotation.constant);
|
| + if (constant == null ||
|
| + constant is! ConstructedConstantValue) return false;
|
| + ConstructedConstantValue constructedConstant = constant;
|
| + return constructedConstant.type.element ==
|
| + backend.helpers.jsAnonymousClass;
|
| + });
|
| + }
|
| +
|
| + void _checkFunctionParameters(FunctionElement fn) {
|
| + if (fn.hasFunctionSignature &&
|
| + fn.functionSignature.optionalParametersAreNamed) {
|
| + backend.reporter.reportErrorMessage(fn,
|
| + MessageKind.JS_INTEROP_METHOD_WITH_NAMED_ARGUMENTS, {
|
| + 'method': fn.name
|
| + });
|
| + }
|
| + }
|
| +
|
| void processJsInteropAnnotationsInLibrary(LibraryElement library) {
|
| processJsInteropAnnotation(library);
|
| library.implementation.forEachLocalMember((Element element) {
|
| processJsInteropAnnotation(element);
|
| - if (!element.isClass || !backend.isJsInterop(element)) return;
|
| + if (!backend.isJsInterop(element)) return;
|
| + if (element is FunctionElement) {
|
| + _checkFunctionParameters(element);
|
| + }
|
| +
|
| + if (!element.isClass) return;
|
|
|
| ClassElement classElement = element;
|
|
|
| @@ -108,12 +137,30 @@ class JsInteropAnalysis {
|
| backend.isJsInterop(classElement) &&
|
| member is FunctionElement) {
|
| FunctionElement fn = member;
|
| - if (!fn.isExternal && !fn.isAbstract) {
|
| + if (!fn.isExternal && !fn.isAbstract && !fn.isConstructor &&
|
| + !fn.isStatic) {
|
| backend.reporter.reportErrorMessage(
|
| fn,
|
| MessageKind.JS_INTEROP_CLASS_NON_EXTERNAL_MEMBER,
|
| {'cls': classElement.name, 'member': member.name});
|
| }
|
| +
|
| + if (fn.isFactoryConstructor && hasAnonymousAnnotation(classElement)) {
|
| + fn.functionSignature.orderedForEachParameter(
|
| + (ParameterElement parameter) {
|
| + if (!parameter.isNamed) {
|
| + backend.reporter.reportErrorMessage(parameter,
|
| + MessageKind
|
| + .JS_OBJECT_LITERAL_CONSTRUCTOR_WITH_POSITIONAL_ARGUMENTS,
|
| + {
|
| + 'parameter': parameter.name,
|
| + 'cls': classElement.name
|
| + });
|
| + }
|
| + });
|
| + } else {
|
| + _checkFunctionParameters(fn);
|
| + }
|
| }
|
| });
|
| });
|
|
|