Skip to content

Commit

Permalink
chore: mark babelParserPlugins option as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyinws committed Dec 3, 2024
1 parent c805bb4 commit 61adfff
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 102 deletions.
2 changes: 1 addition & 1 deletion docs/guide/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| disableHighlight | `boolean` | `false` | Wheather to disable [highlight output](/features/highlight) feature |
| port | `number` | `3070` | Specify the plugin's service port number |
| extendedPathFileNames | `string[]` | `[]` | [Extended path file names](/features/highlight.html#expand-path-file-name) |
| babelParserPlugins | `ParserPlugin[]` | `["typescript", "jsx"]` | The incoming value will be automatically merged with the default value. [All babel parser plugins](https://babeljs.io/docs/en/babel-parser#plugins) |
| <span class="text-yellow-600 font-600">This option has been removed since v1.11.0</span> <br /> ~~babelParserPlugins~~ | `ParserPlugin[]` | `["typescript", "jsx"]` | The incoming value will be automatically merged with the default value. [All babel parser plugins](https://babeljs.io/docs/en/babel-parser#plugins) |
| disablePassLogs | `boolean` | `false` | Wheather to disable [Pass Logs](/features/pass-logs) feature |
| silent | `boolean` | `false` | Avoid the plugin's terminal output at project startup |

Expand Down
26 changes: 0 additions & 26 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,3 @@ console.log('bar') // turbo-console-disable-line
console.log('foo')
console.log('bar')
```

## Compilation Syntax Errors

If you use some unstable ECMAScript syntax, you might see errors like the following in the terminal:

```
[unplugin-turbo-console] Transform src/App.vue error: SyntaxError:
This experimental syntax requires enabling the parser plugin: "importAttributes". (5:39)
```

To resolve this, add the missing Babel parser plugin to `babelParserPlugins`:

```js{2,7} twoslash [vite.config.ts]
import { defineConfig } from 'vite'
import TurboConsole from 'unplugin-turbo-console/vite'
export default defineConfig({
plugins: [
TurboConsole({
babelParserPlugins: ['importAttributes'],
}),
],
})
```

> Related [issus](https://github.com/unplugin/unplugin-turbo-console/issues/35)
2 changes: 1 addition & 1 deletion docs/zh-CN/guide/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| disableHighlight | `boolean` | `false` | 是否禁用[高亮输出](/zh-CN/features/highlight)功能 |
| port | `number` | `3070` | 指定插件的服务端口号 |
| extendedPathFileNames | `string[]` | `[]` | [拓展路径文件名](/zh-CN/features/highlight.html#拓展路径文件名) |
| babelParserPlugins | `ParserPlugin[]` | `["typescript", "jsx"]` | babel插件,传入的值会与默认值自动合并。[所有插件](https://babeljs.io/docs/en/babel-parser#plugins) |
| <span class="text-yellow-600 font-600">此选项已于 v1.11.0 移除</span> <br /> ~~babelParserPlugins~~ | `ParserPlugin[]` | `["typescript", "jsx"]` | babel插件,传入的值会与默认值自动合并。[所有插件](https://babeljs.io/docs/en/babel-parser#plugins) |
| disablePassLogs | `boolean` | `false` | 是否禁用[传递日志](/zh-CN/features/pass-logs)功能 |
| silent | `boolean` | `false` | 阻止项目启动时插件的终端输出 |

Expand Down
26 changes: 0 additions & 26 deletions docs/zh-CN/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,3 @@ console.log('bar') // turbo-console-disable-line
console.log('foo')
console.log('bar')
```

## 编译语法错误

如果你使用了一些未稳定的ECMAScript语法,你可能会在终端看到类似错误:

```
[unplugin-turbo-console] Transform src/App.vue error: SyntaxError:
This experimental syntax requires enabling the parser plugin: "importAttributes". (5:39)
```

解决方法是将缺失的 babel parser 插件添加到`babelParserPlugins`中:

```js{2,7} twoslash [vite.config.ts]
import { defineConfig } from 'vite'
import TurboConsole from 'unplugin-turbo-console/vite'
export default defineConfig({
plugins: [
TurboConsole({
babelParserPlugins: ['importAttributes'],
}),
],
})
```

> 相关 [issus](https://github.com/unplugin/unplugin-turbo-console/issues/35)
9 changes: 0 additions & 9 deletions src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const DEFAULT_OPTIONS: Options = {
disableHighlight: false,
disablePassLogs: false,
extendedPathFileNames: [],
babelParserPlugins: ['typescript', 'jsx'],
port: 3070,
silent: false,
}
Expand All @@ -20,14 +19,6 @@ export const BUILD_OPTIONS: Options = {
}

export function resolveOptions(options: Options): Options {
// merge babel parser plugins
if (options.babelParserPlugins) {
options.babelParserPlugins = [
...DEFAULT_OPTIONS.babelParserPlugins!,
...options.babelParserPlugins,
]
}

let resolved = {
...DEFAULT_OPTIONS,
...options,
Expand Down
9 changes: 2 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ParserPlugin } from '@babel/parser'

export interface Options {
/**
* Add a string prefix to the console log.
Expand Down Expand Up @@ -61,13 +59,10 @@ export interface Options {
specifiedEditor?: string | undefined

/**
* Babel parser plugins. `typescript` and `jsx` are enabled by default.
*
* https://babeljs.io/docs/en/babel-parser#plugins
*
* @defaultValue ['typescript', 'jsx']
* @deprecated This option has been removed since v1.11.0 and will be deleted on next major version.
*/
babelParserPlugins?: ParserPlugin[]
babelParserPlugins?: never

/**
* Whether to disable pass logs feature.
Expand Down
32 changes: 0 additions & 32 deletions test/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,6 @@ describe('resolve options', () => {
it('empty', () => {
expect(resolveOptions({})).toMatchInlineSnapshot(`
{
"babelParserPlugins": [
"typescript",
"jsx",
],
"disableHighlight": false,
"disableLaunchEditor": false,
"disablePassLogs": false,
"extendedPathFileNames": [],
"port": 3070,
"prefix": "",
"silent": false,
"suffix": "",
}
`)
})

it('babel parser plugins', () => {
expect(resolveOptions({
babelParserPlugins: ['importAttributes', ['optionalChainingAssign', { version: '2023-07' }]],
})).toMatchInlineSnapshot(`
{
"babelParserPlugins": [
"typescript",
"jsx",
"importAttributes",
[
"optionalChainingAssign",
{
"version": "2023-07",
},
],
],
"disableHighlight": false,
"disableLaunchEditor": false,
"disablePassLogs": false,
Expand Down

0 comments on commit 61adfff

Please sign in to comment.