Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Each stage preset enables the more advanced stages #1971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions js/repl/Repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,13 @@ class Repl extends React.Component<Props, State> {
return {
runtimePolyfillState,
};
} else if (/^stage-[0-3]$/.test(name)) {
const changedStage = Number(name.slice(-1));
const stage = value ? changedStage : changedStage + 1;
for (let i = 0; i <= 3; i++) {
presets[`stage-${i}`].isEnabled = stage <= i;
}
return { presets };
} else if (state.hasOwnProperty(name)) {
return {
[name]: value,
Expand Down
47 changes: 29 additions & 18 deletions js/repl/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const DEFAULT_PRETTIER_CONFIG = {
useTabs: false,
};

const isStagePreset = n => typeof n === "string" && /^stage-[0-3]$/.test(n);

export default function compile(code: string, config: CompileConfig): Return {
const { envConfig, presetsOptions } = config;

Expand Down Expand Up @@ -86,30 +88,39 @@ export default function compile(code: string, config: CompileConfig): Return {
config.presets.push(["env", options]);
}

const actualPresets = config.presets.filter(n => !isStagePreset(n));
const stages = config.presets
.filter(isStagePreset)
.map(name => Number(name.slice(-1)))
.sort();

if (stages.length) {
const stage = stages[0];
const options = {};
const useOption = name => (options[name] = presetsOptions[name]);

switch (stage) {
case 0:
case 1:
useOption("pipelineProposal");
case 2:
useOption("decoratorsLegacy");
if (!options.decoratorsLegacy) useOption("decoratorsBeforeExport");
case 3:
}

actualPresets.push([`stage-${stage}`, options]);
}

console.log("PRESETS", actualPresets);

try {
const babelConfig = {
babelrc: false,
filename: "repl",
sourceMap: config.sourceMap,

presets: config.presets.map(preset => {
if (typeof preset === "string" && /^stage-[0-2]$/.test(preset)) {
const decoratorsLegacy = presetsOptions.decoratorsLegacy;
const decoratorsBeforeExport = decoratorsLegacy
? undefined
: presetsOptions.decoratorsBeforeExport;

return [
preset,
{
decoratorsLegacy,
decoratorsBeforeExport,
pipelineProposal: presetsOptions.pipelineProposal,
},
];
}
return preset;
}),
presets: actualPresets,
plugins: config.plugins,
sourceType: config.sourceType,
wrapPluginVisitorMethod: config.getTransitions
Expand Down