babel-generator
Advanced tools
Comparing version 6.6.5 to 6.7.0
@@ -27,2 +27,12 @@ /* eslint max-len: 0 */ | ||
function Identifier(node) { | ||
// FIXME: We hang variance off Identifer to support Flow's def-site variance. | ||
// This is a terrible hack, but changing type annotations to use a new, | ||
// dedicated node would be a breaking change. This should be cleaned up in | ||
// the next major. | ||
if (node.variance === "plus") { | ||
this.push("+"); | ||
} else if (node.variance === "minus") { | ||
this.push("-"); | ||
} | ||
this.push(node.name); | ||
@@ -29,0 +39,0 @@ } |
@@ -79,3 +79,3 @@ "use strict"; | ||
var style = " "; | ||
if (code) { | ||
if (code && typeof code === "string") { | ||
var _indent = _detectIndent2["default"](code).indent; | ||
@@ -82,0 +82,0 @@ if (_indent && _indent !== " ") style = _indent; |
@@ -5,2 +5,4 @@ "use strict"; | ||
var _Object$keys = require("babel-runtime/core-js/object/keys")["default"]; | ||
var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"]; | ||
@@ -26,2 +28,6 @@ | ||
function SourceMap(position, opts, code) { | ||
// istanbul ignore next | ||
var _this = this; | ||
_classCallCheck(this, SourceMap); | ||
@@ -39,3 +45,9 @@ | ||
this.map.setSourceContent(opts.sourceFileName, code); | ||
if (typeof code === "string") { | ||
this.map.setSourceContent(opts.sourceFileName, code); | ||
} else if (typeof code === "object") { | ||
_Object$keys(code).forEach(function (sourceFileName) { | ||
_this.map.setSourceContent(sourceFileName, code[sourceFileName]); | ||
}); | ||
} | ||
} else { | ||
@@ -90,3 +102,3 @@ this.map = null; | ||
this.last = { | ||
source: this.opts.sourceFileName, | ||
source: loc.filename || this.opts.sourceFileName, | ||
generated: generated, | ||
@@ -93,0 +105,0 @@ original: original |
{ | ||
"name": "babel-generator", | ||
"version": "6.6.5", | ||
"version": "6.7.0", | ||
"description": "Turns an AST into code.", | ||
@@ -16,3 +16,3 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"babel-runtime": "^5.0.0", | ||
"babel-types": "^6.6.5", | ||
"babel-types": "^6.7.0", | ||
"detect-indent": "^3.0.1", | ||
@@ -27,4 +27,4 @@ "is-integer": "^1.0.4", | ||
"babel-helper-fixtures": "^6.6.5", | ||
"babylon": "^6.6.5" | ||
"babylon": "^6.7.0" | ||
} | ||
} |
@@ -47,2 +47,39 @@ # babel-generator | ||
sourceRoot | string | | A root for all relative URLs in the source map | ||
sourceFileName | string | | The filename for the source code (i.e. the code in the `code` argument) | ||
sourceFileName | 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. | ||
## AST from Multiple Sources | ||
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 | ||
should be the source filenames, and values should be the source content. | ||
Here's an example of what that might look like: | ||
```js | ||
import {parse} from 'babylon'; | ||
import traverse from "babel-traverse"; | ||
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 ast = { | ||
type: 'Program', | ||
body: [].concat(astA.body, ast2.body) | ||
}; | ||
const { code, map } = generate(ast, { /* options */ }, { | ||
'a.js': a, | ||
'b.js': b | ||
}); | ||
// Sourcemap will point to both a.js and b.js where appropriate. | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87099
2632
85
Updatedbabel-types@^6.7.0