Skip to content

Commit 7d2c12c

Browse files
committed
php 7.4 fixes
1 parent 0dd2727 commit 7d2c12c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=5.3.0"
16+
"php": ">=7.0.0"
1717
},
1818
"autoload": {
1919
"psr-0": {

src/CoffeeScript/Lexer.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ static function t_canonical($token)
292292

293293
return $token;
294294
}
295-
else if (is_numeric($token))
295+
296+
if (is_numeric($token))
296297
{
297298
$token = substr(Parser::tokenName($token), 3);
298299
}
@@ -316,7 +317,7 @@ function __construct($code, $options)
316317
$code = "\n{$code}";
317318
}
318319

319-
$code = preg_replace(self::$TRAILING_SPACES, '', str_replace("\r", '', $code));
320+
$code = rtrim(str_replace("\r", '', $code));
320321

321322
$options = array_merge(array(
322323
'indent' => 0,
@@ -357,7 +358,7 @@ function balanced_string($str, $end)
357358
continue;
358359
}
359360

360-
switch ($letter = $str{$i})
361+
switch ($letter = $str[$i])
361362
{
362363
case '\\':
363364
++$continue_count;
@@ -443,7 +444,7 @@ function heredoc_token()
443444
}
444445

445446
$heredoc = $match[0];
446-
$quote = $heredoc{0};
447+
$quote = $heredoc[0];
447448
$doc = $this->sanitize_heredoc($match[2], array('quote' => $quote, 'indent' => NULL));
448449

449450
if ($quote === '"' && strpos($doc, '#{') !== FALSE)
@@ -469,7 +470,7 @@ function heregex_token($match)
469470
$re = preg_replace(self::$HEREGEX_OMIT, '', $body);
470471
$re = preg_replace('/\//', '\\/', $re);
471472

472-
if (preg_match('/^\*/', $re))
473+
if (strpos($re, "*") === 0)
473474
{
474475
$this->error('regular expressions cannot begin with `*`');
475476
}
@@ -731,8 +732,7 @@ function interpolate_string($str, array $options = array()) // #{0}
731732
$this->token('(', '(');
732733
}
733734

734-
for ($i = 0; $i < count($tokens); $i++)
735-
{
735+
foreach ($tokens as $i => $iValue) {
736736
list($tag, $value) = $tokens[$i];
737737

738738
if ($i)
@@ -760,7 +760,7 @@ function interpolate_string($str, array $options = array()) // #{0}
760760

761761
function js_token()
762762
{
763-
if ( ! ($this->chunk{0} === '`' && preg_match(self::$JSTOKEN, $this->chunk, $match)))
763+
if ( ! ($this->chunk[0] === '`' && preg_match(self::$JSTOKEN, $this->chunk, $match)))
764764
{
765765
return 0;
766766
}
@@ -841,7 +841,7 @@ function literal_token()
841841
}
842842
else
843843
{
844-
$value = $this->chunk{0};
844+
$value = $this->chunk[0];
845845
}
846846

847847
$tag = t($value);
@@ -888,7 +888,7 @@ function literal_token()
888888
{
889889
$tag = t('SHIFT');
890890
}
891-
else if (in_array($value, self::$LOGIC) || $value === '?' && (isset($prev['spaced']) && $prev['spaced']))
891+
else if (in_array($value, self::$LOGIC) || ($value === '?' && (isset($prev['spaced']) && $prev['spaced'])))
892892
{
893893
$tag = t('LOGIC');
894894
}
@@ -979,7 +979,7 @@ function number_token()
979979
{
980980
$this->error("radix prefix '$number' must be lowercase");
981981
}
982-
else if (preg_match('/E/', $number) && ! preg_match('/^0x/', $number))
982+
else if (strpos($number, "E") !== false && strpos($number, "0x") !== 0)
983983
{
984984
$this->error("exponential notation '$number' must be indicated with a lowercase 'e'");
985985
}
@@ -1077,7 +1077,7 @@ function pair($tag)
10771077

10781078
function regex_token()
10791079
{
1080-
if ($this->chunk{0} !== '/')
1080+
if ($this->chunk[0] !== '/')
10811081
{
10821082
return 0;
10831083
}
@@ -1094,7 +1094,7 @@ function regex_token()
10941094

10951095
if ($prev)
10961096
{
1097-
if (in_array($prev[0], t((isset($prev['spaced']) && $prev['spaced']) ?
1097+
if (in_array($prev[0], t((isset($prev['spaced']) && $prev['spaced']) ?
10981098
self::$NOT_REGEX : self::$NOT_SPACED_REGEX)))
10991099
{
11001100
return 0;
@@ -1168,7 +1168,7 @@ function sanitize_heredoc($doc, array $options)
11681168

11691169
function string_token()
11701170
{
1171-
switch ($this->chunk{0})
1171+
switch ($this->chunk[0])
11721172
{
11731173
case "'":
11741174
if ( ! preg_match(self::$SIMPLESTR, $this->chunk, $match))
@@ -1222,6 +1222,8 @@ function tag($index = 0, $tag = NULL)
12221222
{
12231223
$token = & last($this->tokens, $index);
12241224

1225+
if (!$token) $token = [];
1226+
12251227
if ( ! is_null($tag))
12261228
{
12271229
$token[0] = $tag;
@@ -1286,7 +1288,7 @@ function tokenize()
12861288
{
12871289
while ( ($this->chunk = substr($this->code, $this->index)) != FALSE )
12881290
{
1289-
$types = array('identifier', 'comment', 'whitespace', 'line', 'heredoc',
1291+
$types = array('identifier', 'comment', 'whitespace', 'line', 'heredoc',
12901292
'string', 'number', 'regex', 'js', 'literal');
12911293

12921294
foreach ($types as $type)
@@ -1319,12 +1321,14 @@ function value($index = 0, $value = NULL)
13191321
{
13201322
$token = & last($this->tokens, $index);
13211323

1324+
if (!$token) $token = [];
1325+
13221326
if ( ! is_null($value))
13231327
{
13241328
$token[1] = $value;
13251329
}
13261330

1327-
return $token[1];
1331+
return $token[1] ?? null;
13281332
}
13291333

13301334
function unfinished()
@@ -1337,7 +1341,7 @@ function unfinished()
13371341

13381342
function whitespace_token()
13391343
{
1340-
if ( ! (preg_match(self::$WHITESPACE, $this->chunk, $match) || ($nline = ($this->chunk{0} === "\n"))))
1344+
if ( ! (preg_match(self::$WHITESPACE, $this->chunk, $match) || ($nline = ($this->chunk[0] === "\n"))))
13411345
{
13421346
return 0;
13431347
}

0 commit comments

Comments
 (0)