Replies: 9 comments 16 replies
-
sorry it took a while to get to this. since you and i both converted the repo to typescript at the same time, i think a sensible thing to do would be to compare implementations roughly and adopt any improvements from mine into this fork. im happy to then discard the work i've done moving it to typescript, as long as we're both happy this one is ahead of it/better. i think it'd make sense to also convert all the mixins at some point into plugins instead. this would need discussion though and a rough spec of how it'd work (so the parser would call its plugins rather than mixins mutating the parser, etc). what'd be very useful from you is to document some kind of overview of what you've done here. it isn't only an esm/typescript port, you've also changed quite a lot of things. i'd like to understand those changes and the differences in this repo. i'd be happy to then collaborate on this fork and PR into it rather than parse5. if you're around on twitter it may be worth having a conversation over DM so we can compare thoughts etc. |
Beta Was this translation helpful? Give feedback.
-
typescript-eslint recommend config & strict compilationAll strict options in typescript enabled, along with the This means no more |
Beta Was this translation helpful? Give feedback.
-
tree adapters are now classesI reworked tree adapters to be classes which conform to an interface, rather than importing the module and hoping for the best. You can see the interface/types here. The default tree adapter here. Currently, your tree adapters don't implement the interface really. there's no way inside the default tree adapter file to get type checking on if we've implemented the tree adapter interface correctly. for that and other reasons it should be a single object exported which is strongly typed as the interface. |
Beta Was this translation helpful? Give feedback.
-
comments on your tree adapter interfaceI don't think the type map should be generic the way you've done it. we shouldn't be restricting tree adapters to ensure everything inherits their this also doesn't make the most sense with the the interface was specifically not generic before for these reasons.
it is up to mixins and tree adapters if they want to restrict it to elements.
updateNodeSourceCodeLocation(node: T['element'], endLocation: EndLocation & { endTag?: Location }): void;
updateNodeSourceCodeLocation(node: T['node'], endLocation: EndLocation): void; i used overloads to deal with this. a |
Beta Was this translation helpful? Give feedback.
-
comments on your default tree adapter / node interfacesIn my branch, i make heavy use of tagged unions. This makes it very easy to narrow types of node to the right type. with your current interfaces, it'll be a real pain for consumers to deal with the produced AST. lots of casting will be needed, which was a problem with parse5 already until i partially fixed it in the DT types. For example, using your code: declare const node: Node;
if (node.type === 'comment') {
// annoyingly still a `Node`, no use to me without a cast
} with my branch, typescript will infer that it is a i'd highly recommend we do this in this fork, as it is already a real pain in the existing parse5 types i've spent plenty of time trying to improve. you can see how it is done here. You should still have a For example: export function detachNode(node: NodeWithParent) {
if (node.parentNode) { parse5 checks if there's a parentNode because the parameter was always intended to be similar, appending children would ideally consume a |
Beta Was this translation helpful? Give feedback.
-
comments on locationsas mentioned in the other posts, the two call-sites are here and here. this is why I have an you can see here. strangely, your |
Beta Was this translation helpful? Give feedback.
-
mixin utilityThe mixin util types are fairly weak and not quite right, it would be good to strengthen them. Examples:
Also, if you use a You can see what i did here. With mine, i did have to specify the type of The ideal would be to strongly type the parameter as the same type as the return, but i think time is better spent throwing this whole idea of mixins away and building a plugins system instead. |
Beta Was this translation helpful? Give feedback.
-
open element stackits in the name: open element stack. we should change the type of its |
Beta Was this translation helpful? Give feedback.
-
mixins in generalAgain i think they should go away, but anyway.... I noticed in many places, you cast the mixins as Also, most of the methods the mixins override are meant to be protected. once we add visibility to methods, the mixins will (or should) fail to build. In my branch, i ended up making a whole bunch of methods public to work with this. Really, though, we should mixin over |
Beta Was this translation helpful? Give feedback.
-
Now that we have forked, what should happen?
Things I'd like to see:
Map
s andSet
s where appropriateincludes
,startsWith
Beta Was this translation helpful? Give feedback.
All reactions