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

@hypermode/functions-as

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hypermode/functions-as - npm Package Compare versions

Comparing version 0.9.3 to 0.9.4

2

package.json
{
"name": "@hypermode/functions-as",
"version": "0.9.3",
"version": "0.9.4",
"description": "Hypermode library for AssemblyScript functions",

@@ -5,0 +5,0 @@ "author": "Hypermode, Inc.",

@@ -130,4 +130,5 @@ import binaryen from "assemblyscript/lib/binaryen.js";

const type = getTypeInfo(_type);
const optional = MultiParamGen.SN.opt_fns.get(e.name).find((e) => e.param.name == name)
?.param.optional || false;
const optional = MultiParamGen.SN.optional_fns
.get(e.name)
?.find((e) => e.param.name == name)?.param.optional || false;
params.push({

@@ -134,0 +135,0 @@ name,

@@ -8,4 +8,4 @@ import { Node, Parser, Source, Tokenizer, } from "assemblyscript/dist/assemblyscript.js";

static SN = new MultiParamGen();
opt_fns = new Map();
constructor() { }
required_fns = [];
optional_fns = new Map();
static init() {

@@ -16,92 +16,89 @@ if (!MultiParamGen.SN)

}
visitSource(source) {
const paramsFieldName = "__SUPPLIED_PARAMS";
const uninitializedValue = "UNINITIALIZED_VALUE";
for (const stmt of source.statements) {
if (stmt.kind === 55) {
const node = stmt;
if (node.flags === 2 &&
source.sourceKind === 1) {
let name = node.name.text;
if (!node.body && node.decorators?.length) {
const decorator = node.decorators.find((e) => e.name.text === "external");
if (decorator.args.length > 1 &&
decorator.args[1].kind === 16) {
name = decorator.args[1].value.toString();
}
}
if (node.signature.parameters.length > 63) {
throw new Error("Functions exceeding 64 parameters not allowed!");
}
const params = [];
for (const param of node.signature.parameters) {
const defaultValue = getDefaultValue(param);
params.push({
param: {
name: param.name.text,
type: {
name: uninitializedValue,
path: uninitializedValue,
},
optional: !!param.initializer,
},
defaultValue,
});
}
this.opt_fns.set(name, params);
if (node.signature.parameters.find((v) => v.parameterKind === 1)) {
let body;
if (node.body.kind != 30) {
body = Node.createBlockStatement([node.body], node.range);
}
else {
body = node.body;
}
node.signature.parameters.push(Node.createParameter(0, Node.createIdentifierExpression(paramsFieldName, node.range, false), Node.createNamedType(Node.createSimpleTypeName("u64", node.range), [], false, node.range), null, node.range));
let first = true;
for (let i = 0; i < node.signature.parameters.length; i++) {
const param = node.signature.parameters[i];
if (param.parameterKind != 1)
continue;
const stmt = Node.createIfStatement(Node.createBinaryExpression(76, Node.createParenthesizedExpression(Node.createBinaryExpression(92, first
? ((first = false),
Node.createIdentifierExpression(paramsFieldName, node.range))
: Node.createParenthesizedExpression(Node.createBinaryExpression(90, Node.createIdentifierExpression(paramsFieldName, node.range), newIntegerLiteral(i, node.range), node.range), node.range), newIntegerLiteral(1, node.range), node.range), node.range), newIntegerLiteral(0, node.range), node.range), Node.createExpressionStatement(Node.createBinaryExpression(101, Node.createIdentifierExpression(param.name.text, node.range, false), param.initializer, node.range)), null, node.range);
body.statements.unshift(stmt);
if (param.initializer)
param.initializer = null;
}
}
visitExportStatement(node) {
const source = node.range.source;
if (source.sourceKind != 1)
return;
for (const member of node.members) {
const name = member.localName.text;
this.required_fns.push(name);
}
}
visitFunctionDeclaration(node) {
const source = node.range.source;
let name = node.name.text;
if (!node.body && node.decorators?.length) {
const decorator = node.decorators.find((e) => e.name.text === "external");
if (decorator.args.length > 1 &&
decorator.args[1].kind === 16) {
name = decorator.args[1].value.toString();
}
}
if (source.sourceKind != 1 &&
!this.required_fns.includes(name))
return;
if (node.flags != 2 && !this.required_fns.includes(name))
return;
if (node.signature.parameters.length > 63) {
throw new Error("Functions exceeding 64 parameters not allowed!");
}
const params = [];
for (const param of node.signature.parameters) {
const defaultValue = getDefaultValue(param);
params.push({
param: {
name: param.name.text,
type: {
name: "UNINITIALIZED_VALUE",
path: "UNINITIALIZED_VALUE",
},
optional: !!param.initializer,
},
defaultValue,
});
}
this.optional_fns.set(name, params);
initDefaultValues(node);
if (node.body == null) {
let name = node.name.text;
if (!node.body && node.decorators?.length) {
const decorator = node.decorators.find((e) => e.name.text === "external");
if (decorator.args.length > 1 &&
decorator.args[1].kind === 16) {
name = decorator.args[1].value.toString();
}
if (node.body == null) {
let name = node.name.text;
if (!node.body && node.decorators?.length) {
const decorator = node.decorators.find((e) => e.name.text === "external");
if (decorator.args.length > 1 &&
decorator.args[1].kind === 16) {
name = decorator.args[1].value.toString();
}
}
const params = [];
for (const param of node.signature.parameters) {
const defaultValue = getDefaultValue(param);
params.push({
param: {
name: param.name.text,
type: {
name: uninitializedValue,
path: uninitializedValue,
},
optional: !!param.initializer,
},
defaultValue,
});
if (param.initializer)
param.initializer = null;
}
this.opt_fns.set(name, params);
}
}
const params = [];
for (const param of node.signature.parameters) {
const defaultValue = getDefaultValue(param);
params.push({
param: {
name: param.name.text,
type: {
name: "UNINITIALIZED_VALUE",
path: "UNINITIALIZED_VALUE",
},
optional: !!param.initializer,
},
defaultValue,
});
if (param.initializer)
param.initializer = null;
}
this.optional_fns.set(name, params);
}
}
visitSource(node) {
if (node.isLibrary)
return;
for (const stmt of node.statements) {
if (stmt.kind === 35) {
this.visitExportStatement(stmt);
}
}
for (const stmt of node.statements) {
if (stmt.kind === 55) {
this.visitFunctionDeclaration(stmt);
}
}
}
}

@@ -165,2 +162,27 @@ function getDefaultValue(param) {

}
function initDefaultValues(node) {
if (node.signature.parameters.find((v) => v.parameterKind === 1)) {
let body;
if (node.body.kind != 30) {
body = Node.createBlockStatement([node.body], node.range);
}
else {
body = node.body;
}
node.signature.parameters.push(Node.createParameter(0, Node.createIdentifierExpression("__SUPPLIED_PARAMS", node.range, false), Node.createNamedType(Node.createSimpleTypeName("u64", node.range), [], false, node.range), null, node.range));
let first = true;
for (let i = 0; i < node.signature.parameters.length; i++) {
const param = node.signature.parameters[i];
if (param.parameterKind != 1)
continue;
const stmt = Node.createIfStatement(Node.createBinaryExpression(76, Node.createParenthesizedExpression(Node.createBinaryExpression(92, first
? ((first = false),
Node.createIdentifierExpression("__SUPPLIED_PARAMS", node.range))
: Node.createParenthesizedExpression(Node.createBinaryExpression(90, Node.createIdentifierExpression("__SUPPLIED_PARAMS", node.range), newIntegerLiteral(i, node.range), node.range), node.range), newIntegerLiteral(1, node.range), node.range), node.range), newIntegerLiteral(0, node.range), node.range), Node.createExpressionStatement(Node.createBinaryExpression(101, Node.createIdentifierExpression(param.name.text, node.range, false), param.initializer, node.range)), null, node.range);
body.statements.unshift(stmt);
if (param.initializer)
param.initializer = null;
}
}
}
//# sourceMappingURL=multiparam.js.map

@@ -16,7 +16,7 @@ import { MultiParamGen } from "./multiparam.js";

toString() {
const optionalParams = MultiParamGen.SN?.opt_fns.get(this.name);
const optionalParams = MultiParamGen.SN?.optional_fns.get(this.name);
let params = "";
for (let i = 0; i < this.parameters.length; i++) {
const param = this.parameters[i];
const { defaultValue } = optionalParams[i] || {
const { defaultValue } = (optionalParams && optionalParams[i]) || {
defaultValue: null,

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