New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More ā†’
Socket
Sign inDemoInstall
Socket

@putout/engine-parser

Package Overview
Dependencies
Maintainers
0
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/engine-parser

šŸŠPutout parser

  • 12.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20K
increased by39.19%
Maintainers
0
Weekly downloads
Ā 
Created
Source

@putout/engine-parser NPM version

šŸŠPutout engine that parses input.

Install

npm i @putout/engine-parser

Supported parsers

Any parser should be installed before use, but you can be sure that @babel/parse always installed.

API

By default @putout/printer used. It formats code according to eslint-plugin-putout rules but without using ESLint.

But you can also use babel with:

const ast = parse(source);
const code = print(ast, {
    printer: 'babel',
});

When you need to pass options, use:

const code = print(ast, {
    printer: ['putout', {
        format: {
            indent: '    ',
        },
    }],
});

print(ast, {
    printer: ['babel', {
        alginSpaces: false, // when you don't want to add spaces on empty lines
    }],
});

print(ast [, options])

Print code from ast

parse(code, [, options])

You can add default options for custom parser you use.

template.fresh(code)

parse without memoization.

template.ast(code)

create node using memoization.

template.ast.fresh(code)

create node without memoization.

template.extractExpression(code)

Extract expression node from ExpressionStatement.

Generate sourcemaps using Babel

To generate sourcemap using babel generator, you should use babel parser before. This is low level transformation, because Babel doesn't preserve any formatting.

const {generate} = require('@putout/engine-parser');
const {parse} = require('@putout/engine-parser/babel');

const ast = parse(source, {
    sourceFilename: 'hello.js',
});

generate(ast, {sourceMaps: true}, {
    'hello.js': source,
});

// returns
({
    code,
    map,
});

Example

const {parse} = require('@putout/engine-parser');
const parser = 'acorn';

const code = parse('var t = "hello"', {
    parser,
});

License

MIT

Keywords

FAQs

Package last updated on 09 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc