defarg: `(options = {})` where possible
This commit is contained in:
parent
96f74f9da8
commit
371282fe7a
|
@ -6,9 +6,8 @@
|
|||
return eval(CoffeeScript.compile(code, options));
|
||||
};
|
||||
CoffeeScript.run = function(code, options) {
|
||||
if (options != null) {
|
||||
options.bare = true;
|
||||
}
|
||||
options != null ? options : options = {};
|
||||
options.bare = true;
|
||||
return Function(CoffeeScript.compile(code, options))();
|
||||
};
|
||||
if (!(typeof window !== "undefined" && window !== null)) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
exports.VERSION = '0.9.4';
|
||||
exports.helpers = require('./helpers');
|
||||
exports.compile = compile = function(code, options) {
|
||||
options || (options = {});
|
||||
options != null ? options : options = {};
|
||||
try {
|
||||
return (parser.parse(lexer.tokenize(code))).compile(options);
|
||||
} catch (err) {
|
||||
|
|
|
@ -438,7 +438,7 @@
|
|||
};
|
||||
Lexer.prototype.balancedString = function(str, delimited, options) {
|
||||
var _i, _len, close, i, levels, open, pair, slen;
|
||||
options || (options = {});
|
||||
options != null ? options : options = {};
|
||||
levels = [];
|
||||
i = 0;
|
||||
slen = str.length;
|
||||
|
@ -475,8 +475,9 @@
|
|||
return i && str.slice(0, i);
|
||||
};
|
||||
Lexer.prototype.interpolateString = function(str, options) {
|
||||
var _len, _ref2, _ref3, _this, expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value;
|
||||
_ref2 = options || (options = {}), heredoc = _ref2.heredoc, regex = _ref2.regex;
|
||||
var _len, _ref2, _this, expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value;
|
||||
options != null ? options : options = {};
|
||||
heredoc = options.heredoc, regex = options.regex;
|
||||
tokens = [];
|
||||
pi = 0;
|
||||
i = -1;
|
||||
|
@ -523,7 +524,7 @@
|
|||
this.token('(', '(');
|
||||
}
|
||||
for (i = 0, _len = tokens.length; i < _len; i++) {
|
||||
_ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
|
||||
_ref2 = tokens[i], tag = _ref2[0], value = _ref2[1];
|
||||
if (i) {
|
||||
this.token('+', '+');
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ CoffeeScript.eval = (code, options) ->
|
|||
eval CoffeeScript.compile code, options
|
||||
|
||||
# Running code does not provide access to this scope.
|
||||
CoffeeScript.run = (code, options) ->
|
||||
options?.bare = on
|
||||
CoffeeScript.run = (code, options = {}) ->
|
||||
options.bare = on
|
||||
Function(CoffeeScript.compile code, options)()
|
||||
|
||||
# If we're not in a browser environment, we're finished with the public API.
|
||||
|
|
|
@ -27,8 +27,7 @@ exports.helpers = require './helpers'
|
|||
|
||||
# Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
|
||||
# compiler.
|
||||
exports.compile = compile = (code, options) ->
|
||||
options or= {}
|
||||
exports.compile = compile = (code, options = {}) ->
|
||||
try
|
||||
(parser.parse lexer.tokenize code).compile options
|
||||
catch err
|
||||
|
|
|
@ -386,8 +386,7 @@ exports.Lexer = class Lexer
|
|||
# a series of delimiters, all of which must be nested correctly within the
|
||||
# contents of the string. This method allows us to have strings within
|
||||
# interpolations within strings, ad infinitum.
|
||||
balancedString: (str, delimited, options) ->
|
||||
options or= {}
|
||||
balancedString: (str, delimited, options = {}) ->
|
||||
levels = []
|
||||
i = 0
|
||||
slen = str.length
|
||||
|
@ -420,8 +419,8 @@ exports.Lexer = class Lexer
|
|||
# If it encounters an interpolation, this method will recursively create a
|
||||
# new Lexer, tokenize the interpolated contents, and merge them into the
|
||||
# token stream.
|
||||
interpolateString: (str, options) ->
|
||||
{heredoc, regex} = options or= {}
|
||||
interpolateString: (str, options = {}) ->
|
||||
{heredoc, regex} = options
|
||||
tokens = []
|
||||
pi = 0
|
||||
i = -1
|
||||
|
|
Loading…
Reference in New Issue