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

Factor out Forgiving parser from template engine. #234

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

theengineear
Copy link
Collaborator

We want to experiment with an Unforgiving parser which our template engine can leverage. To enable better side-by-side comparison, we can factor out the current parser from our template engine and give it the same parse interface.

/** Internal implementation details for template engine. */
class TemplateEngine {
/** Forgiving HTML parser which leverages innerHTML. */
class Forgiving {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moving some things around to form a new conceptual boundary between our “parser” and our “dom manager”.

const onContent = TemplateEngine.#storeContentLookup.bind(null, lookups);
const onText = TemplateEngine.#storeTextLookup.bind(null, lookups);
const forgivingLanguage = language === TemplateEngine.#SVG ? Forgiving.svg : Forgiving.html;
const fragment = Forgiving.parse(strings, onBoolean, onDefined, onAttribute, onProperty, onContent, onText, forgivingLanguage);
Copy link
Collaborator Author

@theengineear theengineear Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t an interface we will ever make public. But — the idea is that it’s more like a visitor pattern. The parser just tells the integrator when something interesting happens and where it happened. This was one of the untangling changes we made for Unforgiving anyway, just back-porting it, really.

@theengineear theengineear force-pushed the factor-out-forgiving-parser branch from 8f73306 to 710bb86 Compare December 7, 2024 02:24
@theengineear
Copy link
Collaborator Author

FYI @klebba — Thanks for the motivation to improve our ability to do side-by-side comparison here in the future. Now that there is a one-line coupling between TemplateEngine and Forgiving, it makes it easier in the future to move Forgiving into like /test/forgiving.js which we can manually hook up as a comparison.

We want to experiment with an Unforgiving parser which our template
engine can leverage. To enable better side-by-side comparison, we can
factor out the current parser from our template engine and give it the
same `parse` interface.
@theengineear theengineear force-pushed the factor-out-forgiving-parser branch from 710bb86 to 90b81ab Compare December 7, 2024 02:28
@theengineear theengineear merged commit d7b3a48 into main Dec 7, 2024
1 check passed
@theengineear theengineear deleted the factor-out-forgiving-parser branch December 7, 2024 02:31
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.

1 participant