-
Notifications
You must be signed in to change notification settings - Fork 236
feat(export-to-language): Add DeclarationStore to transpiler #2964
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
feat(export-to-language): Add DeclarationStore to transpiler #2964
Conversation
…f github.com:prestonvasquez/compass into COMPASS-5685.addVariableDeclarationsToBSONTranspiler
This reverts commit 1f58923.
Looks good! Since you are updating readme, could you please also add |
Co-authored-by: Anna Henningsen <github@addaleax.net>
Co-authored-by: Anna Henningsen <github@addaleax.net>
…f github.com:prestonvasquez/compass into COMPASS-5685.addVariableDeclarationsToBSONTranspiler
…f github.com:prestonvasquez/compass into COMPASS-5685.addVariableDeclarationsToBSONTranspiler
super(); | ||
this.idiomatic = true; // PUBLIC | ||
this.clearImports(); | ||
this.state = { declarationStore: new DeclarationStore() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alenakhineika @addaleax @mcasimir I ran into an issue concerning the way we handle the argsTemplate
functions. Since they are variadic, passing in the declaration store as the last value will cause a lot of problems with existing language templates. This one, in particular, comes to mind. To fix this, I propose
- Adding this state hash in case we ever need to add state for something else in the future
- Updating all uses of
argsTemplate
so that the first argument will be bethis.state
Here is a more concise explanation.
I played around a bit with adding a new template type altogether, but to add this functionality safely we'd have to update all the templates to include that new type. Given that, using the existing args templates seemed like a more robust solution.
…f github.com:prestonvasquez/compass into COMPASS-5685.addVariableDeclarationsToBSONTranspiler
start(ctx) { | ||
return this.returnResult(ctx).trim(); | ||
start(ctx, useDeclarations = false) { | ||
return (useDeclarations ? this.returnResultWithDeclarations(ctx) : this.returnResult(ctx)).trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewdale @benjirewis Here is the final draft for the code to prepend declarations to statements. |
|
||
Transpilers for building BSON documents in any language. Current support | ||
provided for `shell` `javascript` and `python` as inputs. `java`, `c#`, `node`, `shell` and `python` as | ||
provided for `shell` `javascript` and `python` as inputs. `java`, `c#`, `node`, `shell`, `python` and `ruby` as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this say go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, we should definitely include go
. I'll update that on #2991 so that this PR can remain language agnostic. I added ruby for this request.
} | ||
``` | ||
The output of the driver syntax for this language will be the one-line statement `Hello World`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! 🧑🔧
args = visitedElements.map((arg, index) => { | ||
const last = !visitedElements[index + 1]; | ||
return ctx.type.argsTemplate(arg, ctx.indentDepth, last); | ||
return ctx.type.argsTemplate.bind(this.getState())(arg, ctx.indentDepth, last); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does bind
just merge the variables in state
with the ones already in this
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually replaces the existing this
of the prototypes with state
. The solutions seems safe based on my conversations with @mcasimir , but there may definitely be underlying problems I'm not aware of. An alternative would be to merge the two objects before the bind.
|
||
assert.strictEqual(ds.length(), 3); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great testing 🧑🔧
Co-authored-by: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com>
Description
COMPASS-5685
See the the updated README.md for the bson-transpilers package.
Checklist
Motivation and Context
The go driver export has a need to prepend the driver syntax with variable declarations to avoid using closures within the CRUD operations. For example, the following would be what is generated under the current architecture:
The proposed changes would add an optional functionality to prepend the document body with variable declarations
Open Questions
argsTemplate
hold up? That is, is it best practices?DeclarationStore
follow good JS class-naming standards?Dependents
GODRIVER-2268
Types of changes