functionless / nodejs-closure-serializer Goto Github PK
View Code? Open in Web Editor NEWSerialize arbitrary NodeJS closures and customize serialization behavior.
License: Apache License 2.0
Serialize arbitrary NodeJS closures and customize serialization behavior.
License: Apache License 2.0
It should be possible to transform the AST syntax prior to serialization rather than relying purely on value-level serialization customization.
This would be useful for removing syntax added by Functionless's TS transformers.
For functionless/functionless#274
import
and export
instead of require
and exports
.From functionless/functionless#273
It would be nice to remove the deploymentOnlyModule
from the bottom of all of the files. By passing in a pattern to the serialize function, we could avoiding missing files and polluting the modules.
Add a README and be sure to mention that this is a fork.
The way the closure serializer wraps closures in a with
degrades performance by approximately 4-5x. See below for an example.
function foo() {
with({
a: "hello"
}) {
return (function() {
return function() {
return arguments * 10 ;
}
}).apply(undefined, undefined).apply(this, arguments);
}
}
function foo2() {
return (function() {
return function() {
return arguments * 10;
}
}).apply(undefined, undefined).apply(this, arguments)
}
for (let j = 0; j < 10; j++) {
const start = new Date();
for (let i = 0; i < 10*1000*1000; i++) {
foo2(i);
}
console.log(new Date().getTime() - start.getTime());
}
Closure serialization should maintain references to closured let
and var
and all modifications of that value should reflect everywhere it is referenced.
Below is a test case that should pass, with expectResult: 2
, but the result is 0
- because the closured let
is re-declared in each closure and copied by-value, not by-ref. This is true even when using the previous with
technique.
let i = 0;
function a() {
i += 1;
}
function b() {
i += 1;
}
cases.push({
title: "two functions modifying a single let have changes reflected",
func: () => {
a();
b();
return i;
},
snapshot: true,
expectResult: 2,
});
The repo is a fork of @pulumi/pulumi's closure serializer.
One of the changes to the original repo was to support replacement of objects to be serialized using the serialize
callback.
The current implementation supports the contract (o: any) => boolean | any
where:
o
as is - original contracto
(replace with undefined) - original contracto
with the valueThis contract isn't great, but it was a quick update from the original contract.
We should update this to support the edge case where a boolean value should replace the original value.
Proposal:
/**
* return the value to serialize, return `undefined` to skip serialization. `undefined` may also be used to avoid circular references.
**/
serialize: (o: any) => any | undefined
In the updated contract, the user just returns the new value or current value.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.