Skip to content

Commit

Permalink
Remove workaround for webpack 4 (#91)
Browse files Browse the repository at this point in the history
* Remove workaround for webpack 4

* Update docs

* Remove include docs since it's now a pass-through
  • Loading branch information
billyjanitsch authored Jun 22, 2021
1 parent 54962c3 commit 3ec9a9e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 69 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ Default: `false`

Whether to enable support for CSS-in-JS via [Emotion](https://emotion.sh). If an `options` object is passed, it is forwarded to the [Emotion plugin](https://emotion.sh/docs/@emotion/babel-plugin). This option requires an additional dependency on [`@emotion/react`](https://npm.im/@emotion/react).

### `include`

`Array<string|RegExp>`<br />
Default: `['@babel/plugin-proposal-optional-chaining', '@babel/plugin-proposal-nullish-coalescing-operator']`

List of plugins to always include. Forwarded to [the corresponding option in `@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env#include).

### `modules`

`false` | `'commonjs'`<br />
Expand Down
58 changes: 16 additions & 42 deletions __snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1656,34 +1656,21 @@ exports.default = _default;
`;

exports[`transpiles ES2020+ syntax given {}, {"targets":"Chrome 88"}: output (development) 1`] = `
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/classPrivateFieldLooseKey";
var _nullishAssignment;
import defaultImport, { namedImport } from 'foo';
import * as namespaceImport from 'bar';
const dynamicImport = import('baz');
var _privateMethod = /*#__PURE__*/_classPrivateFieldLooseKey("privateMethod");
class Foo {
constructor() {
Object.defineProperty(this, _privateMethod, {
value: _privateMethod2
});
static bar = 'abc';
baz = (x, y) => x({ ...y
});
this.baz = (x, y) => x({ ...y
});
#privateMethod() {
return 1;
}
}
function _privateMethod2() {
return 1;
}
Foo.bar = 'abc';
function* infiniteGenerator() {
yield 1;
yield* infiniteGenerator();
Expand All @@ -1706,9 +1693,9 @@ const {
...rest
} = spread;
let nullishAssignment;
(_nullishAssignment = nullishAssignment) != null ? _nullishAssignment : nullishAssignment = 1;
const nullishCoalescing = obj != null ? obj : 1;
const optionalChaining = obj == null ? void 0 : obj.b;
nullishAssignment ??= 1;
const nullishCoalescing = obj ?? 1;
const optionalChaining = obj?.b;
export default obj;
export { obj };
`;
Expand Down Expand Up @@ -1759,34 +1746,21 @@ export { obj };
`;

exports[`transpiles ES2020+ syntax given {}, {"targets":"Chrome 88"}: output (production) 1`] = `
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/classPrivateFieldLooseKey";
var _nullishAssignment;
import defaultImport, { namedImport } from 'foo';
import * as namespaceImport from 'bar';
const dynamicImport = import('baz');
var _privateMethod = /*#__PURE__*/_classPrivateFieldLooseKey("privateMethod");
class Foo {
constructor() {
Object.defineProperty(this, _privateMethod, {
value: _privateMethod2
});
static bar = 'abc';
baz = (x, y) => x({ ...y
});
this.baz = (x, y) => x({ ...y
});
#privateMethod() {
return 1;
}
}
function _privateMethod2() {
return 1;
}
Foo.bar = 'abc';
function* infiniteGenerator() {
yield 1;
yield* infiniteGenerator();
Expand All @@ -1809,9 +1783,9 @@ const {
...rest
} = spread;
let nullishAssignment;
(_nullishAssignment = nullishAssignment) != null ? _nullishAssignment : nullishAssignment = 1;
const nullishCoalescing = obj != null ? obj : 1;
const optionalChaining = obj == null ? void 0 : obj.b;
nullishAssignment ??= 1;
const nullishCoalescing = obj ?? 1;
const optionalChaining = obj?.b;
export default obj;
export { obj };
`;
Expand Down
21 changes: 1 addition & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

const NODE_MODULES_REGEX = /node_modules/

// webpack@4 depends on versions of acorn and terser that lack support for certain modern syntax,
// so, when transpiling an app, these plugins must be included
const APP_PLUGIN_INCLUDE_LIST = [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-private-methods',
'@babel/plugin-proposal-logical-assignment-operators',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
]

const PRECOMPILED_PACKAGES = ['core-js', 'lodash', 'react', 'react-dom', 'whatwg-fetch']
const PRECOMPILED_PACKAGES_REGEX = new RegExp(`node_modules/(${PRECOMPILED_PACKAGES.join('|')})/`)

Expand Down Expand Up @@ -58,7 +48,6 @@ module.exports = (babel, options) => {

const {
emotion = false,
include = env === 'development' || env === 'production' ? APP_PLUGIN_INCLUDE_LIST : [],
modules = env === 'test' || env === 'cjs' ? 'commonjs' : false,
react = {},
reactRefresh = env === 'development' && react && {},
Expand Down Expand Up @@ -86,15 +75,7 @@ module.exports = (babel, options) => {
presets: [
[
require('@babel/preset-env').default,
{
...rest,
include,
modules,
targets,
bugfixes: true,
corejs: 3,
useBuiltIns: 'entry',
},
{...rest, modules, targets, bugfixes: true, corejs: 3, useBuiltIns: 'entry'},
],
],
}
Expand Down

0 comments on commit 3ec9a9e

Please sign in to comment.