diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/options.json b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/options.json new file mode 100644 index 0000000000..0a8dd26059 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", ["transform-es2015-modules-commonjs", { "strictMode": false }]] +} diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/strictMode-false/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/strictMode-false/actual.js new file mode 100644 index 0000000000..222b6885ac --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/strictMode-false/actual.js @@ -0,0 +1,3 @@ +import "foo"; +import "foo-bar"; +import "./directory/foo-bar"; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/strictMode-false/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/strictMode-false/expected.js new file mode 100644 index 0000000000..e3de8abeb0 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/disable-strict-mode/strictMode-false/expected.js @@ -0,0 +1,5 @@ +require("foo"); + +require("foo-bar"); + +require("./directory/foo-bar"); diff --git a/packages/babel-plugin-transform-strict-mode/README.md b/packages/babel-plugin-transform-strict-mode/README.md index 34f27d8f2a..638d1f83a5 100644 --- a/packages/babel-plugin-transform-strict-mode/README.md +++ b/packages/babel-plugin-transform-strict-mode/README.md @@ -1,6 +1,11 @@ # babel-plugin-transform-strict-mode -TODO +Add the `"use strict";` directive to the top of your files if it is not there +already. + +> This plugin may be enabled via `babel-plugin-transform-es2015-modules-commonjs`. +> If you wish to disable it you can either turn `strict` off or pass +> `strictMode: false` as an option to the commonjs transform. ## Installation diff --git a/packages/babel-plugin-transform-strict-mode/src/index.js b/packages/babel-plugin-transform-strict-mode/src/index.js index 452f5c9a6b..8ed2d181fb 100644 --- a/packages/babel-plugin-transform-strict-mode/src/index.js +++ b/packages/babel-plugin-transform-strict-mode/src/index.js @@ -4,8 +4,8 @@ export default function () { return { visitor: { Program(path, state) { - if (state.opts.strict === false) return; - + if (state.opts.strict === false || state.opts.strictMode === false) return; + let { node } = path; for (let directive of (node.directives: Array)) { diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/options.json b/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/options.json new file mode 100644 index 0000000000..aaa785cb96 --- /dev/null +++ b/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + ["transform-strict-mode", { "strictMode": false }] + ] +} diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/strictMode-false/actual.js b/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/strictMode-false/actual.js new file mode 100644 index 0000000000..a280f9a5cc --- /dev/null +++ b/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/strictMode-false/actual.js @@ -0,0 +1 @@ +foo(); diff --git a/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/strictMode-false/expected.js b/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/strictMode-false/expected.js new file mode 100644 index 0000000000..a280f9a5cc --- /dev/null +++ b/packages/babel-plugin-transform-strict-mode/test/fixtures/disable-strict-mode/strictMode-false/expected.js @@ -0,0 +1 @@ +foo();