Skip to content
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

Expose source mapping through JSGenApi #8625

Open
benmerckx opened this issue Aug 9, 2019 · 6 comments
Open

Expose source mapping through JSGenApi #8625

benmerckx opened this issue Aug 9, 2019 · 6 comments
Labels
platform-javascript Everything related to JS / JavaScript
Milestone

Comments

@benmerckx
Copy link
Contributor

Would love to get access to source mapping data for generated code by JSGenApi (generateValue & generateStatement).

@Aurel300
Copy link
Member

Aurel300 commented Aug 9, 2019

Both generateValue and generateStatement take a TypedExpr, which has a pos field, expressing where in the source code this expression comes from. Is this not what you want?

@benmerckx
Copy link
Contributor Author

Yes, but I'm looking to get that information for every sub expression as well. I thought of going through the expressions but it essentially means reimplementing gen_exp and gen_value of genjs.

@Aurel300
Copy link
Member

Aurel300 commented Aug 9, 2019

TypedExprTools has iter (and map), which lets you provide a function that is called on every sub-expression of a given TypedExpr.

@benmerckx
Copy link
Contributor Author

That would help iterating and finding source positions. But it doesn't help that much finding generated code positions (unless I'm not thinking this through). In the scenario where I'd use JSGenApi to generate expressions I can get the code, then iterate through sub expressions. But to have an idea of position in the generated code (which was already generated for it's parent expr) I'd have to generate code again and then somehow string search its position in the parent code.

@Aurel300
Copy link
Member

Aurel300 commented Aug 9, 2019

Oh right, now I understand. I'm not sure this can be made easily accessible. The actual positions in the generated code can only be determined once the code is generated, since a change in any expression results in everything after it in the file changing positions as well …

Perhaps you could insert /*POS:...*/ markers in the generated code, then post-process that? I'm not sure what your intended application is.

@benmerckx
Copy link
Contributor Author

I'm not sure what your intended application is.

I was looking into generating split js files(#5831). Hxgenjs does just that using a custom generator but provides no sourcemap support. I realize adding it involves tracking all generated code positions. Couldn't see where to get at that data for generateValue though. Inserting the position data into the code would work but I fear that would slow the whole process down a lot more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-javascript Everything related to JS / JavaScript
Projects
None yet
Development

No branches or pull requests

4 participants