diff --git a/package.json b/package.json index dc80fa7ce..651d431e8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dependencies": { "linguist-languages": "^7.5.1", "mem": "^8.0.0", - "php-parser": "3.1.0-beta.4" + "php-parser": "3.1.0-beta.5" }, "devDependencies": { "@babel/preset-env": "^7.16.11", diff --git a/src/printer.js b/src/printer.js index 1278ce9c5..062f3fb9d 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1613,6 +1613,18 @@ function isStringOnItsOwnLine(node, text, options) { ); } +function printComposedTypes(path, print, glue) { + return group( + concat( + path.map( + (uPath, i) => + concat(i === 0 ? [path.call(print)] : [glue, path.call(print)]), + "types" + ) + ) + ); +} + function printNode(path, options, print) { const node = path.getValue(); @@ -2930,16 +2942,11 @@ function printNode(path, options, print) { quote, ]); } + case "intersectiontype": { + return printComposedTypes(path, print, "&"); + } case "uniontype": { - return group( - concat( - path.map( - (uPath, i) => - concat(i === 0 ? [path.call(print)] : ["|", path.call(print)]), - "types" - ) - ) - ); + return printComposedTypes(path, print, "|"); } case "encapsedpart": { const open = diff --git a/tests/intersection-types/__snapshots__/jsfmt.spec.js.snap b/tests/intersection-types/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..7b9668d10 --- /dev/null +++ b/tests/intersection-types/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`intersection.php 1`] = ` +====================================options===================================== +parsers: ["php"] +printWidth: 80 + | printWidth +=====================================input====================================== +getTitle()) . $post->getId(); +} +=====================================output===================================== +getTitle()) . $post->getId(); +} + +================================================================================ +`; diff --git a/tests/intersection-types/intersection.php b/tests/intersection-types/intersection.php new file mode 100644 index 000000000..f68572c29 --- /dev/null +++ b/tests/intersection-types/intersection.php @@ -0,0 +1,4 @@ +getTitle()) . $post->getId(); +} \ No newline at end of file diff --git a/tests/intersection-types/jsfmt.spec.js b/tests/intersection-types/jsfmt.spec.js new file mode 100644 index 000000000..e395434ee --- /dev/null +++ b/tests/intersection-types/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["php"]); diff --git a/yarn.lock b/yarn.lock index b3734c8e9..2eb20bd38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3694,10 +3694,10 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -php-parser@3.1.0-beta.4: - version "3.1.0-beta.4" - resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.1.0-beta.4.tgz#a56e3c90e0371e41fb9c1a09f4459b5adad2b03b" - integrity sha512-fLW5tSV8PK0Kizn+Wx1LrhJIFW5eYME4RXoHwIIXfArTBRs7RQJhoU016rXJTPQZIKAXo93ddVyojVvCOETxiA== +php-parser@3.1.0-beta.5: + version "3.1.0-beta.5" + resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.1.0-beta.5.tgz#81fd04ede37f3796ba2585b985831caffd62ba50" + integrity sha512-3F3+yThjD7wn0sMuIG5iMQqutmH+RJUAbEyPW5S/greTp5ZArkpEweylQh+do22q9UJlJT1PrLN/AwnzDUti6Q== picocolors@^1.0.0: version "1.0.0"