Default templates to sourceType:module.

This commit is contained in:
Logan Smyth 2017-10-07 21:45:18 -04:00
parent afc3963848
commit fc3433c5cf
4 changed files with 7 additions and 6 deletions

View File

@ -6,7 +6,7 @@ const helpers = {};
export default helpers; export default helpers;
function defineHelper(str) { function defineHelper(str) {
return template(str, { sourceType: "module" }); return template(str);
} }
helpers.typeof = defineHelper(` helpers.typeof = defineHelper(`

View File

@ -17,7 +17,7 @@ export default function defineHelper(
throw new Error(`The ${id} helper is already defined.`); throw new Error(`The ${id} helper is already defined.`);
} }
Object.defineProperty(helpers, id, { Object.defineProperty(helpers, id, {
value: template(code, { sourceType: "module" }), value: template(code),
}); });
return id; return id;
} }

View File

@ -129,6 +129,7 @@ function factory(code: string, opts?: Object): Function {
allowReturnOutsideFunction: true, allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true, allowSuperOutsideMethod: true,
preserveComments: false, preserveComments: false,
sourceType: "module",
}, },
opts, opts,
); );

View File

@ -5,18 +5,18 @@ import chai from "chai";
const comments = "// Sum two numbers\nconst add = (a, b) => a + b;"; const comments = "// Sum two numbers\nconst add = (a, b) => a + b;";
describe("templating", function() { describe("templating", function() {
it("import statement will cause parser to throw by default", function() { it("import statements are allowed by default", function() {
chai chai
.expect(function() { .expect(function() {
template("import foo from 'foo'")({}); template("import foo from 'foo'")({});
}) })
.to.throw(); .not.to.throw();
}); });
it("import statements are allowed with sourceType: module", function() { it("with statements are allowed with sourceType: script", function() {
chai chai
.expect(function() { .expect(function() {
template("import foo from 'foo'", { sourceType: "module" })({}); template("with({}){}", { sourceType: "script" })({});
}) })
.not.to.throw(); .not.to.throw();
}); });