Skip to content

Commit

Permalink
Extract helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Nov 7, 2019
1 parent 3599b9e commit 3c73022
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/source-code/source-code.js
Expand Up @@ -78,6 +78,17 @@ function sortedMerge(tokens, comments) {
return result;
}

/**
* Determines if two nodes or tokens overlap.
* @param {ASTNode|Token} first The first node or token to check.
* @param {ASTNode|Token} second The second node or token to check.
* @returns {boolean} True if the two nodes or tokens overlap.
* @private
*/
function nodesOrTokensOverlap(first, second) {
return first.range[0] <= second.range[0] && first.range[1] >= second.range[0];
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -421,10 +432,7 @@ class SourceCode extends TokenStore {
* @public
*/
isSpaceBetweenTokens(first, second) {

// Arguments are overlapping.
if (first.range[0] <= second.range[0] && first.range[1] >= second.range[0] ||
second.range[0] <= first.range[0] && second.range[1] >= first.range[0]) {
if (nodesOrTokensOverlap(first, second) || nodesOrTokensOverlap(second, first)) {
return false;
}

Expand Down

0 comments on commit 3c73022

Please sign in to comment.