Socket
Socket
Sign inDemoInstall

@vitejs/plugin-react-swc

Package Overview
Dependencies
1
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.5.0 to 3.6.0

9

index.d.ts

@@ -1,2 +0,2 @@

import { JscTarget } from "@swc/core";
import { ParserConfig, JscTarget } from "@swc/core";
import { PluginOption } from "vite";

@@ -25,4 +25,11 @@ type Options = {

devTarget?: JscTarget;
/**
* Override the default include list (.ts, .tsx, .mts, .jsx, .mdx).
* This requires to redefine the config for any file you want to be included.
* If you want to trigger fast refresh on compiled JS, use `jsx: true`.
* Exclusion of node_modules should be handled by the function if needed.
*/
parserConfig?: (id: string) => ParserConfig | undefined;
};
declare const react: (_options?: Options) => PluginOption[];
export default react;

4

package.json
{
"name": "@vitejs/plugin-react-swc",
"description": "Speed up your Vite dev server with SWC",
"version": "3.5.0",
"version": "3.6.0",
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",

@@ -31,4 +31,4 @@ "license": "MIT",

"dependencies": {
"@swc/core": "^1.3.96"
"@swc/core": "^1.3.107"
}
}

@@ -59,3 +59,3 @@ # @vitejs/plugin-react-swc [![npm](https://img.shields.io/npm/v/@vitejs/plugin-react-swc)](https://www.npmjs.com/package/@vitejs/plugin-react-swc)

## plugins
### plugins

@@ -68,3 +68,3 @@ Use SWC plugins. Enable SWC at build time.

## devTarget
### devTarget

@@ -81,2 +81,19 @@ Set the target for SWC in dev. This can avoid to down-transpile private class method for example.

### parserConfig
Override the default include list (.ts, .tsx, .mts, .jsx, .mdx).
This requires to redefine the config for any file you want to be included (ts, mdx, ...).
If you want to trigger fast refresh on compiled JS, use `jsx: true`. Exclusion of node_modules should be handled by the function if needed. Using this option to use JSX inside `.js` files is highly discouraged and can be removed in any future version.
```ts
react({
parserConfig(id) {
if (id.endsWith(".res")) return { syntax: "ecmascript", jsx: true };
if (id.endsWith(".ts")) return { syntax: "typescript", tsx: false };
},
});
```
## Consistent components exports

@@ -83,0 +100,0 @@

@@ -20,5 +20,5 @@ /*! Copyright (c) Meta Platforms, Inc. and affiliates. **/

let fullKey = signature.ownKey;
let hooks;
let hooks2;
try {
hooks = signature.getCustomHooks();
hooks2 = signature.getCustomHooks();
} catch (err) {

@@ -29,4 +29,4 @@ signature.forceReset = true;

}
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
for (let i = 0; i < hooks2.length; i++) {
const hook = hooks2[i];
if (typeof hook !== "function") {

@@ -394,8 +394,26 @@ signature.forceReset = true;

}
const enqueueUpdate = debounce(performReactRefresh, 16);
function validateRefreshBoundaryAndEnqueueUpdate(prevExports, nextExports) {
if (!predicateOnExport(prevExports, (key) => key in nextExports)) {
const hooks = [];
window.__registerBeforePerformReactRefresh = (cb) => {
hooks.push(cb);
};
const enqueueUpdate = debounce(async () => {
if (hooks.length)
await Promise.all(hooks.map((cb) => cb()));
performReactRefresh();
}, 16);
function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
var _a, _b;
const ignoredExports = (_b = (_a = window.__getReactRefreshIgnoredExports) == null ? void 0 : _a.call(window, { id })) != null ? _b : [];
if (predicateOnExport(
ignoredExports,
prevExports,
(key) => key in nextExports
) !== true) {
return "Could not Fast Refresh (export removed)";
}
if (!predicateOnExport(nextExports, (key) => key in prevExports)) {
if (predicateOnExport(
ignoredExports,
nextExports,
(key) => key in prevExports
) !== true) {
return "Could not Fast Refresh (new export)";

@@ -405,2 +423,3 @@ }

const allExportsAreComponentsOrUnchanged = predicateOnExport(
ignoredExports,
nextExports,

@@ -414,17 +433,19 @@ (key, value) => {

);
if (hasExports && allExportsAreComponentsOrUnchanged) {
if (hasExports && allExportsAreComponentsOrUnchanged === true) {
enqueueUpdate();
} else {
return "Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react-swc#consistent-components-exports";
return `Could not Fast Refresh ("${allExportsAreComponentsOrUnchanged}" export is incompatible). Learn more at https://github.com/vitejs/vite-plugin-react-swc#consistent-components-exports`;
}
}
function predicateOnExport(moduleExports, predicate) {
function predicateOnExport(ignoredExports, moduleExports, predicate) {
for (const key in moduleExports) {
if (key === "__esModule")
continue;
if (ignoredExports.includes(key))
continue;
const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
if (desc && desc.get)
return false;
return key;
if (!predicate(key, moduleExports[key]))
return false;
return key;
}

@@ -431,0 +452,0 @@ return true;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc