Skip to content

Custom JSX Parser - #38

Merged
developit merged 48 commits into
masterfrom
custom-jsx-parser
Dec 20, 2018
Merged

developit merged 48 commits into
masterfrom
custom-jsx-parser

Conversation

@developit

Copy link
Copy Markdown
Owner

This PR replaces htm's DOM-based parsing with a custom parser implementing the complete JSX syntax.

The result is a fair bit smaller (~600b), produces higher-quality intermediary code, and likely consumes/retains a lot less memory since no objects are created.

/cc @jviide sorry for taking so long to get this PR'd!

Comment thread src/index.mjs Resolved
developit and others added 4 commits December 18, 2018 09:40
Prefix the key with a non-numeric character, as this seems to give a
speed-up on Chrome.
Use JSON.stringify for cache key generation
Comment thread test/index.test.mjs
});

test('auto-closing tag', () => {
expect(html`<a><//>`).toEqual({ tag: 'a', props: null, children: [] });

@dy dy Dec 18, 2018 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not related to the PR - but what was the motivation for double-slash closing tag? JSX introduces </> for the purpose of closing fragments, and tbh I had that expectation here too, like <${Component}></>. Are there some collisions?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The original reason was that it was easy to parse - end tag names were ignored in the HTML parser version and are ignored in the custom parser version too. Really you could give the tag any name, like <a></>.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does the new parser ignore end tags due to the same reason?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

just to save bytes. It doesn't validate the opening and closing tags match.

@developit
developit merged commit c190cf0 into master Dec 20, 2018
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.

3 participants