MCPcopy Create free account
hub / github.com/reactjs/react-rails / transform

Function transform

lib/assets/javascripts/JSXTransformer.js:12524–12550  ·  view source on GitHub ↗

* Applies all available transformations to the source * @param {array} visitors * @param {string} source * @param {?object} options * @return {object}

(visitors, source, options)

Source from the content-addressed store, hash-verified

12522 * @return {object}
12523 */
12524function transform(visitors, source, options) {
12525 options = options || {};
12526 var ast;
12527 try {
12528 ast = getAstForSource(source, options);
12529 } catch (e) {
12530 e.message = 'Parse Error: ' + e.message;
12531 throw e;
12532 }
12533 var state = utils.createState(source, ast, options);
12534 state.g.visitors = visitors;
12535
12536 if (options.sourceMap) {
12537 var SourceMapGenerator = _dereq_('source-map').SourceMapGenerator;
12538 state.g.sourceMap = new SourceMapGenerator({file: options.filename || 'transformed.js'});
12539 }
12540
12541 traverse(ast, [], state);
12542 utils.catchup(source.length, state);
12543
12544 var ret = {code: state.g.buffer, extra: state.g.extra};
12545 if (options.sourceMap) {
12546 ret.sourceMap = state.g.sourceMap;
12547 ret.sourceMapFilename = options.filename || 'source.js';
12548 }
12549 return ret;
12550}
12551
12552exports.transform = transform;
12553exports.Syntax = Syntax;

Callers 1

innerTransformFunction · 0.85

Calls 2

getAstForSourceFunction · 0.85
traverseFunction · 0.85

Tested by

no test coverage detected