Require AST output to be opt-in, rather than opt-out.

This commit is contained in:
Logan Smyth 2018-02-26 18:27:06 -08:00
parent d4a8c7672c
commit 8e3e6e0a88
3 changed files with 23 additions and 2 deletions

View File

@ -64,7 +64,7 @@ export function runSync(
return {
metadata: file.metadata,
options: opts,
ast: opts.ast !== false ? file.ast : null,
ast: opts.ast === true ? file.ast : null,
code: outputCode === undefined ? null : outputCode,
map: outputMap === undefined ? null : outputMap,
};

View File

@ -34,6 +34,7 @@ describe("parser and generator options", function() {
function newTransform(string) {
return babel.transform(string, {
ast: true,
parserOpts: {
parser: recast.parse,
plugins: ["flow"],
@ -47,7 +48,10 @@ describe("parser and generator options", function() {
it("options", function() {
const string = "original;";
assert.deepEqual(newTransform(string).ast, babel.transform(string).ast);
assert.deepEqual(
newTransform(string).ast,
babel.transform(string, { ast: true }).ast,
);
assert.equal(newTransform(string).code, string);
});
@ -57,6 +61,7 @@ describe("parser and generator options", function() {
assert.deepEqual(
newTransform(experimental).ast,
babel.transform(experimental, {
ast: true,
parserOpts: {
plugins: ["flow"],
},
@ -66,6 +71,7 @@ describe("parser and generator options", function() {
function newTransformWithPlugins(string) {
return babel.transform(string, {
ast: true,
plugins: [__dirname + "/../../babel-plugin-syntax-flow"],
parserOpts: {
parser: recast.parse,
@ -79,6 +85,7 @@ describe("parser and generator options", function() {
assert.deepEqual(
newTransformWithPlugins(experimental).ast,
babel.transform(experimental, {
ast: true,
parserOpts: {
plugins: ["flow"],
},
@ -93,6 +100,7 @@ describe("parser and generator options", function() {
assert.notEqual(
newTransform(experimental).ast,
babel.transform(experimental, {
ast: true,
parserOpts: {
allowImportExportEverywhere: true,
},
@ -401,6 +409,18 @@ describe("api", function() {
});
});
it("ast option true", function() {
return transformAsync("foo('bar');", { ast: true }).then(function(result) {
assert.ok(result.ast);
});
});
it("ast option default", function() {
return transformAsync("foo('bar');").then(function(result) {
assert.ok(!result.ast);
});
});
it("auxiliaryComment option", function() {
return transformAsync("class Foo {}", {
auxiliaryCommentBefore: "before",

View File

@ -5,6 +5,7 @@ test("Doesn't use the same object for two different nodes in the AST", function(
const code = 'import Foo from "bar"; Foo; Foo;';
const ast = babel.transform(code, {
ast: true,
plugins: [[require("../"), { loose: true }]],
}).ast;