Support for NumericLiteralSeparator, Stage 1 feature (#5793)
* Support for NumericLiteralSeparator, Stage 1 feature commit cd8f6e062876261a334d968f875e477a48927b6d Author: Sven SAULEAU <xtuc@users.noreply.github.com> Date: Wed May 31 16:14:15 2017 +0200 docs: update README [skip ci] commit cf013e3382bf73cdf9224026c1ec0b1a368cfef2 Author: Rick Waldron <waldron.rick@gmail.com> Date: Tue May 30 14:51:20 2017 -0400 Support for NumericLiteralSeparator, Stage 1 feature Signed-off-by: Rick Waldron <waldron.rick@gmail.com> Signed-off-by: Rick Waldron <waldron.rick@gmail.com> * add note about presets [skip ci]
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import syntaxNumericSeparator from "babel-plugin-syntax-numeric-separator";
|
||||
|
||||
export default function () {
|
||||
|
||||
function replacer(value) {
|
||||
return value.replace(/_/g, "");
|
||||
}
|
||||
|
||||
function replaceNumberArg({ node }) {
|
||||
if (node.callee.name === "Number") {
|
||||
node.arguments[0].value = replacer(node.arguments[0].value);
|
||||
}
|
||||
}
|
||||
|
||||
const CallExpression = replaceNumberArg;
|
||||
const NewExpression = replaceNumberArg;
|
||||
|
||||
return {
|
||||
inherits: syntaxNumericSeparator,
|
||||
|
||||
visitor: {
|
||||
CallExpression,
|
||||
NewExpression,
|
||||
NumericLiteral({ node }) {
|
||||
if (node.extra && /_/.test(node.extra.raw)) {
|
||||
node.value = replacer(node.extra.raw);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user