JSXTransformer: don't look for docblock
Paul O’Shannessy committed
Oct 10, 2014 at 11:27 UTC
cf5fea46168ce97313730d07014223e0c11267ff
1 file changed
+41
-51
vendor/browser-transforms.js
+41
-51
@@ -19,7 +19,6 @@
19
'use strict';
20
21
var buffer = require('buffer');
22
-var docblock = require('jstransform/src/docblock');
22
var transform = require('jstransform').transform;
23
var visitors = require('./fbtransform/visitors');
24
@@ -118,62 +117,53 @@ function createSourceCodeErrorMessage(code, e) {
117
* @internal
118
*/
119
function transformCode(code, url, options) {
121
- var jsx = docblock.parseAsObject(docblock.extract(code)).jsx;
122
-
123
- if (jsx) {
124
- try {
125
- var transformed = transformReact(code, options);
126
- } catch(e) {
127
- e.message += '\n at ';
128
- if (url) {
129
- if ('fileName' in e) {
130
- // We set `fileName` if it's supported by this error object and
131
- // a `url` was provided.
132
- // The error will correctly point to `url` in Firefox.
133
- e.fileName = url;
134
- }
135
- e.message += url + ':' + e.lineNumber + ':' + e.column;
136
- } else {
137
- e.message += location.href;
120
+ try {
121
+ var transformed = transformReact(code, options);
122
+ } catch(e) {
123
+ e.message += '\n at ';
124
+ if (url) {
125
+ if ('fileName' in e) {
126
+ // We set `fileName` if it's supported by this error object and
127
+ // a `url` was provided.
128
+ // The error will correctly point to `url` in Firefox.
129
+ e.fileName = url;
130
}
139
- e.message += createSourceCodeErrorMessage(code, e);
140
- throw e;
131
+ e.message += url + ':' + e.lineNumber + ':' + e.column;
132
+ } else {
133
+ e.message += location.href;
134
}
135
+ e.message += createSourceCodeErrorMessage(code, e);
136
+ throw e;
137
+ }
138
143
- if (!transformed.sourceMap) {
144
- return transformed.code;
145
- }
139
+ if (!transformed.sourceMap) {
140
+ return transformed.code;
141
+ }
142
147
- var map = transformed.sourceMap.toJSON();
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);
143
+ var map = transformed.sourceMap.toJSON();
144
+ var source;
145
+ if (url == null) {
146
+ source = "Inline JSX script";
147
+ inlineScriptCount++;
148
+ if (inlineScriptCount > 1) {
149
+ source += ' (' + inlineScriptCount + ')';
150
}
163
- map.sources = [source];
164
- map.sourcesContent = [code];
165
-
166
- return (
167
- transformed.code +
168
- '\n//# sourceMappingURL=data:application/json;base64,' +
169
- buffer.Buffer(JSON.stringify(map)).toString('base64')
170
- );
171
- } else {
172
- // TODO: warn that we found a script tag missing the docblock?
173
- // or warn and proceed anyway?
174
- // or warn, add it ourselves, and proceed anyway?
175
- return code;
151
+ } else if (dummyAnchor) {
152
+ // Firefox has problems when the sourcemap source is a proper URL with a
153
+ // protocol and hostname, so use the pathname. We could use just the
154
+ // filename, but hopefully using the full path will prevent potential
155
+ // issues where the same filename exists in multiple directories.
156
+ dummyAnchor.href = url;
157
+ source = dummyAnchor.pathname.substr(1);
158
}
159
+ map.sources = [source];
160
+ map.sourcesContent = [code];
161
+
162
+ return (
163
+ transformed.code +
164
+ '\n//# sourceMappingURL=data:application/json;base64,' +
165
+ buffer.Buffer(JSON.stringify(map)).toString('base64')
166
+ );
167
}
168
169