Hacker News new | ask | show | jobs
by pornel 3269 days ago
That's a weekend project and it turned out better than I expected. Thanks to nikic's php-parser, astexplorer.net and Babel infrastructure handling the gnarly bits (e.g. source maps just worked).

I started it because I hoped it would speed up rewrites of projects from PHP to JS, but now that I've actually seen the results, I realised that bad PHP code makes only worse JS (and there's no point rewriting good PHP code).

Still, I think it could be useful for sharing some logic between client and the server, without replacing server-side with Node. This isn't a VM, so it has zero overhead at the cost of being loose with semantic edge cases.

And I find it funny that it now takes 1 line of config to make JS tools work with PHP syntax instead.

3 comments

You did a great job with this, I started something really similar about 6 months ago because I wanted to port SabreDAV to js (I didn't quite get to the stage of self hosting PHP parser) but eventually came to the same conclusions, even with a good codebase idiomatic PHP does not map cleanly to idiomatic JS
If anyone wants to try this out (I did), just added it to the Babel website! https://babeljs.io/php

atm you have to add `<?php` at the beginning.

Hi pornel, just a little precision on the library author, it seems you are using ichiriac's php-parser :))
Oh, indeed! Sorry for miscrediting. Great work.