{"_id":"better-babel-generator","_rev":"338410","name":"better-babel-generator","description":"Turns an AST into code.","dist-tags":{"latest":"6.26.1"},"maintainers":[{"name":"yuche","email":""}],"time":{"modified":"2021-06-20T02:23:07.000Z","created":"2018-12-19T08:30:48.895Z","6.26.1":"2018-12-19T08:30:48.895Z"},"users":{},"author":{"name":"yuche","email":"i@yuche.me"},"repository":{"type":"git","url":"https://github.com/babel/babel/tree/master/packages/babel-generator"},"versions":{"6.26.1":{"name":"better-babel-generator","version":"6.26.1","description":"Turns an AST into code.","author":{"name":"yuche","email":"i@yuche.me"},"homepage":"https://babeljs.io/","license":"MIT","repository":{"type":"git","url":"https://github.com/babel/babel/tree/master/packages/babel-generator"},"main":"lib/index.js","dependencies":{"babel-messages":"^6.23.0","babel-runtime":"^6.26.0","babel-types":"^6.26.0","detect-indent":"^4.0.0","jsesc":"2","lodash":"^4.17.4","source-map":"^0.5.7","trim-right":"^1.0.1"},"devDependencies":{"babel-helper-fixtures":"^6.26.0","babylon":"^6.18.0"},"_id":"better-babel-generator@6.26.1","_npmVersion":"6.1.0","_nodeVersion":"10.3.0","_npmUser":{"name":"yuche","email":"i@yuche.me"},"dist":{"shasum":"7c26035f32d8d55d06dbc81b410378a6230a515e","size":18753,"noattachment":false,"key":"/better-babel-generator/-/better-babel-generator-6.26.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/better-babel-generator/download/better-babel-generator-6.26.1.tgz"},"maintainers":[{"name":"yuche","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/better-babel-generator_6.26.1_1545208248691_0.24225949583980455"},"_hasShrinkwrap":false,"publish_time":1545208248895,"_cnpm_publish_time":1545208248895}},"readme":"# babel-generator\n\n> Turns an AST into code.\n> Due to the Babel@6 version is not longer maintained, this package mainly fix two two things:\n> 1. JSX comments generation.\n> 2. Update `jsesc` dependency and apply `jsesc` option.\n\n## Install\n\n```sh\nnpm install --save-dev babel-generator\n```\n\n## Usage\n\n```js\nimport {parse} from 'babylon';\nimport generate from 'babel-generator';\n\nconst code = 'class Example {}';\nconst ast = parse(code);\n\nconst output = generate(ast, { /* options */ }, code);\n```\n\n## Options\n\nOptions for formatting output:\n\nname                   | type     | default         | description\n-----------------------|----------|-----------------|--------------------------------------------------------------------------\nauxiliaryCommentBefore | string   |                 | Optional string to add as a block comment at the start of the output file\nauxiliaryCommentAfter  | string   |                 | Optional string to add as a block comment at the end of the output file\nshouldPrintComment     | function | `opts.comments` | Function that takes a comment (as a string) and returns `true` if the comment should be included in the output.  By default, comments are included if `opts.comments` is `true` or if `opts.minifed` is `false` and the comment contains `@preserve` or `@license`\nretainLines            | boolean  | `false`         | Attempt to use the same line numbers in the output code as in the source code (helps preserve stack traces)\nretainFunctionParens   | boolean  | `false`         | Retain parens around function expressions (could be used to change engine parsing behavior)\ncomments               | boolean  | `true`          | Should comments be included in output\ncompact                | boolean or `'auto'` | `opts.minified` | Set to `true` to avoid adding whitespace for formatting\nminified               | boolean  | `false`         | Should the output be minified\nconcise                | boolean  | `false`         | Set to `true` to reduce whitespace (but not as much as `opts.compact`)\nquotes                 | `'single'` or `'double'` | autodetect based on `ast.tokens` | The type of quote to use in the output\nfilename               | string   |                 | Used in warning messages\nflowCommaSeparator     | boolean  | `false`         | Set to `true` to use commas instead of semicolons as Flow property separators\njsonCompatibleStrings  | boolean  | `false`         | Set to true to run `jsesc` with \"json\": true to print \"\\u00A9\" vs. \"©\";\n\nOptions for source maps:\n\nname                   | type     | default         | description\n-----------------------|----------|-----------------|--------------------------------------------------------------------------\nsourceMaps             | boolean  | `false`         | Enable generating source maps\nsourceMapTarget        | string   |                 | The filename of the generated code that the source map will be associated with\nsourceRoot             | string   |                 | A root for all relative URLs in the source map\nsourceFileName         | string   |                 | The filename for the source code (i.e. the code in the `code` argument).  This will only be used if `code` is a string.\n\n## AST from Multiple Sources\n\nIn most cases, Babel does a 1:1 transformation of input-file to output-file.  However,\nyou may be dealing with AST constructed from multiple sources - JS files, templates, etc.\nIf this is the case, and you want the sourcemaps to reflect the correct sources, you'll need\nto pass an object to `generate` as the `code` parameter.  Keys\nshould be the source filenames, and values should be the source content.\n\nHere's an example of what that might look like:\n\n```js\nimport {parse} from 'babylon';\nimport generate from 'babel-generator';\n\nconst a = 'var a = 1;';\nconst b = 'var b = 2;';\nconst astA = parse(a, { sourceFilename: 'a.js' });\nconst astB = parse(b, { sourceFilename: 'b.js' });\nconst ast = {\n  type: 'Program',\n  body: [].concat(astA.program.body, astB.program.body)\n};\n\nconst { code, map } = generate(ast, { sourceMaps: true }, {\n  'a.js': a,\n  'b.js': b\n});\n\n// Sourcemap will point to both a.js and b.js where appropriate.\n```\n","_attachments":{},"homepage":"https://babeljs.io/","license":"MIT"}