(args, options = {})
| 15 | /* eslint-enable */ |
| 16 | |
| 17 | function plugin(args, options = {}) { |
| 18 | // This is a Babel plugin, but the user put it in the Webpack config. |
| 19 | if (this && this.callback) { |
| 20 | throw new Error( |
| 21 | 'React Hot Loader: You are erroneously trying to use a Babel plugin ' + |
| 22 | 'as a Webpack loader. We recommend that you use Babel, ' + |
| 23 | 'remove "react-hot-loader/babel" from the "loaders" section ' + |
| 24 | 'of your Webpack configuration, and instead add ' + |
| 25 | '"react-hot-loader/babel" to the "plugins" section of your .babelrc file. ' + |
| 26 | 'If you prefer not to use Babel, replace "react-hot-loader/babel" with ' + |
| 27 | '"react-hot-loader/webpack" in the "loaders" section of your Webpack configuration. ', |
| 28 | ); |
| 29 | } |
| 30 | const { types: t, template } = args; |
| 31 | |
| 32 | const { safetyNet = true } = options; |
| 33 | |
| 34 | const buildRegistration = template('reactHotLoader.register(ID, NAME, FILENAME);', templateOptions); |
| 35 | |
| 36 | const signatureHeader = template( |
| 37 | `var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {return a;}`, |
| 38 | templateOptions, |
| 39 | ); |
| 40 | |
| 41 | const headerTemplate = template( |
| 42 | `(function () { |
| 43 | var enterModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined); |
| 44 | enterModule && enterModule(module); |
| 45 | }())`, |
| 46 | templateOptions, |
| 47 | ); |
| 48 | const footerTemplate = template( |
| 49 | `(function () { |
| 50 | var leaveModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined); |
| 51 | leaveModule && leaveModule(module); |
| 52 | }())`, |
| 53 | templateOptions, |
| 54 | ); |
| 55 | const evalTemplate = template('this[key]=eval(code);', templateOptions); |
| 56 | |
| 57 | // We're making the IIFE we insert at the end of the file an unused variable |
| 58 | // because it otherwise breaks the output of the babel-node REPL (#359). |
| 59 | |
| 60 | const buildTagger = template( |
| 61 | ` |
| 62 | (function () { |
| 63 | |
| 64 | var reactHotLoader = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined); |
| 65 | |
| 66 | if (!reactHotLoader) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | REGISTRATIONS |
| 71 | }()); |
| 72 | `, |
| 73 | templateOptions, |
| 74 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected