Skip to content

Commit

Permalink
Merge pull request #723 from exeba/useless-if-fix
Browse files Browse the repository at this point in the history
Simpler trimming logic
  • Loading branch information
RobLoach authored Feb 23, 2020
2 parents 5f05d14 + 69f27af commit f50d1e0
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/twig.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,9 @@ module.exports = function (Twig) {
if (prevOutput.type === Twig.token.type.raw) {
output.pop();

// If the previous output is not just whitespace, trim it
if (prevOutput.value.match(/^\s*$/) === null) {
prevOutput.value = prevOutput.value.trimEnd();
// Repush the previous output
output.push(prevOutput);
}
prevOutput.value = prevOutput.value.trimEnd();
// Repush the previous output
output.push(prevOutput);
}
}

Expand All @@ -552,12 +549,9 @@ module.exports = function (Twig) {
if (prevIntermediateOutput.type === Twig.token.type.raw) {
intermediateOutput.pop();

// If the previous output is not just whitespace, trim it
if (prevIntermediateOutput.value.match(/^\s*$/) === null) {
prevIntermediateOutput.value = prevIntermediateOutput.value.trimEnd();
// Repush the previous intermediate output
intermediateOutput.push(prevIntermediateOutput);
}
prevIntermediateOutput.value = prevIntermediateOutput.value.trimEnd();
// Repush the previous intermediate output
intermediateOutput.push(prevIntermediateOutput);
}
}
}
Expand All @@ -584,12 +578,9 @@ module.exports = function (Twig) {
if (nextToken.type === Twig.token.type.raw) {
tokens.shift();

// If the next token is not just whitespace, trim it
if (nextToken.value.match(/^\s*$/) === null) {
nextToken.value = nextToken.value.trimStart();
// Unshift the next token
tokens.unshift(nextToken);
}
nextToken.value = nextToken.value.trimStart();
// Unshift the next token
tokens.unshift(nextToken);
}
}
}
Expand Down

0 comments on commit f50d1e0

Please sign in to comment.