Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recent changes in JSONata 1.2.x introduced the use of ES6 generators, but support for these is not universal, so an ES5-compatible version of JSONata is desirable.
babel-cli
as a development dependency inpackage.json
.babel-preset-env
as a development dependency inpackage.json
- this provides a basic preset configuration for Babel, named "env"..babelrc
to configurebabel
for this task. Note the use of the "env" preset, provided above.babel-runtime
as a development dependency inpackage.json
. This provides the transformation which turns ES6 generators into simple ES5 code.babel-plugin-transform-runtime
as a development dependency inpackage.json
. When ES6 code which makes use of generators is compiled to ES5, ordinarily the output ES5 code makes use of a global variableregeneratorRuntime
to work... and just assumes that this global variable exists somehow. However, using this plugin means that the output ES5 code instead explicitly callsvar _regenerator = require('babel-runtime/regenerator');
and uses_regenerator
to accomplish the same result..babelrc
..babelrc
to compiles./jsonata.js
(ES6) to./jsonata-es5.js
(ES5).Unfortunately this leaves us in a situation where
jsonata-es5.js
has an external dependency onbabel-runtime/regenerator
- previously, JSONata had no external dependencies, and we want to keep it that way. So a few more steps were needed:browserify
as a development dependency inpackage.json
.jsonata-es5.js
as input and browserifies it in place. Note the use of the--standalone jsonata
flag, which makes it so that thejsonata
module is exposed as a global variable in the resulting UMD module.browserify
pulls in all needed modules, andjsonata
currently makes use ofBuffer
, we find thatbrowserify
pulls in a full browser implemention ofBuffer
along withieee754
andbase64
, which bloats the output. This is unnecessary, becauseBuffer
is only used whenjsonata
is running on Node.js. Usingglobal.Buffer
instead ofBuffer
prevents this. (I wasn't able to find abrowserify
flag to accomplish this.)And:
jsonata.js
tojsonata.min.js
. A new task "minify-es5" minifiesjsonata-es5.js
tojsonata-es5.min.js
.jsonata-es5.js
andjsonata-es5.min.js
have been added to.eslintignore
and.gitignore
.Possible future work:
jsonata.js
as a properly bundled UMD module as well?Buffer
hack and can bring JSONata back down to 0 external dependencies (at least in the ES6 case)?