return through(function write (file, enc, next) { if (file.isNull()) return next(null, file); if (file.path.match(options.match || /jsx?$/i)) { if (file.isStream()) { var data = ''; file.contents.on('data', function(chunk) { data += chunk.toString('utf8'); }); file.contents.on('end', function() { try { file.contents = jsx.transform(data, options); next(); } catch (err) { next(err); } }); return this.push(file); } if (file.isBuffer()) { try { file.contents = new Buffer( jsx.fromString(file.contents.toString('utf8'), options) ); } catch (err) { next(err); } } } this.push(file); next(); });
(function() { const jsxSource = `<div x={ foo }>{ bar }</div>`; const jsSource = jsxTransform.fromString(jsxSource, { factory: 'React.createElement' }); assert.strictEqual(jsSource, `React.createElement('div', {x: foo }, [bar ])`); })();
(function() { const jsxSource = `<div x="foo" y={ 2 }>Tekisuto</div>`; const jsSource = jsxTransform.fromString(jsxSource, { factory: 'React.createElement' }); assert.strictEqual(jsSource, `React.createElement('div', {x: "foo", y: 2 }, ["Tekisuto"])`); })();
process.stdin.on('end', () => { process.stdout.write(jsx.fromString(chunks.join(''), { factory })) })