Skip to content

Make Babel import JSX pragma plugin aware of wp.element.createElement#13809

Merged
gziolo merged 6 commits intomasterfrom
update/babel-jsx-pragma-global
Feb 22, 2019
Merged

Make Babel import JSX pragma plugin aware of wp.element.createElement#13809
gziolo merged 6 commits intomasterfrom
update/babel-jsx-pragma-global

Conversation

@gziolo
Copy link
Copy Markdown
Member

@gziolo gziolo commented Feb 11, 2019

Description

As suggested by @aduth in #13540 (comment):

Would it make sense to do as its own separate pull request as an enhancement to the Babel plugin?

This PR is opened to make @wordpress/babel-plugin-import-jsx-pragma Babel plugin more flexible. In particular, it adds new behavior where it does nothing if the scope variable is already defined when using custom options.

Implementation is going to be based on the suggestions from @nerrad and @aduth:

the plugin docs are here (which you may already know, just linking in case you didn't).

Something I picked up from #12828 is the concept of context scope, on which all known variables are enumerated.

https://github.com/WordPress/gutenberg/pull/12828/files#diff-86d15238abb96bf543d1fd070227274eR18

Haven't looked deep enough yet to know whether this is exposed for the top-level of a file, but it would certainly help simplify things.

It solves the issue raised by @youknowriad:

If you don't use externals and you rely on const { createElement } = wp.element; this pull request will increase your bundle size by bundling @wordpress/element and will also create an ambiguity as you'd have two createElement variables on these files.

TODO

  • Add an entry to the changelog, breaking?
  • Update README file to include the note about the variable in the scope

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Tool] Babel plugin import JSX pragma /packages/babel-plugin-import-jsx-pragma [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants