-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Vague idea: add support for stack
#16
Comments
I'm open to the idea. Previously the concern was how verbose this could get in logs. |
These concerns seem to be more about programmer errors in JavaScript. Plugins being configured wrong, or so. I think those errors should be thrown sync, not in a transformer, they don’t relate to a file or tree. Here I am thinking more about lint messages. Someone forgot an |
Ahhh, thanks for the clarification on the intent and planned use-case. ["children", 1, "children", 0] or would it include the raw nodes? [
{
type: 'root',
...
},
{
type: 'element',
...,
},
...
} |
|
I like the idea, but since In order to get this stack, the VFile message needs to either:
I suggest a separate utility functions instead: // Convenient for a single node.
/**
* Get the stack of a node.
*
* @param {Node} node
* The node whose position to lookup in the AST.
* @param {Node} ancestor
* The ancestor node to traverse to find the given node in. Typically this is a root node.
* @returns {Node[] | undefined}
* The node’s ancestry within the given ancestor.
*/
function getNodeStack(node: Node, ancestor: Node): Node[] | undefined;
// This way we only need to traverse the ancestor once for multiple nodes.
/**
* Get the stacks of multiple nodes.
*
* @param {Node[]} node
* The nodes whose position to lookup in the AST.
* @param {Node} ancestor
* The ancestor node to traverse to find the given nodes in. Typically this is a root node.
* @returns {Map<Node>}
* A map that maps the node to its ancestry within the given ancestor.
*/
function getNodeStacks(node: Node, ancestor: Node): Map<Node>;
// For presentation
/**
* Convert a node stack to a string representation.
*
* @param {Node[]} nodes
* The nodes to represent in the stack.
* @param {(node: Node) => string} [printer]
* Represent a node as a string. By default it will print the Node’s type and position.
* @returns {string}
* A string that looks like a JavaScript stack trace.
*/
function printNodeStack(nodes: Node[], printer?: (node: Node) => string): string; This way The downside is users need to manually pull in this library to use it. It |
Why? What is a stack, other than showing a trace of where something happened in JS, and who called who? Also That being said, different engines might overwrite it, or not show it, as they might not accept tools setting it.
Yeah, I’m thinking allowing a list of nodes, where currently a point/position/node is accepted. One more benefit for all this is that some nodes (perhaps the final
E.g., say Adjacent to this issue: code frames (https://babeljs.io/docs/en/babel-code-frame). I would really like to see that. But it’s tough to get right (when a reporter runs, the files have likely already been overwritten, and the |
This commit replaces a potentially incorrect `position` (`Position`-like value) field with a correct `place` (`Position | Point`) field. Then it adds support for a single options object as a parameter, which can contain the current parameters as fields, but also adds support for a `cause` error and an `ancestors` node stack. Closes GH-15. Closes GH-16. Closes GH-17. Closes GH-19. Reviewed-by: Remco Haszing <remcohaszing@gmail.com>
Initial checklist
Problem
stack
field on errors, which we we use when an error is passed (not super common I think)vfile
, they often are used together.Solution
We could support stacks of nodes. E.g., hast/xast:
mdast:
Alternatives
?
The text was updated successfully, but these errors were encountered: