Merge pull request #3304 from jamestalmage/fix-T7046
[babel-template][T7046]: Add optional babylon options argument.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import assign from "lodash/object/assign";
|
||||
import has from "lodash/object/has";
|
||||
import traverse from "babel-traverse";
|
||||
import * as babylon from "babylon";
|
||||
@@ -7,7 +8,7 @@ import * as t from "babel-types";
|
||||
let FROM_TEMPLATE = "_fromTemplate"; //Symbol(); // todo: probably wont get copied over
|
||||
let TEMPLATE_SKIP = Symbol();
|
||||
|
||||
export default function (code: string): Function {
|
||||
export default function (code: string, opts?: Object): Function {
|
||||
// since we lazy parse the template, we get the current stack so we have the
|
||||
// original stack to append if it errors when parsing
|
||||
let stack;
|
||||
@@ -22,10 +23,10 @@ export default function (code: string): Function {
|
||||
let ast;
|
||||
|
||||
try {
|
||||
ast = babylon.parse(code, {
|
||||
ast = babylon.parse(code, assign({
|
||||
allowReturnOutsideFunction: true,
|
||||
allowSuperOutsideMethod: true
|
||||
});
|
||||
}, opts));
|
||||
|
||||
ast = traverse.removeProperties(ast);
|
||||
|
||||
|
||||
16
packages/babel-template/test/index.js
Normal file
16
packages/babel-template/test/index.js
Normal file
@@ -0,0 +1,16 @@
|
||||
var template = require("../lib");
|
||||
var chai = require("chai");
|
||||
|
||||
suite("templating", function () {
|
||||
test("import statement will cause parser to throw by default", function () {
|
||||
chai.expect(function () {
|
||||
template("import foo from 'foo'")({});
|
||||
}).to.throw();
|
||||
});
|
||||
|
||||
test("import statements are allowed with sourceType: module", function () {
|
||||
chai.expect(function () {
|
||||
template("import foo from 'foo'", {sourceType: 'module'})({});
|
||||
}).not.to.throw();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user