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
Support async parser for embedded languages #13211
Conversation
src/language-js/embed.js
Outdated
|
||
function embed(path, print, textToDoc, options, language) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the logic don't need separate, and check language twice.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take your time, no rush. There is no async parser in the world yet.
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.
I agree that this would be a better API.
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.
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 |
I get the tokens in |
@fisker |
We also have |
tests/format/misc/plugins/embed-async-parser/with-aync-parser-code-block.md
Outdated
Show resolved
Hide resolved
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.
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 <lionkay@gmail.com>
Description
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨