Shift Refactor Plugin: Common methods
These are common utility methods. This is a plugin for shift-refactor
.
Installation
$ npm install refactor-plugin-common
Usage
const refactor = ;const commonMethods = ; const src = `/* js source */`; const $script = ;
API
Methods
debug()
compressConditonalExpressions()
compressCommaOperators()
convertComputedToStatic()
unshorten()
expandBoolean()
normalizeIdentifiers()
.debug()
Insert a debugger statement into a function.
Example
;
.compressConditonalExpressions()
Transform conditional expressions that have been reduced to testing only a literal value into the appropriate branch, e.g. var a = true ? 1 : 2;
into var a = 1;
Example
$script;
.compressCommaOperators()
For comma operator expressions that include literal values, eliminate all but the rightmost expression, e.g. var a = true, false, 1, 2, "hello";
into var a = "hello";
Example
$script;
.convertComputedToStatic()
Turn computed member expressions into static member expressions, e.g. window["document"]
into window.document
Example
$script;
.unshorten()
Remove declaration statements like var r = require;
and transform all references to the shortened identifier into the original.
Example
;
.expandBoolean()
Expands !1
and !0
into false
and true
Example
$script;
.normalizeIdentifiers()
Transform all identifiers into consistent, memorable identifiers like $$abruptBrother
Example
$script;