How to use @babel/plugin-syntax-typescript - 1 common examples

To help you get started, we’ve selected a few @babel/plugin-syntax-typescript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erukiti / ast-book-sample / chapter6 / typescript-ast-viewer.js View on Github external
const {transform} = require('@babel/core')
const syntaxTypeScript = require('@babel/plugin-syntax-typescript').default

const src = 'const hoge: Fraction'

const replacer = (key, value) => {
  return ['start', 'end', 'loc'].indexOf(key) !== -1 ? undefined : value
}

const plugin = {
  inherits: syntaxTypeScript,
  visitor: {
    VariableDeclarator: (nodePath) => {
      console.log(JSON.stringify(nodePath.node.id, replacer,  '  '))
    }
  }
}

@babel/plugin-syntax-typescript

Allow parsing of TypeScript syntax

MIT
Latest version published 1 month ago

Package Health Score

95 / 100
Full package analysis

Popular @babel/plugin-syntax-typescript functions