parse5 icon indicating copy to clipboard operation
parse5 copied to clipboard

Consider exporting `InsertionMode` enum

Open ICodeMyOwnLife opened this issue 3 years ago • 4 comments

When creating a custom parser we need to check the insertionMode field against a value. Without the InsertionMode enum exported we have to use a magic number or redefine another enum within our codebase.

Screen Shot 2022-05-06 at 11 06 13 AM

Is there any reason preventing us from exporting the enum?

ICodeMyOwnLife avatar May 06 '22 04:05 ICodeMyOwnLife

InsertionMode is actually exported: https://github.com/inikulin/parse5/blob/master/packages/parse5/lib/index.ts

We mark it as internal, to avoid clutter in the documentation. But there is nothing stopping you from importing it.

fb55 avatar May 06 '22 07:05 fb55

Hey @fb55 I could miss something but InsertionMode was not exported inside parser/index.ts and I couldn't find anywhere that indirectly exports the enum.

ICodeMyOwnLife avatar May 09 '22 03:05 ICodeMyOwnLife

I was thinking of tokenizer modes – sorry about the confusion. I'm not sure how useful exporting insertion modes would be, as the parser is pretty hard to extend in the current form (_processToken is only called when re-processing tokens).

fb55 avatar May 09 '22 06:05 fb55

The authors of single-spa-layout extended Parser in their project https://github.com/single-spa/single-spa-layout/blob/main/src/server/CustomParser.js. I'm rewriting that piece of code into TypeScript (after upgrading the parse5 dependency to v7) for a project in my company and that's when I encountered InsertionMode enum. I think we could export the enum inside its file but not in the package index. The enum itself was marked as internal so that people use it at their own risk.

ICodeMyOwnLife avatar May 09 '22 08:05 ICodeMyOwnLife