Skip to content

Commit

Permalink
Fixed issue where an automatic semi-colon was incorrectly inserted wh…
Browse files Browse the repository at this point in the history
…en the linebreak was preceded by a double operator.

Added tests.
  • Loading branch information
hexydec committed Nov 28, 2022
1 parent 706a53c commit 7922434
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tokens/expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected function isEol(tokenise $tokens, $prev = null, $beforeprev = null, boo
return false;

// if the previous expression is an operator, like + or =, then the expression must end if next not an operator
} elseif ($beforeprevtype === $op && !\in_array($next['type'], ['operator', 'openbracket', 'eol'])) {
} elseif ($beforeprevtype === $op && $prevtype !== $op && !\in_array($next['type'], ['operator', 'openbracket', 'eol'])) {
return true;

// next expression starts with a keyword
Expand Down
21 changes: 21 additions & 0 deletions tests/jsliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,27 @@ function () {
}
);',
'output' => 'func(test,500,"string",function(){return "watevz";});'
],
[ // don't insert semi-colon
'input' => 's.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
urlAnchor.protocol + "//" + urlAnchor.host;',
'output' => 's.crossDomain=originAnchor.protocol+"//"+originAnchor.host!==urlAnchor.protocol+"//"+urlAnchor.host;'
],
[
'input' => 'var val = 5 +
6;',
'output' => 'var val=5+6;'
],
[
'input' => 'var val = 5
+ 6;',
'output' => 'var val=5+6;'
],
[
'input' => 'var val = 5
+
6;',
'output' => 'var val=5+6;'
]
];
$this->compareMinify($tests, ['semicolons' => false]);
Expand Down

0 comments on commit 7922434

Please sign in to comment.