comparison vendor/squizlabs/php_codesniffer/src/Tokenizers/JS.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
255 * @param string $content The content to tokenize, 255 * @param string $content The content to tokenize,
256 * @param \PHP_CodeSniffer\Config $config The config data for the run. 256 * @param \PHP_CodeSniffer\Config $config The config data for the run.
257 * @param string $eolChar The EOL char used in the content. 257 * @param string $eolChar The EOL char used in the content.
258 * 258 *
259 * @return void 259 * @return void
260 * @throws TokenizerException If the file appears to be minified. 260 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
261 */ 261 */
262 public function __construct($content, Config $config, $eolChar='\n') 262 public function __construct($content, Config $config, $eolChar='\n')
263 { 263 {
264 if ($this->isMinifiedContent($content, $eolChar) === true) { 264 if ($this->isMinifiedContent($content, $eolChar) === true) {
265 throw new TokenizerException('File appears to be minified and cannot be processed'); 265 throw new TokenizerException('File appears to be minified and cannot be processed');
266 } 266 }
267 267
268 return parent::__construct($content, $config, $eolChar); 268 parent::__construct($content, $config, $eolChar);
269 269
270 }//end __construct() 270 }//end __construct()
271 271
272 272
273 /** 273 /**
444 } 444 }
445 445
446 // Special case for T_DIVIDE which can actually be 446 // Special case for T_DIVIDE which can actually be
447 // the start of a regular expression. 447 // the start of a regular expression.
448 if ($buffer === $char && $char === '/' && $chars[($i + 1)] !== '*') { 448 if ($buffer === $char && $char === '/' && $chars[($i + 1)] !== '*') {
449 $regex = $this->getRegexToken( 449 $regex = $this->getRegexToken($i, $string, $chars, $tokens);
450 $i,
451 $string,
452 $chars,
453 $tokens,
454 $this->eolChar
455 );
456
457 if ($regex !== null) { 450 if ($regex !== null) {
458 $tokens[] = [ 451 $tokens[] = [
459 'code' => T_REGULAR_EXPRESSION, 452 'code' => T_REGULAR_EXPRESSION,
460 'type' => 'T_REGULAR_EXPRESSION', 453 'type' => 'T_REGULAR_EXPRESSION',
461 'content' => $regex['content'], 454 'content' => $regex['content'],
830 if (strpos($token['content'], $this->eolChar) !== false) { 823 if (strpos($token['content'], $this->eolChar) !== false) {
831 $tokenLines = explode($this->eolChar, $token['content']); 824 $tokenLines = explode($this->eolChar, $token['content']);
832 $numLines = count($tokenLines); 825 $numLines = count($tokenLines);
833 826
834 for ($i = 0; $i < $numLines; $i++) { 827 for ($i = 0; $i < $numLines; $i++) {
835 $newToken['content'] = $tokenLines[$i]; 828 $newToken = ['content' => $tokenLines[$i]];
836 if ($i === ($numLines - 1)) { 829 if ($i === ($numLines - 1)) {
837 if ($tokenLines[$i] === '') { 830 if ($tokenLines[$i] === '') {
838 break; 831 break;
839 } 832 }
840 } else { 833 } else {
916 * @param string $char The index of the possible regex start character. 909 * @param string $char The index of the possible regex start character.
917 * @param string $string The complete content of the string being tokenized. 910 * @param string $string The complete content of the string being tokenized.
918 * @param string $chars An array of characters being tokenized. 911 * @param string $chars An array of characters being tokenized.
919 * @param string $tokens The current array of tokens found in the string. 912 * @param string $tokens The current array of tokens found in the string.
920 * 913 *
921 * @return void 914 * @return array<string, string>|null
922 */ 915 */
923 public function getRegexToken($char, $string, $chars, $tokens) 916 public function getRegexToken($char, $string, $chars, $tokens)
924 { 917 {
925 $beforeTokens = [ 918 $beforeTokens = [
926 T_EQUAL => true, 919 T_EQUAL => true,
1109 continue; 1102 continue;
1110 } else if ($this->tokens[$i]['code'] === T_OPEN_CURLY_BRACKET 1103 } else if ($this->tokens[$i]['code'] === T_OPEN_CURLY_BRACKET
1111 && isset($this->tokens[$i]['scope_condition']) === false 1104 && isset($this->tokens[$i]['scope_condition']) === false
1112 && isset($this->tokens[$i]['bracket_closer']) === true 1105 && isset($this->tokens[$i]['bracket_closer']) === true
1113 ) { 1106 ) {
1114 $condition = end($this->tokens[$i]['conditions']); 1107 $condition = $this->tokens[$i]['conditions'];
1115 reset($this->tokens[$i]['conditions']); 1108 $condition = end($condition);
1116 if ($condition === T_CLASS) { 1109 if ($condition === T_CLASS) {
1117 // Possibly an ES6 method. To be classified as one, the previous 1110 // Possibly an ES6 method. To be classified as one, the previous
1118 // non-empty tokens need to be a set of parenthesis, and then a string 1111 // non-empty tokens need to be a set of parenthesis, and then a string
1119 // (the method name). 1112 // (the method name).
1120 for ($parenCloser = ($i - 1); $parenCloser > 0; $parenCloser--) { 1113 for ($parenCloser = ($i - 1); $parenCloser > 0; $parenCloser--) {