Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Add support for <template> tags #1

Merged
merged 6 commits into from Jan 26, 2019
Merged

Add support for <template> tags #1

merged 6 commits into from Jan 26, 2019

Conversation

jarrodldavis
Copy link
Contributor

parse5 seems to handle <template> tags differently from other tags by wrapping child nodes in a root type node, which causes purgecss-from-html to skip children of template elements altogether. Adding support for <template> nodes supports Single File Components, as used by Vue.js and other frameworks.

Here's what I did to support them:

  • Set Jest's testEnvironment configuration to node to avoid errors with JSDOM
  • Organize the existing tests into a sub-group/suite for normal HTML documents
  • Add fixtures and tests for a simple Single File Component similar to the existing test HTML document
  • Implement the fix by gathering selectors from root type nodes and adding to the selectors return array

Please let me know if you want the testEnvironment extracted into a separate PR, or if I should update Jest to a newer version since that error has been fixed.

Set the Jest test environment to `node` to avoid a JSDom error.
Add failing tests for extracting selectors from HTML tags under
`<template>` tags.
Organize the existing tests for normal HTML documents into a sub-group.
If a node type is `root`, gather selectors from children.
Add to the existing `selectors` return array when gathering selectors
from a `root` type node instead of immediately returning.
Actually use the spread operator when gathering selectors from `root`
type nodes.
@Ffloriel
Copy link
Member

Thanks a lot! I missed the notification, sorry about that.
This is a nice addition, especially for vuejs, web components.

@Ffloriel Ffloriel merged commit b50cfeb into FullHuman:master Jan 26, 2019
@jarrodldavis jarrodldavis deleted the bugfix/template-tags branch January 26, 2019 14:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants