Skip to content

Commit

Permalink
ES2015ify and require Node.js 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 30, 2017
1 parent 76e30a0 commit 0ecaa94
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
sudo: false
language: node_js
node_js:
- '5'
- '6'
- '4'
- '0.12'
- '0.10'
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
module.exports = function toFastproperties(o) {
function Sub() {}
Sub.prototype = o;
var receiver = new Sub(); // create an instance
function ic() { return typeof receiver.foo; } // perform access
ic();
const receiver = new Sub(); // Create an instance
function ic() {
return typeof receiver.foo; // Perform access
}
ic();
ic();
return o;
eval("o" + o); // ensure no dead code elimination
}
eval('o' + o); // Ensure no dead code elimination
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "node --allow-natives-syntax test.js"
Expand Down
15 changes: 8 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict';
var test = require('ava');
var toFastProperties = require('./');
const test = require('ava');
const toFastProperties = require('.');

var toSlowProperties = function (obj) {
for (var i = 0; i < 1000; ++i) {
obj['foo' + i] = 'foo';
const toSlowProperties = obj => {
for (let i = 0; i < 1000; i++) {
obj[`foo${i}`] = 'foo';
}

return obj;
};

test(function (t) {
var obj = toSlowProperties({});
test(t => {
const obj = toSlowProperties({});
obj.foo = 'foo';
t.assert(!%HasFastProperties(obj), 'obj has slow properties');

Expand Down

0 comments on commit 0ecaa94

Please sign in to comment.