From 31f25255b9c03fe293a3ce97732fc411abc40731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 16 Jun 2015 11:01:15 -0700 Subject: [PATCH] Stop building JSXTransformer Pick of/closes #4148. --- .travis.yml | 1 - Gruntfile.js | 5 - grunt/config/browserify.js | 17 -- grunt/tasks/npm-react.js | 9 +- grunt/tasks/release.js | 9 +- vendor/browser-transforms.js | 329 ----------------------------------- 6 files changed, 12 insertions(+), 358 deletions(-) delete mode 100644 vendor/browser-transforms.js diff --git a/.travis.yml b/.travis.yml index 0e188d9a9c..36b070a99d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,6 @@ script: curl \ -F "react=@build/react.js" \ -F "react.min=@build/react.min.js" \ - -F "transformer=@build/JSXTransformer.js" \ -F "react-with-addons=@build/react-with-addons.js" \ -F "react-with-addons.min=@build/react-with-addons.min.js" \ -F "react-dom=@build/react-dom.js" \ diff --git a/Gruntfile.js b/Gruntfile.js index 3f4a02e3e3..c1bc0d265a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -89,10 +89,6 @@ module.exports = function(grunt) { 'build-modules', 'browserify:addons', ]); - grunt.registerTask('build:transformer', [ - 'build-modules', - 'browserify:transformer', - ]); grunt.registerTask('build:min', [ 'build-modules', 'version-check', @@ -121,7 +117,6 @@ module.exports = function(grunt) { 'build-modules', 'version-check', 'browserify:basic', - 'browserify:transformer', 'browserify:addons', 'browserify:min', 'browserify:addonsMin', diff --git a/grunt/config/browserify.js b/grunt/config/browserify.js index 0caa472976..b50ddbbae4 100644 --- a/grunt/config/browserify.js +++ b/grunt/config/browserify.js @@ -79,22 +79,6 @@ var min = { after: [minify, bannerify], }; -var transformer = { - entries:[ - './vendor/browser-transforms.js', - ], - outfile: './build/JSXTransformer.js', - debug: false, - standalone: 'JSXTransformer', - transforms: [], - // Source-map-generator uses amdefine, which looks at the type of __dereq__. - // If it's not a string, it assumes something else (array of strings), but - // collapser passes a number; this would throw. - - // plugins: [collapser], - after: [derequire, simpleBannerify], -}; - var addons = { entries: [ './build/modules/ReactWithAddons.js', @@ -128,7 +112,6 @@ var addonsMin = { module.exports = { basic: basic, min: min, - transformer: transformer, addons: addons, addonsMin: addonsMin, }; diff --git a/grunt/tasks/npm-react.js b/grunt/tasks/npm-react.js index 2ceaf79e33..1fd635275e 100644 --- a/grunt/tasks/npm-react.js +++ b/grunt/tasks/npm-react.js @@ -9,9 +9,12 @@ var modSrc = 'build/modules/'; var lib = dest + 'lib/'; var dist = dest + 'dist/'; var distFiles = [ - 'react.js', 'react.min.js', 'JSXTransformer.js', - 'react-with-addons.js', 'react-with-addons.min.js', - 'react-dom.js', 'react-dom.min.js', + 'react.js', + 'react.min.js', + 'react-with-addons.js', + 'react-with-addons.min.js', + 'react-dom.js', + 'react-dom.min.js', ]; function buildRelease() { diff --git a/grunt/tasks/release.js b/grunt/tasks/release.js index 36ef67837d..9c9072d0fc 100644 --- a/grunt/tasks/release.js +++ b/grunt/tasks/release.js @@ -5,9 +5,12 @@ var grunt = require('grunt'); var BOWER_PATH = '../react-bower/'; var BOWER_GLOB = [BOWER_PATH + '*.{js}']; var BOWER_FILES = [ - 'react.js', 'react.min.js', 'JSXTransformer.js', - 'react-with-addons.js', 'react-with-addons.min.js', - 'react-dom.js', 'react-dom.min.js', + 'react.js', + 'react.min.js', + 'react-with-addons.js', + 'react-with-addons.min.js', + 'react-dom.js', + 'react-dom.min.js', ]; var GH_PAGES_PATH = '../react-gh-pages/'; var GH_PAGES_GLOB = [GH_PAGES_PATH + '*']; diff --git a/vendor/browser-transforms.js b/vendor/browser-transforms.js deleted file mode 100644 index 0f18fdf69a..0000000000 --- a/vendor/browser-transforms.js +++ /dev/null @@ -1,329 +0,0 @@ -/** - * Copyright 2013-2015, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -/* jslint evil: true */ -/*eslint-disable no-eval */ -/*eslint-disable block-scoped-var */ - -'use strict'; - -var jstransform = require('jstransform/simple'); - -var headEl; -var dummyAnchor; -var inlineScriptCount = 0; - -// The source-map library relies on Object.defineProperty, but IE8 doesn't -// support it fully even with es5-sham. Indeed, es5-sham's defineProperty -// throws when Object.prototype.__defineGetter__ is missing, so we skip building -// the source map in that case. -var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); - -/** - * Run provided code through jstransform. - * - * @param {string} source Original source code - * @param {object?} options Options to pass to jstransform - * @return {object} object as returned from jstransform - */ -function transformReact(source, options) { - options = options || {}; - - // Always enable the React transforms. - options.react = true; - - // Force the sourcemaps option manually. We don't want to use it if it will - // break (see above note about supportsAccessors). We'll only override the - // value here if sourceMap was specified and is truthy. This guarantees that - // we won't override any user intent (since this method is exposed publicly). - if (options.sourceMap) { - options.sourceMap = supportsAccessors; - } - - // Otherwise just pass all options straight through to react-tools. - return jstransform.transform(source, options); -} - -/** - * Eval provided source after transforming it. - * - * @param {string} source Original source code - * @param {object?} options Options to pass to jstransform - */ -function exec(source, options) { - return eval(transformReact(source, options).code); -} - -/** - * This method returns a nicely formated line of code pointing to the exact - * location of the error `e`. The line is limited in size so big lines of code - * are also shown in a readable way. - * - * Example: - * ... x', overflow:'scroll'}} id={} onScroll={this.scroll} class=" ... - * ^ - * - * @param {string} code The full string of code - * @param {Error} e The error being thrown - * @return {string} formatted message - * @internal - */ -function createSourceCodeErrorMessage(code, e) { - var sourceLines = code.split('\n'); - // e.lineNumber is non-standard so we can't depend on its availability. If - // we're in a browser where it isn't supported, don't even bother trying to - // format anything. We may also hit a case where the line number is reported - // incorrectly and is outside the bounds of the actual code. Handle that too. - if (!e.lineNumber || e.lineNumber > sourceLines.length) { - return ''; - } - var erroneousLine = sourceLines[e.lineNumber - 1]; - - // Removes any leading indenting spaces and gets the number of - // chars indenting the `erroneousLine` - var indentation = 0; - erroneousLine = erroneousLine.replace(/^\s+/, function(leadingSpaces) { - indentation = leadingSpaces.length; - return ''; - }); - - // Defines the number of characters that are going to show - // before and after the erroneous code - var LIMIT = 30; - var errorColumn = e.column - indentation; - - if (errorColumn > LIMIT) { - erroneousLine = '... ' + erroneousLine.slice(errorColumn - LIMIT); - errorColumn = 4 + LIMIT; - } - if (erroneousLine.length - errorColumn > LIMIT) { - erroneousLine = erroneousLine.slice(0, errorColumn + LIMIT) + ' ...'; - } - var message = '\n\n' + erroneousLine + '\n'; - message += new Array(errorColumn - 1).join(' ') + '^'; - return message; -} - -/** - * Actually transform the code. - * - * @param {string} code - * @param {string?} url - * @param {object?} options - * @return {string} The transformed code. - * @internal - */ -function transformCode(code, url, options) { - try { - return transformReact(code, options).code; - } catch(e) { - e.message += '\n at '; - if (url) { - if ('fileName' in e) { - // We set `fileName` if it's supported by this error object and - // a `url` was provided. - // The error will correctly point to `url` in Firefox. - e.fileName = url; - } - e.message += url + ':' + e.lineNumber + ':' + e.columnNumber; - } else { - e.message += location.href; - } - e.message += createSourceCodeErrorMessage(code, e); - throw e; - } -} - - -/** - * Appends a script element at the end of the with the content of code, - * after transforming it. - * - * @param {string} code The original source code - * @param {string?} url Where the code came from. null if inline - * @param {object?} options Options to pass to jstransform - * @internal - */ -function run(code, url, options) { - var scriptEl = document.createElement('script'); - scriptEl.text = transformCode(code, url, options); - headEl.appendChild(scriptEl); -} - -/** - * Load script from the provided url and pass the content to the callback. - * - * @param {string} url The location of the script src - * @param {function} successCallback Function to call with the content of url - * @param {function} errorCallback Function to call if error - * @internal - */ -function load(url, successCallback, errorCallback) { - var xhr; - xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') - : new XMLHttpRequest(); - - // async, however scripts will be executed in the order they are in the - // DOM to mirror normal script loading. - xhr.open('GET', url, true); - if ('overrideMimeType' in xhr) { - xhr.overrideMimeType('text/plain'); - } - xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - if (xhr.status === 0 || xhr.status === 200) { - successCallback(xhr.responseText); - } else { - errorCallback(); - throw new Error('Could not load ' + url); - } - } - }; - return xhr.send(null); -} - -/** - * Loop over provided script tags and get the content, via innerHTML if an - * inline script, or by using XHR. Transforms are applied if needed. The scripts - * are executed in the order they are found on the page. - * - * @param {array} scripts The