Merge branch 'master' into development
This commit is contained in:
commit
dbf320f6f0
@ -13,6 +13,11 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.7.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Add back mistakenly removed `replaceWithSourceString` method.
|
||||
|
||||
## 5.7.0
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
@ -7,12 +7,6 @@
|
||||
|
|
||||
<strong><a href="#running-tests">Running tests</a></strong>
|
||||
|
|
||||
<strong><a href="#workflow">Workflow</a></strong>
|
||||
|
|
||||
<strong><a href="#dependencies">Dependencies</a></strong>
|
||||
|
|
||||
<strong><a href="#code-standards">Code Standards</a></strong>
|
||||
|
|
||||
<strong><a href="#internals">Internals</a></strong>
|
||||
</p>
|
||||
|
||||
@ -26,6 +20,8 @@ contributing, please read the
|
||||
|
||||
## Developing
|
||||
|
||||
**Note:** Versions `< 5.1.10` can't be built.
|
||||
|
||||
#### Setup
|
||||
|
||||
```sh
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"version": "5.7.0",
|
||||
"version": "5.7.1",
|
||||
"description": "A compiler for writing next generation JavaScript",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@ -42,7 +42,7 @@
|
||||
"babel-plugin-runtime": "^1.0.7",
|
||||
"babel-plugin-undeclared-variables-check": "^1.0.2",
|
||||
"babel-plugin-undefined-to-void": "^1.1.6",
|
||||
"babylon": "^5.6.23",
|
||||
"babylon": "^5.7.1",
|
||||
"bluebird": "^2.9.33",
|
||||
"chalk": "^1.0.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import codeFrame from "../../helpers/code-frame";
|
||||
import traverse from "../index";
|
||||
import NodePath from "./index";
|
||||
import parse from "../../helpers/parse";
|
||||
import * as t from "../../types";
|
||||
|
||||
/**
|
||||
@ -60,11 +63,31 @@ export function replaceWithMultiple(nodes: Array<Object>) {
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
* Parse a string as an expression and replace the current node with the result.
|
||||
*
|
||||
* NOTE: This is typically not a good idea to use. Building source strings when
|
||||
* transforming ASTs is an antipattern and SHOULD NOT be encouraged. Even if it's
|
||||
* easier to use, your transforms will be extremely brittle.
|
||||
*/
|
||||
|
||||
export function replaceWithSourceString(replacement) {
|
||||
throw new Error("TODO");
|
||||
this.resync();
|
||||
|
||||
try {
|
||||
replacement = `(${replacement})`;
|
||||
replacement = parse(replacement);
|
||||
} catch (err) {
|
||||
var loc = err.loc;
|
||||
if (loc) {
|
||||
err.message += " - make sure this is an expression.";
|
||||
err.message += "\n" + codeFrame(replacement, loc.line, loc.column + 1);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
replacement = replacement.program.body[0].expression;
|
||||
traverse.removeProperties(replacement);
|
||||
return this.replaceWith(replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
23
packages/babel/test/path.js
Normal file
23
packages/babel/test/path.js
Normal file
@ -0,0 +1,23 @@
|
||||
var transform = require("../lib/transformation");
|
||||
var Plugin = require("../lib/transformation/plugin");
|
||||
var babel = require("../lib/api/node");
|
||||
var chai = require("chai");
|
||||
|
||||
suite("traversal path", function () {
|
||||
test("replaceWithSourceString", function () {
|
||||
var expectCode = "function foo() {}";
|
||||
|
||||
var actualCode = transform(expectCode, {
|
||||
blacklist: "strict",
|
||||
plugins: [new Plugin("foobar", {
|
||||
visitor: {
|
||||
FunctionDeclaration: function () {
|
||||
this.replaceWithSourceString("console.whatever()");
|
||||
}
|
||||
}
|
||||
})]
|
||||
}).code;
|
||||
|
||||
chai.expect(actualCode).to.be.equal("console.whatever();");
|
||||
});
|
||||
});
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babylon",
|
||||
"version": "5.6.23",
|
||||
"version": "5.7.1",
|
||||
"description": "",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user