* Applies all available transformations to the source * @param {array} visitors * @param {string} source * @param {?object} options * @return {object}
(visitors, source, options)
| 12522 | * @return {object} |
| 12523 | */ |
| 12524 | function 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 | |
| 12552 | exports.transform = transform; |
| 12553 | exports.Syntax = Syntax; |
no test coverage detected