Skip to content

Instantly share code, notes, and snippets.

@joshblack
Last active April 3, 2016 19:53
Show Gist options
  • Save joshblack/0b170475b9651895e9344405aaea4952 to your computer and use it in GitHub Desktop.
Save joshblack/0b170475b9651895e9344405aaea4952 to your computer and use it in GitHub Desktop.
export default function ({ types: t }) {
return {
visitor: {
JSXText(path) {
path.replaceWith(
t.expressionStatement(
t.callExpression(
t.identifier('__'),
[t.stringLiteral(path.node.value)]
)
)
);
},
JSXExpressionContainer(path) {
const binding = path.scope.bindings[path.node.expression.name];
if (!t.isStringLiteral(binding.path.node.init)) {
return;
}
binding.path.replaceWith(t.variableDeclarator(
path.node.expression,
t.callExpression(
t.identifier('__'),
[t.stringLiteral(binding.path.node.init.value)]
)
));
}
}
};
}
class I18N extends React.Component {
render() {
return (
<div>'Hello World'</div>
);
}
}
class Variable extends React.Component {
render() {
const string = `Some ${1 + 1}`;
return <div>{string}</div>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment