zaach / jsxgettext

Extract gettext calls from JavaScript, EJS, and other template formats.
Mozilla Public License 2.0
105 stars 56 forks source link

Include filename in throw #104

Open andrewcharnley opened 8 years ago

andrewcharnley commented 8 years ago
var ast      = parser.parse(source, {
  ecmaVersion: 6,
  locations: true
});
} catch(e) {

    e.fileName = filename;
    throw e;
};
BYK commented 8 years ago

Good idea but not sure if this is really possible. May be eslint/espree does it. Are you willing to submit a pull request?

andrewcharnley commented 8 years ago

Why's it not possible? Just add e.fileName = filename;

Reason: the api.parse() takes a dataset and doesn't provide the specific item Acorn threw, instead just passing the Acorn error through.

I doubt linters are using Acorn? so potentially they can throw different errors.

BYK commented 8 years ago

Well that's true. I was a bit busy so didn't think long on this before replying. I'd much prefer the parser do this itself and Espree may be doing it. I'm already planning to switch to Espree sometime soon since it helps with handling comments so would simplify our code here.

So if you have the time I'd look into switching the parser to Espree instead of adding this try-catch block.