Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10370/ |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Thank you for working on this proposal! I think that it could help having better discussions around the pipeline proposal.
cc @rbuckton (proposal champion) could you take a quick look at the tests?
|
|
||
| case tt.question: | ||
| node = this.startNode(); | ||
| this.raise(node.start, "Partial Application syntax is not allowed"); |
There was a problem hiding this comment.
What are these lines needed for?
There was a problem hiding this comment.
I wanted to be able to throw a message whenever the user is using an invalid syntax.
I added a boolean allowPlaceholder to parseExprListItem and parseCallExpressionArguments and thought, I could set it to false whenever we do not want to allow the usage of ?.
Maybe I could throw the error message with another conditional here:
} else if (this.match(tt.question)) {
if (!allowPlaceholder){
const node = this.startNode();
this.raise(node.start, "Partial Application syntax is not allowed");
}
this.expectPlugin("partialApplication");
const node = this.startNode();
this.next();
elt = this.finishNode(node, "Partial");
}There was a problem hiding this comment.
Also another solution could be to let Babel throw its own errors.
There was a problem hiding this comment.
The default error would be unexpected ?. it's ok either way.
There was a problem hiding this comment.
I like the allowPlaceholder idea from @byara , it can evolve into something more specific and make the users aware of when a partial application is allowed and when it's not, taking examples from https://github.com/tc39/proposal-partial-application#syntax we can tell the user we can point the user on the right direction instead of having him figure out why he's seeing an unexpected ? error.
packages/babel-parser/ast/spec.md
Outdated
| ## Super | ||
|
|
||
| ```js | ||
| interface PartialExpression <: Node { |
There was a problem hiding this comment.
Maybe we could call it ArgumentPlaceholder?
There was a problem hiding this comment.
Sure, I was just trying to follow the Grammar section of the proposal: Grammar. But I also think, ArgumentPlaceholder shows the purpose better.
| } | ||
| } | ||
|
|
||
| export function Partial() { |
There was a problem hiding this comment.
This name doesn't match with the name defined in the parser. Also, could you add a generator test?
There was a problem hiding this comment.
Sure, I'll add tests for the generator.
Do you mean in: packages/babel-parser/src/types.js
I see that I made a mistake there. I'll fix it 👍
I named it PartialExpression, thinking we can take it as an expression but remembered that the proposal does not consider this to be an expression.
There was a problem hiding this comment.
Additionally, I suppose, I can move this function to src/generators/types.js? Because we are not considering Partial (or if we call it ArgumentPlaceholder) to be an expression.
There was a problem hiding this comment.
Yeah good idea (I still prefer ArgumentPlaceholder)
|
👍
All the files inside |
removed the alias
removed my changes from the I'll try to add more test cases for the parser and generator. |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
removed my changes from the generated folder.
Sorry if I wasn't clear; I meant that it is correct to have those auto-generated files.
| visitor: ["argument"], | ||
| fields: { | ||
| argument: { | ||
| validate: assertNodeType("ArgumentPlaceholder"), |
There was a problem hiding this comment.
This would mean that the AST is something like this:
{
"type": "ArgumentPlaceholder",
"argument": {
"type": "ArgumentPlaceholder",
// ...
}
}It should only be this:
defineType("ArgumentPlaceholder", {});| if (refTrailingCommaPos && this.match(tt.comma)) { | ||
| refTrailingCommaPos.start = this.state.start; | ||
| } | ||
| } else if (allowPlaceholder && this.match(tt.question)) { |
There was a problem hiding this comment.
Wdyt about this logic, to have better errors?
} else if (this.match(tt.question)) {
this.expectPlugin("partialApplication");
if (allowPlaceholder) {
this.raise(this.state.start, "Unexpected argument placeholder");
}
// ...There was a problem hiding this comment.
I like this! It has a clear message and does not confuse the user. The user will understand that they should not use ArgumentPlaceholder there. I'll apply it in my next push.
P.S. I should apply the negated one right?
if (!allowPlaceholder) {
this.raise(this.state.start, "Unexpected argument placeholder");
}
packages/babel-parser/ast/spec.md
Outdated
| - [ForStatement](#forstatement) | ||
| - [ForInStatement](#forinstatement) | ||
| - [ForOfStatement](#forofstatement) | ||
| - [ForOfStatement](#forofstatement) |
There was a problem hiding this comment.
Are these indent changes auto-generated? 🤔
There was a problem hiding this comment.
Yeah, I didn't change anything about the list, I just added my change in spec and the list was generated for me 🤔
There was a problem hiding this comment.
I don't think this file is autogenerated, maybe it was one of your ide extensions, or formatter?
Can you revert this line and the one above in Changes?
There was a problem hiding this comment.
You are right. Apparently, Markdown All in One was doing auto formatting.
| classMethodOrDeclareMethodCommon, | ||
| } from "./es2015"; | ||
|
|
||
| defineType("ArgumentPlaceholder", {}); |
There was a problem hiding this comment.
We should also update the CallExpression definition to accept placeholder arguments
There was a problem hiding this comment.
@nicolo-ribaudo You mean in /packages/babel-types/src/definitions/core.js I have to add another assert node type like this:
defineType("CallExpression", {
visitor: ["callee", "arguments", "typeParameters", "typeArguments"],
builder: ["callee", "arguments"],
aliases: ["Expression"],
fields: {
callee: {
validate: assertNodeType("Expression"),
},
arguments: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType(
"Expression",
"SpreadElement",
"JSXNamespacedName",
"ArgumentPlaceholder",
),
),
),
},
...
| { | ||
| "name": "@babel/plugin-syntax-partial-application", | ||
| "version": "7.2.0", | ||
| "description": "Allow parsing of optional properties", |
There was a problem hiding this comment.
This description needs to be updated
|
|
|
Partial application in tagged templates was pretty much rejected in a previous TC39 meeting, so I plan to remove that from the proposal for the time being. |
Do you mean that |
Right now, we can parse |
|
I think that that part is only disallowing the old proposed |
I knew I got it wrong! Then I guess everything is alright! |
|
Lets just wait for anather review so that this PR can be merged. Can you rebase it in the meantime? |
Sure! I'll do that 👍 |
danez
left a comment
There was a problem hiding this comment.
Looks good to me, I only added some comments about some nits in the markdown file.
Thank you
packages/babel-parser/ast/spec.md
Outdated
| } | ||
| ``` | ||
|
|
||
| ## ArgumentPlaceholder |
packages/babel-parser/ast/spec.md
Outdated
| - [LogicalExpression](#logicalexpression) | ||
| - [LogicalOperator](#logicaloperator) | ||
| - [SpreadElement](#spreadelement) | ||
| - [ArgumentPlaceholder](#argumentplaceholder) |
There was a problem hiding this comment.
should also be intended one more level.
packages/babel-parser/ast/spec.md
Outdated
| - [ForStatement](#forstatement) | ||
| - [ForInStatement](#forinstatement) | ||
| - [ForOfStatement](#forofstatement) | ||
| - [ForOfStatement](#forofstatement) |
There was a problem hiding this comment.
I don't think this file is autogenerated, maybe it was one of your ide extensions, or formatter?
Can you revert this line and the one above in Changes?
packages/babel-parser/ast/spec.md
Outdated
|
|
||
| Any expression node. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern. | ||
|
|
||
|
|
|
@byara Thank you! We will merge this PR when we decide to release v7.4.0. In the meantime, could you squash it and rebase the other PR on top of this one? |
|
I'm merging this locally since it has some conflicts |
* add partial application syntax and some tests * remove unnecessary error message and hasPartial function from parseNewArguments * add types for PartialExpression * Update the tests * rename PartialExpression to Partial * move Partial from expressions to types and rename to ArgumentPlaceholder * add tests for ArgumentPlaceholder in babel-generator * rename Partial to ArgumentPlaceholder * update the tests * remove alias from the type and undo changes in generated folder * adds a nice error message * better definition for the type * auto-generated files * update the conditional for allowPlaceholder message and tests * update CallExpression definition to accept ArgumentPlaceholder * change description * clean up * indent ArgumentPlaceholder entry and revert unwanted changes
parseExprListItemand added a new condition that checks fortt.commaand anotherbooleancalledallowPlaceholder. Then I check for the plugin and add the nodePartialallowPlaceholderinparseCallExpressionArgumentsandparseExprListItemto able to check if using?is allowed or not, so I can throw and error.