Skip to content

Commit b3f4f83

Browse files
committed
Fixed bug #808 : JS tokeniser incorrectly setting some function and class names to control structure tokens
1 parent 1f17c67 commit b3f4f83

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ do {
1919
} while (something);
2020

2121
do i++; while (i < 5);
22+
23+
SomeClass.prototype.switch = function() {
24+
// do something
25+
};

CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ do {
1919
} while (something);
2020

2121
do { i++; } while (i < 5);
22+
23+
SomeClass.prototype.switch = function() {
24+
// do something
25+
};

CodeSniffer/Tokenizers/JS.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ public function tokenizeString($string, $eolChar='\n')
676676
$cleanBuffer = false;
677677
}
678678
}//end for
679+
679680
if (empty($buffer) === false) {
680681
// Buffer contains whitespace from the end of the file.
681682
$tokens[] = array(
@@ -827,6 +828,25 @@ public function tokenizeString($string, $eolChar='\n')
827828
$stackPtr = $oldStackPtr;
828829
}
829830
}//end if
831+
832+
// Convert the token after an object operator into a string, in most cases.
833+
if ($token['code'] === T_OBJECT_OPERATOR) {
834+
for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
835+
if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
836+
continue;
837+
}
838+
839+
if ($tokens[$i]['code'] !== T_PROTOTYPE
840+
&& $tokens[$i]['code'] !== T_LNUMBER
841+
&& $tokens[$i]['code'] !== T_DNUMBER
842+
) {
843+
$tokens[$i]['code'] = T_STRING;
844+
$tokens[$i]['type'] = 'T_STRING';
845+
}
846+
847+
break;
848+
}
849+
}
830850
}//end for
831851

832852
if (PHP_CODESNIFFER_VERBOSITY > 1) {

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
4343
- Fixed bug #797 : Parsing CSS url() value breaks further parsing
4444
- Fixed bug #805 : Squiz.Commenting.FunctionComment.InvalidTypeHint on Scalar types on PHP7
4545
- Fixed bug #807 : Cannot fix line endings when open PHP tag is not on the first line
46+
- Fixed bug #808 : JS tokeniser incorrectly setting some function and class names to control structure tokens
4647
</notes>
4748
<contents>
4849
<dir name="/">

0 commit comments

Comments
 (0)