Skip to content

JS Specific Challenges while Extending RM

Shiblu edited this page Jan 19, 2022 · 4 revisions

Challenges Faced in JavaScript

Operation Invocations

Although Refactoring Miner has fairly language-independent logic for mapping statements, many of them are not. For example, function invocations can be written without any name. Consider the following javaScript self-invoking function pattern where the function declared inside the single parenthesis immediately starts executing itself as soon as it is declared.

(function (){
   alert('Hello');
})
();

In this case, we cannot put a name for the functionName property of this invocation but the refactoring miner needs the name of operation invocation to work properly. We could potentially name it as the whole text of the function declaration but the is not feasible as we have found that sometimes whole scripts of more than 13KLOC are written inside of such functions. Besides, it would potentially hamper the performance since in String edit distance algorithm would take too much time for such large strings.

Related issue #43

Operations cannot be assigned to variables One of the main difficulties of extending the Refactoring miner is that it does not consider that functions are actually variables in javascript and can be assigned.

Technical List of changes made

argumentIsReturned(String statement); argumentIsEqual(String statement);

Rest Syntax Here inside of a class declaration, state object contains a spread syntax (...)

  state = {
    ...Touchable.Mixin.touchableGetInitialState(),
    isHighlighted: false,
    createResponderHandlers: this._createResponseHandlers.bind(this),
    responseHandlers: null,
  };

**Nested Object Declarations **

https://github.com/chartjs/Chart.js/commit/326991ce50c36fd714aefc5bafd4cbe53806051f#diff-d3292ae69bd072d0aef6419e8a645f75eee76a8dfbc271d46449f580f80d34fe

src\core\core.interaction.js line 140

module.exports = {
	// Helper function for different modes
	modes: {
		single: function(chart, e) {
			var position = getRelativePosition(e, chart);
			var elements = [];

			parseVisibleItems(chart, function(element) {
				if (element.inRange(position.x, position.y)) {
					elements.push(element);
					return elements;
				}
			});
Clone this wiki locally