Skip to content

Commit

Permalink
[babel 8] Deprecate uppercase builders
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 14, 2025
1 parent 6f27075 commit d96c220
Show file tree
Hide file tree
Showing 2 changed files with 303 additions and 270 deletions.
42 changes: 30 additions & 12 deletions packages/babel-types/scripts/generators/builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,37 @@ function generateUppercaseBuilders() {
* To re-generate run 'make build'
*/
export {\n`;

Object.keys(BUILDER_KEYS).forEach(type => {
const formattedBuilderName = formatBuilderName(type);
output += ` ${formattedBuilderName} as ${type},\n`;
});

Object.keys(DEPRECATED_KEYS).forEach(type => {
const formattedBuilderName = formatBuilderName(type);
output += ` ${formattedBuilderName} as ${type},\n`;
});
import * as b from "./lowercase.ts";
import deprecationWarning from "../../utils/deprecationWarning.ts";
function alias<const N extends keyof typeof b>(lowercase: N): typeof b[N] {
if (process.env.BABEL_8_BREAKING) {
return function () {
deprecationWarning(
lowercase.replace(/^[a-z]+/, x => x.toUpperCase()),
lowercase
);
return (b[lowercase] as any)(...arguments);
} as any;
} else {
return b[lowercase];
}
}
export const\n`;
output += Object.keys(BUILDER_KEYS)
.map(type => ` ${type} = alias("${formatBuilderName(type)}")`)
.join(",\n");
output += `;\n`;

if (!process.env.BABEL_8_BREAKING) {
output += `export const\n`;
output += Object.keys(DEPRECATED_KEYS)
.map(type => ` ${type} = b.${formatBuilderName(type)}`)
.join(",\n");
output += `;\n`;
}

output += ` } from './lowercase.ts';\n`;
return output;
}

Expand Down
Loading

0 comments on commit d96c220

Please sign in to comment.