Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else if (isKeyword(token, keywords.global)) {
eatToken(); // keyword
if (token.type === tokens.openParen) {
eatToken(); // (
eatTokenOfType(tokens.keyword); // mut keyword
var valtype = token.value;
eatToken();
descr = t.globalType(valtype, "var");
eatTokenOfType(tokens.closeParen);
} else {
var _valtype = token.value;
eatTokenOfType(tokens.valtype);
descr = t.globalType(_valtype, "const");
}
} else if (isKeyword(token, keywords.memory) === true) {
eatToken(); // Keyword
descr = parseMemory();
} else if (isKeyword(token, keywords.table) === true) {
eatToken(); // Keyword
descr = parseTable();
} else {
throw new Error("Unsupported import type: " + tokenToString(token));
}
eatTokenOfType(tokens.closeParen);
return t.moduleImport(moduleName, name, descr);
}
if (typeof fnName === "undefined") {
throw new Error("Imported function must have a name");
}
descr = t.funcImportDescr(fnName, t.signature(fnParams, fnResult));
} else if (isKeyword(token, keywords.global)) {
eatToken(); // keyword
if (token.type === tokens.openParen) {
eatToken(); // (
eatTokenOfType(tokens.keyword); // mut keyword
var valtype = token.value;
eatToken();
descr = t.globalType(valtype, "var");
eatTokenOfType(tokens.closeParen);
} else {
var _valtype = token.value;
eatTokenOfType(tokens.valtype);
descr = t.globalType(_valtype, "const");
}
} else if (isKeyword(token, keywords.memory) === true) {
eatToken(); // Keyword
descr = parseMemory();
} else if (isKeyword(token, keywords.table) === true) {
eatToken(); // Keyword
descr = parseTable();
} else {
throw new Error("Unsupported import type: " + tokenToString(token));
var _name3 = token.value;
eatTokenOfType(tokens.string);
importing = {
module: moduleName,
name: _name3,
descr: undefined
};
eatTokenOfType(tokens.closeParen);
}
/**
* global_sig
*/
if (token.type === tokens.valtype) {
type = t.globalType(token.value, "const");
eatToken();
} else if (token.type === tokens.openParen) {
eatToken(); // (
if (isKeyword(token, keywords.mut) === false) {
throw function () {
return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Unsupported global type, expected mut" + ", given " + tokenToString(token));
}();
}
eatToken(); // mut
type = t.globalType(token.value, "var");
eatToken();
eatTokenOfType(tokens.closeParen);
}
if (typeof fnName === "undefined") {
throw new Error("Imported function must have a name");
}
descr = t.funcImportDescr(fnName, typeRef !== undefined ? typeRef : t.signature(fnParams, fnResult));
} else if (isKeyword(token, keywords.global)) {
eatToken(); // keyword
if (token.type === tokens.openParen) {
eatToken(); // (
eatTokenOfType(tokens.keyword); // mut keyword
var valtype = token.value;
eatToken();
descr = t.globalType(valtype, "var");
eatTokenOfType(tokens.closeParen);
} else {
var _valtype = token.value;
eatTokenOfType(tokens.valtype);
descr = t.globalType(_valtype, "const");
}
} else if (isKeyword(token, keywords.memory) === true) {
eatToken(); // Keyword
descr = parseMemory();
} else if (isKeyword(token, keywords.table) === true) {
eatToken(); // Keyword
descr = parseTable();
} else {
throw new Error("Unsupported import type: " + tokenToString(token));
descr = t.funcImportDescr(
fnName,
typeRef !== undefined ? typeRef : t.signature(fnParams, fnResult)
);
} else if (isKeyword(token, keywords.global)) {
eatToken(); // keyword
if (token.type === tokens.openParen) {
eatToken(); // (
eatTokenOfType(tokens.keyword); // mut keyword
const valtype = token.value;
eatToken();
descr = t.globalType(valtype, "var");
eatTokenOfType(tokens.closeParen);
} else {
const valtype = token.value;
eatTokenOfType(tokens.valtype);
descr = t.globalType(valtype, "const");
}
} else if (isKeyword(token, keywords.memory) === true) {
eatToken(); // Keyword
descr = parseMemory();
} else if (isKeyword(token, keywords.table) === true) {
eatToken(); // Keyword
descr = parseTable();
if (token.type === tokens.valtype) {
type = t.globalType(token.value, "const");
eatToken();
} else if (token.type === tokens.openParen) {
eatToken(); // (
if (isKeyword(token, keywords.mut) === false) {
throw function () {
return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Unsupported global type, expected mut" + ", given " + tokenToString(token));
}();
}
eatToken(); // mut
type = t.globalType(token.value, "var");
eatToken();
eatTokenOfType(tokens.closeParen);
}
if (type === undefined) {
throw function () {
return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Could not determine global type" + ", given " + tokenToString(token));
}();
}
maybeIgnoreComment();
var init = [];
if (importing != null) {
importing.descr = type;
init.push(t.moduleImport(importing.module, importing.name, importing.descr));
dump([valtypeByte], type);
if (typeof type === "undefined") {
throw new CompileError("Unknown valtype: " + toHex(valtypeByte));
}
var globalTypeByte = readByte();
eatBytes(1);
var globalType = constants.globalTypes[globalTypeByte];
dump([globalTypeByte], "global type (".concat(globalType, ")"));
if (typeof globalType === "undefined") {
throw new CompileError("Invalid mutability: " + toHex(globalTypeByte));
}
return t.globalType(type, globalType);
} // function parseNameModule() {
// const lenu32 = readVaruint32();
if (token.type === tokens.valtype) {
type = t.globalType(token.value, "const");
eatToken();
} else if (token.type === tokens.openParen) {
eatToken(); // (
if (isKeyword(token, keywords.mut) === false) {
throw function () {
return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Unsupported global type, expected mut" + ", given " + tokenToString(token));
}();
}
eatToken(); // mut
type = t.globalType(token.value, "var");
eatToken();
eatTokenOfType(tokens.closeParen);
}
if (type === undefined) {
throw function () {
return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Could not determine global type" + ", given " + tokenToString(token));
}();
}
maybeIgnoreComment();
var init = [];
if (importing != null) {
importing.descr = type;
init.push(t.moduleImport(importing.module, importing.name, importing.descr));
var _name3 = token.value;
eatTokenOfType(tokens.string);
importing = {
module: moduleName,
name: _name3,
descr: undefined
};
eatTokenOfType(tokens.closeParen);
}
/**
* global_sig
*/
if (token.type === tokens.valtype) {
type = t.globalType(token.value, "const");
eatToken();
} else if (token.type === tokens.openParen) {
eatToken(); // (
if (isKeyword(token, keywords.mut) === false) {
throw function () {
return new Error("\n" + (0, _helperCodeFrame.codeFrameFromSource)(source, token.loc) + "\n" + "Unsupported global type, expected mut" + ", given " + tokenToString(token));
}();
}
eatToken(); // mut
type = t.globalType(token.value, "var");
eatToken();
eatTokenOfType(tokens.closeParen);
}
dump([valtypeByte], type);
if (typeof type === "undefined") {
throw new _helperApiError.CompileError("Unknown valtype: " + toHex(valtypeByte));
}
var globalTypeByte = readByte();
eatBytes(1);
var globalType = globalTypes[globalTypeByte];
dump([globalTypeByte], "global type (".concat(globalType, ")"));
if (typeof globalType === "undefined") {
throw new _helperApiError.CompileError("Invalid mutability: " + toHex(globalTypeByte));
}
return t.globalType(type, globalType);
}