@webassemblyjs/wast-printer
Advanced tools
Comparing version 1.2.1 to 1.2.2
138
lib/index.js
@@ -57,2 +57,37 @@ "use strict"; | ||
function printTypeInstruction(n) { | ||
var out = ""; | ||
out += "("; | ||
out += "type"; | ||
out += space; | ||
if (n.id != null) { | ||
out += printIndex(n.id); | ||
out += space; | ||
} | ||
out += "("; | ||
out += "func"; | ||
n.functype.params.forEach(function (param) { | ||
out += space; | ||
out += "("; | ||
out += "param"; | ||
out += space; | ||
out += printFuncParam(param); | ||
out += ")"; | ||
}); | ||
n.functype.result.forEach(function (result) { | ||
out += space; | ||
out += "("; | ||
out += "result"; | ||
out += space; | ||
out += result; | ||
out += ")"; | ||
}); | ||
out += ")"; // func | ||
out += ")"; | ||
return out; | ||
} | ||
function printModule(n, depth) { | ||
@@ -78,36 +113,65 @@ var out = "("; | ||
if (field.type === "Func") { | ||
out += printFunc(field, depth + 1); | ||
} | ||
switch (field.type) { | ||
case "Func": | ||
{ | ||
out += printFunc(field, depth + 1); | ||
break; | ||
} | ||
if (field.type === "Table") { | ||
out += printTable(field); | ||
} | ||
case "TypeInstruction": | ||
{ | ||
out += printTypeInstruction(field); | ||
break; | ||
} | ||
if (field.type === "Global") { | ||
out += printGlobal(field, depth + 1); | ||
} | ||
case "Table": | ||
{ | ||
out += printTable(field); | ||
break; | ||
} | ||
if (field.type === "ModuleExport") { | ||
out += printModuleExport(field); | ||
} | ||
case "Global": | ||
{ | ||
out += printGlobal(field, depth + 1); | ||
break; | ||
} | ||
if (field.type === "ModuleImport") { | ||
out += printModuleImport(field); | ||
} | ||
case "ModuleExport": | ||
{ | ||
out += printModuleExport(field); | ||
break; | ||
} | ||
if (field.type === "Memory") { | ||
out += printMemory(field); | ||
} | ||
case "ModuleImport": | ||
{ | ||
out += printModuleImport(field); | ||
break; | ||
} | ||
if (field.type === "BlockComment") { | ||
out += printBlockComment(field); | ||
} | ||
case "Memory": | ||
{ | ||
out += printMemory(field); | ||
break; | ||
} | ||
if (field.type === "LeadingComment") { | ||
out += printLeadingComment(field); | ||
} | ||
case "BlockComment": | ||
{ | ||
out += printBlockComment(field); | ||
break; | ||
} | ||
if (field.type === "Start") { | ||
out += printStart(field); | ||
case "LeadingComment": | ||
{ | ||
out += printLeadingComment(field); | ||
break; | ||
} | ||
case "Start": | ||
{ | ||
out += printStart(field); | ||
break; | ||
} | ||
default: | ||
throw new Error("Unsupported node in printModule: " + String(field.type)); | ||
} | ||
@@ -569,2 +633,6 @@ | ||
function printLongNumberLiteral(n) { | ||
if (typeof n.raw === "string") { | ||
return n.raw; | ||
} | ||
var _n$value = n.value, | ||
@@ -577,2 +645,10 @@ low = _n$value.low, | ||
function printFloatLiteral(n) { | ||
if (typeof n.raw === "string") { | ||
return n.raw; | ||
} | ||
return String(n.value); | ||
} | ||
function printFuncInstructionArg(n) { | ||
@@ -597,2 +673,6 @@ var out = ""; | ||
if (n.type === "FloatLiteral") { | ||
out += printFloatLiteral(n); | ||
} | ||
if (n.type === "Instr") { | ||
@@ -606,3 +686,7 @@ out += printGenericInstruction(n); | ||
function printNumberLiteral(n) { | ||
return n.value + ""; | ||
if (typeof n.raw === "string") { | ||
return n.raw; | ||
} | ||
return String(n.value); | ||
} | ||
@@ -609,0 +693,0 @@ |
{ | ||
"name": "@webassemblyjs/wast-printer", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "WebAssembly text format printer", | ||
@@ -20,3 +20,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@webassemblyjs/wast-parser": "1.2.1", | ||
"@webassemblyjs/wast-parser": "1.2.2", | ||
"long": "^3.2.0" | ||
@@ -23,0 +23,0 @@ }, |
139
src/index.js
@@ -48,2 +48,46 @@ // @flow | ||
function printTypeInstruction(n: TypeInstruction): string { | ||
let out = ""; | ||
out += "("; | ||
out += "type"; | ||
out += space; | ||
if (n.id != null) { | ||
out += printIndex(n.id); | ||
out += space; | ||
} | ||
out += "("; | ||
out += "func"; | ||
n.functype.params.forEach(param => { | ||
out += space; | ||
out += "("; | ||
out += "param"; | ||
out += space; | ||
out += printFuncParam(param); | ||
out += ")"; | ||
}); | ||
n.functype.result.forEach(result => { | ||
out += space; | ||
out += "("; | ||
out += "result"; | ||
out += space; | ||
out += result; | ||
out += ")"; | ||
}); | ||
out += ")"; // func | ||
out += ")"; | ||
return out; | ||
} | ||
function printModule(n: Module, depth: number): string { | ||
@@ -69,36 +113,57 @@ let out = "("; | ||
if (field.type === "Func") { | ||
out += printFunc(field, depth + 1); | ||
} | ||
switch (field.type) { | ||
case "Func": { | ||
out += printFunc(field, depth + 1); | ||
break; | ||
} | ||
if (field.type === "Table") { | ||
out += printTable(field); | ||
} | ||
case "TypeInstruction": { | ||
out += printTypeInstruction(field); | ||
break; | ||
} | ||
if (field.type === "Global") { | ||
out += printGlobal(field, depth + 1); | ||
} | ||
case "Table": { | ||
out += printTable(field); | ||
break; | ||
} | ||
if (field.type === "ModuleExport") { | ||
out += printModuleExport(field); | ||
} | ||
case "Global": { | ||
out += printGlobal(field, depth + 1); | ||
break; | ||
} | ||
if (field.type === "ModuleImport") { | ||
out += printModuleImport(field); | ||
} | ||
case "ModuleExport": { | ||
out += printModuleExport(field); | ||
break; | ||
} | ||
if (field.type === "Memory") { | ||
out += printMemory(field); | ||
} | ||
case "ModuleImport": { | ||
out += printModuleImport(field); | ||
break; | ||
} | ||
if (field.type === "BlockComment") { | ||
out += printBlockComment(field); | ||
} | ||
case "Memory": { | ||
out += printMemory(field); | ||
break; | ||
} | ||
if (field.type === "LeadingComment") { | ||
out += printLeadingComment(field); | ||
} | ||
case "BlockComment": { | ||
out += printBlockComment(field); | ||
break; | ||
} | ||
if (field.type === "Start") { | ||
out += printStart(field); | ||
case "LeadingComment": { | ||
out += printLeadingComment(field); | ||
break; | ||
} | ||
case "Start": { | ||
out += printStart(field); | ||
break; | ||
} | ||
default: | ||
throw new Error( | ||
"Unsupported node in printModule: " + String(field.type) | ||
); | ||
} | ||
@@ -623,2 +688,6 @@ | ||
function printLongNumberLiteral(n: LongNumberLiteral): string { | ||
if (typeof n.raw === "string") { | ||
return n.raw; | ||
} | ||
const { low, high } = n.value; | ||
@@ -631,2 +700,10 @@ | ||
function printFloatLiteral(n: FloatLiteral): string { | ||
if (typeof n.raw === "string") { | ||
return n.raw; | ||
} | ||
return String(n.value); | ||
} | ||
function printFuncInstructionArg(n: Object): string { | ||
@@ -651,2 +728,6 @@ let out = ""; | ||
if (n.type === "FloatLiteral") { | ||
out += printFloatLiteral(n); | ||
} | ||
if (n.type === "Instr") { | ||
@@ -660,3 +741,7 @@ out += printGenericInstruction(n); | ||
function printNumberLiteral(n: NumberLiteral): string { | ||
return n.value + ""; | ||
if (typeof n.raw === "string") { | ||
return n.raw; | ||
} | ||
return String(n.value); | ||
} | ||
@@ -663,0 +748,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26900
1230
+ Added@webassemblyjs/ast@1.2.2(transitive)
+ Added@webassemblyjs/helper-leb128@1.2.2(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.2.2(transitive)
+ Added@webassemblyjs/wasm-parser@1.2.2(transitive)
+ Added@webassemblyjs/wast-parser@1.2.2(transitive)
+ Addedwebassemblyjs@1.2.2(transitive)
- Removed@webassemblyjs/ast@1.2.1(transitive)
- Removed@webassemblyjs/helper-leb128@1.2.1(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.2.1(transitive)
- Removed@webassemblyjs/wasm-parser@1.2.1(transitive)
- Removed@webassemblyjs/wast-parser@1.2.1(transitive)
- Removedwebassemblyjs@1.2.1(transitive)