Skip to content

Commit 1827d2e

Browse files
Merge pull request #2 from Enkora/php74fixes
N-12043 php7.4 issues: coffeescript compiler is broken
2 parents 0dd2727 + 9b4bcc4 commit 1827d2e

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
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: 24 additions & 20 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
}
@@ -651,9 +652,9 @@ function interpolate_string($str, array $options = array()) // #{0}
651652
$pi = 0;
652653
$i = -1;
653654

654-
while ( isset($str{++$i}) )
655+
while ( isset($str[++$i]) )
655656
{
656-
$letter = $str{$i};
657+
$letter = $str[$i];
657658

658659
if ($letter === '\\')
659660
{
@@ -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,12 +1222,14 @@ 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;
12281230
}
12291231

1230-
return $token[0];
1232+
return $token[0] ?? null;
12311233
}
12321234

12331235
function tag_parameters()
@@ -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
}

src/CoffeeScript/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3014,7 +3014,7 @@ function yy_r186(){ $this->_retvalue = yy('Op', $this->yystack[$this->yyidx + -1
30143014
#line 3014 "/var/www/coffeescript-php/grammar.php"
30153015
#line 294 "/var/www/coffeescript-php/grammar.y"
30163016
function yy_r192(){
3017-
if ($this->yystack[$this->yyidx + -1]->minor{0} === '!') {
3017+
if ($this->yystack[$this->yyidx + -1]->minor[0] === '!') {
30183018
$this->_retvalue = yy('Op', substr($this->yystack[$this->yyidx + -1]->minor, 1), $this->yystack[$this->yyidx + -2]->minor, $this->yystack[$this->yyidx + 0]->minor);
30193019
$this->_retvalue = $this->_retvalue->invert();
30203020
}

src/CoffeeScript/Scope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function declared_variables()
9898
{
9999
if ($v['type'] === 'var')
100100
{
101-
if ($v['name']{0} === '_')
101+
if ($v['name'][0] === '_')
102102
{
103103
$temp_vars[] = $v['name'];
104104
}

tests/cases/strict.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ test "octal escape sequences prohibited", ->
4141
strict '"_\\1_"'
4242
strict '"\\\\\\1"'
4343
strictOk '"\\0"'
44-
eq "\x00", "\0"
44+
eq "\x00", "\\0"
4545
strictOk '"\\08"'
46-
eq "\x008", "\08"
46+
eq "\x008", "\\08"
4747
strictOk '"\\0\\8"'
48-
eq "\x008", "\0\8"
48+
eq "\x008", "\\0\\8"
4949
strictOk '"\\8"'
5050
eq "8", "\8"
5151
strictOk '"\\\\1"'

0 commit comments

Comments
 (0)