
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@lihautan/babel-plugin-transform-roman-numbers
Advanced tools
Roman numerals. Mandatory for floating point numbers.
— Bogdan Marinescu (@bogdanm78) July 22, 2020
OK, I'm a bit lazy over here. I just going to support only integer roman numerals.
The following is a valid JavaScript syntax:
let a = II;
b(VI);
as II is just a normal variable.
If the variable name is a roman numeric, we are going to transpile them into a number.
let a = 2;
b(6);
So it would work like JavaScript supports roman numeric.
Of course not all variable name are free to modify:
II(a);
const III = { IV: b };
class XI {
XC() {}
}
The above is a valid JS, but it does not make sense to turn them into number, as function call expression, variable declaration, class name and method does not allow number as the sole variable name.
2(a);
const 3 = { 4: b };
class 11 {
90() {}
}
Although { 4: b } looks valid. 🤔
I realised that the places of a variable can be interpreted as roman numeric is limited, so it's easier to whitelist those places rather than blacklist places it shouldn't be appear.
import { isValidRoman, romanToArab } from 'roman-numbers';
export default function ({ types: t }) {
return {
name: 'roman-numbers',
visitor: {
Identifier(path) {
const { parent, node } = path;
if (
// const a = II
(t.isVariableDeclarator(parent) && parent.init === node) ||
// { a: II }
(t.isObjectProperty(parent) && !parent.method) ||
// [II]
t.isArrayExpression(parent) ||
// const { a: b = II } = c
(t.isAssignmentExpression(parent) && parent.right === node) ||
// function a({ a: b = II }) {}
(t.isAssignmentPattern(parent) && parent.right === node) ||
// II + III
(t.isBinaryExpression(parent)) ||
// II++
(t.isUpdateExpression(parent))
) {
const name = node.name;
if (isValidRoman(name) && !path.scope.hasBinding(name)) {
path.replaceWith(t.numericLiteral(romanToArab(name)));
}
}
},
},
};
}
FAQs
## Inspiration
We found that @lihautan/babel-plugin-transform-roman-numbers 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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.