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

Handling ES-2015 exports #183

Open
tbranyen opened this issue Jul 27, 2016 · 0 comments
Open

Handling ES-2015 exports #183

tbranyen opened this issue Jul 27, 2016 · 0 comments

Comments

@tbranyen
Copy link

I found that dox does a pretty good job on its own for handling ES-2015 and the modules syntax. However when trying to document my API, I found it impossible to tag my re-exported module methods.

For example:

/**
 * hrmmm...
 */
export { html } from './util/tagged-template';

So I came up with this very naive and not at all production ready parser that you can add easily and it might cover your use cases:

const dox = require('dox');

const parseArgs = str => {
  const arg = /export\s+\{(.*)\}/g.exec(str)[1];

  if (arg.indexOf(',') > -1) {
    return arg.split(',').map(str => str.trim()).filter(Boolean)[0];
  }
  else if (arg.indexOf('as') > -1) {
    return arg.split(' as ')[1].trim();
  }

  return arg.trim();
};

// Handle ES6 export syntax.
dox.contextPatternMatchers.push((string, parentContext) => {
  if (string.indexOf('export') > -1) {
    const name = parseArgs(string);

    if (name) {
      return {
        type: 'property',
        name,
        string,
      };
    }
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant