-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TransformationError: Node type 'GeneratorExp' [...] No transformation for the node #70
Comments
Hi Joe,
thanks for using JavaScripthon!
>>>> Joe Rickerby ***@***.***> writes:
Hi there! This is a very interesting project to me, currently trying to assess if it will solve a problem I have.
When converting some files in my project, I get this error:
```sh
$ pj pyinstrument/frame.py
An error occurred while compiling source file 'pyinstrument/frame.py'
TransformationError: Node type 'GeneratorExp': Line: 306, column: 29. No transformation for the node
```
eh, in general all the comprehensions aren't so well supported, I could
choose to translate to a more recent version of JS that has a better
support for those kind of code and drop ES5 completely, but with
Javascript it isn't so easy to drop legacy stuff... Anyway, there's at
least two things I can suggest you:
The line that it's referencing is this:
```python
calculated_time = sum(child.time for child in self.children) + self.absorbed_time
```
if you convert it to:
```python
calculated_time = sum([child.time for child in self.children]) + self.absorbed_time
```
then it works:
```sh
$ nix run . -- -s -
calculated_time = sum([child.time for child in self.children]) + self.absorbed_time
var calculated_time;
calculated_time = (sum(function () {
var _pj_a = [], _pj_b = this.children;
for (var _pj_c = 0, _pj_d = _pj_b.length; (_pj_c < _pj_d); _pj_c += 1) {
var child = _pj_b[_pj_c];
_pj_a.push(child.time);
}
return _pj_a;
}
.call(this)) + this.absorbed_time);
```
as you can see the code isn't so elegant, all the translation could have
a more modern cut, but unfortunately I don't use pj so frequently
anymore...
I'm also wondering if that code does the right thing, with the use of
`this`, you will have to try...
So I guess that's the generator expression. I use them a lot in this project. I guess it might translate like so?
```js
let calculated_time = this.children.map(child => child.time).reduce((a, b) => a+b) + this.absorbed_time
```
Is there a way to get these generator expressions to convert?
There's no way that the translator could come up doing such conversion
from a sum of a sequence to the reduction using a '+' binary operation
without having a dedicated translator function that maps the two.
--
Alberto Berti - Information Technology Consultant
PGP: 9377 A68C C5B5 B534 36BD F20B E3B5 C559 99D6 7CF9
"gutta cavat lapidem"
|
Ah, yeah, that might work. I almost think that, given generator expressions don't exist in JS, there's always gonna be an array involved so maybe it should always output an array for such an expression - at least, it seems better than failing. I'll do some more experimentation! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there! This is a very interesting project to me, currently trying to assess if it will solve a problem I have.
When converting some files in my project, I get this error:
The line that it's referencing is this:
So I guess that's the generator expression. I use them a lot in this project. I guess it might translate like so?
Is there a way to get these generator expressions to convert?
The text was updated successfully, but these errors were encountered: