Skip to content

Commit

Permalink
Add global dep and fix Babel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed May 1, 2016
1 parent 55de8a0 commit fa2b745
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 55 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"babel-template": "^6.7.0",
"global": "^4.3.0",
"react-deep-force-update": "^2.0.1",
"react-proxy": "^3.0.0-alpha.0",
"redbox-react": "^1.2.3",
Expand Down
9 changes: 7 additions & 2 deletions src/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ const buildRegistration = template('tagSource(ID, NAME);');
const buildSemi = template(';');
const buildTagger = template(`
(function () {
if (typeof __REACT_HOT_LOADER__ === 'undefined') {
return;
}
var fileName = FILENAME;
function tagSource(fn, localName) {
if (typeof fn !== "function") {
return;
}
var id = FILENAME + '#' + localName;
__REACT_HOT_LOADER__.set(id, fn);
var id = fileName + '#' + localName;
__REACT_HOT_LOADER__.register(id, fn);
}
REGISTRATIONS
})();
Expand Down
3 changes: 2 additions & 1 deletion src/resolveType.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const createProxy = require('react-proxy').default;
const global = require('global');

let proxiesByID = {};
let idsByType = new WeakMap();

window.__REACT_HOT_LOADER__ = {
global.__REACT_HOT_LOADER__ = {
set(id, component) {
idsByType.set(component, id);
}
Expand Down
21 changes: 8 additions & 13 deletions src/webpack/tagCommonJSExports.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
;(function () {
/* react-hot-loader/webpack */
if (process.env.NODE_ENV !== 'production') {
if (typeof __REACT_HOT_LOADER__ === 'undefined') {
return;
}

const fileName = __FILENAME__;
function tagSource(fn, localName) {
if (typeof fn !== 'function') {
return;
}
if (fn.hasOwnProperty('__source')) {
return;
}
try {
Object.defineProperty(fn, '__source', {
enumerable: false,
configurable: true,
value: {
fileName: __FILENAME__,
localName: localName
}
});
} catch (err) { }

const id = fileName + '#' + localName;
__REACT_HOT_LOADER__.register(id, fn);
}

if (typeof module.exports === 'function') {
Expand Down
21 changes: 8 additions & 13 deletions test/babel/fixtures/bindings/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@ export default _default;
;

(function () {
if (typeof __REACT_HOT_LOADER__ === 'undefined') {
return;
}

var fileName = __FILENAME__;

function tagSource(fn, localName) {
if (typeof fn !== "function") {
return;
}

if (fn.hasOwnProperty("__source")) {
return;
}
var id = fileName + '#' + localName;

try {
Object.defineProperty(fn, "__source", {
enumerable: false,
configurable: true,
value: {
fileName: __FILENAME__,
localName: localName
}
});
} catch (err) {}
__REACT_HOT_LOADER__.register(id, fn);
}

tagSource(A, "A");
Expand Down
21 changes: 8 additions & 13 deletions test/babel/fixtures/counter/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@ exports.default = _default;
;

(function () {
if (typeof __REACT_HOT_LOADER__ === 'undefined') {
return;
}

var fileName = __FILENAME__;

function tagSource(fn, localName) {
if (typeof fn !== "function") {
return;
}

if (fn.hasOwnProperty("__source")) {
return;
}
var id = fileName + '#' + localName;

try {
Object.defineProperty(fn, "__source", {
enumerable: false,
configurable: true,
value: {
fileName: __FILENAME__,
localName: localName
}
});
} catch (err) {}
__REACT_HOT_LOADER__.register(id, fn);
}

tagSource(Counter, "Counter");
Expand Down
21 changes: 8 additions & 13 deletions test/babel/fixtures/issue-246/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,20 @@ function spread() {
;

(function () {
if (typeof __REACT_HOT_LOADER__ === 'undefined') {
return;
}

var fileName = __FILENAME__;

function tagSource(fn, localName) {
if (typeof fn !== "function") {
return;
}

if (fn.hasOwnProperty("__source")) {
return;
}
var id = fileName + '#' + localName;

try {
Object.defineProperty(fn, "__source", {
enumerable: false,
configurable: true,
value: {
fileName: __FILENAME__,
localName: localName
}
});
} catch (err) {}
__REACT_HOT_LOADER__.register(id, fn);
}

tagSource(spread, "spread");
Expand Down

0 comments on commit fa2b745

Please sign in to comment.