ql.io-compiler
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -15,3 +15,3 @@ /* | ||
* limitations under the License. | ||
*/ | ||
**/ | ||
@@ -58,2 +58,41 @@ 'use strict'; | ||
var maxid = 0; | ||
function divescope(lines, scope) { | ||
if (!lines){ | ||
return; | ||
} | ||
var i, line; | ||
for (i = 0; i < lines.length; i++) { | ||
line = lines[i]; | ||
maxid = line.id > maxid ? line.id : maxid; | ||
if(scope){ | ||
line.scope = scope; | ||
} | ||
if(line.assign) { | ||
if(symbols[line.assign]) { | ||
throw new this.SyntaxError('Duplicate symbol ' + line.assign); | ||
} | ||
else { | ||
symbols[line.assign] = line; | ||
} | ||
} | ||
else if(line.type === 'create') { // Makes sense when DDL is inline | ||
symbols[line.name] = line; | ||
creates[line.id.toString()] = line; | ||
} | ||
else if (line.type === 'if') { | ||
divescope(line.if, line); | ||
divescope(line.else, line); | ||
} | ||
else if (line.type === 'try') { | ||
//dependsOn are the lines in try clause | ||
divescope(line.dependsOn, line); | ||
_.each(line.catchClause, function(k, mycatch){ | ||
divescope(mycatch.lines, line); | ||
}); | ||
if(line.finallyClause) { | ||
divescope(line.finallyClause, line); | ||
} | ||
} | ||
} | ||
} | ||
for(i = 0; i < compiled.length; i++) { | ||
@@ -87,2 +126,20 @@ line = compiled[i]; | ||
} | ||
else if (line.type === 'if') { | ||
divescope(line.if, line); | ||
if (line.else){ | ||
divescope(line.else, line); | ||
} | ||
single = line; | ||
} | ||
else if (line.type === 'try') { | ||
//dependsOn are the lines in try clause | ||
divescope(line.dependsOn,line); | ||
_.each(line.catchClause, function(mycatch, k){ | ||
divescope(mycatch.lines, line); | ||
}); | ||
if(line.finallyClause) { | ||
divescope(line.finallyClause, line); | ||
} | ||
single = line; | ||
} | ||
else { | ||
@@ -144,2 +201,5 @@ single = line; | ||
} | ||
if(node.scope) { | ||
used.push(node.scope.id); | ||
} | ||
} | ||
@@ -177,3 +237,2 @@ used.push(ret.rhs.id); | ||
ret.rhs.dependsOn = creates.concat(ret.rhs.dependsOn); | ||
return ret; | ||
@@ -195,13 +254,5 @@ } | ||
introspectObject(line.object, symbols, line.dependsOn, line); | ||
if(line.fallback) { | ||
walk(line.fallback, symbols); | ||
} | ||
break; | ||
case 'return': | ||
walk(line.rhs, symbols); | ||
if(line.fallback) { | ||
walk(line.fallback, symbols); | ||
} | ||
// Route | ||
@@ -221,12 +272,19 @@ if(line.route) { | ||
line = introspectWhere(line, symbols); | ||
if(line.fallback) { | ||
walk(line.fallback, symbols); | ||
} | ||
break; | ||
case 'insert': | ||
introspectFrom(line, [line.source], symbols); | ||
if(line.fallback) { | ||
walk(line.fallback, symbols); | ||
if(line.columns){ | ||
_.each(line.values, function(val) { | ||
//introspectString(line, val, symbols); | ||
introspectString(val, symbols, line.dependsOn, line); | ||
}) | ||
} | ||
if(line.jsonObj) { | ||
introspectString(line.jsonObj.value, symbols, line.dependsOn, line); | ||
} | ||
break; | ||
case 'update': | ||
introspectFrom(line, [line.source], symbols); | ||
introspectString(line.withClause.value, symbols, line.dependsOn, line); | ||
break; | ||
case 'select': | ||
@@ -239,7 +297,43 @@ introspectFrom(line, line.fromClause, symbols); | ||
} | ||
if(line.fallback) { | ||
walk(line.fallback, symbols); | ||
break; | ||
case 'if': | ||
addDep(line, line.dependsOn, line.condition, symbols); | ||
walk(line.condition, symbols); | ||
_.each(line.if, function(ifline){ | ||
walk(ifline, symbols); | ||
}); | ||
if(line.else){ | ||
_.each(line.else, function(elseline){ | ||
walk(elseline, symbols); | ||
}) | ||
} | ||
break; | ||
case 'logic': | ||
var condDepends = logicVars(line, symbols); | ||
_.each(condDepends, function(dependency){ | ||
addDep(line, line.dependsOn, dependency, symbols); | ||
walk(dependency, symbols); | ||
}); | ||
break; | ||
case 'try': | ||
_.each(line.dependsOn, function(tryline){ | ||
addListener(tryline, line); | ||
walk(tryline, symbols); | ||
}); | ||
_.each(line.catchClause, function(currentcatch){ | ||
walk(currentcatch.condition, symbols); | ||
_.each(currentcatch.lines, function(catchline){ | ||
walk(catchline, symbols); | ||
}) | ||
}); | ||
if(line.finallyClause) { | ||
_.each(line.finallyClause, function(finallyline){ | ||
walk(finallyline, symbols); | ||
}); | ||
} | ||
break; | ||
} | ||
if(line.fallback) { | ||
walk(line.fallback, symbols); | ||
} | ||
} | ||
@@ -481,1 +575,19 @@ | ||
} | ||
// find all variables that appears in a logic condition. | ||
function logicVars(condition, symbols){ | ||
if(_.isString(condition.values)){ | ||
var conditionDep = symbols[condition.values]; | ||
if (conditionDep) { | ||
return [conditionDep]; | ||
}else{ | ||
return []; | ||
} | ||
} | ||
else if (!_.isArray(condition.values)){ | ||
return logicVars(condition.values, symbols); | ||
} | ||
return _.reduce(condition.values, function(memo, val){ | ||
return memo.concat(logicVars(val, symbols)); | ||
}, []) | ||
} |
{ | ||
"author": "ql.io", | ||
"name": "ql.io-compiler", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
494991
9792
1