From e51623f81aee062255ae062853a6b52b9bd88cef Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Fri, 7 Aug 2020 17:09:23 +0000 Subject: [PATCH] [package:js] Add errors for missing @JS on class Adds errors for class members that have a @JS annotation but the enclosing class does not. Change-Id: Id693af71678510047a723863846d89aa29cebe26 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157004 Reviewed-by: Nate Bosch Reviewed-by: Sigmund Cherem --- .../lib/src/messages/codes_generated.dart | 21 +++++++++ .../lib/js_interop_checks.dart | 29 ++++++++++++ .../lib/src/diagnostics/messages.dart | 7 --- .../lib/src/kernel/native_basic_data.dart | 10 +--- pkg/front_end/messages.status | 2 + pkg/front_end/messages.yaml | 8 ++++ tests/dart2js/jsinterop_test.dart | 36 +++++++-------- tests/dart2js/non_jsinterop_test.dart | 36 +++++++-------- tests/dart2js_2/jsinterop_test.dart | 36 +++++++-------- tests/dart2js_2/non_jsinterop_test.dart | 36 +++++++-------- tests/lib/js/js_annotation_static_test.dart | 46 +++++++++++++++++++ 11 files changed, 180 insertions(+), 87 deletions(-) create mode 100644 tests/lib/js/js_annotation_static_test.dart diff --git a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart index 531cf04286c..7ee3d3fa08b 100644 --- a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart +++ b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart @@ -5420,6 +5420,27 @@ const MessageCode messageJsInteropAnonymousFactoryPositionalParameters = r"""Factory constructors for @anonymous JS interop classes should not contain any positional parameters.""", tip: r"""Try replacing them with named parameters instead."""); +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const Code codeJsInteropEnclosingClassJSAnnotation = + messageJsInteropEnclosingClassJSAnnotation; + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const MessageCode messageJsInteropEnclosingClassJSAnnotation = const MessageCode( + "JsInteropEnclosingClassJSAnnotation", + message: + r"""Member has a JS interop annotation but the enclosing class does not.""", + tip: r"""Try adding the annotation to the enclosing class."""); + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const Code codeJsInteropEnclosingClassJSAnnotationContext = + messageJsInteropEnclosingClassJSAnnotationContext; + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const MessageCode messageJsInteropEnclosingClassJSAnnotationContext = + const MessageCode("JsInteropEnclosingClassJSAnnotationContext", + severity: Severity.context, + message: r"""This is the enclosing class."""); + // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. const Code codeJsInteropIndexNotSupported = messageJsInteropIndexNotSupported; diff --git a/pkg/_js_interop_checks/lib/js_interop_checks.dart b/pkg/_js_interop_checks/lib/js_interop_checks.dart index 08cbb83fa18..2355b50d21e 100644 --- a/pkg/_js_interop_checks/lib/js_interop_checks.dart +++ b/pkg/_js_interop_checks/lib/js_interop_checks.dart @@ -9,6 +9,8 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart' Message, LocatedMessage, messageJsInteropAnonymousFactoryPositionalParameters, + messageJsInteropEnclosingClassJSAnnotation, + messageJsInteropEnclosingClassJSAnnotationContext, messageJsInteropIndexNotSupported, messageJsInteropNamedParameters, messageJsInteropNonExternalConstructor; @@ -20,8 +22,16 @@ class JsInteropChecks extends RecursiveVisitor { JsInteropChecks(this._diagnosticsReporter); + @override + void defaultMember(Member member) { + _checkMemberJSInteropAnnotation(member); + super.defaultMember(member); + } + @override void visitProcedure(Procedure procedure) { + _checkMemberJSInteropAnnotation(procedure); + if (!procedure.isExternal || !isJSInteropMember(procedure)) return; if (!procedure.isStatic && @@ -55,6 +65,8 @@ class JsInteropChecks extends RecursiveVisitor { @override void visitConstructor(Constructor constructor) { + _checkMemberJSInteropAnnotation(constructor); + if (!isJSInteropMember(constructor)) return; if (!constructor.isExternal && !constructor.isSynthetic) { @@ -79,4 +91,21 @@ class JsInteropChecks extends RecursiveVisitor { firstNamedParam.location.file); } } + + /// Reports an error if [m] has a JS interop annotation and is part of a class + /// that does not. + void _checkMemberJSInteropAnnotation(Member m) { + if (!hasJSInteropAnnotation(m)) return; + var enclosingClass = m.enclosingClass; + if (enclosingClass != null && !hasJSInteropAnnotation(enclosingClass)) { + _diagnosticsReporter.report(messageJsInteropEnclosingClassJSAnnotation, + m.fileOffset, m.name.name.length, m.location.file, + context: [ + messageJsInteropEnclosingClassJSAnnotationContext.withLocation( + enclosingClass.location.file, + enclosingClass.fileOffset, + enclosingClass.name.length) + ]); + } + } } diff --git a/pkg/compiler/lib/src/diagnostics/messages.dart b/pkg/compiler/lib/src/diagnostics/messages.dart index e1486546e64..4b78a076747 100644 --- a/pkg/compiler/lib/src/diagnostics/messages.dart +++ b/pkg/compiler/lib/src/diagnostics/messages.dart @@ -77,7 +77,6 @@ enum MessageKind { JS_INTEROP_CLASS_NON_EXTERNAL_MEMBER, JS_INTEROP_FIELD_NOT_SUPPORTED, JS_INTEROP_NON_EXTERNAL_MEMBER, - JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS, JS_INTEROP_METHOD_WITH_NAMED_ARGUMENTS, JS_OBJECT_LITERAL_CONSTRUCTOR_WITH_POSITIONAL_ARGUMENTS, JS_PLACEHOLDER_CAPTURE, @@ -201,12 +200,6 @@ class MessageTemplate { MessageKind.JS_INTEROP_NON_EXTERNAL_MEMBER, "Js-interop members must be 'external'."), - MessageKind.JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS: const MessageTemplate( - MessageKind.JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS, - "Js-interop class members are only supported in js-interop classes.", - howToFix: "Try marking the enclosing class as js-interop or " - "remove the js-interop annotation from the member."), - MessageKind.JS_INTEROP_CLASS_NON_EXTERNAL_MEMBER: const MessageTemplate( MessageKind.JS_INTEROP_CLASS_NON_EXTERNAL_MEMBER, "Member '#{member}' in js-interop class '#{cls}' is not external.", diff --git a/pkg/compiler/lib/src/kernel/native_basic_data.dart b/pkg/compiler/lib/src/kernel/native_basic_data.dart index 3d43255080a..9ebb17db94b 100644 --- a/pkg/compiler/lib/src/kernel/native_basic_data.dart +++ b/pkg/compiler/lib/src/kernel/native_basic_data.dart @@ -156,10 +156,7 @@ class KernelAnnotationProcessor implements AnnotationProcessor { elementEnvironment.forEachLocalClassMember(cls, (MemberEntity member) { String memberName = getJsInteropName( library, elementEnvironment.getMemberMetadata(member)); - if (memberName != null) { - reporter.reportErrorMessage( - member, MessageKind.JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS); - } else if (member is FunctionEntity) { + if (memberName == null && member is FunctionEntity) { if (member.isExternal && !commonElements.isExternalAllowed(member)) { reporter.reportErrorMessage( @@ -171,10 +168,7 @@ class KernelAnnotationProcessor implements AnnotationProcessor { (ConstructorEntity constructor) { String memberName = getJsInteropName( library, elementEnvironment.getMemberMetadata(constructor)); - if (memberName != null) { - reporter.reportErrorMessage(constructor, - MessageKind.JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS); - } else { + if (memberName == null) { if (constructor.isExternal && !commonElements.isExternalAllowed(constructor)) { reporter.reportErrorMessage( diff --git a/pkg/front_end/messages.status b/pkg/front_end/messages.status index 6459cc1b8f5..e375f7151c5 100644 --- a/pkg/front_end/messages.status +++ b/pkg/front_end/messages.status @@ -441,6 +441,8 @@ InvalidVoid/script1: Fail InvalidVoid/script2: Fail JsInteropAnonymousFactoryPositionalParameters/analyzerCode: Fail # Web compiler specific JsInteropAnonymousFactoryPositionalParameters/example: Fail # Web compiler specific +JsInteropEnclosingClassJSAnnotation/analyzerCode: Fail # Web compiler specific +JsInteropEnclosingClassJSAnnotation/example: Fail # Web compiler specific JsInteropIndexNotSupported/analyzerCode: Fail # Web compiler specific JsInteropIndexNotSupported/example: Fail # Web compiler specific JsInteropNamedParameters/analyzerCode: Fail # Web compiler specific diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml index 62ae4a3cbe1..f317340c9d8 100644 --- a/pkg/front_end/messages.yaml +++ b/pkg/front_end/messages.yaml @@ -4090,6 +4090,14 @@ JsInteropAnonymousFactoryPositionalParameters: template: "Factory constructors for @anonymous JS interop classes should not contain any positional parameters." tip: "Try replacing them with named parameters instead." +JsInteropEnclosingClassJSAnnotation: + template: "Member has a JS interop annotation but the enclosing class does not." + tip: "Try adding the annotation to the enclosing class." + +JsInteropEnclosingClassJSAnnotationContext: + template: "This is the enclosing class." + severity: CONTEXT + JsInteropIndexNotSupported: template: "JS interop classes do not support [] and []= operator methods." tip: "Try replacing with a normal method." diff --git a/tests/dart2js/jsinterop_test.dart b/tests/dart2js/jsinterop_test.dart index f44b2b463cd..397f5e22562 100644 --- a/tests/dart2js/jsinterop_test.dart +++ b/tests/dart2js/jsinterop_test.dart @@ -58,16 +58,16 @@ class Class { // NON_NATIVE_EXTERNAL //# 09: compile-time error external factory Class.externalFact(); //# 09: continued - @JS('a') // GENERIC //# 10: compile-time error + @JS('a') // GENERIC, GENERIC //# 10: compile-time error Class.jsInteropGenerative(); //# 10: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 11: compile-time error + @JS('a') // GENERIC //# 11: compile-time error factory Class.jsInteropFact() => null; //# 11: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 12: compile-time error + @JS('a') // GENERIC //# 12: compile-time error external Class.externalJsInteropGenerative(); //# 12: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 13: compile-time error + @JS('a') // GENERIC //# 13: compile-time error external factory Class.externalJsInteropFact(); //# 13: continued var instanceField; @@ -80,28 +80,28 @@ class Class { static set staticSetter(_) {} static staticMethod() {} - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 14: compile-time error + @JS('a') // GENERIC //# 14: compile-time error var instanceJsInteropField; //# 14: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 15: compile-time error + @JS('a') // GENERIC //# 15: compile-time error get instanceJsInteropGetter => null; //# 15: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 16: compile-time error + @JS('a') // GENERIC //# 16: compile-time error set instanceJsInteropSetter(_) {} //# 16: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 17: compile-time error + @JS('a') // GENERIC //# 17: compile-time error instanceJsInteropMethod() {} //# 17: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 18: compile-time error + @JS('a') // GENERIC //# 18: compile-time error static var staticJsInteropField; //# 18: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 19: compile-time error + @JS('a') // GENERIC //# 19: compile-time error static get staticJsInteropGetter => null; //# 19: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 20: compile-time error + @JS('a') // GENERIC //# 20: compile-time error static set staticJsInteropSetter(_) {} //# 20: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 21: compile-time error + @JS('a') // GENERIC //# 21: compile-time error static staticJsInteropMethod() {} //# 21: continued // NON_NATIVE_EXTERNAL //# 22: compile-time error @@ -122,22 +122,22 @@ class Class { // NON_NATIVE_EXTERNAL //# 27: compile-time error external static externalStaticMethod(); //# 27: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 28: compile-time error + @JS('a') // GENERIC //# 28: compile-time error external get externalInstanceJsInteropGetter; //# 28: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 29: compile-time error + @JS('a') // GENERIC //# 29: compile-time error external set externalInstanceJsInteropSetter(_); //# 29: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 30: compile-time error + @JS('a') // GENERIC //# 30: compile-time error external externalInstanceJsInteropMethod(); //# 30: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 31: compile-time error + @JS('a') // GENERIC //# 31: compile-time error external static get externalStaticJsInteropGetter; //# 31: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 32: compile-time error + @JS('a') // GENERIC //# 32: compile-time error external static set externalStaticJsInteropSetter(_); //# 32: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 33: compile-time error + @JS('a') // GENERIC //# 33: compile-time error external static externalStaticJsInteropMethod(); //# 33: continued } diff --git a/tests/dart2js/non_jsinterop_test.dart b/tests/dart2js/non_jsinterop_test.dart index 67f239bc272..68eebe720b9 100644 --- a/tests/dart2js/non_jsinterop_test.dart +++ b/tests/dart2js/non_jsinterop_test.dart @@ -60,16 +60,16 @@ class Class { // NON_NATIVE_EXTERNAL //# 09: compile-time error external factory Class.externalFact(); //# 09: continued - @JS('a') // GENERIC //# 10: compile-time error + @JS('a') // GENERIC, GENERIC //# 10: compile-time error Class.jsInteropGenerative(); //# 10: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 11: compile-time error + @JS('a') // GENERIC //# 11: compile-time error factory Class.jsInteropFact() => null; //# 11: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 12: compile-time error + @JS('a') // GENERIC //# 12: compile-time error external Class.externalJsInteropGenerative(); //# 12: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 13: compile-time error + @JS('a') // GENERIC //# 13: compile-time error external factory Class.externalJsInteropFact(); //# 13: continued var instanceField; @@ -82,28 +82,28 @@ class Class { static set staticSetter(_) {} static staticMethod() {} - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 14: compile-time error + @JS('a') // GENERIC //# 14: compile-time error var instanceJsInteropField; //# 14: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 15: compile-time error + @JS('a') // GENERIC //# 15: compile-time error get instanceJsInteropGetter => null; //# 15: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 16: compile-time error + @JS('a') // GENERIC //# 16: compile-time error set instanceJsInteropSetter(_) {} //# 16: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 17: compile-time error + @JS('a') // GENERIC //# 17: compile-time error instanceJsInteropMethod() {} //# 17: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 18: compile-time error + @JS('a') // GENERIC //# 18: compile-time error static var staticJsInteropField; //# 18: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 19: compile-time error + @JS('a') // GENERIC //# 19: compile-time error static get staticJsInteropGetter => null; //# 19: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 20: compile-time error + @JS('a') // GENERIC //# 20: compile-time error static set staticJsInteropSetter(_) {} //# 20: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 21: compile-time error + @JS('a') // GENERIC //# 21: compile-time error static staticJsInteropMethod() {} //# 21: continued // NON_NATIVE_EXTERNAL //# 22: compile-time error @@ -124,22 +124,22 @@ class Class { // NON_NATIVE_EXTERNAL //# 27: compile-time error external static externalStaticMethod(); //# 27: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 28: compile-time error + @JS('a') // GENERIC //# 28: compile-time error external get externalInstanceJsInteropGetter; //# 28: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 29: compile-time error + @JS('a') // GENERIC //# 29: compile-time error external set externalInstanceJsInteropSetter(_); //# 29: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 30: compile-time error + @JS('a') // GENERIC //# 30: compile-time error external externalInstanceJsInteropMethod(); //# 30: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 31: compile-time error + @JS('a') // GENERIC //# 31: compile-time error external static get externalStaticJsInteropGetter; //# 31: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 32: compile-time error + @JS('a') // GENERIC //# 32: compile-time error external static set externalStaticJsInteropSetter(_); //# 32: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 33: compile-time error + @JS('a') // GENERIC //# 33: compile-time error external static externalStaticJsInteropMethod(); //# 33: continued } diff --git a/tests/dart2js_2/jsinterop_test.dart b/tests/dart2js_2/jsinterop_test.dart index 23521a07c49..2db564c3b78 100644 --- a/tests/dart2js_2/jsinterop_test.dart +++ b/tests/dart2js_2/jsinterop_test.dart @@ -60,16 +60,16 @@ class Class { // NON_NATIVE_EXTERNAL //# 09: compile-time error external factory Class.externalFact(); //# 09: continued - @JS('a') // GENERIC //# 10: compile-time error + @JS('a') // GENERIC, GENERIC //# 10: compile-time error Class.jsInteropGenerative(); //# 10: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 11: compile-time error + @JS('a') // GENERIC //# 11: compile-time error factory Class.jsInteropFact() => null; //# 11: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 12: compile-time error + @JS('a') // GENERIC //# 12: compile-time error external Class.externalJsInteropGenerative(); //# 12: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 13: compile-time error + @JS('a') // GENERIC //# 13: compile-time error external factory Class.externalJsInteropFact(); //# 13: continued var instanceField; @@ -82,28 +82,28 @@ class Class { static set staticSetter(_) {} static staticMethod() {} - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 14: compile-time error + @JS('a') // GENERIC //# 14: compile-time error var instanceJsInteropField; //# 14: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 15: compile-time error + @JS('a') // GENERIC //# 15: compile-time error get instanceJsInteropGetter => null; //# 15: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 16: compile-time error + @JS('a') // GENERIC //# 16: compile-time error set instanceJsInteropSetter(_) {} //# 16: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 17: compile-time error + @JS('a') // GENERIC //# 17: compile-time error instanceJsInteropMethod() {} //# 17: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 18: compile-time error + @JS('a') // GENERIC //# 18: compile-time error static var staticJsInteropField; //# 18: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 19: compile-time error + @JS('a') // GENERIC //# 19: compile-time error static get staticJsInteropGetter => null; //# 19: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 20: compile-time error + @JS('a') // GENERIC //# 20: compile-time error static set staticJsInteropSetter(_) {} //# 20: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 21: compile-time error + @JS('a') // GENERIC //# 21: compile-time error static staticJsInteropMethod() {} //# 21: continued // NON_NATIVE_EXTERNAL //# 22: compile-time error @@ -124,22 +124,22 @@ class Class { // NON_NATIVE_EXTERNAL //# 27: compile-time error external static externalStaticMethod(); //# 27: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 28: compile-time error + @JS('a') // GENERIC //# 28: compile-time error external get externalInstanceJsInteropGetter; //# 28: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 29: compile-time error + @JS('a') // GENERIC //# 29: compile-time error external set externalInstanceJsInteropSetter(_); //# 29: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 30: compile-time error + @JS('a') // GENERIC //# 30: compile-time error external externalInstanceJsInteropMethod(); //# 30: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 31: compile-time error + @JS('a') // GENERIC //# 31: compile-time error external static get externalStaticJsInteropGetter; //# 31: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 32: compile-time error + @JS('a') // GENERIC //# 32: compile-time error external static set externalStaticJsInteropSetter(_); //# 32: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 33: compile-time error + @JS('a') // GENERIC //# 33: compile-time error external static externalStaticJsInteropMethod(); //# 33: continued } diff --git a/tests/dart2js_2/non_jsinterop_test.dart b/tests/dart2js_2/non_jsinterop_test.dart index bbaae2c0e77..1bac858e293 100644 --- a/tests/dart2js_2/non_jsinterop_test.dart +++ b/tests/dart2js_2/non_jsinterop_test.dart @@ -62,16 +62,16 @@ class Class { // NON_NATIVE_EXTERNAL //# 09: compile-time error external factory Class.externalFact(); //# 09: continued - @JS('a') // GENERIC //# 10: compile-time error + @JS('a') // GENERIC, GENERIC //# 10: compile-time error Class.jsInteropGenerative(); //# 10: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 11: compile-time error + @JS('a') // GENERIC //# 11: compile-time error factory Class.jsInteropFact() => null; //# 11: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 12: compile-time error + @JS('a') // GENERIC //# 12: compile-time error external Class.externalJsInteropGenerative(); //# 12: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 13: compile-time error + @JS('a') // GENERIC //# 13: compile-time error external factory Class.externalJsInteropFact(); //# 13: continued var instanceField; @@ -84,28 +84,28 @@ class Class { static set staticSetter(_) {} static staticMethod() {} - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 14: compile-time error + @JS('a') // GENERIC //# 14: compile-time error var instanceJsInteropField; //# 14: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 15: compile-time error + @JS('a') // GENERIC //# 15: compile-time error get instanceJsInteropGetter => null; //# 15: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 16: compile-time error + @JS('a') // GENERIC //# 16: compile-time error set instanceJsInteropSetter(_) {} //# 16: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 17: compile-time error + @JS('a') // GENERIC //# 17: compile-time error instanceJsInteropMethod() {} //# 17: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 18: compile-time error + @JS('a') // GENERIC //# 18: compile-time error static var staticJsInteropField; //# 18: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 19: compile-time error + @JS('a') // GENERIC //# 19: compile-time error static get staticJsInteropGetter => null; //# 19: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 20: compile-time error + @JS('a') // GENERIC //# 20: compile-time error static set staticJsInteropSetter(_) {} //# 20: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 21: compile-time error + @JS('a') // GENERIC //# 21: compile-time error static staticJsInteropMethod() {} //# 21: continued // NON_NATIVE_EXTERNAL //# 22: compile-time error @@ -126,22 +126,22 @@ class Class { // NON_NATIVE_EXTERNAL //# 27: compile-time error external static externalStaticMethod(); //# 27: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 28: compile-time error + @JS('a') // GENERIC //# 28: compile-time error external get externalInstanceJsInteropGetter; //# 28: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 29: compile-time error + @JS('a') // GENERIC //# 29: compile-time error external set externalInstanceJsInteropSetter(_); //# 29: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 30: compile-time error + @JS('a') // GENERIC //# 30: compile-time error external externalInstanceJsInteropMethod(); //# 30: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 31: compile-time error + @JS('a') // GENERIC //# 31: compile-time error external static get externalStaticJsInteropGetter; //# 31: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 32: compile-time error + @JS('a') // GENERIC //# 32: compile-time error external static set externalStaticJsInteropSetter(_); //# 32: continued - @JS('a') // JS_INTEROP_MEMBER_IN_NON_JS_INTEROP_CLASS //# 33: compile-time error + @JS('a') // GENERIC //# 33: compile-time error external static externalStaticJsInteropMethod(); //# 33: continued } diff --git a/tests/lib/js/js_annotation_static_test.dart b/tests/lib/js/js_annotation_static_test.dart new file mode 100644 index 00000000000..ef7dc40e91c --- /dev/null +++ b/tests/lib/js/js_annotation_static_test.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// TODO(srujzs): Fix this test once web static error testing is supported. + +// Tests static errors for incorrect JS annotations. + +@JS() +library js_annotation_static_test; + +import 'package:js/js.dart'; + +class Foo { + // ^^^ + // [web] TODO(srujzs): Test context once supported. + @JS() + external Foo(int bar); + // ^ + // [web] TODO(srujzs): Add error once supported. + @JS() + external factory Foo.fooFactory(); + // ^ + // [web] TODO(srujzs): Add error once supported. + @JS() + external int get bar; + // ^^^ + // [web] TODO(srujzs): Add error once supported. + @JS() + external set bar(int val); + // ^^^ + // [web] TODO(srujzs): Add error once supported. + @JS() + external int baz(); + // ^^^ + // [web] TODO(srujzs): Add error once supported. + @JS() + external static int bazStatic(); + // ^^^^^^^^^ + // [web] TODO(srujzs): Add error once supported. +} + +@JS() +external int qux(); + +main() {}