Update Readme + change default transform

Reviewed By: cpojer

Differential Revision: D6401596

fbshipit-source-id: 8928abb825933edd84c508a4f04f50c748725722
This commit is contained in:
Rafael Oleza 2017-11-23 03:04:56 -08:00 committed by Facebook Github Bot
parent 7b5ae96479
commit 70dadc63f9
2 changed files with 15 additions and 7 deletions

View File

@ -137,14 +137,16 @@ The JavaScript transformer (`transformModulePath`) is the place where JS code wi
## Method `transform(module)`
Mandatory method that will transform code. The object received has information about the module being transformed (e.g its path, code...) and the returned object has to contain a `code` key that is the result of the transform. The default transformer shipped is a pretty good place to start:
Mandatory method that will transform code. The object received has information about the module being transformed (e.g its path, code...) and the returned object has to contain an `ast` key that is the AST representation of the transformed code. The default shipped transformer does the bare minimum amount of work by just parsing the code to AST:
```js
module.exports.transform = file => {
return {
code: file.src,
};
});
const babylon = require('babylon');
module.exports.transform = (file: {filename: string, src: string}) => {
const ast = babylon.parse(code, {sourceType: 'module'});
return {ast};
};
```
If you would like to plug-in babel, you can simply do that by passing the code to it:

View File

@ -11,4 +11,10 @@
*/
'use strict';
module.exports.transform = (file: {src: string}) => ({code: file.src});
const babylon = require('babylon');
module.exports.transform = (file: {filename: string, src: string}) => {
const ast = babylon.parse(file.src, {sourceType: 'module'});
return {ast};
};