Skip to content

Commit

Permalink
Fixed bug #808 : JS tokeniser incorrectly setting some function and c…
Browse files Browse the repository at this point in the history
…lass names to control structure tokens
  • Loading branch information
gsherwood committed Dec 8, 2015
1 parent 1f17c67 commit b3f4f83
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ do {
} while (something);

do i++; while (i < 5);

SomeClass.prototype.switch = function() {
// do something
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ do {
} while (something);

do { i++; } while (i < 5);

SomeClass.prototype.switch = function() {
// do something
};
20 changes: 20 additions & 0 deletions CodeSniffer/Tokenizers/JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ public function tokenizeString($string, $eolChar='\n')
$cleanBuffer = false;
}
}//end for

if (empty($buffer) === false) {
// Buffer contains whitespace from the end of the file.
$tokens[] = array(
Expand Down Expand Up @@ -827,6 +828,25 @@ public function tokenizeString($string, $eolChar='\n')
$stackPtr = $oldStackPtr;
}
}//end if

// Convert the token after an object operator into a string, in most cases.
if ($token['code'] === T_OBJECT_OPERATOR) {
for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
continue;
}

if ($tokens[$i]['code'] !== T_PROTOTYPE
&& $tokens[$i]['code'] !== T_LNUMBER
&& $tokens[$i]['code'] !== T_DNUMBER
) {
$tokens[$i]['code'] = T_STRING;
$tokens[$i]['type'] = 'T_STRING';
}

break;
}
}
}//end for

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

0 comments on commit b3f4f83

Please sign in to comment.