@rolldown/plugin-babel 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,18 +5,18 @@ Rolldown plugin for transforming code with [Babel](https://babeljs.io/).
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install @rolldown/plugin-babel @babel/core
8
+ pnpm install @rolldown/plugin-babel @babel/core
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
13
  ```js
14
- import babelPlugin from '@rolldown/plugin-babel'
14
+ import babel from '@rolldown/plugin-babel'
15
15
 
16
16
  export default {
17
17
  plugins: [
18
- babelPlugin({
19
- presets: [['@babel/preset-env', { targets: { chrome: '100' } }]],
18
+ babel({
19
+ plugins: ['@babel/plugin-proposal-throw-expressions'],
20
20
  }),
21
21
  ],
22
22
  }
@@ -31,8 +31,9 @@ The plugin automatically configures Babel's parser for `.jsx`, `.ts`, and `.tsx`
31
31
  ### `include`
32
32
 
33
33
  - **Type:** `string | RegExp | (string | RegExp)[]`
34
+ - **Default:** `/\.(?:[jt]sx?|[cm][jt]s)(?:$|\?)/`
34
35
 
35
- If specified, only files matching the pattern will be processed.
36
+ Only files matching the pattern will be processed.
36
37
 
37
38
  ### `exclude`
38
39
 
package/dist/index.d.mts CHANGED
@@ -31,11 +31,18 @@ interface InnerTransformOptions extends Pick<babel.InputOptions, 'assumptions' |
31
31
  interface PluginOptions extends Omit<InnerTransformOptions, 'include' | 'exclude'> {
32
32
  /**
33
33
  * If specified, only files matching the pattern will be processed by babel.
34
+ * @default `/\.(?:[jt]sx?|[cm][jt]s)(?:$|\?)/`
35
+ *
36
+ * Note that this option receives the syntax supported by babel instead of picomatch.
37
+ * @see https://babeljs.io/docs/options#matchpattern
34
38
  */
35
39
  include?: InnerTransformOptions['include'];
36
40
  /**
37
41
  * If any of patterns match, babel will not process the file.
38
42
  * @default `/[\/\\]node_modules[\/\\]/`
43
+ *
44
+ * Note that this option receives the syntax supported by babel instead of picomatch.
45
+ * @see https://babeljs.io/docs/options#matchpattern
39
46
  */
40
47
  exclude?: InnerTransformOptions['exclude'];
41
48
  /**
package/dist/index.mjs CHANGED
@@ -75,10 +75,13 @@ function convertToBabelPresetItem(ctx, preset, compiledFilter) {
75
75
 
76
76
  //#endregion
77
77
  //#region src/options.ts
78
+ const DEFAULT_INCLUDE = [/\.(?:[jt]sx?|[cm][jt]s)(?:$|\?)/];
79
+ const DEFAULT_EXCLUDE = [/[/\\]node_modules[/\\]/];
78
80
  function resolveOptions(options) {
79
81
  return {
80
82
  ...options,
81
- exclude: options.exclude ?? [/[/\\]node_modules[/\\]/],
83
+ include: options.include ?? DEFAULT_INCLUDE,
84
+ exclude: options.exclude ?? DEFAULT_EXCLUDE,
82
85
  sourceMap: options.sourceMap ?? true
83
86
  };
84
87
  }
@@ -290,6 +293,7 @@ async function babelPlugin(rawOptions) {
290
293
  const envState = /* @__PURE__ */ new Map();
291
294
  const plugin = {
292
295
  name: "@rolldown/plugin-babel",
296
+ enforce: "pre",
293
297
  configResolved(config) {
294
298
  configFilteredOptions = filterPresetsWithConfigResolved(rawOptions, config);
295
299
  const resolved = resolveOptions(configFilteredOptions);
@@ -345,7 +349,18 @@ async function babelPlugin(rawOptions) {
345
349
  filename: id
346
350
  });
347
351
  if (!loadedOptions || loadedOptions.plugins.length === 0) return;
348
- const result = await babel.transformAsync(code, loadedOptions);
352
+ let result;
353
+ try {
354
+ result = await babel.transformAsync(code, loadedOptions);
355
+ } catch (err) {
356
+ this.error({
357
+ message: `[BabelError] ${err.message}`,
358
+ loc: err.loc,
359
+ pos: err.pos,
360
+ cause: err,
361
+ pluginCode: `${err.code}:${err.reasonCode}`
362
+ });
363
+ }
349
364
  if (result) return {
350
365
  code: result.code ?? void 0,
351
366
  map: result.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolldown/plugin-babel",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Rolldown plugin for Babel",
5
5
  "keywords": [
6
6
  "babel",