Stop building JSXTransformer
Pick of/closes #4148.
Paul O’Shannessy committed
Jun 16, 2015 at 11:01 UTC
31f25255b9c03fe293a3ce97732fc411abc40731
6 files changed
+12
-358
.travis.yml
-1
@@ -49,7 +49,6 @@ script:
49
curl \
50
-F "react=@build/react.js" \
51
-F "react.min=@build/react.min.js" \
52
- -F "transformer=@build/JSXTransformer.js" \
52
-F "react-with-addons=@build/react-with-addons.js" \
53
-F "react-with-addons.min=@build/react-with-addons.min.js" \
54
-F "react-dom=@build/react-dom.js" \
Gruntfile.js
-5
@@ -89,10 +89,6 @@ module.exports = function(grunt) {
89
'build-modules',
90
'browserify:addons',
91
]);
92
- grunt.registerTask('build:transformer', [
93
- 'build-modules',
94
- 'browserify:transformer',
95
- ]);
92
grunt.registerTask('build:min', [
93
'build-modules',
94
'version-check',
@@ -121,7 +117,6 @@ module.exports = function(grunt) {
117
'build-modules',
118
'version-check',
119
'browserify:basic',
124
- 'browserify:transformer',
120
'browserify:addons',
121
'browserify:min',
122
'browserify:addonsMin',
grunt/config/browserify.js
-17
@@ -79,22 +79,6 @@ var min = {
79
after: [minify, bannerify],
80
};
81
82
-var transformer = {
83
- entries:[
84
- './vendor/browser-transforms.js',
85
- ],
86
- outfile: './build/JSXTransformer.js',
87
- debug: false,
88
- standalone: 'JSXTransformer',
89
- transforms: [],
90
- // Source-map-generator uses amdefine, which looks at the type of __dereq__.
91
- // If it's not a string, it assumes something else (array of strings), but
92
- // collapser passes a number; this would throw.
93
-
94
- // plugins: [collapser],
95
- after: [derequire, simpleBannerify],
96
-};
97
-
82
var addons = {
83
entries: [
84
'./build/modules/ReactWithAddons.js',
@@ -128,7 +112,6 @@ var addonsMin = {
112
module.exports = {
113
basic: basic,
114
min: min,
131
- transformer: transformer,
115
addons: addons,
116
addonsMin: addonsMin,
117
};
grunt/tasks/npm-react.js
+6
-3
@@ -9,9 +9,12 @@ var modSrc = 'build/modules/';
9
var lib = dest + 'lib/';
10
var dist = dest + 'dist/';
11
var distFiles = [
12
- 'react.js', 'react.min.js', 'JSXTransformer.js',
13
- 'react-with-addons.js', 'react-with-addons.min.js',
14
- 'react-dom.js', 'react-dom.min.js',
12
+ 'react.js',
13
+ 'react.min.js',
14
+ 'react-with-addons.js',
15
+ 'react-with-addons.min.js',
16
+ 'react-dom.js',
17
+ 'react-dom.min.js',
18
];
19
20
function buildRelease() {
grunt/tasks/release.js
+6
-3
@@ -5,9 +5,12 @@ var grunt = require('grunt');
5
var BOWER_PATH = '../react-bower/';
6
var BOWER_GLOB = [BOWER_PATH + '*.{js}'];
7
var BOWER_FILES = [
8
- 'react.js', 'react.min.js', 'JSXTransformer.js',
9
- 'react-with-addons.js', 'react-with-addons.min.js',
10
- 'react-dom.js', 'react-dom.min.js',
8
+ 'react.js',
9
+ 'react.min.js',
10
+ 'react-with-addons.js',
11
+ 'react-with-addons.min.js',
12
+ 'react-dom.js',
13
+ 'react-dom.min.js',
14
];
15
var GH_PAGES_PATH = '../react-gh-pages/';
16
var GH_PAGES_GLOB = [GH_PAGES_PATH + '*'];
vendor/browser-transforms.js
deleted
-329
@@ -1,329 +0,0 @@
1
-/**
2
- * Copyright 2013-2015, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- */
9
-/* jslint evil: true */
10
-/*eslint-disable no-eval */
11
-/*eslint-disable block-scoped-var */
12
-
13
-'use strict';
14
-
15
-var jstransform = require('jstransform/simple');
16
-
17
-var headEl;
18
-var dummyAnchor;
19
-var inlineScriptCount = 0;
20
-
21
-// The source-map library relies on Object.defineProperty, but IE8 doesn't
22
-// support it fully even with es5-sham. Indeed, es5-sham's defineProperty
23
-// throws when Object.prototype.__defineGetter__ is missing, so we skip building
24
-// the source map in that case.
25
-var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
26
-
27
-/**
28
- * Run provided code through jstransform.
29
- *
30
- * @param {string} source Original source code
31
- * @param {object?} options Options to pass to jstransform
32
- * @return {object} object as returned from jstransform
33
- */
34
-function transformReact(source, options) {
35
- options = options || {};
36
-
37
- // Always enable the React transforms.
38
- options.react = true;
39
-
40
- // Force the sourcemaps option manually. We don't want to use it if it will
41
- // break (see above note about supportsAccessors). We'll only override the
42
- // value here if sourceMap was specified and is truthy. This guarantees that
43
- // we won't override any user intent (since this method is exposed publicly).
44
- if (options.sourceMap) {
45
- options.sourceMap = supportsAccessors;
46
- }
47
-
48
- // Otherwise just pass all options straight through to react-tools.
49
- return jstransform.transform(source, options);
50
-}
51
-
52
-/**
53
- * Eval provided source after transforming it.
54
- *
55
- * @param {string} source Original source code
56
- * @param {object?} options Options to pass to jstransform
57
- */
58
-function exec(source, options) {
59
- return eval(transformReact(source, options).code);
60
-}
61
-
62
-/**
63
- * This method returns a nicely formated line of code pointing to the exact
64
- * location of the error `e`. The line is limited in size so big lines of code
65
- * are also shown in a readable way.
66
- *
67
- * Example:
68
- * ... x', overflow:'scroll'}} id={} onScroll={this.scroll} class=" ...
69
- * ^
70
- *
71
- * @param {string} code The full string of code
72
- * @param {Error} e The error being thrown
73
- * @return {string} formatted message
74
- * @internal
75
- */
76
-function createSourceCodeErrorMessage(code, e) {
77
- var sourceLines = code.split('\n');
78
- // e.lineNumber is non-standard so we can't depend on its availability. If
79
- // we're in a browser where it isn't supported, don't even bother trying to
80
- // format anything. We may also hit a case where the line number is reported
81
- // incorrectly and is outside the bounds of the actual code. Handle that too.
82
- if (!e.lineNumber || e.lineNumber > sourceLines.length) {
83
- return '';
84
- }
85
- var erroneousLine = sourceLines[e.lineNumber - 1];
86
-
87
- // Removes any leading indenting spaces and gets the number of
88
- // chars indenting the `erroneousLine`
89
- var indentation = 0;
90
- erroneousLine = erroneousLine.replace(/^\s+/, function(leadingSpaces) {
91
- indentation = leadingSpaces.length;
92
- return '';
93
- });
94
-
95
- // Defines the number of characters that are going to show
96
- // before and after the erroneous code
97
- var LIMIT = 30;
98
- var errorColumn = e.column - indentation;
99
-
100
- if (errorColumn > LIMIT) {
101
- erroneousLine = '... ' + erroneousLine.slice(errorColumn - LIMIT);
102
- errorColumn = 4 + LIMIT;
103
- }
104
- if (erroneousLine.length - errorColumn > LIMIT) {
105
- erroneousLine = erroneousLine.slice(0, errorColumn + LIMIT) + ' ...';
106
- }
107
- var message = '\n\n' + erroneousLine + '\n';
108
- message += new Array(errorColumn - 1).join(' ') + '^';
109
- return message;
110
-}
111
-
112
-/**
113
- * Actually transform the code.
114
- *
115
- * @param {string} code
116
- * @param {string?} url
117
- * @param {object?} options
118
- * @return {string} The transformed code.
119
- * @internal
120
- */
121
-function transformCode(code, url, options) {
122
- try {
123
- return transformReact(code, options).code;
124
- } catch(e) {
125
- e.message += '\n at ';
126
- if (url) {
127
- if ('fileName' in e) {
128
- // We set `fileName` if it's supported by this error object and
129
- // a `url` was provided.
130
- // The error will correctly point to `url` in Firefox.
131
- e.fileName = url;
132
- }
133
- e.message += url + ':' + e.lineNumber + ':' + e.columnNumber;
134
- } else {
135
- e.message += location.href;
136
- }
137
- e.message += createSourceCodeErrorMessage(code, e);
138
- throw e;
139
- }
140
-}
141
-
142
-
143
-/**
144
- * Appends a script element at the end of the <head> with the content of code,
145
- * after transforming it.
146
- *
147
- * @param {string} code The original source code
148
- * @param {string?} url Where the code came from. null if inline
149
- * @param {object?} options Options to pass to jstransform
150
- * @internal
151
- */
152
-function run(code, url, options) {
153
- var scriptEl = document.createElement('script');
154
- scriptEl.text = transformCode(code, url, options);
155
- headEl.appendChild(scriptEl);
156
-}
157
-
158
-/**
159
- * Load script from the provided url and pass the content to the callback.
160
- *
161
- * @param {string} url The location of the script src
162
- * @param {function} successCallback Function to call with the content of url
163
- * @param {function} errorCallback Function to call if error
164
- * @internal
165
- */
166
-function load(url, successCallback, errorCallback) {
167
- var xhr;
168
- xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP')
169
- : new XMLHttpRequest();
170
-
171
- // async, however scripts will be executed in the order they are in the
172
- // DOM to mirror normal script loading.
173
- xhr.open('GET', url, true);
174
- if ('overrideMimeType' in xhr) {
175
- xhr.overrideMimeType('text/plain');
176
- }
177
- xhr.onreadystatechange = function() {
178
- if (xhr.readyState === 4) {
179
- if (xhr.status === 0 || xhr.status === 200) {
180
- successCallback(xhr.responseText);
181
- } else {
182
- errorCallback();
183
- throw new Error('Could not load ' + url);
184
- }
185
- }
186
- };
187
- return xhr.send(null);
188
-}
189
-
190
-/**
191
- * Loop over provided script tags and get the content, via innerHTML if an
192
- * inline script, or by using XHR. Transforms are applied if needed. The scripts
193
- * are executed in the order they are found on the page.
194
- *
195
- * @param {array} scripts The <script> elements to load and run.
196
- * @internal
197
- */
198
-function loadScripts(scripts) {
199
- var result = [];
200
- var count = scripts.length;
201
-
202
- function check() {
203
- var script, i;
204
-
205
- for (i = 0; i < count; i++) {
206
- script = result[i];
207
-
208
- if (script.loaded && !script.executed) {
209
- script.executed = true;
210
- run(script.content, script.url, script.options);
211
- } else if (!script.loaded && !script.error && !script.async) {
212
- break;
213
- }
214
- }
215
- }
216
-
217
- scripts.forEach(function(script, i) {
218
- // Determine the filename to use for the sourcemap.
219
- var sourceFilename;
220
- if (script.src == null) {
221
- sourceFilename = 'Inline JSX script';
222
- inlineScriptCount++;
223
- if (inlineScriptCount > 1) {
224
- sourceFilename += ' (' + inlineScriptCount + ')';
225
- }
226
- } else if (dummyAnchor) {
227
- // Firefox has problems when the sourcemap sourceFilename is a proper URL
228
- // with a protocol and hostname, so use the pathname. We could use just
229
- // the filename, but hopefully using the full path will prevent potential
230
- // issues where the same filename exists in multiple directories.
231
- dummyAnchor.href = script.src;
232
- sourceFilename = dummyAnchor.pathname.substr(1);
233
- }
234
-
235
- var options = {
236
- sourceMapInline: true,
237
- sourceFilename: sourceFilename,
238
- };
239
- if (/;harmony=true(;|$)/.test(script.type)) {
240
- options.harmony = true;
241
- }
242
- if (/;stripTypes=true(;|$)/.test(script.type)) {
243
- options.stripTypes = true;
244
- }
245
-
246
- // script.async is always true for non-javascript script tags
247
- var async = script.hasAttribute('async');
248
-
249
- if (script.src) {
250
- result[i] = {
251
- async: async,
252
- error: false,
253
- executed: false,
254
- content: null,
255
- loaded: false,
256
- url: script.src,
257
- options: options,
258
- };
259
-
260
- load(script.src, function(content) {
261
- result[i].loaded = true;
262
- result[i].content = content;
263
- check();
264
- }, function() {
265
- result[i].error = true;
266
- check();
267
- });
268
- } else {
269
- result[i] = {
270
- async: async,
271
- error: false,
272
- executed: false,
273
- content: script.innerHTML,
274
- loaded: true,
275
- url: null,
276
- options: options,
277
- };
278
- }
279
- });
280
-
281
- check();
282
-}
283
-
284
-/**
285
- * Find and run all script tags with type="text/jsx".
286
- *
287
- * @internal
288
- */
289
-function runScripts() {
290
- var scripts = document.getElementsByTagName('script');
291
-
292
- // Array.prototype.slice cannot be used on NodeList on IE8
293
- var jsxScripts = [];
294
- for (var i = 0; i < scripts.length; i++) {
295
- if (/^text\/jsx(;|$)/.test(scripts.item(i).type)) {
296
- jsxScripts.push(scripts.item(i));
297
- }
298
- }
299
-
300
- if (jsxScripts.length < 1) {
301
- return;
302
- }
303
-
304
- console.warn(
305
- 'You are using the in-browser JSX transformer. Be sure to precompile ' +
306
- 'your JSX for production - ' +
307
- 'http://facebook.github.io/react/docs/tooling-integration.html#jsx'
308
- );
309
-
310
- loadScripts(jsxScripts);
311
-}
312
-
313
-// Listen for load event if we're in a browser and then kick off finding and
314
-// running of scripts.
315
-if (typeof window !== 'undefined' && window !== null) {
316
- headEl = document.getElementsByTagName('head')[0];
317
- dummyAnchor = document.createElement('a');
318
-
319
- if (window.addEventListener) {
320
- window.addEventListener('DOMContentLoaded', runScripts, false);
321
- } else {
322
- window.attachEvent('onload', runScripts);
323
- }
324
-}
325
-
326
-module.exports = {
327
- transform: transformReact,
328
- exec: exec,
329
-};