Skip to content

Commit 2812ae6

Browse files
authored
fix(php8): non-capturing exception catches (#1763)
Fixes #1760
1 parent 539fa40 commit 2812ae6

5 files changed

Lines changed: 43 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"linguist-languages": "^7.5.1",
1515
"mem": "^8.0.0",
16-
"php-parser": "https://github.com/glayzzle/php-parser#bb89fff9e636a991aa3ac931d5f8a66a365fccce"
16+
"php-parser": "https://github.com/glayzzle/php-parser#425c4dcc9f386596bdcd5b458503b3667a858141"
1717
},
1818
"devDependencies": {
1919
"@babel/preset-env": "^7.7.5",

src/printer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,8 +2072,7 @@ function printNode(path, options, print) {
20722072
? concat([
20732073
" (",
20742074
join(" | ", path.map(print, "what")),
2075-
" ",
2076-
path.call(print, "variable"),
2075+
node.variable ? concat([" ", path.call(print, "variable")]) : "",
20772076
")",
20782077
])
20792078
: "",

tests/errors/__snapshots__/jsfmt.spec.js.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ try {
5555
// Comment
5656
}
5757
58+
// PHP 8.0 non-capturing exception catch
59+
try {
60+
// Something
61+
} catch (\\Exception) {
62+
// Nothing
63+
}
64+
65+
try {
66+
// Something
67+
} catch (MyException | OtherException) {
68+
// Nothing
69+
}
70+
5871
=====================================output=====================================
5972
<?php
6073
try {
@@ -107,5 +120,18 @@ try {
107120
// Comment
108121
}
109122
123+
// PHP 8.0 non-capturing exception catch
124+
try {
125+
// Something
126+
} catch (\\Exception) {
127+
// Nothing
128+
}
129+
130+
try {
131+
// Something
132+
} catch (MyException | OtherException) {
133+
// Nothing
134+
}
135+
110136
================================================================================
111137
`;

tests/errors/errors.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,16 @@
4646
} finally {
4747
// Comment
4848
}
49+
50+
// PHP 8.0 non-capturing exception catch
51+
try {
52+
// Something
53+
} catch (\Exception) {
54+
// Nothing
55+
}
56+
57+
try {
58+
// Something
59+
} catch (MyException | OtherException) {
60+
// Nothing
61+
}

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,9 +4603,9 @@ performance-now@^2.1.0:
46034603
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
46044604
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
46054605

4606-
"php-parser@https://github.com/glayzzle/php-parser#bb89fff9e636a991aa3ac931d5f8a66a365fccce":
4606+
"php-parser@https://github.com/glayzzle/php-parser#425c4dcc9f386596bdcd5b458503b3667a858141":
46074607
version "3.0.2"
4608-
resolved "https://github.com/glayzzle/php-parser#bb89fff9e636a991aa3ac931d5f8a66a365fccce"
4608+
resolved "https://github.com/glayzzle/php-parser#425c4dcc9f386596bdcd5b458503b3667a858141"
46094609

46104610
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1:
46114611
version "2.2.2"

0 commit comments

Comments
 (0)