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

Fix(#182): correct types and type checks #183

Merged
merged 1 commit into from
Apr 6, 2022
Merged

Conversation

SukkaW
Copy link
Contributor

@SukkaW SukkaW commented Apr 6, 2022

The PR closes #182.
X-Ref: parcel-bundler/parcel#7906

PostHTML does supports node.content to be either a string or a string[] when stringify a PostHTML AST Tree into HTML, while PostHTML parser will only emit node.content as an array of string. So the new htmlnano module syntax (#128) just take it for granted that node.content will always be a string[].

However, some htmlnano modules (minifyJson and minifySvg) will transform node.content into a string instead of a string[], so when other modules (which expects node.content to be a string[]) process the new node.content later on, htmlnano will crash.

This PR fixes the issue by:

  • Make sure minifyJson, minifySvg, and other modules will always return string[].
  • node.content will always be cast into an array before passed into onContent.
  • The result from onContent will always be cast into an array.
  • Add additional type check when applying new syntax modules.

cc @maltsev @AndrewKvalheim @mischnic @arneke

@netlify
Copy link

netlify bot commented Apr 6, 2022

‼️ Deploy request for htmlnano rejected.

Name Link
🔨 Latest commit f992afd

@maltsev maltsev merged commit 4598130 into posthtml:master Apr 6, 2022
@maltsev
Copy link
Member

maltsev commented Apr 6, 2022

Thanks! I'll release a new version this evening.

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.

Crash with JSON-LD data
2 participants