mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
* postfix for on first line of implicit object * issue numbers * handle until and while similarly
This commit is contained in:
parent
31cd782ba7
commit
0619a7a76c
4 changed files with 58 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
// Generated by CoffeeScript 2.0.0-beta2
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, makePrelude, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs,
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, buildCSOptionParser, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, makePrelude, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs,
|
||||
indexOf = [].indexOf;
|
||||
|
||||
fs = require('fs');
|
||||
|
@ -49,8 +49,13 @@
|
|||
|
||||
optionParser = null;
|
||||
|
||||
exports.buildCSOptionParser = buildCSOptionParser = function() {
|
||||
return new optparse.OptionParser(SWITCHES, BANNER);
|
||||
};
|
||||
|
||||
exports.run = function() {
|
||||
var i, len, literals, ref, replCliOpts, results, source;
|
||||
optionParser = buildCSOptionParser();
|
||||
parseOptions();
|
||||
replCliOpts = {
|
||||
useGlobal: true
|
||||
|
@ -532,7 +537,6 @@
|
|||
|
||||
parseOptions = function() {
|
||||
var o;
|
||||
optionParser = new optparse.OptionParser(SWITCHES, BANNER);
|
||||
o = opts = optionParser.parse(process.argv.slice(2));
|
||||
o.compile || (o.compile = !!o.output);
|
||||
o.run = !(o.compile || o.print || o.map);
|
||||
|
@ -587,7 +591,7 @@
|
|||
};
|
||||
|
||||
usage = function() {
|
||||
return printLine((new optparse.OptionParser(SWITCHES, BANNER)).help());
|
||||
return printLine(optionParser.help());
|
||||
};
|
||||
|
||||
version = function() {
|
||||
|
|
|
@ -346,7 +346,7 @@
|
|||
[stackTag, stackIdx, {sameLine, startsLine}] = stackTop();
|
||||
if (inImplicitCall() && prevTag !== ',') {
|
||||
endImplicitCall();
|
||||
} else if (inImplicitObject() && sameLine && tag !== 'TERMINATOR' && prevTag !== ':' && !(tag === 'POST_IF' && startsLine && implicitObjectContinues(i + 1))) {
|
||||
} else if (inImplicitObject() && sameLine && tag !== 'TERMINATOR' && prevTag !== ':' && !((tag === 'POST_IF' || tag === 'FOR' || tag === 'WHILE' || tag === 'UNTIL') && startsLine && implicitObjectContinues(i + 1))) {
|
||||
endImplicitObject();
|
||||
} else if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) {
|
||||
if (nextTag === 'HERECOMMENT') {
|
||||
|
|
|
@ -321,7 +321,7 @@ exports.Rewriter = class Rewriter
|
|||
# return a: 1, b: 2 unless true
|
||||
else if inImplicitObject() and sameLine and
|
||||
tag isnt 'TERMINATOR' and prevTag isnt ':' and
|
||||
not (tag is 'POST_IF' and startsLine and implicitObjectContinues(i + 1))
|
||||
not (tag in ['POST_IF', 'FOR', 'WHILE', 'UNTIL'] and startsLine and implicitObjectContinues(i + 1))
|
||||
endImplicitObject()
|
||||
# Close implicit objects when at end of line, line didn't end with a comma
|
||||
# and the implicit object didn't start the line or the next line doesn't look like
|
||||
|
|
|
@ -648,3 +648,52 @@ test "#4544: Postfix conditionals in first line of implicit object literals", ->
|
|||
val: "hello"
|
||||
val2: "all good"
|
||||
eq a.val2, "all good"
|
||||
|
||||
test "#4579: Postfix for/while/until in first line of implicit object literals", ->
|
||||
two =
|
||||
foo:
|
||||
bar: x for x in [1, 2, 3]
|
||||
baz: 1337
|
||||
arrayEq [1, 2, 3], two.foo.bar
|
||||
eq 1337, two.foo.baz
|
||||
|
||||
f = (x) -> x
|
||||
|
||||
three =
|
||||
foo: f
|
||||
# Uncomment when #4580 is fixed
|
||||
# bar: x + y for x, y of a: 'b', c: 'd'
|
||||
bar: x + 'c' for x of a: 1, b: 2
|
||||
baz: 1337
|
||||
arrayEq ['ac', 'bc'], three.foo.bar
|
||||
eq 1337, three.foo.baz
|
||||
|
||||
four =
|
||||
f
|
||||
foo:
|
||||
"bar_#{x}": x for x of a: 1, b: 2
|
||||
baz: 1337
|
||||
eq 'a', four.foo[0].bar_a
|
||||
eq 'b', four.foo[1].bar_b
|
||||
eq 1337, four.baz
|
||||
|
||||
x = bar: 42 for y in [1]
|
||||
baz: 1337
|
||||
eq x.bar, 42
|
||||
|
||||
i = 5
|
||||
five =
|
||||
foo:
|
||||
bar: i while i-- > 0
|
||||
baz: 1337
|
||||
arrayEq [4, 3, 2, 1, 0], five.foo.bar
|
||||
eq 1337, five.foo.baz
|
||||
|
||||
i = 5
|
||||
six =
|
||||
foo:
|
||||
bar: i until i-- <= 0
|
||||
baz: 1337
|
||||
arrayEq [4, 3, 2, 1, 0], six.foo.bar
|
||||
eq 1337, six.foo.baz
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue