Skip to content

Commit

Permalink
Update why_is_babel-plugin-transform-runtime_and_tslib_included_by_de…
Browse files Browse the repository at this point in the history
…fault.md
  • Loading branch information
wessberg authored Jun 8, 2022
1 parent a9939c3 commit 91c9f5f
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### Why are helpers imported by default, and why are things like @babel/plugin-transform-runtime, tslib, and @swc/helpers peer dependencies?

Babel and Typescript both come with a set of helper functions.
Babel, swc, and Typescript both come with a set of helper functions.
For example, the following code:

```typescript
Expand All @@ -17,7 +17,7 @@ function _typeof(obj) {
typeof foo === "undefined" ? "undefined" : _typeof(foo);
```

And something similar to it with TypeScript. Let's focus on Babel for now, but the same can be said for using TypeScript as the transpiler:
And something similar to it with TypeScript and swc. Let's focus on Babel for now, but the same can be said for using TypeScript or swc as the transpiler:

With `rollup-plugin-ts`, most Babel plugins are run per file, rather than per-chunk. This is because for each file, the output provided to Rollup must be compatible with [Acorn](https://github.com/acornjs/acorn), which Rollup is based on, and you may be transforming experimental syntax that Acorn doesn't yet support.
In effect, this means that if you pass 3 files containing `typeof` through Rollup, you get 3 duplications of the helper inside the output bundle. For example
Expand Down

0 comments on commit 91c9f5f

Please sign in to comment.