@@ -169,7 +169,7 @@ AbstractMemberTransformation.prototype.detect = function (node, parent, stack) {
169169 var type = object . scopeInfo . type ;
170170
171171 type = getType ( type , transformationTargets , oldMemberName , stack ) ;
172-
172+
173173 if ( type . type === "?" ) {
174174 return null ;
175175 }
@@ -239,6 +239,65 @@ function isReservedMember(keyName) {
239239 || keyName === "$static" || keyName === "$clinit" ;
240240}
241241
242+ /**
243+ * @param {Object } config
244+ * @constructor
245+ * @extends AbstractTransformation
246+ */
247+ function SetterArgTransformation ( config ) {
248+ AbstractTransformation . call ( this , config [ "memberRenamings" ] ) ;
249+ }
250+ SetterArgTransformation . prototype = Object . create ( AbstractTransformation . prototype ) ;
251+
252+ /**
253+ * @param {Node } node
254+ * @param {Node } parent
255+ * @return {AbstractResolver|null }
256+ */
257+ SetterArgTransformation . prototype . detect = function detect ( node , parent , stack ) {
258+ if ( node . type === Syntax . Property && node . kind === "init" && stack [ 1 ] . type === Syntax . ObjectExpression && stack [ 2 ] . type === Syntax . NewExpression ) {
259+ if ( stack [ 2 ] . scopeInfo && stack [ 2 ] . scopeInfo . type ) {
260+ var key = node . key . type === Syntax . Literal ? node . key . value : node . key . name ;
261+ var object = stack [ 2 ] ;
262+ var type = object . scopeInfo . type ;
263+
264+ var safe = type . type !== "?" ;
265+ type = getType ( type , this . transformationTargets , key , stack ) ;
266+ if ( type ) {
267+ let renames = this . transformationTargets [ type . type ] ;
268+ if ( renames ) {
269+ if ( renames [ key ] ) {
270+ if ( ! safe ) {
271+ return new ConfidentCommentResolver ( this , "'" + memberToString ( type . type , key ) + "' has been renamed to '" + renames [ key ] + "'" , true ) ;
272+ } else {
273+ return new AutomaticResolver ( this ) ;
274+ }
275+ }
276+ }
277+ }
278+ }
279+ }
280+ } ;
281+ /**
282+ * @param {Node } node
283+ * @param {Node|null } parent
284+ */
285+ SetterArgTransformation . prototype . perform = function perform ( node , parent , stack ) {
286+ var key = node . key . type === Syntax . Literal ? node . key . value : node . key . name ;
287+ var object = stack [ 2 ] ;
288+ var type = object . scopeInfo . type ;
289+
290+ var newName = this . transformationTargets [ getType ( type , this . transformationTargets , key , stack ) . type ] [ key ] ;
291+
292+ if ( node . key . type === Syntax . Literal ) {
293+ node . key . value = newName ;
294+ } else {
295+ node . key . name = newName ;
296+ }
297+ } ;
298+
299+
300+
242301/**
243302 * @param {Object } config
244303 * @constructor
@@ -799,7 +858,7 @@ function ConfidentCommentResolver(transformation, comment, keepOldLine) {
799858}
800859ConfidentCommentResolver . prototype = Object . create ( AbstractResolver . prototype ) ;
801860
802- ConfidentCommentResolver . prototype . resolve = function ( node , parent ) {
861+ ConfidentCommentResolver . prototype . resolve = function ( node , parent , stack ) {
803862 commentsCount ++ ;
804863
805864 var rawComments = [ ] . concat (
@@ -814,7 +873,7 @@ ConfidentCommentResolver.prototype.resolve = function (node, parent) {
814873
815874 var comments = createCommentsAst ( rawComments ) ;
816875
817- node = AbstractResolver . prototype . resolve . call ( this , node , parent ) ;
876+ node = AbstractResolver . prototype . resolve . call ( this , node , parent , stack ) ;
818877
819878 attachComments ( node , comments ) ;
820879} ;
@@ -1041,7 +1100,8 @@ module.exports = function (files, finishedCallback, convertClassDeclarations) {
10411100 new MemberRemovedTransformation ( config ) ,
10421101 new TypeRemovedTransformation ( config ) ,
10431102 new ChangeNamespaceTransformation ( config ) ,
1044- new MemberRenameTransformation ( config )
1103+ new MemberRenameTransformation ( config ) ,
1104+ new SetterArgTransformation ( config ) ,
10451105 ] ;
10461106
10471107
0 commit comments