Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Aug 19, 2014
0 parents commit 5223502
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_js:
- "0.11"
language: node_js
script: "npm run-script test-travis"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# es6-shorthands

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

This will simply replace the new ES6 shorthand method syntax with the
corresponding ES5 equivalent.

So `{a, b() {}}` becomes `{a: a, b: function b() {}}`


[npm-image]: https://img.shields.io/npm/v/es6-shorthands.svg?style=flat
[npm-url]: https://npmjs.org/package/es6-shorthands
[travis-image]: https://img.shields.io/travis/polyfills/es6-shorthands.svg?style=flat
[travis-url]: https://travis-ci.org/polyfills/es6-shorthands
[coveralls-image]: https://img.shields.io/coveralls/polyfills/es6-shorthands.svg?style=flat
[coveralls-url]: https://coveralls.io/r/polyfills/es6-shorthands?branch=master

17 changes: 17 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* vim: set shiftwidth=2 tabstop=2 noexpandtab textwidth=80 wrap : */
"use strict";

var recast = require('recast');
var types = recast.types;
var b = types.builders;

exports.transform = function (ast) {
return types.visit(ast.program, {
visitProperty: function (path) {
path.value.method = false;
path.value.shorthand = false;
this.traverse(path);
}
});
};

30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "es6-shorthands",
"description": "An ES6 and CommonJS cross-compatible transpiler",
"version": "0.0.1",
"author": "Arpad Borsos <arpad.borsos@googlemail.com> (http://swatinem.de)",
"license": "MIT",
"repository": "polyfills/es6-shorthands",
"dependencies": {
"recast": "0"
},
"devDependencies": {
"esprima": "git://github.com/esnext/esprima#harmony-esnext",
"mocha": "1",
"istanbul": "0"
},
"scripts": {
"test": "mocha --reporter spec --bail test/index.js",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/index.js",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot test/index.js"
},
"keywords": [
"es6",
"transpiler",
"shorthands"
],
"main": "lib",
"files": [
"lib"
]
}
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* vim: set shiftwidth=2 tabstop=2 noexpandtab textwidth=80 wrap : */
"use strict";

var recast = require('recast');
var esprima = require('esprima');
var assert = require('assert');
var shorthands = require('../');

function transform(source) {
var ast = recast.parse(source, {esprima: esprima});
ast = shorthands.transform(ast);
return recast.print(ast);
}

describe('es6-shorthands', function () {
it('should transform shorthand properties', function () {
assert.equal(transform('({a, b, c, d: d})').code, '({a: a, b: b, c: c, d: d})');
});
it('should transform shorthand methods', function () {
assert.equal(transform('({a, m() { method; }})').code, '({a: a, m: function() { method; }})');
});
});

0 comments on commit 5223502

Please sign in to comment.