-
Notifications
You must be signed in to change notification settings - Fork 2
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
direction? #2
Comments
It looks like you're modifying the original AST, but that isn't obvious to users. I'd recommend leaving the original AST untouched and returning the fully-formed shell code as a string. I get nasty errors when trying to call
|
I put it in the README and the test cases that ensure the user knows they are getting back and AST with an attribute to retrieve the source. I can submit a PR to do what you are asking, instead of sending back the AST or maybe have two methods? One for altering the AST, another for actually returning the values? |
@gabrielcsapo you can clone the original node and add the This could anyway have a big impact on the performance of the transform, especially for very big tree. Do you know how |
@parro-it looking at https://github.com/babel/babel/tree/7.0/packages/babel-generator it seems like they are accessing an object and updating it via functions like |
@gabrielcsapo yes, it seems babel mutate AST nodes.
According to me, you can go ahead mutating input objects, we just have to make it clear what we are doing for the users, using clever names for API functions... It could be better to check if source property is already present on the node, to avoid the exception above. |
@parro-it would you be able to specify where in the readme we should add this? So I had put code to block adding the property for nodes if they had a source property already, but with the recent release to the AST traverser it had fixed the issue of not being recursive. |
It could be in the example section: const enableCodeGen = require('bash-codegen');
enableCodeGen(ast);
const parsed = ast.commands.map((code) => {
return code.source + '\n';
}).join(''); |
okay, to point out that the AST is being transformed? @parro-it I will submit a PR for that then |
Why does |
@nfischer because I didn't want to call a function to get source, since it is really just a dynamic property. |
@gabrielcsapo I would complete source code generation for all node types. So, we have a source code parser, an AST traverser & transformer and finally sa source code generator. These toolkit start to resemble the What do you think of a compelte code transpiler for bash? I would love, for example, to have function with named arguments. That feature could be transpiled, like we do with js |
I will try to allocate time to finish up the generation piece. The preservation of location will be very helpful. Having a Babel like parser for bash will be incredibly helpful! I like the idea! |
@parro-it are you suggesting making a new bash-like language with extra features, and transpiling down to bash in order to run it? |
Yes, I'm suggesting that. Does it sound crazy? |
that would be awesome 😮 |
Could be a fun project. What new features do you have in mind? |
Okay finally back working on this, I saw you made changes to bash-ast-parser @parro-it that allows us to get functions?! woot woot! Do we have an test data that we can deconstruct and reconstruct so I can write some tests? |
What would be the best path for a bash2js transpiler? Run over the bash-ast and write Javscript code from it, or convert the bash-ast to some kind of Javascript-ast and use an already available Javascript code generator? What ones currently there are that accept a JSON object and are easy to use (and generate performant code, too :-D )? |
hello from the future : ) |
Hello future! |
I added a basic initial commit with some working code and a test case.
What do you think about the direction?
@parro-it @dthree
The text was updated successfully, but these errors were encountered: