diff --git a/scripts/babel-relay-plugin/lib/babelAdapter.js b/scripts/babel-relay-plugin/lib/babelAdapter.js index 5dd4da55b5f05..3adb4f4ee3a5d 100644 --- a/scripts/babel-relay-plugin/lib/babelAdapter.js +++ b/scripts/babel-relay-plugin/lib/babelAdapter.js @@ -19,8 +19,37 @@ var path = require('path'); function babelAdapter(Plugin, t, name, visitorsBuilder) { if (Plugin == null) { - // Babel 6. - return visitorsBuilder(t); + var _ret = (function () { + // Babel 6. + + var _visitorsBuilder = visitorsBuilder(t); + + var _visitorsBuilder$visitor = _visitorsBuilder.visitor; + var _Program = _visitorsBuilder$visitor.Program; + var _TaggedTemplateExpression = _visitorsBuilder$visitor.TaggedTemplateExpression; + + var taggedTemplateExpressionVisitor = { + TaggedTemplateExpression: function TaggedTemplateExpression(path) { + _TaggedTemplateExpression(path, this); + } + }; + + /** + * Run both transforms on Program to make sure that they run before other plugins. + */ + return { + v: { + visitor: { + Program: function Program(path, state) { + _Program(path, state); + path.traverse(taggedTemplateExpressionVisitor, state); + } + } + } + }; + })(); + + if (typeof _ret === 'object') return _ret.v; } // Babel 5. var legacyT = _extends({}, t, { diff --git a/scripts/babel-relay-plugin/src/babelAdapter.js b/scripts/babel-relay-plugin/src/babelAdapter.js index d32208427cb56..cd5a1c6b3e74b 100644 --- a/scripts/babel-relay-plugin/src/babelAdapter.js +++ b/scripts/babel-relay-plugin/src/babelAdapter.js @@ -26,7 +26,25 @@ function babelAdapter( ): mixed { if (Plugin == null) { // Babel 6. - return visitorsBuilder(t); + const {visitor: {Program, TaggedTemplateExpression}} = visitorsBuilder(t); + + const taggedTemplateExpressionVisitor = { + TaggedTemplateExpression(path) { + TaggedTemplateExpression(path, this); + } + } + + /** + * Run both transforms on Program to make sure that they run before other plugins. + */ + return { + visitor: { + Program(path, state) { + Program(path, state); + path.traverse(taggedTemplateExpressionVisitor, state); + } + } + } } // Babel 5. const legacyT = {