Skip to content

Commit f5d736f

Browse files
authored
Merge pull request #26 from wojtekmaj/bugfix/commonjs-in-es5
Fix ES2015 imports not transpiled to commonJS in es5
2 parents 02dfa52 + 580b17b commit f5d736f

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"react"
1111
],
1212
"plugins": [
13-
"babel-plugin-transform-class-properties"
13+
"transform-class-properties",
14+
"transform-es2015-modules-commonjs"
1415
]
1516
}

es5/react-pdf.js

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
17
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
28

39
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
410

11+
var _react = require('react');
12+
13+
var _react2 = _interopRequireDefault(_react);
14+
15+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16+
517
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
618

719
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
820

921
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1022

11-
import React, { Component, PropTypes } from 'react';
12-
1323
require('pdfjs-dist/web/compatibility');
1424
require('pdfjs-dist/build/pdf');
1525
PDFJS.workerSrc = require('pdfjs-dist/build/pdf.worker.js');
@@ -219,7 +229,7 @@ var ReactPDF = function (_Component) {
219229
}, {
220230
key: 'renderNoData',
221231
value: function renderNoData() {
222-
return React.createElement(
232+
return _react2.default.createElement(
223233
'div',
224234
null,
225235
this.props.noData
@@ -228,7 +238,7 @@ var ReactPDF = function (_Component) {
228238
}, {
229239
key: 'renderError',
230240
value: function renderError() {
231-
return React.createElement(
241+
return _react2.default.createElement(
232242
'div',
233243
null,
234244
this.props.error
@@ -237,7 +247,7 @@ var ReactPDF = function (_Component) {
237247
}, {
238248
key: 'renderLoader',
239249
value: function renderLoader() {
240-
return React.createElement(
250+
return _react2.default.createElement(
241251
'div',
242252
null,
243253
this.props.loading
@@ -266,7 +276,7 @@ var ReactPDF = function (_Component) {
266276
return this.renderLoader();
267277
}
268278

269-
return React.createElement('canvas', {
279+
return _react2.default.createElement('canvas', {
270280
ref: function ref(_ref2) {
271281
if (!_ref2) return;
272282

@@ -311,7 +321,7 @@ var ReactPDF = function (_Component) {
311321
}]);
312322

313323
return ReactPDF;
314-
}(Component);
324+
}(_react.Component);
315325

316326
var _initialiseProps = function _initialiseProps() {
317327
var _this4 = this;
@@ -414,7 +424,7 @@ var _initialiseProps = function _initialiseProps() {
414424
};
415425
};
416426

417-
export default ReactPDF;
427+
exports.default = ReactPDF;
418428

419429

420430
ReactPDF.defaultProps = {
@@ -426,21 +436,21 @@ ReactPDF.defaultProps = {
426436
};
427437

428438
ReactPDF.propTypes = {
429-
error: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
430-
file: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(File), PropTypes.instanceOf(Blob), PropTypes.shape({
431-
data: PropTypes.object,
432-
httpHeaders: PropTypes.object,
433-
range: PropTypes.object,
434-
url: PropTypes.string
439+
error: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.node]),
440+
file: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.instanceOf(File), _react.PropTypes.instanceOf(Blob), _react.PropTypes.shape({
441+
data: _react.PropTypes.object,
442+
httpHeaders: _react.PropTypes.object,
443+
range: _react.PropTypes.object,
444+
url: _react.PropTypes.string
435445
})]),
436-
loading: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
437-
noData: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
438-
onDocumentError: PropTypes.func,
439-
onDocumentLoad: PropTypes.func,
440-
onPageError: PropTypes.func,
441-
onPageLoad: PropTypes.func,
442-
onPageRender: PropTypes.func,
443-
pageIndex: PropTypes.number,
444-
scale: PropTypes.number,
445-
width: PropTypes.number
446+
loading: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.node]),
447+
noData: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.node]),
448+
onDocumentError: _react.PropTypes.func,
449+
onDocumentLoad: _react.PropTypes.func,
450+
onPageError: _react.PropTypes.func,
451+
onPageLoad: _react.PropTypes.func,
452+
onPageRender: _react.PropTypes.func,
453+
pageIndex: _react.PropTypes.number,
454+
scale: _react.PropTypes.number,
455+
width: _react.PropTypes.number
446456
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"babel-eslint": "^7.1.1",
4646
"babel-loader": "^6.3.2",
4747
"babel-plugin-transform-class-properties": "^6.23.0",
48+
"babel-plugin-add-module-exports": "^0.2.1",
4849
"babel-preset-es2015": "^6.22.0",
4950
"babel-preset-react": "^6.23.0",
5051
"babel-preset-stage-2": "^6.22.0",

0 commit comments

Comments
 (0)