Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ts-ast-to-literal

dword-design8.2kMIT4.0.0TypeScript support: included

Transform a TypeScript AST node into a real JS object.

abstract-syntax-tree, ast, node, typescript

readme

ts-ast-to-literal

npm version Linux macOS Windows compatible Build status Coverage status Dependency status Renovate enabled
Open in Gitpod Buy Me a Coffee PayPal Patreon

Transform a TypeScript AST node into a real JS object.

Special thanks to ast-to-literal for the initial idea 👏.

Install

# npm
$ npm install ts-ast-to-literal

# Yarn
$ yarn add ts-ast-to-literal

Usage

const ts = require('typescript')

const ast = ts.createSourceFile(
  'x.ts',
  `export default { foo: 'bar', num: 8 }`,
  ts.ScriptTarget.Latest
)

console.log(self(ast.statements[0].expression))
// { foo: 'bar', num: 8 }

Contribute

Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️

Support

Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:

Buy Me a Coffee  If you want to send me a one time donation. The coffee is pretty good 😊.
PayPal  Also for one time donations if you like PayPal.
Patreon  Here you can support me regularly, which is great so I can steadily work on projects.

Thanks a lot for your support! ❤️

License

MIT License © Sebastian Landwehr

changelog

4.0.0 (2024-03-04)

Bug Fixes

BREAKING CHANGES

  • node.js >= 18

3.0.13 (2023-05-16)

Bug Fixes

  • update dependency @dword-design/tester to v2.0.16 (a35eff6)

3.0.12 (2023-04-09)

Bug Fixes

  • update dependency @dword-design/functions to v4.1.7 (e213285)

3.0.11 (2023-04-09)

Bug Fixes

  • update dependency @dword-design/tester to v2.0.14 (d8bfec8)

3.0.10 (2023-04-09)

Bug Fixes

3.0.9 (2023-03-19)

Bug Fixes

  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.18 (1f98bd5)

3.0.8 (2023-03-19)

Bug Fixes

  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.17 (186dec8)

3.0.7 (2023-03-19)

Bug Fixes

  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.16 (630d0c1)

3.0.6 (2023-03-19)

Bug Fixes

  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.15 (1523eef)

3.0.5 (2023-03-18)

Bug Fixes

  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.13 (21ff6c7)
  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.14 (10390e2)

3.0.4 (2023-03-16)

Bug Fixes

  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.12 (20edf76)

3.0.3 (2023-03-16)

Bug Fixes

  • update dependency typescript to v4.9.5 (8640552)

3.0.2 (2023-03-15)

Bug Fixes

  • update dependency @dword-design/tester-plugin-tmp-dir to v2.1.10 (a488904)

3.0.1 (2023-02-15)

Bug Fixes

3.0.0 (2022-12-04)

Bug Fixes

BREAKING CHANGES

  • drop node.js 12, move to esm

2.0.0 (2022-10-13)

Bug Fixes

  • make typescript a peer dependency (#50) (6aa4de6)

BREAKING CHANGES

  • make typescript a peer dependency

1.0.6 (2022-07-25)

Bug Fixes

  • make typescript a direct dependency (22b3873)

1.0.5 (2022-02-13)

Bug Fixes

1.0.4 (2022-02-12)

Bug Fixes

  • handle StringLiteral as object property; TypeScript declarations (#26) (4637cf2)

1.0.3 (2022-01-12)

Bug Fixes

1.0.2 (2022-01-04)

Bug Fixes

1.0.1 (2021-08-19)

Bug Fixes

1.0.0 (2021-08-19)

Bug Fixes

  • update config files (f3f80c5)
  • write GitHub metadata to package.json [description, keywords] (#1) (e9caeeb)

Features