From 66d4ae24dda238fca961a1a0b502d1ebf5c33fff Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Mon, 15 Jun 2020 13:07:48 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Add=20=E2=80=9Cstatic=E2=80=9D=20diagnostic?= =?UTF-8?q?=20support=20for=20Component2.defaultProps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/src/diagnostic/pseudo_static_lifecycle.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/over_react_analyzer_plugin/lib/src/diagnostic/pseudo_static_lifecycle.dart b/over_react_analyzer_plugin/lib/src/diagnostic/pseudo_static_lifecycle.dart index 92a12a95c..800185f5e 100644 --- a/over_react_analyzer_plugin/lib/src/diagnostic/pseudo_static_lifecycle.dart +++ b/over_react_analyzer_plugin/lib/src/diagnostic/pseudo_static_lifecycle.dart @@ -3,7 +3,7 @@ import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:over_react_analyzer_plugin/src/diagnostic/component_usage.dart'; -const staticMethodNames = ['getDefaultProps', 'getDerivedStateFromProps']; +const staticMethodNames = ['getDefaultProps', 'defaultProps', 'getDerivedStateFromProps']; const instanceMemberWhitelist = [ 'newProps', 'newState', From 519f4cc06b7ee21065c816bd06c06337976dbf49 Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Mon, 15 Jun 2020 13:08:12 -0700 Subject: [PATCH 2/2] Add test cases for PseudoStaticLifecycleDiagnostic --- playground/web/pseudo_static_lifecycle.dart | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 playground/web/pseudo_static_lifecycle.dart diff --git a/playground/web/pseudo_static_lifecycle.dart b/playground/web/pseudo_static_lifecycle.dart new file mode 100644 index 000000000..b5cf734ce --- /dev/null +++ b/playground/web/pseudo_static_lifecycle.dart @@ -0,0 +1,40 @@ +import 'package:over_react/over_react.dart'; + +part 'dom_prop_types.over_react.g.dart'; + +UiFactory HammerTime = + // ignore: undefined_identifier + _$HammerTime; + +mixin HammerTimeProps on UiProps { + String somethingThatCanBeTouched; +} + +mixin HammerTimeState on UiState {} + +class HammerTimeComponent extends UiStatefulComponent2 { + final mcHammer = 'cant touch this'; + + @override + get defaultProps { + return newProps() + ..somethingThatCanBeTouched = mcHammer; + } + + @override + getDerivedStateFromProps(Map nextProps, Map prevState) { + final tNextProps = typedPropsFactory(nextProps); + final tNextPropsJs = typedPropsFactoryJs(nextProps); + final tPrevState = typedStateFactory(prevState); + final tPrevStateJs = typedStateFactoryJs(prevState); + + if (props.somethingThatCanBeTouched == mcHammer) { + return newState(); + } + + return null; + } + + @override + render() {} +}