@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
44 lines (43 loc) • 1.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parser = void 0;
const parser_1 = require("@babel/parser");
const traverse_1 = __importDefault(require("@babel/traverse"));
const parser = (codes) => {
const hash = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
codes.forEach(code => {
const plugins = [
'typescript'
];
const ast = (0, parser_1.parse)(code, {
sourceType: 'module',
plugins
});
const visitor = visitorFn({
addType(key, node) {
hash[key] = node;
}
});
(0, traverse_1.default)(ast, visitor);
});
return hash;
};
exports.parser = parser;
const visitorFn = (parser) => ({
TSTypeAliasDeclaration(path) {
parser.addType(path.node.id.name, path.parentPath.node);
// if (path.node.id.name.endsWith('For_Empty')) {
// const newName = path.node.id.name.replace(/For_Empty$/, '_for_Empty');
// path.parentPath.node.declaration.id.name = newName;
// parser.addType(newName, path.parentPath.node);
// } else {
// parser.addType(path.node.id.name, path.parentPath.node);
// }
},
TSInterfaceDeclaration(path) {
parser.addType(path.node.id.name, path.parentPath.node);
}
});