add exponentiation operator
This commit is contained in:
parent
b599e2c794
commit
fafdb1a18a
@ -78,6 +78,7 @@ better suited if you'd like a full ES6 environment with polyfills and all.
|
|||||||
| Constants | ✓ | ✓ | ✓ | | | |
|
| Constants | ✓ | ✓ | ✓ | | | |
|
||||||
| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||||
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
|
| Exponentiation operator | ✓ | ✓ | | | | |
|
||||||
| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||||
| Generators | ✓ | ✓ | | ✓ | | |
|
| Generators | ✓ | ✓ | | ✓ | | |
|
||||||
| Generator comprehension | ✓ | ✓ | | | | |
|
| Generator comprehension | ✓ | ✓ | | | | |
|
||||||
|
|||||||
@ -130,6 +130,15 @@ var [a] = [];
|
|||||||
a === undefined;
|
a === undefined;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Exponentiation operator ([experimental](usage.md#experimental)) ([spec](https://github.com/rwaldron/exponentiation-operator))
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var a = 2;
|
||||||
|
a **= 2;
|
||||||
|
|
||||||
|
var squared = 2 ** 2;
|
||||||
|
```
|
||||||
|
|
||||||
## For-of
|
## For-of
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
|||||||
@ -40,6 +40,7 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
|
|||||||
- [Constants](features.md#constants)
|
- [Constants](features.md#constants)
|
||||||
- [Default parameters](features.md#default-parameters)
|
- [Default parameters](features.md#default-parameters)
|
||||||
- [Destructuring](features.md#destructuring)
|
- [Destructuring](features.md#destructuring)
|
||||||
|
- [Exponentiation operator](features.md#exponentiation-operator) ([experimental](usage.md#experimental))
|
||||||
- [For-of](features.md#for-of)
|
- [For-of](features.md#for-of)
|
||||||
- [Generators](features.md#generators)
|
- [Generators](features.md#generators)
|
||||||
- [Generator comprehension](features.md#generator-comprehension) ([experimental](usage.md#experimental))
|
- [Generator comprehension](features.md#generator-comprehension) ([experimental](usage.md#experimental))
|
||||||
|
|||||||
@ -39,6 +39,7 @@ _.each({
|
|||||||
computedPropertyNames: require("./transformers/es6-computed-property-names"),
|
computedPropertyNames: require("./transformers/es6-computed-property-names"),
|
||||||
|
|
||||||
objectSpread: require("./transformers/es7-object-spread"),
|
objectSpread: require("./transformers/es7-object-spread"),
|
||||||
|
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
|
||||||
spread: require("./transformers/es6-spread"),
|
spread: require("./transformers/es6-spread"),
|
||||||
templateLiterals: require("./transformers/es6-template-literals"),
|
templateLiterals: require("./transformers/es6-template-literals"),
|
||||||
propertyMethodAssignment: require("./transformers/es5-property-method-assignment"),
|
propertyMethodAssignment: require("./transformers/es5-property-method-assignment"),
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
// https://github.com/rwaldron/exponentiation-operator
|
||||||
|
|
||||||
|
var t = require("../../types");
|
||||||
|
var pow = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
|
||||||
|
|
||||||
|
exports.AssignmentExpression = function (node) {
|
||||||
|
if (node.operator !== "**=") return;
|
||||||
|
node.operator = "=";
|
||||||
|
node.right = t.callExpression(pow, [node.left, node.right]);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.BinaryExpression = function (node) {
|
||||||
|
if (node.operator !== "**") return;
|
||||||
|
|
||||||
|
return t.callExpression(pow, [node.left, node.right]);
|
||||||
|
};
|
||||||
@ -47,7 +47,7 @@
|
|||||||
"chokidar": "0.11.1",
|
"chokidar": "0.11.1",
|
||||||
"source-map-support": "0.2.8",
|
"source-map-support": "0.2.8",
|
||||||
"esutils": "1.1.6",
|
"esutils": "1.1.6",
|
||||||
"acorn-6to5": "0.9.1-6",
|
"acorn-6to5": "0.9.1-7",
|
||||||
"estraverse": "1.8.0",
|
"estraverse": "1.8.0",
|
||||||
"private": "0.1.6"
|
"private": "0.1.6"
|
||||||
},
|
},
|
||||||
|
|||||||
1
test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js
vendored
Normal file
1
test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
num **= 2;
|
||||||
3
test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js
vendored
Normal file
3
test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
num = Math.pow(num, 2);
|
||||||
1
test/fixtures/transformation/es7-exponentian-operator/binary/actual.js
vendored
Normal file
1
test/fixtures/transformation/es7-exponentian-operator/binary/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
2 ** 2;
|
||||||
3
test/fixtures/transformation/es7-exponentian-operator/binary/expected.js
vendored
Normal file
3
test/fixtures/transformation/es7-exponentian-operator/binary/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
Math.pow(2, 2);
|
||||||
3
test/fixtures/transformation/es7-exponentian-operator/options.json
vendored
Normal file
3
test/fixtures/transformation/es7-exponentian-operator/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"experimental": true
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user