Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kobezzza committed Apr 13, 2015
1 parent 31b2743 commit f1ddd79
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions lib/api/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
* @return {!Array}
*/
DirObj.prototype.getFnArgs = function (str) {
var res = [],
params = false;
const res = [];

var pOpen = 0,
arg = '';
let
pOpen = 0,
arg = '',
params = false;

for (let i = -1; ++i < str.length;) {
let el = str[i];
Expand Down Expand Up @@ -58,7 +59,7 @@ DirObj.prototype.getFnArgs = function (str) {
return res;
};

var scopeModRgxp = new RegExp(`^${G_MOD}+`);
const scopeModRgxp = new RegExp(`^${G_MOD}+`);

/**
* Searches function arguments from a string
Expand All @@ -73,11 +74,13 @@ var scopeModRgxp = new RegExp(`^${G_MOD}+`);
*/
DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplName, opt_name) {
opt_tplName = this.tplName;
var struct = this.structure;
var argsList = this.getFnArgs(str),
let
struct = this.structure,
argsList = this.getFnArgs(str),
params = argsList.params;

var parentArgs,
let
parentArgs,
argsTable;

if (!argsCache[opt_tplName]) {
Expand Down Expand Up @@ -120,7 +123,7 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
argsTable = argsCache[opt_tplName][type];
}

var scope;
let scope;
for (let i = -1; ++i < argsList.length;) {
let arg = argsList[i].split('=');
arg[0] = arg[0].trim();
Expand Down Expand Up @@ -164,10 +167,12 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
aKey = `@${key}`;
}

let rKey = argsTable[key] ?
key : aKey;
const
rKey = argsTable[key] ?
key : aKey;

let current = argsTable[rKey],
const
current = argsTable[rKey],
cVal = current &&
current.value === undefined;

Expand All @@ -193,7 +198,7 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
});

argsList = [];
var localVars = [];
const localVars = [];

forIn(argsTable, (el) => {
if (el.local) {
Expand All @@ -204,13 +209,16 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
}
});

var consts = constCache[this.tplName],
const
consts = constCache[this.tplName],
constsCache = {};

var decl = '',
let
decl = '',
defParams = '';

var locals = [];
const
locals = [];

for (let i = -1; ++i < localVars.length;) {
let el = localVars[i];
Expand Down Expand Up @@ -239,7 +247,8 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
};
}

var args = [],
let
args = [],
needArgs = type === 'proto';

if (needArgs) {
Expand All @@ -259,9 +268,12 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
}

for (let i = -1; ++i < argsList.length;) {
let el = argsList[i];
let
el = argsList[i];

el.key = el.key
.replace(scopeModRgxp, '');

el.key = el.key.replace(scopeModRgxp, '');
let old = el.key;

if (consts[old] && opt_name) {
Expand All @@ -282,7 +294,8 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
decl += el.key;

if (el.value !== undefined) {
defParams += `${el.key} = ${el.key} != null ? ${el.key} : ${this.prepareOutput(this.replaceDangerBlocks(el.value), true)};`;
defParams +=
`${el.key} = ${el.key} != null ? ${el.key} : ${this.prepareOutput(this.replaceDangerBlocks(el.value), true)};`;
}

if (i !== argsList.length - 1) {
Expand All @@ -301,8 +314,7 @@ DirObj.prototype.prepareArgs = function (str, type, opt_tplName, opt_parentTplNa
}

struct.params._consts = constsCache;

var res = {
const res = {
params: params,
str: decl,
list: args,
Expand Down

0 comments on commit f1ddd79

Please sign in to comment.