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

flux-easy

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flux-easy - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

samples/features/build/emit.jsx

2

package.json
{
"name": "flux-easy",
"version": "0.0.7",
"version": "0.0.8",
"description": "Transpiler for use flux with simplicity",

@@ -5,0 +5,0 @@ "bin": "bin/fluxeasy-cli.js",

@@ -477,3 +477,3 @@ var fs = require('fs');

visits = {
visitCallExpression: visitAddEventListener,
visitCallExpression: visitCallExpression,
visitThisExpression: visitThisExpressionForStore

@@ -483,3 +483,3 @@ };

visits = {
visitCallExpression: visitAddEventListener
visitCallExpression: visitCallExpression
};

@@ -500,2 +500,3 @@ if (method.key.name == 'render')

function visitThisExpressionForStore(path) {

@@ -520,9 +521,4 @@

if (n.CallExpression.check(parent_node) && n.MemberExpression.check(last_node) && n.ThisExpression.check(last_node.object)) {
if (last_node.property.name == 'emit')
processEmit();
} else {
if (transpilingStore)
path.replace($state);
}
if (transpilingStore)
path.replace($state);

@@ -540,93 +536,5 @@ this.traverse(path);

function processEmit() {
emit_something = true;
var call_path = p;
var call_node = parent_node;
if (!call_path.parentPath)
throwError(call_node, 'Invalid emit');
var stmt_node = call_path.parentPath.node;
if (!(n.ExpressionStatement.check(stmt_node) &&
(call_node.arguments.length > 0) &&
n.Literal.check(call_node.arguments[0]) &&
typeof call_node.arguments[0].value === 'string'))
throwError(call_node, 'Invalid emit');
}
var has_params;
if (call_node.arguments.length == 1)
has_params = false;
else if (call_node.arguments.length <= 2) {
if (!n.ObjectExpression.check(call_node.arguments[1]))
throwError(call_node, 'Use an object as event arguments');
has_params = true;
} else
throwError(call_node, 'Use an object as event arguments');
var event_name = call_node.arguments[0].value;
event_name = event_name[0].toUpperCase() + event_name.substr(1);
var emit;
if (has_params)
emit = b.expressionStatement(b.callExpression(
b.memberExpression($dependents,
b.identifier('forEach')), [
b.functionExpression(null, [b.identifier('$ref')], b.blockStatement([
b.expressionStatement(b.callExpression(
b.memberExpression(
b.memberExpression(b.identifier('$ref'),
b.identifier('_on' + event_name)),
b.identifier('forEach')), [
b.functionExpression(null, [b.identifier('$event')], b.blockStatement([
b.expressionStatement(b.callExpression(
$emitter, [b.identifier('$event'), call_node.arguments[1]
]))
]))
]))
]))]));
else
emit = b.expressionStatement(b.callExpression(
b.memberExpression($dependents,
b.identifier('forEach')), [
b.functionExpression(null, [b.identifier('r')], b.blockStatement([
b.expressionStatement(b.callExpression(
b.memberExpression(
b.memberExpression(b.identifier('r'),
b.identifier('_on' + event_name)),
b.identifier('forEach')), [$emitter
]
))
]))
]));
var def = true;
for (var i = 0; i < refobject.properties.length; i++)
if (refobject.properties[i].key.name == '_on' + event_name) {
def = false;
break;
}
if (def) {
var listener = b.identifier('listener');
// TODO: define typeAlias for events
// if (state_type) {
// if (has_params)
// ;
// else
// if (!event_without_param)
// event_without_param = b.typeAlias(b.identifier('$EventWithoutParams'), null,
// b.declareFunction(b.functionTypeAnnotation([], {
// "type": "VoidTypeAnnotation"
// }, null, null)));
// listener.typeAnnotation = b.typeAnnotation(b.genericTypeAnnotation(event_without_param.id, null));;
// }
refobject.properties.push(
b.property('init', b.identifier('_on' + event_name), b.arrayExpression([]))
);
}
call_path.replace(emit);
}
}
function visitJSXAttribute(path) {

@@ -718,3 +626,3 @@ var node = path.node;

throwError(m2, "TODO: valueLink with complex objects");
var setBody=[
var setBody = [

@@ -724,5 +632,4 @@ b.expressionStatement(b.assignmentExpression('=', expr.node, b.identifier('newValue'))),

b.expressionStatement(b.callExpression(
b.memberExpression(b.thisExpression(), b.identifier('setState')),
[ b.objectExpression([])]
))
b.memberExpression(b.thisExpression(), b.identifier('setState')), [b.objectExpression([])]
))
];

@@ -740,5 +647,13 @@ processed_instance.internals.push(b.property('init', b.identifier(fnname + '_change'),

function visitAddEventListener(path) {
function visitCallExpression(path) {
var node = path.node;
if (n.MemberExpression.check(node.callee) && (node.callee.property.name == 'addEventListener')) {
if (n.MemberExpression.check(node.callee)) {
if (node.callee.property.name == 'addEventListener')
processAddEventListener();
else if (node.callee.property.name == 'emit')
processEmit(node.callee.object);
}
function processAddEventListener() {
if (node.arguments.length == 2) {

@@ -753,3 +668,3 @@ if (n.ThisExpression.check(node.arguments[1])) {

b.identifier('setState')), [b.objectExpression([])]))
])));
])));
node.arguments[1] = b.memberExpression(b.thisExpression(),

@@ -764,2 +679,96 @@ b.identifier('refreshView'));

}
function processEmit(obj) {
emit_something = true;
var call_path = path;
var call_node = node;
if (!call_path.parentPath)
throwError(call_node, 'Invalid emit');
var stmt_node = call_path.parentPath.node;
if (!(n.ExpressionStatement.check(stmt_node) &&
(call_node.arguments.length > 0) &&
n.Literal.check(call_node.arguments[0]) &&
typeof call_node.arguments[0].value === 'string'))
throwError(call_node, 'Invalid emit');
var has_params;
if (call_node.arguments.length == 1)
has_params = false;
else if (call_node.arguments.length <= 2) {
if (!n.ObjectExpression.check(call_node.arguments[1]))
throwError(call_node, 'Use an object as event arguments');
has_params = true;
} else
throwError(call_node, 'Use an object as event arguments');
var event_name = call_node.arguments[0].value;
event_name = event_name[0].toUpperCase() + event_name.substr(1);
var emit;
var obj_deps = n.ThisExpression.check(obj) ? $dependents :
b.memberExpression(obj, b.identifier('__dependents'));
var obj_emitter = n.ThisExpression.check(obj) ? $emitter :
b.memberExpression(obj, b.identifier('__emitter'));
if (has_params)
emit = b.expressionStatement(b.callExpression(
b.memberExpression(obj_deps,
b.identifier('forEach')), [
b.functionExpression(null, [b.identifier('$ref')], b.blockStatement([
b.expressionStatement(b.callExpression(
b.memberExpression(
b.memberExpression(b.identifier('$ref'),
b.identifier('_on' + event_name)),
b.identifier('forEach')), [
b.functionExpression(null, [b.identifier('$event')], b.blockStatement([
b.expressionStatement(b.callExpression(
obj_emitter, [b.identifier('$event'), call_node.arguments[1]
]))
]))
]))
]))]));
else
emit = b.expressionStatement(b.callExpression(
b.memberExpression(obj_deps,
b.identifier('forEach')), [
b.functionExpression(null, [b.identifier('r')], b.blockStatement([
b.expressionStatement(b.callExpression(
b.memberExpression(
b.memberExpression(b.identifier('r'),
b.identifier('_on' + event_name)),
b.identifier('forEach')), [obj_emitter
]
))
]))
]));
var def = true;
for (var i = 0; i < refobject.properties.length; i++)
if (refobject.properties[i].key.name == '_on' + event_name) {
def = false;
break;
}
if (def) {
var listener = b.identifier('listener');
// TODO: define typeAlias for events
// if (state_type) {
// if (has_params)
// ;
// else
// if (!event_without_param)
// event_without_param = b.typeAlias(b.identifier('$EventWithoutParams'), null,
// b.declareFunction(b.functionTypeAnnotation([], {
// "type": "VoidTypeAnnotation"
// }, null, null)));
// listener.typeAnnotation = b.typeAnnotation(b.genericTypeAnnotation(event_without_param.id, null));;
// }
refobject.properties.push(
b.property('init', b.identifier('_on' + event_name), b.arrayExpression([]))
);
}
call_path.replace(emit);
}
this.traverse(path);

@@ -766,0 +775,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