Babel plugin that compiles ES2015 unicode string and number literals to ES5
86
Build a command-line tool that transforms JavaScript files containing ES2015 numeric literals used in method calls and member expressions to ES5-compatible code.
Your tool should:
.toString(), .toFixed())Your program will receive a file path as the first command-line argument:
node src/index.js input.jsThe input file will contain JavaScript code with ES2015 numeric literal syntax (binary with 0b/0B prefix, octal with 0o/0O prefix) used in member expressions.
Your program should output the transformed JavaScript code to stdout, where:
0b1111) are converted to their decimal equivalents (e.g., 15)0o755) are converted to their decimal equivalents (e.g., 493)Input file content:
const result = 0b1111.toString();Expected output:
const result = (15).toString();0b1111 (15 in decimal) is used with .toString() method @testInput file content:
const value = 0o10.toFixed(2);Expected output:
const value = (8).toFixed(2);0o10 (8 in decimal) is used with .toFixed(2) method @testInput file content:
const a = 0B101.valueOf();
const b = 0O77.valueOf();Expected output:
const a = (5).valueOf();
const b = (63).valueOf();0B101 and octal 0O77 are transformed correctly @test@generates
// Your program should be executable as a Node.js script
// It reads a file path from process.argv[2]
// It outputs the transformed code to stdoutProvides the core Babel transformation API for parsing and generating JavaScript code.
Babel plugin that transforms ES2015 binary and octal numeric literals to ES5-compatible decimal format.
Install with Tessl CLI
npx tessl i tessl/npm-babel-plugin-transform-es2015-literalsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10