Skip to content

Commit

Permalink
Merge pull request #52 from unplugin/feat/oxc-parser
Browse files Browse the repository at this point in the history
* chore: update playground

* feat: oxc-parser

* chore: mark `babelParserPlugins` option as deprecated

* feat: oxc-parser

* chore: lint error

* fix: use oxc-parser builtin MagicString
  • Loading branch information
yuyinws authored Dec 11, 2024
2 parents 7a3a65c + ecaa347 commit 16b310c
Show file tree
Hide file tree
Showing 22 changed files with 1,350 additions and 764 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)
6 changes: 5 additions & 1 deletion examples/vite-vue3/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { logTs } from './tsLog'
import { server } from 'unplugin-turbo-console/helper'
function logVue() {
console.log('from vue')
}
function serverLog() {
server.log('from vue')
}
</script>
Expand All @@ -27,7 +31,7 @@ function logVue() {
</h2>

<div style="display: flex; gap: 10px;">
<button @click="logVue">Client -> Server</button>
<button @click="serverLog">Client -> Server</button>
</div>
</template>

Expand Down
2 changes: 1 addition & 1 deletion examples/vite-vue3/src/jsLog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function logJs() {
console.log('from js')
console.log('from js') // turbo-console-disable-line
}

3 changes: 2 additions & 1 deletion examples/vite-vue3/src/tsLog.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function logTs() {
console.log('from ts')
const a = '你好'
console.log(a)
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,20 @@
},
"dependencies": {
"@rollup/pluginutils": "^5.1.2",
"ast-kit": "^1.2.0",
"estree-walker": "^3.0.3",
"get-port-please": "^3.1.2",
"h3": "1.12.0",
"launch-editor": "^2.9.1",
"magic-string": "^0.30.11",
"oxc-parser": "^0.40.1",
"pathe": "^1.1.2",
"unplugin": "^1.14.1"
},
"devDependencies": {
"@antfu/eslint-config": "^3.7.1",
"@babel/types": "^7.25.6",
"@nuxt/kit": "^3.13.2",
"@nuxt/schema": "^3.13.2",
"@oxc-project/types": "^0.38.0",
"@types/fs-extra": "^11.0.4",
"@types/node": "^22.7.0",
"@vitest/ui": "^2.1.1",
Expand Down
Loading

0 comments on commit 16b310c

Please sign in to comment.