From e2c2d7d7423a8823dda60ab54e0881011be6baf1 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 8 Apr 2017 10:14:56 +0200 Subject: [PATCH] Update babel-generator's README #5517 --- packages/babel-generator/README.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/babel-generator/README.md b/packages/babel-generator/README.md index a337191353..ff215b753f 100644 --- a/packages/babel-generator/README.md +++ b/packages/babel-generator/README.md @@ -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 });