Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseMemory() {
var id = t.identifier(getUniqueName("memory"));
var limits = t.limit(0);
if (token.type === tokens.string || token.type === tokens.identifier) {
id = t.identifier(token.value);
eatToken();
} else {
id = t.withRaw(id, ""); // preserve anonymous
}
/**
* Maybe data
*/
if (lookaheadAndCheck(tokens.openParen, keywords.data)) {
eatToken(); // (
function parseTable() {
var name = t.identifier(getUniqueName("table"));
var limit = t.limit(0);
var elemIndices = [];
var elemType = "anyfunc";
if (token.type === tokens.string || token.type === tokens.identifier) {
name = identifierFromToken(token);
eatToken();
} else {
name = t.withRaw(name, ""); // preserve anonymous
}
while (token.type !== tokens.closeParen) {
/**
* Maybe export
*/
if (lookaheadAndCheck(tokens.openParen, keywords.elem)) {
function parseLoop(): LoopInstruction {
let label = t.identifier(getUniqueName("loop"));
let blockResult;
const instr = [];
if (token.type === tokens.identifier) {
label = identifierFromToken(token);
eatToken();
} else {
label = t.withRaw(label, ""); // preserve anonymous
}
while (token.type === tokens.openParen) {
eatToken();
if (lookaheadAndCheck(keywords.result) === true) {
eatToken();
var args = [];
if (instruction.name === "loop") {
var blocktypeByte = readByte();
eatBytes(1);
var blocktype = constants.blockTypes[blocktypeByte];
dump([blocktypeByte], "blocktype");
if (typeof blocktype === "undefined") {
throw new CompileError("Unexpected blocktype: " + toHex(blocktypeByte));
}
var instr = [];
parseInstructionBlock(instr); // preserve anonymous
var label = t.withRaw(t.identifier(getUniqueName("loop")), "");
var loopNode = t.loopInstruction(label, blocktype, instr);
code.push(loopNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "if") {
var _blocktypeByte = readByte();
eatBytes(1);
var _blocktype = constants.blockTypes[_blocktypeByte];
dump([_blocktypeByte], "blocktype");
if (typeof _blocktype === "undefined") {
throw new CompileError("Unexpected blocktype: " + toHex(_blocktypeByte));
}
var testIndex = t.withRaw(t.identifier(getUniqueName("if")), "");
var ifBody = [];
const name = token.value;
eatToken();
eatTokenOfType(tokens.openParen);
let descr;
if (isKeyword(token, keywords.func)) {
eatToken(); // keyword
const fnParams = [];
const fnResult = [];
let typeRef;
let fnName = t.identifier(getUniqueName("func"));
if (token.type === tokens.identifier) {
fnName = identifierFromToken(token);
eatToken();
}
while (token.type === tokens.openParen) {
eatToken();
if (lookaheadAndCheck(keywords.type) === true) {
eatToken();
typeRef = parseTypeReference();
} else if (lookaheadAndCheck(keywords.param) === true) {
eatToken();
}(function (_ref3) {
var node = _ref3.node;
if (node.descr.exportType === "Func") {
// $FlowIgnore
var nodeName = node.descr.id;
var index = nodeName.value;
var functionName = functionNames.find(function (f) {
return f.index === index;
});
if (functionName) {
node.descr.id = t.identifier(functionName.name);
}
}
}),
ModuleImport: function (_ModuleImport) {
while (token.type !== tokens.closeParen) {
if (lookaheadAndCheck(tokens.openParen, keywords.offset)) {
eatToken(); // (
eatToken(); // offset
while (token.type !== tokens.closeParen) {
eatTokenOfType(tokens.openParen);
offset.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
eatTokenOfType(tokens.closeParen);
} else if (token.type === tokens.identifier) {
funcs.push(t.identifier(token.value));
eatToken();
} else if (token.type === tokens.number) {
funcs.push(t.indexLiteral(token.value));
eatToken();
} else if (token.type === tokens.openParen) {
eatToken(); // (
offset.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
} else {
throw function () {
return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Unsupported token in elem" + ", given " + tokenToString(token));
}();
}
}
while (token.type !== tokens.closeParen) {
if (lookaheadAndCheck(tokens.openParen, keywords.offset)) {
eatToken(); // (
eatToken(); // offset
while (token.type !== tokens.closeParen) {
eatTokenOfType(tokens.openParen);
offset.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
eatTokenOfType(tokens.closeParen);
} else if (token.type === tokens.identifier) {
funcs.push(t.identifier(token.value));
eatToken();
} else if (token.type === tokens.number) {
funcs.push(t.indexLiteral(token.value));
eatToken();
} else if (token.type === tokens.openParen) {
eatToken(); // (
offset.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
} else {
throw createUnexpectedToken("Unsupported token in elem");
}
}
return t.elem(tableIndex, offset, funcs);
generate(module, dependencyTemplates, runtimeTemplate, type) {
let bin = module.originalSource().source();
const initFuncId = t.identifier(
Array.isArray(module.usedExports)
? Template.numberToIdentifer(module.usedExports.length)
: "__webpack_init__"
);
// parse it
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true,
ignoreCustomNameSection: true
});
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);
generate(module, dependencyTemplates, runtimeTemplate, type) {
let bin = module.originalSource().source();
const initFuncId = t.identifier(
Array.isArray(module.usedExports)
? Template.numberToIdentifer(module.usedExports.length)
: "__webpack_init__"
);
// parse it
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true,
ignoreCustomNameSection: true
});
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);