Skip to content

Commit 5d2b6c6

Browse files
authored
fix: force non-legacy import attributes babel output (#386)
1 parent 063fa5e commit 5d2b6c6

File tree

7 files changed

+364
-818
lines changed

7 files changed

+364
-818
lines changed

packages/plugin-react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
4040
"dependencies": {
41-
"@babel/core": "^7.25.2",
41+
"@babel/core": "^7.26.0",
4242
"@babel/plugin-transform-react-jsx-self": "^7.24.7",
4343
"@babel/plugin-transform-react-jsx-source": "^7.24.7",
4444
"@types/babel__core": "^7.20.5",

packages/plugin-react/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
249249
},
250250
generatorOpts: {
251251
...babelOptions.generatorOpts,
252+
// import attributes parsing available without plugin since 7.26
253+
importAttributesKeyword: 'with',
252254
decoratorsBeforeExport: true,
253255
},
254256
plugins,

playground/react/App.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Parent from './hmr/parent'
55
import { JsxImportRuntime } from './hmr/jsx-import-runtime'
66
import { CountProvider } from './context/CountProvider'
77
import { ContextButton } from './context/ContextButton'
8+
import { TestImportAttributes } from './import-attributes/test'
89

910
function App() {
1011
const [count, setCount] = useState(0)
@@ -40,6 +41,7 @@ function App() {
4041
<Parent />
4142
<JsxImportRuntime />
4243
<Button>button</Button>
44+
<TestImportAttributes />
4345
</div>
4446
)
4547
}

playground/react/__tests__/react.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ test.runIf(isServe)(
6969
},
7070
)
7171

72+
test('import attributes', async () => {
73+
expect(await page.textContent('.import-attributes')).toBe('ok')
74+
})
75+
7276
if (!isBuild) {
7377
// #9869
7478
test('should only hmr files with exported react components', async () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"message": "ok"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import data from './data.json' with { type: 'json' }
2+
3+
export function TestImportAttributes() {
4+
return (
5+
<div>
6+
import-attirbutes: <span class="import-attributes">{data.message}</span>
7+
</div>
8+
)
9+
}

0 commit comments

Comments
 (0)