* Actually transform the code. * * @param {string} code * @param {string?} url * @param {object?} options * @return {string} The transformed code. * @internal
(code, url, options)
| 122 | * @internal |
| 123 | */ |
| 124 | function transformCode(code, url, options) { |
| 125 | try { |
| 126 | var transformed = transformReact(code, options); |
| 127 | } catch(e) { |
| 128 | e.message += '\n at '; |
| 129 | if (url) { |
| 130 | if ('fileName' in e) { |
| 131 | // We set `fileName` if it's supported by this error object and |
| 132 | // a `url` was provided. |
| 133 | // The error will correctly point to `url` in Firefox. |
| 134 | e.fileName = url; |
| 135 | } |
| 136 | e.message += url + ':' + e.lineNumber + ':' + e.columnNumber; |
| 137 | } else { |
| 138 | e.message += location.href; |
| 139 | } |
| 140 | e.message += createSourceCodeErrorMessage(code, e); |
| 141 | throw e; |
| 142 | } |
| 143 | |
| 144 | if (!transformed.sourceMap) { |
| 145 | return transformed.code; |
| 146 | } |
| 147 | |
| 148 | var source; |
| 149 | if (url == null) { |
| 150 | source = 'Inline JSX script'; |
| 151 | inlineScriptCount++; |
| 152 | if (inlineScriptCount > 1) { |
| 153 | source += ' (' + inlineScriptCount + ')'; |
| 154 | } |
| 155 | } else if (dummyAnchor) { |
| 156 | // Firefox has problems when the sourcemap source is a proper URL with a |
| 157 | // protocol and hostname, so use the pathname. We could use just the |
| 158 | // filename, but hopefully using the full path will prevent potential |
| 159 | // issues where the same filename exists in multiple directories. |
| 160 | dummyAnchor.href = url; |
| 161 | source = dummyAnchor.pathname.substr(1); |
| 162 | } |
| 163 | |
| 164 | return ( |
| 165 | transformed.code + |
| 166 | '\n' + |
| 167 | inlineSourceMap(transformed.sourceMap, code, source) |
| 168 | ); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /** |
no test coverage detected