Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
6to5 turns ES6 code into vanilla ES5, so you can use ES6 features today.
It's as easy as:
$ npm install -g 6to5
To be implemented:
Compile the file script.js
and output it to stdout.
$ 6to5 script.js
Compile the file script.js
and output it to script-compiled.js
.
$ 6to5 script.js --out-file script-compiled.js
Compile the file script.js
and output it to script-compiled.js
and save a
source map to script-compiled.js.map
.
$ 6to5 script.js --source-maps --out-file script-compiled.js
Compile the file script.js
and output it to script-compiled.js
with a source
map embedded in a comment at the bottom.
$ 6to5 script.js --source-maps-comment --out-file script-compiled.js
Compile the entire src
directory and output it to the lib
directory.
$ 6to5 src --out-dir lib
Launch a repl.
$ 6to5-node
Evaluate code.
$ 6to5-node -e "class Test { }"
Compile and run test.js
.
$ 6to5-node test
var to5 = require("6to5");
to5.transform("code();", options);
to5.transformFileSync("filename.js", options);
to5.transformFile("filename.js", options, function (err, data) {
});
{
// List of transformers to EXCLUDE
// This is a camelised version of the name found in `features`
// eg. "Arrow functions" is "arrowFunctions"
blacklist: [],
// List of transformers to ONLY use.
// See `blacklist` for naming scheme.
whitelist: [],
// Append source map and comment to bottom of returned output.
sourceMap: false,
// Returns an object `{ code: "", map: {} }` instead of an appended string.
sourceMapObject: false,
// Filename for use in errors etc.
filename: "unknown",
// Format options
// See https://github.com/Constellation/escodegen/wiki/API for options.
format: {}
}
All subsequent files required by node will be transformed by 6to5. An ES6 polyfill is also required negating the polyfill caveat.
require("6to5/register");
6to5 does not include a runtime nor polyfill and it's up to the developer to include one in compiled browser code.
A polyfill is included with 6to5 code that can be included in node like so:
require("6to5/polyfill");
This is simply a wrapper around the es6-shim and es6-symbol polyfills.
When using the require hook the aforementioned polyfill is automatically required.
If you're planning on using 6to5 output in the browser then it's up to you to include polyfills. es6-symbol and es6-shim fill the vast majority of polyfill concerns.
A polyfill is required for for-of functionality that implements Symbol
and
adds prototype[Symbol.iterator]
behaviour to built-ins. Using the polyfills
specified in polyfill suffices.
Built-in classes such as Date
, Array
and DOM
cannot be subclassed due to
limitations in ES5 implementations.
6to5 | Traceur | esnext | es6now | es6-transpiler | |
---|---|---|---|---|---|
No runtime | ✓ | ✓ | |||
Source maps | ✓ | ✓ | ✓ | ✓ | |
No compiler global pollution | ✓ | ✓ | ✓ | ||
Array comprehension | ✓ | ✓ | ✓ | ✓ | |
Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ |
Block binding | ✓ | ✓ | ✓ | ||
Classes | ✓ | ✓ | ✓ | ✓ | ✓ |
Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ |
Constants | ✓ | ✓ | ✓ | ||
Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ |
Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ |
For-of | ✓ | ✓ | ✓ | ✓ | ✓ |
Generator comprehension | ✓ | ✓ | ✓ | ||
Generators | ✓ | ✓ | |||
Modules | ✓ | ✓ | ✓ | ||
Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ |
Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ |
Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ |
Spread | ✓ | ✓ | ✓ | ✓ | ✓ |
Template literals | ✓ | ✓ | ✓ | ✓ | ✓ |
To run benchmarks against various transpilers run:
$ make bench
The following graphs are using the full benchmark fixture.
Lower is better.
Higher is better.
Traceur requires quite a bulky runtime (~75KB) and produces quite verbose code. While this can be trimmed down by selectively building the runtime, it's an unneccesary step when a runtime can be eliminated entirely.
esnext is slow, painfully so. See performance for stats.
es6now doesn't output sourcemaps. This is cited as a positive as line-to-line mapping is the goal. This however obviously doesn't retain column mapping resulting in the output code not being very pleasant.
The es6-transpiler compiler requires shims to operate which pollutes the global scope resulting in possible collisions.
es6-transpiler maps line-by-line, just like es6now, this results in the same issues such as lack of column information and unpleasant code output.
FAQs
Turn ES6 code into readable vanilla ES5 with source maps
The npm package 6to5 receives a total of 609 weekly downloads. As such, 6to5 popularity was classified as not popular.
We found that 6to5 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.