From f609036beef3aa1529c210ffad3ced818ee94cce Mon Sep 17 00:00:00 2001 From: Demian Ferreiro Date: Mon, 25 Feb 2013 10:44:56 -0300 Subject: [PATCH] Remove unnecessary returns and use default parameters --- lib/coffee-script/lexer.js | 8 +++++--- src/lexer.coffee | 13 +++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index 6a7b5430..edf5c9f6 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -732,13 +732,15 @@ Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) { var lastCharacter, locationData, token, _ref2, _ref3; - offsetInChunk = offsetInChunk || 0; - if (length === void 0) { + if (offsetInChunk == null) { + offsetInChunk = 0; + } + if (length == null) { length = value.length; } locationData = {}; _ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1]; - lastCharacter = length > 0 ? length - 1 : 0; + lastCharacter = Math.max(0, length - 1); _ref3 = this.getLineAndColumnFromChunk(offsetInChunk + (length - 1)), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1]; token = [tag, value, locationData]; return token; diff --git a/src/lexer.coffee b/src/lexer.coffee index 81c2834b..bfb60c46 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -634,27 +634,24 @@ exports.Lexer = class Lexer else column += string.length - return [@chunkLine + lineCount, column] + [@chunkLine + lineCount, column] # Same as "token", exception this just returns the token without adding it # to the results. - makeToken: (tag, value, offsetInChunk, length) -> - offsetInChunk = offsetInChunk || 0 - if length is undefined then length = value.length - + makeToken: (tag, value, offsetInChunk = 0, length = value.length) -> locationData = {} [locationData.first_line, locationData.first_column] = @getLineAndColumnFromChunk offsetInChunk # Use length - 1 for the final offset - we're supplying the last_line and the last_column, # so if last_column == first_column, then we're looking at a character of length 1. - lastCharacter = if length > 0 then (length - 1) else 0 + lastCharacter = Math.max 0, length - 1 [locationData.last_line, locationData.last_column] = @getLineAndColumnFromChunk offsetInChunk + (length - 1) token = [tag, value, locationData] - return token + token # Add a token to the results. # `offset` is the offset into the current @chunk where the token starts. @@ -665,7 +662,7 @@ exports.Lexer = class Lexer token: (tag, value, offsetInChunk, length) -> token = @makeToken tag, value, offsetInChunk, length @tokens.push token - return token + token # Peek at a tag in the current token stream. tag: (index, tag) ->