Skip to content

Commit

Permalink
Added conversion for setter args - fixed defs file again.
Browse files Browse the repository at this point in the history
  • Loading branch information
yGuy committed Feb 7, 2018
1 parent ce11589 commit 425fde7
Show file tree
Hide file tree
Showing 4 changed files with 857 additions and 7 deletions.
68 changes: 64 additions & 4 deletions lib/migration-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ AbstractMemberTransformation.prototype.detect = function (node, parent, stack) {
var type = object.scopeInfo.type;

type = getType(type, transformationTargets, oldMemberName, stack);

if (type.type === "?") {
return null;
}
Expand Down Expand Up @@ -239,6 +239,65 @@ function isReservedMember(keyName) {
|| keyName === "$static" || keyName === "$clinit";
}

/**
* @param {Object} config
* @constructor
* @extends AbstractTransformation
*/
function SetterArgTransformation(config) {
AbstractTransformation.call(this, config["memberRenamings"]);
}
SetterArgTransformation.prototype = Object.create(AbstractTransformation.prototype);

/**
* @param {Node} node
* @param {Node} parent
* @return {AbstractResolver|null}
*/
SetterArgTransformation.prototype.detect = function detect(node, parent, stack) {
if (node.type === Syntax.Property && node.kind === "init" && stack[1].type === Syntax.ObjectExpression && stack[2].type === Syntax.NewExpression){
if (stack[2].scopeInfo && stack[2].scopeInfo.type){
var key = node.key.type === Syntax.Literal ? node.key.value : node.key.name;
var object = stack[2];
var type = object.scopeInfo.type;

var safe = type.type !== "?";
type = getType(type, this.transformationTargets, key, stack);
if (type){
let renames = this.transformationTargets[type.type];
if (renames){
if (renames[key]){
if (!safe){
return new ConfidentCommentResolver(this, "'" + memberToString(type.type, key) + "' has been renamed to '" + renames[key] + "'", true);
} else {
return new AutomaticResolver(this);
}
}
}
}
}
}
};
/**
* @param {Node} node
* @param {Node|null} parent
*/
SetterArgTransformation.prototype.perform = function perform(node, parent, stack) {
var key = node.key.type === Syntax.Literal ? node.key.value : node.key.name;
var object = stack[2];
var type = object.scopeInfo.type;

var newName = this.transformationTargets[getType(type, this.transformationTargets, key, stack).type][key];

if (node.key.type === Syntax.Literal) {
node.key.value = newName;
} else {
node.key.name = newName;
}
};



/**
* @param {Object} config
* @constructor
Expand Down Expand Up @@ -799,7 +858,7 @@ function ConfidentCommentResolver(transformation, comment, keepOldLine) {
}
ConfidentCommentResolver.prototype = Object.create(AbstractResolver.prototype);

ConfidentCommentResolver.prototype.resolve = function (node, parent) {
ConfidentCommentResolver.prototype.resolve = function (node, parent, stack) {
commentsCount++;

var rawComments = [].concat(
Expand All @@ -814,7 +873,7 @@ ConfidentCommentResolver.prototype.resolve = function (node, parent) {

var comments = createCommentsAst(rawComments);

node = AbstractResolver.prototype.resolve.call(this, node, parent);
node = AbstractResolver.prototype.resolve.call(this, node, parent, stack);

attachComments(node, comments);
};
Expand Down Expand Up @@ -1041,7 +1100,8 @@ module.exports = function (files, finishedCallback, convertClassDeclarations) {
new MemberRemovedTransformation(config),
new TypeRemovedTransformation(config),
new ChangeNamespaceTransformation(config),
new MemberRenameTransformation(config)
new MemberRenameTransformation(config),
new SetterArgTransformation(config),
];


Expand Down
4 changes: 2 additions & 2 deletions lib/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ function AbstractResolver(transformation) {
* @param {Node} parent
* @return {Node|undefined}
*/
AbstractResolver.prototype.resolve = function (node, parent) {
AbstractResolver.prototype.resolve = function (node, parent, stack) {
return this.transformations.reduce(function (node, transformation) {
return transformation.perform(node, parent) || node;
return transformation.perform(node, parent, stack) || node;
}, node);
};

Expand Down
2 changes: 1 addition & 1 deletion lib/yfilesDefs.js

Large diffs are not rendered by default.

Loading

0 comments on commit 425fde7

Please sign in to comment.