Skip to content

Commit 681e16a

Browse files
natebiggsCommit Queue
authored andcommitted
Add support for const field access in @js() constructor invocation.
Bug: b/367811144 Change-Id: Icfab309499861047a7ef9a528213b4c476a88686 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388800 Commit-Queue: Nate Biggs <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]> Auto-Submit: Nate Biggs <[email protected]>
1 parent ac2a58a commit 681e16a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/_js_interop_checks/lib/src/js_interop.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,25 @@ List<String> stringAnnotationValues(Expression node) {
222222
'positional argument: $node.');
223223
} else if (argLength == 1) {
224224
var value = node.arguments.positional[0];
225-
if (value is StringLiteral) values.addAll(value.value.split(','));
225+
if (value is StringLiteral) {
226+
values.addAll(value.value.split(','));
227+
} else if (value is StaticGet) {
228+
// Sometimes the CFE will translate the following to a StaticGet of a
229+
// const field:
230+
//
231+
// const String fieldName = 'field';
232+
// @JS(fieldName)
233+
//
234+
// In this case we derive the name from the intializer of the referenced
235+
// field.
236+
var target = value.target;
237+
if (target is Field && target.isConst) {
238+
final value = target.initializer;
239+
if (value is StringLiteral) {
240+
values.addAll(value.value.split(','));
241+
}
242+
}
243+
}
226244
}
227245
}
228246
return values;

0 commit comments

Comments
 (0)