-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature: chalk package #7
Comments
The first question is, at what level should this package operate? My instinct is to try to make a single package that is agnostic to the precise text formatting of the error, i.e. the chalk package would work equally well with errors parsed from v8 syntax as it would with errors parsed from SpiderMonkey syntax. Otherwise I'll start to get a proliferation of packages like So how should I make the code reusable? My first idea was to make chalk could operate on ASTs, e.g. I think the I need to take another page out of babel's book and create APIs that permit plugins, where a plugin defines a set (or subset) of visitors. Babel has definitely seen their plugin system stretch to the breaking point and are currently working on explicit dependency management for plugins, but they're not done yet (that I know of) and their current system has gotten them very far indeed so I'm inclined to treat it as sound. |
On second though though maybe Babel isn't as much of an analog as I'm imagining. It's plugin system definitely is ast->ast, so their printing code is never mixed with anything else. Essentially they do a complete pass of the AST for plugins to do transformations, then do a single complete pass to print. I'm talking about doing a pass that mixes different kinds of printing visitors. I think I just need to start building and see what happens. |
I'm going to need some way of doing the chaining, e.g. |
A better name for |
The rock bottom simplest solution I could provide is to expand the definition of a visitor from |
I like that this solution gives you the complete set of visitors you are overriding, which could be useful when extending from visitors that are already themselves extended, something which I haven't created an API for yet. I think the class paradigm is pretty natural to describe this as it offers extension, super calling, and stored state. If I were to use the class paradigm then actually chalk would be a visitor mixin, which sounds great to me. |
OK so I have this built and can see it working -- a chalk visitor expressed in a way that is fundamentally agnostic to the underlying syntax. But after all that it's not clear to me if I want a chalk package. Maybe just having a way to build this easily is enough? It's essentially just a styling system, but is applying some default styles worth a whole package? And especially a package that seems like it's going to have a pretty ugly API? And chalk itself is a bit finnicky when it comes to exactly how you express certain things, so extending from a chalk printing just doesn't seem like a better idea than making your own. |
You can see what I have working in this comment. |
I'd like to have a
@stack-tools/chalk-tools
package that offers users the ability for format error syntax with chalk.This is for the most part straightforward thanks to the most recent work I've done (monorepo and visitor pattern). The goal is to provide syntax hightlighting for terminal environments with chalk, and also to put the AST and visitor systems through their first real test.
The text was updated successfully, but these errors were encountered: