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

abstract-parser

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-parser - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

39

build/src/main.js

@@ -1,28 +0,33 @@

"use strict";require("core-js/modules/es.object.from-entries");var _main=require("./parsers/main.js");
var _options=require("./options.js");
var _main2=require("./normalize/main.js");
import{normalizeNode}from"./normalize/main.js";
import{getOpts}from"./options.js";
import{
acorn as acornParser,
babel as babelParser,
babelEstree as babelEstreeParser,
espree as espreeParser,
esprima as esprimaParser,
meriyah as meriyahParser,
typescriptEstree as typescriptEstreeParser}from
"./parsers/main.js";
const getParsers=function(){
return Object.fromEntries(_main.PARSERS.map(getParser));
const getParser=function(parser){
return{...parser,parse:parseCode.bind(undefined,parser.parse)};
};
const getParser=function({id,parse,...parser}){
return[id,{id,...parser,parse:parseCode.bind(null,parse)}];
};
const parseCode=function(parse,code,opts){
const optsA=(0,_options.getOpts)(code,opts);
const optsA=getOpts(code,opts);
const node=parse(code,optsA);
const nodeA=(0,_main2.normalizeNode)(node,optsA);
const nodeA=normalizeNode(node,optsA);
return nodeA;
};
const abstractParser=getParsers();
module.exports=abstractParser;
export const acorn=getParser(acornParser);
export const babel=getParser(babelParser);
export const babelEstree=getParser(babelEstreeParser);
export const espree=getParser(espreeParser);
export const esprima=getParser(esprimaParser);
export const meriyah=getParser(meriyahParser);
export const typescriptEstree=getParser(typescriptEstreeParser);
//# sourceMappingURL=main.js.map

@@ -1,3 +0,3 @@

"use strict";require("core-js/modules/es.object.from-entries");Object.defineProperty(exports,"__esModule",{value:true});exports.removeAttrs=exports.LOCATION_ATTRS=exports.getRemovedAttrs=void 0;
const getRemovedAttrs=function({locations,comments,parens}){
export const getRemovedAttrs=function({locations,comments,parens}){
return[

@@ -8,5 +8,5 @@ ...(locations?[]:LOCATION_ATTRS),

};exports.getRemovedAttrs=getRemovedAttrs;
};
const LOCATION_ATTRS=["start","end","range","loc"];exports.LOCATION_ATTRS=LOCATION_ATTRS;
export const LOCATION_ATTRS=["start","end","range","loc"];
const COMMENT_ATTRS=[

@@ -21,3 +21,3 @@ "comments",

const removeAttrs=function(node,removedAttrs){
export const removeAttrs=function(node,removedAttrs){
if(removedAttrs.length===0){

@@ -30,3 +30,3 @@ return node;

};exports.removeAttrs=removeAttrs;
};
//# sourceMappingURL=attributes.js.map

@@ -1,7 +0,7 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.normalizeNode=void 0;var _traverse=require("./traverse.js");
var _attributes=require("./attributes.js");
var _sort=require("./sort.js");
import{getRemovedAttrs,removeAttrs}from"./attributes.js";
import{sortKeys}from"./sort.js";
import{traverse}from"./traverse.js";
const normalizeNode=function(
export const normalizeNode=function(
node,

@@ -12,3 +12,3 @@ {top,locations,comments,parens,sort})

const removedAttrs=(0,_attributes.getRemovedAttrs)({locations,comments,parens});
const removedAttrs=getRemovedAttrs({locations,comments,parens});

@@ -20,4 +20,4 @@

return(0,_traverse.traverse)(nodeA,normalize.bind(null,{removedAttrs,sort}));
};exports.normalizeNode=normalizeNode;
return traverse(nodeA,normalize.bind(undefined,{removedAttrs,sort}));
};

@@ -39,6 +39,6 @@

const normalize=function({removedAttrs,sort},node){
const nodeA=(0,_attributes.removeAttrs)(node,removedAttrs);
const nodeB=(0,_sort.sortKeys)(nodeA,{sort});
const nodeA=removeAttrs(node,removedAttrs);
const nodeB=sortKeys(nodeA,{sort});
return nodeB;
};
//# sourceMappingURL=main.js.map

@@ -1,5 +0,5 @@

"use strict";require("core-js/modules/es.object.from-entries");Object.defineProperty(exports,"__esModule",{value:true});exports.sortKeys=void 0;var _attributes=require("./attributes.js");
import{LOCATION_ATTRS}from"./attributes.js";
const sortKeys=function(node,{sort}){
export const sortKeys=function(node,{sort}){
if(!sort){

@@ -10,3 +10,3 @@ return node;

return sortObject(node,keysComparator);
};exports.sortKeys=sortKeys;
};

@@ -16,3 +16,3 @@ const sortObject=function(object,comparator){

const keys=Object.keys(object).sort(comparator);
return Object.fromEntries(keys.map(key=>[key,object[key]]));
return Object.fromEntries(keys.map((key)=>[key,object[key]]));
};

@@ -59,4 +59,4 @@

const getLocIndexes=function(keyA,keyB){
const locIndexA=_attributes.LOCATION_ATTRS.indexOf(keyA);
const locIndexB=_attributes.LOCATION_ATTRS.indexOf(keyB);
const locIndexA=LOCATION_ATTRS.indexOf(keyA);
const locIndexB=LOCATION_ATTRS.indexOf(keyB);

@@ -63,0 +63,0 @@ if(locIndexA===-1&&locIndexB===-1){

@@ -1,3 +0,3 @@

"use strict";require("core-js/modules/es.object.from-entries");Object.defineProperty(exports,"__esModule",{value:true});exports.traverse=void 0;
const traverse=function(object,transform){
export const traverse=function(object,transform){
if(typeof object!=="object"||object===null){

@@ -8,3 +8,3 @@ return object;

if(Array.isArray(object)){
return object.map(child=>traverse(child,transform));
return object.map((child)=>traverse(child,transform));
}

@@ -15,7 +15,7 @@

const objectB=Object.keys(objectA).
map(key=>[key,traverse(objectA[key],transform)]).
map((key)=>[key,traverse(objectA[key],transform)]).
filter(isDefinedChild);
const objectC=Object.fromEntries(objectB);
return objectC;
};exports.traverse=traverse;
};

@@ -22,0 +22,0 @@ const isDefinedChild=function([,child]){

@@ -1,15 +0,17 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.EXAMPLE_OPTS=exports.DEFAULT_OPTS=exports.getOpts=void 0;var _jestValidate=require("jest-validate");
var _isPlainObj=_interopRequireDefault(require("is-plain-obj"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
import filterObj from"filter-obj";
import isPlainObj from"is-plain-obj";
import{validate}from"jest-validate";
const getOpts=function(code,opts={}){
export const getOpts=function(code,opts={}){
validateBasic(code,opts);
(0,_jestValidate.validate)(opts,{exampleConfig:EXAMPLE_OPTS});
validate(opts,{exampleConfig:EXAMPLE_OPTS});
const optsA={...DEFAULT_OPTS,...opts};
const optsA=filterObj(opts,isDefined);
const optsB={...DEFAULT_OPTS,...optsA};
const optsB=setForcedOpts({opts:optsA});
const optsC=addSourceType(optsB);
return optsC;
};exports.getOpts=getOpts;
const optsC=setForcedOpts({opts:optsB});
const optsD=addSourceType(optsC);
return optsD;
};

@@ -21,3 +23,3 @@ const validateBasic=function(code,opts){

if(!(0,_isPlainObj.default)(opts)){
if(!isPlainObj(opts)){
throw new TypeError(`Options must be a plain object: ${opts}`);

@@ -28,3 +30,3 @@ }

const DEFAULT_OPTS={
export const DEFAULT_OPTS={
legacy:false,

@@ -42,10 +44,14 @@ script:false,

flow:false,
jsx:false};exports.DEFAULT_OPTS=DEFAULT_OPTS;
jsx:false};
const EXAMPLE_OPTS={
export const EXAMPLE_OPTS={
...DEFAULT_OPTS,
source:"filename.js"};exports.EXAMPLE_OPTS=EXAMPLE_OPTS;
source:"filename.js"};
const isDefined=function(key,value){
return value!==undefined;
};
const setForcedOpts=function({

@@ -52,0 +58,0 @@ opts,

@@ -1,4 +0,4 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.acorn=void 0;var _tokens=require("../../tokens.js");
import{normalizeTokens}from"../../tokens.js";
var _plugins=require("./plugins.js");
import{addPlugins}from"./plugins.js";

@@ -20,5 +20,6 @@

{
const acornParser=(0,_plugins.addPlugins)(legacy,jsx);
const acornParser=addPlugins(legacy,jsx);
const mutableOpts=getMutableOpts({comments,tokens});
const ecmaVersion=getEcmaVersion(legacy);

@@ -37,3 +38,3 @@ const node=acornParser.parse(code,{

preserveParens:parens,
...(legacy?{}:{ecmaVersion:2020}),
ecmaVersion,
allowHashBang:true,

@@ -44,11 +45,22 @@ sourceFile:source,

const mutableOptsA=(0,_tokens.normalizeTokens)(mutableOpts,"onToken");
const mutableOptsA=normalizeTokens(mutableOpts,"onToken");
return{...node,...mutableOptsA};
};
const acorn={
const getEcmaVersion=function(legacy){
if(legacy){
return EARLIEST_ECMA_VERSION;
}
return LATEST_ECMA_VERSION;
};
const EARLIEST_ECMA_VERSION=3;
const LATEST_ECMA_VERSION=2022;
export const acorn={
id:"acorn",
title:"Acorn",
syntaxes:["jsx"],
parse};exports.acorn=acorn;
parse};

@@ -55,0 +67,0 @@

@@ -1,6 +0,5 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.addPlugins=void 0;
var acornMain=_interopRequireWildcard(require("acorn"));
var _acornStage=_interopRequireDefault(require("acorn-stage3"));
var _acornJsx=_interopRequireDefault(require("acorn-jsx"));
var _moize=_interopRequireDefault(require("moize"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _getRequireWildcardCache(){if(typeof WeakMap!=="function")return null;var cache=new WeakMap;_getRequireWildcardCache=function(){return cache};return cache}function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache();if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}
import{parse,Parser}from"acorn";
import acornJsx from"acorn-jsx";
import acornStage3 from"acorn-stage3";
import moize from"moize";

@@ -10,14 +9,9 @@

const plugins=[
...(legacy?[]:[_acornStage.default]),
...(jsx?[(0,_acornJsx.default)()]:[])];
...(legacy?[]:[acornStage3]),
...(jsx?[acornJsx()]:[])];
if(plugins.length===0){
return acornMain;
}
return acornMain.Parser.extend(...plugins);
return plugins.length===0?parse:Parser.extend(...plugins);
};
const addPlugins=(0,_moize.default)(mAddPlugins);exports.addPlugins=addPlugins;
export const addPlugins=moize(mAddPlugins,{maxSize:1e3});
//# sourceMappingURL=plugins.js.map

@@ -1,6 +0,6 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.babelestree=exports.babel=void 0;var _parser=require("@babel/parser");
import{parse as babelParse}from"@babel/parser";
var _tokens=require("../../tokens.js");
import{normalizeTokens}from"../../tokens.js";
var _plugins=require("./plugins.js");
import{getPlugins}from"./plugins.js";

@@ -17,2 +17,3 @@

locations,
comments,
tokens,

@@ -25,5 +26,5 @@ source,

{
const pluginsA=(0,_plugins.getPlugins)({plugins,typescript,flow,jsx,legacy});
const pluginsA=getPlugins({plugins,typescript,flow,jsx,legacy});
const node=(0,_parser.parse)(code,{
const node=babelParse(code,{
sourceType,

@@ -40,2 +41,3 @@

plugins:pluginsA,
attachComment:comments,
ranges:locations,

@@ -46,3 +48,3 @@ tokens,

const nodeA=(0,_tokens.normalizeTokens)(node,"tokens");
const nodeA=normalizeTokens(node,"tokens");
return nodeA;

@@ -52,15 +54,15 @@ };

const babel={
export const babel={
id:"babel",
title:"Babel",
syntaxes:["typescript","flow","jsx"],
parse:parse.bind(null,[])};exports.babel=babel;
parse:parse.bind(undefined,[])};
const babelestree={
id:"babelestree",
export const babelEstree={
id:"babelEstree",
title:"Babel-ESTree",
syntaxes:["typescript","flow","jsx"],
parse:parse.bind(null,["estree"])};exports.babelestree=babelestree;
parse:parse.bind(undefined,["estree"])};
//# sourceMappingURL=main.js.map

@@ -1,3 +0,9 @@

"use strict";require("core-js/modules/es.array.flat-map");require("core-js/modules/es.array.unscopables.flat-map");Object.defineProperty(exports,"__esModule",{value:true});exports.getPlugins=void 0;
const getPlugins=function({plugins,typescript,flow,jsx,legacy}){
export const getPlugins=function({
plugins,
typescript,
flow,
jsx,
legacy})
{
return[

@@ -12,3 +18,3 @@ {names:plugins,enabled:true},

flatMap(getPluginsNames);
};exports.getPlugins=getPlugins;
};

@@ -15,0 +21,0 @@

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.espree=void 0;var _espree=require("espree");
import{parse as espreeParse}from"espree";

@@ -8,3 +8,3 @@

{
return(0,_espree.parse)(code,{
return espreeParse(code,{
sourceType:legacy?"script":sourceType,

@@ -14,3 +14,3 @@ loc:locations,

comment:comments,
...(legacy?{}:{ecmaVersion:2020}),
...(legacy?{}:{ecmaVersion:2022}),
ecmaFeatures:{

@@ -25,7 +25,7 @@ globalReturn:loose,

const espree={
export const espree={
id:"espree",
title:"Espree",
syntaxes:["jsx"],
parse};exports.espree=espree;
parse};
//# sourceMappingURL=espree.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.esprima=void 0;var _esprima=require("esprima");
import{parse as esprimaParse}from"esprima";

@@ -8,3 +8,3 @@

{
return(0,_esprima.parse)(code,{
return esprimaParse(code,{
sourceType,

@@ -20,7 +20,7 @@ tolerant:loose,

const esprima={
export const esprima={
id:"esprima",
title:"Esprima",
syntaxes:["jsx"],
parse};exports.esprima=esprima;
parse};
//# sourceMappingURL=esprima.js.map

@@ -1,16 +0,7 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.PARSERS=void 0;var _esprima=require("./esprima.js");
var _main=require("./acorn/main.js");
var _espree=require("./espree.js");
var _typescript_estree=require("./typescript_estree.js");
var _meriyah=require("./meriyah.js");
var _main2=require("./babel/main.js");
const PARSERS=[
_esprima.esprima,
_main.acorn,
_espree.espree,
_meriyah.meriyah,
_typescript_estree.typescriptestree,
_main2.babelestree,
_main2.babel];exports.PARSERS=PARSERS;
export{acorn}from"./acorn/main.js";
export{babel,babelEstree}from"./babel/main.js";
export{espree}from"./espree.js";
export{esprima}from"./esprima.js";
export{meriyah}from"./meriyah.js";
export{typescriptEstree}from"./typescript_estree.js";
//# sourceMappingURL=main.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.meriyah=void 0;var _meriyah=require("meriyah");
import{parse as meriyahParse}from"meriyah";

@@ -21,3 +21,3 @@

const node=(0,_meriyah.parse)(code,{
const node=meriyahParse(code,{
module:sourceType==="module",

@@ -41,7 +41,7 @@ globalReturn:loose,

const meriyah={
export const meriyah={
id:"meriyah",
title:"Meriyah",
syntaxes:["jsx"],
parse};exports.meriyah=meriyah;
parse};
//# sourceMappingURL=meriyah.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.typescriptestree=void 0;var _typescriptEstree=require("@typescript-eslint/typescript-estree");
import{parse as typescriptestreeParse}from"@typescript-eslint/typescript-estree";

@@ -6,3 +6,3 @@

try{
return(0,_typescriptEstree.parse)(code,{
return typescriptestreeParse(code,{
errorOnUnknownASTType:loose,

@@ -13,3 +13,2 @@ loc:locations,

jsx,
useJSXTextNode:jsx,
tokens});

@@ -22,7 +21,7 @@

const typescriptestree={
id:"typescriptestree",
export const typescriptEstree={
id:"typescriptEstree",
title:"TypeScript-ESTree",
syntaxes:["typescript","jsx"],
parse};exports.typescriptestree=typescriptestree;
parse};

@@ -29,0 +28,0 @@

@@ -1,4 +0,4 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.normalizeTokens=void 0;
const normalizeTokens=function(node,name){
export const normalizeTokens=function(node,name){
if(node[name]===undefined){

@@ -10,3 +10,3 @@ return node;

return{...node,[name]:tokens};
};exports.normalizeTokens=normalizeTokens;
};

@@ -13,0 +13,0 @@ const normalizeToken=function({type,value}){

{
"name": "abstract-parser",
"version": "0.2.0",
"main": "build/src/main.js",
"version": "0.3.0",
"type": "module",
"exports": "./build/src/main.js",
"main": "./build/src/main.js",
"files": [
"build/src",
"!~"
"build/src/**/*.{js,ts,map,json,sh,md}",
"examples/**/*.{js,ts,map,json,sh,md}"
],

@@ -12,7 +14,2 @@ "scripts": {

},
"husky": {
"hooks": {
"pre-push": "gulp check --full"
}
},
"description": "Abstraction layer for JavaScript parsers",

@@ -32,25 +29,22 @@ "keywords": [],

"dependencies": {
"@babel/parser": "^7.7.7",
"@typescript-eslint/typescript-estree": "^2.12.0",
"acorn": "^7.1.0",
"acorn-jsx": "^5.1.0",
"acorn-stage3": "^2.0.0",
"core-js": "^3.6.0",
"espree": "^6.1.2",
"@babel/parser": "^7.17.9",
"@typescript-eslint/typescript-estree": "^5.18.0",
"acorn": "^8.7.0",
"acorn-jsx": "^5.3.2",
"acorn-stage3": "^4.0.0",
"espree": "^9.3.1",
"esprima": "^4.0.1",
"is-plain-obj": "^2.0.0",
"jest-validate": "^24.9.0",
"meriyah": "^1.9.3",
"moize": "^5.4.4",
"typescript": "^3.7.3"
"filter-obj": "^3.0.0",
"is-plain-obj": "^4.0.0",
"jest-validate": "^27.5.1",
"meriyah": "^2.1.1",
"moize": "^6.1.0",
"typescript": "^4.6.3"
},
"devDependencies": {
"@ehmicky/dev-tasks": "^0.30.71",
"ava": "^2.4.0",
"gulp": "^4.0.2",
"husky": "^3.1.0"
"@ehmicky/dev-tasks": "^1.0.72"
},
"engines": {
"node": ">=10.17.0"
"node": ">=14.18.0"
}
}
[![Codecov](https://img.shields.io/codecov/c/github/ehmicky/abstract-parser.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/abstract-parser)
[![Travis](https://img.shields.io/badge/cross-platform-4cc61e.svg?logo=travis)](https://travis-ci.org/ehmicky/abstract-parser)
[![Build](https://github.com/ehmicky/abstract-parser/workflows/Build/badge.svg)](https://github.com/ehmicky/abstract-parser/actions)
[![Node](https://img.shields.io/node/v/abstract-parser.svg?logo=node.js)](https://www.npmjs.com/package/abstract-parser)
[![Gitter](https://img.shields.io/gitter/room/ehmicky/abstract-parser.svg?logo=gitter)](https://gitter.im/ehmicky/abstract-parser)
[![Twitter](https://img.shields.io/badge/%E2%80%8B-twitter-4cc61e.svg?logo=twitter)](https://twitter.com/intent/follow?screen_name=ehmicky)

@@ -10,12 +9,8 @@ [![Medium](https://img.shields.io/badge/%E2%80%8B-medium-4cc61e.svg?logo=medium)](https://medium.com/@ehmicky)

Work in progress!
Work in progress.
# Support
If you found a bug or would like a new feature, _don't hesitate_ to
[submit an issue on GitHub](../../issues).
For any question, _don't hesitate_ to [submit an issue on GitHub](../../issues).
For other questions, feel free to
[chat with us on Gitter](https://gitter.im/ehmicky/abstract-parser).
Everyone is welcome regardless of personal background. We enforce a

@@ -22,0 +17,0 @@ [Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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