Add abstract references base #205
This commit is contained in:
parent
4808689795
commit
02c42b94f5
@ -6,9 +6,11 @@ satisfy **all** 6to5 feature requirements by using the included
|
|||||||
|
|
||||||
| Feature | Requirements |
|
| Feature | Requirements |
|
||||||
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| Abstract References | `Symbol` |
|
||||||
| Array destructuring | `Array.isArray`, `Array.from` |
|
| 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) |
|
| 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` |
|
| Comprehensions | [experimental option](usage.md#experimental), `Array.isArray`, `Array.from` |
|
||||||
|
| For..Of | `Symbol`, `prototype[Symbol.iterator]` |
|
||||||
| Spread | `Array.isArray`, `Array.from` |
|
| Spread | `Array.isArray`, `Array.from` |
|
||||||
|
|
||||||
## Classes
|
## 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.
|
|
||||||
|
|||||||
@ -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 |
|
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
|
||||||
| ---------------------------- | ----- | ------- | -------------- | ------ | ------ | ----------- |
|
| ---------------------------- | ----- | ------- | -------------- | ------ | ------ | ----------- |
|
||||||
|
| Abstract references | ✓ | | | | | |
|
||||||
| Array comprehension | ✓ | ✓ | ✓ | | | |
|
| Array comprehension | ✓ | ✓ | ✓ | | | |
|
||||||
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Async functions | ✓ | ✓ | | ✓ | | |
|
| Async functions | ✓ | ✓ | | ✓ | | |
|
||||||
|
|||||||
@ -1,5 +1,13 @@
|
|||||||
# Features
|
# Features
|
||||||
|
|
||||||
|
## Abstract references ([experimental](usage.md#experimental))
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
foo::bar;
|
||||||
|
foo::bar = baz;
|
||||||
|
delete foo::bar;
|
||||||
|
```
|
||||||
|
|
||||||
## Array comprehension ([experimental](usage.md#experimental))
|
## Array comprehension ([experimental](usage.md#experimental))
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
|||||||
@ -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)
|
## [Features](features.md)
|
||||||
|
|
||||||
|
- [Abstract references](features.md#abstract-references) ([experimental](usage.md#experimental))
|
||||||
- [Array comprehension](features.md#array-comprehension) ([experimental](usage.md#experimental))
|
- [Array comprehension](features.md#array-comprehension) ([experimental](usage.md#experimental))
|
||||||
- [Async functions](features.md#async-functions) ([experimental](usage.md#experimental))
|
- [Async functions](features.md#async-functions) ([experimental](usage.md#experimental))
|
||||||
- [Arrow functions](features.md#arrow-functions)
|
- [Arrow functions](features.md#arrow-functions)
|
||||||
|
|||||||
@ -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") {
|
if (typeof Symbol === "undefined") {
|
||||||
require("es6-symbol/implement");
|
require("es6-symbol/implement");
|
||||||
}
|
}
|
||||||
|
|
||||||
require("es6-shim");
|
require("es6-shim");
|
||||||
require("./transformation/transformers/generators/runtime");
|
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);
|
||||||
|
|||||||
@ -47,6 +47,7 @@ _.each({
|
|||||||
forOf: require("./transformers/for-of"),
|
forOf: require("./transformers/for-of"),
|
||||||
unicodeRegex: require("./transformers/unicode-regex"),
|
unicodeRegex: require("./transformers/unicode-regex"),
|
||||||
react: require("./transformers/react"),
|
react: require("./transformers/react"),
|
||||||
|
abstractReferences: require("./transformers/abstract-references"),
|
||||||
|
|
||||||
constants: require("./transformers/constants"),
|
constants: require("./transformers/constants"),
|
||||||
letScoping: require("./transformers/let-scoping"),
|
letScoping: require("./transformers/let-scoping"),
|
||||||
|
|||||||
1
test/fixtures/transformation/abstract-references/delete/actual.js
vendored
Normal file
1
test/fixtures/transformation/abstract-references/delete/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
delete foo::bar;
|
||||||
3
test/fixtures/transformation/abstract-references/delete/expected.js
vendored
Normal file
3
test/fixtures/transformation/abstract-references/delete/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
bar[Symbol.referenceDelete](foo);
|
||||||
1
test/fixtures/transformation/abstract-references/get/actual.js
vendored
Normal file
1
test/fixtures/transformation/abstract-references/get/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo::bar;
|
||||||
3
test/fixtures/transformation/abstract-references/get/expected.js
vendored
Normal file
3
test/fixtures/transformation/abstract-references/get/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
bar[Symbol.referenceGet](foo);
|
||||||
1
test/fixtures/transformation/abstract-references/set/actual.js
vendored
Normal file
1
test/fixtures/transformation/abstract-references/set/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo::bar = baz;
|
||||||
3
test/fixtures/transformation/abstract-references/set/expected.js
vendored
Normal file
3
test/fixtures/transformation/abstract-references/set/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
bar[Symbol.referenceSet](foo, baz);
|
||||||
Loading…
x
Reference in New Issue
Block a user