@webassemblyjs/wast-parser
Advanced tools
Comparing version 1.5.2 to 1.5.3
@@ -41,2 +41,9 @@ "use strict"; | ||
function identifierFromToken(token) { | ||
var _token$loc = token.loc, | ||
end = _token$loc.end, | ||
start = _token$loc.start; | ||
return t.withLoc(t.identifier(token.value), end, start); | ||
} | ||
function parse(tokensList, source) { | ||
@@ -57,2 +64,17 @@ var current = 0; | ||
function getEndLoc() { | ||
var currentToken = token; | ||
if (typeof currentToken === "undefined") { | ||
var lastToken = tokensList[tokensList.length - 1]; | ||
currentToken = lastToken; | ||
} | ||
return currentToken.loc.end; | ||
} | ||
function getStartLoc() { | ||
return token.loc.start; | ||
} | ||
function eatTokenOfType(type) { | ||
@@ -70,3 +92,3 @@ if (token.type !== type) { | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
index = identifierFromToken(token); | ||
eatToken(); | ||
@@ -104,3 +126,3 @@ } else if (token.type === tokens.number) { | ||
function maybeIgnoreComment() { | ||
if (token.type === tokens.comment) { | ||
while (token.type === tokens.comment) { | ||
eatToken(); | ||
@@ -125,3 +147,3 @@ } | ||
var id = t.identifier(getUniqueName("memory")); | ||
var limits = t.limits(0); | ||
var limits = t.limit(0); | ||
@@ -148,3 +170,3 @@ if (token.type === tokens.string || token.type === tokens.identifier) { | ||
limits = t.limits(stringInitializer.length); | ||
limits = t.limit(stringInitializer.length); | ||
eatTokenOfType(tokens.closeParen); | ||
@@ -184,3 +206,3 @@ } | ||
if (token.type === tokens.number) { | ||
limits = t.limits((0, _numberLiterals.parse32I)(token.value)); | ||
limits = t.limit((0, _numberLiterals.parse32I)(token.value)); | ||
eatToken(); | ||
@@ -229,3 +251,3 @@ | ||
var numberLiteral = t.numberLiteral(token.value, "i32"); | ||
var numberLiteral = t.numberLiteralFromRaw(token.value, "i32"); | ||
offset = t.objectInstruction("const", "i32", [numberLiteral]); | ||
@@ -237,3 +259,3 @@ eatToken(); | ||
var _numberLiteral = t.numberLiteral(token.value, "i32"); | ||
var _numberLiteral = t.numberLiteralFromRaw(token.value, "i32"); | ||
@@ -270,3 +292,3 @@ offset = t.instruction("get_global", [_numberLiteral]); | ||
var name = t.identifier(getUniqueName("table")); | ||
var limit = t.limits(0); | ||
var limit = t.limit(0); | ||
var elemIndices = []; | ||
@@ -276,3 +298,3 @@ var elemType = "anyfunc"; | ||
if (token.type === tokens.string || token.type === tokens.identifier) { | ||
name = t.identifier(token.value); | ||
name = identifierFromToken(token); | ||
eatToken(); | ||
@@ -334,5 +356,5 @@ } else { | ||
eatToken(); | ||
limit = t.limits(min, max); | ||
limit = t.limit(min, max); | ||
} else { | ||
limit = t.limits(min); | ||
limit = t.limit(min); | ||
} | ||
@@ -395,3 +417,3 @@ | ||
if (token.type === tokens.identifier) { | ||
fnName = t.identifier(token.value); | ||
fnName = identifierFromToken(token); | ||
eatToken(); | ||
@@ -457,3 +479,2 @@ } | ||
eatTokenOfType(tokens.closeParen); | ||
eatTokenOfType(tokens.closeParen); | ||
return t.moduleImport(moduleName, name, descr); | ||
@@ -479,3 +500,3 @@ } | ||
if (token.type === tokens.identifier) { | ||
label = t.identifier(token.value); | ||
label = identifierFromToken(token); | ||
eatToken(); | ||
@@ -538,3 +559,3 @@ } else { | ||
if (token.type === tokens.identifier) { | ||
label = t.identifier(token.value); | ||
label = identifierFromToken(token); | ||
eatToken(); | ||
@@ -664,3 +685,3 @@ } else { | ||
if (token.type === tokens.identifier) { | ||
label = t.identifier(token.value); | ||
label = identifierFromToken(token); | ||
eatToken(); | ||
@@ -769,29 +790,32 @@ } else { | ||
eatToken(); | ||
var moduleExportDescr = parseModuleExportDescr(); | ||
return t.moduleExport(name, moduleExportDescr); | ||
} | ||
function parseModuleExportDescr() { | ||
var startLoc = getStartLoc(); | ||
var type = ""; | ||
var index; | ||
eatTokenOfType(tokens.openParen); | ||
if (token.type === tokens.openParen) { | ||
eatToken(); | ||
while (token.type !== tokens.closeParen) { | ||
if (isKeyword(token, keywords.func)) { | ||
type = "Func"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "func"); | ||
} else if (isKeyword(token, keywords.table)) { | ||
type = "Table"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "table"); | ||
} else if (isKeyword(token, keywords.global)) { | ||
type = "Global"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "global"); | ||
} else if (isKeyword(token, keywords.memory)) { | ||
type = "Memory"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "memory"); | ||
} | ||
while (token.type !== tokens.closeParen) { | ||
if (isKeyword(token, keywords.func)) { | ||
type = "Func"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "func"); | ||
} else if (isKeyword(token, keywords.table)) { | ||
type = "Table"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "table"); | ||
} else if (isKeyword(token, keywords.global)) { | ||
type = "Global"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "global"); | ||
} else if (isKeyword(token, keywords.memory)) { | ||
type = "Memory"; | ||
eatToken(); | ||
index = parseExportIdentifier(token, "memory"); | ||
} | ||
eatToken(); | ||
} | ||
@@ -807,4 +831,6 @@ | ||
var node = t.moduleExportDescr(type, index); | ||
var endLoc = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return t.moduleExport(name, t.moduleExportDescr(type, index)); | ||
return t.withLoc(node, endLoc, startLoc); | ||
} | ||
@@ -840,3 +866,2 @@ | ||
maybeIgnoreComment(); | ||
maybeIgnoreComment(); | ||
} | ||
@@ -893,3 +918,3 @@ | ||
if (token.type === tokens.number) { | ||
value = t.numberLiteral(token.value); | ||
value = t.numberLiteralFromRaw(token.value); | ||
} else { | ||
@@ -909,3 +934,3 @@ throw new Error("Unexpected type for argument: " + token.type); | ||
// Handle locals | ||
args.push(t.valtype(token.value)); | ||
args.push(t.valtypeLiteral(token.value)); | ||
eatToken(); | ||
@@ -918,4 +943,4 @@ } else if (token.type === tokens.string) { | ||
// https://github.com/xtuc/webassemblyjs/pull/129 is a good start | ||
// $FlowIgnore | ||
t.numberLiteral(token.value, signature[signaturePtr++] || "f64")); | ||
t.numberLiteralFromRaw(token.value, // $FlowIgnore | ||
signature[signaturePtr++] || "f64")); | ||
eatToken(); | ||
@@ -930,2 +955,3 @@ } else if (token.type === tokens.openParen) { | ||
) { | ||
// $FlowIgnore | ||
args.push(parseFuncInstr()); | ||
@@ -1029,3 +1055,3 @@ } else { | ||
function parseFuncInstr() { | ||
var startLoc = token.loc.start; | ||
var startLoc = getStartLoc(); | ||
/** | ||
@@ -1096,3 +1122,3 @@ * A simple instruction | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
index = identifierFromToken(token); | ||
eatToken(); | ||
@@ -1169,3 +1195,3 @@ } else if (token.type === tokens.number) { | ||
if (token.type === tokens.identifier) { | ||
fnName = t.identifier(token.value); | ||
fnName = identifierFromToken(token); | ||
eatToken(); | ||
@@ -1258,3 +1284,3 @@ } else { | ||
if (token.type === tokens.identifier) { | ||
id = t.identifier(token.value); | ||
id = identifierFromToken(token); | ||
eatToken(); | ||
@@ -1331,6 +1357,6 @@ } | ||
if (token.type === tokens.identifier) { | ||
ref = t.identifier(token.value); | ||
ref = identifierFromToken(token); | ||
eatToken(); | ||
} else if (token.type === tokens.number) { | ||
ref = t.numberLiteral(token.value); | ||
ref = t.numberLiteralFromRaw(token.value); | ||
eatToken(); | ||
@@ -1363,3 +1389,3 @@ } | ||
if (token.type === tokens.identifier) { | ||
name = t.identifier(token.value); | ||
name = identifierFromToken(token); | ||
eatToken(); | ||
@@ -1527,3 +1553,3 @@ } else { | ||
if (token.type === tokens.identifier) { | ||
tableIndex = t.identifier(token.value); | ||
tableIndex = identifierFromToken(token); | ||
eatToken(); | ||
@@ -1589,3 +1615,3 @@ } | ||
if (token.type === tokens.identifier) { | ||
var index = t.identifier(token.value); | ||
var index = identifierFromToken(token); | ||
eatToken(); | ||
@@ -1607,6 +1633,11 @@ return t.start(index); | ||
eatToken(); | ||
var startLoc = getStartLoc(); | ||
if (isKeyword(token, keywords.export)) { | ||
eatToken(); | ||
return parseExport(); | ||
var node = parseExport(); | ||
var _endLoc2 = getEndLoc(); | ||
return t.withLoc(node, _endLoc2, startLoc); | ||
} | ||
@@ -1616,3 +1647,8 @@ | ||
eatToken(); | ||
return parseLoop(); | ||
var _node = parseLoop(); | ||
var _endLoc3 = getEndLoc(); | ||
return t.withLoc(_node, _endLoc3, startLoc); | ||
} | ||
@@ -1622,5 +1658,9 @@ | ||
eatToken(); | ||
var node = parseFunc(); | ||
var _node2 = parseFunc(); | ||
var _endLoc4 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return node; | ||
return t.withLoc(_node2, _endLoc4, startLoc); | ||
} | ||
@@ -1630,3 +1670,8 @@ | ||
eatToken(); | ||
return parseModule(); | ||
var _node3 = parseModule(); | ||
var _endLoc5 = getEndLoc(); | ||
return t.withLoc(_node3, _endLoc5, startLoc); | ||
} | ||
@@ -1636,3 +1681,9 @@ | ||
eatToken(); | ||
return parseImport(); | ||
var _node4 = parseImport(); | ||
var _endLoc6 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return t.withLoc(_node4, _endLoc6, startLoc); | ||
} | ||
@@ -1643,6 +1694,8 @@ | ||
var _node = parseBlock(); | ||
var _node5 = parseBlock(); | ||
var _endLoc7 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node; | ||
return t.withLoc(_node5, _endLoc7, startLoc); | ||
} | ||
@@ -1653,6 +1706,8 @@ | ||
var _node2 = parseMemory(); | ||
var _node6 = parseMemory(); | ||
var _endLoc8 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node2; | ||
return t.withLoc(_node6, _endLoc8, startLoc); | ||
} | ||
@@ -1663,6 +1718,8 @@ | ||
var _node3 = parseData(); | ||
var _node7 = parseData(); | ||
var _endLoc9 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node3; | ||
return t.withLoc(_node7, _endLoc9, startLoc); | ||
} | ||
@@ -1673,6 +1730,8 @@ | ||
var _node4 = parseTable(); | ||
var _node8 = parseTable(); | ||
var _endLoc10 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node4; | ||
return t.withLoc(_node8, _endLoc10, startLoc); | ||
} | ||
@@ -1683,6 +1742,8 @@ | ||
var _node5 = parseGlobal(); | ||
var _node9 = parseGlobal(); | ||
var _endLoc11 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node5; | ||
return t.withLoc(_node9, _endLoc11, startLoc); | ||
} | ||
@@ -1693,6 +1754,8 @@ | ||
var _node6 = parseType(); | ||
var _node10 = parseType(); | ||
var _endLoc12 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node6; | ||
return t.withLoc(_node10, _endLoc12, startLoc); | ||
} | ||
@@ -1703,6 +1766,8 @@ | ||
var _node7 = parseStart(); | ||
var _node11 = parseStart(); | ||
var _endLoc13 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node7; | ||
return t.withLoc(_node11, _endLoc13, startLoc); | ||
} | ||
@@ -1713,13 +1778,16 @@ | ||
var _node8 = parseElem(); | ||
var _node12 = parseElem(); | ||
var _endLoc14 = getEndLoc(); | ||
eatTokenOfType(tokens.closeParen); | ||
return _node8; | ||
return t.withLoc(_node12, _endLoc14, startLoc); | ||
} | ||
var instruction = parseFuncInstr(); | ||
var endLoc = getEndLoc(); | ||
if (_typeof(instruction) === "object") { | ||
eatTokenOfType(tokens.closeParen); | ||
return instruction; | ||
return t.withLoc(instruction, endLoc, startLoc); | ||
} | ||
@@ -1729,8 +1797,13 @@ } | ||
if (token.type === tokens.comment) { | ||
var _startLoc = getStartLoc(); | ||
var builder = token.opts.type === "leading" ? t.leadingComment : t.blockComment; | ||
var _node9 = builder(token.value); | ||
var _node13 = builder(token.value); | ||
eatToken(); | ||
return _node9; | ||
eatToken(); // comment | ||
var _endLoc15 = getEndLoc(); | ||
return t.withLoc(_node13, _endLoc15, _startLoc); | ||
} | ||
@@ -1737,0 +1810,0 @@ |
@@ -147,3 +147,3 @@ "use strict"; | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var startColumn = opts.startColumn || column; | ||
var startColumn = opts.startColumn || column - String(v).length; | ||
delete opts.startColumn; | ||
@@ -212,2 +212,3 @@ var endColumn = opts.endColumn || startColumn + String(v).length - 1; | ||
if (char === ";" && lookahead() === ";") { | ||
var startColumn = column; | ||
eatCharacter(2); | ||
@@ -225,4 +226,7 @@ var text = ""; | ||
var endColumn = column; | ||
pushCommentToken(text, { | ||
type: "leading" | ||
type: "leading", | ||
startColumn: startColumn, | ||
endColumn: endColumn | ||
}); | ||
@@ -234,2 +238,3 @@ continue; | ||
if (char === "(" && lookahead() === ";") { | ||
var _startColumn = column; | ||
eatCharacter(2); | ||
@@ -255,4 +260,7 @@ var _text = ""; // ;) | ||
var _endColumn = column; | ||
pushCommentToken(_text, { | ||
type: "block" | ||
type: "block", | ||
startColumn: _startColumn, | ||
endColumn: _endColumn | ||
}); | ||
@@ -293,2 +301,3 @@ continue; | ||
if (char === "$") { | ||
var _startColumn2 = column; | ||
eatCharacter(); | ||
@@ -302,3 +311,7 @@ var value = ""; | ||
pushIdentifierToken(value); | ||
var _endColumn2 = column; | ||
pushIdentifierToken(value, { | ||
startColumn: _startColumn2, | ||
endColumn: _endColumn2 | ||
}); | ||
continue; | ||
@@ -308,3 +321,3 @@ } | ||
if (NUMBERS.test(char) || NUMBER_KEYWORDS.test(lookahead(3, 0)) || char === "-" || char === "+") { | ||
var startColumn = column; | ||
var _startColumn3 = column; | ||
@@ -319,3 +332,3 @@ var _value = numberLiteralFSM.run(input.slice(current)); | ||
pushNumberToken(_value, { | ||
startColumn: startColumn | ||
startColumn: _startColumn3 | ||
}); | ||
@@ -333,3 +346,3 @@ eatCharacter(_value.length); | ||
if (char === '"') { | ||
var _startColumn = column; | ||
var _startColumn4 = column; | ||
var _value2 = ""; | ||
@@ -350,6 +363,6 @@ eatCharacter(); // " | ||
var endColumn = column; | ||
var _endColumn3 = column; | ||
pushStringToken(_value2, { | ||
startColumn: _startColumn, | ||
endColumn: endColumn | ||
startColumn: _startColumn4, | ||
endColumn: _endColumn3 | ||
}); | ||
@@ -361,3 +374,3 @@ continue; | ||
var _value3 = ""; | ||
var _startColumn2 = column; | ||
var _startColumn5 = column; | ||
@@ -378,3 +391,3 @@ while (char && LETTERS.test(char)) { | ||
pushValtypeToken(_value3, { | ||
startColumn: _startColumn2 | ||
startColumn: _startColumn5 | ||
}); | ||
@@ -410,3 +423,3 @@ } else { | ||
pushKeywordToken(_value3, { | ||
startColumn: _startColumn2 | ||
startColumn: _startColumn5 | ||
}); | ||
@@ -422,3 +435,3 @@ continue; | ||
pushValtypeToken(_value3, { | ||
startColumn: _startColumn2 | ||
startColumn: _startColumn5 | ||
}); | ||
@@ -433,3 +446,3 @@ continue; | ||
pushNameToken(_value3, { | ||
startColumn: _startColumn2 | ||
startColumn: _startColumn5 | ||
}); | ||
@@ -436,0 +449,0 @@ continue; |
{ | ||
"name": "@webassemblyjs/wast-parser", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"description": "WebAssembly text format parser", | ||
@@ -20,11 +20,11 @@ "keywords": [ | ||
"dependencies": { | ||
"@webassemblyjs/ast": "1.5.2", | ||
"@webassemblyjs/floating-point-hex-parser": "1.5.2", | ||
"@webassemblyjs/helper-code-frame": "1.5.2", | ||
"@webassemblyjs/helper-fsm": "1.5.2", | ||
"@webassemblyjs/ast": "1.5.3", | ||
"@webassemblyjs/floating-point-hex-parser": "1.5.3", | ||
"@webassemblyjs/helper-code-frame": "1.5.3", | ||
"@webassemblyjs/helper-fsm": "1.5.3", | ||
"long": "^3.2.0", | ||
"webassemblyjs": "1.5.2" | ||
"webassemblyjs": "1.5.3" | ||
}, | ||
"devDependencies": { | ||
"@webassemblyjs/helper-test-framework": "1.5.2" | ||
"@webassemblyjs/helper-test-framework": "1.5.3" | ||
}, | ||
@@ -31,0 +31,0 @@ "repository": { |
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
67685
1985
+ Added@webassemblyjs/ast@1.5.3(transitive)
+ Added@webassemblyjs/floating-point-hex-parser@1.5.3(transitive)
+ Added@webassemblyjs/helper-code-frame@1.5.3(transitive)
+ Added@webassemblyjs/helper-fsm@1.5.3(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.5.3(transitive)
+ Added@webassemblyjs/leb128@1.5.3(transitive)
+ Added@webassemblyjs/validation@1.5.3(transitive)
+ Added@webassemblyjs/wasm-parser@1.5.3(transitive)
+ Added@webassemblyjs/wast-printer@1.5.3(transitive)
+ Addedwebassemblyjs@1.5.3(transitive)
- Removed@webassemblyjs/ast@1.5.2(transitive)
- Removed@webassemblyjs/floating-point-hex-parser@1.5.2(transitive)
- Removed@webassemblyjs/helper-code-frame@1.5.2(transitive)
- Removed@webassemblyjs/helper-fsm@1.5.2(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.5.2(transitive)
- Removed@webassemblyjs/leb128@1.5.2(transitive)
- Removed@webassemblyjs/validation@1.5.2(transitive)
- Removed@webassemblyjs/wasm-parser@1.5.2(transitive)
- Removed@webassemblyjs/wast-printer@1.5.2(transitive)
- Removedwebassemblyjs@1.5.2(transitive)
Updated@webassemblyjs/ast@1.5.3
Updatedwebassemblyjs@1.5.3