Tolerant parsing: continue parsing when a Glimmer syntax is invalid#1666
Tolerant parsing: continue parsing when a Glimmer syntax is invalid#1666BlueCutOfficial wants to merge 3 commits intoglimmerjs:mainfrom
Conversation
I started to work on the Error node thing. I hope I can post one more commit tomorrow, and you'll tell me if I am doing this right or wrong. Thanks for the first answer and recordings 👍 |
f0076f4 to
9fc1fd3
Compare
|
yea, for partials, that's that a very nice output! |
9fc1fd3 to
7dd1104
Compare
|
@NullVoxPopuli I moved a bit forward on my locale machine, and I would like to have your opinion on something. If I have this piece of code: Parsing t results to the following structure ⬇️{
"attributes": [],
"blockParams": [],
"children": [],
"comments": [],
"modifiers": [
{
"hash": {
"pairs": [],
"type": "Hash"
},
"params": [],
"path": {
"head": {
"name": "mymodifier",
"original": "mymodifier",
"type": "VarHead"
},
"original": "mymodifier",
"tail": [],
"type": "PathExpression"
},
"type": "ElementModifierStatement"
}
],
"params": [],
"path": {
"head": {
"name": "div",
"original": "div",
"type": "VarHead"
},
"original": "div",
"tail": [],
"type": "PathExpression"
},
"selfClosing": false,
"tag": "div",
"type": "ElementNode"
}Now if I have something invalid: Where do you think the error node should go in the structure? Would it belong to 1. the list of modifiers, or 2. a list |
|
Hi there -- I'm thinking this PR would be a first step for prettier to support some handlebars variants. Ideally, I would love if when Glimmer fails to parse the AST of a node, it can expose enough information that the the rest of the document can be parsed and formatted. For example if There are currently a couple prettier issues with handlebars templates, so making the parser more tolerant would support those cases. The ones I am aware of are: prettier/prettier#14834 |
|
aye, we have some of that work happening over here: #1690 which has lead to vastly improved error reporting 🎉 |


This PR is far from ready, it simply aims at starting a discussion.
Context
When using
ember-template-lint, any syntax error found throws aGlimmerSyntaxErrorand makes the result of the lint process invalid. On a project I've been working on with @mansona, we would have needed some sort of "tolerant mode", a way to be notified about errors without blocking the linter.The current state of this PR is just a start, and aims at gathering feedbacks about the direction it should take:
PartialStatementas an example and doesn't throw when a Handlebars partial is found, and the resulting AST template simply doesn't contain the node.Parserseemed cleaner and less intrusive to me than trying to implement it as parse function's argument.