Skip to content

Commit

Permalink
fix: force non-legacy import attributes babel output (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Nov 26, 2024
1 parent 063fa5e commit 5d2b6c6
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 818 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
"dependencies": {
"@babel/core": "^7.25.2",
"@babel/core": "^7.26.0",
"@babel/plugin-transform-react-jsx-self": "^7.24.7",
"@babel/plugin-transform-react-jsx-source": "^7.24.7",
"@types/babel__core": "^7.20.5",
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
},
generatorOpts: {
...babelOptions.generatorOpts,
// import attributes parsing available without plugin since 7.26
importAttributesKeyword: 'with',
decoratorsBeforeExport: true,
},
plugins,
Expand Down
2 changes: 2 additions & 0 deletions playground/react/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Parent from './hmr/parent'
import { JsxImportRuntime } from './hmr/jsx-import-runtime'
import { CountProvider } from './context/CountProvider'
import { ContextButton } from './context/ContextButton'
import { TestImportAttributes } from './import-attributes/test'

function App() {
const [count, setCount] = useState(0)
Expand Down Expand Up @@ -40,6 +41,7 @@ function App() {
<Parent />
<JsxImportRuntime />
<Button>button</Button>
<TestImportAttributes />
</div>
)
}
Expand Down
4 changes: 4 additions & 0 deletions playground/react/__tests__/react.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ test.runIf(isServe)(
},
)

test('import attributes', async () => {
expect(await page.textContent('.import-attributes')).toBe('ok')
})

if (!isBuild) {
// #9869
test('should only hmr files with exported react components', async () => {
Expand Down
3 changes: 3 additions & 0 deletions playground/react/import-attributes/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "ok"
}
9 changes: 9 additions & 0 deletions playground/react/import-attributes/test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import data from './data.json' with { type: 'json' }

export function TestImportAttributes() {
return (
<div>
import-attirbutes: <span class="import-attributes">{data.message}</span>
</div>
)
}
Loading

0 comments on commit 5d2b6c6

Please sign in to comment.