├── .gitignore ├── src ├── features │ ├── exponentiation-operator.js │ ├── async-generators.js │ ├── es2015-typeof-symbol.js │ ├── es2015-arrow-functions.js │ ├── es2015-unicode-regex.js │ ├── es3-property-literals.js │ ├── es2015-computed-properties.js │ ├── es2015-literals.js │ ├── es2015-parameters.js │ ├── es2015-shorthand-properties.js │ ├── es3-member-expression-literals.js │ ├── es5-property-mutators.js │ ├── trailing-function-commas.js │ ├── es2015-template-literals.js │ ├── es2015-spread.js │ ├── es2015-duplicate-keys.js │ ├── es2015-constants.js │ ├── es3-function-scope.js │ ├── es2015-classes.js │ ├── es2015-destructuring.js │ ├── es2015-object-super.js │ ├── es2015-function-name.js │ ├── es2015-sticky-regex.js │ ├── es2015-block-scoped-functions.js │ ├── object-rest-spread.js │ ├── function-sent.js │ ├── es2015-block-scoping.js │ ├── async-functions.js │ ├── es2015-for-of.js │ ├── es2015-generators.js │ └── es2015-generator-return.js └── features.yaml ├── lib ├── tests.js └── index.js ├── test.js ├── test.html ├── dist-template.js ├── package.json ├── README.md └── dist └── babel-features.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /sandbox 3 | -------------------------------------------------------------------------------- /src/features/exponentiation-operator.js: -------------------------------------------------------------------------------- 1 | assert( 2 | 2 ** 10 === 1024 3 | ) 4 | -------------------------------------------------------------------------------- /src/features/async-generators.js: -------------------------------------------------------------------------------- 1 | async function* foo(x) { 2 | return await x 3 | } 4 | -------------------------------------------------------------------------------- /src/features/es2015-typeof-symbol.js: -------------------------------------------------------------------------------- 1 | assert( 2 | typeof Symbol() === 'symbol' 3 | ) 4 | -------------------------------------------------------------------------------- /src/features/es2015-arrow-functions.js: -------------------------------------------------------------------------------- 1 | var foo = () => true 2 | 3 | assert( 4 | foo() 5 | ) 6 | -------------------------------------------------------------------------------- /src/features/es2015-unicode-regex.js: -------------------------------------------------------------------------------- 1 | var re = /^.$/u 2 | 3 | assert( 4 | re.test("𠮷") 5 | ) 6 | -------------------------------------------------------------------------------- /src/features/es3-property-literals.js: -------------------------------------------------------------------------------- 1 | var foo = {if: true} 2 | 3 | assert( 4 | foo["if"] 5 | ) 6 | -------------------------------------------------------------------------------- /src/features/es2015-computed-properties.js: -------------------------------------------------------------------------------- 1 | var foo = {["b" + "ar"]: true} 2 | 3 | assert( 4 | foo.bar 5 | ) 6 | -------------------------------------------------------------------------------- /src/features/es2015-literals.js: -------------------------------------------------------------------------------- 1 | assert( 2 | 0b111 === 0o7 3 | ) 4 | 5 | assert( 6 | '\u{20bb7}' === '𠮷' 7 | ) 8 | -------------------------------------------------------------------------------- /src/features/es2015-parameters.js: -------------------------------------------------------------------------------- 1 | function foo(x = true) { 2 | return x 3 | } 4 | 5 | assert( 6 | foo() 7 | ) 8 | -------------------------------------------------------------------------------- /src/features/es2015-shorthand-properties.js: -------------------------------------------------------------------------------- 1 | var foo = true 2 | var bar = {foo} 3 | 4 | assert( 5 | bar.foo 6 | ) 7 | -------------------------------------------------------------------------------- /src/features/es3-member-expression-literals.js: -------------------------------------------------------------------------------- 1 | var foo = {} 2 | foo.if = true 3 | 4 | assert( 5 | foo.if 6 | ) 7 | -------------------------------------------------------------------------------- /src/features/es5-property-mutators.js: -------------------------------------------------------------------------------- 1 | var foo = { 2 | get bar() { return true } 3 | } 4 | 5 | assert( 6 | foo.bar 7 | ) 8 | -------------------------------------------------------------------------------- /src/features/trailing-function-commas.js: -------------------------------------------------------------------------------- 1 | function foo(a, b,) { return a + b } 2 | 3 | assert( 4 | foo(1, 2,) === 3 5 | ) 6 | -------------------------------------------------------------------------------- /src/features/es2015-template-literals.js: -------------------------------------------------------------------------------- 1 | var foo = "foo" 2 | var bar = `${foo}bar` 3 | 4 | assert( 5 | bar === "foobar" 6 | ) 7 | -------------------------------------------------------------------------------- /src/features/es2015-spread.js: -------------------------------------------------------------------------------- 1 | function foo(a, b, c) { 2 | return a + b === c 3 | } 4 | var list = [2, 3] 5 | 6 | assert( 7 | foo(1, ...list) 8 | ) 9 | -------------------------------------------------------------------------------- /src/features/es2015-duplicate-keys.js: -------------------------------------------------------------------------------- 1 | var x = {a: 5, a: 6} 2 | assert(x.a === 6) 3 | 4 | var y = { 5 | get a() { return 1 }, 6 | a: 2, 7 | } 8 | assert(y.a === 2) 9 | -------------------------------------------------------------------------------- /src/features/es2015-constants.js: -------------------------------------------------------------------------------- 1 | const foo = true 2 | 3 | try { 4 | foo = false 5 | } catch (e) { 6 | assert( 7 | foo 8 | ) 9 | } 10 | 11 | assert( 12 | foo 13 | ) 14 | -------------------------------------------------------------------------------- /src/features/es3-function-scope.js: -------------------------------------------------------------------------------- 1 | var foo = function $babel_features_es3_function_scope$() {} 2 | 3 | assert( 4 | typeof $babel_features_es3_function_scope$ === "undefined" 5 | ) 6 | -------------------------------------------------------------------------------- /src/features/es2015-classes.js: -------------------------------------------------------------------------------- 1 | class A { 2 | foo() { return false } 3 | } 4 | class B extends A { 5 | bar() { return !super.foo() } 6 | } 7 | 8 | assert( 9 | new B().bar() 10 | ) 11 | -------------------------------------------------------------------------------- /src/features/es2015-destructuring.js: -------------------------------------------------------------------------------- 1 | function foo({a, b: b1, c: [x, , y]}) { 2 | return a === 1 && b1 === 2 && x === 3 && y === 5 3 | } 4 | 5 | assert( 6 | foo({a: 1, b: 2, c: [3, 4, 5]}) 7 | ) 8 | -------------------------------------------------------------------------------- /src/features/es2015-object-super.js: -------------------------------------------------------------------------------- 1 | var a = { foo() { return 'f' } } 2 | var b = { foo() { return super.foo() + 'oo' } } 3 | Object.setPrototypeOf(b, a) 4 | 5 | assert( 6 | b.foo() === 'foo' 7 | ) 8 | -------------------------------------------------------------------------------- /src/features/es2015-function-name.js: -------------------------------------------------------------------------------- 1 | var foo = function () {} 2 | 3 | assert( 4 | foo.name === 'foo' 5 | ) 6 | 7 | var obj = { bar: function () {} } 8 | 9 | assert( 10 | obj.bar.name === 'bar' 11 | ) 12 | -------------------------------------------------------------------------------- /src/features/es2015-sticky-regex.js: -------------------------------------------------------------------------------- 1 | // NOTE: Up to now, there is no runtime polyfill/shim available for sticky, 2 | // So this test never pass even with babel plugin applied. 3 | 4 | assert( 5 | /o+/y.sticky 6 | ) 7 | -------------------------------------------------------------------------------- /src/features/es2015-block-scoped-functions.js: -------------------------------------------------------------------------------- 1 | var outer = foo() 2 | function foo() { return 1 } 3 | 4 | { 5 | var inner = foo() 6 | function foo() { return 0 } 7 | } 8 | 9 | assert( 10 | inner === 0 && outer === 1 11 | ) 12 | -------------------------------------------------------------------------------- /src/features/object-rest-spread.js: -------------------------------------------------------------------------------- 1 | var {x, y, ...z} = {x: 1, y: 2, a: 3, b: 4} 2 | assert(Object.keys(z).length === 2 && z.a === 3 && z.b === 4) 3 | 4 | var o = {x, y, ...z} 5 | assert(Object.keys(o).length === 4 && o.a === 3 && o.b === 4) 6 | -------------------------------------------------------------------------------- /src/features/function-sent.js: -------------------------------------------------------------------------------- 1 | function* g() { 2 | assert(function.sent === 1) 3 | yield 4 | assert(function.sent === 2) 5 | var x = yield 6 | assert(function.sent === x) 7 | } 8 | 9 | var test = g() 10 | test.next(1) 11 | test.next(2) 12 | test.next(Math.random()) 13 | -------------------------------------------------------------------------------- /src/features/es2015-block-scoping.js: -------------------------------------------------------------------------------- 1 | let foo = 0, bar = 1 2 | foo += bar 3 | { 4 | const bar = 2 5 | foo += bar 6 | } 7 | 8 | assert( 9 | foo === 3 10 | ) 11 | 12 | switch (0) { 13 | default: 14 | const bar = 3 15 | foo += bar 16 | } 17 | 18 | assert( 19 | foo === 6 20 | ) 21 | -------------------------------------------------------------------------------- /src/features/async-functions.js: -------------------------------------------------------------------------------- 1 | async function foo(x) { 2 | return await x 3 | } 4 | 5 | var called = false 6 | var p = foo({ 7 | then: function () { 8 | called = true 9 | throw 'test async functions' 10 | } 11 | }) 12 | 13 | assert(typeof p.then === 'function') 14 | assert(called) 15 | -------------------------------------------------------------------------------- /src/features/es2015-for-of.js: -------------------------------------------------------------------------------- 1 | var o = {} 2 | o[Symbol.iterator] = function () { 3 | var i = 0 4 | return { 5 | next: function () { 6 | if (i < 3) return {value: ++i} 7 | return {done: true} 8 | } 9 | } 10 | } 11 | var sum = 0 12 | for (var x of o) { 13 | sum += x 14 | } 15 | 16 | assert( 17 | sum === 6 18 | ) 19 | -------------------------------------------------------------------------------- /lib/tests.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var fs = require('fs') 4 | var yaml = require('js-yaml') 5 | 6 | module.exports = 7 | yaml.safeLoad(fs.readFileSync(__dirname + '/../src/features.yaml', 'utf-8')) 8 | .map(function (f) { 9 | return { 10 | feature: f, 11 | code: fs.readFileSync(__dirname + '/../src/features/' + f + '.js', 'utf-8') 12 | } 13 | }) 14 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var f = require('./lib') 4 | console.log('Node.js:', process.versions.node) 5 | console.log('V8:', process.versions.v8) 6 | console.log() 7 | 8 | console.log('babel features test result:') 9 | console.log(f.test()) 10 | console.log() 11 | 12 | console.log('recommended plugins:') 13 | console.log(f.options().plugins) 14 | console.log() 15 | -------------------------------------------------------------------------------- /src/features/es2015-generators.js: -------------------------------------------------------------------------------- 1 | function* g() { 2 | yield 1 3 | yield 2 4 | yield 3 5 | } 6 | var foo = g() 7 | 8 | assert( 9 | foo.next().value === 1 10 | ) 11 | assert( 12 | foo.next().value === 2 13 | ) 14 | assert( 15 | foo.next().value === 3 16 | ) 17 | assert( 18 | foo.next().done 19 | ) 20 | 21 | var result = function* () { return 1 }().next() 22 | 23 | assert( 24 | result.done && result.value === 1 25 | ) 26 | -------------------------------------------------------------------------------- /src/features/es2015-generator-return.js: -------------------------------------------------------------------------------- 1 | var closed 2 | function* g() { 3 | try { 4 | closed = false 5 | while (true) yield 6 | } finally { 7 | closed = true 8 | } 9 | } 10 | var foo = g() 11 | foo.next() 12 | var result = foo.return('ok') 13 | 14 | assert( 15 | result.done && result.value === 'ok' && closed 16 | ) 17 | 18 | result = foo.next() 19 | 20 | assert( 21 | result.done && result.value === undefined 22 | ) 23 | 24 | result = function* () {}().return('ok2') 25 | 26 | assert( 27 | result.done && result.value === 'ok2' 28 | ) 29 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 26 | -------------------------------------------------------------------------------- /dist-template.js: -------------------------------------------------------------------------------- 1 | void function(global) { 2 | 'use strict' 3 | 4 | switch (moduleFormat()) { 5 | case 'systemjs': 6 | System.register([], function (_export) { 7 | return { 8 | execute: function () { 9 | _export("test", test) 10 | _export("options", options) 11 | } 12 | } 13 | }) 14 | break 15 | case 'amd': 16 | define({test: test, options: options}) 17 | break 18 | case 'commonjs': 19 | exports.test = test 20 | exports.options = options 21 | break 22 | default: 23 | global.BabelFeatures = {test: test, options: options} 24 | } 25 | 26 | /* BODY */ 27 | 28 | }(this) 29 | -------------------------------------------------------------------------------- /src/features.yaml: -------------------------------------------------------------------------------- 1 | # ES3 2 | - es3-member-expression-literals 3 | - es3-property-literals 4 | 5 | # ES5 6 | - es5-property-mutators 7 | 8 | # ES2015 9 | - es2015-arrow-functions 10 | - es2015-block-scoped-functions 11 | - es2015-block-scoping 12 | - es2015-classes 13 | - es2015-computed-properties 14 | - es2015-constants 15 | - es2015-destructuring 16 | - es2015-duplicate-keys 17 | - es2015-for-of 18 | - es2015-function-name 19 | - es2015-literals 20 | - es2015-object-super 21 | - es2015-parameters 22 | - es2015-shorthand-properties 23 | - es2015-spread 24 | - es2015-sticky-regex 25 | - es2015-template-literals 26 | - es2015-typeof-symbol 27 | - es2015-unicode-regex 28 | 29 | # Stage 3 30 | - exponentiation-operator # ES2016 31 | - trailing-function-commas # Stage 3 32 | 33 | # Special features 34 | - es3-function-scope 35 | - es2015-generators 36 | - es2015-generator-return 37 | - async-functions # Stage 3 38 | - async-generators # Stage 2 39 | - function-sent # Stage 2 40 | - object-rest-spread # Stage 2 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-features", 3 | "version": "2.0.1", 4 | "description": "Test babel features, can be used to generate babel options for specific compilation targets", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "prepublish": "node build", 8 | "test": "node test", 9 | "test-es2015": "BABEL_DISABLE_CACHE=1 babel-node --presets es2015 test", 10 | "test-features": "BABEL_DISABLE_CACHE=1 babel-node --presets features test", 11 | "test-generator": "BABEL_DISABLE_CACHE=1 babel-node test -w transform-async-to-generator,transform-es2015-generator-return", 12 | "test-function-name": "BABEL_DISABLE_CACHE=1 babel-node --plugins transform-es2015-function-name test" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/hax/babel-features.git" 17 | }, 18 | "keywords": [ 19 | "babel" 20 | ], 21 | "author": "HE Shi-Jun