@webassemblyjs/wast-parser
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -49,10 +49,3 @@ "use strict"; | ||
var current = 0; | ||
var inc = 0; | ||
function getUniqueName() { | ||
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp"; | ||
inc++; | ||
return prefix + "_" + inc; | ||
} | ||
var getUniqueName = t.getUniqueNameGenerator(); | ||
var state = { | ||
@@ -79,2 +72,17 @@ registredExportedElements: [] | ||
function parseExportIdentifier(token, prefix) { | ||
var index; | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} else if (token.type === tokens.number) { | ||
index = t.identifier(prefix + "_" + token.value); | ||
index = t.withRaw(index, String(token.value)); | ||
eatToken(); | ||
} | ||
return index; | ||
} | ||
function lookaheadAndCheck() { | ||
@@ -127,2 +135,4 @@ var len = arguments.length; | ||
eatToken(); | ||
} else { | ||
id = t.withRaw(id, ""); // preserve anonymous | ||
} | ||
@@ -258,3 +268,3 @@ /** | ||
function parseTable() { | ||
var name = t.identifier(getUniqueName()); | ||
var name = t.identifier(getUniqueName("table")); | ||
var limit = t.limits(0); | ||
@@ -267,2 +277,4 @@ var elemIndices = []; | ||
eatToken(); | ||
} else { | ||
name = t.withRaw(name, ""); // preserve anonymous | ||
} | ||
@@ -446,3 +458,3 @@ | ||
var label = t.identifier(getUniqueName("block")); | ||
var blockResult; | ||
var blockResult = null; | ||
var instr = []; | ||
@@ -453,2 +465,4 @@ | ||
eatToken(); | ||
} else { | ||
label = t.withRaw(label, ""); // preserve anonymous | ||
} | ||
@@ -505,2 +519,4 @@ | ||
eatToken(); | ||
} else { | ||
label = t.withRaw(label, ""); // preserve anonymous | ||
} | ||
@@ -611,2 +627,4 @@ | ||
eatToken(); | ||
} else { | ||
label = t.withRaw(label, ""); // preserve anonymous | ||
} | ||
@@ -667,57 +685,15 @@ | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
} | ||
if (isKeyword(token, keywords.table)) { | ||
index = parseExportIdentifier(token, "func"); | ||
} else if (isKeyword(token, keywords.table)) { | ||
type = "Table"; | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
} | ||
if (isKeyword(token, keywords.global)) { | ||
index = parseExportIdentifier(token, "table"); | ||
} else if (isKeyword(token, keywords.global)) { | ||
type = "Global"; | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
} | ||
if (isKeyword(token, keywords.memory)) { | ||
index = parseExportIdentifier(token, "global"); | ||
} else if (isKeyword(token, keywords.memory)) { | ||
type = "Memory"; | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
index = parseExportIdentifier(token, "memory"); | ||
} | ||
@@ -1128,2 +1104,4 @@ | ||
eatToken(); | ||
} else { | ||
fnName = t.withRaw(fnName, ""); // preserve anonymous | ||
} | ||
@@ -1284,2 +1262,4 @@ | ||
eatToken(); | ||
} else { | ||
name = t.withRaw(name, ""); // preserve anonymous | ||
} | ||
@@ -1286,0 +1266,0 @@ /** |
@@ -16,3 +16,3 @@ "use strict"; | ||
var parseHexFloat = require("webassembly-floating-point-hex-parser"); | ||
var parseHexFloat = require("@webassemblyjs/floating-point-hex-parser"); | ||
@@ -19,0 +19,0 @@ var _require = require("webassemblyjs/lib/errors"), |
@@ -1,4 +0,7 @@ | ||
var _require = require("@babel/code-frame"), | ||
codeFrameColumns = _require.codeFrameColumns; | ||
"use strict"; | ||
var _codeFrame = require("@babel/code-frame"); | ||
var _helperFsm = require("@webassemblyjs/helper-fsm"); | ||
function showCodeFrame(source, line, column) { | ||
@@ -11,3 +14,3 @@ var loc = { | ||
}; | ||
var out = codeFrameColumns(source, loc); | ||
var out = (0, _codeFrame.codeFrameColumns)(source, loc); | ||
process.stdout.write(out + "\n"); | ||
@@ -17,2 +20,3 @@ } | ||
var WHITESPACE = /\s/; | ||
var PARENS = /\(|\)/; | ||
var LETTERS = /[a-z0-9_/]/i; | ||
@@ -23,3 +27,2 @@ var idchar = /[a-z0-9!#$%&*+./:<=>?@\\[\]^_`|~-]/i; | ||
var NUMBER_KEYWORDS = /nan|inf/; | ||
var HEX_NUMBERS = /[0-9|A-F|a-f|_|.|p|P|-]/; | ||
@@ -89,3 +92,41 @@ function isNewLine(char) { | ||
}; | ||
var NUMERIC_SEPARATOR = "_"; | ||
/** | ||
* Build the FSM for number literals | ||
*/ | ||
var numberLiteralFSM = new _helperFsm.FSM({ | ||
START: [(0, _helperFsm.makeTransition)(/-|\+/, "START"), (0, _helperFsm.makeTransition)(/nan:0x/, "NAN_HEX", { | ||
n: 6 | ||
}), (0, _helperFsm.makeTransition)(/nan|inf/, "STOP", { | ||
n: 3 | ||
}), (0, _helperFsm.makeTransition)(/0x/, "HEX", { | ||
n: 2 | ||
}), (0, _helperFsm.makeTransition)(/[0-9]/, "DEC"), (0, _helperFsm.makeTransition)(/\./, "DEC_FRAC")], | ||
DEC_FRAC: [(0, _helperFsm.makeTransition)(/[0-9]/, "DEC_FRAC", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}), (0, _helperFsm.makeTransition)(/e|E/, "DEC_SIGNED_EXP")], | ||
DEC: [(0, _helperFsm.makeTransition)(/[0-9]/, "DEC", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}), (0, _helperFsm.makeTransition)(/\./, "DEC_FRAC"), (0, _helperFsm.makeTransition)(/e|E/, "DEC_SIGNED_EXP")], | ||
DEC_SIGNED_EXP: [(0, _helperFsm.makeTransition)(/\+|-/, "DEC_EXP"), (0, _helperFsm.makeTransition)(/[0-9]/, "DEC_EXP")], | ||
DEC_EXP: [(0, _helperFsm.makeTransition)(/[0-9]/, "DEC_EXP", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
})], | ||
HEX: [(0, _helperFsm.makeTransition)(/[0-9|A-F|a-f]/, "HEX", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}), (0, _helperFsm.makeTransition)(/\./, "HEX_FRAC"), (0, _helperFsm.makeTransition)(/p|P/, "HEX_SIGNED_EXP")], | ||
HEX_FRAC: [(0, _helperFsm.makeTransition)(/[0-9|A-F|a-f]/, "HEX_FRAC", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}), (0, _helperFsm.makeTransition)(/p|P|/, "HEX_SIGNED_EXP")], | ||
HEX_SIGNED_EXP: [(0, _helperFsm.makeTransition)(/[0-9|+|-]/, "HEX_EXP")], | ||
HEX_EXP: [(0, _helperFsm.makeTransition)(/[0-9]/, "HEX_EXP", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
})], | ||
NAN_HEX: [(0, _helperFsm.makeTransition)(/[0-9|A-F|a-f]/, "NAN_HEX", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
})], | ||
STOP: [] | ||
}, "START", "STOP"); | ||
function tokenize(input) { | ||
@@ -99,5 +140,13 @@ var current = 0; | ||
/** | ||
* Throw an error in case the current character is invalid | ||
*/ | ||
function unexpectedCharacter() { | ||
throw new Error("Unexpected character \"".concat(char, "\"")); | ||
} | ||
/** | ||
* Creates a pushToken function for a given type | ||
*/ | ||
function pushToken(type) { | ||
@@ -133,4 +182,4 @@ return function (v) { | ||
* | ||
* @param int length How many characters to query. Default = 1 | ||
* @param int offset How many characters to skip forward from current one. Default = 1 | ||
* @param {number} length How many characters to query. Default = 1 | ||
* @param {number} offset How many characters to skip forward from current one. Default = 1 | ||
* | ||
@@ -145,22 +194,5 @@ */ | ||
/** | ||
* Can be used to look at the last few character(s). | ||
* | ||
* The default behavior `lookbehind()` simply returns the last character. | ||
* Letters are always returned in lowercase. | ||
* | ||
* @param int length How many characters to query. Default = 1 | ||
* @param int offset How many characters to skip back from current one. Default = 1 | ||
* | ||
*/ | ||
function lookbehind() { | ||
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
return input.substring(current - offset, current - offset + length).toLowerCase(); | ||
} | ||
/** | ||
* Advances the cursor in the input by a certain amount | ||
* | ||
* @param int amount How many characters to consume. Default = 1 | ||
* @param {number} amount How many characters to consume. Default = 1 | ||
*/ | ||
@@ -276,51 +308,15 @@ | ||
if (NUMBERS.test(char) || NUMBER_KEYWORDS.test(lookahead(3, 0)) || char === "-" || char === "+") { | ||
var _value = ""; | ||
var startColumn = column; | ||
var _value = numberLiteralFSM.run(input.slice(current)); | ||
if (char === "-" || char === "+") { | ||
_value += char; | ||
eatCharacter(); | ||
if (_value === "") { | ||
unexpectedCharacter(); | ||
} | ||
if (NUMBER_KEYWORDS.test(lookahead(3, 0))) { | ||
var tokenLength = 3; | ||
pushNumberToken(_value); | ||
eatCharacter(_value.length); | ||
if (lookahead(4, 0) === "nan:") { | ||
tokenLength = 4; | ||
} else if (lookahead(3, 0) === "nan") { | ||
tokenLength = 3; | ||
} | ||
_value += input.substring(current, current + tokenLength); | ||
eatCharacter(tokenLength); | ||
if (char && !PARENS.test(char) && !WHITESPACE.test(char)) { | ||
unexpectedCharacter(); | ||
} | ||
var numberLiterals = NUMBERS; | ||
if (char === "0" && lookahead() === "x") { | ||
_value += "0x"; | ||
numberLiterals = HEX_NUMBERS; | ||
eatCharacter(2); | ||
} | ||
while (char !== undefined && numberLiterals.test(char) || lookbehind() === "p" && char === "+" || lookbehind() === "p" && char === "-" || lookbehind() === "e" && char === "+" || lookbehind() === "e" && char === "-" || _value.length > 0 && (char === "e" || char === "E")) { | ||
if (char === "p" && _value.includes("p")) { | ||
throw new Error('Unexpected character "p"'); | ||
} | ||
if (char === "." && _value.includes(".")) { | ||
throw new Error('Unexpected character "."'); | ||
} | ||
if (numberLiterals !== HEX_NUMBERS && char === "e" && _value.includes("e")) { | ||
throw new Error('Unexpected character "e"'); | ||
} | ||
_value += char; | ||
eatCharacter(); | ||
} | ||
pushNumberToken(_value, { | ||
startColumn: startColumn | ||
}); | ||
continue; | ||
@@ -335,3 +331,3 @@ } | ||
if (isNewLine(char)) { | ||
throw new Error("Unterminated string constant"); | ||
unexpectedCharacter(); | ||
} | ||
@@ -352,5 +348,5 @@ | ||
var _value3 = ""; | ||
var _startColumn = column; | ||
var startColumn = column; | ||
while (LETTERS.test(char)) { | ||
while (char && LETTERS.test(char)) { | ||
_value3 += char; | ||
@@ -369,3 +365,3 @@ eatCharacter(); | ||
pushValtypeToken(_value3, { | ||
startColumn: _startColumn | ||
startColumn: startColumn | ||
}); | ||
@@ -428,3 +424,3 @@ } else { | ||
showCodeFrame(input, line, column); | ||
throw new TypeError("Unexpected character \"".concat(char, "\"")); | ||
unexpectedCharacter(); | ||
} | ||
@@ -431,0 +427,0 @@ |
{ | ||
"name": "@webassemblyjs/wast-parser", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "WebAssembly text format parser", | ||
@@ -21,6 +21,7 @@ "keywords": [ | ||
"@babel/code-frame": "^7.0.0-beta.36", | ||
"@webassemblyjs/ast": "1.2.2", | ||
"@webassemblyjs/ast": "1.2.3", | ||
"@webassemblyjs/floating-point-hex-parser": "1.2.3", | ||
"@webassemblyjs/helper-fsm": "1.2.3", | ||
"long": "^3.2.0", | ||
"webassembly-floating-point-hex-parser": "0.1.2", | ||
"webassemblyjs": "1.2.2" | ||
"webassemblyjs": "1.2.3" | ||
}, | ||
@@ -27,0 +28,0 @@ "repository": { |
@@ -48,10 +48,4 @@ // @flow | ||
let current = 0; | ||
let inc = 0; | ||
const getUniqueName = t.getUniqueNameGenerator(); | ||
function getUniqueName(prefix: string = "temp"): string { | ||
inc++; | ||
return prefix + "_" + inc; | ||
} | ||
const state: ParserState = { | ||
@@ -85,2 +79,16 @@ registredExportedElements: [] | ||
function parseExportIdentifier(token: Object, prefix: string) { | ||
let index; | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} else if (token.type === tokens.number) { | ||
index = t.identifier(prefix + "_" + token.value); | ||
index = t.withRaw(index, String(token.value)); | ||
eatToken(); | ||
} | ||
return index; | ||
} | ||
function lookaheadAndCheck(...tokenTypes: Array<string>): boolean { | ||
@@ -133,2 +141,4 @@ const len = tokenTypes.length; | ||
eatToken(); | ||
} else { | ||
id = t.withRaw(id, ""); // preserve anonymous | ||
} | ||
@@ -259,3 +269,3 @@ | ||
function parseTable(): Table { | ||
let name = t.identifier(getUniqueName()); | ||
let name = t.identifier(getUniqueName("table")); | ||
@@ -269,2 +279,4 @@ let limit = t.limits(0); | ||
eatToken(); | ||
} else { | ||
name = t.withRaw(name, ""); // preserve anonymous | ||
} | ||
@@ -456,3 +468,3 @@ | ||
let label = t.identifier(getUniqueName("block")); | ||
let blockResult; | ||
let blockResult = null; | ||
const instr = []; | ||
@@ -463,2 +475,4 @@ | ||
eatToken(); | ||
} else { | ||
label = t.withRaw(label, ""); // preserve anonymous | ||
} | ||
@@ -521,2 +535,4 @@ | ||
eatToken(); | ||
} else { | ||
label = t.withRaw(label, ""); // preserve anonymous | ||
} | ||
@@ -650,2 +666,4 @@ | ||
eatToken(); | ||
} else { | ||
label = t.withRaw(label, ""); // preserve anonymous | ||
} | ||
@@ -711,62 +729,16 @@ | ||
type = "Func"; | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
} | ||
if (isKeyword(token, keywords.table)) { | ||
index = parseExportIdentifier(token, "func"); | ||
} else if (isKeyword(token, keywords.table)) { | ||
type = "Table"; | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
} | ||
if (isKeyword(token, keywords.global)) { | ||
index = parseExportIdentifier(token, "table"); | ||
} else if (isKeyword(token, keywords.global)) { | ||
type = "Global"; | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
} | ||
if (isKeyword(token, keywords.memory)) { | ||
index = parseExportIdentifier(token, "global"); | ||
} else if (isKeyword(token, keywords.memory)) { | ||
type = "Memory"; | ||
eatToken(); | ||
if (token.type === tokens.identifier) { | ||
index = t.identifier(token.value); | ||
eatToken(); | ||
} | ||
if (token.type === tokens.number) { | ||
index = t.indexLiteral(token.value); | ||
eatToken(); | ||
} | ||
index = parseExportIdentifier(token, "memory"); | ||
} | ||
@@ -1205,2 +1177,4 @@ | ||
eatToken(); | ||
} else { | ||
fnName = t.withRaw(fnName, ""); // preserve anonymous | ||
} | ||
@@ -1370,2 +1344,4 @@ | ||
eatToken(); | ||
} else { | ||
name = t.withRaw(name, ""); // preserve anonymous | ||
} | ||
@@ -1372,0 +1348,0 @@ |
// @flow | ||
const Long = require("long"); | ||
const parseHexFloat = require("webassembly-floating-point-hex-parser"); | ||
const parseHexFloat = require("@webassemblyjs/floating-point-hex-parser"); | ||
const { CompileError } = require("webassemblyjs/lib/errors"); | ||
@@ -5,0 +5,0 @@ |
// @flow | ||
const { codeFrameColumns } = require("@babel/code-frame"); | ||
import { codeFrameColumns } from "@babel/code-frame"; | ||
import { FSM, makeTransition } from "@webassemblyjs/helper-fsm"; | ||
@@ -16,2 +17,3 @@ function showCodeFrame(source: string, line: number, column: number) { | ||
const WHITESPACE = /\s/; | ||
const PARENS = /\(|\)/; | ||
const LETTERS = /[a-z0-9_/]/i; | ||
@@ -23,3 +25,2 @@ const idchar = /[a-z0-9!#$%&*+./:<=>?@\\[\]^_`|~-]/i; | ||
const NUMBER_KEYWORDS = /nan|inf/; | ||
const HEX_NUMBERS = /[0-9|A-F|a-f|_|.|p|P|-]/; | ||
@@ -91,4 +92,82 @@ function isNewLine(char: string): boolean { | ||
const NUMERIC_SEPARATOR = "_"; | ||
/** | ||
* Build the FSM for number literals | ||
*/ | ||
type NumberLiteralState = | ||
| "START" | ||
| "HEX" | ||
| "HEX_FRAC" | ||
| "NAN_HEX" | ||
| "DEC" | ||
| "DEC_EXP" | ||
| "DEC_FRAC" | ||
| "DEC_SIGNED_EXP" | ||
| "STOP" | ||
| "HEX_SIGNED_EXP" | ||
| "HEX_EXP"; | ||
const numberLiteralFSM: FSM<NumberLiteralState> = new FSM( | ||
{ | ||
START: [ | ||
makeTransition(/-|\+/, "START"), | ||
makeTransition(/nan:0x/, "NAN_HEX", { n: 6 }), | ||
makeTransition(/nan|inf/, "STOP", { n: 3 }), | ||
makeTransition(/0x/, "HEX", { n: 2 }), | ||
makeTransition(/[0-9]/, "DEC"), | ||
makeTransition(/\./, "DEC_FRAC") | ||
], | ||
DEC_FRAC: [ | ||
makeTransition(/[0-9]/, "DEC_FRAC", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}), | ||
makeTransition(/e|E/, "DEC_SIGNED_EXP") | ||
], | ||
DEC: [ | ||
makeTransition(/[0-9]/, "DEC", { allowedSeparator: NUMERIC_SEPARATOR }), | ||
makeTransition(/\./, "DEC_FRAC"), | ||
makeTransition(/e|E/, "DEC_SIGNED_EXP") | ||
], | ||
DEC_SIGNED_EXP: [ | ||
makeTransition(/\+|-/, "DEC_EXP"), | ||
makeTransition(/[0-9]/, "DEC_EXP") | ||
], | ||
DEC_EXP: [ | ||
makeTransition(/[0-9]/, "DEC_EXP", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}) | ||
], | ||
HEX: [ | ||
makeTransition(/[0-9|A-F|a-f]/, "HEX", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}), | ||
makeTransition(/\./, "HEX_FRAC"), | ||
makeTransition(/p|P/, "HEX_SIGNED_EXP") | ||
], | ||
HEX_FRAC: [ | ||
makeTransition(/[0-9|A-F|a-f]/, "HEX_FRAC", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}), | ||
makeTransition(/p|P|/, "HEX_SIGNED_EXP") | ||
], | ||
HEX_SIGNED_EXP: [makeTransition(/[0-9|+|-]/, "HEX_EXP")], | ||
HEX_EXP: [ | ||
makeTransition(/[0-9]/, "HEX_EXP", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}) | ||
], | ||
NAN_HEX: [ | ||
makeTransition(/[0-9|A-F|a-f]/, "NAN_HEX", { | ||
allowedSeparator: NUMERIC_SEPARATOR | ||
}) | ||
], | ||
STOP: [] | ||
}, | ||
"START", | ||
"STOP" | ||
); | ||
function tokenize(input: string) { | ||
let current = 0; | ||
let current: number = 0; | ||
let char = input[current]; | ||
@@ -103,2 +182,9 @@ | ||
/** | ||
* Throw an error in case the current character is invalid | ||
*/ | ||
function unexpectedCharacter() { | ||
throw new Error(`Unexpected character "${char}"`); | ||
} | ||
/** | ||
* Creates a pushToken function for a given type | ||
@@ -135,7 +221,7 @@ */ | ||
* | ||
* @param int length How many characters to query. Default = 1 | ||
* @param int offset How many characters to skip forward from current one. Default = 1 | ||
* @param {number} length How many characters to query. Default = 1 | ||
* @param {number} offset How many characters to skip forward from current one. Default = 1 | ||
* | ||
*/ | ||
function lookahead(length = 1, offset = 1) { | ||
function lookahead(length: number = 1, offset: number = 1): string { | ||
return input | ||
@@ -147,23 +233,7 @@ .substring(current + offset, current + offset + length) | ||
/** | ||
* Can be used to look at the last few character(s). | ||
* | ||
* The default behavior `lookbehind()` simply returns the last character. | ||
* Letters are always returned in lowercase. | ||
* | ||
* @param int length How many characters to query. Default = 1 | ||
* @param int offset How many characters to skip back from current one. Default = 1 | ||
* | ||
*/ | ||
function lookbehind(length = 1, offset = 1) { | ||
return input | ||
.substring(current - offset, current - offset + length) | ||
.toLowerCase(); | ||
} | ||
/** | ||
* Advances the cursor in the input by a certain amount | ||
* | ||
* @param int amount How many characters to consume. Default = 1 | ||
* @param {number} amount How many characters to consume. Default = 1 | ||
*/ | ||
function eatCharacter(amount = 1) { | ||
function eatCharacter(amount: number = 1): void { | ||
column += amount; | ||
@@ -288,59 +358,15 @@ current += amount; | ||
) { | ||
let value = ""; | ||
const startColumn = column; | ||
const value = numberLiteralFSM.run(input.slice(current)); | ||
if (char === "-" || char === "+") { | ||
value += char; | ||
eatCharacter(); | ||
if (value === "") { | ||
unexpectedCharacter(); | ||
} | ||
if (NUMBER_KEYWORDS.test(lookahead(3, 0))) { | ||
let tokenLength = 3; | ||
if (lookahead(4, 0) === "nan:") { | ||
tokenLength = 4; | ||
} else if (lookahead(3, 0) === "nan") { | ||
tokenLength = 3; | ||
} | ||
value += input.substring(current, current + tokenLength); | ||
eatCharacter(tokenLength); | ||
} | ||
pushNumberToken(value); | ||
eatCharacter(value.length); | ||
let numberLiterals = NUMBERS; | ||
if (char === "0" && lookahead() === "x") { | ||
value += "0x"; | ||
numberLiterals = HEX_NUMBERS; | ||
eatCharacter(2); | ||
if (char && !PARENS.test(char) && !WHITESPACE.test(char)) { | ||
unexpectedCharacter(); | ||
} | ||
while ( | ||
(char !== undefined && numberLiterals.test(char)) || | ||
(lookbehind() === "p" && char === "+") || | ||
(lookbehind() === "p" && char === "-") || | ||
(lookbehind() === "e" && char === "+") || | ||
(lookbehind() === "e" && char === "-") || | ||
(value.length > 0 && (char === "e" || char === "E")) | ||
) { | ||
if (char === "p" && value.includes("p")) { | ||
throw new Error('Unexpected character "p"'); | ||
} | ||
if (char === "." && value.includes(".")) { | ||
throw new Error('Unexpected character "."'); | ||
} | ||
if ( | ||
numberLiterals !== HEX_NUMBERS && | ||
char === "e" && | ||
value.includes("e") | ||
) { | ||
throw new Error('Unexpected character "e"'); | ||
} | ||
value += char; | ||
eatCharacter(); | ||
} | ||
pushNumberToken(value, { startColumn }); | ||
continue; | ||
@@ -356,3 +382,3 @@ } | ||
if (isNewLine(char)) { | ||
throw new Error("Unterminated string constant"); | ||
unexpectedCharacter(); | ||
} | ||
@@ -378,3 +404,3 @@ | ||
while (LETTERS.test(char)) { | ||
while (char && LETTERS.test(char)) { | ||
value += char; | ||
@@ -448,3 +474,3 @@ eatCharacter(); | ||
throw new TypeError(`Unexpected character "${char}"`); | ||
unexpectedCharacter(); | ||
} | ||
@@ -451,0 +477,0 @@ |
122014
3765
6
+ Added@webassemblyjs/ast@1.2.3(transitive)
+ Added@webassemblyjs/floating-point-hex-parser@1.2.3(transitive)
+ Added@webassemblyjs/helper-fsm@1.2.3(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.2.3(transitive)
+ Added@webassemblyjs/leb128@1.2.3(transitive)
+ Added@webassemblyjs/wasm-parser@1.2.3(transitive)
+ Addedwebassemblyjs@1.2.3(transitive)
- Removed@webassemblyjs/ast@1.2.2(transitive)
- Removed@webassemblyjs/helper-leb128@1.2.2(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.2.2(transitive)
- Removed@webassemblyjs/wasm-parser@1.2.2(transitive)
- Removedwebassembly-floating-point-hex-parser@0.1.2(transitive)
- Removedwebassemblyjs@1.2.2(transitive)
Updated@webassemblyjs/ast@1.2.3
Updatedwebassemblyjs@1.2.3