add array comprehension and property name shorthand

This commit is contained in:
Sebastian McKenzie
2014-09-29 03:11:59 +10:00
parent 3732b4fe39
commit b9ed7f0cb2
5 changed files with 145 additions and 15 deletions

126
FEATURES.md Normal file
View File

@@ -0,0 +1,126 @@
# Features
## Arrow functions
```javascript
arr.map(x => x * x);
```
## Classes
```javascript
class Foo extends Bar {
constructor() {
}
foo() {
}
get bar() {
}
set bar() {
}
}
```
## Default parameters
```javascript
function foo(bar = "foo") {
return bar + "bar";
}
```
## Spread
```javascript
function add(x, y) {
return x + y;
}
var numbers = [5, 10]
add(...numbers); // 15
```
## Block binding
```javascript
for (let i in arr) {
let v = arr[i];
}
```
## Property method assignment
```javascript
var obj = {
bar: "foobar",
foo() {
return "foobar";
},
get bar() {
},
set bar() {
}
};
```
## Rest parameters
```javascript
function printList(name, ...items) {
console.log("list %s has the following items", name);
items.forEach(function (item) {
console.log(item);
});
};
```
## Template literals
```javascript
var x = 5;
var y = 10;
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
```
## Modules
```javascript
```
## Property name shorthand
```javascript
function f(x, y) {
return { x, y };
}
```
## Array comprehension
```javascript
[for (i of [1, 2, 3]) i * i]; // [1, 4, 9]
```
## Destructuring assignment
```javascript
var [a, [b], c, d] = ["hello", [", ", "junk"], ["world"]];
console.log(a + b + c); // hello, world
```
## Generators
```javascript
```

View File

@@ -23,26 +23,28 @@
**6to5** turns ES6 code into vanilla ES5, so you can use ES6 features **today.**
- **Fast** - [10x faster than Traceur](#performance).
- **Easy** - with Browserify support, Node API, Connect Middleware and a CLI.
- **Extensive** - with Browserify support, Node API, Connect Middleware and a CLI.
- **Lossless** - source map support so you can debug your compiled code with ease.
- **Compact** - maps directly to the equivalent ES5 with **no runtime required**.
- **Concise** - does not pollute scope with unneccesary variables.
## Features
| Name | Implemented |
| -------------------------- | ----------- |
| Arrow functions | ✓ |
| Classes | ✓ |
| Default parameters | ✓ |
| Spread | ✓ |
| Block binding | ✓ |
| Property method assignment | ✓ |
| Rest parameters | ✓ |
| Template literals | ✓ |
| Modules | ✓ |
| Destructuring assignment | |
| Generators | |
| Name | Implemented |
| -------------------------------------------------------------------- | ----------- |
| [Arrow functions](FEATURES.md#arrow-functions) | ✓ |
| [Classes](FEATURES.md#classes) | ✓ |
| [Default parameters](FEATURES.md#default-parameters) | ✓ |
| [Spread](FEATURES.md#spread) | ✓ |
| [Block binding](FEATURES.md#block-binding) | ✓ |
| [Property method assignment](FEATURES.md#property-method-assignment) | ✓ |
| [Rest parameters](FEATURES.md#rest-parameters) | ✓ |
| [Template literals](FEATURES.md#template-literals) | ✓ |
| [Modules](FEATURES.md#modules) | ✓ |
| [Array comprehension](FEATURES.md#array-comprehension) | |
| [Property name shorthand](FEATURES.md#property-name-shorthand) | |
| [Destructuring assignment](FEATURES.md#destructuring-assignment) | |
| [Generators](FEATURES.md#generators) | |
## Installation
@@ -122,7 +124,7 @@ require("6to5/register");
var to5 = require("6to5");
app.use(to5.middleware({
transform: {
options: {
// options to use when transforming files
},
src: "assets",

View File

@@ -95,6 +95,8 @@ transform.test = function (actual, expect, opts) {
};
transform.transformers = {
propertyNameShorthand: require("./transformers/property-name-shorthand"),
arrayComprehension: require("./transformers/array-comprehension"),
arrowFunctions: require("./transformers/arrow-functions"),
classes: require("./transformers/classes"),
spread: require("./transformers/spread"),