tb-harmony-modern-ts/bblplugin.ts
2025-11-13 12:14:15 +01:00

25 lines
785 B
TypeScript

// Example from: https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-reserved-words/src/index.ts
import { declare } from "@babel/helper-plugin-utils";
import { types as t, type NodePath } from "@babel/core";
import { isIdentifierName } from "@babel/helper-validator-identifier";
const QT_SCRIPT_RESERVED_WORDS = new Set(["for"]);
function isQtScriptReservedWord(name: string): boolean {
return isIdentifierName(name) && QT_SCRIPT_RESERVED_WORDS.has(name);
}
export default declare((_api) => {
return {
name: "test",
visitor: {
Identifier(path: NodePath<t.Identifier>) {
if (isQtScriptReservedWord(path.node.name)) {
console.log(path.node.name);
path.scope.rename(path.node.name);
}
},
},
};
});