Skip to content

...#42

Open
zaoqi wants to merge 52 commits into
endel:masterfrom
zaoqi-clone:master
Open

...#42
zaoqi wants to merge 52 commits into
endel:masterfrom
zaoqi-clone:master

Conversation

@zaoqi

@zaoqi zaoqi commented May 4, 2019

Copy link
Copy Markdown

No description provided.

cscott added 30 commits February 4, 2019 17:06
Multiple initializers should be comma-separated.
This prevents matching 'hasOwnProperty' and other properties of object.
Property names are encoded with a leading dot, since method names are the
most common case.  This allows us to handle `Array.prototype.slice.call(...)`
and similar constructs in a subsequent patch.
@zaoqi

zaoqi commented May 4, 2019

Copy link
Copy Markdown
Author

@cscott

$ echo 'function f(){var a=0;function g(){return a;}return g();}' | npx js2php /dev/stdin
function f() { $a = 0; function g() use ( &$a ) { return $a;  }return g();  }
$ php -a
Interactive shell

php > function f() { $a = 0; function g() use ( &$a ) { return $a;  }return g();  }
PHP Parse error:  syntax error, unexpected 'use' (T_USE), expecting '{' in php shell code on line 1

@zaoqi

zaoqi commented May 4, 2019

Copy link
Copy Markdown
Author
$ echo 'function f(){var x=0;var g=(x)=>x;}' | npx js2php /dev/stdin
<?php
function f() { $x = 0; $g = function ( $x ) use ( &$x ) {return  $x; };  }

@cscott

@zaoqi

zaoqi commented May 4, 2019

Copy link
Copy Markdown
Author
$ echo 'function f(){}var g=f;' | npx js2php
<?php
function f() {}$g = $f;

@cscott

@endel

endel commented May 5, 2019

Copy link
Copy Markdown
Owner

Wow, lots of additions @zaoqi!

Do you mind reviewing it? @2pha @allain @cscott @Grynn
I'm not using this project anymore, so if you're okay with these changes, I'll just going to accept it.

Cheers!

@yi-ge

yi-ge commented Jul 29, 2019

Copy link
Copy Markdown

Very cool!

@cscott

cscott commented Jul 30, 2019

Copy link
Copy Markdown
Contributor

It's not quite clear to me, but I think @zaoqi is proposing to merge a bunch of changes from the https://github.com/cscott/js2php fork back into master? They are all appropriate, I guess, except mabe for b4bd92a and da730e8 -- and even those probably don't hurt anything.

I should note though that the focus of my patches shifted from trying to exactly match JS execution (ie, execute JavaScript in PHP) from trying to provide a reasonable-quality "natural reading" source-level transformation to guide a port. We are porting https://www.mediawiki.org/wiki/Parsoid from JS into PHP ( https://www.mediawiki.org/wiki/Parsing/Notes/Moving_Parsoid_Into_Core/Porting ) and we've found js2php invaluable for doing a first pass conversion of our ~70k lines of code (see wikimedia/mediawiki-services-parsoid@83ed537). When we actually "port" the code after that, we can easily concentrate on the differences between the js2php-generated skeleton and the working file -- the diff now shows "real" changes, not just syntax conversion.

All of which is to say I wasn't super concerned with executability of the result, as long as it "looked right" to a reader, and in a few places I added big /* REVIEW ME */ type comments to the output where the semantics of the JS and PHP were subtly different and a human really needed to think hard about the code to figure out what the right thing to do was. So my fork is subtly different in purpose from mainline. But it was extremely helpful to us, thank you thank you @endel!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants