Comparing version 0.0.5 to 0.0.6
# code-red changelog | ||
## 0.0.6 | ||
* Flatten arguments and parameters | ||
## 0.0.5 | ||
@@ -4,0 +8,0 @@ |
@@ -152,7 +152,7 @@ (function (global, factory) { | ||
const flatten = (array, target) => { | ||
const flatten_body = (array, target) => { | ||
for (let i = 0; i < array.length; i += 1) { | ||
const statement = array[i]; | ||
if (Array.isArray(statement)) { | ||
flatten(statement, target); | ||
flatten_body(statement, target); | ||
continue; | ||
@@ -165,3 +165,3 @@ } | ||
if (Array.isArray(statement.expression)) { | ||
flatten(statement.expression, target); | ||
flatten_body(statement.expression, target); | ||
continue; | ||
@@ -177,2 +177,19 @@ } | ||
const flatten = (nodes, target) => { | ||
for (let i = 0; i < nodes.length; i += 1) { | ||
const node = nodes[i]; | ||
if (!node) continue; | ||
if (Array.isArray(node)) { | ||
flatten(node, target); | ||
continue; | ||
} | ||
target.push(node); | ||
} | ||
return target; | ||
}; | ||
const inject = (node, values) => { | ||
@@ -188,10 +205,14 @@ estreeWalker.walk(node, { | ||
if (match) { | ||
const value = match[1] | ||
? +match[1] in values ? values[+match[1]] : match[1] | ||
: { type: 'Identifier', name: `${match[2] ? `@` : `#`}${match[4]}` }; | ||
if (match[1]) { | ||
if (+match[1] in values) { | ||
const value = values[+match[1]]; | ||
if (index === null) { | ||
parent[key] = value; | ||
if (index === null) { | ||
parent[key] = value; | ||
} else { | ||
parent[key][index] = value; | ||
} | ||
} | ||
} else { | ||
parent[key][index] = value; | ||
node.name = `${match[2] ? `@` : `#`}${match[4]}`; | ||
} | ||
@@ -202,4 +223,7 @@ } | ||
if (node.type === 'Program' || node.type === 'BlockStatement') { | ||
node.body = flatten(node.body, []); | ||
node.body = flatten_body(node.body, []); | ||
} | ||
if (node.params) node.params = flatten(node.params, []); | ||
if (node.arguments) node.arguments = flatten(node.arguments, []); | ||
} | ||
@@ -223,3 +247,3 @@ }); | ||
} catch (err) { | ||
console.log(str); // TODO proper error reporting | ||
console.log(`failed to parse:\n${str}`); // TODO proper error reporting | ||
throw err; | ||
@@ -239,3 +263,3 @@ } | ||
} catch (err) { | ||
console.log(str); // TODO proper error reporting | ||
console.log(`failed to parse:\n${str}`); // TODO proper error reporting | ||
throw err; | ||
@@ -242,0 +266,0 @@ } |
{ | ||
"name": "code-red", | ||
"description": "code-red", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"repository": "Rich-Harris/code-red", | ||
@@ -6,0 +6,0 @@ "main": "dist/code-red.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16325
433