MCPcopy Index your code
hub / github.com/material-shell/material-shell / transpile

Function transpile

scripts/transpile.ts:242–304  ·  view source on GitHub ↗
(ast: BaseNode)

Source from the content-addressed store, hash-verified

240 return text;
241}
242function transpile(ast: BaseNode) {
243 let insideClass = false;
244 let decoratedClasses = [];
245
246 // Find all classes that have been decorated with @registerGObjectClass
247 walk(ast, {
248 enter: function (node, parent, prop, index) {
249 let decoratedNames = getDecoratorTargets(node);
250 if (decoratedNames !== null) {
251 for (let name of decoratedNames) {
252 decoratedClasses.push(name);
253 }
254 }
255 },
256 leave: function (node, parent, prop, index) {},
257 });
258
259 walk(ast, {
260 enter: function (node, parent, prop, index) {
261 if (isClassExpression(node)) {
262 if (decoratedClasses.indexOf(node.id.name) !== -1) {
263 insideClass = true;
264 }
265 }
266
267 if (insideClass) {
268 if (isMethodDefinition(node) && node.kind == 'constructor') {
269 if (isIdentifier(node.key)) {
270 // We have found a constructor, change it to a normal method named `_init`
271 node.kind = 'method';
272 node.key.name = '_init';
273 }
274 }
275 if (isSimpleCallExpression(node)) {
276 if (node.callee.type == 'Super') {
277 // We found a `super(...)` call
278 // Change it to `super._init(...)`
279 node.callee = {
280 type: 'MemberExpression',
281 object: node.callee,
282 property: {
283 type: 'Identifier',
284 name: '_init',
285 },
286 computed: false,
287 optional: false,
288 };
289 }
290 }
291 }
292 },
293 leave: function (node, parent, prop, index) {
294 if (isClassExpression(node)) {
295 if (decoratedClasses.indexOf(node.id.name) !== -1) {
296 console.assert(insideClass);
297 insideClass = false;
298 }
299 }

Callers 2

testFunction · 0.85
transpile.tsFile · 0.85

Calls 7

getDecoratorTargetsFunction · 0.85
isClassExpressionFunction · 0.85
isMethodDefinitionFunction · 0.85
isIdentifierFunction · 0.85
isSimpleCallExpressionFunction · 0.85
assertMethod · 0.80
pushMethod · 0.65

Tested by 1

testFunction · 0.68