1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

literals need newlines after them

This commit is contained in:
Michael Ficarra 2011-12-24 06:46:09 -05:00
parent e2a205ab22
commit 8d5f800e2f
6 changed files with 42 additions and 2 deletions

View file

@ -8,6 +8,7 @@
exports.Lexer = Lexer = (function() { exports.Lexer = Lexer = (function() {
Lexer.name = 'Lexer'; Lexer.name = 'Lexer';
function Lexer() {} function Lexer() {}
Lexer.prototype.tokenize = function(code, opts) { Lexer.prototype.tokenize = function(code, opts) {

View file

@ -31,6 +31,7 @@
exports.Base = Base = (function() { exports.Base = Base = (function() {
Base.name = 'Base'; Base.name = 'Base';
function Base() {} function Base() {}
Base.prototype.compile = function(o, lvl) { Base.prototype.compile = function(o, lvl) {
@ -193,6 +194,7 @@
Block.name = 'Block'; Block.name = 'Block';
function Block(nodes) { function Block(nodes) {
this.expressions = compact(flatten(nodes || [])); this.expressions = compact(flatten(nodes || []));
} }
@ -284,7 +286,11 @@
} else if (top) { } else if (top) {
node.front = true; node.front = true;
code = node.compile(o); code = node.compile(o);
codes.push(node.isStatement(o) ? code : "" + this.tab + code + ";"); if (!node.isStatement(o)) {
code = "" + this.tab + code + ";";
if (node instanceof Literal) code = "" + code + "\n";
}
codes.push(code);
} else { } else {
codes.push(node.compile(o, LEVEL_LIST)); codes.push(node.compile(o, LEVEL_LIST));
} }
@ -389,6 +395,7 @@
Literal.name = 'Literal'; Literal.name = 'Literal';
function Literal(value) { function Literal(value) {
this.value = value; this.value = value;
} }
@ -447,6 +454,7 @@
Return.name = 'Return'; Return.name = 'Return';
function Return(expr) { function Return(expr) {
if (expr && !expr.unwrap().isUndefined) this.expression = expr; if (expr && !expr.unwrap().isUndefined) this.expression = expr;
} }
@ -483,6 +491,7 @@
Value.name = 'Value'; Value.name = 'Value';
function Value(base, props, tag) { function Value(base, props, tag) {
if (!props && base instanceof Value) return base; if (!props && base instanceof Value) return base;
this.base = base; this.base = base;
@ -633,6 +642,7 @@
Comment.name = 'Comment'; Comment.name = 'Comment';
function Comment(comment) { function Comment(comment) {
this.comment = comment; this.comment = comment;
} }
@ -658,6 +668,7 @@
Call.name = 'Call'; Call.name = 'Call';
function Call(variable, args, soak) { function Call(variable, args, soak) {
this.args = args != null ? args : []; this.args = args != null ? args : [];
this.soak = soak; this.soak = soak;
@ -829,6 +840,7 @@
Extends.name = 'Extends'; Extends.name = 'Extends';
function Extends(child, parent) { function Extends(child, parent) {
this.child = child; this.child = child;
this.parent = parent; this.parent = parent;
@ -850,6 +862,7 @@
Access.name = 'Access'; Access.name = 'Access';
function Access(name, tag) { function Access(name, tag) {
this.name = name; this.name = name;
this.name.asKey = true; this.name.asKey = true;
@ -880,6 +893,7 @@
Index.name = 'Index'; Index.name = 'Index';
function Index(index) { function Index(index) {
this.index = index; this.index = index;
} }
@ -904,6 +918,7 @@
Range.name = 'Range'; Range.name = 'Range';
Range.prototype.children = ['from', 'to']; Range.prototype.children = ['from', 'to'];
function Range(from, to, tag) { function Range(from, to, tag) {
@ -989,6 +1004,7 @@
Slice.name = 'Slice'; Slice.name = 'Slice';
Slice.prototype.children = ['range']; Slice.prototype.children = ['range'];
function Slice(range) { function Slice(range) {
@ -1017,6 +1033,7 @@
Obj.name = 'Obj'; Obj.name = 'Obj';
function Obj(props, generated) { function Obj(props, generated) {
this.generated = generated != null ? generated : false; this.generated = generated != null ? generated : false;
this.objects = this.properties = props || []; this.objects = this.properties = props || [];
@ -1085,6 +1102,7 @@
Arr.name = 'Arr'; Arr.name = 'Arr';
function Arr(objs) { function Arr(objs) {
this.objects = objs || []; this.objects = objs || [];
} }
@ -1135,6 +1153,7 @@
Class.name = 'Class'; Class.name = 'Class';
function Class(variable, parent, body) { function Class(variable, parent, body) {
this.variable = variable; this.variable = variable;
this.parent = parent; this.parent = parent;
@ -1294,6 +1313,7 @@
Assign.name = 'Assign'; Assign.name = 'Assign';
function Assign(variable, value, context, options) { function Assign(variable, value, context, options) {
this.variable = variable; this.variable = variable;
this.value = value; this.value = value;
@ -1494,6 +1514,7 @@
Code.name = 'Code'; Code.name = 'Code';
function Code(params, body, tag) { function Code(params, body, tag) {
this.params = params || []; this.params = params || [];
this.body = body || new Block; this.body = body || new Block;
@ -1608,6 +1629,7 @@
Param.name = 'Param'; Param.name = 'Param';
function Param(name, value, splat) { function Param(name, value, splat) {
this.name = name; this.name = name;
this.value = value; this.value = value;
@ -1649,6 +1671,7 @@
Splat.name = 'Splat'; Splat.name = 'Splat';
Splat.prototype.children = ['name']; Splat.prototype.children = ['name'];
Splat.prototype.isAssignable = YES; Splat.prototype.isAssignable = YES;
@ -1717,6 +1740,7 @@
While.name = 'While'; While.name = 'While';
function While(condition, options) { function While(condition, options) {
this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition; this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
this.guard = options != null ? options.guard : void 0; this.guard = options != null ? options.guard : void 0;
@ -1792,6 +1816,7 @@
Op.name = 'Op'; Op.name = 'Op';
function Op(op, first, second, flip) { function Op(op, first, second, flip) {
if (op === 'in') return new In(first, second); if (op === 'in') return new In(first, second);
if (op === 'do') return this.generateDo(first); if (op === 'do') return this.generateDo(first);
@ -1959,6 +1984,7 @@
In.name = 'In'; In.name = 'In';
function In(object, array) { function In(object, array) {
this.object = object; this.object = object;
this.array = array; this.array = array;
@ -2033,6 +2059,7 @@
Try.name = 'Try'; Try.name = 'Try';
function Try(attempt, error, recovery, ensure) { function Try(attempt, error, recovery, ensure) {
this.attempt = attempt; this.attempt = attempt;
this.error = error; this.error = error;
@ -2075,6 +2102,7 @@
Throw.name = 'Throw'; Throw.name = 'Throw';
function Throw(expression) { function Throw(expression) {
this.expression = expression; this.expression = expression;
} }
@ -2101,6 +2129,7 @@
Existence.name = 'Existence'; Existence.name = 'Existence';
function Existence(expression) { function Existence(expression) {
this.expression = expression; this.expression = expression;
} }
@ -2136,6 +2165,7 @@
Parens.name = 'Parens'; Parens.name = 'Parens';
function Parens(body) { function Parens(body) {
this.body = body; this.body = body;
} }
@ -2176,6 +2206,7 @@
For.name = 'For'; For.name = 'For';
function For(body, source) { function For(body, source) {
var _ref2; var _ref2;
this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index; this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
@ -2317,6 +2348,7 @@
Switch.name = 'Switch'; Switch.name = 'Switch';
function Switch(subject, cases, otherwise) { function Switch(subject, cases, otherwise) {
this.subject = subject; this.subject = subject;
this.cases = cases; this.cases = cases;
@ -2394,6 +2426,7 @@
If.name = 'If'; If.name = 'If';
function If(condition, body, options) { function If(condition, body, options) {
this.body = body; this.body = body;
if (options == null) options = {}; if (options == null) options = {};

View file

@ -3,6 +3,7 @@
exports.OptionParser = OptionParser = (function() { exports.OptionParser = OptionParser = (function() {
OptionParser.name = 'OptionParser'; OptionParser.name = 'OptionParser';
function OptionParser(rules, banner) { function OptionParser(rules, banner) {
this.banner = banner; this.banner = banner;
this.rules = buildRules(rules); this.rules = buildRules(rules);

View file

@ -5,6 +5,7 @@
exports.Rewriter = (function() { exports.Rewriter = (function() {
Rewriter.name = 'Rewriter'; Rewriter.name = 'Rewriter';
function Rewriter() {} function Rewriter() {}
Rewriter.prototype.rewrite = function(tokens) { Rewriter.prototype.rewrite = function(tokens) {

View file

@ -5,6 +5,7 @@
exports.Scope = Scope = (function() { exports.Scope = Scope = (function() {
Scope.name = 'Scope'; Scope.name = 'Scope';
Scope.root = null; Scope.root = null;
function Scope(parent, expressions, method) { function Scope(parent, expressions, method) {

View file

@ -227,7 +227,10 @@ exports.Block = class Block extends Base
else if top else if top
node.front = true node.front = true
code = node.compile o code = node.compile o
codes.push if node.isStatement o then code else "#{@tab}#{code};" unless node.isStatement o
code = "#{@tab}#{code};"
code = "#{code}\n" if node instanceof Literal
codes.push code
else else
codes.push node.compile o, LEVEL_LIST codes.push node.compile o, LEVEL_LIST
if top if top