Skip to content

Commit

Permalink
Get code fragment with keys (#34)
Browse files Browse the repository at this point in the history
Update `extractCode` function to output the location of the extracted
keys as well as the translation keys.

This would close #31.
  • Loading branch information
Phyks authored and oliviertassinari committed Aug 3, 2017
1 parent 5068c1d commit 9e33023
Show file tree
Hide file tree
Showing 12 changed files with 659 additions and 59 deletions.
13 changes: 9 additions & 4 deletions src/extractFromCode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { parse } from 'babylon';
import traverse from 'babel-traverse';
import { uniq } from './utils';

const noInformationTypes = [
'CallExpression',
Expand Down Expand Up @@ -64,7 +63,10 @@ export default function extractFromCode(code, options = {}) {
ast.comments.forEach((comment) => {
let match = commentRegExp.exec(comment.value);
if (match) {
keys.push(match[1].trim());
keys.push({
key: match[1].trim(),
loc: comment.loc,
});
}

// Check for ignored lines
Expand Down Expand Up @@ -98,11 +100,14 @@ export default function extractFromCode(code, options = {}) {
const key = getKey(node.arguments[0]);

if (key) {
keys.push(key);
keys.push({
key,
loc: node.loc,
});
}
}
},
});

return uniq(keys);
return keys;
}
Loading

0 comments on commit 9e33023

Please sign in to comment.