-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5223502
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; }})'); | ||
}); | ||
}); |