Skip to content

Commit

Permalink
fix(plugin-react-refresh): enable parsing for stage 3 and decorators …
Browse files Browse the repository at this point in the history
…syntax

close #1970
  • Loading branch information
yyx990803 committed Feb 10, 2021
1 parent df0e957 commit 565bcb4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
18 changes: 15 additions & 3 deletions packages/plugin-react-refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,23 @@ function reactRefreshPlugin(opts) {
/**
* @type ParserOptions["plugins"]
*/
const parserPlugins = ['jsx']
const parserPlugins = [
'jsx',
'importMeta',
// since the plugin now applies before esbuild transforms the code,
// we need to enable some stage 3 syntax since they are supported in
// TS and some environments already.
'topLevelAwait',
'classProperties',
'classPrivateProperties',
'classPrivateMethods'
]
if (/\.tsx?$/.test(id)) {
// it's a typescript file
parserPlugins.push('typescript')
// TODO: maybe we need to read tsconfig to determine parser plugins to
// enable here, but allowing decorators by default since it's very
// commonly used with TS.
parserPlugins.push('typescript', 'decorators-legacy')
}
if (opts && opts.parserPlugins) {
parserPlugins.push(...opts.parserPlugins)
Expand All @@ -99,7 +112,6 @@ function reactRefreshPlugin(opts) {
plugins: [
require('@babel/plugin-transform-react-jsx-self'),
require('@babel/plugin-transform-react-jsx-source'),
require('@babel/plugin-syntax-import-meta'),
[require('react-refresh/babel'), { skipEnvCheck: true }]
],
ast: !isReasonReact,
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-react-refresh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
},
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-react-refresh#readme",
"dependencies": {
"@babel/core": "^7.12.10",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-react-jsx-self": "^7.12.10",
"@babel/plugin-transform-react-jsx-source": "^7.12.10",
"@babel/core": "^7.12.13",
"@babel/plugin-transform-react-jsx-self": "^7.12.13",
"@babel/plugin-transform-react-jsx-source": "^7.12.13",
"react-refresh": "^0.9.0"
}
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
dependencies:
"@babel/highlight" "^7.12.13"

"@babel/core@^7.1.0", "@babel/core@^7.12.10", "@babel/core@^7.7.5":
"@babel/core@^7.1.0", "@babel/core@^7.12.10", "@babel/core@^7.12.13", "@babel/core@^7.7.5":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.13.tgz#b73a87a3a3e7d142a66248bf6ad88b9ceb093425"
integrity sha512-BQKE9kXkPlXHPeqissfxo0lySWJcYdEP0hdtJOH/iJfDdhOCcgtNCjftCJg3qqauB4h+lz2N6ixM++b9DN1Tcw==
Expand Down Expand Up @@ -366,14 +366,14 @@
dependencies:
"@babel/helper-plugin-utils" "^7.12.13"

"@babel/plugin-transform-react-jsx-self@^7.12.10":
"@babel/plugin-transform-react-jsx-self@^7.12.13":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.12.13.tgz#422d99d122d592acab9c35ea22a6cfd9bf189f60"
integrity sha512-FXYw98TTJ125GVCCkFLZXlZ1qGcsYqNQhVBQcZjyrwf8FEUtVfKIoidnO8S0q+KBQpDYNTmiGo1gn67Vti04lQ==
dependencies:
"@babel/helper-plugin-utils" "^7.12.13"

"@babel/plugin-transform-react-jsx-source@^7.12.10":
"@babel/plugin-transform-react-jsx-source@^7.12.13":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.12.13.tgz#051d76126bee5c9a6aa3ba37be2f6c1698856bcb"
integrity sha512-O5JJi6fyfih0WfDgIJXksSPhGP/G0fQpfxYy87sDc+1sFmsCS6wr3aAn+whbzkhbjtq4VMqLRaSzR6IsshIC0Q==
Expand Down

0 comments on commit 565bcb4

Please sign in to comment.