Skip to content

Commit 950d49b

Browse files
authored
fix: Add default options for other external official plugins (#3117)
1 parent 32dad61 commit 950d49b

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed

website/src/components/repl/Repl.tsx

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import {
3232
persistedStateToPresetsOptions,
3333
persistedStateToShippedProposalsState,
3434
persistedStateToExternalPluginsState,
35+
provideDefaultOptionsForExternalPlugins,
3536
} from "./replUtils";
3637
import WorkerApi from "./WorkerApi";
3738
import scopedEval from "./scopedEval";
3839
import { media } from "./styles";
40+
import { toCamelCase, hasOwnProperty } from "./Utils";
3941

4042
import type {
4143
BabelPresets,
@@ -83,53 +85,6 @@ type State = {
8385

8486
const DEBOUNCE_DELAY = 500;
8587

86-
function toCamelCase(str) {
87-
return str
88-
.replace(/-/g, " ")
89-
.replace(/\//g, "_")
90-
.replace(/@/g, "_")
91-
.replace(/\s(.)/g, function ($1) {
92-
return $1.toUpperCase();
93-
})
94-
.replace(/\s/g, "")
95-
.replace(/^(.)/, function ($1) {
96-
return $1.toLowerCase();
97-
});
98-
}
99-
100-
function hasOwnProperty(obj, string) {
101-
return Object.prototype.hasOwnProperty.call(obj, string);
102-
}
103-
104-
function provideDefaultOptionsForExternalPlugins(pluginName, babelVersion) {
105-
switch (pluginName) {
106-
case "@babel/plugin-proposal-decorators": {
107-
if (compareVersions(babelVersion, "7.24.0") >= 0) {
108-
return { version: "2023-11" };
109-
} else if (compareVersions(babelVersion, "7.22.0") >= 0) {
110-
return { version: "2023-05" };
111-
} else if (compareVersions(babelVersion, "7.21.0") >= 0) {
112-
return { version: "2023-01" };
113-
} else if (compareVersions(babelVersion, "7.19.0") >= 0) {
114-
return { version: "2022-03" };
115-
} else if (compareVersions(babelVersion, "7.17.0") >= 0) {
116-
return { version: "2021-12" };
117-
} else if (compareVersions(babelVersion, "7.0.0") >= 0) {
118-
return { version: "2018-09", decoratorsBeforeExport: true };
119-
}
120-
}
121-
case "@babel/plugin-proposal-pipeline-operator": {
122-
if (compareVersions(babelVersion, "7.15.0") >= 0) {
123-
return { proposal: "hack", topicToken: "%" };
124-
} else {
125-
return { proposal: "minimal" };
126-
}
127-
}
128-
default:
129-
return {};
130-
}
131-
}
132-
13388
class Repl extends React.Component<Props, State> {
13489
_numLoadingPlugins = 0;
13590
_workerApi = new WorkerApi();

website/src/components/repl/Utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,21 @@ export function compareVersions(a: string, b: string): 1 | 0 | -1 {
5353
}
5454
return 0;
5555
}
56+
57+
export function toCamelCase(str) {
58+
return str
59+
.replace(/-/g, " ")
60+
.replace(/\//g, "_")
61+
.replace(/@/g, "_")
62+
.replace(/\s(.)/g, function ($1) {
63+
return $1.toUpperCase();
64+
})
65+
.replace(/\s/g, "")
66+
.replace(/^(.)/, function ($1) {
67+
return $1.toLowerCase();
68+
});
69+
}
70+
71+
export function hasOwnProperty(obj, string) {
72+
return Object.prototype.hasOwnProperty.call(obj, string);
73+
}

website/src/components/repl/replUtils.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { envPresetDefaults, replDefaults } from "./PluginConfig";
22
import StorageService from "./StorageService";
33
import UriUtils from "./UriUtils";
4+
import { compareVersions } from "./Utils";
45

56
import type {
67
BabelState,
@@ -219,3 +220,38 @@ export const persistedStateToExternalPluginsState = (
219220
return { name, version };
220221
});
221222
};
223+
224+
export function provideDefaultOptionsForExternalPlugins(pluginName, babelVersion) {
225+
switch (pluginName) {
226+
case "@babel/plugin-proposal-decorators": {
227+
if (compareVersions(babelVersion, "7.24.0") >= 0) {
228+
return { version: "2023-11" };
229+
} else if (compareVersions(babelVersion, "7.22.0") >= 0) {
230+
return { version: "2023-05" };
231+
} else if (compareVersions(babelVersion, "7.21.0") >= 0) {
232+
return { version: "2023-01" };
233+
} else if (compareVersions(babelVersion, "7.19.0") >= 0) {
234+
return { version: "2022-03" };
235+
} else if (compareVersions(babelVersion, "7.17.0") >= 0) {
236+
return { version: "2021-12" };
237+
} else if (compareVersions(babelVersion, "7.0.0") >= 0) {
238+
return { version: "2018-09", decoratorsBeforeExport: true };
239+
}
240+
}
241+
case "@babel/plugin-proposal-discard-binding": {
242+
return { syntaxType: "void" };
243+
}
244+
case "@babel/plugin-proposal-optional-chaining-assign": {
245+
return { version: "2023-07" };
246+
}
247+
case "@babel/plugin-proposal-pipeline-operator": {
248+
if (compareVersions(babelVersion, "7.15.0") >= 0) {
249+
return { proposal: "hack", topicToken: "%" };
250+
} else {
251+
return { proposal: "minimal" };
252+
}
253+
}
254+
default:
255+
return {};
256+
}
257+
}

0 commit comments

Comments
 (0)