@putout/engine-parser
putout parser
Last updated 4 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/engine-parser 
SYNC missed versions from official npm registry.

@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 recast or babel with:

const ast = parse(source, {
    printer: 'recast',
});

const code = print(ast, {
    printer: 'recast',
});

When you need to pass options, use:

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

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.

Sourcemaps

You have two ways to benefit from source map generation:

  • using Recast print;
  • using Babel generator;

Generate sourcemaps using Recast

const source = `const hello = 'world';`;

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

print(ast, {
    printer: 'recast',
    sourceMapName: 'hello.map',
});

// returns
`const hello = 'world';
{"version":3,"sources":["hello.js"],"names":[],"mappings":"AAAA...","file":"hello.map","sourcesContent":["const hello = 'world';"]}`;

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 babel = require('@putout/engine-parser/babel');

const ast = babel.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

Current Tags

  • 11.1.0                                ...           latest (15 days ago)

111 Versions

  • 11.1.0                                ...           15 days ago
  • 11.0.1                                ...           2 months ago
  • 11.0.0                                ...           2 months ago
  • 10.8.0                                ...           7 months ago
  • 10.7.0                                ...           7 months ago
  • 10.6.0                                ...           7 months ago
  • 10.5.0                                ...           8 months ago
  • 10.4.0                                ...           9 months ago
  • 10.3.0                                ...           9 months ago
  • 10.2.0                                ...           9 months ago
  • 10.1.0                                ...           a year ago
  • 10.0.4                                ...           a year ago
  • 10.0.3                                ...           a year ago
  • 10.0.2                                ...           a year ago
  • 10.0.1                                ...           a year ago
  • 10.0.0                                ...           a year ago
  • 9.6.0                                ...           a year ago
  • 9.5.0                                ...           a year ago
  • 9.4.0                                ...           a year ago
  • 9.3.0                                ...           a year ago
  • 9.2.0                                ...           a year ago
  • 9.1.0                                ...           a year ago
  • 9.0.0                                ...           a year ago
  • 8.4.0                                ...           a year ago
  • 8.3.0                                ...           a year ago
  • 8.2.0                                ...           a year ago
  • 8.0.3                                ...           a year ago
  • 8.0.2                                ...           a year ago
  • 8.0.1                                ...           a year ago
  • 8.0.0                                ...           a year ago
  • 7.2.1                                ...           a year ago
  • 7.2.0                                ...           a year ago
  • 7.1.0                                ...           a year ago
  • 7.0.0                                ...           a year ago
  • 6.5.1                                ...           2 years ago
  • 6.5.0                                ...           2 years ago
  • 6.4.1                                ...           2 years ago
  • 6.4.0                                ...           2 years ago
  • 6.3.0                                ...           2 years ago
  • 6.2.0                                ...           2 years ago
  • 6.1.0                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 5.6.0                                ...           2 years ago
  • 5.5.0                                ...           2 years ago
  • 5.4.1                                ...           2 years ago
  • 5.4.0                                ...           2 years ago
  • 5.3.3                                ...           2 years ago
  • 5.3.2                                ...           2 years ago
  • 5.3.1                                ...           2 years ago
  • 5.3.0                                ...           2 years ago
  • 5.2.0                                ...           2 years ago
  • 5.1.1                                ...           3 years ago
  • 5.1.0                                ...           3 years ago
  • 5.0.0                                ...           3 years ago
  • 4.10.2                                ...           3 years ago
  • 4.10.1                                ...           3 years ago
  • 4.10.0                                ...           3 years ago
  • 4.9.1                                ...           3 years ago
  • 4.9.0                                ...           3 years ago
  • 4.8.0                                ...           3 years ago
  • 4.7.0                                ...           3 years ago
  • 4.6.0                                ...           3 years ago
  • 4.5.0                                ...           3 years ago
  • 4.4.0                                ...           3 years ago
  • 4.3.1                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.0                                ...           4 years ago
  • 4.1.1                                ...           4 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.18.3                                ...           5 years ago
  • 1.18.2                                ...           5 years ago
  • 1.18.1                                ...           5 years ago
  • 1.18.0                                ...           5 years ago
  • 1.17.2                                ...           5 years ago
  • 1.17.1                                ...           5 years ago
  • 1.17.0                                ...           5 years ago
  • 1.16.0                                ...           5 years ago
  • 1.15.0                                ...           5 years ago
  • 1.14.0                                ...           5 years ago
  • 1.13.2                                ...           5 years ago
  • 1.13.1                                ...           5 years ago
  • 1.13.0                                ...           5 years ago
  • 1.12.0                                ...           5 years ago
  • 1.11.0                                ...           5 years ago
  • 1.10.1                                ...           5 years ago
  • 1.10.0                                ...           5 years ago
  • 1.9.0                                ...           5 years ago
  • 1.8.0                                ...           5 years ago
  • 1.7.0                                ...           5 years ago
  • 1.6.0                                ...           5 years ago
  • 1.5.1                                ...           5 years ago
  • 1.5.0                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.4                                ...           5 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (22)

© 2010 - cnpmjs.org x YWFE | Home | YWFE