Skip to content

Commit

Permalink
feat: add babel-plugin-transform-not-strict
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 12, 2020
1 parent 72655a8 commit 15a4d43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ Enable `"@babel/preset-react"`. `true` by default.

Enable `"@babel/preset-flow"`. `true` by default.

8) `removeAllUseStrict`

Remove all `'use strict'` from all files. Passed to `babel-plugin-transform-not-strict`. This is `false` by default.

## Behind the scenes

Expand All @@ -141,3 +144,6 @@ It includes the plugins for compile time code generation:

It has the preset that automatically adds default export for older Node versions (so no `require().default` is needed).
- `"babel-plugin-add-module-exports"`

It has the plugin for removing `'use strict'`:
- `"babel-plugin-transform-not-strict"`
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ function handleOptions(options) {
flow = true
}

return {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap, react, flow }
if (removeAllUseStrict == null) {
removeAllUseStrict = false
}

return {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap, react, flow, removeAllUseStrict }
}

module.exports = (api, options, dirname) => {

const {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap, react, flow } = handleOptions(options)
const {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, sourceMap, react, flow, removeAllUseStrict } = handleOptions(options)

let presets = [
[
Expand Down Expand Up @@ -94,6 +98,9 @@ module.exports = (api, options, dirname) => {
// compile time code generation
require("babel-plugin-codegen"),
require("babel-plugin-preval"),

// not strict
[require("babel-plugin-transform-not-strict"), {removeAll: removeAllUseStrict}],
];

// transform modules (e.g when without Rollup)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"@babel/preset-react": "7.10.4",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-codegen": "^4.0.1",
"babel-plugin-preval": "^5.0.0"
"babel-plugin-preval": "^5.0.0",
"babel-plugin-transform-not-strict": "^0.2.0"
},
"peerDependencies": {
"@babel/cli": "7.11.6",
Expand Down
22 changes: 16 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15a4d43

Please sign in to comment.