Skip to content

Commit

Permalink
feat(es2015): add es2015 implementation to support rollup (#10)
Browse files Browse the repository at this point in the history
* feat(es2015): add es2015 implementation to support rollup

The build now comes from the es2015 files under the `es/` directory.

closes #9

* chore(package): add es files and lib files to npm files

* chore(package): ensure build and test before publish

* refactor(ponyfill): make Symbol const

* chore(ponyfill test): update tests to look at built file

* refactor(all): ensure only es6 feature used is modules
  • Loading branch information
benlesh committed May 28, 2016
1 parent 5f4c2c6 commit 7a41de9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["add-module-exports"],
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
lib
11 changes: 11 additions & 0 deletions es/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* global window */
import ponyfill from './ponyfill';

let root = this;

This comment has been minimized.

Copy link
@TrySound

TrySound Sep 8, 2016

es modules doesn't have own context. And top-level this keyword compiles to undefined by rollup. It's possible to set context option. But it's a hack. Let's do something like this

var root = typeof global !== undefined ? global : window;
if (typeof global !== 'undefined') {
root = global;
} else if (typeof window !== 'undefined') {
root = window;
}

export default ponyfill(root);
4 changes: 1 addition & 3 deletions ponyfill.js → es/ponyfill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function symbolObservablePonyfill(root) {
export default function symbolObservablePonyfill(root) {
var result;
var Symbol = root.Symbol;

Expand Down
11 changes: 1 addition & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
/* global window */
'use strict';

var root = this;
if (typeof global !== 'undefined') {
root = global;
} else if (typeof window !== 'undefined') {
root = window;
}
module.exports = require('./ponyfill')(root);
module.exports = require('./lib/');
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
"build": "babel es --out-dir lib",
"test": "npm run build && mocha",
"prepublish": "npm test"
},
"files": [
"index.js",
"ponyfill.js",
"index.d.ts"
"index.d.ts",
"es/index.js",
"es/ponyfill/js",
"lib/index.js",
"lib/ponyfill.js"
],
"keywords": [
"symbol",
Expand All @@ -28,6 +34,9 @@
"shim"
],
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.9.0",
"chai": "^3.5.0",
"mocha": "^2.4.5"
}
Expand Down
2 changes: 1 addition & 1 deletion test/ponyfill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global describe, it */
var expect = require('chai').expect;
var ponyfill = require('../ponyfill');
var ponyfill = require('../lib/ponyfill');

describe('ponyfill unit tests', function () {
describe('when Symbol does NOT exist as a function', function () {
Expand Down

0 comments on commit 7a41de9

Please sign in to comment.