@samitouri / QOS-React-2 / commits / 93a782b40b

Use Babel to build React

Size comparison: ``` raw gz Compared to master @ 6ed98ec0c83918d91b16517544e658e2ec068070 = = build/JSXTransformer.js -15736 -3247 build/react-with-addons.js +287 +7 build/react-with-addons.min.js -14412 -2887 build/react.js +274 +15 build/react.min.js ``` Differences mostly look to be various bits of whitespace that Babel ends up removing during its transforms (https://gist.github.com/spicyj/21ef31f4d95fb7a58daf). In minified files, mostly additions of `"use strict";`.

Ben Alpert committed May 1, 2015 at 11:10 UTC 93a782b40ba0899ccdf577b4a7f3400667ad577a
5 files changed +26 -10
bin/jsx-internal
+7 -2
@@ -1,8 +1,10 @@
1 #!/usr/bin/env node
2 // -*- mode: js -*-
3 +// vim: set ft=javascript :
4 "use strict";
5
5 -var transform = require('../main').transform;
6 +var babel = require('babel-core');
7 +
8 var propagate = require("../vendor/constants").propagate;
9
10 require("commoner").version(
@@ -30,7 +32,10 @@ require("commoner").version(
32 var constants = context.config.constants || {};
33
34 // This is where JSX, ES6, etc. desugaring happens.
33 - source = transform(source, {harmony: true, stripTypes: true});
35 + source = babel.transform(source, {
36 + blacklist: ['spec.functionName', 'validation.react'],
37 + filename: id
38 + }).code;
39
40 // Constant propagation means removing any obviously dead code after
41 // replacing constant expressions with literal (boolean) values.
jest/preprocessor.js
+9 -3
@@ -1,8 +1,8 @@
1 'use strict';
2
3 -var ReactTools = require('../main.js');
4 -
3 +var babel = require('babel-core');
4 var coffee = require('coffee-script');
5 +
6 var tsPreprocessor = require('./ts-preprocessor');
7
8 var defaultLibraries = [
@@ -20,6 +20,12 @@ module.exports = {
20 if (path.match(/\.ts$/) && !path.match(/\.d\.ts$/)) {
21 return ts.compile(src, path);
22 }
23 - return ReactTools.transform(src, {harmony: true});
23 + if (!path.match(/\/node_modules\//)) {
24 + return babel.transform(src, {
25 + blacklist: ['spec.functionName', 'validation.react'],
26 + filename: path
27 + }).code;
28 + }
29 + return src;
30 }
31 };
package.json
+2 -1
@@ -31,6 +31,7 @@
31 "jstransform": "^10.1.0"
32 },
33 "devDependencies": {
34 + "babel-core": "^5.2.7",
35 "benchmark": "~1.0.0",
36 "browserify": "^9.0.3",
37 "bundle-collapser": "^1.1.1",
@@ -70,7 +71,7 @@
71 },
72 "preferGlobal": true,
73 "commonerConfig": {
73 - "version": 4
74 + "version": 5
75 },
76 "scripts": {
77 "test": "jest",
src/browser/ui/dom/setInnerHTML.js
+5 -1
@@ -67,7 +67,11 @@ if (ExecutionEnvironment.canUseDOM) {
67 html[0] === '<' && NONVISIBLE_TEST.test(html)) {
68 // Recover leading whitespace by temporarily prepending any character.
69 // \uFEFF has the potential advantage of being zero-width/invisible.
70 - node.innerHTML = '\uFEFF' + html;
70 + // UglifyJS drops U+FEFF chars when parsing, so use String.fromCharCode
71 + // in hopes that this is preserved even if "\uFEFF" is transformed to
72 + // the actual Unicode character (by Babel, for example).
73 + // https://github.com/mishoo/UglifyJS2/blob/v2.4.20/lib/parse.js#L216
74 + node.innerHTML = String.fromCharCode(0xFEFF) + html;
75
76 // deleteData leaves an empty `TextNode` which offsets the index of all
77 // children. Definitely want to avoid this.
src/test/mocks.js
+3 -3
@@ -69,7 +69,7 @@ function makeComponent(metadata) {
69
70 instances.push(this);
71 calls.push(Array.prototype.slice.call(arguments));
72 - if (this instanceof arguments.callee) {
72 + if (this instanceof f) {
73 // This is probably being called as a constructor
74 for (var slot in prototype) {
75 // Copy prototype methods to the instance to make
@@ -106,8 +106,8 @@ function makeComponent(metadata) {
106 }
107
108 // Otherwise use prototype implementation
109 - if (returnValue === undefined && arguments.callee._protoImpl) {
110 - return arguments.callee._protoImpl.apply(this, arguments);
109 + if (returnValue === undefined && f._protoImpl) {
110 + return f._protoImpl.apply(this, arguments);
111 }
112
113 return returnValue;