Update babel-generator's README #5517

This commit is contained in:
Sven SAULEAU 2017-04-08 10:14:56 +02:00
parent 2cb4d08d19
commit e2c2d7d742
No known key found for this signature in database
GPG Key ID: 7C3212582FBA1BA2

View File

@ -54,12 +54,7 @@ sourceFileName | string | | The filename for the sourc
In most cases, Babel does a 1:1 transformation of input-file to output-file. However,
you may be dealing with AST constructed from multiple sources - JS files, templates, etc.
If this is the case, and you want the sourcemaps to reflect the correct sources, you'll need
to make some changes to your code.
First, each node with a `loc` property (which indicates that node's original placement in the
source document) must also include a `loc.filename` property, set to the source filename.
Second, you should pass an object to `generate` as the `code` parameter. Keys
to pass an object to `generate` as the `code` parameter. Keys
should be the source filenames, and values should be the source content.
Here's an example of what that might look like:
@ -70,14 +65,14 @@ import generate from 'babel-generator';
const a = 'var a = 1;';
const b = 'var b = 2;';
const astA = parse(a, { filename: 'a.js' });
const astB = parse(b, { filename: 'b.js' });
const astA = parse(a, { sourceFilename: 'a.js' });
const astB = parse(b, { sourceFilename: 'b.js' });
const ast = {
type: 'Program',
body: [].concat(astA.body, ast2.body)
body: [].concat(astA.program.body, astB.program.body)
};
const { code, map } = generate(ast, { /* options */ }, {
const { code, map } = generate(ast, { sourceMaps: true }, {
'a.js': a,
'b.js': b
});