@samitouri / QOS-React-2 / commits / d2fe87892d

Remove transforms from repo, react-tools

Time to just use jstransform.

Paul O’Shannessy committed Apr 28, 2015 at 15:14 UTC d2fe87892de8bdfa733f4730c1ea79dd4998e84b
13 files changed +51 -1586
main.js
+22 -79
@@ -8,88 +8,31 @@
8 */
9
10 'use strict';
11 -/*eslint-disable no-undef*/
12 -var visitors = require('./vendor/fbtransform/visitors');
13 -var transform = require('jstransform').transform;
14 -var typesSyntax = require('jstransform/visitors/type-syntax');
15 -var inlineSourceMap = require('./vendor/inline-source-map');
11
17 -module.exports = {
18 - transform: function(input, options) {
19 - options = processOptions(options);
20 - var output = innerTransform(input, options);
21 - var result = output.code;
22 - if (options.sourceMap) {
23 - var map = inlineSourceMap(
24 - output.sourceMap,
25 - input,
26 - options.filename
27 - );
28 - result += '\n' + map;
29 - }
30 - return result;
31 - },
32 - transformWithDetails: function(input, options) {
33 - options = processOptions(options);
34 - var output = innerTransform(input, options);
35 - var result = {};
36 - result.code = output.code;
37 - if (options.sourceMap) {
38 - result.sourceMap = output.sourceMap.toJSON();
39 - }
40 - if (options.filename) {
41 - result.sourceMap.sources = [options.filename];
42 - }
43 - return result;
44 - }
45 -};
12 +var jstransform = require('jstransform/simple');
13
47 -/**
48 - * Only copy the values that we need. We'll do some preprocessing to account for
49 - * converting command line flags to options that jstransform can actually use.
50 - */
51 -function processOptions(opts) {
14 +function transformWithDetails(code, opts) {
15 opts = opts || {};
53 - var options = {};
54 -
55 - options.harmony = opts.harmony;
56 - options.stripTypes = opts.stripTypes;
57 - options.sourceMap = opts.sourceMap;
58 - options.filename = opts.sourceFilename;
59 -
60 - if (opts.es6module) {
61 - options.sourceType = 'module';
62 - }
63 - if (opts.nonStrictEs6module) {
64 - options.sourceType = 'nonStrictModule';
65 - }
66 -
67 - // Instead of doing any fancy validation, only look for 'es3'. If we have
68 - // that, then use it. Otherwise use 'es5'.
69 - options.es3 = opts.target === 'es3';
70 - options.es5 = !options.es3;
16
72 - return options;
17 + // Copy out the values we need and make sure they are compatible with
18 + // jstransform options. Always set react:true.
19 + var options = {
20 + react: true,
21 + harmony: opts.harmony,
22 + stripTypes: opts.stripTypes,
23 + sourceMapInline: opts.sourceMap,
24 + sourceFilename: opts.sourceFilename,
25 + es6module: opts.es6module,
26 + nonStrictEs6module: opts.nonStrictEs6module,
27 + target: opts.target
28 + };
29 +
30 + return jstransform.transform(code, options);
31 }
32
75 -function innerTransform(input, options) {
76 - var visitorSets = ['react'];
77 - if (options.harmony) {
78 - visitorSets.push('harmony');
79 - }
80 -
81 - if (options.es3) {
82 - visitorSets.push('es3');
83 - }
84 -
85 - if (options.stripTypes) {
86 - // Stripping types needs to happen before the other transforms
87 - // unfortunately, due to bad interactions. For example,
88 - // es6-rest-param-visitors conflict with stripping rest param type
89 - // annotation
90 - input = transform(typesSyntax.visitorList, input, options).code;
91 - }
92 -
93 - var visitorList = visitors.getVisitorsBySet(visitorSets);
94 - return transform(visitorList, input, options);
95 -}
33 +module.exports = {
34 + transform: function(input, options) {
35 + return transformWithDetails(input, options).code;
36 + },
37 + transformWithDetails: transformWithDetails
38 +};
package.json
+3 -4
@@ -14,9 +14,7 @@
14 "files": [
15 "main.js",
16 "bin/jsx",
17 - "src/",
18 - "vendor/fbtransform/",
19 - "vendor/inline-source-map.js"
17 + "src/"
18 ],
19 "main": "main.js",
20 "bin": {
@@ -28,7 +26,8 @@
26 },
27 "dependencies": {
28 "commoner": "^0.10.0",
31 - "jstransform": "^10.1.0"
29 + "esprima-fb": "^15001.1.0-dev-harmony-fb",
30 + "jstransform": "^11.0.0"
31 },
32 "devDependencies": {
33 "babel-core": "^5.2.7",
vendor/browser-transforms.js
+26 -31
@@ -13,8 +13,7 @@
13
14 'use strict';
15
16 -var ReactTools = require('../main');
17 -var inlineSourceMap = require('./inline-source-map');
16 +var jstransform = require('jstransform/simple');
17
18 var headEl;
19 var dummyAnchor;
@@ -36,6 +35,9 @@ var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
35 function transformReact(source, options) {
36 options = options || {};
37
38 + // Always enable the React transforms.
39 + options.react = true;
40 +
41 // Force the sourcemaps option manually. We don't want to use it if it will
42 // break (see above note about supportsAccessors). We'll only override the
43 // value here if sourceMap was specified and is truthy. This guarantees that
@@ -45,7 +47,7 @@ function transformReact(source, options) {
47 }
48
49 // Otherwise just pass all options straight through to react-tools.
48 - return ReactTools.transformWithDetails(source, options);
50 + return jstransform.transform(source, options);
51 }
52
53 /**
@@ -119,7 +121,7 @@ function createSourceCodeErrorMessage(code, e) {
121 */
122 function transformCode(code, url, options) {
123 try {
122 - var transformed = transformReact(code, options);
124 + return transformReact(code, options).code;
125 } catch(e) {
126 e.message += '\n at ';
127 if (url) {
@@ -136,32 +138,6 @@ function transformCode(code, url, options) {
138 e.message += createSourceCodeErrorMessage(code, e);
139 throw e;
140 }
139 -
140 - if (!transformed.sourceMap) {
141 - return transformed.code;
142 - }
143 -
144 - var source;
145 - if (url == null) {
146 - source = 'Inline JSX script';
147 - inlineScriptCount++;
148 - if (inlineScriptCount > 1) {
149 - source += ' (' + inlineScriptCount + ')';
150 - }
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 -
160 - return (
161 - transformed.code +
162 - '\n' +
163 - inlineSourceMap(transformed.sourceMap, code, source)
164 - );
141 }
142
143
@@ -239,8 +215,27 @@ function loadScripts(scripts) {
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 + console.log(sourceFilename);
235 +
236 var options = {
243 - sourceMap: true
237 + sourceMapInline: true,
238 + sourceFilename: sourceFilename
239 };
240 if (/;harmony=true(;|$)/.test(script.type)) {
241 options.harmony = true;
vendor/fbtransform/.eslintrc deleted
-9
@@ -1,9 +0,0 @@
1 ----
2 -globals:
3 - describe: true
4 - expect: true
5 - it: true
6 - jest: true
7 -
8 -rules:
9 - no-process-exit: 0
vendor/fbtransform/syntax.js deleted
-94
@@ -1,94 +0,0 @@
1 -/*global process:false*/
2 -/*global module:true*/
3 -/*global exports:true*/
4 -"use strict";
5 -
6 -var transform = require('jstransform').transform;
7 -var typesSyntax = require('jstransform/visitors/type-syntax');
8 -var visitors = require('./visitors');
9 -
10 -/**
11 - * @typechecks
12 - * @param {string} source
13 - * @param {object?} options
14 - * @param {array?} excludes
15 - * @return {string}
16 - */
17 -function transformAll(source, options, excludes) {
18 - excludes = excludes || [];
19 -
20 - // Stripping types needs to happen before the other transforms
21 - // unfortunately, due to bad interactions. For example,
22 - // es6-rest-param-visitors conflict with stripping rest param type
23 - // annotation
24 - source = transform(typesSyntax.visitorList, source, options).code;
25 -
26 - // The typechecker transform must run in a second pass in order to operate on
27 - // the entire source code -- so exclude it from the first pass
28 - var visitorsList = visitors.getAllVisitors(excludes.concat('typechecker'));
29 - source = transform(visitorsList, source, options);
30 - if (excludes.indexOf('typechecks') == -1 && /@typechecks/.test(source.code)) {
31 - source = transform(
32 - visitors.transformVisitors.typechecker,
33 - source.code,
34 - options
35 - );
36 - }
37 - return source;
38 -}
39 -
40 -function runCli(argv) {
41 - var options = {};
42 - for (var optName in argv) {
43 - if (optName === '_' || optName === '$0') {
44 - continue;
45 - }
46 - options[optName] = optimist.argv[optName];
47 - }
48 -
49 - if (options.help) {
50 - optimist.showHelp();
51 - process.exit(0);
52 - }
53 -
54 - var excludes = options.excludes;
55 - delete options.excludes;
56 -
57 - var source = '';
58 - process.stdin.resume();
59 - process.stdin.setEncoding('utf8');
60 - process.stdin.on('data', function(chunk) {
61 - source += chunk;
62 - });
63 - process.stdin.on('end', function() {
64 - try {
65 - source = transformAll(source, options, excludes);
66 - } catch (e) {
67 - console.error(e.stack);
68 - process.exit(1);
69 - }
70 - process.stdout.write(source.code);
71 - });
72 -}
73 -
74 -if (require.main === module) {
75 - var optimist = require('optimist');
76 -
77 - optimist = optimist
78 - .usage('Usage: $0 [options]')
79 - .default('exclude', [])
80 - .boolean('help').alias('h', 'help')
81 - .boolean('minify')
82 - .describe(
83 - 'minify',
84 - 'Best-effort minification of the output source (when possible)'
85 - )
86 - .describe(
87 - 'exclude',
88 - 'A list of transformNames to exclude'
89 - );
90 -
91 - runCli(optimist.argv);
92 -} else {
93 - exports.transformAll = transformAll;
94 -}
vendor/fbtransform/transforms/__tests__/jsx-test.js deleted
-142
@@ -1,142 +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 - * @emails jeffmo@fb.com
10 - */
11 -
12 -'use strict';
13 -
14 -require('mock-modules').autoMockOff();
15 -
16 -describe('jsx', function() {
17 - var jsx = require('../jsx');
18 - var utils = require('jstransform/src/utils');
19 - var esprima = require('esprima-fb');
20 -
21 - function runWithLiteral(text, isLast) {
22 - var source = '<div>' + text + '</div>';
23 - var ast = esprima.parse(source, { range: true });
24 - var state = utils.createState(source);
25 - var literal = ast.body[0].expression.children[0];
26 - state.g.position = literal.range[0];
27 - jsx.renderJSXLiteral(literal, isLast, state);
28 - return state;
29 - }
30 -
31 - function runWithAttribute(inlineAttribute, isLast) {
32 - var source = '<div ' + inlineAttribute + ' />';
33 - var ast = esprima.parse(source, { range: true });
34 - var state = utils.createState(source);
35 - var attribute = ast.body[0].expression.openingElement.attributes[0];
36 - state.g.position = attribute.value.range[0];
37 - jsx.renderJSXExpressionContainer(
38 - function() {},
39 - attribute.value,
40 - isLast,
41 - [],
42 - state
43 - );
44 - return state;
45 - }
46 -
47 - it('should render simple literal', function() {
48 - var state = runWithLiteral('a', true);
49 - expect(state.g.buffer).toEqual('"a"');
50 - });
51 -
52 -
53 - it('should render simple literal with single space before', function() {
54 - var state = runWithLiteral(' a', true);
55 - expect(state.g.buffer).toEqual('" a"');
56 - });
57 -
58 - it('should render simple literal with single space before' +
59 - ' from multiple spaces', function() {
60 - var state = runWithLiteral(' \t a', true);
61 - expect(state.g.buffer).toEqual('" a"');
62 - });
63 -
64 - it('should render simple literal with single space after', function() {
65 - var state = runWithLiteral('a ', true);
66 - expect(state.g.buffer).toEqual('"a "');
67 - });
68 -
69 - it('should render simple literal with single space after' +
70 - ' from multiple spaces', function() {
71 - var state = runWithLiteral('a \t \t ', true);
72 - expect(state.g.buffer).toEqual('"a "');
73 - });
74 -
75 - it('should render multiline literal as last', function() {
76 - var state = runWithLiteral(
77 - ' sdfsdfsdf\n' +
78 - ' sdlkfjsdfljs\n' +
79 - ' ',
80 - true);
81 -
82 - expect(state.g.buffer).toEqual(
83 - '" sdfsdfsdf" + \' \' +\n' +
84 - ' "sdlkfjsdfljs"\n' +
85 - ' ');
86 - });
87 -
88 - it('should render multiline literal as not last', function() {
89 - var state = runWithLiteral(
90 - ' sdfsdfsdf\n' +
91 - ' sdlkfjsdfljs\n' +
92 - ' ',
93 - false);
94 -
95 - expect(state.g.buffer).toEqual(
96 - '" sdfsdfsdf" + \' \' +\n' +
97 - ' "sdlkfjsdfljs", \n' +
98 - ' ');
99 - });
100 -
101 - it('should render attribute expressions', function() {
102 - var state = runWithAttribute('attr={"foo"}', true);
103 - expect(state.g.buffer).toEqual('"foo"');
104 - });
105 -
106 - it('should render attribute expressions as not last', function() {
107 - var state = runWithAttribute('attr={"foo"}', false);
108 - expect(state.g.buffer).toEqual('"foo", ');
109 - });
110 -
111 - it('should render attribute expressions with spaces', function() {
112 - var state = runWithAttribute('attr={ "foo"\n }', true);
113 - expect(state.g.buffer).toEqual(' "foo"\n ');
114 - });
115 -
116 - it('should render attribute expressions with commas before trailing ' +
117 - 'whitespace', function() {
118 - var state = runWithAttribute('attr={\n"foo"\n }', false);
119 - expect(state.g.buffer).toEqual('\n"foo", \n ');
120 - });
121 -
122 - it('should render empty child expressions with comments', function() {
123 - var source = '<div>{/*comment*/}</div>';
124 - var ast = esprima.parse(source, {range: true});
125 - var child = ast.body[0].expression.children[0];
126 - var state = utils.createState(source, child);
127 - state.g.position = child.range[0];
128 - jsx.renderJSXExpressionContainer(function() {}, child, true, [], state);
129 - expect(state.g.buffer).toBe('/*comment*/');
130 - });
131 -
132 - it('should not render commas after empty child expressions even if they\'re' +
133 - 'not last', function() {
134 - var source = '<div>{/*comment*/}</div>';
135 - var ast = esprima.parse(source, {range: true});
136 - var child = ast.body[0].expression.children[0];
137 - var state = utils.createState(source, child);
138 - state.g.position = child.range[0];
139 - jsx.renderJSXExpressionContainer(function() {}, child, false, [], state);
140 - expect(state.g.buffer).toBe('/*comment*/');
141 - });
142 -});
vendor/fbtransform/transforms/__tests__/react-displayName-test.js deleted
-174
@@ -1,174 +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 - * @emails react-core
10 - */
11 -'use strict';
12 -
13 -require('mock-modules').autoMockOff();
14 -
15 -var transformAll = require('../../syntax.js').transformAll;
16 -
17 -function transform(source) {
18 - return transformAll(source, {}, ['sourcemeta']);
19 -}
20 -
21 -describe('react displayName jsx', function() {
22 -
23 - it('should only inject displayName if missing', function() {
24 - var code = [
25 - '"use strict";',
26 - 'var Whateva = React.createClass({',
27 - ' displayName: "Whateva",',
28 - ' render: function() {',
29 - ' return null;',
30 - ' }',
31 - '});'
32 - ].join('\n');
33 -
34 - var result = [
35 - '"use strict";',
36 - 'var Whateva = React.createClass({',
37 - ' displayName: "Whateva",',
38 - ' render: function() {',
39 - ' return null;',
40 - ' }',
41 - '});'
42 - ].join('\n');
43 -
44 - expect(transform(code).code).toEqual(result);
45 - });
46 -
47 - it('should inject displayName in simple assignment', () => {
48 - var code = [
49 - 'var Component = React.createClass({',
50 - ' render: function() {',
51 - ' return null;',
52 - ' }',
53 - '});'
54 - ].join('\n');
55 -
56 - var result = [
57 - 'var Component = React.createClass({displayName: "Component",',
58 - ' render: function() {',
59 - ' return null;',
60 - ' }',
61 - '});'
62 - ].join('\n');
63 -
64 - expect(transform(code).code).toEqual(result);
65 - });
66 -
67 - it('should inject displayName in simple assignment without var', () => {
68 - var code = [
69 - 'var Component;',
70 - 'Component = React.createClass({',
71 - ' render: function() {',
72 - ' return null;',
73 - ' }',
74 - '});'
75 - ].join('\n');
76 -
77 - var result = [
78 - 'var Component;',
79 - 'Component = React.createClass({displayName: "Component",',
80 - ' render: function() {',
81 - ' return null;',
82 - ' }',
83 - '});'
84 - ].join('\n');
85 -
86 - expect(transform(code).code).toEqual(result);
87 - });
88 -
89 - it('should inject displayName in property assignment', () => {
90 - var code = [
91 - 'ns.Component = React.createClass({',
92 - ' render: function() {',
93 - ' return null;',
94 - ' }',
95 - '});'
96 - ].join('\n');
97 -
98 - var result = [
99 - 'ns.Component = React.createClass({displayName: "ns.Component",',
100 - ' render: function() {',
101 - ' return null;',
102 - ' }',
103 - '});'
104 - ].join('\n');
105 -
106 - expect(transform(code).code).toEqual(result);
107 - });
108 -
109 - it('should inject displayName in chained property assignment', () => {
110 - var code = [
111 - 'ns.ns1.Component = React.createClass({',
112 - ' render: function() {',
113 - ' return null;',
114 - ' }',
115 - '});'
116 - ].join('\n');
117 -
118 - var result = [
119 - 'ns.ns1.Component = React.createClass({displayName: "ns.ns1.Component",',
120 - ' render: function() {',
121 - ' return null;',
122 - ' }',
123 - '});'
124 - ].join('\n');
125 -
126 - expect(transform(code).code).toEqual(result);
127 - });
128 -
129 -
130 - it('should inject displayName in exports property assignment', () => {
131 - var code = [
132 - 'exports.Component = React.createClass({',
133 - ' render: function() {',
134 - ' return null;',
135 - ' }',
136 - '});'
137 - ].join('\n');
138 -
139 - var result = [
140 - 'exports.Component = React.createClass({displayName: "Component",',
141 - ' render: function() {',
142 - ' return null;',
143 - ' }',
144 - '});'
145 - ].join('\n');
146 -
147 - expect(transform(code).code).toEqual(result);
148 - });
149 -
150 - it('should inject displayName in object declaration', () => {
151 - var code = [
152 - 'exports = {',
153 - ' Component: React.createClass({',
154 - ' render: function() {',
155 - ' return null;',
156 - ' }',
157 - ' })',
158 - '};'
159 - ].join('\n');
160 -
161 - var result = [
162 - 'exports = {',
163 - ' Component: React.createClass({displayName: "Component",',
164 - ' render: function() {',
165 - ' return null;',
166 - ' }',
167 - ' })',
168 - '};'
169 - ].join('\n');
170 -
171 - expect(transform(code).code).toEqual(result);
172 - });
173 -
174 -});
vendor/fbtransform/transforms/__tests__/react-test.js deleted
-396
@@ -1,396 +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 - * @emails react-core
10 - */
11 -
12 -/*jshint evil:true, unused:false*/
13 -
14 -'use strict';
15 -
16 -require('mock-modules').autoMockOff();
17 -
18 -describe('react jsx', function() {
19 - var transformAll = require('../../syntax.js').transformAll;
20 -
21 - var transform = function(code, options, excludes) {
22 - return transformAll(
23 - code,
24 - options,
25 - (excludes || []).concat(['sourcemeta'])
26 - );
27 - };
28 -
29 - // These are placeholder variables in scope that we can use to assert that a
30 - // specific variable reference was passed, rather than an object clone of it.
31 - var x = 123456;
32 - var y = 789012;
33 - var z = 345678;
34 -
35 - var expectObjectAssign = function(code) {
36 - /*eslint-disable no-unused-vars, no-eval*/
37 - var Component = jest.genMockFunction();
38 - var Child = jest.genMockFunction();
39 - var objectAssignMock = jest.genMockFunction();
40 - React.__spread = objectAssignMock;
41 - eval(transform(code).code);
42 - return expect(objectAssignMock);
43 - /*eslint-enable*/
44 - };
45 -
46 - var React = {
47 - createElement: jest.genMockFunction()
48 - };
49 -
50 - it('should convert simple tags', function() {
51 - var code = 'var x = <div></div>;';
52 - var result = 'var x = React.createElement("div", null);';
53 -
54 - expect(transform(code).code).toEqual(result);
55 - });
56 -
57 - it('should convert simple text', function() {
58 - var code = 'var x = <div>text</div>;';
59 - var result = 'var x = React.createElement("div", null, "text");';
60 -
61 - expect(transform(code).code).toEqual(result);
62 - });
63 -
64 - it('should have correct comma in nested children', function() {
65 - var code = [
66 - 'var x = <div>',
67 - ' <div><br /></div>',
68 - ' <Component>{foo}<br />{bar}</Component>',
69 - ' <br />',
70 - '</div>;'
71 - ].join('\n');
72 - var result = [
73 - 'var x = React.createElement("div", null, ',
74 - ' React.createElement("div", null, ' +
75 - 'React.createElement("br", null)), ',
76 - ' React.createElement(Component, null, foo, ' +
77 - 'React.createElement("br", null), bar), ',
78 - ' React.createElement("br", null)',
79 - ');'
80 - ].join('\n');
81 -
82 - expect(transform(code).code).toEqual(result);
83 - });
84 -
85 - it('should avoid wrapping in extra parens if not needed', function() {
86 - // Try with a single composite child, wrapped in a div.
87 - var code = [
88 - 'var x = <div>',
89 - ' <Component />',
90 - '</div>;'
91 - ].join('\n');
92 - var result = [
93 - 'var x = React.createElement("div", null, ',
94 - ' React.createElement(Component, null)',
95 - ');'
96 - ].join('\n');
97 -
98 - expect(transform(code).code).toEqual(result);
99 -
100 - // Try with a single interpolated child, wrapped in a div.
101 - code = [
102 - 'var x = <div>',
103 - ' {this.props.children}',
104 - '</div>;'
105 - ].join('\n');
106 - result = [
107 - 'var x = React.createElement("div", null, ',
108 - ' this.props.children',
109 - ');'
110 - ].join('\n');
111 - expect(transform(code).code).toEqual(result);
112 -
113 - // Try with a single interpolated child, wrapped in a composite.
114 - code = [
115 - 'var x = <Composite>',
116 - ' {this.props.children}',
117 - '</Composite>;'
118 - ].join('\n');
119 - result = [
120 - 'var x = React.createElement(Composite, null, ',
121 - ' this.props.children',
122 - ');'
123 - ].join('\n');
124 - expect(transform(code).code).toEqual(result);
125 -
126 - // Try with a single composite child, wrapped in a composite.
127 - code = [
128 - 'var x = <Composite>',
129 - ' <Composite2 />',
130 - '</Composite>;'
131 - ].join('\n');
132 - result = [
133 - 'var x = React.createElement(Composite, null, ',
134 - ' React.createElement(Composite2, null)',
135 - ');'
136 - ].join('\n');
137 - expect(transform(code).code).toEqual(result);
138 - });
139 -
140 - it('should insert commas after expressions before whitespace', function() {
141 - var code = [
142 - 'var x =',
143 - ' <div',
144 - ' attr1={',
145 - ' "foo" + "bar"',
146 - ' }',
147 - ' attr2={',
148 - ' "foo" + "bar" +',
149 - ' ',
150 - ' "baz" + "bug"',
151 - ' }',
152 - ' attr3={',
153 - ' "foo" + "bar" +',
154 - ' "baz" + "bug"',
155 - ' // Extra line here.',
156 - ' }',
157 - ' attr4="baz">',
158 - ' </div>;'
159 - ].join('\n');
160 - var result = [
161 - 'var x =',
162 - ' React.createElement("div", {',
163 - ' attr1: ',
164 - ' "foo" + "bar", ',
165 - ' ',
166 - ' attr2: ',
167 - ' "foo" + "bar" +',
168 - ' ',
169 - ' "baz" + "bug", ',
170 - ' ',
171 - ' attr3: ',
172 - ' "foo" + "bar" +',
173 - ' "baz" + "bug", ',
174 - ' // Extra line here.',
175 - ' ',
176 - ' attr4: "baz"}',
177 - ' );'
178 - ].join('\n');
179 -
180 - expect(transform(code).code).toEqual(result);
181 - });
182 -
183 - it('should properly handle comments adjacent to children', function() {
184 - var code = [
185 - 'var x = (',
186 - ' <div>',
187 - ' {/* A comment at the beginning */}',
188 - ' {/* A second comment at the beginning */}',
189 - ' <span>',
190 - ' {/* A nested comment */}',
191 - ' </span>',
192 - ' {/* A sandwiched comment */}',
193 - ' <br />',
194 - ' {/* A comment at the end */}',
195 - ' {/* A second comment at the end */}',
196 - ' </div>',
197 - ');'
198 - ].join('\n');
199 - var result = [
200 - 'var x = (',
201 - ' React.createElement("div", null, ',
202 - ' /* A comment at the beginning */',
203 - ' /* A second comment at the beginning */',
204 - ' React.createElement("span", null',
205 - ' /* A nested comment */',
206 - ' ), ',
207 - ' /* A sandwiched comment */',
208 - ' React.createElement("br", null)',
209 - ' /* A comment at the end */',
210 - ' /* A second comment at the end */',
211 - ' )',
212 - ');'
213 - ].join('\n');
214 -
215 - expect(transform(code).code).toBe(result);
216 - });
217 -
218 - it('should properly handle comments between props', function() {
219 - var code = [
220 - 'var x = (',
221 - ' <div',
222 - ' /* a multi-line',
223 - ' comment */',
224 - ' attr1="foo">',
225 - ' <span // a double-slash comment',
226 - ' attr2="bar"',
227 - ' />',
228 - ' </div>',
229 - ');'
230 - ].join('\n');
231 - var result = [
232 - 'var x = (',
233 - ' React.createElement("div", {',
234 - ' /* a multi-line',
235 - ' comment */',
236 - ' attr1: "foo"}, ',
237 - ' React.createElement("span", {// a double-slash comment',
238 - ' attr2: "bar"}',
239 - ' )',
240 - ' )',
241 - ');'
242 - ].join('\n');
243 -
244 - expect(transform(code).code).toBe(result);
245 - });
246 -
247 - it('should not strip tags with a single child of &nbsp;', function() {
248 - var code = [
249 - '<div>&nbsp;</div>;'
250 - ].join('\n');
251 - var result = [
252 - 'React.createElement("div", null, "\u00A0");'
253 - ].join('\n');
254 -
255 - expect(transform(code).code).toBe(result);
256 - });
257 -
258 - it('should not strip &nbsp; even coupled with other whitespace', function() {
259 - var code = [
260 - '<div>&nbsp; </div>;'
261 - ].join('\n');
262 - var result = [
263 - 'React.createElement("div", null, "\u00A0 ");'
264 - ].join('\n');
265 -
266 - expect(transform(code).code).toBe(result);
267 - });
268 -
269 - it('should handle hasOwnProperty correctly', function() {
270 - var code = '<hasOwnProperty>testing</hasOwnProperty>;';
271 - var result = 'React.createElement("hasOwnProperty", null, "testing");';
272 - expect(transform(code).code).toBe(result);
273 - });
274 -
275 - it('should allow constructor as prop', function() {
276 - var code = '<Component constructor="foo" />;';
277 - var result = 'React.createElement(Component, {constructor: "foo"});';
278 -
279 - expect(transform(code).code).toBe(result);
280 - });
281 -
282 - it('should allow JS namespacing', function() {
283 - var code = '<Namespace.Component />;';
284 - var result = 'React.createElement(Namespace.Component, null);';
285 -
286 - expect(transform(code).code).toBe(result);
287 - });
288 -
289 - it('should allow deeper JS namespacing', function() {
290 - var code = '<Namespace.DeepNamespace.Component />;';
291 - var result =
292 - 'React.createElement(Namespace.DeepNamespace.Component, null);';
293 -
294 - expect(transform(code).code).toBe(result);
295 - });
296 -
297 - it('should disallow XML namespacing', function() {
298 - var code = '<Namespace:Component />;';
299 -
300 - expect(() => transform(code)).toThrow();
301 - });
302 -
303 - it('wraps props in React.__spread for spread attributes', function() {
304 - var code =
305 - '<Component { ... x } y\n' +
306 - '={2 } z />';
307 - var result =
308 - 'React.createElement(Component, React.__spread({}, x , {y: \n' +
309 - '2, z: true}))';
310 -
311 - expect(transform(code).code).toBe(result);
312 - });
313 -
314 - it('adds appropriate newlines when using spread attribute', function() {
315 - var code =
316 - '<Component\n' +
317 - ' {...this.props}\n' +
318 - ' sound="moo" />';
319 - var result =
320 - 'React.createElement(Component, React.__spread({}, \n' +
321 - ' this.props, \n' +
322 - ' {sound: "moo"}))';
323 -
324 - expect(transform(code).code).toBe(result);
325 - });
326 -
327 - it('handles overparenthesized JS', function() {
328 - var code =
329 - '<foo a={(b)} c={(d)}>Foo {(e+f //A line comment\n' +
330 - '/* A multiline comment */)\n' +
331 - '} bar\n' +
332 - '</foo>';
333 - var result = 'React.createElement("foo", {a: (b), c: (d)}, "Foo ", (e+f //A line comment\n' +
334 - '/* A multiline comment */), \n' +
335 - '" bar"\n' +
336 - ')';
337 - expect(transform(code).code).toBe(result);
338 - });
339 -
340 - it('should transform known hyphenated tags', function() {
341 - var code = '<font-face />;';
342 - var result = 'React.createElement("font-face", null);';
343 -
344 - expect(transform(code).code).toBe(result);
345 - });
346 -
347 - it('does not call React.__spread when there are no spreads', function() {
348 - expectObjectAssign(
349 - '<Component x={y} />'
350 - ).not.toBeCalled();
351 - });
352 -
353 - it('should not throw for unknown hyphenated tags', function() {
354 - var code = '<x-component />;';
355 - expect(function() {
356 - transform(code);
357 - }).not.toThrow();
358 - });
359 -
360 - it('calls assign with a new target object for spreads', function() {
361 - expectObjectAssign(
362 - '<Component {...x} />'
363 - ).toBeCalledWith({}, x);
364 - });
365 -
366 - it('calls assign with an empty object when the spread is first', function() {
367 - expectObjectAssign(
368 - '<Component { ...x } y={2} />'
369 - ).toBeCalledWith({}, x, {y: 2});
370 - });
371 -
372 - it('coalesces consecutive properties into a single object', function() {
373 - expectObjectAssign(
374 - '<Component { ... x } y={2} z />'
375 - ).toBeCalledWith({}, x, {y: 2, z: true});
376 - });
377 -
378 - it('avoids an unnecessary empty object when spread is not first', function() {
379 - expectObjectAssign(
380 - '<Component x={1} {...y} />'
381 - ).toBeCalledWith({x: 1}, y);
382 - });
383 -
384 - it('passes the same value multiple times to React.__spread', function() {
385 - expectObjectAssign(
386 - '<Component x={1} y="2" {...z} {...z}><Child /></Component>'
387 - ).toBeCalledWith({x: 1, y: '2'}, z, z);
388 - });
389 -
390 - it('evaluates sequences before passing them to React.__spread', function() {
391 - expectObjectAssign(
392 - '<Component x="1" {...(z = { y: 2 }, z)} z={3}>Text</Component>'
393 - ).toBeCalledWith({x: '1'}, {y: 2}, {z: 3});
394 - });
395 -
396 -});
vendor/fbtransform/transforms/jsx.js deleted
-138
@@ -1,138 +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 -/*global exports:true*/
10 -'use strict';
11 -var Syntax = require('jstransform').Syntax;
12 -var utils = require('jstransform/src/utils');
13 -
14 -function commaAfterLastParen(value) {
15 - var state = 'normal';
16 - var commaPos = 0;
17 - for (var i = 0; i < value.length; ++i) {
18 - if (state === 'normal') {
19 - if (value.substr(i, 2) === '//') {
20 - state = 'singleline';
21 - i += 1;
22 - } else if (value.substr(i, 2) === '/*') {
23 - state = 'multiline';
24 - i += 1;
25 - } else if (value.charAt(i).trim() !== '') {
26 - commaPos = i + 1;
27 - }
28 - } else if (state === 'singleline' && value.charAt(i) === '\n') {
29 - state = 'normal';
30 - } else if (state === 'multiline' &&
31 - value.charAt(i) === '*' &&
32 - i + 1 < value.length &&
33 - value.charAt(i + 1) === '/') {
34 - i += 1;
35 - state = 'normal';
36 - }
37 - }
38 - return value.substring(0, commaPos) + ', ' + trimLeft(value.substring(commaPos));
39 -}
40 -
41 -function renderJSXLiteral(object, isLast, state, start, end) {
42 - var lines = object.value.split(/\r\n|\n|\r/);
43 -
44 - if (start) {
45 - utils.append(start, state);
46 - }
47 -
48 - var lastNonEmptyLine = 0;
49 -
50 - lines.forEach(function(line, index) {
51 - if (line.match(/[^ \t]/)) {
52 - lastNonEmptyLine = index;
53 - }
54 - });
55 -
56 - lines.forEach(function(line, index) {
57 - var isFirstLine = index === 0;
58 - var isLastLine = index === lines.length - 1;
59 - var isLastNonEmptyLine = index === lastNonEmptyLine;
60 -
61 - // replace rendered whitespace tabs with spaces
62 - var trimmedLine = line.replace(/\t/g, ' ');
63 -
64 - // trim whitespace touching a newline
65 - if (!isFirstLine) {
66 - trimmedLine = trimmedLine.replace(/^[ ]+/, '');
67 - }
68 - if (!isLastLine) {
69 - trimmedLine = trimmedLine.replace(/[ ]+$/, '');
70 - }
71 -
72 - if (!isFirstLine) {
73 - utils.append(line.match(/^[ \t]*/)[0], state);
74 - }
75 -
76 - if (trimmedLine || isLastNonEmptyLine) {
77 - utils.append(
78 - JSON.stringify(trimmedLine) +
79 - (!isLastNonEmptyLine ? ' + \' \' +' : ''),
80 - state);
81 -
82 - if (isLastNonEmptyLine) {
83 - if (end) {
84 - utils.append(end, state);
85 - }
86 - if (!isLast) {
87 - utils.append(', ', state);
88 - }
89 - }
90 -
91 - // only restore tail whitespace if line had literals
92 - if (trimmedLine && !isLastLine) {
93 - utils.append(line.match(/[ \t]*$/)[0], state);
94 - }
95 - }
96 -
97 - if (!isLastLine) {
98 - utils.append('\n', state);
99 - }
100 - });
101 -
102 - utils.move(object.range[1], state);
103 -}
104 -
105 -function renderJSXExpressionContainer(traverse, object, isLast, path, state) {
106 - // Plus 1 to skip `{`.
107 - utils.move(object.range[0] + 1, state);
108 - utils.catchup(object.expression.range[0], state);
109 - traverse(object.expression, path, state);
110 -
111 - if (!isLast && object.expression.type !== Syntax.JSXEmptyExpression) {
112 - // If we need to append a comma, make sure to do so after the expression.
113 - utils.catchup(object.expression.range[1], state, trimLeft);
114 - utils.catchup(object.range[1] - 1, state, commaAfterLastParen);
115 - } else {
116 - // Minus 1 to skip `}`.
117 - utils.catchup(object.range[1] - 1, state, trimLeft);
118 - }
119 - utils.move(object.range[1], state);
120 - return false;
121 -}
122 -
123 -function quoteAttrName(attr) {
124 - // Quote invalid JS identifiers.
125 - if (!/^[a-z_$][a-z\d_$]*$/i.test(attr)) {
126 - return '"' + attr + '"';
127 - }
128 - return attr;
129 -}
130 -
131 -function trimLeft(value) {
132 - return value.replace(/^[ ]+/, '');
133 -}
134 -
135 -exports.renderJSXExpressionContainer = renderJSXExpressionContainer;
136 -exports.renderJSXLiteral = renderJSXLiteral;
137 -exports.quoteAttrName = quoteAttrName;
138 -exports.trimLeft = trimLeft;
vendor/fbtransform/transforms/react.js deleted
-241
@@ -1,241 +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 -'use strict';
10 -
11 -/*global exports:true*/
12 -
13 -var Syntax = require('jstransform').Syntax;
14 -var utils = require('jstransform/src/utils');
15 -
16 -var renderJSXExpressionContainer = require('./jsx').renderJSXExpressionContainer;
17 -var renderJSXLiteral = require('./jsx').renderJSXLiteral;
18 -var quoteAttrName = require('./jsx').quoteAttrName;
19 -
20 -var trimLeft = require('./jsx').trimLeft;
21 -
22 -/**
23 - * Customized desugar processor for React JSX. Currently:
24 - *
25 - * <X> </X> => React.createElement(X, null)
26 - * <X prop="1" /> => React.createElement(X, {prop: '1'}, null)
27 - * <X prop="2"><Y /></X> => React.createElement(X, {prop:'2'},
28 - * React.createElement(Y, null)
29 - * )
30 - * <div /> => React.createElement("div", null)
31 - */
32 -
33 -/**
34 - * Removes all non-whitespace/parenthesis characters
35 - */
36 -var reNonWhiteParen = /([^\s\(\)])/g;
37 -function stripNonWhiteParen(value) {
38 - return value.replace(reNonWhiteParen, '');
39 -}
40 -
41 -var tagConvention = /^[a-z]|\-/;
42 -function isTagName(name) {
43 - return tagConvention.test(name);
44 -}
45 -
46 -function visitReactTag(traverse, object, path, state) {
47 - var openingElement = object.openingElement;
48 - var nameObject = openingElement.name;
49 - var attributesObject = openingElement.attributes;
50 -
51 - utils.catchup(openingElement.range[0], state, trimLeft);
52 -
53 - if (nameObject.type === Syntax.JSXNamespacedName && nameObject.namespace) {
54 - throw new Error('Namespace tags are not supported. ReactJSX is not XML.');
55 - }
56 -
57 - // We assume that the React runtime is already in scope
58 - utils.append('React.createElement(', state);
59 -
60 - if (nameObject.type === Syntax.JSXIdentifier && isTagName(nameObject.name)) {
61 - utils.append('"' + nameObject.name + '"', state);
62 - utils.move(nameObject.range[1], state);
63 - } else {
64 - // Use utils.catchup in this case so we can easily handle
65 - // JSXMemberExpressions which look like Foo.Bar.Baz. This also handles
66 - // JSXIdentifiers that aren't fallback tags.
67 - utils.move(nameObject.range[0], state);
68 - utils.catchup(nameObject.range[1], state);
69 - }
70 -
71 - utils.append(', ', state);
72 -
73 - var hasAttributes = attributesObject.length;
74 -
75 - var hasAtLeastOneSpreadProperty = attributesObject.some(function(attr) {
76 - return attr.type === Syntax.JSXSpreadAttribute;
77 - });
78 -
79 - // if we don't have any attributes, pass in null
80 - if (hasAtLeastOneSpreadProperty) {
81 - utils.append('React.__spread({', state);
82 - } else if (hasAttributes) {
83 - utils.append('{', state);
84 - } else {
85 - utils.append('null', state);
86 - }
87 -
88 - // keep track of if the previous attribute was a spread attribute
89 - var previousWasSpread = false;
90 -
91 - // write attributes
92 - attributesObject.forEach(function(attr, index) {
93 - var isLast = index === attributesObject.length - 1;
94 -
95 - if (attr.type === Syntax.JSXSpreadAttribute) {
96 - // Close the previous object or initial object
97 - if (!previousWasSpread) {
98 - utils.append('}, ', state);
99 - }
100 -
101 - // Move to the expression start, ignoring everything except parenthesis
102 - // and whitespace.
103 - utils.catchup(attr.range[0], state, stripNonWhiteParen);
104 - // Plus 1 to skip `{`.
105 - utils.move(attr.range[0] + 1, state);
106 - utils.catchup(attr.argument.range[0], state, stripNonWhiteParen);
107 -
108 - traverse(attr.argument, path, state);
109 -
110 - utils.catchup(attr.argument.range[1], state);
111 -
112 - // Move to the end, ignoring parenthesis and the closing `}`
113 - utils.catchup(attr.range[1] - 1, state, stripNonWhiteParen);
114 -
115 - if (!isLast) {
116 - utils.append(', ', state);
117 - }
118 -
119 - utils.move(attr.range[1], state);
120 -
121 - previousWasSpread = true;
122 -
123 - return;
124 - }
125 -
126 - // If the next attribute is a spread, we're effective last in this object
127 - if (!isLast) {
128 - isLast = attributesObject[index + 1].type === Syntax.JSXSpreadAttribute;
129 - }
130 -
131 - if (attr.name.namespace) {
132 - throw new Error(
133 - 'Namespace attributes are not supported. ReactJSX is not XML.');
134 - }
135 - var name = attr.name.name;
136 -
137 - utils.catchup(attr.range[0], state, trimLeft);
138 -
139 - if (previousWasSpread) {
140 - utils.append('{', state);
141 - }
142 -
143 - utils.append(quoteAttrName(name), state);
144 - utils.append(': ', state);
145 -
146 - if (!attr.value) {
147 - state.g.buffer += 'true';
148 - state.g.position = attr.name.range[1];
149 - if (!isLast) {
150 - utils.append(', ', state);
151 - }
152 - } else {
153 - utils.move(attr.name.range[1], state);
154 - // Use catchupNewlines to skip over the '=' in the attribute
155 - utils.catchupNewlines(attr.value.range[0], state);
156 - if (attr.value.type === Syntax.Literal) {
157 - renderJSXLiteral(attr.value, isLast, state);
158 - } else {
159 - renderJSXExpressionContainer(traverse, attr.value, isLast, path, state);
160 - }
161 - }
162 -
163 - utils.catchup(attr.range[1], state, trimLeft);
164 -
165 - previousWasSpread = false;
166 - });
167 -
168 - if (!openingElement.selfClosing) {
169 - utils.catchup(openingElement.range[1] - 1, state, trimLeft);
170 - utils.move(openingElement.range[1], state);
171 - }
172 -
173 - if (hasAttributes && !previousWasSpread) {
174 - utils.append('}', state);
175 - }
176 -
177 - if (hasAtLeastOneSpreadProperty) {
178 - utils.append(')', state);
179 - }
180 -
181 - // filter out whitespace
182 - var childrenToRender = object.children.filter(function(child) {
183 - return !(child.type === Syntax.Literal
184 - && typeof child.value === 'string'
185 - && child.value.match(/^[ \t]*[\r\n][ \t\r\n]*$/));
186 - });
187 - if (childrenToRender.length > 0) {
188 - var lastRenderableIndex;
189 -
190 - childrenToRender.forEach(function(child, index) {
191 - if (child.type !== Syntax.JSXExpressionContainer ||
192 - child.expression.type !== Syntax.JSXEmptyExpression) {
193 - lastRenderableIndex = index;
194 - }
195 - });
196 -
197 - if (lastRenderableIndex !== undefined) {
198 - utils.append(', ', state);
199 - }
200 -
201 - childrenToRender.forEach(function(child, index) {
202 - utils.catchup(child.range[0], state, trimLeft);
203 -
204 - var isLast = index >= lastRenderableIndex;
205 -
206 - if (child.type === Syntax.Literal) {
207 - renderJSXLiteral(child, isLast, state);
208 - } else if (child.type === Syntax.JSXExpressionContainer) {
209 - renderJSXExpressionContainer(traverse, child, isLast, path, state);
210 - } else {
211 - traverse(child, path, state);
212 - if (!isLast) {
213 - utils.append(', ', state);
214 - }
215 - }
216 -
217 - utils.catchup(child.range[1], state, trimLeft);
218 - });
219 - }
220 -
221 - if (openingElement.selfClosing) {
222 - // everything up to />
223 - utils.catchup(openingElement.range[1] - 2, state, trimLeft);
224 - utils.move(openingElement.range[1], state);
225 - } else {
226 - // everything up to </ sdflksjfd>
227 - utils.catchup(object.closingElement.range[0], state, trimLeft);
228 - utils.move(object.closingElement.range[1], state);
229 - }
230 -
231 - utils.append(')', state);
232 - return false;
233 -}
234 -
235 -visitReactTag.test = function(object, path, state) {
236 - return object.type === Syntax.JSXElement;
237 -};
238 -
239 -exports.visitorList = [
240 - visitReactTag
241 -];
vendor/fbtransform/transforms/reactDisplayName.js deleted
-126
@@ -1,126 +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 -/*global exports:true*/
10 -'use strict';
11 -
12 -var Syntax = require('jstransform').Syntax;
13 -var utils = require('jstransform/src/utils');
14 -
15 -function shouldAddDisplayName(object) {
16 - if (object &&
17 - object.type === Syntax.CallExpression &&
18 - object.callee.type === Syntax.MemberExpression &&
19 - object.callee.object.type === Syntax.Identifier &&
20 - object.callee.object.name === 'React' &&
21 - object.callee.property.type === Syntax.Identifier &&
22 - object.callee.property.name === 'createClass' &&
23 - object.arguments.length === 1 &&
24 - object.arguments[0].type === Syntax.ObjectExpression) {
25 - // Verify that the displayName property isn't already set
26 - var properties = object.arguments[0].properties;
27 - var safe = properties.every(function(property) {
28 - var value = property.key.type === Syntax.Identifier ?
29 - property.key.name :
30 - property.key.value;
31 - return value !== 'displayName';
32 - });
33 - return safe;
34 - }
35 - return false;
36 -}
37 -
38 -/**
39 - * If `expr` is an Identifier or MemberExpression node made of identifiers and
40 - * dot accesses, return a list of the identifier parts. Other nodes return null.
41 - *
42 - * Examples:
43 - *
44 - * MyComponent -> ['MyComponent']
45 - * namespace.MyComponent -> ['namespace', 'MyComponent']
46 - * namespace['foo'] -> null
47 - * namespace['foo'].bar -> ['bar']
48 - */
49 -function flattenIdentifierOrMemberExpression(expr) {
50 - if (expr.type === Syntax.Identifier) {
51 - return [expr.name];
52 - } else if (expr.type === Syntax.MemberExpression) {
53 - if (!expr.computed && expr.property.type === Syntax.Identifier) {
54 - var flattenedObject = flattenIdentifierOrMemberExpression(expr.object);
55 - if (flattenedObject) {
56 - flattenedObject.push(expr.property.name);
57 - return flattenedObject;
58 - } else {
59 - return [expr.property.name];
60 - }
61 - }
62 - }
63 - return null;
64 -}
65 -
66 -/**
67 - * Transforms the following:
68 - *
69 - * var MyComponent = React.createClass({
70 - * render: ...
71 - * });
72 - *
73 - * into:
74 - *
75 - * var MyComponent = React.createClass({
76 - * displayName: 'MyComponent',
77 - * render: ...
78 - * });
79 - *
80 - * Also catches:
81 - *
82 - * MyComponent = React.createClass(...);
83 - * namespace.MyComponent = React.createClass(...);
84 - * exports.MyComponent = React.createClass(...);
85 - * module.exports = {MyComponent: React.createClass(...)};
86 - */
87 -function visitReactDisplayName(traverse, object, path, state) {
88 - var left, right;
89 -
90 - if (object.type === Syntax.AssignmentExpression) {
91 - left = object.left;
92 - right = object.right;
93 - } else if (object.type === Syntax.Property) {
94 - left = object.key;
95 - right = object.value;
96 - } else if (object.type === Syntax.VariableDeclarator) {
97 - left = object.id;
98 - right = object.init;
99 - }
100 -
101 - if (right && shouldAddDisplayName(right)) {
102 - var displayNamePath = flattenIdentifierOrMemberExpression(left);
103 - if (displayNamePath) {
104 - if (displayNamePath.length > 1 && displayNamePath[0] === 'exports') {
105 - displayNamePath.shift();
106 - }
107 -
108 - var displayName = displayNamePath.join('.');
109 -
110 - utils.catchup(right.arguments[0].range[0] + 1, state);
111 - utils.append('displayName: "' + displayName + '",', state);
112 - }
113 - }
114 -}
115 -
116 -visitReactDisplayName.test = function(object, path, state) {
117 - return (
118 - object.type === Syntax.AssignmentExpression ||
119 - object.type === Syntax.Property ||
120 - object.type === Syntax.VariableDeclarator
121 - );
122 -};
123 -
124 -exports.visitorList = [
125 - visitReactDisplayName
126 -];
vendor/fbtransform/visitors.js deleted
-125
@@ -1,125 +0,0 @@
1 -/*global exports:true*/
2 -
3 -'use strict';
4 -
5 -var es6ArrowFunctions =
6 - require('jstransform/visitors/es6-arrow-function-visitors');
7 -var es6Classes = require('jstransform/visitors/es6-class-visitors');
8 -var es6Destructuring =
9 - require('jstransform/visitors/es6-destructuring-visitors');
10 -var es6ObjectConciseMethod =
11 - require('jstransform/visitors/es6-object-concise-method-visitors');
12 -var es6ObjectShortNotation =
13 - require('jstransform/visitors/es6-object-short-notation-visitors');
14 -var es6RestParameters = require('jstransform/visitors/es6-rest-param-visitors');
15 -var es6Templates = require('jstransform/visitors/es6-template-visitors');
16 -var es6CallSpread =
17 - require('jstransform/visitors/es6-call-spread-visitors');
18 -var es7SpreadProperty =
19 - require('jstransform/visitors/es7-spread-property-visitors');
20 -var react = require('./transforms/react');
21 -var reactDisplayName = require('./transforms/reactDisplayName');
22 -var reservedWords = require('jstransform/visitors/reserved-words-visitors');
23 -
24 -/**
25 - * Map from transformName => orderedListOfVisitors.
26 - */
27 -var transformVisitors = {
28 - 'es6-arrow-functions': es6ArrowFunctions.visitorList,
29 - 'es6-classes': es6Classes.visitorList,
30 - 'es6-destructuring': es6Destructuring.visitorList,
31 - 'es6-object-concise-method': es6ObjectConciseMethod.visitorList,
32 - 'es6-object-short-notation': es6ObjectShortNotation.visitorList,
33 - 'es6-rest-params': es6RestParameters.visitorList,
34 - 'es6-templates': es6Templates.visitorList,
35 - 'es6-call-spread': es6CallSpread.visitorList,
36 - 'es7-spread-property': es7SpreadProperty.visitorList,
37 - 'react': react.visitorList.concat(reactDisplayName.visitorList),
38 - 'reserved-words': reservedWords.visitorList
39 -};
40 -
41 -var transformSets = {
42 - 'harmony': [
43 - 'es6-arrow-functions',
44 - 'es6-object-concise-method',
45 - 'es6-object-short-notation',
46 - 'es6-classes',
47 - 'es6-rest-params',
48 - 'es6-templates',
49 - 'es6-destructuring',
50 - 'es6-call-spread',
51 - 'es7-spread-property'
52 - ],
53 - 'es3': [
54 - 'reserved-words'
55 - ],
56 - 'react': [
57 - 'react'
58 - ]
59 -};
60 -
61 -/**
62 - * Specifies the order in which each transform should run.
63 - */
64 -var transformRunOrder = [
65 - 'reserved-words',
66 - 'es6-arrow-functions',
67 - 'es6-object-concise-method',
68 - 'es6-object-short-notation',
69 - 'es6-classes',
70 - 'es6-rest-params',
71 - 'es6-templates',
72 - 'es6-destructuring',
73 - 'es6-call-spread',
74 - 'es7-spread-property',
75 - 'react'
76 -];
77 -
78 -/**
79 - * Given a list of transform names, return the ordered list of visitors to be
80 - * passed to the transform() function.
81 - *
82 - * @param {array?} excludes
83 - * @return {array}
84 - */
85 -function getAllVisitors(excludes) {
86 - var ret = [];
87 - for (var i = 0, il = transformRunOrder.length; i < il; i++) {
88 - if (!excludes || excludes.indexOf(transformRunOrder[i]) === -1) {
89 - ret = ret.concat(transformVisitors[transformRunOrder[i]]);
90 - }
91 - }
92 - return ret;
93 -}
94 -
95 -/**
96 - * Given a list of visitor set names, return the ordered list of visitors to be
97 - * passed to jstransform.
98 - *
99 - * @param {array}
100 - * @return {array}
101 - */
102 -function getVisitorsBySet(sets) {
103 - var visitorsToInclude = sets.reduce(function(visitors, set) {
104 - if (!transformSets.hasOwnProperty(set)) {
105 - throw new Error('Unknown visitor set: ' + set);
106 - }
107 - transformSets[set].forEach(function(visitor) {
108 - visitors[visitor] = true;
109 - });
110 - return visitors;
111 - }, {});
112 -
113 - var visitorList = [];
114 - for (var i = 0; i < transformRunOrder.length; i++) {
115 - if (visitorsToInclude.hasOwnProperty(transformRunOrder[i])) {
116 - visitorList = visitorList.concat(transformVisitors[transformRunOrder[i]]);
117 - }
118 - }
119 -
120 - return visitorList;
121 -}
122 -
123 -exports.getVisitorsBySet = getVisitorsBySet;
124 -exports.getAllVisitors = getAllVisitors;
125 -exports.transformVisitors = transformVisitors;
vendor/inline-source-map.js deleted
-27
@@ -1,27 +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 -
10 -'use strict';
11 -/*eslint-disable no-undef*/
12 -var Buffer = require('buffer').Buffer;
13 -
14 -function inlineSourceMap(sourceMap, sourceCode, sourceFilename) {
15 - // This can be used with a sourcemap that has already has toJSON called on it.
16 - // Check first.
17 - var json = sourceMap;
18 - if (typeof sourceMap.toJSON === 'function') {
19 - json = sourceMap.toJSON();
20 - }
21 - json.sources = [sourceFilename];
22 - json.sourcesContent = [sourceCode];
23 - var base64 = Buffer(JSON.stringify(json)).toString('base64');
24 - return '//# sourceMappingURL=data:application/json;base64,' + base64;
25 -}
26 -
27 -module.exports = inlineSourceMap;