From 15a4d431426f5e2fcf89a51ff7a94b9836b85f71 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 11 Sep 2020 22:10:38 -0500 Subject: [PATCH] feat: add babel-plugin-transform-not-strict --- README.md | 6 ++++++ index.js | 11 +++++++++-- package.json | 3 ++- pnpm-lock.yaml | 22 ++++++++++++++++------ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bde11a8..8d3fe83 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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"` diff --git a/index.js b/index.js index 5858455..7fd575b 100644 --- a/index.js +++ b/index.js @@ -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 = [ [ @@ -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) diff --git a/package.json b/package.json index 9402bac..d0782dc 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3cd320b..0a39d59 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,6 +21,7 @@ dependencies: babel-plugin-add-module-exports: 1.0.2 babel-plugin-codegen: 4.0.1 babel-plugin-preval: 5.0.0 + babel-plugin-transform-not-strict: 0.2.0_@babel+core@7.11.4 devDependencies: '@babel/cli': 7.10.5_@babel+core@7.11.4 '@babel/core': 7.11.4 @@ -1535,6 +1536,14 @@ packages: npm: '>=6' resolution: integrity: sha512-8DqJq6/LPUjSZ0Qq6bVIFpsj2flCEE0Cbnbut9TvGU6jP9g3dOWEXtQ/sdvsA9d6souza8eNGh04WRXpuH9ThA== + /babel-plugin-transform-not-strict/0.2.0_@babel+core@7.11.4: + dependencies: + '@babel/core': 7.11.4 + dev: false + peerDependencies: + '@babel/core': 7.11.6 + resolution: + integrity: sha512-SDA0NN6N4mhnRIObsDo2FaUFZApUSiE9o6ZvlOzErSAVQSaNCGZbPQa0RZLBycoVAvxOk/oClEGo/DSIPScAAw== /balanced-match/1.0.0: dev: true resolution: @@ -4555,14 +4564,14 @@ packages: resolution: integrity: sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg== specifiers: - '@babel/cli': 7.10.5 - '@babel/core': 7.11.4 + '@babel/cli': 7.11.6 + '@babel/core': 7.11.6 '@babel/plugin-proposal-class-properties': ^7.10.4 '@babel/plugin-proposal-decorators': ^7.10.5 '@babel/plugin-proposal-do-expressions': 7.10.4 '@babel/plugin-proposal-export-default-from': 7.10.4 '@babel/plugin-proposal-export-namespace-from': 7.10.4 - '@babel/plugin-proposal-function-bind': 7.10.5 + '@babel/plugin-proposal-function-bind': 7.11.5 '@babel/plugin-proposal-function-sent': 7.10.4 '@babel/plugin-proposal-json-strings': 7.10.4 '@babel/plugin-proposal-logical-assignment-operators': 7.11.0 @@ -4573,10 +4582,11 @@ specifiers: '@babel/plugin-proposal-throw-expressions': 7.10.4 '@babel/plugin-syntax-dynamic-import': 7.8.3 '@babel/plugin-syntax-import-meta': 7.10.4 - '@babel/preset-env': 7.11.0 + '@babel/preset-env': 7.11.5 '@babel/preset-flow': 7.10.4 '@babel/preset-react': 7.10.4 - babel-plugin-add-module-exports: ^1.0.2 + babel-plugin-add-module-exports: ^1.0.4 babel-plugin-codegen: ^4.0.1 babel-plugin-preval: ^5.0.0 - npm-check-updates: 8.0.1 + babel-plugin-transform-not-strict: ^0.2.0 + npm-check-updates: 8.1.1