Socket
Socket
Sign inDemoInstall

coffeescript

Package Overview
Dependencies
Maintainers
3
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coffeescript - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

test/test_option_parser.coffee

2

lib/coffee-script.js

@@ -18,3 +18,3 @@ (function(){

}
exports.VERSION = '0.7.0';
exports.VERSION = '0.7.1';
lexer = new Lexer();

@@ -21,0 +21,0 @@ exports.compile = (compile = function(code, options) {

@@ -42,2 +42,6 @@ (function(){

}
if (options.run) {
flags = sources.slice(1, sources.length + 1).concat(flags);
sources = [sources[0]];
}
process.ARGV = (process.argv = flags);

@@ -157,7 +161,3 @@ return compileScripts();

return path.exists(dir, function(exists) {
if (exists) {
return compile();
} else {
return exec(("mkdir -p " + dir), compile);
}
return exists ? compile() : exec(("mkdir -p " + dir), compile);
});

@@ -196,6 +196,6 @@ };

optionParser = new optparse.OptionParser(SWITCHES, BANNER);
o = (options = optionParser.parse(process.argv));
o = (options = optionParser.parse(process.argv.slice(2, process.argv.length)));
options.run = !(o.compile || o.print || o.lint);
options.print = !!(o.print || (o.eval || o.stdio && o.compile));
sources = options.arguments.slice(2, options.arguments.length);
sources = options.arguments;
return sources;

@@ -202,0 +202,0 @@ };

@@ -37,3 +37,3 @@ (function(){

],
Expression: [o("Value"), o("Call"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Splat"), o("Existence")],
Expression: [o("Value"), o("Call"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Splat"), o("Existence"), o("Comment")],
Block: [

@@ -44,2 +44,4 @@ o("INDENT Body OUTDENT", function() {

return new Expressions();
}), o("TERMINATOR Comment", function() {
return Expressions.wrap([$2]);
})

@@ -90,3 +92,3 @@ ],

return new AssignNode(new ValueNode($1), $3, 'object');
})
}), o("Comment")
],

@@ -100,2 +102,7 @@ Return: [

],
Comment: [
o("HERECOMMENT", function() {
return new CommentNode($1);
})
],
Existence: [

@@ -239,5 +246,7 @@ o("Expression ?", function() {

Call: [
o("Invocation"), o("NEW Invocation", function() {
o("Invocation"), o("Super"), o("NEW Invocation", function() {
return $2.newInstance();
}), o("Super")
}), o("NEW Value", function() {
return (new CallNode($2, [])).newInstance();
})
],

@@ -312,7 +321,3 @@ Extends: [

o("Expression"), o("SimpleArgs , Expression", function() {
if ($1 instanceof Array) {
return $1.concat([$3]);
} else {
return [$1].concat([$3]);
}
return $1 instanceof Array ? $1.concat([$3]) : [$1].concat([$3]);
})

@@ -569,3 +574,3 @@ ],

return new OpNode('||', $1, $3);
}), o("Expression ? Expression", function() {
}), o("Expression OP? Expression", function() {
return new OpNode('?', $1, $3);

@@ -601,3 +606,3 @@ }), o("Expression -= Expression", function() {

};
operators = [["left", '?'], ["nonassoc", 'UMINUS', 'UPLUS', '!', '!!', '~', '++', '--'], ["left", '*', '/', '%'], ["left", '+', '-'], ["left", '<<', '>>', '>>>'], ["left", '&', '|', '^'], ["left", '<=', '<', '>', '>='], ["right", 'DELETE', 'INSTANCEOF', 'TYPEOF'], ["left", '==', '!='], ["left", '&&', '||'], ["right", '-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?='], ["left", '.'], ["right", 'INDENT'], ["left", 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'NEW', 'SUPER', 'CLASS'], ["left", 'EXTENDS'], ["right", 'ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'IF', 'ELSE']];
operators = [["left", '?'], ["nonassoc", 'UMINUS', 'UPLUS', '!', '!!', '~', '++', '--'], ["left", '*', '/', '%'], ["left", '+', '-'], ["left", '<<', '>>', '>>>'], ["left", '&', '|', '^'], ["left", '<=', '<', '>', '>='], ["right", 'DELETE', 'INSTANCEOF', 'TYPEOF'], ["left", '==', '!='], ["left", '&&', '||', 'OP?'], ["right", '-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?='], ["left", '.'], ["right", 'INDENT'], ["left", 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'NEW', 'SUPER', 'CLASS'], ["left", 'EXTENDS'], ["right", 'ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'IF', 'ELSE']];
tokens = [];

@@ -604,0 +609,0 @@ _a = grammar;

@@ -155,3 +155,3 @@ (function(){

Lexer.prototype.commentToken = function() {
var match;
var comment, match;
if (!(match = this.chunk.match(COMMENT))) {

@@ -162,2 +162,9 @@ return false;

this.i += match[1].length;
if (match[2]) {
comment = this.sanitizeHeredoc(match[2], {
herecomment: true
});
this.token('HERECOMMENT', comment.split(MULTILINER));
this.token('TERMINATOR', '\n');
}
return true;

@@ -304,2 +311,4 @@ };

tag = 'TERMINATOR';
} else if (value === '?' && prevSpaced) {
tag = 'OP?';
} else if (include(CALLABLE, this.tag()) && !prevSpaced) {

@@ -344,7 +353,3 @@ if (value === '(') {

}).call(this);
if (accessor) {
return 'accessor';
} else {
return false;
}
return accessor ? 'accessor' : false;
};

@@ -359,6 +364,13 @@ Lexer.prototype.sanitizeHeredoc = function(doc, options) {

}
return doc.replace(new RegExp("^" + indent, 'gm'), '').replace(MULTILINER, "\\n").replace(new RegExp(options.quote, 'g'), ("\\" + options.quote));
doc = doc.replace(new RegExp("^" + indent, 'gm'), '');
if (options.herecomment) {
return doc;
}
return doc.replace(MULTILINER, "\\n").replace(new RegExp(options.quote, 'g'), ("\\" + options.quote));
};
Lexer.prototype.tagHalfAssignment = function(tag) {
var last;
if (tag === 'OP?') {
tag = '?';
}
last = this.tokens.pop();

@@ -441,7 +453,3 @@ this.tokens.push([("" + tag + "="), ("" + tag + "="), last[2]]);

}
if (!i) {
return false;
} else {
return str.substring(0, i);
}
return !i ? false : str.substring(0, i);
};

@@ -481,2 +489,3 @@ Lexer.prototype.interpolateString = function(str, escapeQuotes) {

if (inner.length) {
inner = inner.replace(new RegExp('\\\\' + quote, 'g'), quote);
nested = lexer.tokenize(("(" + inner + ")"), {

@@ -567,7 +576,3 @@ line: this.line

}
if (m) {
return m[index];
} else {
return false;
}
return m ? m[index] : false;
};

@@ -590,5 +595,5 @@ Lexer.prototype.unfinished = function() {

INTERPOLATION = /^\$([a-zA-Z_@]\w*(\.\w+)*)/;
OPERATOR = /^([+\*&|\/\-%=<>:!?]+)([ \t]*)/;
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>:!?]+)([ \t]*)/;
WHITESPACE = /^([ \t]+)/;
COMMENT = /^(\s*#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*#{3}|(\s*#[^\n]*)+)/;
COMMENT = /^(\s*#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*#{3}|(\s*#(?!##[^#])[^\n]*)+)/;
CODE = /^((-|=)>)/;

@@ -608,3 +613,3 @@ MULTI_DENT = /^((\n([ \t]*))+)(\.)?/;

HEREDOC_INDENT = /(\n+([ \t]*)|^([ \t]+))/g;
ASSIGNED = /^([a-zA-Z\$_]\w*[ \t]*?[:=])/;
ASSIGNED = /^([a-zA-Z\$_]\w*[ \t]*?[:=][^=])/;
NEXT_CHARACTER = /^\s*(\S)/;

@@ -614,3 +619,3 @@ NOT_REGEX = ['NUMBER', 'REGEX', '++', '--', 'FALSE', 'NULL', 'TRUE', ']'];

LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
HALF_ASSIGNMENTS = ['-', '+', '/', '*', '%', '||', '&&', '?'];
HALF_ASSIGNMENTS = ['-', '+', '/', '*', '%', '||', '&&', '?', 'OP?'];
CONVERSIONS = {

@@ -617,0 +622,0 @@ 'and': '&&',

(function(){
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, DOUBLE_PARENS, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NUMBER, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, _a, compact, del, flatten, helpers, include, indexOf, literal, merge, starts, utility;
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, DOUBLE_PARENS, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NUMBER, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, _a, compact, del, flatten, helpers, include, indexOf, literal, merge, starts, utility;
var __extends = function(child, parent) {

@@ -39,8 +39,4 @@ var ctor = function(){ };

top = this.topSensitive() ? this.options.top : del(this.options, 'top');
closure = this.isStatement() && !this.isPureStatement() && !top && !this.options.asStatement && !this.containsPureStatement();
if (closure) {
return this.compileClosure(this.options);
} else {
return this.compileNode(this.options);
}
closure = this.isStatement() && !this.isPureStatement() && !top && !this.options.asStatement && !(this instanceof CommentNode) && !this.containsPureStatement();
return closure ? this.compileClosure(this.options) : this.compileNode(this.options);
};

@@ -104,6 +100,6 @@ BaseNode.prototype.compileClosure = function(o) {

};
BaseNode.prototype.toString = function(idt) {
var _b, _c, _d, _e, child;
BaseNode.prototype.toString = function(idt, override) {
var _b, _c, _d, _e, child, children;
idt = idt || '';
return '\n' + idt + this['class'] + (function() {
children = (function() {
_b = []; _d = this.collectChildren();

@@ -116,2 +112,3 @@ for (_c = 0, _e = _d.length; _c < _e; _c++) {

}).call(this).join('');
return '\n' + idt + (override || this['class']) + children;
};

@@ -190,7 +187,3 @@ BaseNode.prototype.eachChild = function(func) {

Expressions.prototype.unwrap = function() {
if (this.expressions.length === 1) {
return this.expressions[0];
} else {
return this;
}
return this.expressions.length === 1 ? this.expressions[0] : this;
};

@@ -204,2 +197,5 @@ Expressions.prototype.empty = function() {

last = this.expressions[idx];
if (last instanceof CommentNode) {
last = this.expressions[idx -= 1];
}
if (!last || last instanceof ReturnNode) {

@@ -213,7 +209,3 @@ return this;

o = o || {};
if (o.scope) {
return Expressions.__superClass__.compile.call(this, o);
} else {
return this.compileRoot(o);
}
return o.scope ? Expressions.__superClass__.compile.call(this, o) : this.compileRoot(o);
};

@@ -235,10 +227,6 @@ Expressions.prototype.compileNode = function(o) {

o.scope = new Scope(null, this, null);
code = o.globals ? this.compileNode(o) : this.compileWithDeclarations(o);
code = this.compileWithDeclarations(o);
code = code.replace(TRAILING_WHITESPACE, '');
code = code.replace(DOUBLE_PARENS, '($1)');
if (o.noWrap) {
return code;
} else {
return "(function(){\n" + code + "\n})();\n";
}
return o.noWrap ? code : ("(function(){\n" + code + "\n})();\n");
};

@@ -251,3 +239,3 @@ Expressions.prototype.compileWithDeclarations = function(o) {

}
if (o.scope.hasDeclarations(this)) {
if (!o.globals && o.scope.hasDeclarations(this)) {
code = ("" + (this.tab) + "var " + (o.scope.compiledDeclarations()) + ";\n" + code);

@@ -263,7 +251,3 @@ }

}));
if (node.isStatement()) {
return compiledNode;
} else {
return "" + (this.idt()) + compiledNode + ";";
}
return node.isStatement() ? compiledNode : ("" + (this.idt()) + compiledNode + ";");
};

@@ -314,9 +298,6 @@ return Expressions;

ReturnNode.prototype.children = ['expression'];
ReturnNode.prototype.topSensitive = function() {
return true;
};
ReturnNode.prototype.makeReturn = function() {
return this;
};
ReturnNode.prototype.compileNode = function(o) {
ReturnNode.prototype.compile = function(o) {
var expr;

@@ -327,3 +308,5 @@ expr = this.expression.makeReturn();

}
del(o, 'top');
return ReturnNode.__superClass__.compile.call(this, o);
};
ReturnNode.prototype.compileNode = function(o) {
if (this.expression.isStatement()) {

@@ -363,14 +346,6 @@ o.asStatement = true;

ValueNode.prototype.makeReturn = function() {
if (this.hasProperties()) {
return ValueNode.__superClass__.makeReturn.call(this);
} else {
return this.base.makeReturn();
}
return this.hasProperties() ? ValueNode.__superClass__.makeReturn.call(this) : this.base.makeReturn();
};
ValueNode.prototype.unwrap = function() {
if (this.properties.length) {
return this;
} else {
return this.base;
}
return this.properties.length ? this : this.base;
};

@@ -394,2 +369,5 @@ ValueNode.prototype.isStatement = function() {

};
ValueNode.prototype.compile = function(o) {
return !o.top || this.properties.length ? ValueNode.__superClass__.compile.call(this, o) : this.base.compile(o);
};
ValueNode.prototype.compileNode = function(o) {

@@ -426,10 +404,26 @@ var _b, _c, baseline, complete, i, only, op, part, prop, props, temp;

}
if (op && this.wrapped) {
return "(" + complete + ")";
} else {
return complete;
}
return op && this.wrapped ? ("(" + complete + ")") : complete;
};
return ValueNode;
})();
exports.CommentNode = (function() {
CommentNode = function(lines) {
this.lines = lines;
return this;
};
__extends(CommentNode, BaseNode);
CommentNode.prototype['class'] = 'CommentNode';
CommentNode.prototype.isStatement = function() {
return true;
};
CommentNode.prototype.makeReturn = function() {
return this;
};
CommentNode.prototype.compileNode = function(o) {
var sep;
sep = ("\n" + this.tab);
return "" + this.tab + "/*" + sep + (this.lines.join(sep)) + "\n" + this.tab + "*/";
};
return CommentNode;
})();
exports.CallNode = (function() {

@@ -454,7 +448,3 @@ CallNode = function(variable, args) {

CallNode.prototype.prefix = function() {
if (this.isNew) {
return 'new ';
} else {
return '';
}
return this.isNew ? 'new ' : '';
};

@@ -496,7 +486,3 @@ CallNode.prototype.superReference = function(o) {

}
if (o.operation && this.wrapped) {
return "(" + compilation + ")";
} else {
return compilation;
}
return o.operation && this.wrapped ? ("(" + compilation + ")") : compilation;
};

@@ -596,7 +582,3 @@ CallNode.prototype.compileSuper = function(args, o) {

}
if (parts.length) {
return "" + (parts.join('; ')) + ";\n" + o.indent;
} else {
return '';
}
return parts.length ? ("" + (parts.join('; ')) + ";") : '';
};

@@ -617,3 +599,3 @@ RangeNode.prototype.compileNode = function(o) {

RangeNode.prototype.compileArray = function(o) {
var body, clause, equals, from, idt, post, pre, to, vars;
var body, clause, equals, from, i, idt, post, pre, result, to, vars;
idt = this.idt(1);

@@ -626,7 +608,9 @@ vars = this.compileVariables(merge(o, {

to = this.toVar.compile(o);
result = o.scope.freeVariable();
i = o.scope.freeVariable();
clause = ("" + from + " <= " + to + " ?");
pre = ("\n" + (idt) + "a = [];" + (vars));
body = ("var i = " + from + "; (" + clause + " i <" + equals + " " + to + " : i >" + equals + " " + to + "); (" + clause + " i += 1 : i -= 1)");
post = ("a.push(i);\n" + (idt) + "return a;\n" + o.indent);
return "(function(){" + (pre) + "for (" + body + ") " + post + "}).call(this)";
pre = ("\n" + (idt) + (result) + " = []; " + (vars));
body = ("var " + i + " = " + from + "; " + clause + " " + i + " <" + equals + " " + to + " : " + i + " >" + equals + " " + to + "; " + clause + " " + i + " += 1 : " + i + " -= 1");
post = ("{ " + (result) + ".push(" + i + ") };\n" + (idt) + "return " + result + ";\n" + o.indent);
return "(function(){" + (pre) + "\n" + (idt) + "for (" + body + ")" + post + "}).call(this)";
};

@@ -661,18 +645,33 @@ return RangeNode;

ObjectNode.prototype.compileNode = function(o) {
var _b, _c, _d, i, inner, join, last, prop, props;
var _b, _c, _d, _e, _f, _g, _h, i, indent, inner, join, lastNoncom, nonComments, prop, props;
o.indent = this.idt(1);
last = this.properties.length - 1;
nonComments = (function() {
_b = []; _d = this.properties;
for (_c = 0, _e = _d.length; _c < _e; _c++) {
prop = _d[_c];
!(prop instanceof CommentNode) ? _b.push(prop) : null;
}
return _b;
}).call(this);
lastNoncom = nonComments[nonComments.length - 1];
props = (function() {
_b = []; _c = this.properties;
for (i = 0, _d = _c.length; i < _d; i++) {
prop = _c[i];
_b.push((function() {
join = i === last ? '' : ',\n';
if (!(prop instanceof AssignNode)) {
_f = []; _g = this.properties;
for (i = 0, _h = _g.length; i < _h; i++) {
prop = _g[i];
_f.push((function() {
join = ",\n";
if ((prop === lastNoncom) || (prop instanceof CommentNode)) {
join = "\n";
}
if (i === this.properties.length - 1) {
join = '';
}
indent = prop instanceof CommentNode ? '' : this.idt(1);
if (!(prop instanceof AssignNode || prop instanceof CommentNode)) {
prop = new AssignNode(prop, prop, 'object');
}
return this.idt(1) + prop.compile(o) + join;
return indent + prop.compile(o) + join;
}).call(this));
}
return _b;
return _f;
}).call(this);

@@ -706,2 +705,4 @@ props = props.join('');

return this.compileSplatLiteral(this.objects, o);
} else if (obj instanceof CommentNode) {
objects.push("\n" + code + "\n" + o.indent);
} else if (i === this.objects.length - 1) {

@@ -714,7 +715,3 @@ objects.push(code);

objects = objects.join('');
if (indexOf(objects, '\n') >= 0) {
return "[\n" + (this.idt(1)) + objects + "\n" + this.tab + "]";
} else {
return "[" + objects + "]";
}
return indexOf(objects, '\n') >= 0 ? ("[\n" + (this.idt(1)) + objects + "\n" + this.tab + "]") : ("[" + objects + "]");
};

@@ -762,2 +759,5 @@ return ArrayNode;

if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
if (func.bound) {
throw new Error("cannot define a constructor as a bound function.");
}
func.name = className;

@@ -857,7 +857,3 @@ func.body.push(new ReturnNode(literal('this')));

}
if (top) {
return val;
} else {
return "(" + val + ")";
}
return top ? val : ("(" + val + ")");
};

@@ -1018,7 +1014,3 @@ AssignNode.prototype.compilePatternMatch = function(o) {

var _b;
if ((typeof (_b = this.index) !== "undefined" && _b !== null)) {
return this.compileParam(o);
} else {
return this.name.compile(o);
}
return (typeof (_b = this.index) !== "undefined" && _b !== null) ? this.compileParam(o) : this.name.compile(o);
};

@@ -1151,2 +1143,5 @@ SplatNode.prototype.compileParam = function(o) {

};
OpNode.prototype.toString = function(idt) {
return OpNode.__superClass__.toString.call(this, idt, this['class'] + ' ' + this.operator);
};
OpNode.prototype.compileNode = function(o) {

@@ -1233,7 +1228,3 @@ o.operation = true;

this.obj2 = _b[1];
if (this.isArray()) {
return this.compileOrTest(o);
} else {
return this.compileLoopTest(o);
}
return this.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
};

@@ -1263,3 +1254,3 @@ InNode.prototype.compileOrTest = function(o) {

prefix = this.obj1 !== this.obj2 ? this.obj1 + '; ' : '';
return "!!(function(){ " + (prefix) + "for (var " + i + "=0, " + l + "=" + (this.arr1) + ".length; " + i + "<" + l + "; " + i + "++) if (" + (this.arr2) + "[" + i + "] === " + this.obj2 + ") return true; })()";
return "!!(function(){ " + (prefix) + "for (var " + i + "=0, " + l + "=" + (this.arr1) + ".length; " + i + "<" + l + "; " + i + "++) if (" + (this.arr2) + "[" + i + "] === " + this.obj2 + ") return true; }).call(this)";
};

@@ -1356,7 +1347,11 @@ return InNode;

};
ParentheticalNode.prototype.topSensitive = function() {
return true;
};
ParentheticalNode.prototype.compileNode = function(o) {
var code, l;
var code, l, top;
top = del(o, 'top');
code = this.expression.compile(o);
if (this.isStatement()) {
return code;
return (top ? ("" + this.tab + code + ";") : code);
}

@@ -1367,7 +1362,3 @@ l = code.length;

}
if (this.expression instanceof AssignNode) {
return code;
} else {
return "(" + code + ")";
}
return this.expression instanceof AssignNode ? code : ("(" + code + ")");
};

@@ -1453,2 +1444,5 @@ return ParentheticalNode;

sourcePart = source.compileVariables(o);
if (sourcePart) {
sourcePart += ("\n" + o.indent);
}
forPart = source.compile(merge(o, {

@@ -1465,3 +1459,3 @@ index: ivar,

top: true
})) + "\n";
})) + '\n';
} else {

@@ -1494,5 +1488,3 @@ if (name) {

} else {
if (namePart) {
varPart = ("" + (this.idt(1)) + namePart + ";\n");
}
varPart = (namePart || '') && (this.pattern ? namePart : ("" + (this.idt(1)) + namePart + ";\n"));
}

@@ -1590,19 +1582,15 @@ this.object ? (forPart = ("" + ivar + " in " + svar + ") { if (" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")")) : null;

IfNode.prototype.compileNode = function(o) {
return this.isStatement() ? this.compileStatement(o) : this.compileTernary(o);
};
IfNode.prototype.makeReturn = function() {
if (this.isStatement()) {
return this.compileStatement(o);
this.body = this.body && this.ensureExpressions(this.body.makeReturn());
this.elseBody = this.elseBody && this.ensureExpressions(this.elseBody.makeReturn());
return this;
} else {
return this.compileTernary(o);
return new ReturnNode(this);
}
};
IfNode.prototype.makeReturn = function() {
this.body = this.body && this.ensureExpressions(this.body.makeReturn());
this.elseBody = this.elseBody && this.ensureExpressions(this.elseBody.makeReturn());
return this;
};
IfNode.prototype.ensureExpressions = function(node) {
if (node instanceof Expressions) {
return node;
} else {
return new Expressions([node]);
}
return node instanceof Expressions ? node : new Expressions([node]);
};

@@ -1658,6 +1646,6 @@ IfNode.prototype.compileStatement = function(o) {

mentionsArgs = expressions.contains(function(n) {
return (n instanceof LiteralNode) && (n.value === 'arguments');
return n instanceof LiteralNode && (n.value === 'arguments');
});
mentionsThis = expressions.contains(function(n) {
return (n instanceof LiteralNode) && (n.value === 'this');
return (n instanceof LiteralNode && (n.value === 'this')) || (n instanceof CodeNode && n.bound);
});

@@ -1673,7 +1661,3 @@ if (mentionsArgs || mentionsThis) {

call = new CallNode(func, args);
if (statement) {
return Expressions.wrap([call]);
} else {
return call;
}
return statement ? Expressions.wrap([call]) : call;
}

@@ -1680,0 +1664,0 @@ });

@@ -10,3 +10,3 @@ (function(){

OptionParser.prototype.parse = function(args) {
var _a, _b, _c, arg, isOption, matchedRule, options, rule;
var _a, _b, _c, _d, _e, arg, i, isOption, matchedRule, options, rule;
options = {

@@ -16,10 +16,12 @@ arguments: []

args = normalizeArguments(args);
while ((arg = args.shift())) {
_a = args;
for (i = 0, _b = _a.length; i < _b; i++) {
arg = _a[i];
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
matchedRule = false;
_b = this.rules;
for (_a = 0, _c = _b.length; _a < _c; _a++) {
rule = _b[_a];
_d = this.rules;
for (_c = 0, _e = _d.length; _c < _e; _c++) {
rule = _d[_c];
if (rule.shortFlag === arg || rule.longFlag === arg) {
options[rule.name] = rule.hasArgument ? args.shift() : true;
options[rule.name] = rule.hasArgument ? args[i + 1] : true;
matchedRule = true;

@@ -32,4 +34,5 @@ break;

}
if (!(isOption)) {
options.arguments.push(arg);
if (!isOption) {
options.arguments = args.slice(i, args.length);
break;
}

@@ -36,0 +39,0 @@ }

@@ -17,2 +17,3 @@ (function(){

this.tokens = tokens;
this.adjustComments();
this.removeLeadingNewlines();

@@ -39,2 +40,31 @@ this.removeMidExpressionNewlines();

};
Rewriter.prototype.adjustComments = function() {
return this.scanTokens((function(__this) {
var __func = function(prev, token, post, i) {
var _c, _d, after, before;
if (!(token[0] === 'HERECOMMENT')) {
return 1;
}
_c = [this.tokens[i - 2], this.tokens[i + 2]];
before = _c[0];
after = _c[1];
if (after && after[0] === 'INDENT') {
this.tokens.splice(i + 2, 1);
before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? this.tokens.splice(i - 2, 1) : this.tokens.splice(i, 0, after);
} else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
this.tokens.splice.apply(this.tokens, [i + 3, 0].concat(this.tokens.splice(i, 2)));
this.tokens.splice(i + 3, 0, ['TERMINATOR', "\n", prev[2]]);
} else {
this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
}
return 2;
}
return 1;
};
return (function() {
return __func.apply(__this, arguments);
});
})(this));
};
Rewriter.prototype.removeLeadingNewlines = function() {

@@ -143,3 +173,3 @@ var _c;

}
if (open && !token.generated && (!post || include(IMPLICIT_END, tag))) {
if (open && !token.generated && prev[0] !== ',' && (!post || include(IMPLICIT_END, tag))) {
j = 1;

@@ -175,7 +205,11 @@ while ((typeof (_d = (nx = this.tokens[i + j])) !== "undefined" && _d !== null) && include(IMPLICIT_END, nx[0])) {

var __func = function(prev, token, post, i) {
var idx, indent, insertion, outdent, parens, pre, starter, tok;
var _c, idx, indent, insertion, outdent, parens, pre, starter, tok;
if (token[0] === 'ELSE' && prev[0] !== 'OUTDENT') {
this.tokens.splice(i, 0, ['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]);
this.tokens.splice.apply(this.tokens, [i, 0].concat(this.indentation(token)));
return 2;
}
if (token[0] === 'CATCH' && this.tokens[i + 2][0] === 'TERMINATOR') {
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.indentation(token)));
return 4;
}
if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) {

@@ -185,4 +219,6 @@ return 1;

starter = token[0];
indent = ['INDENT', 2, token[2]];
indent.generated = true;
_c = this.indentation(token);
indent = _c[0];
outdent = _c[1];
indent.generated = (outdent.generated = true);
this.tokens.splice(i + 1, 0, indent);

@@ -197,4 +233,2 @@ idx = i + 1;

insertion = pre[0] === "," ? idx - 1 : idx;
outdent = ['OUTDENT', 2, token[2]];
outdent.generated = true;
this.tokens.splice(insertion, 0, outdent);

@@ -316,2 +350,5 @@ break;

};
Rewriter.prototype.indentation = function(token) {
return [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]];
};
return Rewriter;

@@ -318,0 +355,0 @@ })();

@@ -6,3 +6,3 @@ {

"author": "Jeremy Ashkenas",
"version": "0.7.0",
"version": "0.7.1",
"licenses": [{

@@ -9,0 +9,0 @@ "type": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc