diff --git a/CHANGELOG.md b/CHANGELOG.md index d3736834d9..160dc49ee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,46 @@ Gaps between patch versions are faulty/broken releases. +## 2.0.0 + + * Make string literal generation only escapes unicode that it has to. + * Internal code generation format options have been exposed. + * Change playground method binding operator from `:` to `#` removing ambiguous syntax with terns. + * Fix rest parameters in async and generator functions. + * Export/import declarations replace by the modules transformer now inherit comments. + * Added playground flag to `6to5-node`. + * `6to5-node` now behaves the same as `node`. + * `6to5-node` now uses `kexec` to become the forked process to correctly propagate signals on unix. + * Constants are now block scoped. + * Exposed ast transformer. + * Merged `commonInterop` and `common` module formatters. + * Fix generator comprehensions not inheriting `arguments`, `this` etc. + * Object and class mutator shorthand are now enumerable. + * Remove regenerator `Generator has already finished` error which isn't spec-compliant. + * Expose internal `spec` transformers that nicen up code output. + * Add export variable declaration default initializers. + * Propagate export declaration reassignments. + * Add initializer default to block scoped variable declarations within a loop. + * Flow type support. + * Make async/await contextual keywords. + * Allow `yield`ing of non-objects. + * Class declarations now lack an IIFE. + * Support falsy and `null` super classes. + * Add support for experimental abstract references `private` declarations. + * Leave out IIFE for class declarations. + * Switched to [core-js](https://github.com/zloirock/core-js) from [es6-symbol](https://github.com/medikoo/es6-symbol) and [es6-shim](https://github.com/paulmillr/es6-shim/) for built-in polyfill. + * `amd` and `umd` module formatters now behave the same as `common` with `interopRequire`. + * Micro-optimizations to boost performance by 200%. + * Rename module formatter methods `import` to `importDeclaration` and `export` to `exportDeclaration`. + * Support multiple declarators in export variable declarations. + * Freeze tagged template literal object. + * Remove inlined `regenerator` fork. + * Remove `ParenthesizedExpression`. + * Rename `object-spread` helper to `object-without-properties`. + * Rename `class-props` helper to `prototype-properties`. + * Rename `extends` helper to `inherits`. + * Completely rewritten `system` module formatter. + ## 1.15.0 * Don't alias `GeneratorFunction` and check the name which causes minifiers to remove the name and throw an error later on when we check if it's set. diff --git a/README.md b/README.md index d1f2e07244..eb4bb860c0 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@
+
+
+
+
@@ -24,7 +28,11 @@
+ 6to5 turns ES6+ code into vanilla ES5, so you can use next generation features today. +
-For more information view the [documentation](https://6to5.github.io). For -support visit the [gitter room](https://gitter.im/6to5/6to5). ++ For more information view the documentation. For + support visit the gitter room. +
diff --git a/benchmark/index.js b/benchmark/index.js index c7d04b1b65..f0f820081d 100644 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -2,9 +2,9 @@ Error.stackTraceLimit = Infinity; var jsTrans = require("jstransform"); var traceur = require("traceur"); -var es6tr = require("es6-transpiler"); +//var es6tr = require("es6-transpiler"); var es6now = require("es6now"); -var esnext = require("esnext"); +//var esnext = require("esnext"); var to5 = require("../lib/6to5"); //var uglify = require("uglify-js"); @@ -56,12 +56,12 @@ var compilers = { } }, - esnext: { + /*esnext: { runtime: readResolve("esnext/node_modules/regenerator/runtime.js") || readResolve("regenerator/runtime.js"), compile: function (code) { return esnext.compile(code).code; } - }, + },*/ es6now: { runtime: readResolve("es6now/runtime/ES6.js"), @@ -70,13 +70,13 @@ var compilers = { } }, - "es6-transpiler": { + /*"es6-transpiler": { compile: function (code) { var result = es6tr.run({ src: code }); if (result.errors.length) throw new Error(result.join("; ")); return result.src; } - }, + },*/ jstransform: { compile: function (code) { diff --git a/bin/6to5/file.js b/bin/6to5/file.js index 73c0f19a7f..a06bf304ea 100644 --- a/bin/6to5/file.js +++ b/bin/6to5/file.js @@ -113,16 +113,14 @@ module.exports = function (commander, filenames) { walk(); if (commander.watch) { - var watcher = chokidar.watch(filenames, { + chokidar.watch(filenames, { persistent: true, ignoreInitial: true - }); - - _.each(["add", "change", "unlink"], function (type) { - watcher.on(type, function (filename) { + }).on("all", function (type, filename) { + if (type === "add" || type === "change" || type === "unlink" ) { console.log(type, filename); walk(); - }); + } }); } }; diff --git a/bin/_6to5-node b/bin/_6to5-node index 2133bf156e..842ebd666b 100644 --- a/bin/_6to5-node +++ b/bin/_6to5-node @@ -1,12 +1,14 @@ #!/usr/bin/env node -var commander = require("commander"); -var path = require("path"); -var repl = require("repl"); -var to5 = require("../lib/6to5"); -var util = require("../lib/6to5/util"); -var vm = require("vm"); -var _ = require("lodash"); +var roadrunner = require("roadrunner"); +var commander = require("commander"); +var Module = require("module"); +var path = require("path"); +var repl = require("repl"); +var to5 = require("../lib/6to5"); +var util = require("../lib/6to5/util"); +var vm = require("vm"); +var _ = require("lodash"); commander.option("-e, --eval [script]", "Evaluate script"); commander.option("-p, --print", "Evaluate script and print result"); @@ -14,28 +16,33 @@ commander.option("-i, --ignore [regex]", "Ignore all files that match this regex commander.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]"); commander.option("-r, --experimental", "Enable experimental support for proposed ES7 features"); commander.option("-g, --playground", "Enable playground support"); +commander.option("-c, --cache", "Cache compiled files and require paths"); var pkg = require("../package.json"); commander.version(pkg.version); commander.usage("[options] [ -e script | script.js ] [arguments]"); commander.parse(process.argv); +if (commander.cache) roadrunner.load(); + // to5.register({ experimental: commander.experimental, extensions: commander.extensions, - ignore: commander.ignore + playground: commander.playground, + ignore: commander.ignore, + cache: commander.cache && roadrunner.get("6to5") }); // var _eval = function (code, filename) { code = to5.transform(code, { - modules: "commonInterop", filename: filename, blacklist: ["useStrict"], - experimental: commander.experimental + experimental: commander.experimental, + playground: commander.playground }).code; return vm.runInThisContext(code, filename); }; @@ -44,21 +51,34 @@ if (commander.eval) { var result = _eval(commander.eval, "eval"); if (commander.print) console.log(result); } else { - var filenames = commander.args; + if (commander.args.length) { + // slice all arguments up to the first filename since they're 6to5 args that we handle + var args = process.argv.slice(2); - if (filenames.length) { - _.each(filenames, function (filename) { - if (!util.isAbsolute(filename)) { - filename = path.join(process.cwd(), filename); + var i = 0; + _.each(args, function (arg, i2) { + if (arg[0] !== "-") { + i = i2; + return false; } - - require(require.resolve(filename)); }); + args = args.slice(i); + + // make the filename absolute + var filename = args[0] + if (!util.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename); + + // add back on node and concat the sliced args + process.argv = ["node"].concat(args); + + Module.runMain(); } else { replStart(); } } +if (commander.cache) roadrunner.save(); + function replStart() { repl.start({ prompt: "> ", diff --git a/doc/caveats.md b/doc/caveats.md index 269d114207..67fd0d0a7b 100644 --- a/doc/caveats.md +++ b/doc/caveats.md @@ -2,22 +2,31 @@ In order for certain features to work they require certain polyfills. You can satisfy **all** 6to5 feature requirements by using the included -[polyfill](polyfill.md). You may alternatively selectively include what you need: +[polyfill](polyfill.md). -| Feature | Requirements | -| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -| Abstract References | [experimental](usage.md#experimental), `Symbol` | -| Array destructuring | `Array.isArray`, `Array.from` | -| Async functions, Generators | [experimental](usage.md#experimental), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) | -| Comprehensions | [experimental](usage.md#experimental), `Array.isArray`, `Array.from` | -| For Of | `Symbol`, `prototype[Symbol.iterator]` | -| Object spread/rest | [experimental](usage.md#experimental), `Object.assign` | -| Spread | `Array.isArray`, `Array.from` | +You may alternatively selectively include what you need: -## Classes +| Feature | Requirements | +| --------------------------- | ---------------------------------------------------------------------------------------------------------------------- | +| Abstract References | [experimental](experimental.md), `Symbol` | +| Array destructuring | `Array.isArray`, `Array.from` | +| Async functions, Generators | [experimental](experimental.md), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) | +| Comprehensions | [experimental](experimental.md), `Array.isArray`, `Array.from` | +| For Of | `Symbol`, `prototype[Symbol.iterator]` | +| Object spread/rest | [experimental](experimental.md), `Object.assign` | +| Spread | `Array.isArray`, `Array.from` | -Built-in classes such as `Date`, `Array` and `DOM` cannot be subclassed due to -limitations in ES5 implementations. +## ES5 + +Since 6to5 assumes that your code will be ran in an ES5 environment it uses ES5 +functions. So if you're using an environment that has limited or no support for +ES5 such as lower versions of IE then using the +[es5-shim](https://github.com/es-shims/es5-shim) along with the +[6to5 polyfill](polyfill.md) will add support for these methods. + +## Internet Explorer + +### Classes (9 and below) If you're inheriting from a class then static properties are inherited from it via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto), @@ -40,9 +49,11 @@ class Bar extends Foo { } ``` -## 6to5-node +## Getters/setters (8 and below) -It is necessary to manually install `kexec` package on Unix-like OSes for -`6to5-node` to correctly handle signals. +In IE8 `Object.defineProperty` can only be used on DOM objects. This is +unfortunate as it's required to set getters and setters. Due to this if +you plan on supporting IE8 or below then the user of getters and setters +isn't recommended. -**It is not recommended to use `6to5-node` with a process manager (`supervisord`, `upstart`, `systemd`, ...) without first installing `kexec`!** +Reference: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes). diff --git a/doc/differences.md b/doc/differences.md index 73f5babd0c..f4ef9475ee 100644 --- a/doc/differences.md +++ b/doc/differences.md @@ -1,6 +1,8 @@ # Differences -## Philosophy +There are three main points that separate 6to5 from all other transpilers. + +### Readable code The fundamental concept behind 6to5 is that the generated code must be close as possible to the original, retaining all the same formatting and readability. @@ -51,7 +53,27 @@ As you can tell, it's not very pretty, unreadable even. Instead of mapping directly to a runtime, like other transpilers, 6to5 maps directly to the equivalent ES5. -Sometimes there are little things that 6to5 needs +Sometimes there are little inline functions that 6to5 needs. These are +placed at the top of your file much like coffee-script does. If these +are bother you then you can use the [optional runtime](optional-runtime.md). +We promise that these inline functions will never be significant and will +always be used as little as possible. + +### Static analysis + +6to5 uses a lot of static analysis to simplify code as much as possible. +Not many other transpilers do this, and those that do don't do it nearly +as much as 6to5. This process is pretty intensive but it leads to higher +quality code. + +### Spec compliancy + +6to5 prides itself on +[spec compliancy](https://kangax.github.io/compat-table/es6/). We have +excellent support for edgecases, something that many other transpilers +suffer from, including Traceur. When you use 6to5 you can be confident +that when you turn it off and use your code in a full ES6 environment +**it'll just work**. ## Comparison to other transpilers @@ -62,40 +84,44 @@ Sometimes there are little things that 6to5 needs | Source maps | ✓ | ✓ | ✓ | ✓ | | ✓ | | No compiler global pollution | ✓ | | ✓ | ✓ | | ✓ | | Optional runtime | ✓ | | ✓ | | | ✓ | -| Browser support | ✓ | ✓ | | ✓ | | | +| Browser compiler | ✓ | ✓ | | ✓ | | | ### Language Support -| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform | -| ---------------------------- | ----- | ------- | -------------- | ------ | ------ | ----------- | -| Abstract references | ✓ | | | | | | -| Array comprehension | ✓ | ✓ | ✓ | | | | -| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Async functions | ✓ | ✓ | | ✓ | | | -| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Constants | ✓ | ✓ | ✓ | | | | -| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Exponentiation operator | ✓ | ✓ | | | | | -| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Generators | ✓ | ✓ | | ✓ | | | -| Generator comprehension | ✓ | ✓ | | | | | -| Let scoping | ✓ | ✓ | ✓ | | | | -| Modules | ✓ | ✓ | | | ✓ | | -| Object rest/spread | ✓ | | | | | ✓ | -| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Unicode regex | ✓ | ✓ | ✓ | | | | +| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform | +| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- | +| Abstract references | ✓ | | | | | | +| Array comprehension | ✓ | ✓ | ✓ | | | | +| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| Async functions | ✓ | ✓ | | ✓ | | | +| Async generator functions | ✓ | ✓ | | | | | +| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | | +| Constants | ✓ | ✓ | ✓ | | | | +| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | | +| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| Exponentiation operator | ✓ | ✓ | | | | | +| Flow types | ✓ | | | | | ✓ | +| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | | +| Generators | ✓ | ✓ | | ✓ | | | +| Generator comprehension | ✓ | ✓ | | | | | +| JSX | ✓ | | | | | | +| Let scoping | ✓ | ✓ | ✓ | | | | +| Modules | ✓ | ✓ | | | ✓ | | +| Object rest/spread | ✓ | | | | | ✓ | +| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| React | ✓ | | | | | | +| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | | +| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| Unicode regex | ✓ | ✓ | ✓ | | | | ### [Traceur](https://github.com/google/traceur-compiler) 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 large runtime can be eliminated entirely. +unnecessary step when a large runtime can be eliminated entirely. ### [es6now](https://github.com/zenparsing/es6now) diff --git a/doc/experimental.md b/doc/experimental.md new file mode 100644 index 0000000000..3546d0cb82 --- /dev/null +++ b/doc/experimental.md @@ -0,0 +1,8 @@ +## Experimental + +6to5 also has experimental support for ES7 proposals. You can enable this with +the `experimental: true` option when using the [Node API](#node) or +`--experimental` when using the [CLI](#cli). + +**WARNING:** These proposals are subject to change so use with +**extreme caution**. diff --git a/doc/features.md b/doc/features.md index d23e891620..a5c55fda81 100644 --- a/doc/features.md +++ b/doc/features.md @@ -1,6 +1,6 @@ # Features -## Abstract references ([experimental](usage.md#experimental)) ([spec](https://github.com/zenparsing/es-abstract-refs)) +## Abstract references ([experimental](experimental.md)) ([spec](https://github.com/zenparsing/es-abstract-refs)) ```javascript foo::bar; @@ -8,7 +8,7 @@ foo::bar = baz; delete foo::bar; ``` -## Array comprehensions ([experimental](usage.md#experimental)) +## Array comprehensions ([experimental](experimental.md)) ```javascript var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }] @@ -39,7 +39,7 @@ var bob = { }; ``` -## Async functions ([experimental](usage.md#experimental)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait)) +## Async functions ([experimental](experimental.md)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait)) ```javascript async function chainAnimationsAsync(elem, animations) { @@ -49,6 +49,12 @@ async function chainAnimationsAsync(elem, animations) { } ``` +## Async generator functions ([experimental](experimental.md)) ([spec](https://github.com/jhusain/asyncgenerator)) + +```javascript + +``` + ## Classes ```javascript @@ -130,7 +136,7 @@ var [a] = []; a === undefined; ``` -## Exponentiation operator ([experimental](usage.md#experimental)) ([spec](https://github.com/rwaldron/exponentiation-operator)) +## Exponentiation operator ([experimental](experimental.md)) ([spec](https://github.com/rwaldron/exponentiation-operator)) ```javascript var a = 2; @@ -167,7 +173,7 @@ for (var n of fibonacci()) { } ``` -## Generator comprehensions ([experimental](usage.md#experimental)) +## Generator comprehensions ([experimental](experimental.md)) ```javascript var nums = [1, 2, 3, 4, 5, 6]; @@ -208,7 +214,7 @@ export default test; 0o767 === 503; // true ``` -## Object spread/rest ([experimental](usage.md#experimental)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread)) +## Object spread/rest ([experimental](experimental.md)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread)) ```javascript var n = { x, y, ...z }; diff --git a/doc/index.md b/doc/index.md index 507cf6435d..c6205dd5af 100644 --- a/doc/index.md +++ b/doc/index.md @@ -35,23 +35,24 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the ## [Features](features.md) - - [Abstract references](features.md#abstract-references) ([experimental](usage.md#experimental)) - - [Array comprehension](features.md#array-comprehension) ([experimental](usage.md#experimental)) - - [Async functions](features.md#async-functions) ([experimental](usage.md#experimental)) + - [Abstract references](features.md#abstract-references) ([experimental](experimental.md)) + - [Array comprehension](features.md#array-comprehension) ([experimental](experimental.md)) + - [Async functions](features.md#async-functions) ([experimental](experimental.md)) + - [Async generator functions](features.md#async-generator-functions) ([experimental](experimental.md)) - [Arrow functions](features.md#arrow-functions) - [Classes](features.md#classes) - [Computed property names](features.md#computed-property-names) - [Constants](features.md#constants) - [Default parameters](features.md#default-parameters) - [Destructuring](features.md#destructuring) - - [Exponentiation operator](features.md#exponentiation-operator) ([experimental](usage.md#experimental)) + - [Exponentiation operator](features.md#exponentiation-operator) ([experimental](experimental.md)) - [For-of](features.md#for-of) - [Generators](features.md#generators) - - [Generator comprehension](features.md#generator-comprehension) ([experimental](usage.md#experimental)) + - [Generator comprehension](features.md#generator-comprehension) ([experimental](experimental.md)) - [Let scoping](features.md#let-scoping) - [Modules](features.md#modules) - [Numeric literals](features.md#numeric-literals) - - [Object Rest/Spread](features.md#object-rest-spread) ([experimental](usage.md#experimental)) + - [Object Rest/Spread](features.md#object-rest-spread) ([experimental](experimental.md)) - [Property method assignment](features.md#property-method-assignment) - [Property name shorthand](features.md#property-name-shorthand) - [React/JSX](react.md) diff --git a/doc/modules.md b/doc/modules.md index 5fcba15868..f58c68416f 100644 --- a/doc/modules.md +++ b/doc/modules.md @@ -19,12 +19,11 @@ to5.transform('import "foo";', { modules: "common" }); * [AMD](#amd) * [Common (Default)](#common-default) - * [Common Interop](#common-interop) * [Ignore](#ignore) * [System](#system) * [UMD](#umd) -### Common (Default) +### Common ```sh $ 6to5 --modules common @@ -33,6 +32,11 @@ $ 6to5 --modules common **In** ```javascript +export default test; + +export {test}; +export var test = 5; + import "foo"; import foo from "foo"; @@ -40,95 +44,30 @@ import * as foo from "foo"; import {bar} from "foo"; import {foo as bar} from "foo"; - -export {test}; -export var test = 5; - -export default test; ``` **Out** ```javascript -require("foo"); +"use strict"; -var foo = require("foo").default; -var foo = require("foo"); - -var bar = require("foo").bar; -var bar = require("foo").foo; - -exports.test = test; -var test = 5; exports.test = test; - -exports.default = test; -``` - -### Common interop - -```sh -$ 6to5 --modules commonInterop -``` - -**In** - -```javascript -import "foo"; - -import foo from "foo"; -import * as foo from "foo"; - -import {bar} from "foo"; -import {foo as bar} from "foo"; - -export {test}; -export var test = 5; - -export default test; -``` - -**Out** - -```javascript var _interopRequire = function (obj) { return obj && (obj["default"] || obj); }; -require("foo"); - -var foo = _interopRequire(require("foo")); -var foo = require("foo"); - -var bar = require("foo").bar; -var bar = require("foo").foo; +exports = module.exports = test; exports.test = test; var test = exports.test = 5; -exports["default"] = test; -``` +require("foo"); -#### module.exports behaviour +var foo = _interopRequire(require("foo")); -If there exist no other non-default `export`s then `default exports` are -exported as `module.exports` instead of `exports.default`. +var foo = require("foo"); -**In** - -```javascript -export default function foo() { - -} -``` - -**Out** - -```javascript -module.exports = foo; - -function foo() { - -} +var bar = require("foo").bar; +var bar = require("foo").foo; ``` ### AMD @@ -151,9 +90,14 @@ export function bar() { ```javascript define(["exports", "foo"], function (exports, _foo) { - exports.bar = bar; + "use strict"; - var foo = _foo.default; + var _interopRequire = function (obj) { + return obj && (obj["default"] || obj); + }; + + exports.bar = bar; + var foo = _interopRequire(_foo); function bar() { return foo("foobar"); @@ -192,10 +136,15 @@ export function bar() { } else if (typeof exports !== "undefined") { factory(exports, require("foo")); } -})(function (exports) { - exports.bar = bar; +})(function (exports, _foo) { + "use strict"; - var foo = _foo.default; + var _interopRequire = function (obj) { + return obj && (obj["default"] || obj); + }; + + exports.bar = bar; + var foo = _interopRequire(_foo); function bar() { return foo("foobar"); @@ -288,7 +237,7 @@ ModuleFormatter.prototype.transform = function (ast) { // feel free to modify this however }; -ModuleFormatter.prototype.import = function (node, nodes) { +ModuleFormatter.prototype.importDeclaration = function (node, nodes) { // node is an ImportDeclaration }; @@ -297,7 +246,7 @@ ModuleFormatter.prototype.importSpecifier = function (specifier, node, nodes) { // node is an ImportDeclaration }; -ModuleFormatter.prototype.export = function (node, nodes) { +ModuleFormatter.prototype.exportDeclaration = function (node, nodes) { // node is an ExportDeclaration }; diff --git a/doc/playground.md b/doc/playground.md index c1f143f0ad..e02e89c163 100644 --- a/doc/playground.md +++ b/doc/playground.md @@ -12,7 +12,7 @@ Playground is a proving ground for **possible** ES7 proposals. to5.transform("code", { playground: true }); ``` -**NOTE:** Enabling `playground` also enables [experimental support](usage.md#experimental). +**NOTE:** Enabling `playground` also enables [experimental support](experimental.md). ## Features @@ -52,11 +52,11 @@ if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2; ### Method binding ```javascript -var fn = obj:method; -var fn = obj:method("foob"); +var fn = obj#method; +var fn = obj#method("foob"); -["foo", "bar"].map(:toUpperCase); // ["FOO", "BAR"] -[1.1234, 23.53245, 3].map(:toFixed(2)); // ["1.12", "23.53", "3.00"] +["foo", "bar"].map(#toUpperCase); // ["FOO", "BAR"] +[1.1234, 23.53245, 3].map(#toFixed(2)); // ["1.12", "23.53", "3.00"] ``` equivalent to: diff --git a/doc/plugins.md b/doc/plugins.md index 3c4fa70137..3785d31575 100644 --- a/doc/plugins.md +++ b/doc/plugins.md @@ -1,18 +1,33 @@ # Plugins - - [Broccoli](https://github.com/very-geek/broccoli-6to5-transpiler) - - [Browserify](https://github.com/6to5/6to5-browserify) - - [Brunch](https://github.com/es128/6to5-brunch) - - [Duo](https://github.com/bdo-labs/duo6to5) - - [Connect](https://github.com/6to5/6to5-connect) - - [Gobble](https://github.com/gobblejs/gobble-6to5) - - [Gulp](https://github.com/sindresorhus/gulp-6to5) - - [Grunt](https://github.com/sindresorhus/grunt-6to5) +## Build systems + + - [Broccoli](https://github.com/6to5/broccoli-6to5-transpiler) + - [Browserify](https://github.com/6to5/6to5ify) + - [Brunch](https://github.com/6to5/6to5-brunch) + - [Duo](https://github.com/6to5/duo6to5) + - [Gobble](https://github.com/6to5/gobble-6to5) + - [Gulp](https://github.com/6to5/gulp-6to5) + - [Grunt](https://github.com/6to5/grunt-6to5) + - [Sprockets](https://github.com/josh/sprockets-es6) or via [Browserify](https://github.com/6to5/6to5-rails) + - [webpack](https://github.com/6to5/6to5-loader) + +## Integrations + - [Isparta](https://github.com/douglasduteil/isparta) - Code coverage with `karma` and `instanbul` using 6to5 - - [Jade](https://github.com/Apoxx/jade-6to5) - - [Jest](https://github.com/6to5/6to5-jest) - [JSXHint](https://github.com/STRML/JSXHint) - A wrapper around JSHint to allow linting of JSX files - - [Karma](https://github.com/shuhei/karma-6to5-preprocessor) + +## Bridges + + - [Ruby](https://github.com/6to5/6to5-ruby) + +## Testing + + - [Jest](https://github.com/6to5/6to5-jest) + - [Karma](https://github.com/6to5/karma-6to5-preprocessor) - [Mocha](https://github.com/6to5/6to5-mocha) - - [Rails](https://github.com/josh/sprockets-es6) or via [browserify-rails](https://github.com/6to5/6to5-rails) - - [webpack](https://github.com/Couto/6to5-loader) + +## Misc + + - [Connect](https://github.com/6to5/6to5-connect) + - [Jade](https://github.com/6to5/jade-6to5) diff --git a/doc/polyfill.md b/doc/polyfill.md index 4249e038dc..a97e334fb7 100644 --- a/doc/polyfill.md +++ b/doc/polyfill.md @@ -1,16 +1,15 @@ # Polyfill -6to5 includes a polyfill that includes the -[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and the -[es6-shim](https://github.com/paulmillr/es6-shim) and -[es6-symbol](https://github.com/medikoo/es6-symbol) polyfills. +6to5 includes a polyfill that includes a custom +[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and +[core.js](https://github.com/zloirock/core-js). This will emulate a full ES6 environment. This polyfill is automatically loaded -when using [6to5-node](usage.md#node). +when using [6to5-node](usage.md#node) and [6to5/register](usage.md#register-hook). ## Usage -### Node +### Node/Browserify You need to include the polyfill require at the top the **entry point** to your application. @@ -31,3 +30,5 @@ Available from the `browser-polyfill.js` file within the 6to5 directory of an npm release. This needs to be included **before** all your compiled 6to5 code. You can either prepend it to your compiled code or include it in a `