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

Add wrapPluginVisitorMethod option to allow introspection and metrics tracking of plugins #3659

Merged
merged 1 commit into from Aug 20, 2016

Conversation

sebmck
Copy link
Contributor

@sebmck sebmck commented Aug 16, 2016

I'll submit a PR to babel.github.io with docs once this gets accepted. This adds an optional callback that you can use to wrap visitor methods. At FB we're having problems with plugin performance and Babel 6 merging plugin visitors means we have little insight into performance, this will allow us to have granular tracking and telemetry. Usage is displayed in the included test:

  test("option wrapPluginVisitorMethod", function () {
    var calledRaw = 0;
    var calledIntercept = 0;

    babel.transform("function foo() { bar(foobar); }", {
      wrapPluginVisitorMethod(pluginAlias, visitorType, callback) {
        if (pluginAlias !== "foobar") {
          return callback;
        }

        assert.equal(visitorType, "enter");

        return function () {
          calledIntercept++;
          return callback.apply(this, arguments);
        };
      },

      plugins: [new Plugin({
        name: "foobar",
        visitor: {
          "Program|Identifier": function () {
            calledRaw++;
          }
        }
      })]
    });

    assert.equal(calledRaw, 4);
    assert.equal(calledIntercept, 4);
  });

@codecov-io
Copy link

codecov-io commented Aug 16, 2016

Current coverage is 89.73% (diff: 100%)

Merging #3659 into master will increase coverage by 1.51%

@@             master      #3659   diff @@
==========================================
  Files           191        191           
  Lines         13591      17454   +3863   
  Methods        1424       2080    +656   
  Messages          0          0           
  Branches       3127       4732   +1605   
==========================================
+ Hits          11990      15662   +3672   
- Misses         1601       1792    +191   
  Partials          0          0           

Powered by Codecov. Last update 308de41...0d692fc

@hzoo hzoo added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Aug 20, 2016
@hzoo
Copy link
Member

hzoo commented Aug 20, 2016

Are we able to add a name to the existing plugins (since I see you added them for the 2 internal ones)?

@sebmck
Copy link
Contributor Author

sebmck commented Aug 20, 2016

@hzoo We actually already populate an internal name field if the plugin was created via a string reference.

@hzoo
Copy link
Member

hzoo commented Aug 20, 2016

Cool I was wondering about that 😛

@hzoo hzoo merged commit 07b3dc1 into master Aug 20, 2016
@hzoo
Copy link
Member

hzoo commented Aug 20, 2016

👍

and @loganfsmyth said earlier

I'd love to add a note that it's not really meant for implementing anything, just inspection, when we do the docs

@hzoo hzoo deleted the wrap-visitor-method-option branch August 20, 2016 14:40
@hzoo hzoo mentioned this pull request Sep 8, 2016
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants