Skip to content
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

feat(parse5): change parser/tokenizer methods to be protected #996

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

43081j
Copy link
Collaborator

@43081j 43081j commented Jul 28, 2023

Some projects in the wild depend on extending Parser and Tokenizer by overriding certain methods and using internals we don't publish on our public API.

This just moves all the private members to be protected so those projects can upgrade to 7.x.

Not everything should be protected but it seems our current class members all fit the criteria.

Fixes #992

i think this should be fine but let me know your thoughts @fb55

Some projects in the wild depend on extending `Parser` and `Tokenizer`
by overriding certain methods and using internals we don't publish on
our public API.

This just moves all the private members to be protected so those
projects can upgrade to 7.x.

Not everything should be protected but it seems our current class
members all fit the criteria.
@43081j
Copy link
Collaborator Author

43081j commented Aug 8, 2023

@fb55 any chance you can help with getting this over the line and releasing it?

it'll unblock some work in salesforce and google im trying to sort out

@wooorm
Copy link
Collaborator

wooorm commented Aug 9, 2023

This just moves all the private members to be protected so those projects can upgrade to 7.x.

I’d personally prefer to drop the privates. I already need to include ±100 ts-expect-errors because everything’s private on the classes, while it actually works at runtime.
Would that be acceptable?

@43081j
Copy link
Collaborator Author

43081j commented Aug 9, 2023

@wooorm do you mean you're calling those private (now protected in this branch) methods from outside?

i.e. parser._somePrivateMethod()

as opposed to calling it within a subclass (this._somePrivateMethod())

if thats the case, it suggests these are public methods really, yeah. maybe you could help with an example of why you need to call those methods publicly

@wooorm
Copy link
Collaborator

wooorm commented Aug 9, 2023

See https://github.com/syntax-tree/hast-util-raw.
It’s a complex project that tightly integrates with how p5 works.
It uses the parser to pass both nodes through and strings of HTML, while keeping positional info and other data on objects around.
This is a particular problem that arises with markdown as you can both have nice nodes, and strings of HTML inside/around them.

@43081j
Copy link
Collaborator Author

43081j commented Aug 9, 2023

interesting!

i wonder if it'd make more sense that you implement that logic as a custom parser? you could inherit Parser to consume your custom data and call the exact same methods but from within your equivalent parse method.

something like that.

but ofc thats a big job so its unlikely even if you agree, it'd get done any time soon i think. so im not sure... we can make them public so you don't need to refactor, or we can keep them protected and aim to one day rework your code

@43081j
Copy link
Collaborator Author

43081j commented Sep 17, 2023

@fb55 can you help me decide what to do here?

i don't want this to go stale as i have third party PRs waiting on it

looks like we need to make them protected or public, i don't mind which. public will help @wooorm out

@fb55
Copy link
Collaborator

fb55 commented Sep 19, 2023

My only holdback against public is that that would make the docs harder to consume, but we could fix that using @internal annotations. Besides that, feel free to go ahead with this change.

@43081j
Copy link
Collaborator Author

43081j commented Sep 19, 2023

@wooorm are you ok if we go ahead with protected for now and do the larger public change later? since your code isn't blocked by it at least

i feel like there's probably a cleaner solution than just making everything public for you too, e.g. exposing more helpful public APIs you can use

@wooorm
Copy link
Collaborator

wooorm commented Sep 19, 2023

I think it doesn’t break my code, indeed. So indeed, this does not affect me, and that’s okay!

@43081j 43081j merged commit 802c751 into inikulin:master Sep 19, 2023
8 checks passed
@43081j 43081j deleted the protective branch September 19, 2023 10:30
@43081j
Copy link
Collaborator Author

43081j commented Sep 19, 2023

@fb55 not sure how you've been publishing releases, so would you mind getting one published some day? no rush. or can let me know what process you've been following and i'll do the same

@divmain
Copy link

divmain commented Oct 10, 2023

I went to open an issue/PR asking for exactly this and discovered the exact change I was hoping for had just recently been merged. Kudos and thanks!

@43081j
Copy link
Collaborator Author

43081j commented Oct 10, 2023

@divmain thats because i also had a branch lying around for updating LWC's parse5! 😂

i still have some other changes this will unblock in lwc though, so ill open a pr just for those

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate some or most methods of Tokenizer and Parser to protected
4 participants