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.3 to 0.0.4

630

index.js
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
* File Name : index.js
* Created at : 2020-05-30
* Updated at : 2020-06-02
* Updated at : 2020-10-07
* Author : jeefo

@@ -18,4 +18,4 @@ * Purpose :

const parser = require("@jeefo/ecma_parser/es8/parser");
const EventEmitter = require("@jeefo/utils/event_emitter");
const parser = require("@jeefo/ecma_parser/es8/parser");
const AsyncEventEmitter = require("@jeefo/utils/async/event_emitter");

@@ -45,11 +45,9 @@ const SPACES_REGEX = /\s+/g;

class JavascriptPreprocessor extends EventEmitter {
emit (event_name, event) {
class JavascriptPreprocessor extends AsyncEventEmitter {
async emit (event_name, event) {
if (this._events[event_name]) {
const listeners = this._events[event_name].concat();
for (const listener of listeners) {
listener.call(this, event);
if (event._immediate_propagation_stopped) {
return;
}
await listener.call(this, event);
if (event._immediate_propagation_stopped) return;
}

@@ -59,301 +57,433 @@ }

walk (node) {
async walk (node) {
const event = new PreprocessEvent(node);
this.emit(event.type, event);
await this.emit(event.type, event);
if (event._propagation_stopped) {
return;
}
if (event._propagation_stopped) return;
switch (node.id) {
// Identifiers
case "Identifier" :
case "Identifier name" :
case "Label identifier" :
case "Binding identifier" :
case "Identifier reference" :
case "Async arrow binding identifier" :
// Literals
case "String literal" :
case "Null literal" :
case "Boolean literal" :
case "Numeric literal" :
case "Regular expression literal" :
case "Template literal string" :
// Keyword
case "Keyword" :
case "This keyword" :
// Others
case "Comment" :
case "Undefined" :
case "Punctuator" :
case "This keyword":
case "Null literal":
case "Meta property":
case "Super property":
case "String literal":
case "Boolean literal":
case "Numeric literal":
case "Identifier name":
case "Break statement":
case "Empty statement":
case "Undefined literal":
case "Continue statement":
case "Binding identifier":
case "Debugger statement":
case "Empty parameter list":
case "Identifier reference":
case "Template literal string":
case "Regular expression literal":
case "New target" :
case "Debugger statement" :
case "Empty statement" :
case "Empty parameter list" :
break;
case "Comment" :
if (node.previous_comment) {
this.walk(node.previous_comment);
}
case "Binding pattern" :
case "Assignment pattern" :
await this.walk(node.pattern);
break;
case "Keyword" :
case "Terminal symbol":
case "Label identifier":
case "Contextual keyword" :
if (node.pre_comment) { this.walk(node.pre_comment); }
case "Formal parameter" :
await this.walk(node.binding_element);
break;
case "If statement" :
case "For statement" :
case "While statement" :
this.walk(node.keyword);
this.walk(node.expression);
this.walk(node.statement);
case "Binding rest element" :
await this.walk(node.element);
break;
case "Try statement":
this.walk(node.block);
if (node.handler) { this.walk(node.handler); }
if (node.finalizer) { this.walk(node.finalizer); }
case "Assignment rest element" :
await this.walk(node.target);
break;
case "Method body":
case "Function body":
case "Generator body":
case "Block statement":
case "Async method body":
case "Async function body":
case "Arrow function body":
case "Async arrow function body":
node.statement_list.map(n => this.walk(n));
case "Function rest parameter" :
await this.walk(node.binding_rest_element);
break;
case "Async arrow binding identifier":
this.walk(node.identifier);
case "Initializer" :
case "Concise body" :
case "Async concise body" :
case "Binding element" :
case "Binding property" :
case "Spread element" :
case "Arrow parameters" :
case "Property name" :
case "Property definition" :
// Unary expressions
case "Logical not operator" :
case "Bitwise not operator" :
case "Positive plus operator" :
case "Negation minus operator" :
case "Prefix decrement operator" :
case "Prefix increment operator" :
case "Postfix decrement operator" :
case "Postfix increment operator" :
case "Expression statement" :
case "Assignment property" :
case "Assignment expression" :
case "Computed member access" :
case "Parenthesized expression" :
case "Template literal expression" :
await this.walk(node.expression);
break;
case "Arguments":
case "Expression":
case "Formal parameters":
case "Arrow formal parameters":
node.list.forEach(n => this.walk(n));
case "Arrow function" :
await this.walk(node.parameters);
await this.walk(node.body);
break;
case "Case block":
node.case_clauses.forEach(n => this.walk(n));
case "Async arrow function" :
await this.walk(node.keyword);
await this.walk(node.parameters);
await this.walk(node.body);
break;
case "Class body":
case "Array literal":
case "Array binding pattern":
case "Array assignment pattern":
node.element_list.forEach(n => this.walk(n));
case "Function call expression" :
await this.walk(node.callee);
await this.walk(node.arguments);
break;
case "Object literal":
node.property_definition_list.forEach(n => this.walk(n));
case "Super call" :
await this.walk(node.keyword);
await this.walk(node.arguments);
break;
case "Object binding pattern":
case "Object assignment pattern":
node.property_list.forEach(n => this.walk(n));
case "Super property" :
await this.walk(node.keyword);
await this.walk(node.property);
break;
case "Assignment element":
this.walk(node.target);
case "Computed super property" :
await this.walk(node.keyword);
await this.walk(node.member);
break;
case "Destructuring assignment target":
this.walk(node.expression);
if (node.initializer) { this.walk(node.initializer); }
case "Member operator" :
await this.walk(node.object);
await this.walk(node.property);
break;
case "Template literal":
node.body.forEach(n => this.walk(n));
case "Computed member expression" :
await this.walk(node.object);
await this.walk(node.member);
break;
case "Lexical declaration":
this.walk(node.keyword);
node.binding_list.forEach(n => this.walk(n));
node.delimiters.forEach(n => this.walk(n));
this.walk(node.terminator);
case "Single name binding" :
await this.walk(node.binding_identifier);
if (node.initializer) await this.walk(node.initializer);
break;
case "Lexical binding":
case "Variable declaration":
this.walk(node.binding);
if (node.initializer) { this.walk(node.initializer); }
case "Binding element pattern" :
await this.walk(node.binding_pattern);
if (node.initializer) await this.walk(node.initializer);
break;
case "Single name binding":
if (node.initializer) { this.walk(node.initializer); }
case "Assignment element" :
await this.walk(node.target);
if (node.initializer) await this.walk(node.initializer);
break;
case "Arrow function":
case "Function expression":
case "Function declaration":
case "Generator expression":
case "Async arrow function":
case "Async function expression":
this.walk(node.body);
this.walk(node.parameters);
case "Method definition" :
await this.walk(node.method);
break;
case "Static method" :
await this.walk(node.keyword);
await this.walk(node.method);
break;
case "Method" :
case "Getter method":
case "Generator method":
this.walk(node.property_name);
this.walk(node.parameters);
this.walk(node.body);
await this.walk(node.property_name);
await this.walk(node.parameters);
await this.walk(node.body);
break;
case "Setter method":
this.walk(node.property_name);
this.walk(node.parameter);
this.walk(node.body);
case "Async method" :
case "Getter 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);
break;
case "Async method":
case "Setter method" :
await this.walk(node.keyword);
await this.walk(node.property_name);
await this.walk(node.parameter);
await this.walk(node.body);
break;
case "Function call expression":
this.walk(node.callee);
this.walk(node.arguments);
case "Block statement" :
case "Method body" :
case "Function body" :
case "Generator body" :
case "Arrow function body" :
case "Async method body" :
case "Async function body" :
case "Async arrow function body" :
for (const n of node.statement_list) await this.walk(n);
break;
case "Case clause":
this.walk(node.expression);
node.statements.forEach(n => this.walk(n));
case "Arguments" :
case "Arrow formal parameters" :
for (const n of node.list) await this.walk(n);
break;
case "Default clause":
node.statements.forEach(n => this.walk(n));
case "Formal parameters" :
for (const n of node.list) await this.walk(n);
if (node.rest_parameter) await this.walk(node.rest_parameter);
break;
case "Finally block":
this.walk(node.block);
case "Grouping expression" :
for (const n of node.expressions_list) await this.walk(n);
break;
case "Catch block":
this.walk(node.parameter);
this.walk(node.block);
case "Class body" :
case "Array literal" :
case "Array binding pattern" :
case "Array assignment pattern" :
for (const n of node.element_list) await this.walk(n);
break;
case "For declaration":
this.walk(node.binding);
case "Object literal" :
for (const n of node.property_definition_list) await this.walk(n);
break;
case "For of header":
this.walk(node.binding);
this.walk(node.expression);
case "Template literal" :
for (const n of node.body) await this.walk(n);
break;
case "Binding property element":
this.walk(node.property_name);
this.walk(node.element);
case "Object binding pattern" :
case "Object assignment pattern" :
for (const n of node.property_list) await this.walk(n);
break;
case "Return statement" :
case "For iterator condition" :
case "For iterator initializer" :
if (node.expression) { this.walk(node.expression); }
case "Case block" :
for (const n of node.clauses) await this.walk(n);
break;
case "Class tail" :
if (node.heritage) { this.walk(node.heritage); }
this.walk(node.body);
case "Variable statement" :
case "For variable declaration" :
await this.walk(node.keyword);
for (const n of node.declaration_list) await this.walk(n);
break;
case "Class expression" :
case "Class declaration" :
this.walk(node.tail);
case "Lexical declaration" :
await this.walk(node.keyword);
for (const n of node.binding_list) await this.walk(n);
break;
case "Member operator" :
this.walk(node.object);
case "Lexical binding" :
case "Variable declaration" :
await this.walk(node.binding);
if (node.initializer) await this.walk(node.initializer);
break;
case "Formal parameter" :
this.walk(node.binding_element);
case "New operator with arguments" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(node.arguments);
break;
case "Catch parameter":
case "Property set parameter list":
this.walk(node.parameter);
case "With statement" :
case "While statement" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(node.statement);
break;
case "Binding pattern" :
case "Assignment pattern" :
this.walk(node.pattern);
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);
break;
case "Property definition" :
this.walk(node.expression);
case "Else statement" :
await this.walk(node.keyword);
await this.walk(node.statement);
break;
case "Super call" :
this.walk(node.arguments);
case "Assignment operator" :
case "Logical or operator" :
case "Logical and operator" :
case "Bitwise or operator" :
case "Bitwise xor operator" :
case "Bitwise and operator" :
case "Equality operator" :
case "Relational operator" :
case "Bitwise shift operator" :
case "Additive operator" :
case "Multiplicative operator" :
case "Exponentiation operator" :
case "Relational in operator" :
case "Relational instanceof operator" :
await this.walk(node.left);
await this.walk(node.operator);
await this.walk(node.right);
break;
case "Binding rest element" :
this.walk(node.element);
case "Expression" :
await this.walk(node.left);
await this.walk(node.right);
break;
case "Function rest parameter" :
this.walk(node.binding_rest_element);
case "Return statement" :
await this.walk(node.keyword);
if (node.expression) await this.walk(node.expression);
break;
case "Binding element pattern" :
this.walk(node.binding_pattern);
if (node.initializer) { this.walk(node.initializer); }
case "Void operator" :
case "Typeof operator" :
case "Delete operator" :
case "Class heritage" :
case "Throw statement" :
case "Yield expression" :
case "Await expression" :
case "New operator without arguments" :
await this.walk(node.keyword);
await this.walk(node.expression);
break;
case "Computed member expression" :
this.walk(node.object);
this.walk(node.expression);
case "For in statement" :
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);
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);
break;
case "Property assignment" :
this.walk(node.property_name);
this.walk(node.expression);
await this.walk(node.property_name);
await this.walk(node.expression);
break;
case "In operator" :
case "Equality operator" :
case "Assignment operator" :
case "Arithmetic operator" :
case "Instanceof operator" :
case "Logical or operator" :
case "Bitwise or operator" :
case "Logical and operator" :
case "Bitwise and operator" :
case "Bitwise xor operator" :
case "Comparision operator" :
case "Bitwise shift operator" :
case "Multiplicative operator" :
this.walk(node.left);
this.walk(node.right);
case "Binding property element" :
case "Assignment property element" :
await this.walk(node.property_name);
await this.walk(node.element);
break;
case "Labelled statement" :
await this.walk(node.label);
await this.walk(node.item);
break;
case "Switch statement" :
await this.walk(node.keyword);
await this.walk(node.expression);
await this.walk(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);
break;
case "Default clause" :
await this.walk(node.keyword);
for (const n of node.statements) await this.walk(n);
break;
case "Break statement" :
case "Continue statement" :
await this.walk(node.keyword);
if (node.label) await this.walk(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);
break;
case "Catch" :
await this.walk(node.keyword);
await this.walk(node.parameter);
await this.walk(node.block);
break;
case "Catch parameter" :
await this.walk(node.binding);
break;
case "Finally" :
await this.walk(node.keyword);
await this.walk(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);
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);
break;
case "Generator declaration" :
await this.walk(node.keyword);
await this.walk(node.name);
await this.walk(node.parameters);
await this.walk(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);
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);
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);
break;
case "Conditional operator" :
this.walk(node.condition);
this.walk(node.truthy_expression);
this.walk(node.falsy_expression);
await this.walk(node.condition);
await this.walk(node.truthy_expression);
await this.walk(node.falsy_expression);
break;
case "For iterator header" :
this.walk(node.initializer);
this.walk(node.condition);
if (node.update) { this.walk(node.update); }
case "Class declaration" :
await this.walk(node.keyword);
await this.walk(node.name);
await this.walk(node.tail);
break;
case "Literal" :
case "Initializer" :
case "Concise body" :
case "Static method" :
case "Property name" :
case "Spread element" :
case "Class heritage" :
case "New expression" :
case "Call expression" :
case "Delete operator" :
case "Await exression" :
case "Binding element" :
case "Typeof operator" :
case "Throw statement" :
case "Yield expression" :
case "Arrow parameters" :
case "Binding property" :
case "Method definition" :
case "Member expression" :
case "Primary expression" :
case "Async concise body" :
case "Assignment property" :
case "Grouping expression" :
case "Logical not operator" :
case "Expression statement" :
case "Assignment expression" :
case "Computed property name" :
case "Positive plus operator" :
case "Negation minus operator" :
case "Parenthesized expression" :
case "Left hand side expression" :
case "Prefix increment operator" :
case "Prefix decrement operator" :
case "Postfix decrement operator" :
case "Postfix increment operator" :
case "Template literal expression" :
this.walk(node.expression);
case "Class expression" :
await this.walk(node.keyword);
if (node.name) await this.walk(node.name);
await this.walk(node.tail);
break;
case "Labelled statement":
this.walk(node.label_identifier);
this.walk(node.delimiter);
this.walk(node.statement);
case "Class tail" :
if (node.heritage) await this.walk(node.heritage);
await this.walk(node.body);
break;
case "Switch statement" :
this.walk(node.keyword);
this.walk(node.expression);
this.walk(node.case_block);
case "Property set parameter list" :
await this.walk(node.parameter);
break;
case "Variable statement" :
case "Variable declaration list no in" :
this.walk(node.keyword);
node.declaration_list.forEach(n => this.walk(n));
node.delimiters.forEach(n => this.walk(n));
this.walk(node.terminator);
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);
break;
default:
const error = new Error(`Unexpected node: '${ node.id }'`);
error.node = node;
throw error;
case "Destructuring assignment target" :
case "Assignment property identifier" :
case "For declaration" :
case "For binding" :
case "Binding list" :
parser.log(node);
debugger
break;
default: throw new Error(`Undefined node: '${node.id}'`);
}

@@ -366,3 +496,3 @@ }

const nodes = parser.parse(module.content);
nodes.forEach(n => this.walk(n));
for (const n of nodes) await await this.walk(n);

@@ -369,0 +499,0 @@ module.replacements.sort(sort_by_start_index);

{
"name": "@jeefo/javascript_preprocessor",
"version": "0.0.3",
"version": "0.0.4",
"homepage": "https://github.com/je3f0o/jeefo_javascript_preprocessor",
"copyright": "2020",
"description": "part of jeefo framework",
"description": "ECMA script preprocessor. (under developing...)",
"author": {

@@ -30,4 +30,6 @@ "name": "je3f0o",

"devDependencies": {
"@jeefo/ecma_parser": "0.0.9",
"@jeefo/parser": "0.0.26",
"@jeefo/publish": "0.0.31"
}
}

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

@jeefo/javascript_preprocessor part of jeefo framework.
ECMA script preprocessor. (under developing...)
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