@rolldown/plugin-babel 0.1.3 → 0.1.4
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 +6 -5
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +16 -2
- package/package.json +1 -1
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
|
-
|
|
8
|
+
pnpm install @rolldown/plugin-babel @babel/core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
-
import
|
|
14
|
+
import babel from '@rolldown/plugin-babel'
|
|
15
15
|
|
|
16
16
|
export default {
|
|
17
17
|
plugins: [
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
+
include: options.include ?? DEFAULT_INCLUDE,
|
|
84
|
+
exclude: options.exclude ?? DEFAULT_EXCLUDE,
|
|
82
85
|
sourceMap: options.sourceMap ?? true
|
|
83
86
|
};
|
|
84
87
|
}
|
|
@@ -345,7 +348,18 @@ async function babelPlugin(rawOptions) {
|
|
|
345
348
|
filename: id
|
|
346
349
|
});
|
|
347
350
|
if (!loadedOptions || loadedOptions.plugins.length === 0) return;
|
|
348
|
-
|
|
351
|
+
let result;
|
|
352
|
+
try {
|
|
353
|
+
result = await babel.transformAsync(code, loadedOptions);
|
|
354
|
+
} catch (err) {
|
|
355
|
+
this.error({
|
|
356
|
+
message: `[BabelError] ${err.message}`,
|
|
357
|
+
loc: err.loc,
|
|
358
|
+
pos: err.pos,
|
|
359
|
+
cause: err,
|
|
360
|
+
pluginCode: `${err.code}:${err.reasonCode}`
|
|
361
|
+
});
|
|
362
|
+
}
|
|
349
363
|
if (result) return {
|
|
350
364
|
code: result.code ?? void 0,
|
|
351
365
|
map: result.map
|