Skip to content

Instantly share code, notes, and snippets.

@erukiti
Created November 7, 2017 06:46
Show Gist options
  • Select an option

  • Save erukiti/09801e5e82f542b415130c91fa5b59fd to your computer and use it in GitHub Desktop.

Select an option

Save erukiti/09801e5e82f542b415130c91fa5b59fd to your computer and use it in GitHub Desktop.
s2sでコメントを挿入する実験 (Babel6でも動くバージョン)
const plugin = babel => {
const {types: t} = babel
return {
inherits: inheritsOpts,
name: 's2s-jsdoc-creator',
visitor: {
Function(nodePath, state) {
const comment = `*
* @hoge
* @fuga
`.split('\n').map(line => line.trim()).join('\n')
const stPath = nodePath.getStatementParent()
// assert inList
stPath.insertBefore(t.emptyStatement())
stPath.getPrevSibling().addComment('trailing', comment)
},
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment