Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API - Trouble w/ Parser #872

Closed
tschaub opened this issue Feb 12, 2017 · 4 comments
Closed

API - Trouble w/ Parser #872

tschaub opened this issue Feb 12, 2017 · 4 comments

Comments

@tschaub
Copy link
Contributor

tschaub commented Feb 12, 2017

I'm putting together a plugin that extracts strings for localization (assuming I should use a plugin since one new "dictionary" file will be emitted based on call expressions in many modules). I'd like to visit call expressions on a subset of the modules in a dependency tree.

Seeing the docs for plugging into the parser, I was hopeful I could provide a callback that would get called for call expressions where the callee matched the supplied identifier.

Specifically, these docs:

call <identifier>(expr: Expression) bailing
abc(1) => call abc

a.b.c(1) => call a.b.c

made me think I could do this:

parser.plugin('call this.context.localize', function(expr) {
  // called for this.context.localize() expressions
});

But this callback is not getting called. I can successfully provide a callback for 'call require'. Am I misinterpreting the docs thinking that this works for other identifiers (and member expressions)?

@tschaub tschaub changed the title Trouble with parser('call a.b.c', visitor) Trouble with parser.plugin('call a.b.c', visitor) Feb 12, 2017
@skipjack skipjack added the API label Feb 25, 2017
@skipjack
Copy link
Collaborator

Hmmm sorry for the delay on this... I'm not seeing the code you mentioned on that page anymore. Is this still relevant or should we close it out?

@skipjack
Copy link
Collaborator

skipjack commented May 28, 2017

Ah nevermind, it's here now. @TheLarkInn any idea what's going on here? I'm not too familiar with the plugin API.

@skipjack skipjack changed the title Trouble with parser.plugin('call a.b.c', visitor) API - Trouble w/ Parser Jun 14, 2017
@sokra
Copy link
Member

sokra commented Aug 4, 2017

Most parser hooks only react to free var. i. e. for call a.b.c:

a.b.c(1); // triggered
function test(a) {
  a.b.c(1); // not triggered
}

call this.context.localize won't work, because this is not free (and can't be).

You can try call localize which will trigger for not defined localize calls.

@skipjack
Copy link
Collaborator

@tschaub please refer to @sokra's comment above. I'm going to close as this has been inactive for a while now and I'm not sure how we can change the current documentation in the short term to improve this description. The good news is our cleanup of the Guides section (#1258) is pretty much done and now I (and hopefully others) will start going through the Concepts and API sections next better organize and review the content there.

If you think something can be tweaked sooner to make it more readable please submit a PR or comment here.

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

No branches or pull requests

4 participants