Skip to content

Handling ES-2015 exports #183

@tbranyen

Description

@tbranyen

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,
      };
    }
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions