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

@jeefo/javascript_preprocessor

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jeefo/javascript_preprocessor - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

358

index.js
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
* File Name : index.js
* Created at : 2020-05-30
* Updated at : 2021-01-05
* Updated at : 2021-01-09
* Author : jeefo

@@ -19,15 +19,19 @@ * Purpose :

const parser = require("@jeefo/ecma_parser/es8/parser");
const Readonly = require("@jeefo/utils/object/readonly");
const AsyncEventEmitter = require("@jeefo/utils/async/event_emitter");
const SPACES_REGEX = /\s+/g;
const SPACES_REGEX = /\s+/g;
const sort_by_start_index = (a, b) => a.start - b.start;
class PreprocessEvent {
constructor (node) {
this.type = node.id.replace(SPACES_REGEX, '_').toLowerCase();
this.target = node;
constructor (module, node) {
this._propagation_stopped = false;
this._immediate_propagation_stopped = false;
const type = node.id.replace(SPACES_REGEX, '_').toLowerCase();
const readonly = new Readonly(this);
readonly.prop("type" , type);
readonly.prop("target" , node);
readonly.prop("module" , module);
}

@@ -40,3 +44,2 @@

stopImmediatePropagation () {
this._propagation_stopped = true;
this._immediate_propagation_stopped = true;

@@ -52,3 +55,6 @@ }

await listener.call(this, event);
if (event._immediate_propagation_stopped) return;
if (event._immediate_propagation_stopped) {
event._propagation_stopped = true;
return;
}
}

@@ -58,4 +64,4 @@ }

async walk (node) {
const event = new PreprocessEvent(node);
async walk (module, node) {
const event = new PreprocessEvent(module, node);
await this.emit(event.type, event);

@@ -98,15 +104,15 @@

case "Assignment pattern" :
await this.walk(node.pattern);
await this.walk(module, node.pattern);
break;
case "Formal parameter" :
await this.walk(node.binding_element);
await this.walk(module, node.binding_element);
break;
case "Binding rest element" :
await this.walk(node.element);
await this.walk(module, node.element);
break;
case "Assignment rest element" :
await this.walk(node.target);
await this.walk(module, node.target);
break;
case "Function rest parameter" :
await this.walk(node.binding_rest_element);
await this.walk(module, node.binding_rest_element);
break;

@@ -140,65 +146,65 @@

case "Template literal expression" :
await this.walk(node.expression);
await this.walk(module, node.expression);
break;
case "Arrow function" :
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Async arrow function" :
await this.walk(node.keyword);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.keyword);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Function call expression" :
await this.walk(node.callee);
await this.walk(node.arguments);
await this.walk(module, node.callee);
await this.walk(module, node.arguments);
break;
case "Super call" :
await this.walk(node.keyword);
await this.walk(node.arguments);
await this.walk(module, node.keyword);
await this.walk(module, node.arguments);
break;
case "Super property" :
await this.walk(node.keyword);
await this.walk(node.property);
await this.walk(module, node.keyword);
await this.walk(module, node.property);
break;
case "Computed super property" :
await this.walk(node.keyword);
await this.walk(node.member);
await this.walk(module, node.keyword);
await this.walk(module, node.member);
break;
case "Member operator" :
await this.walk(node.object);
await this.walk(node.property);
await this.walk(module, node.object);
await this.walk(module, node.property);
break;
case "Computed member expression" :
await this.walk(node.object);
await this.walk(node.member);
await this.walk(module, node.object);
await this.walk(module, node.member);
break;
case "Single name binding" :
await this.walk(node.binding_identifier);
if (node.initializer) await this.walk(node.initializer);
await this.walk(module, node.binding_identifier);
if (node.initializer) await this.walk(module, node.initializer);
break;
case "Binding element pattern" :
await this.walk(node.binding_pattern);
if (node.initializer) await this.walk(node.initializer);
await this.walk(module, node.binding_pattern);
if (node.initializer) await this.walk(module, node.initializer);
break;
case "Assignment element" :
await this.walk(node.target);
if (node.initializer) await this.walk(node.initializer);
await this.walk(module, node.target);
if (node.initializer) await this.walk(module, node.initializer);
break;
case "Method definition" :
await this.walk(node.method);
await this.walk(module, node.method);
break;
case "Static method" :
await this.walk(node.keyword);
await this.walk(node.method);
await this.walk(module, node.keyword);
await this.walk(module, node.method);
break;
case "Method" :
await this.walk(node.property_name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.property_name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;

@@ -208,12 +214,12 @@ case "Async method" :

case "Generator method" :
await this.walk(node.keyword);
await this.walk(node.property_name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.keyword);
await this.walk(module, node.property_name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Setter method" :
await this.walk(node.keyword);
await this.walk(node.property_name);
await this.walk(node.parameter);
await this.walk(node.body);
await this.walk(module, node.keyword);
await this.walk(module, node.property_name);
await this.walk(module, node.parameter);
await this.walk(module, node.body);
break;

@@ -229,3 +235,3 @@

case "Async arrow function body" :
for (const n of node.statement_list) await this.walk(n);
for (const n of node.statement_list) await this.walk(module, n);
break;

@@ -235,10 +241,14 @@

case "Arrow formal parameters" :
for (const n of node.list) await this.walk(n);
for (const n of node.list) await this.walk(module, n);
break;
case "Formal parameters" :
for (const n of node.list) await this.walk(n);
if (node.rest_parameter) await this.walk(node.rest_parameter);
for (const n of node.list) await this.walk(module, n);
if (node.rest_parameter) {
await this.walk(module, node.rest_parameter);
}
break;
case "Grouping expression" :
for (const n of node.expressions_list) await this.walk(n);
for (const n of node.expressions_list) {
await this.walk(module, n);
}
break;

@@ -250,16 +260,18 @@

case "Array assignment pattern" :
for (const n of node.element_list) await this.walk(n);
for (const n of node.element_list) await this.walk(module, n);
break;
case "Object literal" :
for (const n of node.property_definition_list) await this.walk(n);
for (const n of node.property_definition_list) {
await this.walk(module, n);
}
break;
case "Template literal" :
for (const n of node.body) await this.walk(n);
for (const n of node.body) await this.walk(module, n);
break;
case "Object binding pattern" :
case "Object assignment pattern" :
for (const n of node.property_list) await this.walk(n);
for (const n of node.property_list) await this.walk(module, n);
break;
case "Case block" :
for (const n of node.clauses) await this.walk(n);
for (const n of node.clauses) await this.walk(module, n);
break;

@@ -269,19 +281,21 @@

case "For variable declaration" :
await this.walk(node.keyword);
for (const n of node.declaration_list) await this.walk(n);
await this.walk(module, node.keyword);
for (const n of node.declaration_list) {
await this.walk(module, n);
}
break;
case "Lexical declaration" :
await this.walk(node.keyword);
for (const n of node.binding_list) await this.walk(n);
await this.walk(module, node.keyword);
for (const n of node.binding_list) await this.walk(module, n);
break;
case "Lexical binding" :
case "Variable declaration" :
await this.walk(node.binding);
if (node.initializer) await this.walk(node.initializer);
await this.walk(module, node.binding);
if (node.initializer) await this.walk(module, node.initializer);
break;
case "New operator with arguments" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(node.arguments);
await this.walk(module, node.keyword);
await this.walk(module, node.expression);
await this.walk(module, node.arguments);
break;

@@ -291,15 +305,17 @@

case "While statement" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(node.statement);
await this.walk(module, node.keyword);
await this.walk(module, node.expression);
await this.walk(module, node.statement);
break;
case "If statement" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(node.statement);
if (node.else_statement) await this.walk(node.else_statement);
await this.walk(module, node.keyword);
await this.walk(module, node.expression);
await this.walk(module, node.statement);
if (node.else_statement) {
await this.walk(module, node.else_statement);
}
break;
case "Else statement" :
await this.walk(node.keyword);
await this.walk(node.statement);
await this.walk(module, node.keyword);
await this.walk(module, node.statement);
break;

@@ -321,14 +337,14 @@

case "Relational instanceof operator" :
await this.walk(node.left);
await this.walk(node.operator);
await this.walk(node.right);
await this.walk(module, node.left);
await this.walk(module, node.operator);
await this.walk(module, node.right);
break;
case "Expression" :
await this.walk(node.left);
await this.walk(node.right);
await this.walk(module, node.left);
await this.walk(module, node.right);
break;
case "Return statement" :
await this.walk(node.keyword);
if (node.expression) await this.walk(node.expression);
await this.walk(module, node.keyword);
if (node.expression) await this.walk(module, node.expression);
break;

@@ -343,4 +359,4 @@ case "Void operator" :

case "New operator without arguments" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(module, node.keyword);
await this.walk(module, node.expression);
break;

@@ -350,44 +366,44 @@

case "For of statement" :
await this.walk(node.keyword);
await this.walk(node.left);
await this.walk(node.operator);
await this.walk(node.right);
await this.walk(node.statement);
await this.walk(module, node.keyword);
await this.walk(module, node.left);
await this.walk(module, node.operator);
await this.walk(module, node.right);
await this.walk(module, node.statement);
break;
case "For statement" :
await this.walk(node.keyword);
if (node.initializer) await this.walk(node.initializer);
if (node.condition) await this.walk(node.condition);
if (node.update) await this.walk(node.update);
await this.walk(node.statement);
await this.walk(module, node.keyword);
if (node.initializer) await this.walk(module, node.initializer);
if (node.condition) await this.walk(module, node.condition);
if (node.update) await this.walk(module, node.update);
await this.walk(module, node.statement);
break;
case "Property assignment" :
await this.walk(node.property_name);
await this.walk(node.expression);
await this.walk(module, node.property_name);
await this.walk(module, node.expression);
break;
case "Binding property element" :
case "Assignment property element" :
await this.walk(node.property_name);
await this.walk(node.element);
await this.walk(module, node.property_name);
await this.walk(module, node.element);
break;
case "Labelled statement" :
await this.walk(node.label);
await this.walk(node.item);
await this.walk(module, node.label);
await this.walk(module, node.item);
break;
case "Switch statement" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(node.case_block);
await this.walk(module, node.keyword);
await this.walk(module, node.expression);
await this.walk(module, node.case_block);
break;
case "Case clause" :
await this.walk(node.keyword);
await this.walk(node.expression);
for (const n of node.statements) await this.walk(n);
await this.walk(module, node.keyword);
await this.walk(module, node.expression);
for (const n of node.statements) await this.walk(module, n);
break;
case "Default clause" :
await this.walk(node.keyword);
for (const n of node.statements) await this.walk(n);
await this.walk(module, node.keyword);
for (const n of node.statements) await this.walk(module, n);
break;

@@ -397,94 +413,94 @@

case "Continue statement" :
await this.walk(node.keyword);
if (node.label) await this.walk(node.label);
await this.walk(module, node.keyword);
if (node.label) await this.walk(module, node.label);
break;
case "Try statement" :
await this.walk(node.keyword);
await this.walk(node.block);
if (node.catch) await this.walk(node.catch);
if (node.finally) await this.walk(node.finally);
await this.walk(module, node.keyword);
await this.walk(module, node.block);
if (node.catch) await this.walk(module, node.catch);
if (node.finally) await this.walk(module, node.finally);
break;
case "Catch" :
await this.walk(node.keyword);
await this.walk(node.parameter);
await this.walk(node.block);
await this.walk(module, node.keyword);
await this.walk(module, node.parameter);
await this.walk(module, node.block);
break;
case "Catch parameter" :
await this.walk(node.binding);
await this.walk(module, node.binding);
break;
case "Finally" :
await this.walk(node.keyword);
await this.walk(node.block);
await this.walk(module, node.keyword);
await this.walk(module, node.block);
break;
case "Function declaration" :
await this.walk(node.keyword);
await this.walk(node.name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.keyword);
await this.walk(module, node.name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Function expression" :
await this.walk(node.keyword);
if (node.name) await this.walk(node.name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.keyword);
if (node.name) await this.walk(module, node.name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Generator declaration" :
await this.walk(node.keyword);
await this.walk(node.name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.keyword);
await this.walk(module, node.name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Generator expression" :
await this.walk(node.keyword);
if (node.name) await this.walk(node.name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.keyword);
if (node.name) await this.walk(module, node.name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Async function declaration" :
await this.walk(node.async_keyword);
await this.walk(node.function_keyword);
await this.walk(node.name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.async_keyword);
await this.walk(module, node.function_keyword);
await this.walk(module, node.name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Async function expression" :
await this.walk(node.async_keyword);
await this.walk(node.function_keyword);
if (node.name) await this.walk(node.name);
await this.walk(node.parameters);
await this.walk(node.body);
await this.walk(module, node.async_keyword);
await this.walk(module, node.function_keyword);
if (node.name) await this.walk(module, node.name);
await this.walk(module, node.parameters);
await this.walk(module, node.body);
break;
case "Conditional operator" :
await this.walk(node.condition);
await this.walk(node.truthy_expression);
await this.walk(node.falsy_expression);
await this.walk(module, node.condition);
await this.walk(module, node.truthy_expression);
await this.walk(module, node.falsy_expression);
break;
case "Class declaration" :
await this.walk(node.keyword);
await this.walk(node.name);
await this.walk(node.tail);
await this.walk(module, node.keyword);
await this.walk(module, node.name);
await this.walk(module, node.tail);
break;
case "Class expression" :
await this.walk(node.keyword);
if (node.name) await this.walk(node.name);
await this.walk(node.tail);
await this.walk(module, node.keyword);
if (node.name) await this.walk(module, node.name);
await this.walk(module, node.tail);
break;
case "Class tail" :
if (node.heritage) await this.walk(node.heritage);
await this.walk(node.body);
if (node.heritage) await this.walk(module, node.heritage);
await this.walk(module, node.body);
break;
case "Property set parameter list" :
await this.walk(node.parameter);
await this.walk(module, node.parameter);
break;
case "Do while statement" :
await this.walk(node.do_keyword);
await this.walk(node.statement);
await this.walk(node.while_keyword);
await this.walk(node.expression);
await this.walk(module, node.do_keyword);
await this.walk(module, node.statement);
await this.walk(module, node.while_keyword);
await this.walk(module, node.expression);
break;

@@ -507,6 +523,4 @@

async compile (module) {
this.module = module;
const nodes = parser.parse(module.content);
for (const n of nodes) await this.walk(n);
for (const n of nodes) await this.walk(module, n);

@@ -513,0 +527,0 @@ const {replacements} = module;

{
"name": "@jeefo/javascript_preprocessor",
"version": "0.0.7",
"version": "0.0.8",
"homepage": "https://github.com/je3f0o/jeefo_javascript_preprocessor",

@@ -5,0 +5,0 @@ "copyright": "2020",

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