-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update for naming convention wrappers
- Loading branch information
Showing
4 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters