Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
esrefactor (BSD licensed) is a little helper library for ECMAScript refactoring.
With Node.js:
npm install esrefactor
In a browser, include first all the dependents:
<!-- esrefactor depends on these libraries -->
<script src="esprima.js"></src>
<script src="estraverse.js"></src>
<script src="escope.js"></src>
<script src="esrefactor.js"></src>
Before using the API, a context needs to be created:
var ctx = new esrefactor.Context(code);
where code
is the source code.
An identifier, whether it is a variable, a function name, or a function
parameter, can be identified using identify()
. Example:
var ctx = new esrefactor.Context('var x = 42; y = x * 2; z = x / 2');
var id = ctx.identify(4);
The only argument to identify
is the zero-based position index.
The return object has 3 (three) properties:
identifier
: the syntax node associated with the positiondeclaration
: the declaration syntax node for the identifierreferences
: an array of all identical referencesIf there is no declaration for the identifier (e.g. x = 42
, global
leak), then declaration
will be null.
The resolution of the declaration syntax node and the references array take into account the identifier scope as defined in the official ECMAScript 5.1 Specification (ECMA-262).
Note that if there is no identifier in the given position index,
identify()
will return undefined.
An identifier can be renamed using rename()
. All other identical references
associated with that identifier will be renamed as well, again taking into
account the proper identifier scope. Renaming works for variable declaration,
function name, and function parameter.
For rename()
to work, it needs to have the identification result
(via identify
) and the new name for the identifier.
var ctx = new esrefactor.Context('var x; x = 42');
var id = ctx.identify(4);
var code = ctx.rename(id, 'answer');
In the above example, code
is var answer; answer = 42
.
FAQs
ECMAScript refactoring helper
We found that esrefactor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.