33// BSD-style license that can be found in the LICENSE file.
44
55import 'package:_js_interop_checks/src/js_interop.dart'
6- show getJSName, hasAnonymousAnnotation, hasJSInteropAnnotation;
6+ show
7+ getDartJSInteropJSName,
8+ getJSName,
9+ hasAnonymousAnnotation,
10+ hasJSInteropAnnotation;
711import 'package:_js_interop_checks/src/transformations/js_util_optimizer.dart'
812 show ExtensionIndex;
913import 'package:kernel/ast.dart' ;
@@ -343,9 +347,22 @@ class _ObjectLiteralSpecializer extends _InvocationSpecializer {
343347 .toList ();
344348 }
345349
350+ /// The name to use in JavaScript for the Dart parameter [variable] .
351+ ///
352+ /// This defaults to the name of the [variable] , but can be changed with a
353+ /// `@JS()` annotation.
354+ String _jsKey (VariableDeclaration variable) {
355+ // Only support `@JS` renaming on extension type object literal
356+ // constructors.
357+ final changedName = interopMethod.isExtensionTypeMember
358+ ? getDartJSInteropJSName (variable)
359+ : '' ;
360+ return changedName.isEmpty ? variable.name! : changedName;
361+ }
362+
346363 @override
347364 String bodyString (String object, List <String > callArguments) {
348- final keys = parameters.map ((named) => named.name ! ).toList ();
365+ final keys = parameters.map (_jsKey ).toList ();
349366 final keyValuePairs = < String > [];
350367 for (int i = 0 ; i < callArguments.length; i++ ) {
351368 keyValuePairs.add ('${keys [i ]}: ${callArguments [i ]}' );
@@ -362,8 +379,7 @@ class _ObjectLiteralSpecializer extends _InvocationSpecializer {
362379 // `Cons(a: 0)`, and `Cons(a: 1, b: 1)` only create two shapes:
363380 // `{a: value, b: value}` and `{a: value}`. Therefore, we only need two
364381 // methods to handle the `Cons` invocations.
365- final shape =
366- parameters.map ((VariableDeclaration decl) => decl.name).join ('|' );
382+ final shape = parameters.map (_jsKey).join ('|' );
367383 final interopProcedure = _jsObjectLiteralMethods
368384 .putIfAbsent (interopMethod, () => {})
369385 .putIfAbsent (shape, () => _getRawInteropProcedure ());
0 commit comments