1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-09-29 09:38:59 +02:00

this rename is absolutely stupid

This commit is contained in:
Pomax
2020-08-20 13:01:32 -07:00
parent 59fdafb2c5
commit d92e370bd1
470 changed files with 22 additions and 9 deletions

View File

@@ -0,0 +1,33 @@
import { GraphicsAPI } from "../api/graphics-api.js";
export default function performCodeSurgery(code) {
// 1. ensure that anything that needs to run by first calling its super function, does so.
GraphicsAPI.superCallers.forEach((name) => {
const re = new RegExp(`${name}\\(([^)]*)\\)[\\s\\r\\n]*{[\\s\\r\\n]*`, `g`);
code = code.replace(re, `${name}($1) { super.${name}($1);\n`);
});
// 2. rewrite event handlers so that they capture the event and forward it to the super function.
GraphicsAPI.eventHandlers.forEach((name) => {
const re = new RegExp(`\\b${name}\\(\\)[\\s\\r\\n]*{[\\s\\r\\n]*`, `g`);
code = code.replace(re, `${name}(evt) { super.${name}(evt);\n`);
});
// 3. rewrite all public GraphicsAPI functions to have the required `this.` prefix
GraphicsAPI.methods.forEach((fn) => {
const re = new RegExp(`([\\s\\r\\n])${fn}\\(`, `g`);
code = code.replace(re, `$1this.${fn}(`);
});
// 4. do the same for all GraphicsAPI constants.
GraphicsAPI.constants.forEach((name) => {
const re = new RegExp(`(\\b)${name}(\\b)`, `g`);
code = code.replace(re, `$1this.${name}$2`);
});
return code;
}