├── .eslintrc ├── .gitignore ├── .travis.yml ├── History.md ├── LICENSE ├── Readme.md ├── lib └── index.js ├── package.json └── test ├── babel.js ├── index.js └── mocha.opts /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "extends": "airbnb/base", 6 | "parser": "babel-eslint", 7 | "rules": { 8 | "semi": [2, "never"], 9 | "no-use-before-define": [2, "nofunc"], 10 | "no-param-reassign": 0, 11 | "id-length": 0, 12 | "max-len": 0 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '5' 4 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | ## 1.2.0 / 2016-03-15 2 | 3 | * fix reserved words in shorthand properties [#10](https://github.com/alekseykulikov/babel-preset-es2015-node5/issues/10) 4 | * pin deps to `^6.7.x` 5 | 6 | ## 1.1.2 / 2016-01-21 7 | 8 | * pin deps to `^6.4.0` 9 | * docs (badges, typos) 10 | * add tests for correct work of block scoping [#8](https://github.com/alekseykulikov/babel-preset-es2015-node5/issues/8) 11 | * travis.ci 12 | 13 | ## 1.1.1 / 2015-11-30 14 | 15 | * pin deps to `^6.2.4` 16 | * improve docs 17 | 18 | ## 1.1.0 / 2015-11-12 19 | 20 | * update deps to `^6.1.4` 21 | * add `transform-es2015-function-name` [#4](https://github.com/alekseykulikov/babel-preset-es2015-node5/issues/4) 22 | 23 | ## 1.0.0 / 2015-11-01 24 | 25 | * initial release 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Aleksey Kulikov (alekseykulikov.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # babel-preset-es2015-node5 2 | 3 | > Babel preset to make node@5 fully ES2015 compatible. 4 | 5 | [![](https://img.shields.io/npm/v/babel-preset-es2015-node5.svg)](https://npmjs.org/package/babel-preset-es2015-node5) 6 | [![](https://img.shields.io/travis/alekseykulikov/babel-preset-es2015-node5.svg)](https://travis-ci.org/alekseykulikov/babel-preset-es2015-node5) 7 | [![](http://img.shields.io/npm/dm/babel-preset-es2015-node5.svg)](https://npmjs.org/package/babel-preset-es2015-node5) 8 | 9 | Node@5 has great [ES2015 support](https://nodejs.org/en/docs/es6/), 10 | this module just adds missing features: 11 | - destructuring assignment ([transform-es2015-destructuring](http://babeljs.io/docs/plugins/transform-es2015-destructuring/)) 12 | - rest & default parameters ([transform-es2015-parameters](http://babeljs.io/docs/plugins/transform-es2015-parameters/)) 13 | - modules ([transform-es2015-modules-commonjs](http://babeljs.io/docs/plugins/transform-es2015-modules-commonjs/)) 14 | - unicode & sticky regular expressions ([transform-es2015-sticky-regex](http://babeljs.io/docs/plugins/transform-es2015-sticky-regex/) & [transform-es2015-unicode-regex](http://babeljs.io/docs/plugins/transform-es2015-unicode-regex/)) 15 | - better function name support ([transform-es2015-function-name](http://babeljs.io/docs/plugins/transform-es2015-function-name/)) 16 | - fix reserved words in shorthand properties [transform-es2015-shorthand-properties](https://github.com/alekseykulikov/babel-preset-es2015-node5/issues/10) 17 | 18 | ## Install 19 | 20 | npm install --save-dev babel-preset-es2015-node5 21 | 22 | ## Usage 23 | 24 | Read ["Configuring Babel 6" article](http://www.2ality.com/2015/11/configuring-babel6.html) 25 | for more information about babel@6 configuration. 26 | 27 | ### Via `.babelrc` (recommended) 28 | 29 | **.babelrc** 30 | 31 | ```json 32 | { 33 | "presets": ["es2015-node5"] 34 | } 35 | ``` 36 | 37 | ### Via CLI 38 | 39 | babel script.js --presets es2015-node5 40 | 41 | ### Via Node API 42 | 43 | ```js 44 | require('babel-core').transform('code', { 45 | presets: ['es2015-node5'], 46 | }) 47 | ``` 48 | 49 | ## License 50 | 51 | [MIT](./LICENSE) 52 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('babel-plugin-transform-es2015-destructuring'), 4 | require('babel-plugin-transform-es2015-modules-commonjs'), 5 | require('babel-plugin-transform-es2015-parameters'), 6 | require('babel-plugin-transform-es2015-sticky-regex'), 7 | require('babel-plugin-transform-es2015-unicode-regex'), 8 | require('babel-plugin-transform-es2015-function-name'), 9 | require('babel-plugin-transform-es2015-shorthand-properties'), 10 | ], 11 | } 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-preset-es2015-node5", 3 | "description": "Babel preset to make node@5 fully ES2015 compatible.", 4 | "repository": "alekseykulikov/babel-preset-es2015-node5", 5 | "version": "1.2.0", 6 | "license": "MIT", 7 | "keywords": [ 8 | "babel-preset-es2015", 9 | "babel-preset", 10 | "babel", 11 | "node5", 12 | "es2015", 13 | "es6" 14 | ], 15 | "main": "lib/index.js", 16 | "files": [ 17 | "lib" 18 | ], 19 | "scripts": { 20 | "test": "eslint lib/ test/ && mocha test/index.js" 21 | }, 22 | "dependencies": { 23 | "babel-plugin-transform-es2015-destructuring": "^6.6.5", 24 | "babel-plugin-transform-es2015-function-name": "^6.5.0", 25 | "babel-plugin-transform-es2015-modules-commonjs": "^6.7.0", 26 | "babel-plugin-transform-es2015-parameters": "^6.7.0", 27 | "babel-plugin-transform-es2015-shorthand-properties": "^6.5.0", 28 | "babel-plugin-transform-es2015-sticky-regex": "^6.5.0", 29 | "babel-plugin-transform-es2015-unicode-regex": "^6.5.0" 30 | }, 31 | "devDependencies": { 32 | "babel-core": "^6.7.2", 33 | "babel-eslint": "^5.0.0-beta6", 34 | "chai": "^3.5.0", 35 | "eslint": "^1.10.3", 36 | "eslint-config-airbnb": "^3.1.0", 37 | "mocha": "^2.4.5" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/babel.js: -------------------------------------------------------------------------------- 1 | require('babel-core/register')(require('../lib')) 2 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai' 2 | 3 | describe('babel-preset-es2015-node5', () => { 4 | it('parameters', () => { 5 | const arrayOf = (...args) => args 6 | const sum = (a = 1, b = a) => a + b 7 | const pushArray = (a1, a2) => { 8 | a1.push(...a2) 9 | return a1 10 | } 11 | 12 | expect(arrayOf(1, 2, 3)).eql([1, 2, 3]) 13 | expect(sum()).equal(2) 14 | expect(pushArray([1], [2])).eql([1, 2]) 15 | }) 16 | 17 | it('regexps', () => { 18 | expect('𠮷'.match(/^.$/u)[0].length).equal(2) // eslint-disable-line no-empty-character-class 19 | expect('𝌆'.match(/\u{1d306}/u)[0].length).equal(2) // eslint-disable-line no-empty-character-class 20 | }) 21 | 22 | it('block scope', () => { 23 | const arr = ['a', 'b', 'c'] 24 | const arrCopy = [] 25 | for (const key of arr) { 26 | arrCopy.push(key) 27 | } 28 | expect(arrCopy).eql(arr) 29 | 30 | const obj = { a: 'b', c: 'd', e: 'f' } 31 | const objCopy = {} 32 | for (const key in obj) { 33 | if (obj.hasOwnProperty(key)) { 34 | objCopy[key] = obj[key] 35 | } 36 | } 37 | expect(objCopy).eql(obj) 38 | }) 39 | 40 | it('shorthand properties', () => { 41 | let val = 1 42 | function get() { return val } 43 | function set(key) { val = key } 44 | 45 | const obj = { get, set } 46 | expect(obj.get()).equal(1) 47 | obj.set(5) 48 | expect(obj.get()).equal(5) 49 | }) 50 | }) 51 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --colors 3 | --require ./test/babel 4 | --------------------------------------------------------------------------------