Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@putout/engine-parser

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/engine-parser - npm Package Compare versions

Comparing version 4.9.1 to 4.10.0

5

lib/generate.js

@@ -5,8 +5,9 @@ 'use strict';

module.exports = (node) => {
module.exports = (node, options, sourceMaps) => {
return generate(node, {
comments: false,
recordAndTupleSyntaxType: 'hash',
});
...options,
}, sourceMaps);
};

3

lib/parse.js

@@ -16,5 +16,7 @@ 'use strict';

isJSX,
sourceFileName,
} = options || {};
const ast = recast.parse(source, {
sourceFileName,
parser: getParser({

@@ -25,2 +27,3 @@ parser,

isJSX,
sourceFileName,
}),

@@ -27,0 +30,0 @@ });

@@ -21,3 +21,6 @@ 'use strict';

module.exports.parse = function babelParse(source, {isTS, isJSX = true, isFlow = getFlow(source)}) {
// There is a difference in options naming for babel and recast
// recast -> sourceFileName
// babel, putout: sourceFilename
module.exports.parse = function babelParse(source, {sourceFilename, isTS, isJSX = true, isFlow = getFlow(source)}) {
const {parse} = initBabel();

@@ -28,2 +31,3 @@

tokens: true,
sourceFilename,
...options,

@@ -30,0 +34,0 @@ plugins: clean([

@@ -6,4 +6,8 @@ 'use strict';

const fixStrictMode = (a) => a.replace(`\n\n\n'use strict'`, `\n\n'use strict'`);
const addSourceMap = (sourceMapName, {code, map}) => !sourceMapName ? code : `${code}\n//${stringify(map)}\n`;
module.exports = (ast) => {
const {stringify} = JSON;
module.exports = (ast, options = {}) => {
const {sourceMapName} = options;
const printOptions = {

@@ -13,9 +17,14 @@ quote: 'single',

wrapColumn: Infinity,
...options,
};
const printed = print(ast, printOptions).code;
const code = fixStrictMode(printed);
const printed = print(ast, printOptions);
const {map} = printed;
const code = fixStrictMode(printed.code);
return code;
return addSourceMap(sourceMapName, {
code,
map,
});
};
{
"name": "@putout/engine-parser",
"version": "4.9.1",
"version": "4.10.0",
"type": "commonjs",
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
"description": "putout parser",
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-parser",
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-parser#readme",
"main": "./lib/parser.js",

@@ -8,0 +9,0 @@ "release": false,

@@ -6,3 +6,3 @@ # @putout/engine-parser [![NPM version][NPMIMGURL]][NPMURL]

`putout` engine that parses input.
🐊[`Putout`](https://github.com/coderaiser/putout) engine that parses input.

@@ -47,2 +47,42 @@ ## Install

### Sourcemaps
You have two ways to benefit from source map generation:
- using `Recast` print;
- using `Babel` generator;
#### Generate sourcemaps usign Recast
```js
const source = `const hello = 'world';`;
const ast = parse(source, {
sourceFileName: 'hello.js',
});
print(ast, {sourceMapName: 'hello.map'});
// returns
`const hello = 'world';
{"version":3,"sources":["hello.js"],"names":[],"mappings":"AAAA...","file":"hello.map","sourcesContent":["const hello = 'world';"]}`;
```
#### Generate sourcemaps usign Bebel
To generate sourcemap usig babel generator, you should use babel parser before.
This is low level transformation, because `Babel` doesn't preserve any formatting.
```js
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

@@ -49,0 +89,0 @@

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