Update output

This commit is contained in:
Geoffrey Booth
2018-01-31 06:33:17 -08:00
parent 0aa77f157a
commit fc5ab1afa3
7 changed files with 325 additions and 447 deletions

View File

@@ -332,16 +332,12 @@
} else {
return `${typeName}.${methodName || '<anonymous>'} (${fileLocation})`;
}
} else if (isConstructor) {
return `new ${functionName || '<anonymous>'} (${fileLocation})`;
} else if (functionName) {
return `${functionName} (${fileLocation})`;
} else {
if (isConstructor) {
return `new ${functionName || '<anonymous>'} (${fileLocation})`;
} else {
if (functionName) {
return `${functionName} (${fileLocation})`;
} else {
return fileLocation;
}
}
return fileLocation;
}
};
@@ -354,25 +350,23 @@
}
if (filename !== '<anonymous>' && (sourceMaps[filename] != null)) {
return sourceMaps[filename][sourceMaps[filename].length - 1];
} else {
// CoffeeScript compiled in a browser or via `CoffeeScript.compile` or `.run`
// may get compiled with `options.filename` thats missing, which becomes
// `<anonymous>`; but the runtime might request the stack trace with the
// filename of the script file. See if we have a source map cached under
// `<anonymous>` that matches the error.
if (sourceMaps['<anonymous>'] != null) {
ref1 = sourceMaps['<anonymous>'];
// Work backwards from the most recent anonymous source maps, until we find
// one that works. This isnt foolproof; there is a chance that multiple
// source maps will have line/column pairs that match. But we have no other
// way to match them. `frame.getFunction().toString()` doesnt always work,
// and its not foolproof either.
for (i = ref1.length - 1; i >= 0; i += -1) {
map = ref1[i];
sourceLocation = map.sourceLocation([line - 1, column - 1]);
if (((sourceLocation != null ? sourceLocation[0] : void 0) != null) && (sourceLocation[1] != null)) {
return map;
}
// CoffeeScript compiled in a browser or via `CoffeeScript.compile` or `.run`
// may get compiled with `options.filename` thats missing, which becomes
// `<anonymous>`; but the runtime might request the stack trace with the
// filename of the script file. See if we have a source map cached under
// `<anonymous>` that matches the error.
} else if (sourceMaps['<anonymous>'] != null) {
ref1 = sourceMaps['<anonymous>'];
// Work backwards from the most recent anonymous source maps, until we find
// one that works. This isnt foolproof; there is a chance that multiple
// source maps will have line/column pairs that match. But we have no other
// way to match them. `frame.getFunction().toString()` doesnt always work,
// and its not foolproof either.
for (i = ref1.length - 1; i >= 0; i += -1) {
map = ref1[i];
sourceLocation = map.sourceLocation([line - 1, column - 1]);
if (((sourceLocation != null ? sourceLocation[0] : void 0) != null) && (sourceLocation[1] != null)) {
return map;
}
}
}

View File

@@ -200,28 +200,26 @@
results.push(compilePath(path.join(source, file), false, base));
}
return results;
} else {
if (topLevel || helpers.isCoffee(source)) {
sources.push(source);
sourceCode.push(null);
delete notSources[source];
if (opts.watch) {
watch(source, base);
}
try {
code = fs.readFileSync(source);
} catch (error) {
err = error;
if (err.code === 'ENOENT') {
return;
} else {
throw err;
}
}
return compileScript(source, code.toString(), base);
} else {
return notSources[source] = true;
} else if (topLevel || helpers.isCoffee(source)) {
sources.push(source);
sourceCode.push(null);
delete notSources[source];
if (opts.watch) {
watch(source, base);
}
try {
code = fs.readFileSync(source);
} catch (error) {
err = error;
if (err.code === 'ENOENT') {
return;
} else {
throw err;
}
}
return compileScript(source, code.toString(), base);
} else {
return notSources[source] = true;
}
};
@@ -257,41 +255,33 @@
CoffeeScript.emit('compile', task);
if (opts.tokens) {
return printTokens(CoffeeScript.tokens(task.input, task.options));
} else if (opts.nodes) {
return printLine(CoffeeScript.nodes(task.input, task.options).toString().trim());
} else if (opts.run) {
CoffeeScript.register();
if (opts.prelude) {
CoffeeScript.eval(opts.prelude, task.options);
}
return CoffeeScript.run(task.input, task.options);
} else if (opts.join && task.file !== opts.join) {
if (helpers.isLiterate(file)) {
task.input = helpers.invertLiterate(task.input);
}
sourceCode[sources.indexOf(task.file)] = task.input;
return compileJoin();
} else {
if (opts.nodes) {
return printLine(CoffeeScript.nodes(task.input, task.options).toString().trim());
} else {
if (opts.run) {
CoffeeScript.register();
if (opts.prelude) {
CoffeeScript.eval(opts.prelude, task.options);
}
return CoffeeScript.run(task.input, task.options);
} else {
if (opts.join && task.file !== opts.join) {
if (helpers.isLiterate(file)) {
task.input = helpers.invertLiterate(task.input);
}
sourceCode[sources.indexOf(task.file)] = task.input;
return compileJoin();
} else {
compiled = CoffeeScript.compile(task.input, task.options);
task.output = compiled;
if (opts.map) {
task.output = compiled.js;
task.sourceMap = compiled.v3SourceMap;
}
CoffeeScript.emit('success', task);
if (opts.print) {
return printLine(task.output.trim());
} else {
if (opts.compile || opts.map) {
saveTo = opts.outputFilename && sources.length === 1 ? path.join(opts.outputPath, opts.outputFilename) : options.jsPath;
return writeJs(base, task.file, task.output, saveTo, task.sourceMap);
}
}
}
}
compiled = CoffeeScript.compile(task.input, task.options);
task.output = compiled;
if (opts.map) {
task.output = compiled.js;
task.sourceMap = compiled.v3SourceMap;
}
CoffeeScript.emit('success', task);
if (opts.print) {
return printLine(task.output.trim());
} else if (opts.compile || opts.map) {
saveTo = opts.outputFilename && sources.length === 1 ? path.join(opts.outputPath, opts.outputFilename) : options.jsPath;
return writeJs(base, task.file, task.output, saveTo, task.sourceMap);
}
}
} catch (error) {
@@ -558,10 +548,8 @@
if (err) {
printLine(err.message);
return process.exit(1);
} else {
if (opts.compile && opts.watch) {
return timeLog(`compiled ${sourcePath}`);
}
} else if (opts.compile && opts.watch) {
return timeLog(`compiled ${sourcePath}`);
}
});
}

View File

@@ -133,18 +133,14 @@
if (blankLine.test(line)) {
insideComment = false;
out.push(line);
} else if (insideComment || listItemStart.test(line)) {
insideComment = true;
out.push(`# ${line}`);
} else if (!insideComment && indented.test(line)) {
out.push(line);
} else {
if (insideComment || listItemStart.test(line)) {
insideComment = true;
out.push(`# ${line}`);
} else {
if (!insideComment && indented.test(line)) {
out.push(line);
} else {
insideComment = true;
out.push(`# ${line}`);
}
}
insideComment = true;
out.push(`# ${line}`);
}
}
return out.join('\n');
@@ -222,10 +218,8 @@
var locationData;
if (("2" in obj) && ("first_line" in obj[2])) {
locationData = obj[2];
} else {
if ("first_line" in obj) {
locationData = obj;
}
} else if ("first_line" in obj) {
locationData = obj;
}
if (locationData) {
return `${locationData.first_line + 1}:${locationData.first_column + 1}-` + `${locationData.last_line + 1}:${locationData.last_column + 1}`;

View File

@@ -133,11 +133,9 @@
if (id === 'as' && this.seenImport) {
if (this.value() === '*') {
this.tokens[this.tokens.length - 1][0] = 'IMPORT_ALL';
} else {
if (ref = this.value(true), indexOf.call(COFFEE_KEYWORDS, ref) >= 0) {
prev = this.prev();
[prev[0], prev[1]] = ['IDENTIFIER', this.value(true)];
}
} else if (ref = this.value(true), indexOf.call(COFFEE_KEYWORDS, ref) >= 0) {
prev = this.prev();
[prev[0], prev[1]] = ['IDENTIFIER', this.value(true)];
}
if ((ref1 = this.tag()) === 'DEFAULT' || ref1 === 'IMPORT_ALL' || ref1 === 'IDENTIFIER') {
this.token('AS', id);
@@ -173,59 +171,41 @@
tag = id.toUpperCase();
if (tag === 'WHEN' && (ref6 = this.tag(), indexOf.call(LINE_BREAK, ref6) >= 0)) {
tag = 'LEADING_WHEN';
} else {
if (tag === 'FOR') {
this.seenFor = true;
} else if (tag === 'FOR') {
this.seenFor = true;
} else if (tag === 'UNLESS') {
tag = 'IF';
} else if (tag === 'IMPORT') {
this.seenImport = true;
} else if (tag === 'EXPORT') {
this.seenExport = true;
} else if (indexOf.call(UNARY, tag) >= 0) {
tag = 'UNARY';
} else if (indexOf.call(RELATION, tag) >= 0) {
if (tag !== 'INSTANCEOF' && this.seenFor) {
tag = 'FOR' + tag;
this.seenFor = false;
} else {
if (tag === 'UNLESS') {
tag = 'IF';
} else {
if (tag === 'IMPORT') {
this.seenImport = true;
} else {
if (tag === 'EXPORT') {
this.seenExport = true;
} else {
if (indexOf.call(UNARY, tag) >= 0) {
tag = 'UNARY';
} else {
if (indexOf.call(RELATION, tag) >= 0) {
if (tag !== 'INSTANCEOF' && this.seenFor) {
tag = 'FOR' + tag;
this.seenFor = false;
} else {
tag = 'RELATION';
if (this.value() === '!') {
poppedToken = this.tokens.pop();
id = '!' + id;
}
}
}
}
}
}
tag = 'RELATION';
if (this.value() === '!') {
poppedToken = this.tokens.pop();
id = '!' + id;
}
}
}
} else {
if (tag === 'IDENTIFIER' && this.seenFor && id === 'from' && isForFrom(prev)) {
tag = 'FORFROM';
this.seenFor = false;
} else {
// Throw an error on attempts to use `get` or `set` as keywords, or
// what CoffeeScript would normally interpret as calls to functions named
// `get` or `set`, i.e. `get({foo: function () {}})`.
if (tag === 'PROPERTY' && prev) {
if (prev.spaced && (ref7 = prev[0], indexOf.call(CALLABLE, ref7) >= 0) && /^[gs]et$/.test(prev[1]) && this.tokens.length > 1 && ((ref8 = this.tokens[this.tokens.length - 2][0]) !== '.' && ref8 !== '?.' && ref8 !== '@')) {
this.error(`'${prev[1]}' cannot be used as a keyword, or as a function call without parentheses`, prev[2]);
} else {
if (this.tokens.length > 2) {
prevprev = this.tokens[this.tokens.length - 2];
if (((ref9 = prev[0]) === '@' || ref9 === 'THIS') && prevprev && prevprev.spaced && /^[gs]et$/.test(prevprev[1]) && ((ref10 = this.tokens[this.tokens.length - 3][0]) !== '.' && ref10 !== '?.' && ref10 !== '@')) {
this.error(`'${prevprev[1]}' cannot be used as a keyword, or as a function call without parentheses`, prevprev[2]);
}
}
}
} else if (tag === 'IDENTIFIER' && this.seenFor && id === 'from' && isForFrom(prev)) {
tag = 'FORFROM';
this.seenFor = false;
// Throw an error on attempts to use `get` or `set` as keywords, or
// what CoffeeScript would normally interpret as calls to functions named
// `get` or `set`, i.e. `get({foo: function () {}})`.
} else if (tag === 'PROPERTY' && prev) {
if (prev.spaced && (ref7 = prev[0], indexOf.call(CALLABLE, ref7) >= 0) && /^[gs]et$/.test(prev[1]) && this.tokens.length > 1 && ((ref8 = this.tokens[this.tokens.length - 2][0]) !== '.' && ref8 !== '?.' && ref8 !== '@')) {
this.error(`'${prev[1]}' cannot be used as a keyword, or as a function call without parentheses`, prev[2]);
} else if (this.tokens.length > 2) {
prevprev = this.tokens[this.tokens.length - 2];
if (((ref9 = prev[0]) === '@' || ref9 === 'THIS') && prevprev && prevprev.spaced && /^[gs]et$/.test(prevprev[1]) && ((ref10 = this.tokens[this.tokens.length - 3][0]) !== '.' && ref10 !== '?.' && ref10 !== '@')) {
this.error(`'${prevprev[1]}' cannot be used as a keyword, or as a function call without parentheses`, prevprev[2]);
}
}
}
@@ -542,10 +522,8 @@
if (!closed || POSSIBLY_DIVISION.test(regex)) {
return 0;
}
} else {
if (ref1 = prev[0], indexOf.call(NOT_REGEX, ref1) >= 0) {
return 0;
}
} else if (ref1 = prev[0], indexOf.call(NOT_REGEX, ref1) >= 0) {
return 0;
}
}
if (!closed) {
@@ -669,15 +647,13 @@
this.outdebt = this.indebt = 0;
this.indent = size;
this.indentLiteral = newIndentLiteral;
} else if (size < this.baseIndent) {
this.error('missing indentation', {
offset: indent.length
});
} else {
if (size < this.baseIndent) {
this.error('missing indentation', {
offset: indent.length
});
} else {
this.indebt = 0;
this.outdentToken(this.indent - size, noNewlines, indent.length);
}
this.indebt = 0;
this.outdentToken(this.indent - size, noNewlines, indent.length);
}
return indent.length;
}
@@ -691,22 +667,20 @@
lastIndent = this.indents[this.indents.length - 1];
if (!lastIndent) {
this.outdebt = moveOut = 0;
} else if (this.outdebt && moveOut <= this.outdebt) {
this.outdebt -= moveOut;
moveOut = 0;
} else {
if (this.outdebt && moveOut <= this.outdebt) {
this.outdebt -= moveOut;
moveOut = 0;
} else {
dent = this.indents.pop() + this.outdebt;
if (outdentLength && (ref = this.chunk[outdentLength], indexOf.call(INDENTABLE_CLOSERS, ref) >= 0)) {
decreasedIndent -= dent - moveOut;
moveOut = dent;
}
this.outdebt = 0;
// pair might call outdentToken, so preserve decreasedIndent
this.pair('OUTDENT');
this.token('OUTDENT', moveOut, 0, outdentLength);
moveOut -= dent;
dent = this.indents.pop() + this.outdebt;
if (outdentLength && (ref = this.chunk[outdentLength], indexOf.call(INDENTABLE_CLOSERS, ref) >= 0)) {
decreasedIndent -= dent - moveOut;
moveOut = dent;
}
this.outdebt = 0;
// pair might call outdentToken, so preserve decreasedIndent
this.pair('OUTDENT');
this.token('OUTDENT', moveOut, 0, outdentLength);
moveOut -= dent;
}
}
if (dent) {
@@ -788,84 +762,76 @@
});
this.csxDepth++;
return id.length + 1;
} else {
if (csxTag = this.atCSXTag()) {
if (this.chunk.slice(0, 2) === '/>') {
this.pair('/>');
this.token(']', ']', 0, 2);
this.token('CALL_END', ')', 0, 2);
this.csxDepth--;
return 2;
} else if (csxTag = this.atCSXTag()) {
if (this.chunk.slice(0, 2) === '/>') {
this.pair('/>');
this.token(']', ']', 0, 2);
this.token('CALL_END', ')', 0, 2);
this.csxDepth--;
return 2;
} else if (firstChar === '{') {
if (prevChar === ':') {
token = this.token('(', '(');
this.csxObjAttribute[this.csxDepth] = false;
} else {
if (firstChar === '{') {
if (prevChar === ':') {
token = this.token('(', '(');
this.csxObjAttribute[this.csxDepth] = false;
} else {
token = this.token('{', '{');
this.csxObjAttribute[this.csxDepth] = true;
}
this.ends.push({
tag: '}',
origin: token
});
return 1;
} else {
if (firstChar === '>') {
// Ignore terminators inside a tag.
this.pair('/>'); // As if the current tag was self-closing.
origin = this.token(']', ']');
this.token(',', ',');
({
tokens,
index: end
} = this.matchWithInterpolations(INSIDE_CSX, '>', '</', CSX_INTERPOLATION));
this.mergeInterpolationTokens(tokens, {
delimiter: '"'
}, (value, i) => {
return this.formatString(value, {
delimiter: '>'
});
});
match = CSX_IDENTIFIER.exec(this.chunk.slice(end)) || CSX_FRAGMENT_IDENTIFIER.exec(this.chunk.slice(end));
if (!match || match[1] !== csxTag.name) {
this.error(`expected corresponding CSX closing tag for ${csxTag.name}`, csxTag.origin[2]);
}
afterTag = end + csxTag.name.length;
if (this.chunk[afterTag] !== '>') {
this.error("missing closing > after tag name", {
offset: afterTag,
length: 1
});
}
// +1 for the closing `>`.
this.token('CALL_END', ')', end, csxTag.name.length + 1);
this.csxDepth--;
return afterTag + 1;
} else {
return 0;
}
}
token = this.token('{', '{');
this.csxObjAttribute[this.csxDepth] = true;
}
this.ends.push({
tag: '}',
origin: token
});
return 1;
} else if (firstChar === '>') {
// Ignore terminators inside a tag.
this.pair('/>'); // As if the current tag was self-closing.
origin = this.token(']', ']');
this.token(',', ',');
({
tokens,
index: end
} = this.matchWithInterpolations(INSIDE_CSX, '>', '</', CSX_INTERPOLATION));
this.mergeInterpolationTokens(tokens, {
delimiter: '"'
}, (value, i) => {
return this.formatString(value, {
delimiter: '>'
});
});
match = CSX_IDENTIFIER.exec(this.chunk.slice(end)) || CSX_FRAGMENT_IDENTIFIER.exec(this.chunk.slice(end));
if (!match || match[1] !== csxTag.name) {
this.error(`expected corresponding CSX closing tag for ${csxTag.name}`, csxTag.origin[2]);
}
afterTag = end + csxTag.name.length;
if (this.chunk[afterTag] !== '>') {
this.error("missing closing > after tag name", {
offset: afterTag,
length: 1
});
}
// +1 for the closing `>`.
this.token('CALL_END', ')', end, csxTag.name.length + 1);
this.csxDepth--;
return afterTag + 1;
} else {
if (this.atCSXTag(1)) {
if (firstChar === '}') {
this.pair(firstChar);
if (this.csxObjAttribute[this.csxDepth]) {
this.token('}', '}');
this.csxObjAttribute[this.csxDepth] = false;
} else {
this.token(')', ')');
}
this.token(',', ',');
return 1;
} else {
return 0;
}
} else {
return 0;
}
return 0;
}
} else if (this.atCSXTag(1)) {
if (firstChar === '}') {
this.pair(firstChar);
if (this.csxObjAttribute[this.csxDepth]) {
this.token('}', '}');
this.csxObjAttribute[this.csxDepth] = false;
} else {
this.token(')', ')');
}
this.token(',', ',');
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
@@ -920,18 +886,12 @@
}
if (value === '{' && this.seenImport) {
this.importSpecifierList = true;
} else {
if (this.importSpecifierList && value === '}') {
this.importSpecifierList = false;
} else {
if (value === '{' && (prev != null ? prev[0] : void 0) === 'EXPORT') {
this.exportSpecifierList = true;
} else {
if (this.exportSpecifierList && value === '}') {
this.exportSpecifierList = false;
}
}
}
} else if (this.importSpecifierList && value === '}') {
this.importSpecifierList = false;
} else if (value === '{' && (prev != null ? prev[0] : void 0) === 'EXPORT') {
this.exportSpecifierList = true;
} else if (this.exportSpecifierList && value === '}') {
this.exportSpecifierList = false;
}
if (value === ';') {
if (ref2 = prev != null ? prev[0] : void 0, indexOf.call(['=', ...UNFINISHED], ref2) >= 0) {
@@ -939,53 +899,33 @@
}
this.seenFor = this.seenImport = this.seenExport = false;
tag = 'TERMINATOR';
} else {
if (value === '*' && (prev != null ? prev[0] : void 0) === 'EXPORT') {
tag = 'EXPORT_ALL';
} else {
if (indexOf.call(MATH, value) >= 0) {
tag = 'MATH';
} else {
if (indexOf.call(COMPARE, value) >= 0) {
tag = 'COMPARE';
} else {
if (indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
tag = 'COMPOUND_ASSIGN';
} else {
if (indexOf.call(UNARY, value) >= 0) {
tag = 'UNARY';
} else {
if (indexOf.call(UNARY_MATH, value) >= 0) {
tag = 'UNARY_MATH';
} else {
if (indexOf.call(SHIFT, value) >= 0) {
tag = 'SHIFT';
} else {
if (value === '?' && (prev != null ? prev.spaced : void 0)) {
tag = 'BIN?';
} else {
if (prev) {
if (value === '(' && !prev.spaced && (ref3 = prev[0], indexOf.call(CALLABLE, ref3) >= 0)) {
if (prev[0] === '?') {
prev[0] = 'FUNC_EXIST';
}
tag = 'CALL_START';
} else {
if (value === '[' && (((ref4 = prev[0], indexOf.call(INDEXABLE, ref4) >= 0) && !prev.spaced) || (prev[0] === '::'))) { // `.prototype` cant be a method you can call.
tag = 'INDEX_START';
switch (prev[0]) {
case '?':
prev[0] = 'INDEX_SOAK';
}
}
}
}
}
}
}
}
}
}
} else if (value === '*' && (prev != null ? prev[0] : void 0) === 'EXPORT') {
tag = 'EXPORT_ALL';
} else if (indexOf.call(MATH, value) >= 0) {
tag = 'MATH';
} else if (indexOf.call(COMPARE, value) >= 0) {
tag = 'COMPARE';
} else if (indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
tag = 'COMPOUND_ASSIGN';
} else if (indexOf.call(UNARY, value) >= 0) {
tag = 'UNARY';
} else if (indexOf.call(UNARY_MATH, value) >= 0) {
tag = 'UNARY_MATH';
} else if (indexOf.call(SHIFT, value) >= 0) {
tag = 'SHIFT';
} else if (value === '?' && (prev != null ? prev.spaced : void 0)) {
tag = 'BIN?';
} else if (prev) {
if (value === '(' && !prev.spaced && (ref3 = prev[0], indexOf.call(CALLABLE, ref3) >= 0)) {
if (prev[0] === '?') {
prev[0] = 'FUNC_EXIST';
}
tag = 'CALL_START';
} else if (value === '[' && (((ref4 = prev[0], indexOf.call(INDEXABLE, ref4) >= 0) && !prev.spaced) || (prev[0] === '::'))) { // `.prototype` cant be a method you can call.
tag = 'INDEX_START';
switch (prev[0]) {
case '?':
prev[0] = 'INDEX_SOAK';
}
}
}
@@ -1033,14 +973,12 @@
case 'CALL_START':
if (stack.length) {
stack.pop();
} else if (tok[0] === '(') {
tok[0] = 'PARAM_START';
return this;
} else {
if (tok[0] === '(') {
tok[0] = 'PARAM_START';
return this;
} else {
paramEndToken[0] = 'CALL_END';
return this;
}
paramEndToken[0] = 'CALL_END';
return this;
}
}
}
@@ -1545,18 +1483,14 @@
}
// `for i from iterable`
return true;
// `for from…`
} else if (prev[0] === 'FOR') {
return false;
// `for {from}…`, `for [from]…`, `for {a, from}…`, `for {a: from}…`
} else if ((ref = prev[1]) === '{' || ref === '[' || ref === ',' || ref === ':') {
return false;
} else {
// `for from…`
if (prev[0] === 'FOR') {
return false;
} else {
// `for {from}…`, `for [from]…`, `for {a, from}…`, `for {a: from}…`
if ((ref = prev[1]) === '{' || ref === '[' || ref === ',' || ref === ':') {
return false;
} else {
return true;
}
}
return true;
}
};

View File

@@ -163,17 +163,15 @@
return node instanceof SuperCall;
}))) {
func.bound = true;
} else {
if ((argumentsNode = this.contains(isLiteralArguments)) || this.contains(isLiteralThis)) {
args = [new ThisLiteral];
if (argumentsNode) {
meth = 'apply';
args.push(new IdentifierLiteral('arguments'));
} else {
meth = 'call';
}
func = new Value(func, [new Access(new PropertyName(meth))]);
} else if ((argumentsNode = this.contains(isLiteralArguments)) || this.contains(isLiteralThis)) {
args = [new ThisLiteral];
if (argumentsNode) {
meth = 'apply';
args.push(new IdentifierLiteral('arguments'));
} else {
meth = 'call';
}
func = new Value(func, [new Access(new PropertyName(meth))]);
}
parts = (new Call(func, args)).compileNode(o);
switch (false) {
@@ -416,14 +414,12 @@
}
}
}
} else if (match(children)) {
this[attr] = replacement(children, this);
return true;
} else {
if (match(children)) {
this[attr] = replacement(children, this);
if (children.replaceInContext(match, replacement)) {
return true;
} else {
if (children.replaceInContext(match, replacement)) {
return true;
}
}
}
}
@@ -720,21 +716,19 @@
// enclose it in a new scope; we just compile the statements in this
// block along with our own.
compiledNodes.push(node.compileNode(o));
} else {
if (top) {
node.front = true;
fragments = node.compileToFragments(o);
if (!node.isStatement(o)) {
fragments = indentInitial(fragments, this);
[lastFragment] = slice1.call(fragments, -1);
if (!(lastFragment.code === '' || lastFragment.isComment)) {
fragments.push(this.makeCode(';'));
}
} else if (top) {
node.front = true;
fragments = node.compileToFragments(o);
if (!node.isStatement(o)) {
fragments = indentInitial(fragments, this);
[lastFragment] = slice1.call(fragments, -1);
if (!(lastFragment.code === '' || lastFragment.isComment)) {
fragments.push(this.makeCode(';'));
}
compiledNodes.push(fragments);
} else {
compiledNodes.push(node.compileToFragments(o, LEVEL_LIST));
}
compiledNodes.push(fragments);
} else {
compiledNodes.push(node.compileToFragments(o, LEVEL_LIST));
}
}
if (top) {
@@ -834,10 +828,8 @@
fragments.push(this.makeCode(scope.assignedVariables().join(`,\n${this.tab + TAB}`)));
}
fragments.push(this.makeCode(`;\n${(this.spaced ? '\n' : '')}`));
} else {
if (fragments.length && post.length) {
fragments.push(this.makeCode("\n"));
}
} else if (fragments.length && post.length) {
fragments.push(this.makeCode("\n"));
}
}
return fragments.concat(post);
@@ -864,10 +856,8 @@
if (indent) {
fragmentIndent = indent[0];
break;
} else {
if (indexOf.call(pastFragment.code, '\n') >= 0) {
break;
}
} else if (indexOf.call(pastFragment.code, '\n') >= 0) {
break;
}
}
code = `\n${fragmentIndent}` + ((function() {
@@ -896,13 +886,11 @@
if (pastFragmentIndex === 0) {
pastFragment.code = '\n' + pastFragment.code;
newLineIndex = 0;
} else if (pastFragment.isStringWithInterpolations && pastFragment.code === '{') {
code = code.slice(1) + '\n'; // Move newline to end.
newLineIndex = 1;
} else {
if (pastFragment.isStringWithInterpolations && pastFragment.code === '{') {
code = code.slice(1) + '\n'; // Move newline to end.
newLineIndex = 1;
} else {
continue;
}
continue;
}
}
delete fragment.precedingComments;
@@ -938,10 +926,8 @@
if (indent) {
fragmentIndent = indent[0];
break;
} else {
if (indexOf.call(upcomingFragment.code, '\n') >= 0) {
break;
}
} else if (indexOf.call(upcomingFragment.code, '\n') >= 0) {
break;
}
}
}
@@ -976,13 +962,11 @@
if (upcomingFragmentIndex === fragments.length - 1) {
upcomingFragment.code = upcomingFragment.code + '\n';
newLineIndex = upcomingFragment.code.length;
} else if (upcomingFragment.isStringWithInterpolations && upcomingFragment.code === '}') {
code = `${code}\n`;
newLineIndex = 0;
} else {
if (upcomingFragment.isStringWithInterpolations && upcomingFragment.code === '}') {
code = `${code}\n`;
newLineIndex = 0;
} else {
continue;
}
continue;
}
}
delete fragment.followingComments;
@@ -1222,12 +1206,10 @@
fragment = answer[j];
if (fragment.isHereComment && indexOf.call(fragment.code, '\n') >= 0) {
fragment.code = multident(fragment.code, this.tab);
} else if (fragment.isLineComment) {
fragment.code = `${this.tab}${fragment.code}`;
} else {
if (fragment.isLineComment) {
fragment.code = `${this.tab}${fragment.code}`;
} else {
break;
}
break;
}
}
} else {
@@ -1514,12 +1496,10 @@
eachName(iterator) {
if (this.hasProperties()) {
return iterator(this);
} else if (this.base.isAssignable()) {
return this.base.eachName(iterator);
} else {
if (this.base.isAssignable()) {
return this.base.eachName(iterator);
} else {
return this.error('tried to assign to unassignable value');
}
return this.error('tried to assign to unassignable value');
}
}

View File

@@ -200,27 +200,25 @@
} else {
rules.push(lastOpt.rule);
}
} else {
if ([LONG_FLAG, SHORT_FLAG].some(function(pat) {
return arg.match(pat) != null;
})) {
singleRule = flagDict[arg];
if (singleRule == null) {
throw new Error(`unrecognized option ${arg}`);
}
if (singleRule.hasArgument) {
needsArgOpt = {
rule: singleRule,
flag: arg
};
} else {
rules.push(singleRule);
}
} else {
// This is a positional argument.
positional = args.slice(argIndex);
break;
} else if ([LONG_FLAG, SHORT_FLAG].some(function(pat) {
return arg.match(pat) != null;
})) {
singleRule = flagDict[arg];
if (singleRule == null) {
throw new Error(`unrecognized option ${arg}`);
}
if (singleRule.hasArgument) {
needsArgOpt = {
rule: singleRule,
flag: arg
};
} else {
rules.push(singleRule);
}
} else {
// This is a positional argument.
positional = args.slice(argIndex);
break;
}
}
if (needsArgOpt != null) {

View File

@@ -134,10 +134,8 @@
}
if (ref = token[0], indexOf.call(EXPRESSION_START, ref) >= 0) {
levels += 1;
} else {
if (ref1 = token[0], indexOf.call(EXPRESSION_END, ref1) >= 0) {
levels -= 1;
}
} else if (ref1 = token[0], indexOf.call(EXPRESSION_END, ref1) >= 0) {
levels -= 1;
}
if (levels < 0) {
if (opts.returnOnNegativeLevel) {
@@ -414,12 +412,10 @@
while (inImplicit()) {
if (inImplicitCall()) {
endImplicitCall();
} else if (inImplicitObject()) {
endImplicitObject();
} else {
if (inImplicitObject()) {
endImplicitObject();
} else {
stack.pop();
}
stack.pop();
}
}
start = stack.pop();
@@ -537,21 +533,17 @@
// Close implicit calls when reached end of argument list
if (inImplicitCall() && prevTag !== ',' || (prevTag === ',' && tag === 'TERMINATOR' && (nextTag == null))) {
endImplicitCall();
// Close implicit objects such as:
// return a: 1, b: 2 unless true
} else if (inImplicitObject() && sameLine && tag !== 'TERMINATOR' && prevTag !== ':' && !((tag === 'POST_IF' || tag === 'FOR' || tag === 'WHILE' || tag === 'UNTIL') && startsLine && 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 doesnt look like
// the continuation of an object.
} else if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) {
endImplicitObject();
} else {
// Close implicit objects such as:
// return a: 1, b: 2 unless true
if (inImplicitObject() && sameLine && tag !== 'TERMINATOR' && prevTag !== ':' && !((tag === 'POST_IF' || tag === 'FOR' || tag === 'WHILE' || tag === 'UNTIL') && startsLine && implicitObjectContinues(i + 1))) {
endImplicitObject();
} else {
// 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 doesnt look like
// the continuation of an object.
if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) {
endImplicitObject();
} else {
break;
}
}
break;
}
}
}
@@ -726,15 +718,13 @@
first_line: line,
first_column: column
} = nextLocation);
} else if (prevLocation = (ref1 = tokens[i - 1]) != null ? ref1[2] : void 0) {
({
last_line: line,
last_column: column
} = prevLocation);
} else {
if (prevLocation = (ref1 = tokens[i - 1]) != null ? ref1[2] : void 0) {
({
last_line: line,
last_column: column
} = prevLocation);
} else {
line = column = 0;
}
line = column = 0;
}
token[2] = {
first_line: line,