ifdef-loader
Advanced tools
Comparing version 0.0.9 to 0.0.10
{ | ||
"name": "ifdef-loader", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "#ifdef conditional Webpack loader", | ||
@@ -5,0 +5,0 @@ "main": "ifdef-loader.js", |
@@ -13,14 +13,14 @@ "use strict"; | ||
var cond = evaluate(startInfo.condition, startInfo.keyword, defs); | ||
if (!cond) { | ||
blank_code(lines, startInfo.line, endLine); | ||
if (cond) { | ||
if (verbose) { | ||
console.log("matched condition #" + startInfo.keyword + " " + startInfo.condition + " => excluded lines [" + (startInfo.line + 1) + "-" + (endLine + 1) + "]"); | ||
console.log("matched condition #" + startInfo.keyword + " " + startInfo.condition + " => including lines [" + (startInfo.line + 1) + "-" + (endLine + 1) + "]"); | ||
} | ||
blank_code(lines, startInfo.line, startInfo.line); | ||
blank_code(lines, endLine, endLine); | ||
} | ||
else { | ||
blank_code(lines, startInfo.line, endLine); | ||
if (verbose) { | ||
console.log("unmatched condition #" + startInfo.keyword + " " + startInfo.condition); | ||
console.log("not matched condition #" + startInfo.keyword + " " + startInfo.condition + " => excluding lines [" + (startInfo.line + 1) + "-" + (endLine + 1) + "]"); | ||
} | ||
blank_code(lines, startInfo.line, startInfo.line); | ||
blank_code(lines, endLine, endLine); | ||
} | ||
@@ -79,7 +79,7 @@ n = startInfo.line; | ||
function evaluate(condition, keyword, defs) { | ||
var code = ""; | ||
var code = "(function(){"; | ||
for (var key in defs) { | ||
code += "var " + key + " = " + JSON.stringify(defs[key]) + ";"; | ||
} | ||
code += "(" + condition + ") ? true : false"; | ||
code += "return (" + condition + ") ? true : false;})()"; | ||
var result; | ||
@@ -86,0 +86,0 @@ try { |
@@ -21,14 +21,14 @@ interface IStart { | ||
if(!cond) { | ||
blank_code(lines, startInfo.line, endLine); | ||
if(cond) { | ||
if(verbose) { | ||
console.log(`matched condition #${startInfo.keyword} ${startInfo.condition} => excluded lines [${startInfo.line+1}-${endLine+1}]`); | ||
console.log(`matched condition #${startInfo.keyword} ${startInfo.condition} => including lines [${startInfo.line+1}-${endLine+1}]`); | ||
} | ||
blank_code(lines, startInfo.line, startInfo.line); | ||
blank_code(lines, endLine, endLine); | ||
} | ||
else { | ||
blank_code(lines, startInfo.line, endLine); | ||
if(verbose) { | ||
console.log(`unmatched condition #${startInfo.keyword} ${startInfo.condition}`); | ||
console.log(`not matched condition #${startInfo.keyword} ${startInfo.condition} => excluding lines [${startInfo.line+1}-${endLine+1}]`); | ||
} | ||
blank_code(lines, startInfo.line, startInfo.line); | ||
blank_code(lines, endLine, endLine); | ||
} | ||
@@ -99,8 +99,7 @@ | ||
let code = ""; | ||
let code = "(function(){"; | ||
for(let key in defs) { | ||
code += `var ${key} = ${JSON.stringify(defs[key])};`; | ||
} | ||
code += `(${condition}) ? true : false`; | ||
//console.log(code); | ||
code += `return (${condition}) ? true : false;})()`; | ||
@@ -107,0 +106,0 @@ let result: boolean; |
15692
474