Add abstract references base #205

This commit is contained in:
Sebastian McKenzie 2014-11-23 16:04:25 +11:00
parent 4808689795
commit 02c42b94f5
13 changed files with 54 additions and 11 deletions

View File

@ -6,9 +6,11 @@ satisfy **all** 6to5 feature requirements by using the included
| Feature | Requirements |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Abstract References | `Symbol` |
| Array destructuring | `Array.isArray`, `Array.from` |
| Async functions, Generators | [experimental option](usage.md#experimental), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
| Comprehensions | [experimental option](usage.md#experimental), `Array.isArray`, `Array.from` |
| For..Of | `Symbol`, `prototype[Symbol.iterator]` |
| Spread | `Array.isArray`, `Array.from` |
## Classes
@ -36,14 +38,3 @@ class Bar extends Foo {
}
}
```
## Constructor spread
Constructor spreads do not currently support built-ins. ie.
`new Array(...items)`.
## For-of
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](polyfill.md) suffices.

View File

@ -69,6 +69,7 @@ better suited if you'd like a full ES6 environment with polyfills and all.
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
| ---------------------------- | ----- | ------- | -------------- | ------ | ------ | ----------- |
| Abstract references | ✓ | | | | | |
| Array comprehension | ✓ | ✓ | ✓ | | | |
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Async functions | ✓ | ✓ | | ✓ | | |

View File

@ -1,5 +1,13 @@
# Features
## Abstract references ([experimental](usage.md#experimental))
```javascript
foo::bar;
foo::bar = baz;
delete foo::bar;
```
## Array comprehension ([experimental](usage.md#experimental))
```javascript

View File

@ -31,6 +31,7 @@ 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))
- [Arrow functions](features.md#arrow-functions)

View File

@ -1,6 +1,35 @@
//
var ensureSymbol = function (key) {
Symbol[key] = Symbol[key] || Symbol();
};
var ensureProto = function (Constructor, key, val) {
var proto = Constructor.prototype;
proto[key] = proto[key] || val;
};
//
if (typeof Symbol === "undefined") {
require("es6-symbol/implement");
}
require("es6-shim");
require("./transformation/transformers/generators/runtime");
// Abstract references
ensureSymbol("referenceGet");
ensureSymbol("referenceSet");
ensureSymbol("referenceDelete");
ensureProto(Function, Symbol.referenceGet, function () { return this });
ensureProto(Map, Symbol.referenceGet, Map.prototype.get);
ensureProto(Map, Symbol.referenceSet, Map.prototype.set);
ensureProto(Map, Symbol.referenceDelete, Map.prototype.delete);
ensureProto(WeakMap, Symbol.referenceGet, WeakMap.prototype.get);
ensureProto(WeakMap, Symbol.referenceSet, WeakMap.prototype.set);
ensureProto(WeakMap, Symbol.referenceDelete, WeakMap.prototype.delete);

View File

@ -47,6 +47,7 @@ _.each({
forOf: require("./transformers/for-of"),
unicodeRegex: require("./transformers/unicode-regex"),
react: require("./transformers/react"),
abstractReferences: require("./transformers/abstract-references"),
constants: require("./transformers/constants"),
letScoping: require("./transformers/let-scoping"),

View File

@ -0,0 +1 @@
delete foo::bar;

View File

@ -0,0 +1,3 @@
"use strict";
bar[Symbol.referenceDelete](foo);

View File

@ -0,0 +1 @@
foo::bar;

View File

@ -0,0 +1,3 @@
"use strict";
bar[Symbol.referenceGet](foo);

View File

@ -0,0 +1 @@
foo::bar = baz;

View File

@ -0,0 +1,3 @@
"use strict";
bar[Symbol.referenceSet](foo, baz);