Skip to content

Commit

Permalink
update for naming convention wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
wentout committed Aug 8, 2022
1 parent 9b9fa96 commit 2a4ab4e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build/api/types/compileNewModificatorFunctionBody.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare const compileNewModificatorFunctionBody: (FunctionName: string, asClass?: boolean) => Function;
declare const compileNewModificatorFunctionBody: (FunctionName: string, asClass?: boolean) => (ConstructHandler: any, CreationHandler: any, SymbolConstructorName: symbol) => any;
export default compileNewModificatorFunctionBody;
53 changes: 31 additions & 22 deletions build/api/types/compileNewModificatorFunctionBody.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value : true });
const getClassConstructor = (ConstructHandler, CreationHandler) => {
return class extends ConstructHandler {
constructor (...args) {
const answer = super(...args);
return CreationHandler.call(this, answer);
}
};
};
const getFunctionConstructor = (ConstructHandler, CreationHandler) => {
return function (...args) {
const answer = ConstructHandler.call(this, ...args);
return CreationHandler.call(this, answer);
};
};
const compileNewModificatorFunctionBody = function (FunctionName, asClass = false) {
const dt = `${Date.now()}_${`${Math.random()}`.split('.')[1]}`;
const modString = asClass ?
`class ${FunctionName} extends ConstructHandler_${dt} {
constructor(...args) {
const answer = super(...args);
return CreationHandler_${dt}.call(this, answer);
return function (ConstructHandler, CreationHandler, SymbolConstructorName) {
return function () {
let ModificationBody;
if (asClass) {
ModificationBody = getClassConstructor(ConstructHandler, CreationHandler);
}
}`
:
`const ${FunctionName} = function (...args) {
const answer = ConstructHandler_${dt}.call(this, ...args);
return CreationHandler_${dt}.call(this, answer);
};`;
return new Function(`ConstructHandler_${dt}`, `CreationHandler_${dt}`, 'SymbolConstructorName', `return function () {
${modString}
Object.defineProperty(${FunctionName}, SymbolConstructorName, {
else {
ModificationBody = getFunctionConstructor(ConstructHandler, CreationHandler);
}
ModificationBody.prototype.constructor = ModificationBody;
Object.defineProperty(ModificationBody.prototype.constructor, 'name', {
value : FunctionName,
writable : false
});
Object.defineProperty(ModificationBody, SymbolConstructorName, {
get () {
return '${FunctionName}';
return FunctionName;
}
});
return ${FunctionName};
return ModificationBody;
};
`);
};
};
exports.default = compileNewModificatorFunctionBody;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mnemonica",
"version": "0.9.943",
"version": "0.9.944",
"description": "abstract technique that aids information retention : instance inheritance system",
"type": "commonjs",
"main": "./build/index.js",
Expand Down
32 changes: 27 additions & 5 deletions src/api/types/compileNewModificatorFunctionBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
// the name of the function might be obfuscated during bundling
// therefore it seems to be more correct to implement using 'new Function'
// however, for better understanding of what is going on here
// I'd like to provide solution with preliminary compiled functions
// therefore considering we have open bug now:
// https://bugs.chromium.org/p/chromium/issues/detail?id=1350404
// related to the links below
// https://gist.github.com/wentout/5dcdd34f926460d89c8c1552d1bbc3d7
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
// we will use next solution as working code
// because this.constructor.name kept OK
// just the bug is for Chrome Dev Tools
// and as preliminary compiled functions solution works faster
// and does not require new code compilation
// we will keep it further
*/

const getClassConstructor = ( ConstructHandler: any, CreationHandler: any, ) => {
return class extends ConstructHandler {
constructor ( ...args: any[] ) {
const answer = super( ...args );
debugger;
// debugger;
return CreationHandler.call( this, answer );
}
};
Expand All @@ -32,7 +45,7 @@ const getClassConstructor = ( ConstructHandler: any, CreationHandler: any, ) =>
const getFunctionConstructor = ( ConstructHandler: any, CreationHandler: any, ) => {
return function ( this: any, ...args: any[] ) {
const answer = ConstructHandler.call( this, ...args );
debugger;
// debugger;
return CreationHandler.call( this, answer );
};
};
Expand Down Expand Up @@ -61,7 +74,12 @@ const compileNewModificatorFunctionBody = function ( FunctionName: string, asCla
};
};

*/
export default compileNewModificatorFunctionBody;

/*
// however, for better understanding of what is going on here
// I'd like to provide
const compileNewModificatorFunctionBody = function ( FunctionName: string, asClass: boolean = false ) {
Expand Down Expand Up @@ -101,3 +119,7 @@ const compileNewModificatorFunctionBody = function ( FunctionName: string, asCla
};
export default compileNewModificatorFunctionBody;
*/


0 comments on commit 2a4ab4e

Please sign in to comment.