Support async parser for embedded languages#13211
Conversation
| return getLanguage(path); | ||
| } | ||
|
|
||
| function embed(path, print, textToDoc, options, language) { |
There was a problem hiding this comment.
What if we ask embed to return print function, so we don't need add an extra detectEmbeddedLanguage?
function embed() {
const language = ...;
return () => formatMarkdown(...)
}There was a problem hiding this comment.
And the logic don't need separate, and check language twice.
There was a problem hiding this comment.
Changing embed's return type from
Doc | undefined | Promise<Doc | undefined>to
Doc | undefined | () => Promise<Doc | undefined>is an interesting idea, but I've run out of time for now. :(
There was a problem hiding this comment.
Take your time, no rush. There is no async parser in the world yet.
There was a problem hiding this comment.
I agree that this would be a better API.
|
I have one more concern, if this get merged, the
//cc @Shinigami92 |
|
I can't see where it calls parse in print |
|
I guess that should be moved to embed then. Isn't this what embed is for? |
|
As mentioned reason here, thorn0#1 (comment), this plugin has to move it to |
|
Any comment? |
Would make things much harder for me (I wrote the whole plugin in an iterative way instead of a AST walker because pug works much better and more performant this way) |
|
As I understand, you don't use In that case, you can also do print (async stuff) in parse... Some other plugins do this.. |
|
@Shinigami92 Making |
|
@fisker |
|
We also have |
|
Will you try this? |
|
No, I really doubt it'll do a better job than |
|
How about moving |
|
If we are going to do this, I prefer getVistorKeys(node) {}Before we implement the real vistor keys, we can just simply use const ignored = new Set(['tokens'])
getVistorKeys(node) {
return Object.keys(node).filter(key => !ignored.has(key))
} |
|
That doesn't look performance-friendly. It will need to be called for each node: a function call, creating an array of keys, and iterating it. A simple |
When traverse ast, normally you need "get keys/values", "check keys", " iterating it", aren't they the same? prettier/src/main/massage-ast.js Lines 19 to 23 in 21b4045 prettier/src/main/multiparser.js Lines 77 to 88 in 21b4045 |
|
Yep. Somehow I misread what you're proposing. It might be not that bad. |
|
But why do you think a simple |
|
Not really, just every estree traver I used use |
|
|
|
Probably. Also maybe it's important to visit keys in a specific order. |
|
Many parsers come with traverse function, eg https://github.com/graphql/graphql-js/blob/67aefd9c1daefceacf937363c2da9e1117e550d9/src/language/visitor.ts#L177, if we remove AstPath someday, we may want use this function or vistorKeys. |
|
How are we going to know where we are at the tree without the path? |
|
Link to that I ask meriyah to supply such ithing meriyah/meriyah#180 |
I found it few hours ago , was working on it, but late here. Caused by #13208. I changed cli test to not print color by default, but not working. |
|
Ah, okay. I'm glad that it's not something local with my env. |
Eslint use |
Not sure. Maybe what I occurred in #13201 is related, but I forgot what the possible bug is, this "Revert plugin change to avoid possible bug" commit fixed test. |
Tracked it down: #13235 |
Co-authored-by: fisker Cheung <[email protected]>
Description
Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨