diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 99259ce4c1..2be88b495a 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -285,16 +285,7 @@ describe("api", function() { assert.equal(aliasBaseType, "NumberTypeAnnotation"); - assert.deepEqual( - [ - '"use strict";', - "", - "var x = function x(y) {", - " return y;", - "};", - ].join("\n"), - result.code, - ); + assert.deepEqual(result.code, "var x = function x(y) {\n return y;\n};"); // 2. passPerPreset: false @@ -304,16 +295,7 @@ describe("api", function() { assert.equal(aliasBaseType, null); - assert.deepEqual( - [ - '"use strict";', - "", - "var x = function x(y) {", - " return y;", - "};", - ].join("\n"), - result.code, - ); + assert.deepEqual(result.code, "var x = function x(y) {\n return y;\n};"); }); it("complex plugin and preset ordering", function() { diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-4855/expected.js b/packages/babel-core/test/fixtures/transformation/misc/regression-4855/expected.js index 31462a08e1..bd646847de 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-4855/expected.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-4855/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var _values = values; var _fieldName = fieldName; value = _values[_fieldName]; diff --git a/packages/babel-helper-fixtures/src/index.js b/packages/babel-helper-fixtures/src/index.js index 42324b4237..5e863ba2f0 100644 --- a/packages/babel-helper-fixtures/src/index.js +++ b/packages/babel-helper-fixtures/src/index.js @@ -1,3 +1,4 @@ +import assert from "assert"; import cloneDeep from "lodash/cloneDeep"; import trimEnd from "lodash/trimEnd"; import resolve from "try-resolve"; @@ -83,24 +84,46 @@ export default function get(entryLoc): Array { } function push(taskName, taskDir) { - const actualLocAlias = suiteName + "/" + taskName + "/actual.js"; + let actualLocAlias = suiteName + "/" + taskName + "/actual.js"; let expectLocAlias = suiteName + "/" + taskName + "/expected.js"; - const execLocAlias = suiteName + "/" + taskName + "/exec.js"; + let execLocAlias = suiteName + "/" + taskName + "/exec.js"; - const actualLoc = taskDir + "/actual.js"; + let actualLoc = taskDir + "/actual.js"; let expectLoc = taskDir + "/expected.js"; let execLoc = taskDir + "/exec.js"; - if (fs.statSync(taskDir).isFile()) { - const ext = path.extname(taskDir); - if (ext !== ".js" && ext !== ".module.js") return; + const hasExecJS = fs.existsSync(execLoc); + const hasExecMJS = fs.existsSync(asMJS(execLoc)); + if (hasExecMJS) { + assert(!hasExecJS, `${asMJS(execLoc)}: Found conflicting .js`); - execLoc = taskDir; + execLoc = asMJS(execLoc); + execLocAlias = asMJS(execLocAlias); } - if (resolve.relative(expectLoc + "on")) { - expectLoc += "on"; - expectLocAlias += "on"; + const hasExpectJS = fs.existsSync(expectLoc); + const hasExpectMJS = fs.existsSync(asMJS(expectLoc)); + if (hasExpectMJS) { + assert(!hasExpectJS, `${asMJS(expectLoc)}: Found conflicting .js`); + + expectLoc = asMJS(expectLoc); + expectLocAlias = asMJS(expectLocAlias); + } + + const hasActualJS = fs.existsSync(actualLoc); + const hasActualMJS = fs.existsSync(asMJS(actualLoc)); + if (hasActualMJS) { + assert(!hasActualJS, `${asMJS(actualLoc)}: Found conflicting .js`); + + actualLoc = asMJS(actualLoc); + actualLocAlias = asMJS(actualLocAlias); + } + + if (fs.statSync(taskDir).isFile()) { + const ext = path.extname(taskDir); + if (ext !== ".js" && ext !== ".mjs") return; + + execLoc = taskDir; } const taskOpts = cloneDeep(suite.options); @@ -186,6 +209,10 @@ export function multiple(entryLoc, ignore?: Array) { return categories; } +function asMJS(filepath) { + return filepath.replace(/\.js$/, ".mjs"); +} + export function readFile(filename) { if (fs.existsSync(filename)) { let file = trimEnd(fs.readFileSync(filename, "utf8")); diff --git a/packages/babel-helper-module-transforms/src/index.js b/packages/babel-helper-module-transforms/src/index.js index 6d40af3f96..f868c01fc3 100644 --- a/packages/babel-helper-module-transforms/src/index.js +++ b/packages/babel-helper-module-transforms/src/index.js @@ -1,3 +1,4 @@ +import assert from "assert"; import * as t from "babel-types"; import template from "babel-template"; import chunk from "lodash/chunk"; @@ -11,6 +12,31 @@ import normalizeAndLoadModuleMetadata, { export { hasExports, isSideEffectImport }; +export function isModule(path: NodePath, requireUnambiguous: boolean = false) { + const { sourceType } = path.node; + if (sourceType !== "module" && sourceType !== "script") { + throw path.buildCodeFrameError( + `Unknown sourceType "${sourceType}", cannot transform.`, + ); + } + + const filename = path.hub.file.opts.filename; + if (/\.mjs$/.test(filename)) { + requireUnambiguous = false; + } + + return ( + path.node.sourceType === "module" && + (!requireUnambiguous || isUnambiguousModule(path)) + ); +} + +// This approach is not ideal. It is here to preserve compatibility for now, +// but really this should just return true or be deleted. +function isUnambiguousModule(path) { + return path.get("body").some(p => p.isModuleDeclaration()); +} + /** * Perform all of the generic ES6 module rewriting needed to handle initial * module processing. This function will rewrite the majority of the given @@ -21,6 +47,9 @@ export function rewriteModuleStatementsAndPrepareHeader( path: NodePath, { exportName, strict, allowTopLevelThis, strictMode, loose, noInterop }, ) { + assert(isModule(path), "Cannot process module statements in a script"); + path.node.sourceType = "script"; + const meta = normalizeAndLoadModuleMetadata(path, exportName, { noInterop, }); diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/general/foobar/expected.js b/packages/babel-plugin-transform-class-properties/test/fixtures/general/foobar/expected.js index 3532914e26..2865c35414 100644 --- a/packages/babel-plugin-transform-class-properties/test/fixtures/general/foobar/expected.js +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/general/foobar/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var Child = /*#__PURE__*/ function (_Parent) { diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/loose/foobar/expected.js b/packages/babel-plugin-transform-class-properties/test/fixtures/loose/foobar/expected.js index cf6a9bc02c..f43f546b7c 100644 --- a/packages/babel-plugin-transform-class-properties/test/fixtures/loose/foobar/expected.js +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/loose/foobar/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var Child = /*#__PURE__*/ function (_Parent) { diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/regression/6154/expected.js b/packages/babel-plugin-transform-class-properties/test/fixtures/regression/6154/expected.js index 01805e5c56..c027b23cbc 100644 --- a/packages/babel-plugin-transform-class-properties/test/fixtures/regression/6154/expected.js +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/regression/6154/expected.js @@ -1,5 +1,3 @@ -"use strict"; - function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } } diff --git a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/5817/expected.js b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/5817/expected.js index 2fe6ea970f..0abfa635e3 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/5817/expected.js +++ b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/5817/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var A = /*#__PURE__*/ function (_B) { diff --git a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2494/expected.js b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2494/expected.js index 86a3c654b2..7ee2040344 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2494/expected.js +++ b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2494/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var x = { Foo: /*#__PURE__*/ diff --git a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/expected.js b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/expected.js index b46893d0e6..8ecfecbaaa 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/expected.js +++ b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var A = function A() { babelHelpers.classCallCheck(this, A); }; diff --git a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6712/expected.js b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6712/expected.js index 96e00e6922..08cac4b578 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6712/expected.js +++ b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6712/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var A = /*#__PURE__*/ function () { diff --git a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/expected.js b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/expected.js index b5fa2e3253..6b2fd1e691 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/expected.js +++ b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var Example = /*#__PURE__*/ function () { diff --git a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/expected.js b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/expected.js index 3d7a460b5a..4f8dfbdae2 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/expected.js +++ b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var Foo = /*#__PURE__*/ function () { diff --git a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7537/expected.js b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7537/expected.js index ae764cf723..1a7251e480 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7537/expected.js +++ b/packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7537/expected.js @@ -1,5 +1,3 @@ -"use strict"; - function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } diff --git a/packages/babel-plugin-transform-es2015-modules-amd/src/index.js b/packages/babel-plugin-transform-es2015-modules-amd/src/index.js index 4c2fce1bf6..b549ac4204 100644 --- a/packages/babel-plugin-transform-es2015-modules-amd/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-amd/src/index.js @@ -1,5 +1,6 @@ import template from "babel-template"; import { + isModule, rewriteModuleStatementsAndPrepareHeader, hasExports, isSideEffectImport, @@ -18,6 +19,8 @@ export default function({ types: t }) { visitor: { Program: { exit(path, state) { + if (!isModule(path)) return; + const { loose, allowTopLevelThis, diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js index b52cfd0d1e..b7119c8774 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -1,4 +1,5 @@ import { + isModule, rewriteModuleStatementsAndPrepareHeader, isSideEffectImport, buildNamespaceInitStatements, @@ -11,6 +12,10 @@ export default function({ types: t }) { visitor: { Program: { exit(path, state) { + // For now this requires unambiguous rather that just sourceType + // because Babel currently parses all files as sourceType:module. + if (!isModule(path, true /* requireUnambiguous */)) return; + const { loose, allowTopLevelThis, diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-arrow-function/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-arrow-function/actual.mjs similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-arrow-function/actual.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-arrow-function/actual.mjs diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-arrow-function/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-arrow-function/expected.js similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-arrow-function/expected.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-arrow-function/expected.js diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-call/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-call/actual.mjs similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-call/actual.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-call/actual.mjs diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-call/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-call/expected.js similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-call/expected.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-call/expected.js diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-declaration/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-declaration/actual.mjs similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-declaration/actual.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-declaration/actual.mjs diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-declaration/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-declaration/expected.js similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-declaration/expected.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-declaration/expected.js diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-reference/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-reference/actual.mjs similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-reference/actual.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-reference/actual.mjs diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-reference/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-reference/expected.js similarity index 100% rename from packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/undefined-this-root-reference/expected.js rename to packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/misc/undefined-this-root-reference/expected.js diff --git a/packages/babel-plugin-transform-es2015-modules-umd/src/index.js b/packages/babel-plugin-transform-es2015-modules-umd/src/index.js index 1cf4fa9f05..c984cb53e7 100644 --- a/packages/babel-plugin-transform-es2015-modules-umd/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-umd/src/index.js @@ -1,6 +1,7 @@ import { basename, extname } from "path"; import template from "babel-template"; import { + isModule, rewriteModuleStatementsAndPrepareHeader, hasExports, isSideEffectImport, @@ -107,6 +108,8 @@ export default function({ types: t }) { visitor: { Program: { exit(path, state) { + if (!isModule(path)) return; + const { globals, exactGlobals, diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-loose-return-type-annotation/expected.js b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-loose-return-type-annotation/expected.js index 16ca53f948..d39c634e40 100644 --- a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-loose-return-type-annotation/expected.js +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-loose-return-type-annotation/expected.js @@ -1,5 +1,3 @@ -"use strict"; - // @flow var C = /*#__PURE__*/ diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-return-type-annotation/expected.js b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-return-type-annotation/expected.js index 68d6c4494b..cca8f738c3 100644 --- a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-return-type-annotation/expected.js +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/transformed-class-method-return-type-annotation/expected.js @@ -1,5 +1,3 @@ -"use strict"; - // @flow var C = /*#__PURE__*/ diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-loose-return-type-annotation/expected.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-loose-return-type-annotation/expected.js index 42a2b16879..f5f9fc21cb 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-loose-return-type-annotation/expected.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-loose-return-type-annotation/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var C = /*#__PURE__*/ function () { diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-return-type-annotation/expected.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-return-type-annotation/expected.js index 8613c02f7e..8665e0ced3 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-return-type-annotation/expected.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/transformed-class-method-return-type-annotation/expected.js @@ -1,5 +1,3 @@ -"use strict"; - var C = /*#__PURE__*/ function () { diff --git a/packages/babel-plugin-transform-regenerator/test/fixtures/regression/4219/expected.js b/packages/babel-plugin-transform-regenerator/test/fixtures/regression/4219/expected.js index ffaa4b9a4e..babd815f2d 100644 --- a/packages/babel-plugin-transform-regenerator/test/fixtures/regression/4219/expected.js +++ b/packages/babel-plugin-transform-regenerator/test/fixtures/regression/4219/expected.js @@ -1,5 +1,3 @@ -"use strict"; - function test(fn) { return function _callee() { var _args = arguments; diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/options.json b/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/options.json index 51bfaafbee..95296e5e98 100644 --- a/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/options.json +++ b/packages/babel-plugin-transform-strict-mode/test/fixtures/strict-mode/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-strict-mode", "transform-es2015-modules-commonjs"] + "plugins": ["transform-strict-mode"] } diff --git a/packages/babel-preset-es2015/test/fixtures/preset-options/spec/expected.js b/packages/babel-preset-es2015/test/fixtures/preset-options/spec/expected.js index e4b0c4adb6..889d4b054a 100644 --- a/packages/babel-preset-es2015/test/fixtures/preset-options/spec/expected.js +++ b/packages/babel-preset-es2015/test/fixtures/preset-options/spec/expected.js @@ -1,11 +1,9 @@ -"use strict"; - -var _this = void 0; +var _this = this; "1".concat(a); (function () { babelHelpers.newArrowCheck(this, _this); -}).bind(void 0); +}).bind(this); function a() { var _this2 = this; diff --git a/packages/babel-runtime/scripts/build-dist.js b/packages/babel-runtime/scripts/build-dist.js index 4f9a3c5a1f..f581bdb4a3 100644 --- a/packages/babel-runtime/scripts/build-dist.js +++ b/packages/babel-runtime/scripts/build-dist.js @@ -104,7 +104,7 @@ function buildRuntimeRewritePlugin(relativePath, helperName) { } function buildHelper(helperName, modules, useBuiltIns) { - const tree = t.program(helpers.get(helperName).nodes); + const tree = t.program(helpers.get(helperName).nodes, [], "module"); const transformOpts = makeTransformOpts(modules, useBuiltIns); diff --git a/packages/babel-standalone/test/babel.js b/packages/babel-standalone/test/babel.js index 73d7802727..088a78408d 100644 --- a/packages/babel-standalone/test/babel.js +++ b/packages/babel-standalone/test/babel.js @@ -18,7 +18,7 @@ describe("babel-standalone", () => { const output = Babel.transform("class A {}", { presets: ["es2015-loose"], }).code; - assert.equal(output, '"use strict";\n\nvar A = function A() {};'); + assert.equal(output, "var A = function A() {};"); }); it("handles the typescript preset", () => { const output = Babel.transform("var a: string;", { @@ -56,7 +56,7 @@ describe("babel-standalone", () => { }; const output = Babel.transformFromAst(ast, "42", { presets: ["es2015"] }) .code; - assert.equal(output, '"use strict";\n' + "\n" + "42;"); + assert.equal(output, "42;"); }); it("handles the react preset", () => { diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index abdcd57bb1..9bb1181762 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -513,13 +513,14 @@ defineType("NewExpression", { inherits: "CallExpression" }); defineType("Program", { visitor: ["directives", "body"], - builder: ["body", "directives"], + builder: ["body", "directives", "sourceType"], fields: { sourceFile: { validate: assertValueType("string"), }, sourceType: { validate: assertOneOf("script", "module"), + default: "script", }, directives: { validate: chain(