Skip to content

Instantly share code, notes, and snippets.

@bwindels
Created September 11, 2019 09:51
Show Gist options
  • Save bwindels/46d69efde2963c13f2d7bf07626ede1a to your computer and use it in GitHub Desktop.
Save bwindels/46d69efde2963c13f2d7bf07626ede1a to your computer and use it in GitHub Desktop.
const acorn = require("acorn");
const walk = require("acorn-walk");
walk.simple(acorn.parse("import i18n from \"i18n\"; const str = i18n`foo ${bar} haha`", {sourceType: "module"}), {
// https://github.com/estree/estree/blob/master/es2015.md#template-literals
TaggedTemplateExpression(node) {
console.log("TaggedTemplateExpression:")
console.log(JSON.stringify(node, undefined, 2));
},
ImportDeclaration(node) {
console.log("ImportDeclaration:")
console.log(JSON.stringify(node, undefined, 2));
}
});
@bwindels
Copy link
Author

could also use a local variable for the tag instead of a global imported variable

@bwindels
Copy link
Author

bwindels commented Sep 11, 2019

e.g. support

const str = this.i18n`foo ${bar} haha`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment