Last active
June 27, 2021 09:06
-
-
Save nestarz/dcaa70b5ecac5fa7e66103658f7ff0b7 to your computer and use it in GitHub Desktop.
TS/JSX Transformer using Service Worker and Sucrase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
navigator.serviceWorker | |
.register("/sw.js") | |
.then(() => console.log("ServiceWorker registration successful")) | |
.catch((err) => console.log("ServiceWorker registration failed: ", err)); | |
</script> | |
<script type="module" src="index.jsx"></script> | |
<div id="root"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var commonjsGlobal = | |
typeof globalThis !== "undefined" | |
? globalThis | |
: typeof window !== "undefined" | |
? window | |
: typeof global !== "undefined" | |
? global | |
: typeof self !== "undefined" | |
? self | |
: {}; | |
function getDefaultExportFromCjs(x) { | |
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") | |
? x["default"] | |
: x; | |
} | |
function createCommonjsModule(fn, basedir, module) { | |
return ( | |
(module = { | |
path: basedir, | |
exports: {}, | |
require: function (path, base) { | |
return commonjsRequire( | |
path, | |
base === void 0 || base === null ? module.path : base | |
); | |
}, | |
}), | |
fn(module, module.exports), | |
module.exports | |
); | |
} | |
function commonjsRequire() { | |
throw new Error( | |
"Dynamic requires are not currently supported by @rollup/plugin-commonjs" | |
); | |
} | |
var global$1 = | |
typeof global !== "undefined" | |
? global | |
: typeof self !== "undefined" | |
? self | |
: typeof window !== "undefined" | |
? window | |
: {}; | |
var lookup = []; | |
var revLookup = []; | |
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array; | |
var inited = false; | |
function init() { | |
inited = true; | |
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | |
for (var i = 0, len = code.length; i < len; ++i) { | |
lookup[i] = code[i]; | |
revLookup[code.charCodeAt(i)] = i; | |
} | |
revLookup["-".charCodeAt(0)] = 62; | |
revLookup["_".charCodeAt(0)] = 63; | |
} | |
function toByteArray(b64) { | |
if (!inited) { | |
init(); | |
} | |
var i, j, l, tmp, placeHolders, arr; | |
var len = b64.length; | |
if (len % 4 > 0) { | |
throw new Error("Invalid string. Length must be a multiple of 4"); | |
} | |
placeHolders = b64[len - 2] === "=" ? 2 : b64[len - 1] === "=" ? 1 : 0; | |
arr = new Arr((len * 3) / 4 - placeHolders); | |
l = placeHolders > 0 ? len - 4 : len; | |
var L = 0; | |
for (i = 0, j = 0; i < l; i += 4, j += 3) { | |
tmp = | |
(revLookup[b64.charCodeAt(i)] << 18) | | |
(revLookup[b64.charCodeAt(i + 1)] << 12) | | |
(revLookup[b64.charCodeAt(i + 2)] << 6) | | |
revLookup[b64.charCodeAt(i + 3)]; | |
arr[L++] = (tmp >> 16) & 255; | |
arr[L++] = (tmp >> 8) & 255; | |
arr[L++] = tmp & 255; | |
} | |
if (placeHolders === 2) { | |
tmp = | |
(revLookup[b64.charCodeAt(i)] << 2) | | |
(revLookup[b64.charCodeAt(i + 1)] >> 4); | |
arr[L++] = tmp & 255; | |
} else if (placeHolders === 1) { | |
tmp = | |
(revLookup[b64.charCodeAt(i)] << 10) | | |
(revLookup[b64.charCodeAt(i + 1)] << 4) | | |
(revLookup[b64.charCodeAt(i + 2)] >> 2); | |
arr[L++] = (tmp >> 8) & 255; | |
arr[L++] = tmp & 255; | |
} | |
return arr; | |
} | |
function tripletToBase64(num) { | |
return ( | |
lookup[(num >> 18) & 63] + | |
lookup[(num >> 12) & 63] + | |
lookup[(num >> 6) & 63] + | |
lookup[num & 63] | |
); | |
} | |
function encodeChunk(uint8, start, end) { | |
var tmp; | |
var output = []; | |
for (var i = start; i < end; i += 3) { | |
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2]; | |
output.push(tripletToBase64(tmp)); | |
} | |
return output.join(""); | |
} | |
function fromByteArray(uint8) { | |
if (!inited) { | |
init(); | |
} | |
var tmp; | |
var len = uint8.length; | |
var extraBytes = len % 3; | |
var output = ""; | |
var parts = []; | |
var maxChunkLength = 16383; | |
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | |
parts.push( | |
encodeChunk( | |
uint8, | |
i, | |
i + maxChunkLength > len2 ? len2 : i + maxChunkLength | |
) | |
); | |
} | |
if (extraBytes === 1) { | |
tmp = uint8[len - 1]; | |
output += lookup[tmp >> 2]; | |
output += lookup[(tmp << 4) & 63]; | |
output += "=="; | |
} else if (extraBytes === 2) { | |
tmp = (uint8[len - 2] << 8) + uint8[len - 1]; | |
output += lookup[tmp >> 10]; | |
output += lookup[(tmp >> 4) & 63]; | |
output += lookup[(tmp << 2) & 63]; | |
output += "="; | |
} | |
parts.push(output); | |
return parts.join(""); | |
} | |
function read(buffer, offset, isLE, mLen, nBytes) { | |
var e, m; | |
var eLen = nBytes * 8 - mLen - 1; | |
var eMax = (1 << eLen) - 1; | |
var eBias = eMax >> 1; | |
var nBits = -7; | |
var i = isLE ? nBytes - 1 : 0; | |
var d = isLE ? -1 : 1; | |
var s = buffer[offset + i]; | |
i += d; | |
e = s & ((1 << -nBits) - 1); | |
s >>= -nBits; | |
nBits += eLen; | |
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} | |
m = e & ((1 << -nBits) - 1); | |
e >>= -nBits; | |
nBits += mLen; | |
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} | |
if (e === 0) { | |
e = 1 - eBias; | |
} else if (e === eMax) { | |
return m ? NaN : (s ? -1 : 1) * Infinity; | |
} else { | |
m = m + Math.pow(2, mLen); | |
e = e - eBias; | |
} | |
return (s ? -1 : 1) * m * Math.pow(2, e - mLen); | |
} | |
function write(buffer, value, offset, isLE, mLen, nBytes) { | |
var e, m, c; | |
var eLen = nBytes * 8 - mLen - 1; | |
var eMax = (1 << eLen) - 1; | |
var eBias = eMax >> 1; | |
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; | |
var i = isLE ? 0 : nBytes - 1; | |
var d = isLE ? 1 : -1; | |
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; | |
value = Math.abs(value); | |
if (isNaN(value) || value === Infinity) { | |
m = isNaN(value) ? 1 : 0; | |
e = eMax; | |
} else { | |
e = Math.floor(Math.log(value) / Math.LN2); | |
if (value * (c = Math.pow(2, -e)) < 1) { | |
e--; | |
c *= 2; | |
} | |
if (e + eBias >= 1) { | |
value += rt / c; | |
} else { | |
value += rt * Math.pow(2, 1 - eBias); | |
} | |
if (value * c >= 2) { | |
e++; | |
c /= 2; | |
} | |
if (e + eBias >= eMax) { | |
m = 0; | |
e = eMax; | |
} else if (e + eBias >= 1) { | |
m = (value * c - 1) * Math.pow(2, mLen); | |
e = e + eBias; | |
} else { | |
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); | |
e = 0; | |
} | |
} | |
for ( | |
; | |
mLen >= 8; | |
buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8 | |
) {} | |
e = (e << mLen) | m; | |
eLen += mLen; | |
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {} | |
buffer[offset + i - d] |= s * 128; | |
} | |
var toString = {}.toString; | |
var isArray = | |
Array.isArray || | |
function (arr) { | |
return toString.call(arr) == "[object Array]"; | |
}; | |
/*! | |
* The buffer module from node.js, for the browser. | |
* | |
* @author Feross Aboukhadijeh <[email protected]> <http://feross.org> | |
* @license MIT | |
*/ | |
var INSPECT_MAX_BYTES = 50; | |
Buffer.TYPED_ARRAY_SUPPORT = | |
global$1.TYPED_ARRAY_SUPPORT !== void 0 ? global$1.TYPED_ARRAY_SUPPORT : true; | |
function kMaxLength() { | |
return Buffer.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823; | |
} | |
function createBuffer(that, length) { | |
if (kMaxLength() < length) { | |
throw new RangeError("Invalid typed array length"); | |
} | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
that = new Uint8Array(length); | |
that.__proto__ = Buffer.prototype; | |
} else { | |
if (that === null) { | |
that = new Buffer(length); | |
} | |
that.length = length; | |
} | |
return that; | |
} | |
function Buffer(arg, encodingOrOffset, length) { | |
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { | |
return new Buffer(arg, encodingOrOffset, length); | |
} | |
if (typeof arg === "number") { | |
if (typeof encodingOrOffset === "string") { | |
throw new Error( | |
"If encoding is specified then the first argument must be a string" | |
); | |
} | |
return allocUnsafe(this, arg); | |
} | |
return from(this, arg, encodingOrOffset, length); | |
} | |
Buffer.poolSize = 8192; | |
Buffer._augment = function (arr) { | |
arr.__proto__ = Buffer.prototype; | |
return arr; | |
}; | |
function from(that, value, encodingOrOffset, length) { | |
if (typeof value === "number") { | |
throw new TypeError('"value" argument must not be a number'); | |
} | |
if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) { | |
return fromArrayBuffer(that, value, encodingOrOffset, length); | |
} | |
if (typeof value === "string") { | |
return fromString(that, value, encodingOrOffset); | |
} | |
return fromObject(that, value); | |
} | |
Buffer.from = function (value, encodingOrOffset, length) { | |
return from(null, value, encodingOrOffset, length); | |
}; | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
Buffer.prototype.__proto__ = Uint8Array.prototype; | |
Buffer.__proto__ = Uint8Array; | |
} | |
function assertSize(size) { | |
if (typeof size !== "number") { | |
throw new TypeError('"size" argument must be a number'); | |
} else if (size < 0) { | |
throw new RangeError('"size" argument must not be negative'); | |
} | |
} | |
function alloc(that, size, fill2, encoding) { | |
assertSize(size); | |
if (size <= 0) { | |
return createBuffer(that, size); | |
} | |
if (fill2 !== void 0) { | |
return typeof encoding === "string" | |
? createBuffer(that, size).fill(fill2, encoding) | |
: createBuffer(that, size).fill(fill2); | |
} | |
return createBuffer(that, size); | |
} | |
Buffer.alloc = function (size, fill2, encoding) { | |
return alloc(null, size, fill2, encoding); | |
}; | |
function allocUnsafe(that, size) { | |
assertSize(size); | |
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0); | |
if (!Buffer.TYPED_ARRAY_SUPPORT) { | |
for (var i = 0; i < size; ++i) { | |
that[i] = 0; | |
} | |
} | |
return that; | |
} | |
Buffer.allocUnsafe = function (size) { | |
return allocUnsafe(null, size); | |
}; | |
Buffer.allocUnsafeSlow = function (size) { | |
return allocUnsafe(null, size); | |
}; | |
function fromString(that, string, encoding) { | |
if (typeof encoding !== "string" || encoding === "") { | |
encoding = "utf8"; | |
} | |
if (!Buffer.isEncoding(encoding)) { | |
throw new TypeError('"encoding" must be a valid string encoding'); | |
} | |
var length = byteLength(string, encoding) | 0; | |
that = createBuffer(that, length); | |
var actual = that.write(string, encoding); | |
if (actual !== length) { | |
that = that.slice(0, actual); | |
} | |
return that; | |
} | |
function fromArrayLike(that, array2) { | |
var length = array2.length < 0 ? 0 : checked(array2.length) | 0; | |
that = createBuffer(that, length); | |
for (var i = 0; i < length; i += 1) { | |
that[i] = array2[i] & 255; | |
} | |
return that; | |
} | |
function fromArrayBuffer(that, array2, byteOffset, length) { | |
array2.byteLength; | |
if (byteOffset < 0 || array2.byteLength < byteOffset) { | |
throw new RangeError("'offset' is out of bounds"); | |
} | |
if (array2.byteLength < byteOffset + (length || 0)) { | |
throw new RangeError("'length' is out of bounds"); | |
} | |
if (byteOffset === void 0 && length === void 0) { | |
array2 = new Uint8Array(array2); | |
} else if (length === void 0) { | |
array2 = new Uint8Array(array2, byteOffset); | |
} else { | |
array2 = new Uint8Array(array2, byteOffset, length); | |
} | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
that = array2; | |
that.__proto__ = Buffer.prototype; | |
} else { | |
that = fromArrayLike(that, array2); | |
} | |
return that; | |
} | |
function fromObject(that, obj) { | |
if (internalIsBuffer(obj)) { | |
var len = checked(obj.length) | 0; | |
that = createBuffer(that, len); | |
if (that.length === 0) { | |
return that; | |
} | |
obj.copy(that, 0, 0, len); | |
return that; | |
} | |
if (obj) { | |
if ( | |
(typeof ArrayBuffer !== "undefined" && | |
obj.buffer instanceof ArrayBuffer) || | |
"length" in obj | |
) { | |
if (typeof obj.length !== "number" || isnan(obj.length)) { | |
return createBuffer(that, 0); | |
} | |
return fromArrayLike(that, obj); | |
} | |
if (obj.type === "Buffer" && isArray(obj.data)) { | |
return fromArrayLike(that, obj.data); | |
} | |
} | |
throw new TypeError( | |
"First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object." | |
); | |
} | |
function checked(length) { | |
if (length >= kMaxLength()) { | |
throw new RangeError( | |
"Attempt to allocate Buffer larger than maximum size: 0x" + | |
kMaxLength().toString(16) + | |
" bytes" | |
); | |
} | |
return length | 0; | |
} | |
Buffer.isBuffer = isBuffer; | |
function internalIsBuffer(b) { | |
return !!(b != null && b._isBuffer); | |
} | |
Buffer.compare = function compare(a, b) { | |
if (!internalIsBuffer(a) || !internalIsBuffer(b)) { | |
throw new TypeError("Arguments must be Buffers"); | |
} | |
if (a === b) return 0; | |
var x = a.length; | |
var y = b.length; | |
for (var i = 0, len = Math.min(x, y); i < len; ++i) { | |
if (a[i] !== b[i]) { | |
x = a[i]; | |
y = b[i]; | |
break; | |
} | |
} | |
if (x < y) return -1; | |
if (y < x) return 1; | |
return 0; | |
}; | |
Buffer.isEncoding = function isEncoding(encoding) { | |
switch (String(encoding).toLowerCase()) { | |
case "hex": | |
case "utf8": | |
case "utf-8": | |
case "ascii": | |
case "latin1": | |
case "binary": | |
case "base64": | |
case "ucs2": | |
case "ucs-2": | |
case "utf16le": | |
case "utf-16le": | |
return true; | |
default: | |
return false; | |
} | |
}; | |
Buffer.concat = function concat(list, length) { | |
if (!isArray(list)) { | |
throw new TypeError('"list" argument must be an Array of Buffers'); | |
} | |
if (list.length === 0) { | |
return Buffer.alloc(0); | |
} | |
var i; | |
if (length === void 0) { | |
length = 0; | |
for (i = 0; i < list.length; ++i) { | |
length += list[i].length; | |
} | |
} | |
var buffer = Buffer.allocUnsafe(length); | |
var pos = 0; | |
for (i = 0; i < list.length; ++i) { | |
var buf = list[i]; | |
if (!internalIsBuffer(buf)) { | |
throw new TypeError('"list" argument must be an Array of Buffers'); | |
} | |
buf.copy(buffer, pos); | |
pos += buf.length; | |
} | |
return buffer; | |
}; | |
function byteLength(string, encoding) { | |
if (internalIsBuffer(string)) { | |
return string.length; | |
} | |
if ( | |
typeof ArrayBuffer !== "undefined" && | |
typeof ArrayBuffer.isView === "function" && | |
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer) | |
) { | |
return string.byteLength; | |
} | |
if (typeof string !== "string") { | |
string = "" + string; | |
} | |
var len = string.length; | |
if (len === 0) return 0; | |
var loweredCase = false; | |
for (;;) { | |
switch (encoding) { | |
case "ascii": | |
case "latin1": | |
case "binary": | |
return len; | |
case "utf8": | |
case "utf-8": | |
case void 0: | |
return utf8ToBytes(string).length; | |
case "ucs2": | |
case "ucs-2": | |
case "utf16le": | |
case "utf-16le": | |
return len * 2; | |
case "hex": | |
return len >>> 1; | |
case "base64": | |
return base64ToBytes(string).length; | |
default: | |
if (loweredCase) return utf8ToBytes(string).length; | |
encoding = ("" + encoding).toLowerCase(); | |
loweredCase = true; | |
} | |
} | |
} | |
Buffer.byteLength = byteLength; | |
function slowToString(encoding, start, end) { | |
var loweredCase = false; | |
if (start === void 0 || start < 0) { | |
start = 0; | |
} | |
if (start > this.length) { | |
return ""; | |
} | |
if (end === void 0 || end > this.length) { | |
end = this.length; | |
} | |
if (end <= 0) { | |
return ""; | |
} | |
end >>>= 0; | |
start >>>= 0; | |
if (end <= start) { | |
return ""; | |
} | |
if (!encoding) encoding = "utf8"; | |
while (true) { | |
switch (encoding) { | |
case "hex": | |
return hexSlice(this, start, end); | |
case "utf8": | |
case "utf-8": | |
return utf8Slice(this, start, end); | |
case "ascii": | |
return asciiSlice(this, start, end); | |
case "latin1": | |
case "binary": | |
return latin1Slice(this, start, end); | |
case "base64": | |
return base64Slice(this, start, end); | |
case "ucs2": | |
case "ucs-2": | |
case "utf16le": | |
case "utf-16le": | |
return utf16leSlice(this, start, end); | |
default: | |
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); | |
encoding = (encoding + "").toLowerCase(); | |
loweredCase = true; | |
} | |
} | |
} | |
Buffer.prototype._isBuffer = true; | |
function swap(b, n, m) { | |
var i = b[n]; | |
b[n] = b[m]; | |
b[m] = i; | |
} | |
Buffer.prototype.swap16 = function swap16() { | |
var len = this.length; | |
if (len % 2 !== 0) { | |
throw new RangeError("Buffer size must be a multiple of 16-bits"); | |
} | |
for (var i = 0; i < len; i += 2) { | |
swap(this, i, i + 1); | |
} | |
return this; | |
}; | |
Buffer.prototype.swap32 = function swap32() { | |
var len = this.length; | |
if (len % 4 !== 0) { | |
throw new RangeError("Buffer size must be a multiple of 32-bits"); | |
} | |
for (var i = 0; i < len; i += 4) { | |
swap(this, i, i + 3); | |
swap(this, i + 1, i + 2); | |
} | |
return this; | |
}; | |
Buffer.prototype.swap64 = function swap64() { | |
var len = this.length; | |
if (len % 8 !== 0) { | |
throw new RangeError("Buffer size must be a multiple of 64-bits"); | |
} | |
for (var i = 0; i < len; i += 8) { | |
swap(this, i, i + 7); | |
swap(this, i + 1, i + 6); | |
swap(this, i + 2, i + 5); | |
swap(this, i + 3, i + 4); | |
} | |
return this; | |
}; | |
Buffer.prototype.toString = function toString2() { | |
var length = this.length | 0; | |
if (length === 0) return ""; | |
if (arguments.length === 0) return utf8Slice(this, 0, length); | |
return slowToString.apply(this, arguments); | |
}; | |
Buffer.prototype.equals = function equals(b) { | |
if (!internalIsBuffer(b)) throw new TypeError("Argument must be a Buffer"); | |
if (this === b) return true; | |
return Buffer.compare(this, b) === 0; | |
}; | |
Buffer.prototype.inspect = function inspect() { | |
var str = ""; | |
var max = INSPECT_MAX_BYTES; | |
if (this.length > 0) { | |
str = this.toString("hex", 0, max).match(/.{2}/g).join(" "); | |
if (this.length > max) str += " ... "; | |
} | |
return "<Buffer " + str + ">"; | |
}; | |
Buffer.prototype.compare = function compare2( | |
target, | |
start, | |
end, | |
thisStart, | |
thisEnd | |
) { | |
if (!internalIsBuffer(target)) { | |
throw new TypeError("Argument must be a Buffer"); | |
} | |
if (start === void 0) { | |
start = 0; | |
} | |
if (end === void 0) { | |
end = target ? target.length : 0; | |
} | |
if (thisStart === void 0) { | |
thisStart = 0; | |
} | |
if (thisEnd === void 0) { | |
thisEnd = this.length; | |
} | |
if ( | |
start < 0 || | |
end > target.length || | |
thisStart < 0 || | |
thisEnd > this.length | |
) { | |
throw new RangeError("out of range index"); | |
} | |
if (thisStart >= thisEnd && start >= end) { | |
return 0; | |
} | |
if (thisStart >= thisEnd) { | |
return -1; | |
} | |
if (start >= end) { | |
return 1; | |
} | |
start >>>= 0; | |
end >>>= 0; | |
thisStart >>>= 0; | |
thisEnd >>>= 0; | |
if (this === target) return 0; | |
var x = thisEnd - thisStart; | |
var y = end - start; | |
var len = Math.min(x, y); | |
var thisCopy = this.slice(thisStart, thisEnd); | |
var targetCopy = target.slice(start, end); | |
for (var i = 0; i < len; ++i) { | |
if (thisCopy[i] !== targetCopy[i]) { | |
x = thisCopy[i]; | |
y = targetCopy[i]; | |
break; | |
} | |
} | |
if (x < y) return -1; | |
if (y < x) return 1; | |
return 0; | |
}; | |
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { | |
if (buffer.length === 0) return -1; | |
if (typeof byteOffset === "string") { | |
encoding = byteOffset; | |
byteOffset = 0; | |
} else if (byteOffset > 2147483647) { | |
byteOffset = 2147483647; | |
} else if (byteOffset < -2147483648) { | |
byteOffset = -2147483648; | |
} | |
byteOffset = +byteOffset; | |
if (isNaN(byteOffset)) { | |
byteOffset = dir ? 0 : buffer.length - 1; | |
} | |
if (byteOffset < 0) byteOffset = buffer.length + byteOffset; | |
if (byteOffset >= buffer.length) { | |
if (dir) return -1; | |
else byteOffset = buffer.length - 1; | |
} else if (byteOffset < 0) { | |
if (dir) byteOffset = 0; | |
else return -1; | |
} | |
if (typeof val === "string") { | |
val = Buffer.from(val, encoding); | |
} | |
if (internalIsBuffer(val)) { | |
if (val.length === 0) { | |
return -1; | |
} | |
return arrayIndexOf(buffer, val, byteOffset, encoding, dir); | |
} else if (typeof val === "number") { | |
val = val & 255; | |
if ( | |
Buffer.TYPED_ARRAY_SUPPORT && | |
typeof Uint8Array.prototype.indexOf === "function" | |
) { | |
if (dir) { | |
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); | |
} else { | |
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); | |
} | |
} | |
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); | |
} | |
throw new TypeError("val must be string, number or Buffer"); | |
} | |
function arrayIndexOf(arr, val, byteOffset, encoding, dir) { | |
var indexSize = 1; | |
var arrLength = arr.length; | |
var valLength = val.length; | |
if (encoding !== void 0) { | |
encoding = String(encoding).toLowerCase(); | |
if ( | |
encoding === "ucs2" || | |
encoding === "ucs-2" || | |
encoding === "utf16le" || | |
encoding === "utf-16le" | |
) { | |
if (arr.length < 2 || val.length < 2) { | |
return -1; | |
} | |
indexSize = 2; | |
arrLength /= 2; | |
valLength /= 2; | |
byteOffset /= 2; | |
} | |
} | |
function read2(buf, i2) { | |
if (indexSize === 1) { | |
return buf[i2]; | |
} else { | |
return buf.readUInt16BE(i2 * indexSize); | |
} | |
} | |
var i; | |
if (dir) { | |
var foundIndex = -1; | |
for (i = byteOffset; i < arrLength; i++) { | |
if ( | |
read2(arr, i) === read2(val, foundIndex === -1 ? 0 : i - foundIndex) | |
) { | |
if (foundIndex === -1) foundIndex = i; | |
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; | |
} else { | |
if (foundIndex !== -1) i -= i - foundIndex; | |
foundIndex = -1; | |
} | |
} | |
} else { | |
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; | |
for (i = byteOffset; i >= 0; i--) { | |
var found = true; | |
for (var j = 0; j < valLength; j++) { | |
if (read2(arr, i + j) !== read2(val, j)) { | |
found = false; | |
break; | |
} | |
} | |
if (found) return i; | |
} | |
} | |
return -1; | |
} | |
Buffer.prototype.includes = function includes(val, byteOffset, encoding) { | |
return this.indexOf(val, byteOffset, encoding) !== -1; | |
}; | |
Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { | |
return bidirectionalIndexOf(this, val, byteOffset, encoding, true); | |
}; | |
Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { | |
return bidirectionalIndexOf(this, val, byteOffset, encoding, false); | |
}; | |
function hexWrite(buf, string, offset, length) { | |
offset = Number(offset) || 0; | |
var remaining = buf.length - offset; | |
if (!length) { | |
length = remaining; | |
} else { | |
length = Number(length); | |
if (length > remaining) { | |
length = remaining; | |
} | |
} | |
var strLen = string.length; | |
if (strLen % 2 !== 0) throw new TypeError("Invalid hex string"); | |
if (length > strLen / 2) { | |
length = strLen / 2; | |
} | |
for (var i = 0; i < length; ++i) { | |
var parsed = parseInt(string.substr(i * 2, 2), 16); | |
if (isNaN(parsed)) return i; | |
buf[offset + i] = parsed; | |
} | |
return i; | |
} | |
function utf8Write(buf, string, offset, length) { | |
return blitBuffer( | |
utf8ToBytes(string, buf.length - offset), | |
buf, | |
offset, | |
length | |
); | |
} | |
function asciiWrite(buf, string, offset, length) { | |
return blitBuffer(asciiToBytes(string), buf, offset, length); | |
} | |
function latin1Write(buf, string, offset, length) { | |
return asciiWrite(buf, string, offset, length); | |
} | |
function base64Write(buf, string, offset, length) { | |
return blitBuffer(base64ToBytes(string), buf, offset, length); | |
} | |
function ucs2Write(buf, string, offset, length) { | |
return blitBuffer( | |
utf16leToBytes(string, buf.length - offset), | |
buf, | |
offset, | |
length | |
); | |
} | |
Buffer.prototype.write = function write2(string, offset, length, encoding) { | |
if (offset === void 0) { | |
encoding = "utf8"; | |
length = this.length; | |
offset = 0; | |
} else if (length === void 0 && typeof offset === "string") { | |
encoding = offset; | |
length = this.length; | |
offset = 0; | |
} else if (isFinite(offset)) { | |
offset = offset | 0; | |
if (isFinite(length)) { | |
length = length | 0; | |
if (encoding === void 0) encoding = "utf8"; | |
} else { | |
encoding = length; | |
length = void 0; | |
} | |
} else { | |
throw new Error( | |
"Buffer.write(string, encoding, offset[, length]) is no longer supported" | |
); | |
} | |
var remaining = this.length - offset; | |
if (length === void 0 || length > remaining) length = remaining; | |
if ( | |
(string.length > 0 && (length < 0 || offset < 0)) || | |
offset > this.length | |
) { | |
throw new RangeError("Attempt to write outside buffer bounds"); | |
} | |
if (!encoding) encoding = "utf8"; | |
var loweredCase = false; | |
for (;;) { | |
switch (encoding) { | |
case "hex": | |
return hexWrite(this, string, offset, length); | |
case "utf8": | |
case "utf-8": | |
return utf8Write(this, string, offset, length); | |
case "ascii": | |
return asciiWrite(this, string, offset, length); | |
case "latin1": | |
case "binary": | |
return latin1Write(this, string, offset, length); | |
case "base64": | |
return base64Write(this, string, offset, length); | |
case "ucs2": | |
case "ucs-2": | |
case "utf16le": | |
case "utf-16le": | |
return ucs2Write(this, string, offset, length); | |
default: | |
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); | |
encoding = ("" + encoding).toLowerCase(); | |
loweredCase = true; | |
} | |
} | |
}; | |
Buffer.prototype.toJSON = function toJSON() { | |
return { | |
type: "Buffer", | |
data: Array.prototype.slice.call(this._arr || this, 0), | |
}; | |
}; | |
function base64Slice(buf, start, end) { | |
if (start === 0 && end === buf.length) { | |
return fromByteArray(buf); | |
} else { | |
return fromByteArray(buf.slice(start, end)); | |
} | |
} | |
function utf8Slice(buf, start, end) { | |
end = Math.min(buf.length, end); | |
var res = []; | |
var i = start; | |
while (i < end) { | |
var firstByte = buf[i]; | |
var codePoint = null; | |
var bytesPerSequence = | |
firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; | |
if (i + bytesPerSequence <= end) { | |
var secondByte, thirdByte, fourthByte, tempCodePoint; | |
switch (bytesPerSequence) { | |
case 1: | |
if (firstByte < 128) { | |
codePoint = firstByte; | |
} | |
break; | |
case 2: | |
secondByte = buf[i + 1]; | |
if ((secondByte & 192) === 128) { | |
tempCodePoint = ((firstByte & 31) << 6) | (secondByte & 63); | |
if (tempCodePoint > 127) { | |
codePoint = tempCodePoint; | |
} | |
} | |
break; | |
case 3: | |
secondByte = buf[i + 1]; | |
thirdByte = buf[i + 2]; | |
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { | |
tempCodePoint = | |
((firstByte & 15) << 12) | | |
((secondByte & 63) << 6) | | |
(thirdByte & 63); | |
if ( | |
tempCodePoint > 2047 && | |
(tempCodePoint < 55296 || tempCodePoint > 57343) | |
) { | |
codePoint = tempCodePoint; | |
} | |
} | |
break; | |
case 4: | |
secondByte = buf[i + 1]; | |
thirdByte = buf[i + 2]; | |
fourthByte = buf[i + 3]; | |
if ( | |
(secondByte & 192) === 128 && | |
(thirdByte & 192) === 128 && | |
(fourthByte & 192) === 128 | |
) { | |
tempCodePoint = | |
((firstByte & 15) << 18) | | |
((secondByte & 63) << 12) | | |
((thirdByte & 63) << 6) | | |
(fourthByte & 63); | |
if (tempCodePoint > 65535 && tempCodePoint < 1114112) { | |
codePoint = tempCodePoint; | |
} | |
} | |
} | |
} | |
if (codePoint === null) { | |
codePoint = 65533; | |
bytesPerSequence = 1; | |
} else if (codePoint > 65535) { | |
codePoint -= 65536; | |
res.push(((codePoint >>> 10) & 1023) | 55296); | |
codePoint = 56320 | (codePoint & 1023); | |
} | |
res.push(codePoint); | |
i += bytesPerSequence; | |
} | |
return decodeCodePointsArray(res); | |
} | |
var MAX_ARGUMENTS_LENGTH = 4096; | |
function decodeCodePointsArray(codePoints) { | |
var len = codePoints.length; | |
if (len <= MAX_ARGUMENTS_LENGTH) { | |
return String.fromCharCode.apply(String, codePoints); | |
} | |
var res = ""; | |
var i = 0; | |
while (i < len) { | |
res += String.fromCharCode.apply( | |
String, | |
codePoints.slice(i, (i += MAX_ARGUMENTS_LENGTH)) | |
); | |
} | |
return res; | |
} | |
function asciiSlice(buf, start, end) { | |
var ret = ""; | |
end = Math.min(buf.length, end); | |
for (var i = start; i < end; ++i) { | |
ret += String.fromCharCode(buf[i] & 127); | |
} | |
return ret; | |
} | |
function latin1Slice(buf, start, end) { | |
var ret = ""; | |
end = Math.min(buf.length, end); | |
for (var i = start; i < end; ++i) { | |
ret += String.fromCharCode(buf[i]); | |
} | |
return ret; | |
} | |
function hexSlice(buf, start, end) { | |
var len = buf.length; | |
if (!start || start < 0) start = 0; | |
if (!end || end < 0 || end > len) end = len; | |
var out = ""; | |
for (var i = start; i < end; ++i) { | |
out += toHex(buf[i]); | |
} | |
return out; | |
} | |
function utf16leSlice(buf, start, end) { | |
var bytes = buf.slice(start, end); | |
var res = ""; | |
for (var i = 0; i < bytes.length; i += 2) { | |
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); | |
} | |
return res; | |
} | |
Buffer.prototype.slice = function slice(start, end) { | |
var len = this.length; | |
start = ~~start; | |
end = end === void 0 ? len : ~~end; | |
if (start < 0) { | |
start += len; | |
if (start < 0) start = 0; | |
} else if (start > len) { | |
start = len; | |
} | |
if (end < 0) { | |
end += len; | |
if (end < 0) end = 0; | |
} else if (end > len) { | |
end = len; | |
} | |
if (end < start) end = start; | |
var newBuf; | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
newBuf = this.subarray(start, end); | |
newBuf.__proto__ = Buffer.prototype; | |
} else { | |
var sliceLen = end - start; | |
newBuf = new Buffer(sliceLen, void 0); | |
for (var i = 0; i < sliceLen; ++i) { | |
newBuf[i] = this[i + start]; | |
} | |
} | |
return newBuf; | |
}; | |
function checkOffset(offset, ext, length) { | |
if (offset % 1 !== 0 || offset < 0) | |
throw new RangeError("offset is not uint"); | |
if (offset + ext > length) | |
throw new RangeError("Trying to access beyond buffer length"); | |
} | |
Buffer.prototype.readUIntLE = function readUIntLE( | |
offset, | |
byteLength2, | |
noAssert | |
) { | |
offset = offset | 0; | |
byteLength2 = byteLength2 | 0; | |
if (!noAssert) checkOffset(offset, byteLength2, this.length); | |
var val = this[offset]; | |
var mul = 1; | |
var i = 0; | |
while (++i < byteLength2 && (mul *= 256)) { | |
val += this[offset + i] * mul; | |
} | |
return val; | |
}; | |
Buffer.prototype.readUIntBE = function readUIntBE( | |
offset, | |
byteLength2, | |
noAssert | |
) { | |
offset = offset | 0; | |
byteLength2 = byteLength2 | 0; | |
if (!noAssert) { | |
checkOffset(offset, byteLength2, this.length); | |
} | |
var val = this[offset + --byteLength2]; | |
var mul = 1; | |
while (byteLength2 > 0 && (mul *= 256)) { | |
val += this[offset + --byteLength2] * mul; | |
} | |
return val; | |
}; | |
Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 1, this.length); | |
return this[offset]; | |
}; | |
Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length); | |
return this[offset] | (this[offset + 1] << 8); | |
}; | |
Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length); | |
return (this[offset] << 8) | this[offset + 1]; | |
}; | |
Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length); | |
return ( | |
(this[offset] | (this[offset + 1] << 8) | (this[offset + 2] << 16)) + | |
this[offset + 3] * 16777216 | |
); | |
}; | |
Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length); | |
return ( | |
this[offset] * 16777216 + | |
((this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3]) | |
); | |
}; | |
Buffer.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) { | |
offset = offset | 0; | |
byteLength2 = byteLength2 | 0; | |
if (!noAssert) checkOffset(offset, byteLength2, this.length); | |
var val = this[offset]; | |
var mul = 1; | |
var i = 0; | |
while (++i < byteLength2 && (mul *= 256)) { | |
val += this[offset + i] * mul; | |
} | |
mul *= 128; | |
if (val >= mul) val -= Math.pow(2, 8 * byteLength2); | |
return val; | |
}; | |
Buffer.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) { | |
offset = offset | 0; | |
byteLength2 = byteLength2 | 0; | |
if (!noAssert) checkOffset(offset, byteLength2, this.length); | |
var i = byteLength2; | |
var mul = 1; | |
var val = this[offset + --i]; | |
while (i > 0 && (mul *= 256)) { | |
val += this[offset + --i] * mul; | |
} | |
mul *= 128; | |
if (val >= mul) val -= Math.pow(2, 8 * byteLength2); | |
return val; | |
}; | |
Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 1, this.length); | |
if (!(this[offset] & 128)) return this[offset]; | |
return (255 - this[offset] + 1) * -1; | |
}; | |
Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length); | |
var val = this[offset] | (this[offset + 1] << 8); | |
return val & 32768 ? val | 4294901760 : val; | |
}; | |
Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length); | |
var val = this[offset + 1] | (this[offset] << 8); | |
return val & 32768 ? val | 4294901760 : val; | |
}; | |
Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length); | |
return ( | |
this[offset] | | |
(this[offset + 1] << 8) | | |
(this[offset + 2] << 16) | | |
(this[offset + 3] << 24) | |
); | |
}; | |
Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length); | |
return ( | |
(this[offset] << 24) | | |
(this[offset + 1] << 16) | | |
(this[offset + 2] << 8) | | |
this[offset + 3] | |
); | |
}; | |
Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length); | |
return read(this, offset, true, 23, 4); | |
}; | |
Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length); | |
return read(this, offset, false, 23, 4); | |
}; | |
Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 8, this.length); | |
return read(this, offset, true, 52, 8); | |
}; | |
Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 8, this.length); | |
return read(this, offset, false, 52, 8); | |
}; | |
function checkInt(buf, value, offset, ext, max, min) { | |
if (!internalIsBuffer(buf)) | |
throw new TypeError('"buffer" argument must be a Buffer instance'); | |
if (value > max || value < min) | |
throw new RangeError('"value" argument is out of bounds'); | |
if (offset + ext > buf.length) throw new RangeError("Index out of range"); | |
} | |
Buffer.prototype.writeUIntLE = function writeUIntLE( | |
value, | |
offset, | |
byteLength2, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
byteLength2 = byteLength2 | 0; | |
if (!noAssert) { | |
var maxBytes = Math.pow(2, 8 * byteLength2) - 1; | |
checkInt(this, value, offset, byteLength2, maxBytes, 0); | |
} | |
var mul = 1; | |
var i = 0; | |
this[offset] = value & 255; | |
while (++i < byteLength2 && (mul *= 256)) { | |
this[offset + i] = (value / mul) & 255; | |
} | |
return offset + byteLength2; | |
}; | |
Buffer.prototype.writeUIntBE = function writeUIntBE( | |
value, | |
offset, | |
byteLength2, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
byteLength2 = byteLength2 | 0; | |
if (!noAssert) { | |
var maxBytes = Math.pow(2, 8 * byteLength2) - 1; | |
checkInt(this, value, offset, byteLength2, maxBytes, 0); | |
} | |
var i = byteLength2 - 1; | |
var mul = 1; | |
this[offset + i] = value & 255; | |
while (--i >= 0 && (mul *= 256)) { | |
this[offset + i] = (value / mul) & 255; | |
} | |
return offset + byteLength2; | |
}; | |
Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 1, 255, 0); | |
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); | |
this[offset] = value & 255; | |
return offset + 1; | |
}; | |
function objectWriteUInt16(buf, value, offset, littleEndian) { | |
if (value < 0) value = 65535 + value + 1; | |
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { | |
buf[offset + i] = | |
(value & (255 << (8 * (littleEndian ? i : 1 - i)))) >>> | |
((littleEndian ? i : 1 - i) * 8); | |
} | |
} | |
Buffer.prototype.writeUInt16LE = function writeUInt16LE( | |
value, | |
offset, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = value & 255; | |
this[offset + 1] = value >>> 8; | |
} else { | |
objectWriteUInt16(this, value, offset, true); | |
} | |
return offset + 2; | |
}; | |
Buffer.prototype.writeUInt16BE = function writeUInt16BE( | |
value, | |
offset, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = value >>> 8; | |
this[offset + 1] = value & 255; | |
} else { | |
objectWriteUInt16(this, value, offset, false); | |
} | |
return offset + 2; | |
}; | |
function objectWriteUInt32(buf, value, offset, littleEndian) { | |
if (value < 0) value = 4294967295 + value + 1; | |
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { | |
buf[offset + i] = (value >>> ((littleEndian ? i : 3 - i) * 8)) & 255; | |
} | |
} | |
Buffer.prototype.writeUInt32LE = function writeUInt32LE( | |
value, | |
offset, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset + 3] = value >>> 24; | |
this[offset + 2] = value >>> 16; | |
this[offset + 1] = value >>> 8; | |
this[offset] = value & 255; | |
} else { | |
objectWriteUInt32(this, value, offset, true); | |
} | |
return offset + 4; | |
}; | |
Buffer.prototype.writeUInt32BE = function writeUInt32BE( | |
value, | |
offset, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = value >>> 24; | |
this[offset + 1] = value >>> 16; | |
this[offset + 2] = value >>> 8; | |
this[offset + 3] = value & 255; | |
} else { | |
objectWriteUInt32(this, value, offset, false); | |
} | |
return offset + 4; | |
}; | |
Buffer.prototype.writeIntLE = function writeIntLE( | |
value, | |
offset, | |
byteLength2, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) { | |
var limit = Math.pow(2, 8 * byteLength2 - 1); | |
checkInt(this, value, offset, byteLength2, limit - 1, -limit); | |
} | |
var i = 0; | |
var mul = 1; | |
var sub = 0; | |
this[offset] = value & 255; | |
while (++i < byteLength2 && (mul *= 256)) { | |
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { | |
sub = 1; | |
} | |
this[offset + i] = (((value / mul) >> 0) - sub) & 255; | |
} | |
return offset + byteLength2; | |
}; | |
Buffer.prototype.writeIntBE = function writeIntBE( | |
value, | |
offset, | |
byteLength2, | |
noAssert | |
) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) { | |
var limit = Math.pow(2, 8 * byteLength2 - 1); | |
checkInt(this, value, offset, byteLength2, limit - 1, -limit); | |
} | |
var i = byteLength2 - 1; | |
var mul = 1; | |
var sub = 0; | |
this[offset + i] = value & 255; | |
while (--i >= 0 && (mul *= 256)) { | |
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { | |
sub = 1; | |
} | |
this[offset + i] = (((value / mul) >> 0) - sub) & 255; | |
} | |
return offset + byteLength2; | |
}; | |
Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 1, 127, -128); | |
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value); | |
if (value < 0) value = 255 + value + 1; | |
this[offset] = value & 255; | |
return offset + 1; | |
}; | |
Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = value & 255; | |
this[offset + 1] = value >>> 8; | |
} else { | |
objectWriteUInt16(this, value, offset, true); | |
} | |
return offset + 2; | |
}; | |
Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = value >>> 8; | |
this[offset + 1] = value & 255; | |
} else { | |
objectWriteUInt16(this, value, offset, false); | |
} | |
return offset + 2; | |
}; | |
Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = value & 255; | |
this[offset + 1] = value >>> 8; | |
this[offset + 2] = value >>> 16; | |
this[offset + 3] = value >>> 24; | |
} else { | |
objectWriteUInt32(this, value, offset, true); | |
} | |
return offset + 4; | |
}; | |
Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { | |
value = +value; | |
offset = offset | 0; | |
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); | |
if (value < 0) value = 4294967295 + value + 1; | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = value >>> 24; | |
this[offset + 1] = value >>> 16; | |
this[offset + 2] = value >>> 8; | |
this[offset + 3] = value & 255; | |
} else { | |
objectWriteUInt32(this, value, offset, false); | |
} | |
return offset + 4; | |
}; | |
function checkIEEE754(buf, value, offset, ext, max, min) { | |
if (offset + ext > buf.length) throw new RangeError("Index out of range"); | |
if (offset < 0) throw new RangeError("Index out of range"); | |
} | |
function writeFloat(buf, value, offset, littleEndian, noAssert) { | |
if (!noAssert) { | |
checkIEEE754(buf, value, offset, 4); | |
} | |
write(buf, value, offset, littleEndian, 23, 4); | |
return offset + 4; | |
} | |
Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { | |
return writeFloat(this, value, offset, true, noAssert); | |
}; | |
Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { | |
return writeFloat(this, value, offset, false, noAssert); | |
}; | |
function writeDouble(buf, value, offset, littleEndian, noAssert) { | |
if (!noAssert) { | |
checkIEEE754(buf, value, offset, 8); | |
} | |
write(buf, value, offset, littleEndian, 52, 8); | |
return offset + 8; | |
} | |
Buffer.prototype.writeDoubleLE = function writeDoubleLE( | |
value, | |
offset, | |
noAssert | |
) { | |
return writeDouble(this, value, offset, true, noAssert); | |
}; | |
Buffer.prototype.writeDoubleBE = function writeDoubleBE( | |
value, | |
offset, | |
noAssert | |
) { | |
return writeDouble(this, value, offset, false, noAssert); | |
}; | |
Buffer.prototype.copy = function copy(target, targetStart, start, end) { | |
if (!start) start = 0; | |
if (!end && end !== 0) end = this.length; | |
if (targetStart >= target.length) targetStart = target.length; | |
if (!targetStart) targetStart = 0; | |
if (end > 0 && end < start) end = start; | |
if (end === start) return 0; | |
if (target.length === 0 || this.length === 0) return 0; | |
if (targetStart < 0) { | |
throw new RangeError("targetStart out of bounds"); | |
} | |
if (start < 0 || start >= this.length) | |
throw new RangeError("sourceStart out of bounds"); | |
if (end < 0) throw new RangeError("sourceEnd out of bounds"); | |
if (end > this.length) end = this.length; | |
if (target.length - targetStart < end - start) { | |
end = target.length - targetStart + start; | |
} | |
var len = end - start; | |
var i; | |
if (this === target && start < targetStart && targetStart < end) { | |
for (i = len - 1; i >= 0; --i) { | |
target[i + targetStart] = this[i + start]; | |
} | |
} else if (len < 1e3 || !Buffer.TYPED_ARRAY_SUPPORT) { | |
for (i = 0; i < len; ++i) { | |
target[i + targetStart] = this[i + start]; | |
} | |
} else { | |
Uint8Array.prototype.set.call( | |
target, | |
this.subarray(start, start + len), | |
targetStart | |
); | |
} | |
return len; | |
}; | |
Buffer.prototype.fill = function fill(val, start, end, encoding) { | |
if (typeof val === "string") { | |
if (typeof start === "string") { | |
encoding = start; | |
start = 0; | |
end = this.length; | |
} else if (typeof end === "string") { | |
encoding = end; | |
end = this.length; | |
} | |
if (val.length === 1) { | |
var code = val.charCodeAt(0); | |
if (code < 256) { | |
val = code; | |
} | |
} | |
if (encoding !== void 0 && typeof encoding !== "string") { | |
throw new TypeError("encoding must be a string"); | |
} | |
if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) { | |
throw new TypeError("Unknown encoding: " + encoding); | |
} | |
} else if (typeof val === "number") { | |
val = val & 255; | |
} | |
if (start < 0 || this.length < start || this.length < end) { | |
throw new RangeError("Out of range index"); | |
} | |
if (end <= start) { | |
return this; | |
} | |
start = start >>> 0; | |
end = end === void 0 ? this.length : end >>> 0; | |
if (!val) val = 0; | |
var i; | |
if (typeof val === "number") { | |
for (i = start; i < end; ++i) { | |
this[i] = val; | |
} | |
} else { | |
var bytes = internalIsBuffer(val) | |
? val | |
: utf8ToBytes(new Buffer(val, encoding).toString()); | |
var len = bytes.length; | |
for (i = 0; i < end - start; ++i) { | |
this[i + start] = bytes[i % len]; | |
} | |
} | |
return this; | |
}; | |
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g; | |
function base64clean(str) { | |
str = stringtrim(str).replace(INVALID_BASE64_RE, ""); | |
if (str.length < 2) return ""; | |
while (str.length % 4 !== 0) { | |
str = str + "="; | |
} | |
return str; | |
} | |
function stringtrim(str) { | |
if (str.trim) return str.trim(); | |
return str.replace(/^\s+|\s+$/g, ""); | |
} | |
function toHex(n) { | |
if (n < 16) return "0" + n.toString(16); | |
return n.toString(16); | |
} | |
function utf8ToBytes(string, units) { | |
units = units || Infinity; | |
var codePoint; | |
var length = string.length; | |
var leadSurrogate = null; | |
var bytes = []; | |
for (var i = 0; i < length; ++i) { | |
codePoint = string.charCodeAt(i); | |
if (codePoint > 55295 && codePoint < 57344) { | |
if (!leadSurrogate) { | |
if (codePoint > 56319) { | |
if ((units -= 3) > -1) bytes.push(239, 191, 189); | |
continue; | |
} else if (i + 1 === length) { | |
if ((units -= 3) > -1) bytes.push(239, 191, 189); | |
continue; | |
} | |
leadSurrogate = codePoint; | |
continue; | |
} | |
if (codePoint < 56320) { | |
if ((units -= 3) > -1) bytes.push(239, 191, 189); | |
leadSurrogate = codePoint; | |
continue; | |
} | |
codePoint = | |
(((leadSurrogate - 55296) << 10) | (codePoint - 56320)) + 65536; | |
} else if (leadSurrogate) { | |
if ((units -= 3) > -1) bytes.push(239, 191, 189); | |
} | |
leadSurrogate = null; | |
if (codePoint < 128) { | |
if ((units -= 1) < 0) break; | |
bytes.push(codePoint); | |
} else if (codePoint < 2048) { | |
if ((units -= 2) < 0) break; | |
bytes.push((codePoint >> 6) | 192, (codePoint & 63) | 128); | |
} else if (codePoint < 65536) { | |
if ((units -= 3) < 0) break; | |
bytes.push( | |
(codePoint >> 12) | 224, | |
((codePoint >> 6) & 63) | 128, | |
(codePoint & 63) | 128 | |
); | |
} else if (codePoint < 1114112) { | |
if ((units -= 4) < 0) break; | |
bytes.push( | |
(codePoint >> 18) | 240, | |
((codePoint >> 12) & 63) | 128, | |
((codePoint >> 6) & 63) | 128, | |
(codePoint & 63) | 128 | |
); | |
} else { | |
throw new Error("Invalid code point"); | |
} | |
} | |
return bytes; | |
} | |
function asciiToBytes(str) { | |
var byteArray = []; | |
for (var i = 0; i < str.length; ++i) { | |
byteArray.push(str.charCodeAt(i) & 255); | |
} | |
return byteArray; | |
} | |
function utf16leToBytes(str, units) { | |
var c, hi, lo; | |
var byteArray = []; | |
for (var i = 0; i < str.length; ++i) { | |
if ((units -= 2) < 0) break; | |
c = str.charCodeAt(i); | |
hi = c >> 8; | |
lo = c % 256; | |
byteArray.push(lo); | |
byteArray.push(hi); | |
} | |
return byteArray; | |
} | |
function base64ToBytes(str) { | |
return toByteArray(base64clean(str)); | |
} | |
function blitBuffer(src, dst, offset, length) { | |
for (var i = 0; i < length; ++i) { | |
if (i + offset >= dst.length || i >= src.length) break; | |
dst[i + offset] = src[i]; | |
} | |
return i; | |
} | |
function isnan(val) { | |
return val !== val; | |
} | |
function isBuffer(obj) { | |
return ( | |
obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj)) | |
); | |
} | |
function isFastBuffer(obj) { | |
return ( | |
!!obj.constructor && | |
typeof obj.constructor.isBuffer === "function" && | |
obj.constructor.isBuffer(obj) | |
); | |
} | |
function isSlowBuffer(obj) { | |
return ( | |
typeof obj.readFloatLE === "function" && | |
typeof obj.slice === "function" && | |
isFastBuffer(obj.slice(0, 0)) | |
); | |
} | |
var util = createCommonjsModule(function (module, exports) { | |
var __extends = | |
(commonjsGlobal && commonjsGlobal.__extends) || | |
(function () { | |
var extendStatics = function (d, b) { | |
extendStatics = | |
Object.setPrototypeOf || | |
({ __proto__: [] } instanceof Array && | |
function (d2, b2) { | |
d2.__proto__ = b2; | |
}) || | |
function (d2, b2) { | |
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p]; | |
}; | |
return extendStatics(d, b); | |
}; | |
return function (d, b) { | |
extendStatics(d, b); | |
function __() { | |
this.constructor = d; | |
} | |
d.prototype = | |
b === null | |
? Object.create(b) | |
: ((__.prototype = b.prototype), new __()); | |
}; | |
})(); | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
exports.DetailContext = exports.NoopContext = exports.VError = void 0; | |
var VError2 = (function (_super) { | |
__extends(VError3, _super); | |
function VError3(path, message) { | |
var _this = _super.call(this, message) || this; | |
_this.path = path; | |
Object.setPrototypeOf(_this, VError3.prototype); | |
return _this; | |
} | |
return VError3; | |
})(Error); | |
exports.VError = VError2; | |
var NoopContext = (function () { | |
function NoopContext2() {} | |
NoopContext2.prototype.fail = function (relPath, message, score) { | |
return false; | |
}; | |
NoopContext2.prototype.unionResolver = function () { | |
return this; | |
}; | |
NoopContext2.prototype.createContext = function () { | |
return this; | |
}; | |
NoopContext2.prototype.resolveUnion = function (ur) {}; | |
return NoopContext2; | |
})(); | |
exports.NoopContext = NoopContext; | |
var DetailContext = (function () { | |
function DetailContext2() { | |
this._propNames = [""]; | |
this._messages = [null]; | |
this._score = 0; | |
} | |
DetailContext2.prototype.fail = function (relPath, message, score) { | |
this._propNames.push(relPath); | |
this._messages.push(message); | |
this._score += score; | |
return false; | |
}; | |
DetailContext2.prototype.unionResolver = function () { | |
return new DetailUnionResolver(); | |
}; | |
DetailContext2.prototype.resolveUnion = function (unionResolver) { | |
var _a, _b; | |
var u = unionResolver; | |
var best = null; | |
for (var _i = 0, _c = u.contexts; _i < _c.length; _i++) { | |
var ctx = _c[_i]; | |
if (!best || ctx._score >= best._score) { | |
best = ctx; | |
} | |
} | |
if (best && best._score > 0) { | |
(_a = this._propNames).push.apply(_a, best._propNames); | |
(_b = this._messages).push.apply(_b, best._messages); | |
} | |
}; | |
DetailContext2.prototype.getError = function (path) { | |
var msgParts = []; | |
for (var i = this._propNames.length - 1; i >= 0; i--) { | |
var p = this._propNames[i]; | |
path += typeof p === "number" ? "[" + p + "]" : p ? "." + p : ""; | |
var m = this._messages[i]; | |
if (m) { | |
msgParts.push(path + " " + m); | |
} | |
} | |
return new VError2(path, msgParts.join("; ")); | |
}; | |
DetailContext2.prototype.getErrorDetail = function (path) { | |
var details = []; | |
for (var i = this._propNames.length - 1; i >= 0; i--) { | |
var p = this._propNames[i]; | |
path += typeof p === "number" ? "[" + p + "]" : p ? "." + p : ""; | |
var message = this._messages[i]; | |
if (message) { | |
details.push({ path, message }); | |
} | |
} | |
var detail = null; | |
for (var i = details.length - 1; i >= 0; i--) { | |
if (detail) { | |
details[i].nested = [detail]; | |
} | |
detail = details[i]; | |
} | |
return detail; | |
}; | |
return DetailContext2; | |
})(); | |
exports.DetailContext = DetailContext; | |
var DetailUnionResolver = (function () { | |
function DetailUnionResolver2() { | |
this.contexts = []; | |
} | |
DetailUnionResolver2.prototype.createContext = function () { | |
var ctx = new DetailContext(); | |
this.contexts.push(ctx); | |
return ctx; | |
}; | |
return DetailUnionResolver2; | |
})(); | |
}); | |
var types = createCommonjsModule(function (module, exports) { | |
var __extends = | |
(commonjsGlobal && commonjsGlobal.__extends) || | |
(function () { | |
var extendStatics = function (d, b) { | |
extendStatics = | |
Object.setPrototypeOf || | |
({ __proto__: [] } instanceof Array && | |
function (d2, b2) { | |
d2.__proto__ = b2; | |
}) || | |
function (d2, b2) { | |
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p]; | |
}; | |
return extendStatics(d, b); | |
}; | |
return function (d, b) { | |
extendStatics(d, b); | |
function __() { | |
this.constructor = d; | |
} | |
d.prototype = | |
b === null | |
? Object.create(b) | |
: ((__.prototype = b.prototype), new __()); | |
}; | |
})(); | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
exports.basicTypes = exports.BasicType = exports.TParamList = exports.TParam = exports.param = exports.TFunc = exports.func = exports.TProp = exports.TOptional = exports.opt = exports.TIface = exports.iface = exports.TEnumLiteral = exports.enumlit = exports.TEnumType = exports.enumtype = exports.TIntersection = exports.intersection = exports.TUnion = exports.union = exports.TTuple = exports.tuple = exports.TArray = exports.array = exports.TLiteral = exports.lit = exports.TName = exports.name = exports.TType = void 0; | |
var TType2 = (function () { | |
function TType3() {} | |
return TType3; | |
})(); | |
exports.TType = TType2; | |
function parseSpec(typeSpec) { | |
return typeof typeSpec === "string" ? name2(typeSpec) : typeSpec; | |
} | |
function getNamedType(suite, name3) { | |
var ttype = suite[name3]; | |
if (!ttype) { | |
throw new Error("Unknown type " + name3); | |
} | |
return ttype; | |
} | |
function name2(value) { | |
return new TName2(value); | |
} | |
exports.name = name2; | |
var TName2 = (function (_super) { | |
__extends(TName3, _super); | |
function TName3(name3) { | |
var _this = _super.call(this) || this; | |
_this.name = name3; | |
_this._failMsg = "is not a " + name3; | |
return _this; | |
} | |
TName3.prototype.getChecker = function (suite, strict, allowedProps) { | |
var _this = this; | |
var ttype = getNamedType(suite, this.name); | |
var checker = ttype.getChecker(suite, strict, allowedProps); | |
if (ttype instanceof BasicType2 || ttype instanceof TName3) { | |
return checker; | |
} | |
return function (value, ctx) { | |
return checker(value, ctx) ? true : ctx.fail(null, _this._failMsg, 0); | |
}; | |
}; | |
return TName3; | |
})(TType2); | |
exports.TName = TName2; | |
function lit2(value) { | |
return new TLiteral2(value); | |
} | |
exports.lit = lit2; | |
var TLiteral2 = (function (_super) { | |
__extends(TLiteral3, _super); | |
function TLiteral3(value) { | |
var _this = _super.call(this) || this; | |
_this.value = value; | |
_this.name = JSON.stringify(value); | |
_this._failMsg = "is not " + _this.name; | |
return _this; | |
} | |
TLiteral3.prototype.getChecker = function (suite, strict) { | |
var _this = this; | |
return function (value, ctx) { | |
return value === _this.value | |
? true | |
: ctx.fail(null, _this._failMsg, -1); | |
}; | |
}; | |
return TLiteral3; | |
})(TType2); | |
exports.TLiteral = TLiteral2; | |
function array2(typeSpec) { | |
return new TArray2(parseSpec(typeSpec)); | |
} | |
exports.array = array2; | |
var TArray2 = (function (_super) { | |
__extends(TArray3, _super); | |
function TArray3(ttype) { | |
var _this = _super.call(this) || this; | |
_this.ttype = ttype; | |
return _this; | |
} | |
TArray3.prototype.getChecker = function (suite, strict) { | |
var itemChecker = this.ttype.getChecker(suite, strict); | |
return function (value, ctx) { | |
if (!Array.isArray(value)) { | |
return ctx.fail(null, "is not an array", 0); | |
} | |
for (var i = 0; i < value.length; i++) { | |
var ok = itemChecker(value[i], ctx); | |
if (!ok) { | |
return ctx.fail(i, null, 1); | |
} | |
} | |
return true; | |
}; | |
}; | |
return TArray3; | |
})(TType2); | |
exports.TArray = TArray2; | |
function tuple2() { | |
var typeSpec = []; | |
for (var _i2 = 0; _i2 < arguments.length; _i2++) { | |
typeSpec[_i2] = arguments[_i2]; | |
} | |
return new TTuple2( | |
typeSpec.map(function (t) { | |
return parseSpec(t); | |
}) | |
); | |
} | |
exports.tuple = tuple2; | |
var TTuple2 = (function (_super) { | |
__extends(TTuple3, _super); | |
function TTuple3(ttypes) { | |
var _this = _super.call(this) || this; | |
_this.ttypes = ttypes; | |
return _this; | |
} | |
TTuple3.prototype.getChecker = function (suite, strict) { | |
var itemCheckers = this.ttypes.map(function (t) { | |
return t.getChecker(suite, strict); | |
}); | |
var checker = function (value, ctx) { | |
if (!Array.isArray(value)) { | |
return ctx.fail(null, "is not an array", 0); | |
} | |
for (var i = 0; i < itemCheckers.length; i++) { | |
var ok = itemCheckers[i](value[i], ctx); | |
if (!ok) { | |
return ctx.fail(i, null, 1); | |
} | |
} | |
return true; | |
}; | |
if (!strict) { | |
return checker; | |
} | |
return function (value, ctx) { | |
if (!checker(value, ctx)) { | |
return false; | |
} | |
return value.length <= itemCheckers.length | |
? true | |
: ctx.fail(itemCheckers.length, "is extraneous", 2); | |
}; | |
}; | |
return TTuple3; | |
})(TType2); | |
exports.TTuple = TTuple2; | |
function union2() { | |
var typeSpec = []; | |
for (var _i2 = 0; _i2 < arguments.length; _i2++) { | |
typeSpec[_i2] = arguments[_i2]; | |
} | |
return new TUnion2( | |
typeSpec.map(function (t) { | |
return parseSpec(t); | |
}) | |
); | |
} | |
exports.union = union2; | |
var TUnion2 = (function (_super) { | |
__extends(TUnion3, _super); | |
function TUnion3(ttypes) { | |
var _this = _super.call(this) || this; | |
_this.ttypes = ttypes; | |
var names = ttypes | |
.map(function (t) { | |
return t instanceof TName2 || t instanceof TLiteral2 ? t.name : null; | |
}) | |
.filter(function (n) { | |
return n; | |
}); | |
var otherTypes = ttypes.length - names.length; | |
if (names.length) { | |
if (otherTypes > 0) { | |
names.push(otherTypes + " more"); | |
} | |
_this._failMsg = "is none of " + names.join(", "); | |
} else { | |
_this._failMsg = "is none of " + otherTypes + " types"; | |
} | |
return _this; | |
} | |
TUnion3.prototype.getChecker = function (suite, strict) { | |
var _this = this; | |
var itemCheckers = this.ttypes.map(function (t) { | |
return t.getChecker(suite, strict); | |
}); | |
return function (value, ctx) { | |
var ur = ctx.unionResolver(); | |
for (var i = 0; i < itemCheckers.length; i++) { | |
var ok = itemCheckers[i](value, ur.createContext()); | |
if (ok) { | |
return true; | |
} | |
} | |
ctx.resolveUnion(ur); | |
return ctx.fail(null, _this._failMsg, 0); | |
}; | |
}; | |
return TUnion3; | |
})(TType2); | |
exports.TUnion = TUnion2; | |
function intersection2() { | |
var typeSpec = []; | |
for (var _i2 = 0; _i2 < arguments.length; _i2++) { | |
typeSpec[_i2] = arguments[_i2]; | |
} | |
return new TIntersection2( | |
typeSpec.map(function (t) { | |
return parseSpec(t); | |
}) | |
); | |
} | |
exports.intersection = intersection2; | |
var TIntersection2 = (function (_super) { | |
__extends(TIntersection3, _super); | |
function TIntersection3(ttypes) { | |
var _this = _super.call(this) || this; | |
_this.ttypes = ttypes; | |
return _this; | |
} | |
TIntersection3.prototype.getChecker = function (suite, strict) { | |
var allowedProps = new Set(); | |
var itemCheckers = this.ttypes.map(function (t) { | |
return t.getChecker(suite, strict, allowedProps); | |
}); | |
return function (value, ctx) { | |
var ok = itemCheckers.every(function (checker) { | |
return checker(value, ctx); | |
}); | |
if (ok) { | |
return true; | |
} | |
return ctx.fail(null, null, 0); | |
}; | |
}; | |
return TIntersection3; | |
})(TType2); | |
exports.TIntersection = TIntersection2; | |
function enumtype2(values) { | |
return new TEnumType2(values); | |
} | |
exports.enumtype = enumtype2; | |
var TEnumType2 = (function (_super) { | |
__extends(TEnumType3, _super); | |
function TEnumType3(members) { | |
var _this = _super.call(this) || this; | |
_this.members = members; | |
_this.validValues = new Set(); | |
_this._failMsg = "is not a valid enum value"; | |
_this.validValues = new Set( | |
Object.keys(members).map(function (name3) { | |
return members[name3]; | |
}) | |
); | |
return _this; | |
} | |
TEnumType3.prototype.getChecker = function (suite, strict) { | |
var _this = this; | |
return function (value, ctx) { | |
return _this.validValues.has(value) | |
? true | |
: ctx.fail(null, _this._failMsg, 0); | |
}; | |
}; | |
return TEnumType3; | |
})(TType2); | |
exports.TEnumType = TEnumType2; | |
function enumlit2(name3, prop) { | |
return new TEnumLiteral2(name3, prop); | |
} | |
exports.enumlit = enumlit2; | |
var TEnumLiteral2 = (function (_super) { | |
__extends(TEnumLiteral3, _super); | |
function TEnumLiteral3(enumName, prop) { | |
var _this = _super.call(this) || this; | |
_this.enumName = enumName; | |
_this.prop = prop; | |
_this._failMsg = "is not " + enumName + "." + prop; | |
return _this; | |
} | |
TEnumLiteral3.prototype.getChecker = function (suite, strict) { | |
var _this = this; | |
var ttype = getNamedType(suite, this.enumName); | |
if (!(ttype instanceof TEnumType2)) { | |
throw new Error( | |
"Type " + this.enumName + " used in enumlit is not an enum type" | |
); | |
} | |
var val = ttype.members[this.prop]; | |
if (!ttype.members.hasOwnProperty(this.prop)) { | |
throw new Error( | |
"Unknown value " + | |
this.enumName + | |
"." + | |
this.prop + | |
" used in enumlit" | |
); | |
} | |
return function (value, ctx) { | |
return value === val ? true : ctx.fail(null, _this._failMsg, -1); | |
}; | |
}; | |
return TEnumLiteral3; | |
})(TType2); | |
exports.TEnumLiteral = TEnumLiteral2; | |
function makeIfaceProps(props) { | |
return Object.keys(props).map(function (name3) { | |
return makeIfaceProp(name3, props[name3]); | |
}); | |
} | |
function makeIfaceProp(name3, prop) { | |
return prop instanceof TOptional2 | |
? new TProp2(name3, prop.ttype, true) | |
: new TProp2(name3, parseSpec(prop), false); | |
} | |
function iface2(bases, props) { | |
return new TIface2(bases, makeIfaceProps(props)); | |
} | |
exports.iface = iface2; | |
var TIface2 = (function (_super) { | |
__extends(TIface3, _super); | |
function TIface3(bases, props) { | |
var _this = _super.call(this) || this; | |
_this.bases = bases; | |
_this.props = props; | |
_this.propSet = new Set( | |
props.map(function (p) { | |
return p.name; | |
}) | |
); | |
return _this; | |
} | |
TIface3.prototype.getChecker = function (suite, strict, allowedProps) { | |
var _this = this; | |
var baseCheckers = this.bases.map(function (b) { | |
return getNamedType(suite, b).getChecker(suite, strict); | |
}); | |
var propCheckers = this.props.map(function (prop) { | |
return prop.ttype.getChecker(suite, strict); | |
}); | |
var testCtx = new util.NoopContext(); | |
var isPropRequired = this.props.map(function (prop, i) { | |
return !prop.isOpt && !propCheckers[i](void 0, testCtx); | |
}); | |
var checker = function (value, ctx) { | |
if (typeof value !== "object" || value === null) { | |
return ctx.fail(null, "is not an object", 0); | |
} | |
for (var i = 0; i < baseCheckers.length; i++) { | |
if (!baseCheckers[i](value, ctx)) { | |
return false; | |
} | |
} | |
for (var i = 0; i < propCheckers.length; i++) { | |
var name_1 = _this.props[i].name; | |
var v = value[name_1]; | |
if (v === void 0) { | |
if (isPropRequired[i]) { | |
return ctx.fail(name_1, "is missing", 1); | |
} | |
} else { | |
var ok = propCheckers[i](v, ctx); | |
if (!ok) { | |
return ctx.fail(name_1, null, 1); | |
} | |
} | |
} | |
return true; | |
}; | |
if (!strict) { | |
return checker; | |
} | |
var propSet = this.propSet; | |
if (allowedProps) { | |
this.propSet.forEach(function (prop) { | |
return allowedProps.add(prop); | |
}); | |
propSet = allowedProps; | |
} | |
return function (value, ctx) { | |
if (!checker(value, ctx)) { | |
return false; | |
} | |
for (var prop in value) { | |
if (!propSet.has(prop)) { | |
return ctx.fail(prop, "is extraneous", 2); | |
} | |
} | |
return true; | |
}; | |
}; | |
return TIface3; | |
})(TType2); | |
exports.TIface = TIface2; | |
function opt2(typeSpec) { | |
return new TOptional2(parseSpec(typeSpec)); | |
} | |
exports.opt = opt2; | |
var TOptional2 = (function (_super) { | |
__extends(TOptional3, _super); | |
function TOptional3(ttype) { | |
var _this = _super.call(this) || this; | |
_this.ttype = ttype; | |
return _this; | |
} | |
TOptional3.prototype.getChecker = function (suite, strict) { | |
var itemChecker = this.ttype.getChecker(suite, strict); | |
return function (value, ctx) { | |
return value === void 0 || itemChecker(value, ctx); | |
}; | |
}; | |
return TOptional3; | |
})(TType2); | |
exports.TOptional = TOptional2; | |
var TProp2 = (function () { | |
function TProp3(name3, ttype, isOpt) { | |
this.name = name3; | |
this.ttype = ttype; | |
this.isOpt = isOpt; | |
} | |
return TProp3; | |
})(); | |
exports.TProp = TProp2; | |
function func2(resultSpec) { | |
var params = []; | |
for (var _i2 = 1; _i2 < arguments.length; _i2++) { | |
params[_i2 - 1] = arguments[_i2]; | |
} | |
return new TFunc2(new TParamList2(params), parseSpec(resultSpec)); | |
} | |
exports.func = func2; | |
var TFunc2 = (function (_super) { | |
__extends(TFunc3, _super); | |
function TFunc3(paramList, result) { | |
var _this = _super.call(this) || this; | |
_this.paramList = paramList; | |
_this.result = result; | |
return _this; | |
} | |
TFunc3.prototype.getChecker = function (suite, strict) { | |
return function (value, ctx) { | |
return typeof value === "function" | |
? true | |
: ctx.fail(null, "is not a function", 0); | |
}; | |
}; | |
return TFunc3; | |
})(TType2); | |
exports.TFunc = TFunc2; | |
function param2(name3, typeSpec, isOpt) { | |
return new TParam2(name3, parseSpec(typeSpec), Boolean(isOpt)); | |
} | |
exports.param = param2; | |
var TParam2 = (function () { | |
function TParam3(name3, ttype, isOpt) { | |
this.name = name3; | |
this.ttype = ttype; | |
this.isOpt = isOpt; | |
} | |
return TParam3; | |
})(); | |
exports.TParam = TParam2; | |
var TParamList2 = (function (_super) { | |
__extends(TParamList3, _super); | |
function TParamList3(params) { | |
var _this = _super.call(this) || this; | |
_this.params = params; | |
return _this; | |
} | |
TParamList3.prototype.getChecker = function (suite, strict) { | |
var _this = this; | |
var itemCheckers = this.params.map(function (t) { | |
return t.ttype.getChecker(suite, strict); | |
}); | |
var testCtx = new util.NoopContext(); | |
var isParamRequired = this.params.map(function (param3, i) { | |
return !param3.isOpt && !itemCheckers[i](void 0, testCtx); | |
}); | |
var checker = function (value, ctx) { | |
if (!Array.isArray(value)) { | |
return ctx.fail(null, "is not an array", 0); | |
} | |
for (var i = 0; i < itemCheckers.length; i++) { | |
var p = _this.params[i]; | |
if (value[i] === void 0) { | |
if (isParamRequired[i]) { | |
return ctx.fail(p.name, "is missing", 1); | |
} | |
} else { | |
var ok = itemCheckers[i](value[i], ctx); | |
if (!ok) { | |
return ctx.fail(p.name, null, 1); | |
} | |
} | |
} | |
return true; | |
}; | |
if (!strict) { | |
return checker; | |
} | |
return function (value, ctx) { | |
if (!checker(value, ctx)) { | |
return false; | |
} | |
return value.length <= itemCheckers.length | |
? true | |
: ctx.fail(itemCheckers.length, "is extraneous", 2); | |
}; | |
}; | |
return TParamList3; | |
})(TType2); | |
exports.TParamList = TParamList2; | |
var BasicType2 = (function (_super) { | |
__extends(BasicType3, _super); | |
function BasicType3(validator, message) { | |
var _this = _super.call(this) || this; | |
_this.validator = validator; | |
_this.message = message; | |
return _this; | |
} | |
BasicType3.prototype.getChecker = function (suite, strict) { | |
var _this = this; | |
return function (value, ctx) { | |
return _this.validator(value) ? true : ctx.fail(null, _this.message, 0); | |
}; | |
}; | |
return BasicType3; | |
})(TType2); | |
exports.BasicType = BasicType2; | |
exports.basicTypes = { | |
any: new BasicType2(function (v) { | |
return true; | |
}, "is invalid"), | |
number: new BasicType2(function (v) { | |
return typeof v === "number"; | |
}, "is not a number"), | |
object: new BasicType2(function (v) { | |
return typeof v === "object" && v; | |
}, "is not an object"), | |
boolean: new BasicType2(function (v) { | |
return typeof v === "boolean"; | |
}, "is not a boolean"), | |
string: new BasicType2(function (v) { | |
return typeof v === "string"; | |
}, "is not a string"), | |
symbol: new BasicType2(function (v) { | |
return typeof v === "symbol"; | |
}, "is not a symbol"), | |
void: new BasicType2(function (v) { | |
return v == null; | |
}, "is not void"), | |
undefined: new BasicType2(function (v) { | |
return v === void 0; | |
}, "is not undefined"), | |
null: new BasicType2(function (v) { | |
return v === null; | |
}, "is not null"), | |
never: new BasicType2(function (v) { | |
return false; | |
}, "is unexpected"), | |
Date: new BasicType2(getIsNativeChecker("[object Date]"), "is not a Date"), | |
RegExp: new BasicType2( | |
getIsNativeChecker("[object RegExp]"), | |
"is not a RegExp" | |
), | |
}; | |
var nativeToString = Object.prototype.toString; | |
function getIsNativeChecker(tag) { | |
return function (v) { | |
return typeof v === "object" && v && nativeToString.call(v) === tag; | |
}; | |
} | |
if (typeof Buffer !== "undefined") { | |
exports.basicTypes.Buffer = new BasicType2(function (v) { | |
return Buffer.isBuffer(v); | |
}, "is not a Buffer"); | |
} | |
var _loop_1 = function (array_12) { | |
exports.basicTypes[array_12.name] = new BasicType2(function (v) { | |
return v instanceof array_12; | |
}, "is not a " + array_12.name); | |
}; | |
for ( | |
var _i = 0, | |
_a = [ | |
Int8Array, | |
Uint8Array, | |
Uint8ClampedArray, | |
Int16Array, | |
Uint16Array, | |
Int32Array, | |
Uint32Array, | |
Float32Array, | |
Float64Array, | |
ArrayBuffer, | |
]; | |
_i < _a.length; | |
_i++ | |
) { | |
var array_1 = _a[_i]; | |
_loop_1(array_1); | |
} | |
}); | |
var dist = createCommonjsModule(function (module, exports) { | |
var __spreadArrays = | |
(commonjsGlobal && commonjsGlobal.__spreadArrays) || | |
function () { | |
for (var s = 0, i = 0, il = arguments.length; i < il; i++) | |
s += arguments[i].length; | |
for (var r = Array(s), k = 0, i = 0; i < il; i++) | |
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | |
r[k] = a[j]; | |
return r; | |
}; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
exports.Checker = exports.createCheckers = void 0; | |
var types_2 = types; | |
Object.defineProperty(exports, "TArray", { | |
enumerable: true, | |
get: function () { | |
return types_2.TArray; | |
}, | |
}); | |
Object.defineProperty(exports, "TEnumType", { | |
enumerable: true, | |
get: function () { | |
return types_2.TEnumType; | |
}, | |
}); | |
Object.defineProperty(exports, "TEnumLiteral", { | |
enumerable: true, | |
get: function () { | |
return types_2.TEnumLiteral; | |
}, | |
}); | |
Object.defineProperty(exports, "TFunc", { | |
enumerable: true, | |
get: function () { | |
return types_2.TFunc; | |
}, | |
}); | |
Object.defineProperty(exports, "TIface", { | |
enumerable: true, | |
get: function () { | |
return types_2.TIface; | |
}, | |
}); | |
Object.defineProperty(exports, "TLiteral", { | |
enumerable: true, | |
get: function () { | |
return types_2.TLiteral; | |
}, | |
}); | |
Object.defineProperty(exports, "TName", { | |
enumerable: true, | |
get: function () { | |
return types_2.TName; | |
}, | |
}); | |
Object.defineProperty(exports, "TOptional", { | |
enumerable: true, | |
get: function () { | |
return types_2.TOptional; | |
}, | |
}); | |
Object.defineProperty(exports, "TParam", { | |
enumerable: true, | |
get: function () { | |
return types_2.TParam; | |
}, | |
}); | |
Object.defineProperty(exports, "TParamList", { | |
enumerable: true, | |
get: function () { | |
return types_2.TParamList; | |
}, | |
}); | |
Object.defineProperty(exports, "TProp", { | |
enumerable: true, | |
get: function () { | |
return types_2.TProp; | |
}, | |
}); | |
Object.defineProperty(exports, "TTuple", { | |
enumerable: true, | |
get: function () { | |
return types_2.TTuple; | |
}, | |
}); | |
Object.defineProperty(exports, "TType", { | |
enumerable: true, | |
get: function () { | |
return types_2.TType; | |
}, | |
}); | |
Object.defineProperty(exports, "TUnion", { | |
enumerable: true, | |
get: function () { | |
return types_2.TUnion; | |
}, | |
}); | |
Object.defineProperty(exports, "TIntersection", { | |
enumerable: true, | |
get: function () { | |
return types_2.TIntersection; | |
}, | |
}); | |
Object.defineProperty(exports, "array", { | |
enumerable: true, | |
get: function () { | |
return types_2.array; | |
}, | |
}); | |
Object.defineProperty(exports, "enumlit", { | |
enumerable: true, | |
get: function () { | |
return types_2.enumlit; | |
}, | |
}); | |
Object.defineProperty(exports, "enumtype", { | |
enumerable: true, | |
get: function () { | |
return types_2.enumtype; | |
}, | |
}); | |
Object.defineProperty(exports, "func", { | |
enumerable: true, | |
get: function () { | |
return types_2.func; | |
}, | |
}); | |
Object.defineProperty(exports, "iface", { | |
enumerable: true, | |
get: function () { | |
return types_2.iface; | |
}, | |
}); | |
Object.defineProperty(exports, "lit", { | |
enumerable: true, | |
get: function () { | |
return types_2.lit; | |
}, | |
}); | |
Object.defineProperty(exports, "name", { | |
enumerable: true, | |
get: function () { | |
return types_2.name; | |
}, | |
}); | |
Object.defineProperty(exports, "opt", { | |
enumerable: true, | |
get: function () { | |
return types_2.opt; | |
}, | |
}); | |
Object.defineProperty(exports, "param", { | |
enumerable: true, | |
get: function () { | |
return types_2.param; | |
}, | |
}); | |
Object.defineProperty(exports, "tuple", { | |
enumerable: true, | |
get: function () { | |
return types_2.tuple; | |
}, | |
}); | |
Object.defineProperty(exports, "union", { | |
enumerable: true, | |
get: function () { | |
return types_2.union; | |
}, | |
}); | |
Object.defineProperty(exports, "intersection", { | |
enumerable: true, | |
get: function () { | |
return types_2.intersection; | |
}, | |
}); | |
Object.defineProperty(exports, "BasicType", { | |
enumerable: true, | |
get: function () { | |
return types_2.BasicType; | |
}, | |
}); | |
var util_2 = util; | |
Object.defineProperty(exports, "VError", { | |
enumerable: true, | |
get: function () { | |
return util_2.VError; | |
}, | |
}); | |
function createCheckers2() { | |
var typeSuite = []; | |
for (var _i = 0; _i < arguments.length; _i++) { | |
typeSuite[_i] = arguments[_i]; | |
} | |
var fullSuite = Object.assign.apply( | |
Object, | |
__spreadArrays([{}, types.basicTypes], typeSuite) | |
); | |
var checkers = {}; | |
for (var _a = 0, typeSuite_1 = typeSuite; _a < typeSuite_1.length; _a++) { | |
var suite_1 = typeSuite_1[_a]; | |
for (var _b = 0, _c = Object.keys(suite_1); _b < _c.length; _b++) { | |
var name2 = _c[_b]; | |
checkers[name2] = new Checker2(fullSuite, suite_1[name2]); | |
} | |
} | |
return checkers; | |
} | |
exports.createCheckers = createCheckers2; | |
var Checker2 = (function () { | |
function Checker3(suite, ttype, _path) { | |
if (_path === void 0) { | |
_path = "value"; | |
} | |
this.suite = suite; | |
this.ttype = ttype; | |
this._path = _path; | |
this.props = new Map(); | |
if (ttype instanceof types.TIface) { | |
for (var _i = 0, _a = ttype.props; _i < _a.length; _i++) { | |
var p = _a[_i]; | |
this.props.set(p.name, p.ttype); | |
} | |
} | |
this.checkerPlain = this.ttype.getChecker(suite, false); | |
this.checkerStrict = this.ttype.getChecker(suite, true); | |
} | |
Checker3.prototype.setReportedPath = function (path) { | |
this._path = path; | |
}; | |
Checker3.prototype.check = function (value) { | |
return this._doCheck(this.checkerPlain, value); | |
}; | |
Checker3.prototype.test = function (value) { | |
return this.checkerPlain(value, new util.NoopContext()); | |
}; | |
Checker3.prototype.validate = function (value) { | |
return this._doValidate(this.checkerPlain, value); | |
}; | |
Checker3.prototype.strictCheck = function (value) { | |
return this._doCheck(this.checkerStrict, value); | |
}; | |
Checker3.prototype.strictTest = function (value) { | |
return this.checkerStrict(value, new util.NoopContext()); | |
}; | |
Checker3.prototype.strictValidate = function (value) { | |
return this._doValidate(this.checkerStrict, value); | |
}; | |
Checker3.prototype.getProp = function (prop) { | |
var ttype = this.props.get(prop); | |
if (!ttype) { | |
throw new Error("Type has no property " + prop); | |
} | |
return new Checker3(this.suite, ttype, this._path + "." + prop); | |
}; | |
Checker3.prototype.methodArgs = function (methodName) { | |
var tfunc = this._getMethod(methodName); | |
return new Checker3(this.suite, tfunc.paramList); | |
}; | |
Checker3.prototype.methodResult = function (methodName) { | |
var tfunc = this._getMethod(methodName); | |
return new Checker3(this.suite, tfunc.result); | |
}; | |
Checker3.prototype.getArgs = function () { | |
if (!(this.ttype instanceof types.TFunc)) { | |
throw new Error("getArgs() applied to non-function"); | |
} | |
return new Checker3(this.suite, this.ttype.paramList); | |
}; | |
Checker3.prototype.getResult = function () { | |
if (!(this.ttype instanceof types.TFunc)) { | |
throw new Error("getResult() applied to non-function"); | |
} | |
return new Checker3(this.suite, this.ttype.result); | |
}; | |
Checker3.prototype.getType = function () { | |
return this.ttype; | |
}; | |
Checker3.prototype._doCheck = function (checkerFunc, value) { | |
var noopCtx = new util.NoopContext(); | |
if (!checkerFunc(value, noopCtx)) { | |
var detailCtx = new util.DetailContext(); | |
checkerFunc(value, detailCtx); | |
throw detailCtx.getError(this._path); | |
} | |
}; | |
Checker3.prototype._doValidate = function (checkerFunc, value) { | |
var noopCtx = new util.NoopContext(); | |
if (checkerFunc(value, noopCtx)) { | |
return null; | |
} | |
var detailCtx = new util.DetailContext(); | |
checkerFunc(value, detailCtx); | |
return detailCtx.getErrorDetail(this._path); | |
}; | |
Checker3.prototype._getMethod = function (methodName) { | |
var ttype = this.props.get(methodName); | |
if (!ttype) { | |
throw new Error("Type has no property " + methodName); | |
} | |
if (!(ttype instanceof types.TFunc)) { | |
throw new Error("Property " + methodName + " is not a method"); | |
} | |
return ttype; | |
}; | |
return Checker3; | |
})(); | |
exports.Checker = Checker2; | |
}); | |
var __pika_web_default_export_for_treeshaking__ = /* @__PURE__ */ getDefaultExportFromCjs( | |
dist | |
); | |
var BasicType = dist.BasicType; | |
var Checker = dist.Checker; | |
var TArray = dist.TArray; | |
var TEnumLiteral = dist.TEnumLiteral; | |
var TEnumType = dist.TEnumType; | |
var TFunc = dist.TFunc; | |
var TIface = dist.TIface; | |
var TIntersection = dist.TIntersection; | |
var TLiteral = dist.TLiteral; | |
var TName = dist.TName; | |
var TOptional = dist.TOptional; | |
var TParam = dist.TParam; | |
var TParamList = dist.TParamList; | |
var TProp = dist.TProp; | |
var TTuple = dist.TTuple; | |
var TType = dist.TType; | |
var TUnion = dist.TUnion; | |
var VError = dist.VError; | |
var array = dist.array; | |
var createCheckers = dist.createCheckers; | |
var enumlit = dist.enumlit; | |
var enumtype = dist.enumtype; | |
var func = dist.func; | |
var iface = dist.iface; | |
var intersection = dist.intersection; | |
var lit = dist.lit; | |
var name = dist.name; | |
var opt = dist.opt; | |
var param = dist.param; | |
var tuple = dist.tuple; | |
var union = dist.union; | |
var LF = "\n"; | |
var CR = "\r"; | |
var LinesAndColumns = (function () { | |
function LinesAndColumns2(string) { | |
this.string = string; | |
var offsets = [0]; | |
for (var offset = 0; offset < string.length; ) { | |
switch (string[offset]) { | |
case LF: | |
offset += LF.length; | |
offsets.push(offset); | |
break; | |
case CR: | |
offset += CR.length; | |
if (string[offset] === LF) { | |
offset += LF.length; | |
} | |
offsets.push(offset); | |
break; | |
default: | |
offset++; | |
break; | |
} | |
} | |
this.offsets = offsets; | |
} | |
LinesAndColumns2.prototype.locationForIndex = function (index) { | |
if (index < 0 || index > this.string.length) { | |
return null; | |
} | |
var line = 0; | |
var offsets = this.offsets; | |
while (offsets[line + 1] <= index) { | |
line++; | |
} | |
var column = index - offsets[line]; | |
return { line, column }; | |
}; | |
LinesAndColumns2.prototype.indexForLocation = function (location) { | |
var line = location.line, | |
column = location.column; | |
if (line < 0 || line >= this.offsets.length) { | |
return null; | |
} | |
if (column < 0 || column > this.lengthOfLine(line)) { | |
return null; | |
} | |
return this.offsets[line] + column; | |
}; | |
LinesAndColumns2.prototype.lengthOfLine = function (line) { | |
var offset = this.offsets[line]; | |
var nextOffset = | |
line === this.offsets.length - 1 | |
? this.string.length | |
: this.offsets[line + 1]; | |
return nextOffset - offset; | |
}; | |
return LinesAndColumns2; | |
})(); | |
var ContextualKeyword; | |
(function (ContextualKeyword2) { | |
const NONE = 0; | |
ContextualKeyword2[(ContextualKeyword2["NONE"] = NONE)] = "NONE"; | |
const _abstract = NONE + 1; | |
ContextualKeyword2[(ContextualKeyword2["_abstract"] = _abstract)] = | |
"_abstract"; | |
const _as = _abstract + 1; | |
ContextualKeyword2[(ContextualKeyword2["_as"] = _as)] = "_as"; | |
const _asserts = _as + 1; | |
ContextualKeyword2[(ContextualKeyword2["_asserts"] = _asserts)] = "_asserts"; | |
const _async = _asserts + 1; | |
ContextualKeyword2[(ContextualKeyword2["_async"] = _async)] = "_async"; | |
const _await = _async + 1; | |
ContextualKeyword2[(ContextualKeyword2["_await"] = _await)] = "_await"; | |
const _checks = _await + 1; | |
ContextualKeyword2[(ContextualKeyword2["_checks"] = _checks)] = "_checks"; | |
const _constructor = _checks + 1; | |
ContextualKeyword2[(ContextualKeyword2["_constructor"] = _constructor)] = | |
"_constructor"; | |
const _declare = _constructor + 1; | |
ContextualKeyword2[(ContextualKeyword2["_declare"] = _declare)] = "_declare"; | |
const _enum = _declare + 1; | |
ContextualKeyword2[(ContextualKeyword2["_enum"] = _enum)] = "_enum"; | |
const _exports = _enum + 1; | |
ContextualKeyword2[(ContextualKeyword2["_exports"] = _exports)] = "_exports"; | |
const _from = _exports + 1; | |
ContextualKeyword2[(ContextualKeyword2["_from"] = _from)] = "_from"; | |
const _get = _from + 1; | |
ContextualKeyword2[(ContextualKeyword2["_get"] = _get)] = "_get"; | |
const _global = _get + 1; | |
ContextualKeyword2[(ContextualKeyword2["_global"] = _global)] = "_global"; | |
const _implements = _global + 1; | |
ContextualKeyword2[(ContextualKeyword2["_implements"] = _implements)] = | |
"_implements"; | |
const _infer = _implements + 1; | |
ContextualKeyword2[(ContextualKeyword2["_infer"] = _infer)] = "_infer"; | |
const _interface = _infer + 1; | |
ContextualKeyword2[(ContextualKeyword2["_interface"] = _interface)] = | |
"_interface"; | |
const _is = _interface + 1; | |
ContextualKeyword2[(ContextualKeyword2["_is"] = _is)] = "_is"; | |
const _keyof = _is + 1; | |
ContextualKeyword2[(ContextualKeyword2["_keyof"] = _keyof)] = "_keyof"; | |
const _mixins = _keyof + 1; | |
ContextualKeyword2[(ContextualKeyword2["_mixins"] = _mixins)] = "_mixins"; | |
const _module = _mixins + 1; | |
ContextualKeyword2[(ContextualKeyword2["_module"] = _module)] = "_module"; | |
const _namespace = _module + 1; | |
ContextualKeyword2[(ContextualKeyword2["_namespace"] = _namespace)] = | |
"_namespace"; | |
const _of = _namespace + 1; | |
ContextualKeyword2[(ContextualKeyword2["_of"] = _of)] = "_of"; | |
const _opaque = _of + 1; | |
ContextualKeyword2[(ContextualKeyword2["_opaque"] = _opaque)] = "_opaque"; | |
const _private = _opaque + 1; | |
ContextualKeyword2[(ContextualKeyword2["_private"] = _private)] = "_private"; | |
const _protected = _private + 1; | |
ContextualKeyword2[(ContextualKeyword2["_protected"] = _protected)] = | |
"_protected"; | |
const _proto = _protected + 1; | |
ContextualKeyword2[(ContextualKeyword2["_proto"] = _proto)] = "_proto"; | |
const _public = _proto + 1; | |
ContextualKeyword2[(ContextualKeyword2["_public"] = _public)] = "_public"; | |
const _readonly = _public + 1; | |
ContextualKeyword2[(ContextualKeyword2["_readonly"] = _readonly)] = | |
"_readonly"; | |
const _require = _readonly + 1; | |
ContextualKeyword2[(ContextualKeyword2["_require"] = _require)] = "_require"; | |
const _set = _require + 1; | |
ContextualKeyword2[(ContextualKeyword2["_set"] = _set)] = "_set"; | |
const _static = _set + 1; | |
ContextualKeyword2[(ContextualKeyword2["_static"] = _static)] = "_static"; | |
const _type = _static + 1; | |
ContextualKeyword2[(ContextualKeyword2["_type"] = _type)] = "_type"; | |
const _unique = _type + 1; | |
ContextualKeyword2[(ContextualKeyword2["_unique"] = _unique)] = "_unique"; | |
})(ContextualKeyword || (ContextualKeyword = {})); | |
var TokenType; | |
(function (TokenType2) { | |
const PRECEDENCE_MASK = 15; | |
TokenType2[(TokenType2["PRECEDENCE_MASK"] = PRECEDENCE_MASK)] = | |
"PRECEDENCE_MASK"; | |
const IS_KEYWORD = 1 << 4; | |
TokenType2[(TokenType2["IS_KEYWORD"] = IS_KEYWORD)] = "IS_KEYWORD"; | |
const IS_ASSIGN = 1 << 5; | |
TokenType2[(TokenType2["IS_ASSIGN"] = IS_ASSIGN)] = "IS_ASSIGN"; | |
const IS_RIGHT_ASSOCIATIVE = 1 << 6; | |
TokenType2[(TokenType2["IS_RIGHT_ASSOCIATIVE"] = IS_RIGHT_ASSOCIATIVE)] = | |
"IS_RIGHT_ASSOCIATIVE"; | |
const IS_PREFIX = 1 << 7; | |
TokenType2[(TokenType2["IS_PREFIX"] = IS_PREFIX)] = "IS_PREFIX"; | |
const IS_POSTFIX = 1 << 8; | |
TokenType2[(TokenType2["IS_POSTFIX"] = IS_POSTFIX)] = "IS_POSTFIX"; | |
const num = 0; | |
TokenType2[(TokenType2["num"] = num)] = "num"; | |
const bigint = 512; | |
TokenType2[(TokenType2["bigint"] = bigint)] = "bigint"; | |
const decimal = 1024; | |
TokenType2[(TokenType2["decimal"] = decimal)] = "decimal"; | |
const regexp = 1536; | |
TokenType2[(TokenType2["regexp"] = regexp)] = "regexp"; | |
const string = 2048; | |
TokenType2[(TokenType2["string"] = string)] = "string"; | |
const name = 2560; | |
TokenType2[(TokenType2["name"] = name)] = "name"; | |
const eof = 3072; | |
TokenType2[(TokenType2["eof"] = eof)] = "eof"; | |
const bracketL = 3584; | |
TokenType2[(TokenType2["bracketL"] = bracketL)] = "bracketL"; | |
const bracketR = 4096; | |
TokenType2[(TokenType2["bracketR"] = bracketR)] = "bracketR"; | |
const braceL = 4608; | |
TokenType2[(TokenType2["braceL"] = braceL)] = "braceL"; | |
const braceBarL = 5120; | |
TokenType2[(TokenType2["braceBarL"] = braceBarL)] = "braceBarL"; | |
const braceR = 5632; | |
TokenType2[(TokenType2["braceR"] = braceR)] = "braceR"; | |
const braceBarR = 6144; | |
TokenType2[(TokenType2["braceBarR"] = braceBarR)] = "braceBarR"; | |
const parenL = 6656; | |
TokenType2[(TokenType2["parenL"] = parenL)] = "parenL"; | |
const parenR = 7168; | |
TokenType2[(TokenType2["parenR"] = parenR)] = "parenR"; | |
const comma = 7680; | |
TokenType2[(TokenType2["comma"] = comma)] = "comma"; | |
const semi = 8192; | |
TokenType2[(TokenType2["semi"] = semi)] = "semi"; | |
const colon = 8704; | |
TokenType2[(TokenType2["colon"] = colon)] = "colon"; | |
const doubleColon = 9216; | |
TokenType2[(TokenType2["doubleColon"] = doubleColon)] = "doubleColon"; | |
const dot = 9728; | |
TokenType2[(TokenType2["dot"] = dot)] = "dot"; | |
const question = 10240; | |
TokenType2[(TokenType2["question"] = question)] = "question"; | |
const questionDot = 10752; | |
TokenType2[(TokenType2["questionDot"] = questionDot)] = "questionDot"; | |
const arrow = 11264; | |
TokenType2[(TokenType2["arrow"] = arrow)] = "arrow"; | |
const template = 11776; | |
TokenType2[(TokenType2["template"] = template)] = "template"; | |
const ellipsis = 12288; | |
TokenType2[(TokenType2["ellipsis"] = ellipsis)] = "ellipsis"; | |
const backQuote = 12800; | |
TokenType2[(TokenType2["backQuote"] = backQuote)] = "backQuote"; | |
const dollarBraceL = 13312; | |
TokenType2[(TokenType2["dollarBraceL"] = dollarBraceL)] = "dollarBraceL"; | |
const at = 13824; | |
TokenType2[(TokenType2["at"] = at)] = "at"; | |
const hash = 14336; | |
TokenType2[(TokenType2["hash"] = hash)] = "hash"; | |
const eq = 14880; | |
TokenType2[(TokenType2["eq"] = eq)] = "eq"; | |
const assign = 15392; | |
TokenType2[(TokenType2["assign"] = assign)] = "assign"; | |
const preIncDec = 16256; | |
TokenType2[(TokenType2["preIncDec"] = preIncDec)] = "preIncDec"; | |
const postIncDec = 16768; | |
TokenType2[(TokenType2["postIncDec"] = postIncDec)] = "postIncDec"; | |
const bang = 17024; | |
TokenType2[(TokenType2["bang"] = bang)] = "bang"; | |
const tilde = 17536; | |
TokenType2[(TokenType2["tilde"] = tilde)] = "tilde"; | |
const pipeline = 17921; | |
TokenType2[(TokenType2["pipeline"] = pipeline)] = "pipeline"; | |
const nullishCoalescing = 18434; | |
TokenType2[(TokenType2["nullishCoalescing"] = nullishCoalescing)] = | |
"nullishCoalescing"; | |
const logicalOR = 18946; | |
TokenType2[(TokenType2["logicalOR"] = logicalOR)] = "logicalOR"; | |
const logicalAND = 19459; | |
TokenType2[(TokenType2["logicalAND"] = logicalAND)] = "logicalAND"; | |
const bitwiseOR = 19972; | |
TokenType2[(TokenType2["bitwiseOR"] = bitwiseOR)] = "bitwiseOR"; | |
const bitwiseXOR = 20485; | |
TokenType2[(TokenType2["bitwiseXOR"] = bitwiseXOR)] = "bitwiseXOR"; | |
const bitwiseAND = 20998; | |
TokenType2[(TokenType2["bitwiseAND"] = bitwiseAND)] = "bitwiseAND"; | |
const equality = 21511; | |
TokenType2[(TokenType2["equality"] = equality)] = "equality"; | |
const lessThan = 22024; | |
TokenType2[(TokenType2["lessThan"] = lessThan)] = "lessThan"; | |
const greaterThan = 22536; | |
TokenType2[(TokenType2["greaterThan"] = greaterThan)] = "greaterThan"; | |
const relationalOrEqual = 23048; | |
TokenType2[(TokenType2["relationalOrEqual"] = relationalOrEqual)] = | |
"relationalOrEqual"; | |
const bitShift = 23561; | |
TokenType2[(TokenType2["bitShift"] = bitShift)] = "bitShift"; | |
const plus = 24202; | |
TokenType2[(TokenType2["plus"] = plus)] = "plus"; | |
const minus = 24714; | |
TokenType2[(TokenType2["minus"] = minus)] = "minus"; | |
const modulo = 25099; | |
TokenType2[(TokenType2["modulo"] = modulo)] = "modulo"; | |
const star = 25611; | |
TokenType2[(TokenType2["star"] = star)] = "star"; | |
const slash = 26123; | |
TokenType2[(TokenType2["slash"] = slash)] = "slash"; | |
const exponent = 26700; | |
TokenType2[(TokenType2["exponent"] = exponent)] = "exponent"; | |
const jsxName = 27136; | |
TokenType2[(TokenType2["jsxName"] = jsxName)] = "jsxName"; | |
const jsxText = 27648; | |
TokenType2[(TokenType2["jsxText"] = jsxText)] = "jsxText"; | |
const jsxTagStart = 28160; | |
TokenType2[(TokenType2["jsxTagStart"] = jsxTagStart)] = "jsxTagStart"; | |
const jsxTagEnd = 28672; | |
TokenType2[(TokenType2["jsxTagEnd"] = jsxTagEnd)] = "jsxTagEnd"; | |
const typeParameterStart = 29184; | |
TokenType2[(TokenType2["typeParameterStart"] = typeParameterStart)] = | |
"typeParameterStart"; | |
const nonNullAssertion = 29696; | |
TokenType2[(TokenType2["nonNullAssertion"] = nonNullAssertion)] = | |
"nonNullAssertion"; | |
const _break = 30224; | |
TokenType2[(TokenType2["_break"] = _break)] = "_break"; | |
const _case = 30736; | |
TokenType2[(TokenType2["_case"] = _case)] = "_case"; | |
const _catch = 31248; | |
TokenType2[(TokenType2["_catch"] = _catch)] = "_catch"; | |
const _continue = 31760; | |
TokenType2[(TokenType2["_continue"] = _continue)] = "_continue"; | |
const _debugger = 32272; | |
TokenType2[(TokenType2["_debugger"] = _debugger)] = "_debugger"; | |
const _default = 32784; | |
TokenType2[(TokenType2["_default"] = _default)] = "_default"; | |
const _do = 33296; | |
TokenType2[(TokenType2["_do"] = _do)] = "_do"; | |
const _else = 33808; | |
TokenType2[(TokenType2["_else"] = _else)] = "_else"; | |
const _finally = 34320; | |
TokenType2[(TokenType2["_finally"] = _finally)] = "_finally"; | |
const _for = 34832; | |
TokenType2[(TokenType2["_for"] = _for)] = "_for"; | |
const _function = 35344; | |
TokenType2[(TokenType2["_function"] = _function)] = "_function"; | |
const _if = 35856; | |
TokenType2[(TokenType2["_if"] = _if)] = "_if"; | |
const _return = 36368; | |
TokenType2[(TokenType2["_return"] = _return)] = "_return"; | |
const _switch = 36880; | |
TokenType2[(TokenType2["_switch"] = _switch)] = "_switch"; | |
const _throw = 37520; | |
TokenType2[(TokenType2["_throw"] = _throw)] = "_throw"; | |
const _try = 37904; | |
TokenType2[(TokenType2["_try"] = _try)] = "_try"; | |
const _var = 38416; | |
TokenType2[(TokenType2["_var"] = _var)] = "_var"; | |
const _let = 38928; | |
TokenType2[(TokenType2["_let"] = _let)] = "_let"; | |
const _const = 39440; | |
TokenType2[(TokenType2["_const"] = _const)] = "_const"; | |
const _while = 39952; | |
TokenType2[(TokenType2["_while"] = _while)] = "_while"; | |
const _with = 40464; | |
TokenType2[(TokenType2["_with"] = _with)] = "_with"; | |
const _new = 40976; | |
TokenType2[(TokenType2["_new"] = _new)] = "_new"; | |
const _this = 41488; | |
TokenType2[(TokenType2["_this"] = _this)] = "_this"; | |
const _super = 42e3; | |
TokenType2[(TokenType2["_super"] = _super)] = "_super"; | |
const _class = 42512; | |
TokenType2[(TokenType2["_class"] = _class)] = "_class"; | |
const _extends = 43024; | |
TokenType2[(TokenType2["_extends"] = _extends)] = "_extends"; | |
const _export = 43536; | |
TokenType2[(TokenType2["_export"] = _export)] = "_export"; | |
const _import = 44048; | |
TokenType2[(TokenType2["_import"] = _import)] = "_import"; | |
const _yield = 44560; | |
TokenType2[(TokenType2["_yield"] = _yield)] = "_yield"; | |
const _null = 45072; | |
TokenType2[(TokenType2["_null"] = _null)] = "_null"; | |
const _true = 45584; | |
TokenType2[(TokenType2["_true"] = _true)] = "_true"; | |
const _false = 46096; | |
TokenType2[(TokenType2["_false"] = _false)] = "_false"; | |
const _in = 46616; | |
TokenType2[(TokenType2["_in"] = _in)] = "_in"; | |
const _instanceof = 47128; | |
TokenType2[(TokenType2["_instanceof"] = _instanceof)] = "_instanceof"; | |
const _typeof = 47760; | |
TokenType2[(TokenType2["_typeof"] = _typeof)] = "_typeof"; | |
const _void = 48272; | |
TokenType2[(TokenType2["_void"] = _void)] = "_void"; | |
const _delete = 48784; | |
TokenType2[(TokenType2["_delete"] = _delete)] = "_delete"; | |
const _async = 49168; | |
TokenType2[(TokenType2["_async"] = _async)] = "_async"; | |
const _get = 49680; | |
TokenType2[(TokenType2["_get"] = _get)] = "_get"; | |
const _set = 50192; | |
TokenType2[(TokenType2["_set"] = _set)] = "_set"; | |
const _declare = 50704; | |
TokenType2[(TokenType2["_declare"] = _declare)] = "_declare"; | |
const _readonly = 51216; | |
TokenType2[(TokenType2["_readonly"] = _readonly)] = "_readonly"; | |
const _abstract = 51728; | |
TokenType2[(TokenType2["_abstract"] = _abstract)] = "_abstract"; | |
const _static = 52240; | |
TokenType2[(TokenType2["_static"] = _static)] = "_static"; | |
const _public = 52752; | |
TokenType2[(TokenType2["_public"] = _public)] = "_public"; | |
const _private = 53264; | |
TokenType2[(TokenType2["_private"] = _private)] = "_private"; | |
const _protected = 53776; | |
TokenType2[(TokenType2["_protected"] = _protected)] = "_protected"; | |
const _as = 54288; | |
TokenType2[(TokenType2["_as"] = _as)] = "_as"; | |
const _enum = 54800; | |
TokenType2[(TokenType2["_enum"] = _enum)] = "_enum"; | |
const _type = 55312; | |
TokenType2[(TokenType2["_type"] = _type)] = "_type"; | |
const _implements = 55824; | |
TokenType2[(TokenType2["_implements"] = _implements)] = "_implements"; | |
})(TokenType || (TokenType = {})); | |
function formatTokenType(tokenType) { | |
switch (tokenType) { | |
case TokenType.num: | |
return "num"; | |
case TokenType.bigint: | |
return "bigint"; | |
case TokenType.decimal: | |
return "decimal"; | |
case TokenType.regexp: | |
return "regexp"; | |
case TokenType.string: | |
return "string"; | |
case TokenType.name: | |
return "name"; | |
case TokenType.eof: | |
return "eof"; | |
case TokenType.bracketL: | |
return "["; | |
case TokenType.bracketR: | |
return "]"; | |
case TokenType.braceL: | |
return "{"; | |
case TokenType.braceBarL: | |
return "{|"; | |
case TokenType.braceR: | |
return "}"; | |
case TokenType.braceBarR: | |
return "|}"; | |
case TokenType.parenL: | |
return "("; | |
case TokenType.parenR: | |
return ")"; | |
case TokenType.comma: | |
return ","; | |
case TokenType.semi: | |
return ";"; | |
case TokenType.colon: | |
return ":"; | |
case TokenType.doubleColon: | |
return "::"; | |
case TokenType.dot: | |
return "."; | |
case TokenType.question: | |
return "?"; | |
case TokenType.questionDot: | |
return "?."; | |
case TokenType.arrow: | |
return "=>"; | |
case TokenType.template: | |
return "template"; | |
case TokenType.ellipsis: | |
return "..."; | |
case TokenType.backQuote: | |
return "`"; | |
case TokenType.dollarBraceL: | |
return "${"; | |
case TokenType.at: | |
return "@"; | |
case TokenType.hash: | |
return "#"; | |
case TokenType.eq: | |
return "="; | |
case TokenType.assign: | |
return "_="; | |
case TokenType.preIncDec: | |
return "++/--"; | |
case TokenType.postIncDec: | |
return "++/--"; | |
case TokenType.bang: | |
return "!"; | |
case TokenType.tilde: | |
return "~"; | |
case TokenType.pipeline: | |
return "|>"; | |
case TokenType.nullishCoalescing: | |
return "??"; | |
case TokenType.logicalOR: | |
return "||"; | |
case TokenType.logicalAND: | |
return "&&"; | |
case TokenType.bitwiseOR: | |
return "|"; | |
case TokenType.bitwiseXOR: | |
return "^"; | |
case TokenType.bitwiseAND: | |
return "&"; | |
case TokenType.equality: | |
return "==/!="; | |
case TokenType.lessThan: | |
return "<"; | |
case TokenType.greaterThan: | |
return ">"; | |
case TokenType.relationalOrEqual: | |
return "<=/>="; | |
case TokenType.bitShift: | |
return "<</>>"; | |
case TokenType.plus: | |
return "+"; | |
case TokenType.minus: | |
return "-"; | |
case TokenType.modulo: | |
return "%"; | |
case TokenType.star: | |
return "*"; | |
case TokenType.slash: | |
return "/"; | |
case TokenType.exponent: | |
return "**"; | |
case TokenType.jsxName: | |
return "jsxName"; | |
case TokenType.jsxText: | |
return "jsxText"; | |
case TokenType.jsxTagStart: | |
return "jsxTagStart"; | |
case TokenType.jsxTagEnd: | |
return "jsxTagEnd"; | |
case TokenType.typeParameterStart: | |
return "typeParameterStart"; | |
case TokenType.nonNullAssertion: | |
return "nonNullAssertion"; | |
case TokenType._break: | |
return "break"; | |
case TokenType._case: | |
return "case"; | |
case TokenType._catch: | |
return "catch"; | |
case TokenType._continue: | |
return "continue"; | |
case TokenType._debugger: | |
return "debugger"; | |
case TokenType._default: | |
return "default"; | |
case TokenType._do: | |
return "do"; | |
case TokenType._else: | |
return "else"; | |
case TokenType._finally: | |
return "finally"; | |
case TokenType._for: | |
return "for"; | |
case TokenType._function: | |
return "function"; | |
case TokenType._if: | |
return "if"; | |
case TokenType._return: | |
return "return"; | |
case TokenType._switch: | |
return "switch"; | |
case TokenType._throw: | |
return "throw"; | |
case TokenType._try: | |
return "try"; | |
case TokenType._var: | |
return "var"; | |
case TokenType._let: | |
return "let"; | |
case TokenType._const: | |
return "const"; | |
case TokenType._while: | |
return "while"; | |
case TokenType._with: | |
return "with"; | |
case TokenType._new: | |
return "new"; | |
case TokenType._this: | |
return "this"; | |
case TokenType._super: | |
return "super"; | |
case TokenType._class: | |
return "class"; | |
case TokenType._extends: | |
return "extends"; | |
case TokenType._export: | |
return "export"; | |
case TokenType._import: | |
return "import"; | |
case TokenType._yield: | |
return "yield"; | |
case TokenType._null: | |
return "null"; | |
case TokenType._true: | |
return "true"; | |
case TokenType._false: | |
return "false"; | |
case TokenType._in: | |
return "in"; | |
case TokenType._instanceof: | |
return "instanceof"; | |
case TokenType._typeof: | |
return "typeof"; | |
case TokenType._void: | |
return "void"; | |
case TokenType._delete: | |
return "delete"; | |
case TokenType._async: | |
return "async"; | |
case TokenType._get: | |
return "get"; | |
case TokenType._set: | |
return "set"; | |
case TokenType._declare: | |
return "declare"; | |
case TokenType._readonly: | |
return "readonly"; | |
case TokenType._abstract: | |
return "abstract"; | |
case TokenType._static: | |
return "static"; | |
case TokenType._public: | |
return "public"; | |
case TokenType._private: | |
return "private"; | |
case TokenType._protected: | |
return "protected"; | |
case TokenType._as: | |
return "as"; | |
case TokenType._enum: | |
return "enum"; | |
case TokenType._type: | |
return "type"; | |
case TokenType._implements: | |
return "implements"; | |
default: | |
return ""; | |
} | |
} | |
class Scope { | |
constructor(startTokenIndex, endTokenIndex, isFunctionScope) { | |
this.startTokenIndex = startTokenIndex; | |
this.endTokenIndex = endTokenIndex; | |
this.isFunctionScope = isFunctionScope; | |
} | |
} | |
class StateSnapshot { | |
constructor( | |
potentialArrowAt, | |
noAnonFunctionType, | |
tokensLength, | |
scopesLength, | |
pos, | |
type, | |
contextualKeyword, | |
start, | |
end, | |
isType, | |
scopeDepth, | |
error | |
) { | |
this.potentialArrowAt = potentialArrowAt; | |
this.noAnonFunctionType = noAnonFunctionType; | |
this.tokensLength = tokensLength; | |
this.scopesLength = scopesLength; | |
this.pos = pos; | |
this.type = type; | |
this.contextualKeyword = contextualKeyword; | |
this.start = start; | |
this.end = end; | |
this.isType = isType; | |
this.scopeDepth = scopeDepth; | |
this.error = error; | |
} | |
} | |
class State { | |
constructor() { | |
State.prototype.__init.call(this); | |
State.prototype.__init2.call(this); | |
State.prototype.__init3.call(this); | |
State.prototype.__init4.call(this); | |
State.prototype.__init5.call(this); | |
State.prototype.__init6.call(this); | |
State.prototype.__init7.call(this); | |
State.prototype.__init8.call(this); | |
State.prototype.__init9.call(this); | |
State.prototype.__init10.call(this); | |
State.prototype.__init11.call(this); | |
State.prototype.__init12.call(this); | |
} | |
__init() { | |
this.potentialArrowAt = -1; | |
} | |
__init2() { | |
this.noAnonFunctionType = false; | |
} | |
__init3() { | |
this.tokens = []; | |
} | |
__init4() { | |
this.scopes = []; | |
} | |
__init5() { | |
this.pos = 0; | |
} | |
__init6() { | |
this.type = TokenType.eof; | |
} | |
__init7() { | |
this.contextualKeyword = ContextualKeyword.NONE; | |
} | |
__init8() { | |
this.start = 0; | |
} | |
__init9() { | |
this.end = 0; | |
} | |
__init10() { | |
this.isType = false; | |
} | |
__init11() { | |
this.scopeDepth = 0; | |
} | |
__init12() { | |
this.error = null; | |
} | |
snapshot() { | |
return new StateSnapshot( | |
this.potentialArrowAt, | |
this.noAnonFunctionType, | |
this.tokens.length, | |
this.scopes.length, | |
this.pos, | |
this.type, | |
this.contextualKeyword, | |
this.start, | |
this.end, | |
this.isType, | |
this.scopeDepth, | |
this.error | |
); | |
} | |
restoreFromSnapshot(snapshot) { | |
this.potentialArrowAt = snapshot.potentialArrowAt; | |
this.noAnonFunctionType = snapshot.noAnonFunctionType; | |
this.tokens.length = snapshot.tokensLength; | |
this.scopes.length = snapshot.scopesLength; | |
this.pos = snapshot.pos; | |
this.type = snapshot.type; | |
this.contextualKeyword = snapshot.contextualKeyword; | |
this.start = snapshot.start; | |
this.end = snapshot.end; | |
this.isType = snapshot.isType; | |
this.scopeDepth = snapshot.scopeDepth; | |
this.error = snapshot.error; | |
} | |
} | |
var charCodes; | |
(function (charCodes2) { | |
const backSpace = 8; | |
charCodes2[(charCodes2["backSpace"] = backSpace)] = "backSpace"; | |
const lineFeed = 10; | |
charCodes2[(charCodes2["lineFeed"] = lineFeed)] = "lineFeed"; | |
const carriageReturn = 13; | |
charCodes2[(charCodes2["carriageReturn"] = carriageReturn)] = | |
"carriageReturn"; | |
const shiftOut = 14; | |
charCodes2[(charCodes2["shiftOut"] = shiftOut)] = "shiftOut"; | |
const space = 32; | |
charCodes2[(charCodes2["space"] = space)] = "space"; | |
const exclamationMark = 33; | |
charCodes2[(charCodes2["exclamationMark"] = exclamationMark)] = | |
"exclamationMark"; | |
const quotationMark = 34; | |
charCodes2[(charCodes2["quotationMark"] = quotationMark)] = "quotationMark"; | |
const numberSign = 35; | |
charCodes2[(charCodes2["numberSign"] = numberSign)] = "numberSign"; | |
const dollarSign = 36; | |
charCodes2[(charCodes2["dollarSign"] = dollarSign)] = "dollarSign"; | |
const percentSign = 37; | |
charCodes2[(charCodes2["percentSign"] = percentSign)] = "percentSign"; | |
const ampersand = 38; | |
charCodes2[(charCodes2["ampersand"] = ampersand)] = "ampersand"; | |
const apostrophe = 39; | |
charCodes2[(charCodes2["apostrophe"] = apostrophe)] = "apostrophe"; | |
const leftParenthesis = 40; | |
charCodes2[(charCodes2["leftParenthesis"] = leftParenthesis)] = | |
"leftParenthesis"; | |
const rightParenthesis = 41; | |
charCodes2[(charCodes2["rightParenthesis"] = rightParenthesis)] = | |
"rightParenthesis"; | |
const asterisk = 42; | |
charCodes2[(charCodes2["asterisk"] = asterisk)] = "asterisk"; | |
const plusSign = 43; | |
charCodes2[(charCodes2["plusSign"] = plusSign)] = "plusSign"; | |
const comma = 44; | |
charCodes2[(charCodes2["comma"] = comma)] = "comma"; | |
const dash = 45; | |
charCodes2[(charCodes2["dash"] = dash)] = "dash"; | |
const dot = 46; | |
charCodes2[(charCodes2["dot"] = dot)] = "dot"; | |
const slash = 47; | |
charCodes2[(charCodes2["slash"] = slash)] = "slash"; | |
const digit0 = 48; | |
charCodes2[(charCodes2["digit0"] = digit0)] = "digit0"; | |
const digit1 = 49; | |
charCodes2[(charCodes2["digit1"] = digit1)] = "digit1"; | |
const digit2 = 50; | |
charCodes2[(charCodes2["digit2"] = digit2)] = "digit2"; | |
const digit3 = 51; | |
charCodes2[(charCodes2["digit3"] = digit3)] = "digit3"; | |
const digit4 = 52; | |
charCodes2[(charCodes2["digit4"] = digit4)] = "digit4"; | |
const digit5 = 53; | |
charCodes2[(charCodes2["digit5"] = digit5)] = "digit5"; | |
const digit6 = 54; | |
charCodes2[(charCodes2["digit6"] = digit6)] = "digit6"; | |
const digit7 = 55; | |
charCodes2[(charCodes2["digit7"] = digit7)] = "digit7"; | |
const digit8 = 56; | |
charCodes2[(charCodes2["digit8"] = digit8)] = "digit8"; | |
const digit9 = 57; | |
charCodes2[(charCodes2["digit9"] = digit9)] = "digit9"; | |
const colon = 58; | |
charCodes2[(charCodes2["colon"] = colon)] = "colon"; | |
const semicolon2 = 59; | |
charCodes2[(charCodes2["semicolon"] = semicolon2)] = "semicolon"; | |
const lessThan = 60; | |
charCodes2[(charCodes2["lessThan"] = lessThan)] = "lessThan"; | |
const equalsTo = 61; | |
charCodes2[(charCodes2["equalsTo"] = equalsTo)] = "equalsTo"; | |
const greaterThan = 62; | |
charCodes2[(charCodes2["greaterThan"] = greaterThan)] = "greaterThan"; | |
const questionMark = 63; | |
charCodes2[(charCodes2["questionMark"] = questionMark)] = "questionMark"; | |
const atSign = 64; | |
charCodes2[(charCodes2["atSign"] = atSign)] = "atSign"; | |
const uppercaseA = 65; | |
charCodes2[(charCodes2["uppercaseA"] = uppercaseA)] = "uppercaseA"; | |
const uppercaseB = 66; | |
charCodes2[(charCodes2["uppercaseB"] = uppercaseB)] = "uppercaseB"; | |
const uppercaseC = 67; | |
charCodes2[(charCodes2["uppercaseC"] = uppercaseC)] = "uppercaseC"; | |
const uppercaseD = 68; | |
charCodes2[(charCodes2["uppercaseD"] = uppercaseD)] = "uppercaseD"; | |
const uppercaseE = 69; | |
charCodes2[(charCodes2["uppercaseE"] = uppercaseE)] = "uppercaseE"; | |
const uppercaseF = 70; | |
charCodes2[(charCodes2["uppercaseF"] = uppercaseF)] = "uppercaseF"; | |
const uppercaseG = 71; | |
charCodes2[(charCodes2["uppercaseG"] = uppercaseG)] = "uppercaseG"; | |
const uppercaseH = 72; | |
charCodes2[(charCodes2["uppercaseH"] = uppercaseH)] = "uppercaseH"; | |
const uppercaseI = 73; | |
charCodes2[(charCodes2["uppercaseI"] = uppercaseI)] = "uppercaseI"; | |
const uppercaseJ = 74; | |
charCodes2[(charCodes2["uppercaseJ"] = uppercaseJ)] = "uppercaseJ"; | |
const uppercaseK = 75; | |
charCodes2[(charCodes2["uppercaseK"] = uppercaseK)] = "uppercaseK"; | |
const uppercaseL = 76; | |
charCodes2[(charCodes2["uppercaseL"] = uppercaseL)] = "uppercaseL"; | |
const uppercaseM = 77; | |
charCodes2[(charCodes2["uppercaseM"] = uppercaseM)] = "uppercaseM"; | |
const uppercaseN = 78; | |
charCodes2[(charCodes2["uppercaseN"] = uppercaseN)] = "uppercaseN"; | |
const uppercaseO = 79; | |
charCodes2[(charCodes2["uppercaseO"] = uppercaseO)] = "uppercaseO"; | |
const uppercaseP = 80; | |
charCodes2[(charCodes2["uppercaseP"] = uppercaseP)] = "uppercaseP"; | |
const uppercaseQ = 81; | |
charCodes2[(charCodes2["uppercaseQ"] = uppercaseQ)] = "uppercaseQ"; | |
const uppercaseR = 82; | |
charCodes2[(charCodes2["uppercaseR"] = uppercaseR)] = "uppercaseR"; | |
const uppercaseS = 83; | |
charCodes2[(charCodes2["uppercaseS"] = uppercaseS)] = "uppercaseS"; | |
const uppercaseT = 84; | |
charCodes2[(charCodes2["uppercaseT"] = uppercaseT)] = "uppercaseT"; | |
const uppercaseU = 85; | |
charCodes2[(charCodes2["uppercaseU"] = uppercaseU)] = "uppercaseU"; | |
const uppercaseV = 86; | |
charCodes2[(charCodes2["uppercaseV"] = uppercaseV)] = "uppercaseV"; | |
const uppercaseW = 87; | |
charCodes2[(charCodes2["uppercaseW"] = uppercaseW)] = "uppercaseW"; | |
const uppercaseX = 88; | |
charCodes2[(charCodes2["uppercaseX"] = uppercaseX)] = "uppercaseX"; | |
const uppercaseY = 89; | |
charCodes2[(charCodes2["uppercaseY"] = uppercaseY)] = "uppercaseY"; | |
const uppercaseZ = 90; | |
charCodes2[(charCodes2["uppercaseZ"] = uppercaseZ)] = "uppercaseZ"; | |
const leftSquareBracket = 91; | |
charCodes2[(charCodes2["leftSquareBracket"] = leftSquareBracket)] = | |
"leftSquareBracket"; | |
const backslash = 92; | |
charCodes2[(charCodes2["backslash"] = backslash)] = "backslash"; | |
const rightSquareBracket = 93; | |
charCodes2[(charCodes2["rightSquareBracket"] = rightSquareBracket)] = | |
"rightSquareBracket"; | |
const caret = 94; | |
charCodes2[(charCodes2["caret"] = caret)] = "caret"; | |
const underscore = 95; | |
charCodes2[(charCodes2["underscore"] = underscore)] = "underscore"; | |
const graveAccent = 96; | |
charCodes2[(charCodes2["graveAccent"] = graveAccent)] = "graveAccent"; | |
const lowercaseA = 97; | |
charCodes2[(charCodes2["lowercaseA"] = lowercaseA)] = "lowercaseA"; | |
const lowercaseB = 98; | |
charCodes2[(charCodes2["lowercaseB"] = lowercaseB)] = "lowercaseB"; | |
const lowercaseC = 99; | |
charCodes2[(charCodes2["lowercaseC"] = lowercaseC)] = "lowercaseC"; | |
const lowercaseD = 100; | |
charCodes2[(charCodes2["lowercaseD"] = lowercaseD)] = "lowercaseD"; | |
const lowercaseE = 101; | |
charCodes2[(charCodes2["lowercaseE"] = lowercaseE)] = "lowercaseE"; | |
const lowercaseF = 102; | |
charCodes2[(charCodes2["lowercaseF"] = lowercaseF)] = "lowercaseF"; | |
const lowercaseG = 103; | |
charCodes2[(charCodes2["lowercaseG"] = lowercaseG)] = "lowercaseG"; | |
const lowercaseH = 104; | |
charCodes2[(charCodes2["lowercaseH"] = lowercaseH)] = "lowercaseH"; | |
const lowercaseI = 105; | |
charCodes2[(charCodes2["lowercaseI"] = lowercaseI)] = "lowercaseI"; | |
const lowercaseJ = 106; | |
charCodes2[(charCodes2["lowercaseJ"] = lowercaseJ)] = "lowercaseJ"; | |
const lowercaseK = 107; | |
charCodes2[(charCodes2["lowercaseK"] = lowercaseK)] = "lowercaseK"; | |
const lowercaseL = 108; | |
charCodes2[(charCodes2["lowercaseL"] = lowercaseL)] = "lowercaseL"; | |
const lowercaseM = 109; | |
charCodes2[(charCodes2["lowercaseM"] = lowercaseM)] = "lowercaseM"; | |
const lowercaseN = 110; | |
charCodes2[(charCodes2["lowercaseN"] = lowercaseN)] = "lowercaseN"; | |
const lowercaseO = 111; | |
charCodes2[(charCodes2["lowercaseO"] = lowercaseO)] = "lowercaseO"; | |
const lowercaseP = 112; | |
charCodes2[(charCodes2["lowercaseP"] = lowercaseP)] = "lowercaseP"; | |
const lowercaseQ = 113; | |
charCodes2[(charCodes2["lowercaseQ"] = lowercaseQ)] = "lowercaseQ"; | |
const lowercaseR = 114; | |
charCodes2[(charCodes2["lowercaseR"] = lowercaseR)] = "lowercaseR"; | |
const lowercaseS = 115; | |
charCodes2[(charCodes2["lowercaseS"] = lowercaseS)] = "lowercaseS"; | |
const lowercaseT = 116; | |
charCodes2[(charCodes2["lowercaseT"] = lowercaseT)] = "lowercaseT"; | |
const lowercaseU = 117; | |
charCodes2[(charCodes2["lowercaseU"] = lowercaseU)] = "lowercaseU"; | |
const lowercaseV = 118; | |
charCodes2[(charCodes2["lowercaseV"] = lowercaseV)] = "lowercaseV"; | |
const lowercaseW = 119; | |
charCodes2[(charCodes2["lowercaseW"] = lowercaseW)] = "lowercaseW"; | |
const lowercaseX = 120; | |
charCodes2[(charCodes2["lowercaseX"] = lowercaseX)] = "lowercaseX"; | |
const lowercaseY = 121; | |
charCodes2[(charCodes2["lowercaseY"] = lowercaseY)] = "lowercaseY"; | |
const lowercaseZ = 122; | |
charCodes2[(charCodes2["lowercaseZ"] = lowercaseZ)] = "lowercaseZ"; | |
const leftCurlyBrace = 123; | |
charCodes2[(charCodes2["leftCurlyBrace"] = leftCurlyBrace)] = | |
"leftCurlyBrace"; | |
const verticalBar = 124; | |
charCodes2[(charCodes2["verticalBar"] = verticalBar)] = "verticalBar"; | |
const rightCurlyBrace = 125; | |
charCodes2[(charCodes2["rightCurlyBrace"] = rightCurlyBrace)] = | |
"rightCurlyBrace"; | |
const tilde = 126; | |
charCodes2[(charCodes2["tilde"] = tilde)] = "tilde"; | |
const nonBreakingSpace = 160; | |
charCodes2[(charCodes2["nonBreakingSpace"] = nonBreakingSpace)] = | |
"nonBreakingSpace"; | |
const oghamSpaceMark = 5760; | |
charCodes2[(charCodes2["oghamSpaceMark"] = oghamSpaceMark)] = | |
"oghamSpaceMark"; | |
const lineSeparator = 8232; | |
charCodes2[(charCodes2["lineSeparator"] = lineSeparator)] = "lineSeparator"; | |
const paragraphSeparator = 8233; | |
charCodes2[(charCodes2["paragraphSeparator"] = paragraphSeparator)] = | |
"paragraphSeparator"; | |
})(charCodes || (charCodes = {})); | |
let isJSXEnabled; | |
let isTypeScriptEnabled; | |
let isFlowEnabled; | |
let state; | |
let input; | |
let nextContextId; | |
function getNextContextId() { | |
return nextContextId++; | |
} | |
function augmentError(error) { | |
if ("pos" in error) { | |
const loc = locationForIndex(error.pos); | |
error.message += ` (${loc.line}:${loc.column})`; | |
error.loc = loc; | |
} | |
return error; | |
} | |
class Loc { | |
constructor(line, column) { | |
this.line = line; | |
this.column = column; | |
} | |
} | |
function locationForIndex(pos) { | |
let line = 1; | |
let column = 1; | |
for (let i = 0; i < pos; i++) { | |
if (input.charCodeAt(i) === charCodes.lineFeed) { | |
line++; | |
column = 1; | |
} else { | |
column++; | |
} | |
} | |
return new Loc(line, column); | |
} | |
function initParser( | |
inputCode, | |
isJSXEnabledArg, | |
isTypeScriptEnabledArg, | |
isFlowEnabledArg | |
) { | |
input = inputCode; | |
state = new State(); | |
nextContextId = 1; | |
isJSXEnabled = isJSXEnabledArg; | |
isTypeScriptEnabled = isTypeScriptEnabledArg; | |
isFlowEnabled = isFlowEnabledArg; | |
} | |
function isContextual(contextualKeyword) { | |
return state.contextualKeyword === contextualKeyword; | |
} | |
function isLookaheadContextual(contextualKeyword) { | |
const l = lookaheadTypeAndKeyword(); | |
return l.type === TokenType.name && l.contextualKeyword === contextualKeyword; | |
} | |
function eatContextual(contextualKeyword) { | |
return state.contextualKeyword === contextualKeyword && eat(TokenType.name); | |
} | |
function expectContextual(contextualKeyword) { | |
if (!eatContextual(contextualKeyword)) { | |
unexpected(); | |
} | |
} | |
function canInsertSemicolon() { | |
return ( | |
match(TokenType.eof) || match(TokenType.braceR) || hasPrecedingLineBreak() | |
); | |
} | |
function hasPrecedingLineBreak() { | |
const prevToken = state.tokens[state.tokens.length - 1]; | |
const lastTokEnd = prevToken ? prevToken.end : 0; | |
for (let i = lastTokEnd; i < state.start; i++) { | |
const code = input.charCodeAt(i); | |
if ( | |
code === charCodes.lineFeed || | |
code === charCodes.carriageReturn || | |
code === 8232 || | |
code === 8233 | |
) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function isLineTerminator() { | |
return eat(TokenType.semi) || canInsertSemicolon(); | |
} | |
function semicolon() { | |
if (!isLineTerminator()) { | |
unexpected('Unexpected token, expected ";"'); | |
} | |
} | |
function expect(type) { | |
const matched = eat(type); | |
if (!matched) { | |
unexpected(`Unexpected token, expected "${formatTokenType(type)}"`); | |
} | |
} | |
function unexpected(message = "Unexpected token", pos = state.start) { | |
if (state.error) { | |
return; | |
} | |
const err = new SyntaxError(message); | |
err.pos = pos; | |
state.error = err; | |
state.pos = input.length; | |
finishToken(TokenType.eof); | |
} | |
const WHITESPACE_CHARS = [ | |
9, | |
11, | |
12, | |
charCodes.space, | |
charCodes.nonBreakingSpace, | |
charCodes.oghamSpaceMark, | |
8192, | |
8193, | |
8194, | |
8195, | |
8196, | |
8197, | |
8198, | |
8199, | |
8200, | |
8201, | |
8202, | |
8239, | |
8287, | |
12288, | |
65279, | |
]; | |
const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g; | |
const IS_WHITESPACE = new Uint8Array(65536); | |
for (const char of WHITESPACE_CHARS) { | |
IS_WHITESPACE[char] = 1; | |
} | |
function computeIsIdentifierChar(code) { | |
if (code < 48) return code === 36; | |
if (code < 58) return true; | |
if (code < 65) return false; | |
if (code < 91) return true; | |
if (code < 97) return code === 95; | |
if (code < 123) return true; | |
if (code < 128) return false; | |
throw new Error("Should not be called with non-ASCII char code."); | |
} | |
const IS_IDENTIFIER_CHAR = new Uint8Array(65536); | |
for (let i = 0; i < 128; i++) { | |
IS_IDENTIFIER_CHAR[i] = computeIsIdentifierChar(i) ? 1 : 0; | |
} | |
for (let i = 128; i < 65536; i++) { | |
IS_IDENTIFIER_CHAR[i] = 1; | |
} | |
for (const whitespaceChar of WHITESPACE_CHARS) { | |
IS_IDENTIFIER_CHAR[whitespaceChar] = 0; | |
} | |
IS_IDENTIFIER_CHAR[8232] = 0; | |
IS_IDENTIFIER_CHAR[8233] = 0; | |
const IS_IDENTIFIER_START = IS_IDENTIFIER_CHAR.slice(); | |
for (let numChar = charCodes.digit0; numChar <= charCodes.digit9; numChar++) { | |
IS_IDENTIFIER_START[numChar] = 0; | |
} | |
const READ_WORD_TREE = new Int32Array([ | |
-1, | |
27, | |
594, | |
729, | |
1566, | |
2187, | |
2673, | |
3294, | |
-1, | |
3510, | |
-1, | |
4428, | |
4563, | |
4644, | |
4941, | |
5319, | |
5508, | |
-1, | |
6048, | |
6507, | |
6966, | |
7398, | |
7560, | |
7722, | |
-1, | |
7938, | |
-1, | |
-1, | |
-1, | |
54, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
243, | |
-1, | |
-1, | |
-1, | |
486, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
81, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
108, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
135, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
162, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
189, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
216, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._abstract << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._as << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
270, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
405, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
297, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
324, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
351, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
378, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._asserts << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
432, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
459, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._async << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
513, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
540, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
567, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._await << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
621, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
648, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
675, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
702, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._break << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
756, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
918, | |
-1, | |
-1, | |
-1, | |
1053, | |
-1, | |
-1, | |
1161, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
783, | |
837, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
810, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._case << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
864, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
891, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._catch << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
945, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
972, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
999, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1026, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._checks << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1080, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1107, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1134, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._class << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1188, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1215, | |
1431, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1242, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._const << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1269, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1296, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1323, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1350, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1377, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1404, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._constructor << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1458, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1485, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1512, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1539, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._continue << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1593, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2160, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1620, | |
1782, | |
-1, | |
-1, | |
1917, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2052, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1647, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1674, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1701, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1728, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1755, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._debugger << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1809, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1836, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1863, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1890, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._declare << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1944, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1971, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
1998, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2025, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._default << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2079, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2106, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2133, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._delete << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._do << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2214, | |
-1, | |
2295, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2376, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2241, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2268, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._else << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2322, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2349, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._enum << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2403, | |
-1, | |
-1, | |
-1, | |
2538, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2430, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2457, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2484, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._export << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2511, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._exports << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2565, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2592, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2619, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2646, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._extends << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2700, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2808, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2970, | |
-1, | |
-1, | |
3024, | |
-1, | |
-1, | |
3105, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2727, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2754, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2781, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._false << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2835, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2862, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2889, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2916, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2943, | |
-1, | |
(TokenType._finally << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
2997, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._for << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3051, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3078, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._from << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3132, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3159, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3186, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3213, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3240, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3267, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._function << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3321, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3375, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3348, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._get << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3402, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3429, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3456, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3483, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._global << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3537, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3564, | |
3888, | |
-1, | |
-1, | |
-1, | |
-1, | |
4401, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._if << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3591, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3618, | |
-1, | |
-1, | |
3807, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3645, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3672, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3699, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3726, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3753, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3780, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._implements << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3834, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3861, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._import << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._in << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3915, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3996, | |
4212, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3942, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
3969, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._infer << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4023, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4050, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4077, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4104, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4131, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4158, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4185, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._instanceof << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4239, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4266, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4293, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4320, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4347, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4374, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._interface << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._is << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4455, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4482, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4509, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4536, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._keyof << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4590, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4617, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._let << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4671, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4806, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4698, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4725, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4752, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4779, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._mixins << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4833, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4860, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4887, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4914, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._module << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4968, | |
-1, | |
-1, | |
-1, | |
5184, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5238, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
4995, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5022, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5049, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5076, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5103, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5130, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5157, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._namespace << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5211, | |
-1, | |
-1, | |
-1, | |
(TokenType._new << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5265, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5292, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._null << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5346, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5373, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._of << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5400, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5427, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5454, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5481, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._opaque << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5535, | |
-1, | |
-1, | |
5913, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5562, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5697, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5589, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5616, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5643, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5670, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._private << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5724, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5751, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5886, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5778, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5805, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5832, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5859, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._protected << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._proto << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5940, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5967, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
5994, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6021, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._public << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6075, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6102, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6264, | |
-1, | |
-1, | |
6399, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6129, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6156, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6183, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6210, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6237, | |
-1, | |
ContextualKeyword._readonly << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6291, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6318, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6345, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6372, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._require << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6426, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6453, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6480, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._return << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6534, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6588, | |
6723, | |
-1, | |
6831, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6561, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._set << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6615, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6642, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6669, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6696, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._static << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6750, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6777, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6804, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._super << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6858, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6885, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6912, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6939, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._switch << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
6993, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7155, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7263, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7020, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7074, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7047, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._this << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7101, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7128, | |
-1, | |
-1, | |
-1, | |
(TokenType._throw << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7182, | |
-1, | |
-1, | |
-1, | |
7236, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7209, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._true << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._try << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7290, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7317, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._type << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7344, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7371, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._typeof << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7425, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7452, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7479, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7506, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7533, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
ContextualKeyword._unique << 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7587, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7641, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7614, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._var << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7668, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7695, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._void << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7749, | |
7857, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7776, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7803, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7830, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._while << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7884, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7911, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._with << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7965, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
7992, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
8019, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
8046, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
(TokenType._yield << 1) + 1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
]); | |
function readWord() { | |
let treePos = 0; | |
let code = 0; | |
let pos = state.pos; | |
while (pos < input.length) { | |
code = input.charCodeAt(pos); | |
if (code < charCodes.lowercaseA || code > charCodes.lowercaseZ) { | |
break; | |
} | |
const next2 = READ_WORD_TREE[treePos + (code - charCodes.lowercaseA) + 1]; | |
if (next2 === -1) { | |
break; | |
} else { | |
treePos = next2; | |
pos++; | |
} | |
} | |
const keywordValue = READ_WORD_TREE[treePos]; | |
if (keywordValue > -1 && !IS_IDENTIFIER_CHAR[code]) { | |
state.pos = pos; | |
if (keywordValue & 1) { | |
finishToken(keywordValue >>> 1); | |
} else { | |
finishToken(TokenType.name, keywordValue >>> 1); | |
} | |
return; | |
} | |
while (pos < input.length) { | |
const ch = input.charCodeAt(pos); | |
if (IS_IDENTIFIER_CHAR[ch]) { | |
pos++; | |
} else if (ch === charCodes.backslash) { | |
pos += 2; | |
if (input.charCodeAt(pos) === charCodes.leftCurlyBrace) { | |
while ( | |
pos < input.length && | |
input.charCodeAt(pos) !== charCodes.rightCurlyBrace | |
) { | |
pos++; | |
} | |
pos++; | |
} | |
} else if ( | |
ch === charCodes.atSign && | |
input.charCodeAt(pos + 1) === charCodes.atSign | |
) { | |
pos += 2; | |
} else { | |
break; | |
} | |
} | |
state.pos = pos; | |
finishToken(TokenType.name); | |
} | |
var IdentifierRole; | |
(function (IdentifierRole2) { | |
const Access = 0; | |
IdentifierRole2[(IdentifierRole2["Access"] = Access)] = "Access"; | |
const ExportAccess = Access + 1; | |
IdentifierRole2[(IdentifierRole2["ExportAccess"] = ExportAccess)] = | |
"ExportAccess"; | |
const TopLevelDeclaration = ExportAccess + 1; | |
IdentifierRole2[ | |
(IdentifierRole2["TopLevelDeclaration"] = TopLevelDeclaration) | |
] = "TopLevelDeclaration"; | |
const FunctionScopedDeclaration = TopLevelDeclaration + 1; | |
IdentifierRole2[ | |
(IdentifierRole2["FunctionScopedDeclaration"] = FunctionScopedDeclaration) | |
] = "FunctionScopedDeclaration"; | |
const BlockScopedDeclaration = FunctionScopedDeclaration + 1; | |
IdentifierRole2[ | |
(IdentifierRole2["BlockScopedDeclaration"] = BlockScopedDeclaration) | |
] = "BlockScopedDeclaration"; | |
const ObjectShorthandTopLevelDeclaration = BlockScopedDeclaration + 1; | |
IdentifierRole2[ | |
(IdentifierRole2[ | |
"ObjectShorthandTopLevelDeclaration" | |
] = ObjectShorthandTopLevelDeclaration) | |
] = "ObjectShorthandTopLevelDeclaration"; | |
const ObjectShorthandFunctionScopedDeclaration = | |
ObjectShorthandTopLevelDeclaration + 1; | |
IdentifierRole2[ | |
(IdentifierRole2[ | |
"ObjectShorthandFunctionScopedDeclaration" | |
] = ObjectShorthandFunctionScopedDeclaration) | |
] = "ObjectShorthandFunctionScopedDeclaration"; | |
const ObjectShorthandBlockScopedDeclaration = | |
ObjectShorthandFunctionScopedDeclaration + 1; | |
IdentifierRole2[ | |
(IdentifierRole2[ | |
"ObjectShorthandBlockScopedDeclaration" | |
] = ObjectShorthandBlockScopedDeclaration) | |
] = "ObjectShorthandBlockScopedDeclaration"; | |
const ObjectShorthand = ObjectShorthandBlockScopedDeclaration + 1; | |
IdentifierRole2[(IdentifierRole2["ObjectShorthand"] = ObjectShorthand)] = | |
"ObjectShorthand"; | |
const ImportDeclaration = ObjectShorthand + 1; | |
IdentifierRole2[(IdentifierRole2["ImportDeclaration"] = ImportDeclaration)] = | |
"ImportDeclaration"; | |
const ObjectKey = ImportDeclaration + 1; | |
IdentifierRole2[(IdentifierRole2["ObjectKey"] = ObjectKey)] = "ObjectKey"; | |
const ImportAccess = ObjectKey + 1; | |
IdentifierRole2[(IdentifierRole2["ImportAccess"] = ImportAccess)] = | |
"ImportAccess"; | |
})(IdentifierRole || (IdentifierRole = {})); | |
function isDeclaration(token) { | |
const role = token.identifierRole; | |
return ( | |
role === IdentifierRole.TopLevelDeclaration || | |
role === IdentifierRole.FunctionScopedDeclaration || | |
role === IdentifierRole.BlockScopedDeclaration || | |
role === IdentifierRole.ObjectShorthandTopLevelDeclaration || | |
role === IdentifierRole.ObjectShorthandFunctionScopedDeclaration || | |
role === IdentifierRole.ObjectShorthandBlockScopedDeclaration | |
); | |
} | |
function isNonTopLevelDeclaration(token) { | |
const role = token.identifierRole; | |
return ( | |
role === IdentifierRole.FunctionScopedDeclaration || | |
role === IdentifierRole.BlockScopedDeclaration || | |
role === IdentifierRole.ObjectShorthandFunctionScopedDeclaration || | |
role === IdentifierRole.ObjectShorthandBlockScopedDeclaration | |
); | |
} | |
function isTopLevelDeclaration(token) { | |
const role = token.identifierRole; | |
return ( | |
role === IdentifierRole.TopLevelDeclaration || | |
role === IdentifierRole.ObjectShorthandTopLevelDeclaration || | |
role === IdentifierRole.ImportDeclaration | |
); | |
} | |
function isBlockScopedDeclaration(token) { | |
const role = token.identifierRole; | |
return ( | |
role === IdentifierRole.TopLevelDeclaration || | |
role === IdentifierRole.BlockScopedDeclaration || | |
role === IdentifierRole.ObjectShorthandTopLevelDeclaration || | |
role === IdentifierRole.ObjectShorthandBlockScopedDeclaration | |
); | |
} | |
function isFunctionScopedDeclaration(token) { | |
const role = token.identifierRole; | |
return ( | |
role === IdentifierRole.FunctionScopedDeclaration || | |
role === IdentifierRole.ObjectShorthandFunctionScopedDeclaration | |
); | |
} | |
function isObjectShorthandDeclaration(token) { | |
return ( | |
token.identifierRole === | |
IdentifierRole.ObjectShorthandTopLevelDeclaration || | |
token.identifierRole === | |
IdentifierRole.ObjectShorthandBlockScopedDeclaration || | |
token.identifierRole === | |
IdentifierRole.ObjectShorthandFunctionScopedDeclaration | |
); | |
} | |
class Token { | |
constructor() { | |
this.type = state.type; | |
this.contextualKeyword = state.contextualKeyword; | |
this.start = state.start; | |
this.end = state.end; | |
this.scopeDepth = state.scopeDepth; | |
this.isType = state.isType; | |
this.identifierRole = null; | |
this.shadowsGlobal = false; | |
this.contextId = null; | |
this.rhsEndIndex = null; | |
this.isExpression = false; | |
this.numNullishCoalesceStarts = 0; | |
this.numNullishCoalesceEnds = 0; | |
this.isOptionalChainStart = false; | |
this.isOptionalChainEnd = false; | |
this.subscriptStartIndex = null; | |
this.nullishStartIndex = null; | |
} | |
} | |
function next() { | |
state.tokens.push(new Token()); | |
nextToken(); | |
} | |
function nextTemplateToken() { | |
state.tokens.push(new Token()); | |
state.start = state.pos; | |
readTmplToken(); | |
} | |
function retokenizeSlashAsRegex() { | |
if (state.type === TokenType.assign) { | |
--state.pos; | |
} | |
readRegexp(); | |
} | |
function pushTypeContext(existingTokensInType) { | |
for ( | |
let i = state.tokens.length - existingTokensInType; | |
i < state.tokens.length; | |
i++ | |
) { | |
state.tokens[i].isType = true; | |
} | |
const oldIsType = state.isType; | |
state.isType = true; | |
return oldIsType; | |
} | |
function popTypeContext(oldIsType) { | |
state.isType = oldIsType; | |
} | |
function eat(type) { | |
if (match(type)) { | |
next(); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function match(type) { | |
return state.type === type; | |
} | |
function lookaheadType() { | |
const snapshot = state.snapshot(); | |
next(); | |
const type = state.type; | |
state.restoreFromSnapshot(snapshot); | |
return type; | |
} | |
class TypeAndKeyword { | |
constructor(type, contextualKeyword) { | |
this.type = type; | |
this.contextualKeyword = contextualKeyword; | |
} | |
} | |
function lookaheadTypeAndKeyword() { | |
const snapshot = state.snapshot(); | |
next(); | |
const type = state.type; | |
const contextualKeyword = state.contextualKeyword; | |
state.restoreFromSnapshot(snapshot); | |
return new TypeAndKeyword(type, contextualKeyword); | |
} | |
function nextTokenStart() { | |
return nextTokenStartSince(state.pos); | |
} | |
function nextTokenStartSince(pos) { | |
skipWhiteSpace.lastIndex = pos; | |
const skip = skipWhiteSpace.exec(input); | |
return pos + skip[0].length; | |
} | |
function lookaheadCharCode() { | |
return input.charCodeAt(nextTokenStart()); | |
} | |
function nextToken() { | |
skipSpace(); | |
state.start = state.pos; | |
if (state.pos >= input.length) { | |
const tokens = state.tokens; | |
if ( | |
tokens.length >= 2 && | |
tokens[tokens.length - 1].start >= input.length && | |
tokens[tokens.length - 2].start >= input.length | |
) { | |
unexpected("Unexpectedly reached the end of input."); | |
} | |
finishToken(TokenType.eof); | |
return; | |
} | |
readToken(input.charCodeAt(state.pos)); | |
} | |
function readToken(code) { | |
if ( | |
IS_IDENTIFIER_START[code] || | |
code === charCodes.backslash || | |
(code === charCodes.atSign && | |
input.charCodeAt(state.pos + 1) === charCodes.atSign) | |
) { | |
readWord(); | |
} else { | |
getTokenFromCode(code); | |
} | |
} | |
function skipBlockComment() { | |
while ( | |
input.charCodeAt(state.pos) !== charCodes.asterisk || | |
input.charCodeAt(state.pos + 1) !== charCodes.slash | |
) { | |
state.pos++; | |
if (state.pos > input.length) { | |
unexpected("Unterminated comment", state.pos - 2); | |
return; | |
} | |
} | |
state.pos += 2; | |
} | |
function skipLineComment(startSkip) { | |
let ch = input.charCodeAt((state.pos += startSkip)); | |
if (state.pos < input.length) { | |
while ( | |
ch !== charCodes.lineFeed && | |
ch !== charCodes.carriageReturn && | |
ch !== charCodes.lineSeparator && | |
ch !== charCodes.paragraphSeparator && | |
++state.pos < input.length | |
) { | |
ch = input.charCodeAt(state.pos); | |
} | |
} | |
} | |
function skipSpace() { | |
while (state.pos < input.length) { | |
const ch = input.charCodeAt(state.pos); | |
switch (ch) { | |
case charCodes.carriageReturn: | |
if (input.charCodeAt(state.pos + 1) === charCodes.lineFeed) { | |
++state.pos; | |
} | |
case charCodes.lineFeed: | |
case charCodes.lineSeparator: | |
case charCodes.paragraphSeparator: | |
++state.pos; | |
break; | |
case charCodes.slash: | |
switch (input.charCodeAt(state.pos + 1)) { | |
case charCodes.asterisk: | |
state.pos += 2; | |
skipBlockComment(); | |
break; | |
case charCodes.slash: | |
skipLineComment(2); | |
break; | |
default: | |
return; | |
} | |
break; | |
default: | |
if (IS_WHITESPACE[ch]) { | |
++state.pos; | |
} else { | |
return; | |
} | |
} | |
} | |
} | |
function finishToken(type, contextualKeyword = ContextualKeyword.NONE) { | |
state.end = state.pos; | |
state.type = type; | |
state.contextualKeyword = contextualKeyword; | |
} | |
function readToken_dot() { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if (nextChar >= charCodes.digit0 && nextChar <= charCodes.digit9) { | |
readNumber(true); | |
return; | |
} | |
if ( | |
nextChar === charCodes.dot && | |
input.charCodeAt(state.pos + 2) === charCodes.dot | |
) { | |
state.pos += 3; | |
finishToken(TokenType.ellipsis); | |
} else { | |
++state.pos; | |
finishToken(TokenType.dot); | |
} | |
} | |
function readToken_slash() { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if (nextChar === charCodes.equalsTo) { | |
finishOp(TokenType.assign, 2); | |
} else { | |
finishOp(TokenType.slash, 1); | |
} | |
} | |
function readToken_mult_modulo(code) { | |
let tokenType = | |
code === charCodes.asterisk ? TokenType.star : TokenType.modulo; | |
let width = 1; | |
let nextChar = input.charCodeAt(state.pos + 1); | |
if (code === charCodes.asterisk && nextChar === charCodes.asterisk) { | |
width++; | |
nextChar = input.charCodeAt(state.pos + 2); | |
tokenType = TokenType.exponent; | |
} | |
if ( | |
nextChar === charCodes.equalsTo && | |
input.charCodeAt(state.pos + 2) !== charCodes.greaterThan | |
) { | |
width++; | |
tokenType = TokenType.assign; | |
} | |
finishOp(tokenType, width); | |
} | |
function readToken_pipe_amp(code) { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if (nextChar === code) { | |
if (input.charCodeAt(state.pos + 2) === charCodes.equalsTo) { | |
finishOp(TokenType.assign, 3); | |
} else { | |
finishOp( | |
code === charCodes.verticalBar | |
? TokenType.logicalOR | |
: TokenType.logicalAND, | |
2 | |
); | |
} | |
return; | |
} | |
if (code === charCodes.verticalBar) { | |
if (nextChar === charCodes.greaterThan) { | |
finishOp(TokenType.pipeline, 2); | |
return; | |
} else if (nextChar === charCodes.rightCurlyBrace && isFlowEnabled) { | |
finishOp(TokenType.braceBarR, 2); | |
return; | |
} | |
} | |
if (nextChar === charCodes.equalsTo) { | |
finishOp(TokenType.assign, 2); | |
return; | |
} | |
finishOp( | |
code === charCodes.verticalBar ? TokenType.bitwiseOR : TokenType.bitwiseAND, | |
1 | |
); | |
} | |
function readToken_caret() { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if (nextChar === charCodes.equalsTo) { | |
finishOp(TokenType.assign, 2); | |
} else { | |
finishOp(TokenType.bitwiseXOR, 1); | |
} | |
} | |
function readToken_plus_min(code) { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if (nextChar === code) { | |
finishOp(TokenType.preIncDec, 2); | |
return; | |
} | |
if (nextChar === charCodes.equalsTo) { | |
finishOp(TokenType.assign, 2); | |
} else if (code === charCodes.plusSign) { | |
finishOp(TokenType.plus, 1); | |
} else { | |
finishOp(TokenType.minus, 1); | |
} | |
} | |
function readToken_lt_gt(code) { | |
if (code === charCodes.greaterThan && state.isType) { | |
finishOp(TokenType.greaterThan, 1); | |
return; | |
} | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if (nextChar === code) { | |
const size = | |
code === charCodes.greaterThan && | |
input.charCodeAt(state.pos + 2) === charCodes.greaterThan | |
? 3 | |
: 2; | |
if (input.charCodeAt(state.pos + size) === charCodes.equalsTo) { | |
finishOp(TokenType.assign, size + 1); | |
return; | |
} | |
finishOp(TokenType.bitShift, size); | |
return; | |
} | |
if (nextChar === charCodes.equalsTo) { | |
finishOp(TokenType.relationalOrEqual, 2); | |
} else if (code === charCodes.lessThan) { | |
finishOp(TokenType.lessThan, 1); | |
} else { | |
finishOp(TokenType.greaterThan, 1); | |
} | |
} | |
function readToken_eq_excl(code) { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if (nextChar === charCodes.equalsTo) { | |
finishOp( | |
TokenType.equality, | |
input.charCodeAt(state.pos + 2) === charCodes.equalsTo ? 3 : 2 | |
); | |
return; | |
} | |
if (code === charCodes.equalsTo && nextChar === charCodes.greaterThan) { | |
state.pos += 2; | |
finishToken(TokenType.arrow); | |
return; | |
} | |
finishOp(code === charCodes.equalsTo ? TokenType.eq : TokenType.bang, 1); | |
} | |
function readToken_question() { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
const nextChar2 = input.charCodeAt(state.pos + 2); | |
if (nextChar === charCodes.questionMark && !state.isType) { | |
if (nextChar2 === charCodes.equalsTo) { | |
finishOp(TokenType.assign, 3); | |
} else { | |
finishOp(TokenType.nullishCoalescing, 2); | |
} | |
} else if ( | |
nextChar === charCodes.dot && | |
!(nextChar2 >= charCodes.digit0 && nextChar2 <= charCodes.digit9) | |
) { | |
state.pos += 2; | |
finishToken(TokenType.questionDot); | |
} else { | |
++state.pos; | |
finishToken(TokenType.question); | |
} | |
} | |
function getTokenFromCode(code) { | |
switch (code) { | |
case charCodes.numberSign: | |
++state.pos; | |
finishToken(TokenType.hash); | |
return; | |
case charCodes.dot: | |
readToken_dot(); | |
return; | |
case charCodes.leftParenthesis: | |
++state.pos; | |
finishToken(TokenType.parenL); | |
return; | |
case charCodes.rightParenthesis: | |
++state.pos; | |
finishToken(TokenType.parenR); | |
return; | |
case charCodes.semicolon: | |
++state.pos; | |
finishToken(TokenType.semi); | |
return; | |
case charCodes.comma: | |
++state.pos; | |
finishToken(TokenType.comma); | |
return; | |
case charCodes.leftSquareBracket: | |
++state.pos; | |
finishToken(TokenType.bracketL); | |
return; | |
case charCodes.rightSquareBracket: | |
++state.pos; | |
finishToken(TokenType.bracketR); | |
return; | |
case charCodes.leftCurlyBrace: | |
if ( | |
isFlowEnabled && | |
input.charCodeAt(state.pos + 1) === charCodes.verticalBar | |
) { | |
finishOp(TokenType.braceBarL, 2); | |
} else { | |
++state.pos; | |
finishToken(TokenType.braceL); | |
} | |
return; | |
case charCodes.rightCurlyBrace: | |
++state.pos; | |
finishToken(TokenType.braceR); | |
return; | |
case charCodes.colon: | |
if (input.charCodeAt(state.pos + 1) === charCodes.colon) { | |
finishOp(TokenType.doubleColon, 2); | |
} else { | |
++state.pos; | |
finishToken(TokenType.colon); | |
} | |
return; | |
case charCodes.questionMark: | |
readToken_question(); | |
return; | |
case charCodes.atSign: | |
++state.pos; | |
finishToken(TokenType.at); | |
return; | |
case charCodes.graveAccent: | |
++state.pos; | |
finishToken(TokenType.backQuote); | |
return; | |
case charCodes.digit0: { | |
const nextChar = input.charCodeAt(state.pos + 1); | |
if ( | |
nextChar === charCodes.lowercaseX || | |
nextChar === charCodes.uppercaseX || | |
nextChar === charCodes.lowercaseO || | |
nextChar === charCodes.uppercaseO || | |
nextChar === charCodes.lowercaseB || | |
nextChar === charCodes.uppercaseB | |
) { | |
readRadixNumber(); | |
return; | |
} | |
} | |
case charCodes.digit1: | |
case charCodes.digit2: | |
case charCodes.digit3: | |
case charCodes.digit4: | |
case charCodes.digit5: | |
case charCodes.digit6: | |
case charCodes.digit7: | |
case charCodes.digit8: | |
case charCodes.digit9: | |
readNumber(false); | |
return; | |
case charCodes.quotationMark: | |
case charCodes.apostrophe: | |
readString(code); | |
return; | |
case charCodes.slash: | |
readToken_slash(); | |
return; | |
case charCodes.percentSign: | |
case charCodes.asterisk: | |
readToken_mult_modulo(code); | |
return; | |
case charCodes.verticalBar: | |
case charCodes.ampersand: | |
readToken_pipe_amp(code); | |
return; | |
case charCodes.caret: | |
readToken_caret(); | |
return; | |
case charCodes.plusSign: | |
case charCodes.dash: | |
readToken_plus_min(code); | |
return; | |
case charCodes.lessThan: | |
case charCodes.greaterThan: | |
readToken_lt_gt(code); | |
return; | |
case charCodes.equalsTo: | |
case charCodes.exclamationMark: | |
readToken_eq_excl(code); | |
return; | |
case charCodes.tilde: | |
finishOp(TokenType.tilde, 1); | |
return; | |
} | |
unexpected(`Unexpected character '${String.fromCharCode(code)}'`, state.pos); | |
} | |
function finishOp(type, size) { | |
state.pos += size; | |
finishToken(type); | |
} | |
function readRegexp() { | |
const start = state.pos; | |
let escaped = false; | |
let inClass = false; | |
for (;;) { | |
if (state.pos >= input.length) { | |
unexpected("Unterminated regular expression", start); | |
return; | |
} | |
const code = input.charCodeAt(state.pos); | |
if (escaped) { | |
escaped = false; | |
} else { | |
if (code === charCodes.leftSquareBracket) { | |
inClass = true; | |
} else if (code === charCodes.rightSquareBracket && inClass) { | |
inClass = false; | |
} else if (code === charCodes.slash && !inClass) { | |
break; | |
} | |
escaped = code === charCodes.backslash; | |
} | |
++state.pos; | |
} | |
++state.pos; | |
skipWord(); | |
finishToken(TokenType.regexp); | |
} | |
function readInt() { | |
while (true) { | |
const code = input.charCodeAt(state.pos); | |
if ( | |
(code >= charCodes.digit0 && code <= charCodes.digit9) || | |
(code >= charCodes.lowercaseA && code <= charCodes.lowercaseF) || | |
(code >= charCodes.uppercaseA && code <= charCodes.uppercaseF) || | |
code === charCodes.underscore | |
) { | |
state.pos++; | |
} else { | |
break; | |
} | |
} | |
} | |
function readRadixNumber() { | |
let isBigInt = false; | |
const start = state.pos; | |
state.pos += 2; | |
readInt(); | |
const nextChar = input.charCodeAt(state.pos); | |
if (nextChar === charCodes.lowercaseN) { | |
++state.pos; | |
isBigInt = true; | |
} else if (nextChar === charCodes.lowercaseM) { | |
unexpected("Invalid decimal", start); | |
} | |
if (isBigInt) { | |
finishToken(TokenType.bigint); | |
return; | |
} | |
finishToken(TokenType.num); | |
} | |
function readNumber(startsWithDot) { | |
let isBigInt = false; | |
let isDecimal = false; | |
if (!startsWithDot) { | |
readInt(); | |
} | |
let nextChar = input.charCodeAt(state.pos); | |
if (nextChar === charCodes.dot) { | |
++state.pos; | |
readInt(); | |
nextChar = input.charCodeAt(state.pos); | |
} | |
if (nextChar === charCodes.uppercaseE || nextChar === charCodes.lowercaseE) { | |
nextChar = input.charCodeAt(++state.pos); | |
if (nextChar === charCodes.plusSign || nextChar === charCodes.dash) { | |
++state.pos; | |
} | |
readInt(); | |
nextChar = input.charCodeAt(state.pos); | |
} | |
if (nextChar === charCodes.lowercaseN) { | |
++state.pos; | |
isBigInt = true; | |
} else if (nextChar === charCodes.lowercaseM) { | |
++state.pos; | |
isDecimal = true; | |
} | |
if (isBigInt) { | |
finishToken(TokenType.bigint); | |
return; | |
} | |
if (isDecimal) { | |
finishToken(TokenType.decimal); | |
return; | |
} | |
finishToken(TokenType.num); | |
} | |
function readString(quote) { | |
state.pos++; | |
for (;;) { | |
if (state.pos >= input.length) { | |
unexpected("Unterminated string constant"); | |
return; | |
} | |
const ch = input.charCodeAt(state.pos); | |
if (ch === charCodes.backslash) { | |
state.pos++; | |
} else if (ch === quote) { | |
break; | |
} | |
state.pos++; | |
} | |
state.pos++; | |
finishToken(TokenType.string); | |
} | |
function readTmplToken() { | |
for (;;) { | |
if (state.pos >= input.length) { | |
unexpected("Unterminated template"); | |
return; | |
} | |
const ch = input.charCodeAt(state.pos); | |
if ( | |
ch === charCodes.graveAccent || | |
(ch === charCodes.dollarSign && | |
input.charCodeAt(state.pos + 1) === charCodes.leftCurlyBrace) | |
) { | |
if (state.pos === state.start && match(TokenType.template)) { | |
if (ch === charCodes.dollarSign) { | |
state.pos += 2; | |
finishToken(TokenType.dollarBraceL); | |
return; | |
} else { | |
++state.pos; | |
finishToken(TokenType.backQuote); | |
return; | |
} | |
} | |
finishToken(TokenType.template); | |
return; | |
} | |
if (ch === charCodes.backslash) { | |
state.pos++; | |
} | |
state.pos++; | |
} | |
} | |
function skipWord() { | |
while (state.pos < input.length) { | |
const ch = input.charCodeAt(state.pos); | |
if (IS_IDENTIFIER_CHAR[ch]) { | |
state.pos++; | |
} else if (ch === charCodes.backslash) { | |
state.pos += 2; | |
if (input.charCodeAt(state.pos) === charCodes.leftCurlyBrace) { | |
while ( | |
state.pos < input.length && | |
input.charCodeAt(state.pos) !== charCodes.rightCurlyBrace | |
) { | |
state.pos++; | |
} | |
state.pos++; | |
} | |
} else { | |
break; | |
} | |
} | |
} | |
const entities = { | |
quot: '"', | |
amp: "&", | |
apos: "'", | |
lt: "<", | |
gt: ">", | |
nbsp: "\xA0", | |
iexcl: "\xA1", | |
cent: "\xA2", | |
pound: "\xA3", | |
curren: "\xA4", | |
yen: "\xA5", | |
brvbar: "\xA6", | |
sect: "\xA7", | |
uml: "\xA8", | |
copy: "\xA9", | |
ordf: "\xAA", | |
laquo: "\xAB", | |
not: "\xAC", | |
shy: "\xAD", | |
reg: "\xAE", | |
macr: "\xAF", | |
deg: "\xB0", | |
plusmn: "\xB1", | |
sup2: "\xB2", | |
sup3: "\xB3", | |
acute: "\xB4", | |
micro: "\xB5", | |
para: "\xB6", | |
middot: "\xB7", | |
cedil: "\xB8", | |
sup1: "\xB9", | |
ordm: "\xBA", | |
raquo: "\xBB", | |
frac14: "\xBC", | |
frac12: "\xBD", | |
frac34: "\xBE", | |
iquest: "\xBF", | |
Agrave: "\xC0", | |
Aacute: "\xC1", | |
Acirc: "\xC2", | |
Atilde: "\xC3", | |
Auml: "\xC4", | |
Aring: "\xC5", | |
AElig: "\xC6", | |
Ccedil: "\xC7", | |
Egrave: "\xC8", | |
Eacute: "\xC9", | |
Ecirc: "\xCA", | |
Euml: "\xCB", | |
Igrave: "\xCC", | |
Iacute: "\xCD", | |
Icirc: "\xCE", | |
Iuml: "\xCF", | |
ETH: "\xD0", | |
Ntilde: "\xD1", | |
Ograve: "\xD2", | |
Oacute: "\xD3", | |
Ocirc: "\xD4", | |
Otilde: "\xD5", | |
Ouml: "\xD6", | |
times: "\xD7", | |
Oslash: "\xD8", | |
Ugrave: "\xD9", | |
Uacute: "\xDA", | |
Ucirc: "\xDB", | |
Uuml: "\xDC", | |
Yacute: "\xDD", | |
THORN: "\xDE", | |
szlig: "\xDF", | |
agrave: "\xE0", | |
aacute: "\xE1", | |
acirc: "\xE2", | |
atilde: "\xE3", | |
auml: "\xE4", | |
aring: "\xE5", | |
aelig: "\xE6", | |
ccedil: "\xE7", | |
egrave: "\xE8", | |
eacute: "\xE9", | |
ecirc: "\xEA", | |
euml: "\xEB", | |
igrave: "\xEC", | |
iacute: "\xED", | |
icirc: "\xEE", | |
iuml: "\xEF", | |
eth: "\xF0", | |
ntilde: "\xF1", | |
ograve: "\xF2", | |
oacute: "\xF3", | |
ocirc: "\xF4", | |
otilde: "\xF5", | |
ouml: "\xF6", | |
divide: "\xF7", | |
oslash: "\xF8", | |
ugrave: "\xF9", | |
uacute: "\xFA", | |
ucirc: "\xFB", | |
uuml: "\xFC", | |
yacute: "\xFD", | |
thorn: "\xFE", | |
yuml: "\xFF", | |
OElig: "\u0152", | |
oelig: "\u0153", | |
Scaron: "\u0160", | |
scaron: "\u0161", | |
Yuml: "\u0178", | |
fnof: "\u0192", | |
circ: "\u02C6", | |
tilde: "\u02DC", | |
Alpha: "\u0391", | |
Beta: "\u0392", | |
Gamma: "\u0393", | |
Delta: "\u0394", | |
Epsilon: "\u0395", | |
Zeta: "\u0396", | |
Eta: "\u0397", | |
Theta: "\u0398", | |
Iota: "\u0399", | |
Kappa: "\u039A", | |
Lambda: "\u039B", | |
Mu: "\u039C", | |
Nu: "\u039D", | |
Xi: "\u039E", | |
Omicron: "\u039F", | |
Pi: "\u03A0", | |
Rho: "\u03A1", | |
Sigma: "\u03A3", | |
Tau: "\u03A4", | |
Upsilon: "\u03A5", | |
Phi: "\u03A6", | |
Chi: "\u03A7", | |
Psi: "\u03A8", | |
Omega: "\u03A9", | |
alpha: "\u03B1", | |
beta: "\u03B2", | |
gamma: "\u03B3", | |
delta: "\u03B4", | |
epsilon: "\u03B5", | |
zeta: "\u03B6", | |
eta: "\u03B7", | |
theta: "\u03B8", | |
iota: "\u03B9", | |
kappa: "\u03BA", | |
lambda: "\u03BB", | |
mu: "\u03BC", | |
nu: "\u03BD", | |
xi: "\u03BE", | |
omicron: "\u03BF", | |
pi: "\u03C0", | |
rho: "\u03C1", | |
sigmaf: "\u03C2", | |
sigma: "\u03C3", | |
tau: "\u03C4", | |
upsilon: "\u03C5", | |
phi: "\u03C6", | |
chi: "\u03C7", | |
psi: "\u03C8", | |
omega: "\u03C9", | |
thetasym: "\u03D1", | |
upsih: "\u03D2", | |
piv: "\u03D6", | |
ensp: "\u2002", | |
emsp: "\u2003", | |
thinsp: "\u2009", | |
zwnj: "\u200C", | |
zwj: "\u200D", | |
lrm: "\u200E", | |
rlm: "\u200F", | |
ndash: "\u2013", | |
mdash: "\u2014", | |
lsquo: "\u2018", | |
rsquo: "\u2019", | |
sbquo: "\u201A", | |
ldquo: "\u201C", | |
rdquo: "\u201D", | |
bdquo: "\u201E", | |
dagger: "\u2020", | |
Dagger: "\u2021", | |
bull: "\u2022", | |
hellip: "\u2026", | |
permil: "\u2030", | |
prime: "\u2032", | |
Prime: "\u2033", | |
lsaquo: "\u2039", | |
rsaquo: "\u203A", | |
oline: "\u203E", | |
frasl: "\u2044", | |
euro: "\u20AC", | |
image: "\u2111", | |
weierp: "\u2118", | |
real: "\u211C", | |
trade: "\u2122", | |
alefsym: "\u2135", | |
larr: "\u2190", | |
uarr: "\u2191", | |
rarr: "\u2192", | |
darr: "\u2193", | |
harr: "\u2194", | |
crarr: "\u21B5", | |
lArr: "\u21D0", | |
uArr: "\u21D1", | |
rArr: "\u21D2", | |
dArr: "\u21D3", | |
hArr: "\u21D4", | |
forall: "\u2200", | |
part: "\u2202", | |
exist: "\u2203", | |
empty: "\u2205", | |
nabla: "\u2207", | |
isin: "\u2208", | |
notin: "\u2209", | |
ni: "\u220B", | |
prod: "\u220F", | |
sum: "\u2211", | |
minus: "\u2212", | |
lowast: "\u2217", | |
radic: "\u221A", | |
prop: "\u221D", | |
infin: "\u221E", | |
ang: "\u2220", | |
and: "\u2227", | |
or: "\u2228", | |
cap: "\u2229", | |
cup: "\u222A", | |
int: "\u222B", | |
there4: "\u2234", | |
sim: "\u223C", | |
cong: "\u2245", | |
asymp: "\u2248", | |
ne: "\u2260", | |
equiv: "\u2261", | |
le: "\u2264", | |
ge: "\u2265", | |
sub: "\u2282", | |
sup: "\u2283", | |
nsub: "\u2284", | |
sube: "\u2286", | |
supe: "\u2287", | |
oplus: "\u2295", | |
otimes: "\u2297", | |
perp: "\u22A5", | |
sdot: "\u22C5", | |
lceil: "\u2308", | |
rceil: "\u2309", | |
lfloor: "\u230A", | |
rfloor: "\u230B", | |
lang: "\u2329", | |
rang: "\u232A", | |
loz: "\u25CA", | |
spades: "\u2660", | |
clubs: "\u2663", | |
hearts: "\u2665", | |
diams: "\u2666", | |
}; | |
function getJSXPragmaInfo(options) { | |
const [base, suffix] = splitPragma( | |
options.jsxPragma || "React.createElement" | |
); | |
const [fragmentBase, fragmentSuffix] = splitPragma( | |
options.jsxFragmentPragma || "React.Fragment" | |
); | |
return { base, suffix, fragmentBase, fragmentSuffix }; | |
} | |
function splitPragma(pragma) { | |
let dotIndex = pragma.indexOf("."); | |
if (dotIndex === -1) { | |
dotIndex = pragma.length; | |
} | |
return [pragma.slice(0, dotIndex), pragma.slice(dotIndex)]; | |
} | |
class Transformer { | |
getPrefixCode() { | |
return ""; | |
} | |
getSuffixCode() { | |
return ""; | |
} | |
} | |
const HEX_NUMBER = /^[\da-fA-F]+$/; | |
const DECIMAL_NUMBER = /^\d+$/; | |
class JSXTransformer extends Transformer { | |
__init() { | |
this.lastLineNumber = 1; | |
} | |
__init2() { | |
this.lastIndex = 0; | |
} | |
__init3() { | |
this.filenameVarName = null; | |
} | |
constructor(rootTransformer, tokens, importProcessor, nameManager, options) { | |
super(); | |
this.rootTransformer = rootTransformer; | |
this.tokens = tokens; | |
this.importProcessor = importProcessor; | |
this.nameManager = nameManager; | |
this.options = options; | |
JSXTransformer.prototype.__init.call(this); | |
JSXTransformer.prototype.__init2.call(this); | |
JSXTransformer.prototype.__init3.call(this); | |
this.jsxPragmaInfo = getJSXPragmaInfo(options); | |
} | |
process() { | |
if (this.tokens.matches1(TokenType.jsxTagStart)) { | |
this.processJSXTag(); | |
return true; | |
} | |
return false; | |
} | |
getPrefixCode() { | |
if (this.filenameVarName) { | |
return `const ${this.filenameVarName} = ${JSON.stringify( | |
this.options.filePath || "" | |
)};`; | |
} else { | |
return ""; | |
} | |
} | |
getLineNumberForIndex(index) { | |
const code = this.tokens.code; | |
while (this.lastIndex < index && this.lastIndex < code.length) { | |
if (code[this.lastIndex] === "\n") { | |
this.lastLineNumber++; | |
} | |
this.lastIndex++; | |
} | |
return this.lastLineNumber; | |
} | |
getFilenameVarName() { | |
if (!this.filenameVarName) { | |
this.filenameVarName = this.nameManager.claimFreeName("_jsxFileName"); | |
} | |
return this.filenameVarName; | |
} | |
processProps(firstTokenStart) { | |
const lineNumber = this.getLineNumberForIndex(firstTokenStart); | |
const devProps = this.options.production | |
? "" | |
: `__self: this, __source: {fileName: ${this.getFilenameVarName()}, lineNumber: ${lineNumber}}`; | |
if ( | |
!this.tokens.matches1(TokenType.jsxName) && | |
!this.tokens.matches1(TokenType.braceL) | |
) { | |
if (devProps) { | |
this.tokens.appendCode(`, {${devProps}}`); | |
} else { | |
this.tokens.appendCode(`, null`); | |
} | |
return; | |
} | |
this.tokens.appendCode(`, {`); | |
while (true) { | |
if (this.tokens.matches2(TokenType.jsxName, TokenType.eq)) { | |
this.processPropKeyName(); | |
this.tokens.replaceToken(": "); | |
if (this.tokens.matches1(TokenType.braceL)) { | |
this.tokens.replaceToken(""); | |
this.rootTransformer.processBalancedCode(); | |
this.tokens.replaceToken(""); | |
} else if (this.tokens.matches1(TokenType.jsxTagStart)) { | |
this.processJSXTag(); | |
} else { | |
this.processStringPropValue(); | |
} | |
} else if (this.tokens.matches1(TokenType.jsxName)) { | |
this.processPropKeyName(); | |
this.tokens.appendCode(": true"); | |
} else if (this.tokens.matches1(TokenType.braceL)) { | |
this.tokens.replaceToken(""); | |
this.rootTransformer.processBalancedCode(); | |
this.tokens.replaceToken(""); | |
} else { | |
break; | |
} | |
this.tokens.appendCode(","); | |
} | |
if (devProps) { | |
this.tokens.appendCode(` ${devProps}}`); | |
} else { | |
this.tokens.appendCode("}"); | |
} | |
} | |
processPropKeyName() { | |
const keyName = this.tokens.identifierName(); | |
if (keyName.includes("-")) { | |
this.tokens.replaceToken(`'${keyName}'`); | |
} else { | |
this.tokens.copyToken(); | |
} | |
} | |
processStringPropValue() { | |
const token = this.tokens.currentToken(); | |
const valueCode = this.tokens.code.slice(token.start + 1, token.end - 1); | |
const replacementCode = formatJSXTextReplacement(valueCode); | |
const literalCode = formatJSXStringValueLiteral(valueCode); | |
this.tokens.replaceToken(literalCode + replacementCode); | |
} | |
processTagIntro() { | |
let introEnd = this.tokens.currentIndex() + 1; | |
while ( | |
this.tokens.tokens[introEnd].isType || | |
(!this.tokens.matches2AtIndex( | |
introEnd - 1, | |
TokenType.jsxName, | |
TokenType.jsxName | |
) && | |
!this.tokens.matches2AtIndex( | |
introEnd - 1, | |
TokenType.greaterThan, | |
TokenType.jsxName | |
) && | |
!this.tokens.matches1AtIndex(introEnd, TokenType.braceL) && | |
!this.tokens.matches1AtIndex(introEnd, TokenType.jsxTagEnd) && | |
!this.tokens.matches2AtIndex( | |
introEnd, | |
TokenType.slash, | |
TokenType.jsxTagEnd | |
)) | |
) { | |
introEnd++; | |
} | |
if (introEnd === this.tokens.currentIndex() + 1) { | |
const tagName = this.tokens.identifierName(); | |
if (startsWithLowerCase(tagName)) { | |
this.tokens.replaceToken(`'${tagName}'`); | |
} | |
} | |
while (this.tokens.currentIndex() < introEnd) { | |
this.rootTransformer.processToken(); | |
} | |
} | |
processChildren() { | |
while (true) { | |
if (this.tokens.matches2(TokenType.jsxTagStart, TokenType.slash)) { | |
return; | |
} | |
if (this.tokens.matches1(TokenType.braceL)) { | |
if (this.tokens.matches2(TokenType.braceL, TokenType.braceR)) { | |
this.tokens.replaceToken(""); | |
this.tokens.replaceToken(""); | |
} else { | |
this.tokens.replaceToken(", "); | |
this.rootTransformer.processBalancedCode(); | |
this.tokens.replaceToken(""); | |
} | |
} else if (this.tokens.matches1(TokenType.jsxTagStart)) { | |
this.tokens.appendCode(", "); | |
this.processJSXTag(); | |
} else if (this.tokens.matches1(TokenType.jsxText)) { | |
this.processChildTextElement(); | |
} else { | |
throw new Error("Unexpected token when processing JSX children."); | |
} | |
} | |
} | |
processChildTextElement() { | |
const token = this.tokens.currentToken(); | |
const valueCode = this.tokens.code.slice(token.start, token.end); | |
const replacementCode = formatJSXTextReplacement(valueCode); | |
const literalCode = formatJSXTextLiteral(valueCode); | |
if (literalCode === '""') { | |
this.tokens.replaceToken(replacementCode); | |
} else { | |
this.tokens.replaceToken(`, ${literalCode}${replacementCode}`); | |
} | |
} | |
processJSXTag() { | |
const { jsxPragmaInfo } = this; | |
const resolvedPragmaBaseName = this.importProcessor | |
? this.importProcessor.getIdentifierReplacement(jsxPragmaInfo.base) || | |
jsxPragmaInfo.base | |
: jsxPragmaInfo.base; | |
const firstTokenStart = this.tokens.currentToken().start; | |
this.tokens.replaceToken( | |
`${resolvedPragmaBaseName}${jsxPragmaInfo.suffix}(` | |
); | |
if (this.tokens.matches1(TokenType.jsxTagEnd)) { | |
const resolvedFragmentPragmaBaseName = this.importProcessor | |
? this.importProcessor.getIdentifierReplacement( | |
jsxPragmaInfo.fragmentBase | |
) || jsxPragmaInfo.fragmentBase | |
: jsxPragmaInfo.fragmentBase; | |
this.tokens.replaceToken( | |
`${resolvedFragmentPragmaBaseName}${jsxPragmaInfo.fragmentSuffix}, null` | |
); | |
this.processChildren(); | |
while (!this.tokens.matches1(TokenType.jsxTagEnd)) { | |
this.tokens.replaceToken(""); | |
} | |
this.tokens.replaceToken(")"); | |
} else { | |
this.processTagIntro(); | |
this.processProps(firstTokenStart); | |
if (this.tokens.matches2(TokenType.slash, TokenType.jsxTagEnd)) { | |
this.tokens.replaceToken(""); | |
this.tokens.replaceToken(")"); | |
} else if (this.tokens.matches1(TokenType.jsxTagEnd)) { | |
this.tokens.replaceToken(""); | |
this.processChildren(); | |
while (!this.tokens.matches1(TokenType.jsxTagEnd)) { | |
this.tokens.replaceToken(""); | |
} | |
this.tokens.replaceToken(")"); | |
} else { | |
throw new Error("Expected either /> or > at the end of the tag."); | |
} | |
} | |
} | |
} | |
function startsWithLowerCase(s) { | |
const firstChar = s.charCodeAt(0); | |
return firstChar >= charCodes.lowercaseA && firstChar <= charCodes.lowercaseZ; | |
} | |
function formatJSXTextLiteral(text) { | |
let result = ""; | |
let whitespace = ""; | |
let isInInitialLineWhitespace = false; | |
let seenNonWhitespace = false; | |
for (let i = 0; i < text.length; i++) { | |
const c = text[i]; | |
if (c === " " || c === " " || c === "\r") { | |
if (!isInInitialLineWhitespace) { | |
whitespace += c; | |
} | |
} else if (c === "\n") { | |
whitespace = ""; | |
isInInitialLineWhitespace = true; | |
} else { | |
if (seenNonWhitespace && isInInitialLineWhitespace) { | |
result += " "; | |
} | |
result += whitespace; | |
whitespace = ""; | |
if (c === "&") { | |
const { entity, newI } = processEntity(text, i + 1); | |
i = newI - 1; | |
result += entity; | |
} else { | |
result += c; | |
} | |
seenNonWhitespace = true; | |
isInInitialLineWhitespace = false; | |
} | |
} | |
if (!isInInitialLineWhitespace) { | |
result += whitespace; | |
} | |
return JSON.stringify(result); | |
} | |
function formatJSXTextReplacement(text) { | |
let numNewlines = 0; | |
let numSpaces = 0; | |
for (const c of text) { | |
if (c === "\n") { | |
numNewlines++; | |
numSpaces = 0; | |
} else if (c === " ") { | |
numSpaces++; | |
} | |
} | |
return "\n".repeat(numNewlines) + " ".repeat(numSpaces); | |
} | |
function formatJSXStringValueLiteral(text) { | |
let result = ""; | |
for (let i = 0; i < text.length; i++) { | |
const c = text[i]; | |
if (c === "\n") { | |
if (/\s/.test(text[i + 1])) { | |
result += " "; | |
while (i < text.length && /\s/.test(text[i + 1])) { | |
i++; | |
} | |
} else { | |
result += "\n"; | |
} | |
} else if (c === "&") { | |
const { entity, newI } = processEntity(text, i + 1); | |
result += entity; | |
i = newI - 1; | |
} else { | |
result += c; | |
} | |
} | |
return JSON.stringify(result); | |
} | |
function processEntity(text, indexAfterAmpersand) { | |
let str = ""; | |
let count = 0; | |
let entity; | |
let i = indexAfterAmpersand; | |
while (i < text.length && count++ < 10) { | |
const ch = text[i]; | |
i++; | |
if (ch === ";") { | |
if (str[0] === "#") { | |
if (str[1] === "x") { | |
str = str.substr(2); | |
if (HEX_NUMBER.test(str)) { | |
entity = String.fromCodePoint(parseInt(str, 16)); | |
} | |
} else { | |
str = str.substr(1); | |
if (DECIMAL_NUMBER.test(str)) { | |
entity = String.fromCodePoint(parseInt(str, 10)); | |
} | |
} | |
} else { | |
entity = entities[str]; | |
} | |
break; | |
} | |
str += ch; | |
} | |
if (!entity) { | |
return { entity: "&", newI: indexAfterAmpersand }; | |
} | |
return { entity, newI: i }; | |
} | |
function getNonTypeIdentifiers(tokens, options) { | |
const jsxPragmaInfo = getJSXPragmaInfo(options); | |
const nonTypeIdentifiers = new Set(); | |
for (let i = 0; i < tokens.tokens.length; i++) { | |
const token = tokens.tokens[i]; | |
if ( | |
token.type === TokenType.name && | |
!token.isType && | |
(token.identifierRole === IdentifierRole.Access || | |
token.identifierRole === IdentifierRole.ObjectShorthand || | |
token.identifierRole === IdentifierRole.ExportAccess) && | |
!token.shadowsGlobal | |
) { | |
nonTypeIdentifiers.add(tokens.identifierNameForToken(token)); | |
} | |
if (token.type === TokenType.jsxTagStart) { | |
nonTypeIdentifiers.add(jsxPragmaInfo.base); | |
} | |
if ( | |
token.type === TokenType.jsxTagStart && | |
i + 1 < tokens.tokens.length && | |
tokens.tokens[i + 1].type === TokenType.jsxTagEnd | |
) { | |
nonTypeIdentifiers.add(jsxPragmaInfo.base); | |
nonTypeIdentifiers.add(jsxPragmaInfo.fragmentBase); | |
} | |
if ( | |
token.type === TokenType.jsxName && | |
token.identifierRole === IdentifierRole.Access | |
) { | |
const identifierName = tokens.identifierNameForToken(token); | |
if ( | |
!startsWithLowerCase(identifierName) || | |
tokens.tokens[i + 1].type === TokenType.dot | |
) { | |
nonTypeIdentifiers.add(tokens.identifierNameForToken(token)); | |
} | |
} | |
} | |
return nonTypeIdentifiers; | |
} | |
class CJSImportProcessor { | |
__init() { | |
this.nonTypeIdentifiers = new Set(); | |
} | |
__init2() { | |
this.importInfoByPath = new Map(); | |
} | |
__init3() { | |
this.importsToReplace = new Map(); | |
} | |
__init4() { | |
this.identifierReplacements = new Map(); | |
} | |
__init5() { | |
this.exportBindingsByLocalName = new Map(); | |
} | |
constructor( | |
nameManager, | |
tokens, | |
enableLegacyTypeScriptModuleInterop, | |
options, | |
isTypeScriptTransformEnabled, | |
helperManager | |
) { | |
this.nameManager = nameManager; | |
this.tokens = tokens; | |
this.enableLegacyTypeScriptModuleInterop = enableLegacyTypeScriptModuleInterop; | |
this.options = options; | |
this.isTypeScriptTransformEnabled = isTypeScriptTransformEnabled; | |
this.helperManager = helperManager; | |
CJSImportProcessor.prototype.__init.call(this); | |
CJSImportProcessor.prototype.__init2.call(this); | |
CJSImportProcessor.prototype.__init3.call(this); | |
CJSImportProcessor.prototype.__init4.call(this); | |
CJSImportProcessor.prototype.__init5.call(this); | |
} | |
preprocessTokens() { | |
for (let i = 0; i < this.tokens.tokens.length; i++) { | |
if ( | |
this.tokens.matches1AtIndex(i, TokenType._import) && | |
!this.tokens.matches3AtIndex( | |
i, | |
TokenType._import, | |
TokenType.name, | |
TokenType.eq | |
) | |
) { | |
this.preprocessImportAtIndex(i); | |
} | |
if ( | |
this.tokens.matches1AtIndex(i, TokenType._export) && | |
!this.tokens.matches2AtIndex(i, TokenType._export, TokenType.eq) | |
) { | |
this.preprocessExportAtIndex(i); | |
} | |
} | |
this.generateImportReplacements(); | |
} | |
pruneTypeOnlyImports() { | |
this.nonTypeIdentifiers = getNonTypeIdentifiers(this.tokens, this.options); | |
for (const [path, importInfo] of this.importInfoByPath.entries()) { | |
if ( | |
importInfo.hasBareImport || | |
importInfo.hasStarExport || | |
importInfo.exportStarNames.length > 0 || | |
importInfo.namedExports.length > 0 | |
) { | |
continue; | |
} | |
const names = [ | |
...importInfo.defaultNames, | |
...importInfo.wildcardNames, | |
...importInfo.namedImports.map(({ localName }) => localName), | |
]; | |
if (names.every((name) => this.isTypeName(name))) { | |
this.importsToReplace.set(path, ""); | |
} | |
} | |
} | |
isTypeName(name) { | |
return ( | |
this.isTypeScriptTransformEnabled && !this.nonTypeIdentifiers.has(name) | |
); | |
} | |
generateImportReplacements() { | |
for (const [path, importInfo] of this.importInfoByPath.entries()) { | |
const { | |
defaultNames, | |
wildcardNames, | |
namedImports, | |
namedExports, | |
exportStarNames, | |
hasStarExport, | |
} = importInfo; | |
if ( | |
defaultNames.length === 0 && | |
wildcardNames.length === 0 && | |
namedImports.length === 0 && | |
namedExports.length === 0 && | |
exportStarNames.length === 0 && | |
!hasStarExport | |
) { | |
this.importsToReplace.set(path, `require('${path}');`); | |
continue; | |
} | |
const primaryImportName = this.getFreeIdentifierForPath(path); | |
let secondaryImportName; | |
if (this.enableLegacyTypeScriptModuleInterop) { | |
secondaryImportName = primaryImportName; | |
} else { | |
secondaryImportName = | |
wildcardNames.length > 0 | |
? wildcardNames[0] | |
: this.getFreeIdentifierForPath(path); | |
} | |
let requireCode = `var ${primaryImportName} = require('${path}');`; | |
if (wildcardNames.length > 0) { | |
for (const wildcardName of wildcardNames) { | |
const moduleExpr = this.enableLegacyTypeScriptModuleInterop | |
? primaryImportName | |
: `${this.helperManager.getHelperName( | |
"interopRequireWildcard" | |
)}(${primaryImportName})`; | |
requireCode += ` var ${wildcardName} = ${moduleExpr};`; | |
} | |
} else if ( | |
exportStarNames.length > 0 && | |
secondaryImportName !== primaryImportName | |
) { | |
requireCode += ` var ${secondaryImportName} = ${this.helperManager.getHelperName( | |
"interopRequireWildcard" | |
)}(${primaryImportName});`; | |
} else if ( | |
defaultNames.length > 0 && | |
secondaryImportName !== primaryImportName | |
) { | |
requireCode += ` var ${secondaryImportName} = ${this.helperManager.getHelperName( | |
"interopRequireDefault" | |
)}(${primaryImportName});`; | |
} | |
for (const { importedName, localName } of namedExports) { | |
requireCode += ` ${this.helperManager.getHelperName( | |
"createNamedExportFrom" | |
)}(${primaryImportName}, '${localName}', '${importedName}');`; | |
} | |
for (const exportStarName of exportStarNames) { | |
requireCode += ` exports.${exportStarName} = ${secondaryImportName};`; | |
} | |
if (hasStarExport) { | |
requireCode += ` ${this.helperManager.getHelperName( | |
"createStarExport" | |
)}(${primaryImportName});`; | |
} | |
this.importsToReplace.set(path, requireCode); | |
for (const defaultName of defaultNames) { | |
this.identifierReplacements.set( | |
defaultName, | |
`${secondaryImportName}.default` | |
); | |
} | |
for (const { importedName, localName } of namedImports) { | |
this.identifierReplacements.set( | |
localName, | |
`${primaryImportName}.${importedName}` | |
); | |
} | |
} | |
} | |
getFreeIdentifierForPath(path) { | |
const components = path.split("/"); | |
const lastComponent = components[components.length - 1]; | |
const baseName = lastComponent.replace(/\W/g, ""); | |
return this.nameManager.claimFreeName(`_${baseName}`); | |
} | |
preprocessImportAtIndex(index) { | |
const defaultNames = []; | |
const wildcardNames = []; | |
let namedImports = []; | |
index++; | |
if ( | |
(this.tokens.matchesContextualAtIndex(index, ContextualKeyword._type) || | |
this.tokens.matches1AtIndex(index, TokenType._typeof)) && | |
!this.tokens.matches1AtIndex(index + 1, TokenType.comma) && | |
!this.tokens.matchesContextualAtIndex(index + 1, ContextualKeyword._from) | |
) { | |
return; | |
} | |
if (this.tokens.matches1AtIndex(index, TokenType.parenL)) { | |
return; | |
} | |
if (this.tokens.matches1AtIndex(index, TokenType.name)) { | |
defaultNames.push(this.tokens.identifierNameAtIndex(index)); | |
index++; | |
if (this.tokens.matches1AtIndex(index, TokenType.comma)) { | |
index++; | |
} | |
} | |
if (this.tokens.matches1AtIndex(index, TokenType.star)) { | |
index += 2; | |
wildcardNames.push(this.tokens.identifierNameAtIndex(index)); | |
index++; | |
} | |
if (this.tokens.matches1AtIndex(index, TokenType.braceL)) { | |
index++; | |
({ newIndex: index, namedImports } = this.getNamedImports(index)); | |
} | |
if (this.tokens.matchesContextualAtIndex(index, ContextualKeyword._from)) { | |
index++; | |
} | |
if (!this.tokens.matches1AtIndex(index, TokenType.string)) { | |
throw new Error("Expected string token at the end of import statement."); | |
} | |
const path = this.tokens.stringValueAtIndex(index); | |
const importInfo = this.getImportInfo(path); | |
importInfo.defaultNames.push(...defaultNames); | |
importInfo.wildcardNames.push(...wildcardNames); | |
importInfo.namedImports.push(...namedImports); | |
if ( | |
defaultNames.length === 0 && | |
wildcardNames.length === 0 && | |
namedImports.length === 0 | |
) { | |
importInfo.hasBareImport = true; | |
} | |
} | |
preprocessExportAtIndex(index) { | |
if ( | |
this.tokens.matches2AtIndex(index, TokenType._export, TokenType._var) || | |
this.tokens.matches2AtIndex(index, TokenType._export, TokenType._let) || | |
this.tokens.matches2AtIndex(index, TokenType._export, TokenType._const) | |
) { | |
this.preprocessVarExportAtIndex(index); | |
} else if ( | |
this.tokens.matches2AtIndex( | |
index, | |
TokenType._export, | |
TokenType._function | |
) || | |
this.tokens.matches2AtIndex(index, TokenType._export, TokenType._class) | |
) { | |
const exportName = this.tokens.identifierNameAtIndex(index + 2); | |
this.addExportBinding(exportName, exportName); | |
} else if ( | |
this.tokens.matches3AtIndex( | |
index, | |
TokenType._export, | |
TokenType.name, | |
TokenType._function | |
) | |
) { | |
const exportName = this.tokens.identifierNameAtIndex(index + 3); | |
this.addExportBinding(exportName, exportName); | |
} else if ( | |
this.tokens.matches2AtIndex(index, TokenType._export, TokenType.braceL) | |
) { | |
this.preprocessNamedExportAtIndex(index); | |
} else if ( | |
this.tokens.matches2AtIndex(index, TokenType._export, TokenType.star) | |
) { | |
this.preprocessExportStarAtIndex(index); | |
} | |
} | |
preprocessVarExportAtIndex(index) { | |
let depth = 0; | |
for (let i = index + 2; ; i++) { | |
if ( | |
this.tokens.matches1AtIndex(i, TokenType.braceL) || | |
this.tokens.matches1AtIndex(i, TokenType.dollarBraceL) || | |
this.tokens.matches1AtIndex(i, TokenType.bracketL) | |
) { | |
depth++; | |
} else if ( | |
this.tokens.matches1AtIndex(i, TokenType.braceR) || | |
this.tokens.matches1AtIndex(i, TokenType.bracketR) | |
) { | |
depth--; | |
} else if ( | |
depth === 0 && | |
!this.tokens.matches1AtIndex(i, TokenType.name) | |
) { | |
break; | |
} else if (this.tokens.matches1AtIndex(1, TokenType.eq)) { | |
const endIndex = this.tokens.currentToken().rhsEndIndex; | |
if (endIndex == null) { | |
throw new Error("Expected = token with an end index."); | |
} | |
i = endIndex - 1; | |
} else { | |
const token = this.tokens.tokens[i]; | |
if (isDeclaration(token)) { | |
const exportName = this.tokens.identifierNameAtIndex(i); | |
this.identifierReplacements.set(exportName, `exports.${exportName}`); | |
} | |
} | |
} | |
} | |
preprocessNamedExportAtIndex(index) { | |
index += 2; | |
const { newIndex, namedImports } = this.getNamedImports(index); | |
index = newIndex; | |
if (this.tokens.matchesContextualAtIndex(index, ContextualKeyword._from)) { | |
index++; | |
} else { | |
for (const { | |
importedName: localName, | |
localName: exportedName, | |
} of namedImports) { | |
this.addExportBinding(localName, exportedName); | |
} | |
return; | |
} | |
if (!this.tokens.matches1AtIndex(index, TokenType.string)) { | |
throw new Error("Expected string token at the end of import statement."); | |
} | |
const path = this.tokens.stringValueAtIndex(index); | |
const importInfo = this.getImportInfo(path); | |
importInfo.namedExports.push(...namedImports); | |
} | |
preprocessExportStarAtIndex(index) { | |
let exportedName = null; | |
if ( | |
this.tokens.matches3AtIndex( | |
index, | |
TokenType._export, | |
TokenType.star, | |
TokenType._as | |
) | |
) { | |
index += 3; | |
exportedName = this.tokens.identifierNameAtIndex(index); | |
index += 2; | |
} else { | |
index += 3; | |
} | |
if (!this.tokens.matches1AtIndex(index, TokenType.string)) { | |
throw new Error( | |
"Expected string token at the end of star export statement." | |
); | |
} | |
const path = this.tokens.stringValueAtIndex(index); | |
const importInfo = this.getImportInfo(path); | |
if (exportedName !== null) { | |
importInfo.exportStarNames.push(exportedName); | |
} else { | |
importInfo.hasStarExport = true; | |
} | |
} | |
getNamedImports(index) { | |
const namedImports = []; | |
while (true) { | |
if (this.tokens.matches1AtIndex(index, TokenType.braceR)) { | |
index++; | |
break; | |
} | |
let isTypeImport = false; | |
if ( | |
(this.tokens.matchesContextualAtIndex(index, ContextualKeyword._type) || | |
this.tokens.matches1AtIndex(index, TokenType._typeof)) && | |
this.tokens.matches1AtIndex(index + 1, TokenType.name) && | |
!this.tokens.matchesContextualAtIndex(index + 1, ContextualKeyword._as) | |
) { | |
isTypeImport = true; | |
index++; | |
} | |
const importedName = this.tokens.identifierNameAtIndex(index); | |
let localName; | |
index++; | |
if (this.tokens.matchesContextualAtIndex(index, ContextualKeyword._as)) { | |
index++; | |
localName = this.tokens.identifierNameAtIndex(index); | |
index++; | |
} else { | |
localName = importedName; | |
} | |
if (!isTypeImport) { | |
namedImports.push({ importedName, localName }); | |
} | |
if ( | |
this.tokens.matches2AtIndex(index, TokenType.comma, TokenType.braceR) | |
) { | |
index += 2; | |
break; | |
} else if (this.tokens.matches1AtIndex(index, TokenType.braceR)) { | |
index++; | |
break; | |
} else if (this.tokens.matches1AtIndex(index, TokenType.comma)) { | |
index++; | |
} else { | |
throw new Error( | |
`Unexpected token: ${JSON.stringify(this.tokens.tokens[index])}` | |
); | |
} | |
} | |
return { newIndex: index, namedImports }; | |
} | |
getImportInfo(path) { | |
const existingInfo = this.importInfoByPath.get(path); | |
if (existingInfo) { | |
return existingInfo; | |
} | |
const newInfo = { | |
defaultNames: [], | |
wildcardNames: [], | |
namedImports: [], | |
namedExports: [], | |
hasBareImport: false, | |
exportStarNames: [], | |
hasStarExport: false, | |
}; | |
this.importInfoByPath.set(path, newInfo); | |
return newInfo; | |
} | |
addExportBinding(localName, exportedName) { | |
if (!this.exportBindingsByLocalName.has(localName)) { | |
this.exportBindingsByLocalName.set(localName, []); | |
} | |
this.exportBindingsByLocalName.get(localName).push(exportedName); | |
} | |
claimImportCode(importPath) { | |
const result = this.importsToReplace.get(importPath); | |
this.importsToReplace.set(importPath, ""); | |
return result || ""; | |
} | |
getIdentifierReplacement(identifierName) { | |
return this.identifierReplacements.get(identifierName) || null; | |
} | |
resolveExportBinding(assignedName) { | |
const exportedNames = this.exportBindingsByLocalName.get(assignedName); | |
if (!exportedNames || exportedNames.length === 0) { | |
return null; | |
} | |
return exportedNames | |
.map((exportedName) => `exports.${exportedName}`) | |
.join(" = "); | |
} | |
getGlobalNames() { | |
return new Set([ | |
...this.identifierReplacements.keys(), | |
...this.exportBindingsByLocalName.keys(), | |
]); | |
} | |
} | |
function computeSourceMap(code, filePath, { compiledFilename }) { | |
let mappings = "AAAA"; | |
for (let i = 0; i < code.length; i++) { | |
if (code.charCodeAt(i) === charCodes.lineFeed) { | |
mappings += ";AACA"; | |
} | |
} | |
return { | |
version: 3, | |
file: compiledFilename || "", | |
sources: [filePath], | |
mappings, | |
names: [], | |
}; | |
} | |
const HELPERS = { | |
interopRequireWildcard: ` | |
function interopRequireWildcard(obj) { | |
if (obj && obj.__esModule) { | |
return obj; | |
} else { | |
var newObj = {}; | |
if (obj != null) { | |
for (var key in obj) { | |
if (Object.prototype.hasOwnProperty.call(obj, key)) { | |
newObj[key] = obj[key]; | |
} | |
} | |
} | |
newObj.default = obj; | |
return newObj; | |
} | |
} | |
`, | |
interopRequireDefault: ` | |
function interopRequireDefault(obj) { | |
return obj && obj.__esModule ? obj : { default: obj }; | |
} | |
`, | |
createNamedExportFrom: ` | |
function createNamedExportFrom(obj, localName, importedName) { | |
Object.defineProperty(exports, localName, {enumerable: true, get: () => obj[importedName]}); | |
} | |
`, | |
createStarExport: ` | |
function createStarExport(obj) { | |
Object.keys(obj) | |
.filter((key) => key !== "default" && key !== "__esModule") | |
.forEach((key) => { | |
if (exports.hasOwnProperty(key)) { | |
return; | |
} | |
Object.defineProperty(exports, key, {enumerable: true, get: () => obj[key]}); | |
}); | |
} | |
`, | |
nullishCoalesce: ` | |
function nullishCoalesce(lhs, rhsFn) { | |
if (lhs != null) { | |
return lhs; | |
} else { | |
return rhsFn(); | |
} | |
} | |
`, | |
asyncNullishCoalesce: ` | |
async function asyncNullishCoalesce(lhs, rhsFn) { | |
if (lhs != null) { | |
return lhs; | |
} else { | |
return await rhsFn(); | |
} | |
} | |
`, | |
optionalChain: ` | |
function optionalChain(ops) { | |
let lastAccessLHS = undefined; | |
let value = ops[0]; | |
let i = 1; | |
while (i < ops.length) { | |
const op = ops[i]; | |
const fn = ops[i + 1]; | |
i += 2; | |
if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { | |
return undefined; | |
} | |
if (op === 'access' || op === 'optionalAccess') { | |
lastAccessLHS = value; | |
value = fn(value); | |
} else if (op === 'call' || op === 'optionalCall') { | |
value = fn((...args) => value.call(lastAccessLHS, ...args)); | |
lastAccessLHS = undefined; | |
} | |
} | |
return value; | |
} | |
`, | |
asyncOptionalChain: ` | |
async function asyncOptionalChain(ops) { | |
let lastAccessLHS = undefined; | |
let value = ops[0]; | |
let i = 1; | |
while (i < ops.length) { | |
const op = ops[i]; | |
const fn = ops[i + 1]; | |
i += 2; | |
if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { | |
return undefined; | |
} | |
if (op === 'access' || op === 'optionalAccess') { | |
lastAccessLHS = value; | |
value = await fn(value); | |
} else if (op === 'call' || op === 'optionalCall') { | |
value = await fn((...args) => value.call(lastAccessLHS, ...args)); | |
lastAccessLHS = undefined; | |
} | |
} | |
return value; | |
} | |
`, | |
optionalChainDelete: ` | |
function optionalChainDelete(ops) { | |
const result = OPTIONAL_CHAIN_NAME(ops); | |
return result == null ? true : result; | |
} | |
`, | |
asyncOptionalChainDelete: ` | |
async function asyncOptionalChainDelete(ops) { | |
const result = await ASYNC_OPTIONAL_CHAIN_NAME(ops); | |
return result == null ? true : result; | |
} | |
`, | |
}; | |
class HelperManager { | |
__init() { | |
this.helperNames = {}; | |
} | |
constructor(nameManager) { | |
this.nameManager = nameManager; | |
HelperManager.prototype.__init.call(this); | |
} | |
getHelperName(baseName) { | |
let helperName = this.helperNames[baseName]; | |
if (helperName) { | |
return helperName; | |
} | |
helperName = this.nameManager.claimFreeName(`_${baseName}`); | |
this.helperNames[baseName] = helperName; | |
return helperName; | |
} | |
emitHelpers() { | |
let resultCode = ""; | |
if (this.helperNames.optionalChainDelete) { | |
this.getHelperName("optionalChain"); | |
} | |
if (this.helperNames.asyncOptionalChainDelete) { | |
this.getHelperName("asyncOptionalChain"); | |
} | |
for (const [baseName, helperCodeTemplate] of Object.entries(HELPERS)) { | |
const helperName = this.helperNames[baseName]; | |
let helperCode = helperCodeTemplate; | |
if (baseName === "optionalChainDelete") { | |
helperCode = helperCode.replace( | |
"OPTIONAL_CHAIN_NAME", | |
this.helperNames.optionalChain | |
); | |
} else if (baseName === "asyncOptionalChainDelete") { | |
helperCode = helperCode.replace( | |
"ASYNC_OPTIONAL_CHAIN_NAME", | |
this.helperNames.asyncOptionalChain | |
); | |
} | |
if (helperName) { | |
resultCode += " "; | |
resultCode += helperCode | |
.replace(baseName, helperName) | |
.replace(/\s+/g, " ") | |
.trim(); | |
} | |
} | |
return resultCode; | |
} | |
} | |
function identifyShadowedGlobals(tokens, scopes, globalNames) { | |
if (!hasShadowedGlobals(tokens, globalNames)) { | |
return; | |
} | |
markShadowedGlobals(tokens, scopes, globalNames); | |
} | |
function hasShadowedGlobals(tokens, globalNames) { | |
for (const token of tokens.tokens) { | |
if ( | |
token.type === TokenType.name && | |
isNonTopLevelDeclaration(token) && | |
globalNames.has(tokens.identifierNameForToken(token)) | |
) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function markShadowedGlobals(tokens, scopes, globalNames) { | |
const scopeStack = []; | |
let scopeIndex = scopes.length - 1; | |
for (let i = tokens.tokens.length - 1; ; i--) { | |
while ( | |
scopeStack.length > 0 && | |
scopeStack[scopeStack.length - 1].startTokenIndex === i + 1 | |
) { | |
scopeStack.pop(); | |
} | |
while (scopeIndex >= 0 && scopes[scopeIndex].endTokenIndex === i + 1) { | |
scopeStack.push(scopes[scopeIndex]); | |
scopeIndex--; | |
} | |
if (i < 0) { | |
break; | |
} | |
const token = tokens.tokens[i]; | |
const name = tokens.identifierNameForToken(token); | |
if ( | |
scopeStack.length > 1 && | |
token.type === TokenType.name && | |
globalNames.has(name) | |
) { | |
if (isBlockScopedDeclaration(token)) { | |
markShadowedForScope(scopeStack[scopeStack.length - 1], tokens, name); | |
} else if (isFunctionScopedDeclaration(token)) { | |
let stackIndex = scopeStack.length - 1; | |
while (stackIndex > 0 && !scopeStack[stackIndex].isFunctionScope) { | |
stackIndex--; | |
} | |
if (stackIndex < 0) { | |
throw new Error("Did not find parent function scope."); | |
} | |
markShadowedForScope(scopeStack[stackIndex], tokens, name); | |
} | |
} | |
} | |
if (scopeStack.length > 0) { | |
throw new Error("Expected empty scope stack after processing file."); | |
} | |
} | |
function markShadowedForScope(scope, tokens, name) { | |
for (let i = scope.startTokenIndex; i < scope.endTokenIndex; i++) { | |
const token = tokens.tokens[i]; | |
if ( | |
token.type === TokenType.name && | |
tokens.identifierNameForToken(token) === name | |
) { | |
token.shadowsGlobal = true; | |
} | |
} | |
} | |
function getIdentifierNames(code, tokens) { | |
const names = []; | |
for (const token of tokens) { | |
if (token.type === TokenType.name) { | |
names.push(code.slice(token.start, token.end)); | |
} | |
} | |
return names; | |
} | |
class NameManager { | |
__init() { | |
this.usedNames = new Set(); | |
} | |
constructor(code, tokens) { | |
NameManager.prototype.__init.call(this); | |
this.usedNames = new Set(getIdentifierNames(code, tokens)); | |
} | |
claimFreeName(name) { | |
const newName = this.findFreeName(name); | |
this.usedNames.add(newName); | |
return newName; | |
} | |
findFreeName(name) { | |
if (!this.usedNames.has(name)) { | |
return name; | |
} | |
let suffixNum = 2; | |
while (this.usedNames.has(name + suffixNum)) { | |
suffixNum++; | |
} | |
return name + suffixNum; | |
} | |
} | |
const Transform = union( | |
lit("jsx"), | |
lit("typescript"), | |
lit("flow"), | |
lit("imports"), | |
lit("react-hot-loader") | |
); | |
const SourceMapOptions = iface([], { | |
compiledFilename: "string", | |
}); | |
const Options = iface([], { | |
transforms: array("Transform"), | |
jsxPragma: opt("string"), | |
jsxFragmentPragma: opt("string"), | |
enableLegacyTypeScriptModuleInterop: opt("boolean"), | |
enableLegacyBabel5ModuleInterop: opt("boolean"), | |
sourceMapOptions: opt("SourceMapOptions"), | |
filePath: opt("string"), | |
production: opt("boolean"), | |
}); | |
const exportedTypeSuite = { | |
Transform, | |
SourceMapOptions, | |
Options, | |
}; | |
const { Options: OptionsChecker } = createCheckers(exportedTypeSuite); | |
function validateOptions(options) { | |
OptionsChecker.strictCheck(options); | |
} | |
function parseSpread() { | |
next(); | |
parseMaybeAssign(false); | |
} | |
function parseRest(isBlockScope) { | |
next(); | |
parseBindingAtom(isBlockScope); | |
} | |
function parseBindingIdentifier(isBlockScope) { | |
parseIdentifier(); | |
markPriorBindingIdentifier(isBlockScope); | |
} | |
function parseImportedIdentifier() { | |
parseIdentifier(); | |
state.tokens[state.tokens.length - 1].identifierRole = | |
IdentifierRole.ImportDeclaration; | |
} | |
function markPriorBindingIdentifier(isBlockScope) { | |
if (state.scopeDepth === 0) { | |
state.tokens[state.tokens.length - 1].identifierRole = | |
IdentifierRole.TopLevelDeclaration; | |
} else { | |
state.tokens[state.tokens.length - 1].identifierRole = isBlockScope | |
? IdentifierRole.BlockScopedDeclaration | |
: IdentifierRole.FunctionScopedDeclaration; | |
} | |
} | |
function parseBindingAtom(isBlockScope) { | |
switch (state.type) { | |
case TokenType._this: { | |
const oldIsType = pushTypeContext(0); | |
next(); | |
popTypeContext(oldIsType); | |
return; | |
} | |
case TokenType._yield: | |
case TokenType.name: { | |
state.type = TokenType.name; | |
parseBindingIdentifier(isBlockScope); | |
return; | |
} | |
case TokenType.bracketL: { | |
next(); | |
parseBindingList(TokenType.bracketR, isBlockScope, true); | |
return; | |
} | |
case TokenType.braceL: | |
parseObj(true, isBlockScope); | |
return; | |
default: | |
unexpected(); | |
} | |
} | |
function parseBindingList( | |
close, | |
isBlockScope, | |
allowEmpty = false, | |
allowModifiers = false, | |
contextId = 0 | |
) { | |
let first = true; | |
let hasRemovedComma = false; | |
const firstItemTokenIndex = state.tokens.length; | |
while (!eat(close) && !state.error) { | |
if (first) { | |
first = false; | |
} else { | |
expect(TokenType.comma); | |
state.tokens[state.tokens.length - 1].contextId = contextId; | |
if (!hasRemovedComma && state.tokens[firstItemTokenIndex].isType) { | |
state.tokens[state.tokens.length - 1].isType = true; | |
hasRemovedComma = true; | |
} | |
} | |
if (allowEmpty && match(TokenType.comma)); | |
else if (eat(close)) { | |
break; | |
} else if (match(TokenType.ellipsis)) { | |
parseRest(isBlockScope); | |
parseAssignableListItemTypes(); | |
eat(TokenType.comma); | |
expect(close); | |
break; | |
} else { | |
parseAssignableListItem(allowModifiers, isBlockScope); | |
} | |
} | |
} | |
function parseAssignableListItem(allowModifiers, isBlockScope) { | |
if (allowModifiers) { | |
tsParseAccessModifier(); | |
tsParseModifier([ContextualKeyword._readonly]); | |
} | |
parseMaybeDefault(isBlockScope); | |
parseAssignableListItemTypes(); | |
parseMaybeDefault(isBlockScope, true); | |
} | |
function parseAssignableListItemTypes() { | |
if (isFlowEnabled) { | |
flowParseAssignableListItemTypes(); | |
} else if (isTypeScriptEnabled) { | |
tsParseAssignableListItemTypes(); | |
} | |
} | |
function parseMaybeDefault(isBlockScope, leftAlreadyParsed = false) { | |
if (!leftAlreadyParsed) { | |
parseBindingAtom(isBlockScope); | |
} | |
if (!eat(TokenType.eq)) { | |
return; | |
} | |
const eqIndex = state.tokens.length - 1; | |
parseMaybeAssign(); | |
state.tokens[eqIndex].rhsEndIndex = state.tokens.length; | |
} | |
function tsIsIdentifier() { | |
return match(TokenType.name); | |
} | |
function tsNextTokenCanFollowModifier() { | |
const snapshot = state.snapshot(); | |
next(); | |
const canFollowModifier = | |
!hasPrecedingLineBreak() && | |
!match(TokenType.parenL) && | |
!match(TokenType.parenR) && | |
!match(TokenType.colon) && | |
!match(TokenType.eq) && | |
!match(TokenType.question) && | |
!match(TokenType.bang); | |
if (canFollowModifier) { | |
return true; | |
} else { | |
state.restoreFromSnapshot(snapshot); | |
return false; | |
} | |
} | |
function tsParseModifier(allowedModifiers) { | |
if (!match(TokenType.name)) { | |
return null; | |
} | |
const modifier = state.contextualKeyword; | |
if ( | |
allowedModifiers.indexOf(modifier) !== -1 && | |
tsNextTokenCanFollowModifier() | |
) { | |
switch (modifier) { | |
case ContextualKeyword._readonly: | |
state.tokens[state.tokens.length - 1].type = TokenType._readonly; | |
break; | |
case ContextualKeyword._abstract: | |
state.tokens[state.tokens.length - 1].type = TokenType._abstract; | |
break; | |
case ContextualKeyword._static: | |
state.tokens[state.tokens.length - 1].type = TokenType._static; | |
break; | |
case ContextualKeyword._public: | |
state.tokens[state.tokens.length - 1].type = TokenType._public; | |
break; | |
case ContextualKeyword._private: | |
state.tokens[state.tokens.length - 1].type = TokenType._private; | |
break; | |
case ContextualKeyword._protected: | |
state.tokens[state.tokens.length - 1].type = TokenType._protected; | |
break; | |
case ContextualKeyword._declare: | |
state.tokens[state.tokens.length - 1].type = TokenType._declare; | |
break; | |
} | |
return modifier; | |
} | |
return null; | |
} | |
function tsParseEntityName() { | |
parseIdentifier(); | |
while (eat(TokenType.dot)) { | |
parseIdentifier(); | |
} | |
} | |
function tsParseTypeReference() { | |
tsParseEntityName(); | |
if (!hasPrecedingLineBreak() && match(TokenType.lessThan)) { | |
tsParseTypeArguments(); | |
} | |
} | |
function tsParseThisTypePredicate() { | |
next(); | |
tsParseTypeAnnotation(); | |
} | |
function tsParseThisTypeNode() { | |
next(); | |
} | |
function tsParseTypeQuery() { | |
expect(TokenType._typeof); | |
if (match(TokenType._import)) { | |
tsParseImportType(); | |
} else { | |
tsParseEntityName(); | |
} | |
} | |
function tsParseImportType() { | |
expect(TokenType._import); | |
expect(TokenType.parenL); | |
expect(TokenType.string); | |
expect(TokenType.parenR); | |
if (eat(TokenType.dot)) { | |
tsParseEntityName(); | |
} | |
if (match(TokenType.lessThan)) { | |
tsParseTypeArguments(); | |
} | |
} | |
function tsParseTypeParameter() { | |
parseIdentifier(); | |
if (eat(TokenType._extends)) { | |
tsParseType(); | |
} | |
if (eat(TokenType.eq)) { | |
tsParseType(); | |
} | |
} | |
function tsTryParseTypeParameters() { | |
if (match(TokenType.lessThan)) { | |
tsParseTypeParameters(); | |
} | |
} | |
function tsParseTypeParameters() { | |
const oldIsType = pushTypeContext(0); | |
if (match(TokenType.lessThan) || match(TokenType.typeParameterStart)) { | |
next(); | |
} else { | |
unexpected(); | |
} | |
while (!eat(TokenType.greaterThan) && !state.error) { | |
tsParseTypeParameter(); | |
eat(TokenType.comma); | |
} | |
popTypeContext(oldIsType); | |
} | |
function tsFillSignature(returnToken) { | |
const returnTokenRequired = returnToken === TokenType.arrow; | |
tsTryParseTypeParameters(); | |
expect(TokenType.parenL); | |
state.scopeDepth++; | |
tsParseBindingListForSignature(false); | |
state.scopeDepth--; | |
if (returnTokenRequired) { | |
tsParseTypeOrTypePredicateAnnotation(returnToken); | |
} else if (match(returnToken)) { | |
tsParseTypeOrTypePredicateAnnotation(returnToken); | |
} | |
} | |
function tsParseBindingListForSignature(isBlockScope) { | |
parseBindingList(TokenType.parenR, isBlockScope); | |
} | |
function tsParseTypeMemberSemicolon() { | |
if (!eat(TokenType.comma)) { | |
semicolon(); | |
} | |
} | |
function tsParseSignatureMember() { | |
tsFillSignature(TokenType.colon); | |
tsParseTypeMemberSemicolon(); | |
} | |
function tsIsUnambiguouslyIndexSignature() { | |
const snapshot = state.snapshot(); | |
next(); | |
const isIndexSignature = eat(TokenType.name) && match(TokenType.colon); | |
state.restoreFromSnapshot(snapshot); | |
return isIndexSignature; | |
} | |
function tsTryParseIndexSignature() { | |
if (!(match(TokenType.bracketL) && tsIsUnambiguouslyIndexSignature())) { | |
return false; | |
} | |
const oldIsType = pushTypeContext(0); | |
expect(TokenType.bracketL); | |
parseIdentifier(); | |
tsParseTypeAnnotation(); | |
expect(TokenType.bracketR); | |
tsTryParseTypeAnnotation(); | |
tsParseTypeMemberSemicolon(); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
function tsParsePropertyOrMethodSignature(isReadonly) { | |
eat(TokenType.question); | |
if (!isReadonly && (match(TokenType.parenL) || match(TokenType.lessThan))) { | |
tsFillSignature(TokenType.colon); | |
tsParseTypeMemberSemicolon(); | |
} else { | |
tsTryParseTypeAnnotation(); | |
tsParseTypeMemberSemicolon(); | |
} | |
} | |
function tsParseTypeMember() { | |
if (match(TokenType.parenL) || match(TokenType.lessThan)) { | |
tsParseSignatureMember(); | |
return; | |
} | |
if (match(TokenType._new)) { | |
next(); | |
if (match(TokenType.parenL) || match(TokenType.lessThan)) { | |
tsParseSignatureMember(); | |
} else { | |
tsParsePropertyOrMethodSignature(false); | |
} | |
return; | |
} | |
const readonly = !!tsParseModifier([ContextualKeyword._readonly]); | |
const found = tsTryParseIndexSignature(); | |
if (found) { | |
return; | |
} | |
parsePropertyName(-1); | |
tsParsePropertyOrMethodSignature(readonly); | |
} | |
function tsParseTypeLiteral() { | |
tsParseObjectTypeMembers(); | |
} | |
function tsParseObjectTypeMembers() { | |
expect(TokenType.braceL); | |
while (!eat(TokenType.braceR) && !state.error) { | |
tsParseTypeMember(); | |
} | |
} | |
function tsLookaheadIsStartOfMappedType() { | |
const snapshot = state.snapshot(); | |
const isStartOfMappedType = tsIsStartOfMappedType(); | |
state.restoreFromSnapshot(snapshot); | |
return isStartOfMappedType; | |
} | |
function tsIsStartOfMappedType() { | |
next(); | |
if (eat(TokenType.plus) || eat(TokenType.minus)) { | |
return isContextual(ContextualKeyword._readonly); | |
} | |
if (isContextual(ContextualKeyword._readonly)) { | |
next(); | |
} | |
if (!match(TokenType.bracketL)) { | |
return false; | |
} | |
next(); | |
if (!tsIsIdentifier()) { | |
return false; | |
} | |
next(); | |
return match(TokenType._in); | |
} | |
function tsParseMappedTypeParameter() { | |
parseIdentifier(); | |
expect(TokenType._in); | |
tsParseType(); | |
} | |
function tsParseMappedType() { | |
expect(TokenType.braceL); | |
if (match(TokenType.plus) || match(TokenType.minus)) { | |
next(); | |
expectContextual(ContextualKeyword._readonly); | |
} else { | |
eatContextual(ContextualKeyword._readonly); | |
} | |
expect(TokenType.bracketL); | |
tsParseMappedTypeParameter(); | |
expect(TokenType.bracketR); | |
if (match(TokenType.plus) || match(TokenType.minus)) { | |
next(); | |
expect(TokenType.question); | |
} else { | |
eat(TokenType.question); | |
} | |
tsTryParseType(); | |
semicolon(); | |
expect(TokenType.braceR); | |
} | |
function tsParseTupleType() { | |
expect(TokenType.bracketL); | |
while (!eat(TokenType.bracketR) && !state.error) { | |
tsParseTupleElementType(); | |
eat(TokenType.comma); | |
} | |
} | |
function tsParseTupleElementType() { | |
if (eat(TokenType.ellipsis)) { | |
tsParseType(); | |
} else { | |
tsParseType(); | |
eat(TokenType.question); | |
} | |
if (eat(TokenType.colon)) { | |
tsParseType(); | |
} | |
} | |
function tsParseParenthesizedType() { | |
expect(TokenType.parenL); | |
tsParseType(); | |
expect(TokenType.parenR); | |
} | |
var FunctionType; | |
(function (FunctionType2) { | |
const TSFunctionType = 0; | |
FunctionType2[(FunctionType2["TSFunctionType"] = TSFunctionType)] = | |
"TSFunctionType"; | |
const TSConstructorType = TSFunctionType + 1; | |
FunctionType2[(FunctionType2["TSConstructorType"] = TSConstructorType)] = | |
"TSConstructorType"; | |
})(FunctionType || (FunctionType = {})); | |
function tsParseFunctionOrConstructorType(type) { | |
if (type === FunctionType.TSConstructorType) { | |
expect(TokenType._new); | |
} | |
tsFillSignature(TokenType.arrow); | |
} | |
function tsParseNonArrayType() { | |
switch (state.type) { | |
case TokenType.name: | |
tsParseTypeReference(); | |
return; | |
case TokenType._void: | |
case TokenType._null: | |
next(); | |
return; | |
case TokenType.string: | |
case TokenType.num: | |
case TokenType.bigint: | |
case TokenType.decimal: | |
case TokenType._true: | |
case TokenType._false: | |
parseLiteral(); | |
return; | |
case TokenType.minus: | |
next(); | |
parseLiteral(); | |
return; | |
case TokenType._this: { | |
tsParseThisTypeNode(); | |
if (isContextual(ContextualKeyword._is) && !hasPrecedingLineBreak()) { | |
tsParseThisTypePredicate(); | |
} | |
return; | |
} | |
case TokenType._typeof: | |
tsParseTypeQuery(); | |
return; | |
case TokenType._import: | |
tsParseImportType(); | |
return; | |
case TokenType.braceL: | |
if (tsLookaheadIsStartOfMappedType()) { | |
tsParseMappedType(); | |
} else { | |
tsParseTypeLiteral(); | |
} | |
return; | |
case TokenType.bracketL: | |
tsParseTupleType(); | |
return; | |
case TokenType.parenL: | |
tsParseParenthesizedType(); | |
return; | |
case TokenType.backQuote: | |
parseTemplate(); | |
return; | |
default: | |
if (state.type & TokenType.IS_KEYWORD) { | |
next(); | |
state.tokens[state.tokens.length - 1].type = TokenType.name; | |
return; | |
} | |
break; | |
} | |
unexpected(); | |
} | |
function tsParseArrayTypeOrHigher() { | |
tsParseNonArrayType(); | |
while (!hasPrecedingLineBreak() && eat(TokenType.bracketL)) { | |
if (!eat(TokenType.bracketR)) { | |
tsParseType(); | |
expect(TokenType.bracketR); | |
} | |
} | |
} | |
function tsParseInferType() { | |
expectContextual(ContextualKeyword._infer); | |
parseIdentifier(); | |
} | |
function tsParseTypeOperatorOrHigher() { | |
if ( | |
isContextual(ContextualKeyword._keyof) || | |
isContextual(ContextualKeyword._unique) || | |
isContextual(ContextualKeyword._readonly) | |
) { | |
next(); | |
tsParseTypeOperatorOrHigher(); | |
} else if (isContextual(ContextualKeyword._infer)) { | |
tsParseInferType(); | |
} else { | |
tsParseArrayTypeOrHigher(); | |
} | |
} | |
function tsParseIntersectionTypeOrHigher() { | |
eat(TokenType.bitwiseAND); | |
tsParseTypeOperatorOrHigher(); | |
if (match(TokenType.bitwiseAND)) { | |
while (eat(TokenType.bitwiseAND)) { | |
tsParseTypeOperatorOrHigher(); | |
} | |
} | |
} | |
function tsParseUnionTypeOrHigher() { | |
eat(TokenType.bitwiseOR); | |
tsParseIntersectionTypeOrHigher(); | |
if (match(TokenType.bitwiseOR)) { | |
while (eat(TokenType.bitwiseOR)) { | |
tsParseIntersectionTypeOrHigher(); | |
} | |
} | |
} | |
function tsIsStartOfFunctionType() { | |
if (match(TokenType.lessThan)) { | |
return true; | |
} | |
return ( | |
match(TokenType.parenL) && tsLookaheadIsUnambiguouslyStartOfFunctionType() | |
); | |
} | |
function tsSkipParameterStart() { | |
if (match(TokenType.name) || match(TokenType._this)) { | |
next(); | |
return true; | |
} | |
if (match(TokenType.braceL) || match(TokenType.bracketL)) { | |
let depth = 1; | |
next(); | |
while (depth > 0 && !state.error) { | |
if (match(TokenType.braceL) || match(TokenType.bracketL)) { | |
depth++; | |
} else if (match(TokenType.braceR) || match(TokenType.bracketR)) { | |
depth--; | |
} | |
next(); | |
} | |
return true; | |
} | |
return false; | |
} | |
function tsLookaheadIsUnambiguouslyStartOfFunctionType() { | |
const snapshot = state.snapshot(); | |
const isUnambiguouslyStartOfFunctionType = tsIsUnambiguouslyStartOfFunctionType(); | |
state.restoreFromSnapshot(snapshot); | |
return isUnambiguouslyStartOfFunctionType; | |
} | |
function tsIsUnambiguouslyStartOfFunctionType() { | |
next(); | |
if (match(TokenType.parenR) || match(TokenType.ellipsis)) { | |
return true; | |
} | |
if (tsSkipParameterStart()) { | |
if ( | |
match(TokenType.colon) || | |
match(TokenType.comma) || | |
match(TokenType.question) || | |
match(TokenType.eq) | |
) { | |
return true; | |
} | |
if (match(TokenType.parenR)) { | |
next(); | |
if (match(TokenType.arrow)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
function tsParseTypeOrTypePredicateAnnotation(returnToken) { | |
const oldIsType = pushTypeContext(0); | |
expect(returnToken); | |
const finishedReturn = tsParseTypePredicateOrAssertsPrefix(); | |
if (!finishedReturn) { | |
tsParseType(); | |
} | |
popTypeContext(oldIsType); | |
} | |
function tsTryParseTypeOrTypePredicateAnnotation() { | |
if (match(TokenType.colon)) { | |
tsParseTypeOrTypePredicateAnnotation(TokenType.colon); | |
} | |
} | |
function tsTryParseTypeAnnotation() { | |
if (match(TokenType.colon)) { | |
tsParseTypeAnnotation(); | |
} | |
} | |
function tsTryParseType() { | |
if (eat(TokenType.colon)) { | |
tsParseType(); | |
} | |
} | |
function tsParseTypePredicateOrAssertsPrefix() { | |
const snapshot = state.snapshot(); | |
if (isContextual(ContextualKeyword._asserts) && !hasPrecedingLineBreak()) { | |
next(); | |
if (eatContextual(ContextualKeyword._is)) { | |
tsParseType(); | |
return true; | |
} else if (tsIsIdentifier() || match(TokenType._this)) { | |
next(); | |
if (eatContextual(ContextualKeyword._is)) { | |
tsParseType(); | |
} | |
return true; | |
} else { | |
state.restoreFromSnapshot(snapshot); | |
return false; | |
} | |
} else if (tsIsIdentifier() || match(TokenType._this)) { | |
next(); | |
if (isContextual(ContextualKeyword._is) && !hasPrecedingLineBreak()) { | |
next(); | |
tsParseType(); | |
return true; | |
} else { | |
state.restoreFromSnapshot(snapshot); | |
return false; | |
} | |
} | |
return false; | |
} | |
function tsParseTypeAnnotation() { | |
const oldIsType = pushTypeContext(0); | |
expect(TokenType.colon); | |
tsParseType(); | |
popTypeContext(oldIsType); | |
} | |
function tsParseType() { | |
tsParseNonConditionalType(); | |
if (hasPrecedingLineBreak() || !eat(TokenType._extends)) { | |
return; | |
} | |
tsParseNonConditionalType(); | |
expect(TokenType.question); | |
tsParseType(); | |
expect(TokenType.colon); | |
tsParseType(); | |
} | |
function tsParseNonConditionalType() { | |
if (tsIsStartOfFunctionType()) { | |
tsParseFunctionOrConstructorType(FunctionType.TSFunctionType); | |
return; | |
} | |
if (match(TokenType._new)) { | |
tsParseFunctionOrConstructorType(FunctionType.TSConstructorType); | |
return; | |
} | |
tsParseUnionTypeOrHigher(); | |
} | |
function tsParseTypeAssertion() { | |
const oldIsType = pushTypeContext(1); | |
tsParseType(); | |
expect(TokenType.greaterThan); | |
popTypeContext(oldIsType); | |
parseMaybeUnary(); | |
} | |
function tsTryParseJSXTypeArgument() { | |
if (eat(TokenType.jsxTagStart)) { | |
state.tokens[state.tokens.length - 1].type = TokenType.typeParameterStart; | |
const oldIsType = pushTypeContext(1); | |
while (!match(TokenType.greaterThan) && !state.error) { | |
tsParseType(); | |
eat(TokenType.comma); | |
} | |
nextJSXTagToken(); | |
popTypeContext(oldIsType); | |
} | |
} | |
function tsParseHeritageClause() { | |
while (!match(TokenType.braceL) && !state.error) { | |
tsParseExpressionWithTypeArguments(); | |
eat(TokenType.comma); | |
} | |
} | |
function tsParseExpressionWithTypeArguments() { | |
tsParseEntityName(); | |
if (match(TokenType.lessThan)) { | |
tsParseTypeArguments(); | |
} | |
} | |
function tsParseInterfaceDeclaration() { | |
parseBindingIdentifier(false); | |
tsTryParseTypeParameters(); | |
if (eat(TokenType._extends)) { | |
tsParseHeritageClause(); | |
} | |
tsParseObjectTypeMembers(); | |
} | |
function tsParseTypeAliasDeclaration() { | |
parseBindingIdentifier(false); | |
tsTryParseTypeParameters(); | |
expect(TokenType.eq); | |
tsParseType(); | |
semicolon(); | |
} | |
function tsParseEnumMember() { | |
if (match(TokenType.string)) { | |
parseLiteral(); | |
} else { | |
parseIdentifier(); | |
} | |
if (eat(TokenType.eq)) { | |
const eqIndex = state.tokens.length - 1; | |
parseMaybeAssign(); | |
state.tokens[eqIndex].rhsEndIndex = state.tokens.length; | |
} | |
} | |
function tsParseEnumDeclaration() { | |
parseBindingIdentifier(false); | |
expect(TokenType.braceL); | |
while (!eat(TokenType.braceR) && !state.error) { | |
tsParseEnumMember(); | |
eat(TokenType.comma); | |
} | |
} | |
function tsParseModuleBlock() { | |
expect(TokenType.braceL); | |
parseBlockBody(TokenType.braceR); | |
} | |
function tsParseModuleOrNamespaceDeclaration() { | |
parseBindingIdentifier(false); | |
if (eat(TokenType.dot)) { | |
tsParseModuleOrNamespaceDeclaration(); | |
} else { | |
tsParseModuleBlock(); | |
} | |
} | |
function tsParseAmbientExternalModuleDeclaration() { | |
if (isContextual(ContextualKeyword._global)) { | |
parseIdentifier(); | |
} else if (match(TokenType.string)) { | |
parseExprAtom(); | |
} else { | |
unexpected(); | |
} | |
if (match(TokenType.braceL)) { | |
tsParseModuleBlock(); | |
} else { | |
semicolon(); | |
} | |
} | |
function tsParseImportEqualsDeclaration() { | |
parseImportedIdentifier(); | |
expect(TokenType.eq); | |
tsParseModuleReference(); | |
semicolon(); | |
} | |
function tsIsExternalModuleReference() { | |
return ( | |
isContextual(ContextualKeyword._require) && | |
lookaheadType() === TokenType.parenL | |
); | |
} | |
function tsParseModuleReference() { | |
if (tsIsExternalModuleReference()) { | |
tsParseExternalModuleReference(); | |
} else { | |
tsParseEntityName(); | |
} | |
} | |
function tsParseExternalModuleReference() { | |
expectContextual(ContextualKeyword._require); | |
expect(TokenType.parenL); | |
if (!match(TokenType.string)) { | |
unexpected(); | |
} | |
parseLiteral(); | |
expect(TokenType.parenR); | |
} | |
function tsTryParseDeclare() { | |
if (isLineTerminator()) { | |
return false; | |
} | |
switch (state.type) { | |
case TokenType._function: { | |
const oldIsType = pushTypeContext(1); | |
next(); | |
const functionStart = state.start; | |
parseFunction(functionStart, true); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
case TokenType._class: { | |
const oldIsType = pushTypeContext(1); | |
parseClass(true, false); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
case TokenType._const: { | |
if ( | |
match(TokenType._const) && | |
isLookaheadContextual(ContextualKeyword._enum) | |
) { | |
const oldIsType = pushTypeContext(1); | |
expect(TokenType._const); | |
expectContextual(ContextualKeyword._enum); | |
state.tokens[state.tokens.length - 1].type = TokenType._enum; | |
tsParseEnumDeclaration(); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
} | |
case TokenType._var: | |
case TokenType._let: { | |
const oldIsType = pushTypeContext(1); | |
parseVarStatement(state.type); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
case TokenType.name: { | |
const oldIsType = pushTypeContext(1); | |
const contextualKeyword = state.contextualKeyword; | |
let matched = false; | |
if (contextualKeyword === ContextualKeyword._global) { | |
tsParseAmbientExternalModuleDeclaration(); | |
matched = true; | |
} else { | |
matched = tsParseDeclaration(contextualKeyword, true); | |
} | |
popTypeContext(oldIsType); | |
return matched; | |
} | |
default: | |
return false; | |
} | |
} | |
function tsTryParseExportDeclaration() { | |
return tsParseDeclaration(state.contextualKeyword, true); | |
} | |
function tsParseExpressionStatement(contextualKeyword) { | |
switch (contextualKeyword) { | |
case ContextualKeyword._declare: { | |
const declareTokenIndex = state.tokens.length - 1; | |
const matched = tsTryParseDeclare(); | |
if (matched) { | |
state.tokens[declareTokenIndex].type = TokenType._declare; | |
return true; | |
} | |
break; | |
} | |
case ContextualKeyword._global: | |
if (match(TokenType.braceL)) { | |
tsParseModuleBlock(); | |
return true; | |
} | |
break; | |
default: | |
return tsParseDeclaration(contextualKeyword, false); | |
} | |
return false; | |
} | |
function tsParseDeclaration(contextualKeyword, isBeforeToken) { | |
switch (contextualKeyword) { | |
case ContextualKeyword._abstract: | |
if (tsCheckLineTerminatorAndMatch(TokenType._class, isBeforeToken)) { | |
if (isBeforeToken) next(); | |
state.tokens[state.tokens.length - 1].type = TokenType._abstract; | |
parseClass(true, false); | |
return true; | |
} | |
break; | |
case ContextualKeyword._enum: | |
if (tsCheckLineTerminatorAndMatch(TokenType.name, isBeforeToken)) { | |
if (isBeforeToken) next(); | |
state.tokens[state.tokens.length - 1].type = TokenType._enum; | |
tsParseEnumDeclaration(); | |
return true; | |
} | |
break; | |
case ContextualKeyword._interface: | |
if (tsCheckLineTerminatorAndMatch(TokenType.name, isBeforeToken)) { | |
const oldIsType = pushTypeContext(1); | |
if (isBeforeToken) next(); | |
tsParseInterfaceDeclaration(); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
break; | |
case ContextualKeyword._module: | |
if (isBeforeToken) next(); | |
if (match(TokenType.string)) { | |
const oldIsType = pushTypeContext(isBeforeToken ? 2 : 1); | |
tsParseAmbientExternalModuleDeclaration(); | |
popTypeContext(oldIsType); | |
return true; | |
} else if (tsCheckLineTerminatorAndMatch(TokenType.name, isBeforeToken)) { | |
const oldIsType = pushTypeContext(isBeforeToken ? 2 : 1); | |
if (isBeforeToken) next(); | |
tsParseModuleOrNamespaceDeclaration(); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
break; | |
case ContextualKeyword._namespace: | |
if (tsCheckLineTerminatorAndMatch(TokenType.name, isBeforeToken)) { | |
const oldIsType = pushTypeContext(1); | |
if (isBeforeToken) next(); | |
tsParseModuleOrNamespaceDeclaration(); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
break; | |
case ContextualKeyword._type: | |
if (tsCheckLineTerminatorAndMatch(TokenType.name, isBeforeToken)) { | |
const oldIsType = pushTypeContext(1); | |
if (isBeforeToken) next(); | |
tsParseTypeAliasDeclaration(); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
break; | |
} | |
return false; | |
} | |
function tsCheckLineTerminatorAndMatch(tokenType, isBeforeToken) { | |
return !isLineTerminator() && (isBeforeToken || match(tokenType)); | |
} | |
function tsTryParseGenericAsyncArrowFunction() { | |
const snapshot = state.snapshot(); | |
tsParseTypeParameters(); | |
parseFunctionParams(); | |
tsTryParseTypeOrTypePredicateAnnotation(); | |
expect(TokenType.arrow); | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
return false; | |
} | |
parseFunctionBody(true); | |
return true; | |
} | |
function tsParseTypeArguments() { | |
const oldIsType = pushTypeContext(0); | |
expect(TokenType.lessThan); | |
while (!eat(TokenType.greaterThan) && !state.error) { | |
tsParseType(); | |
eat(TokenType.comma); | |
} | |
popTypeContext(oldIsType); | |
} | |
function tsIsDeclarationStart() { | |
if (match(TokenType.name)) { | |
switch (state.contextualKeyword) { | |
case ContextualKeyword._abstract: | |
case ContextualKeyword._declare: | |
case ContextualKeyword._enum: | |
case ContextualKeyword._interface: | |
case ContextualKeyword._module: | |
case ContextualKeyword._namespace: | |
case ContextualKeyword._type: | |
return true; | |
} | |
} | |
return false; | |
} | |
function tsParseFunctionBodyAndFinish(functionStart, funcContextId) { | |
if (match(TokenType.colon)) { | |
tsParseTypeOrTypePredicateAnnotation(TokenType.colon); | |
} | |
if (!match(TokenType.braceL) && isLineTerminator()) { | |
let i = state.tokens.length - 1; | |
while ( | |
i >= 0 && | |
(state.tokens[i].start >= functionStart || | |
state.tokens[i].type === TokenType._default || | |
state.tokens[i].type === TokenType._export) | |
) { | |
state.tokens[i].isType = true; | |
i--; | |
} | |
return; | |
} | |
parseFunctionBody(false, funcContextId); | |
} | |
function tsParseSubscript(startTokenIndex, noCalls, stopState) { | |
if (!hasPrecedingLineBreak() && eat(TokenType.bang)) { | |
state.tokens[state.tokens.length - 1].type = TokenType.nonNullAssertion; | |
return; | |
} | |
if (match(TokenType.lessThan)) { | |
const snapshot = state.snapshot(); | |
if (!noCalls && atPossibleAsync()) { | |
const asyncArrowFn = tsTryParseGenericAsyncArrowFunction(); | |
if (asyncArrowFn) { | |
return; | |
} | |
} | |
tsParseTypeArguments(); | |
if (!noCalls && eat(TokenType.parenL)) { | |
state.tokens[ | |
state.tokens.length - 1 | |
].subscriptStartIndex = startTokenIndex; | |
parseCallExpressionArguments(); | |
} else if (match(TokenType.backQuote)) { | |
parseTemplate(); | |
} else { | |
unexpected(); | |
} | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} else { | |
return; | |
} | |
} else if ( | |
!noCalls && | |
match(TokenType.questionDot) && | |
lookaheadType() === TokenType.lessThan | |
) { | |
next(); | |
state.tokens[startTokenIndex].isOptionalChainStart = true; | |
state.tokens[state.tokens.length - 1].subscriptStartIndex = startTokenIndex; | |
tsParseTypeArguments(); | |
expect(TokenType.parenL); | |
parseCallExpressionArguments(); | |
} | |
baseParseSubscript(startTokenIndex, noCalls, stopState); | |
} | |
function tsStartParseNewArguments() { | |
if (match(TokenType.lessThan)) { | |
const snapshot = state.snapshot(); | |
state.type = TokenType.typeParameterStart; | |
tsParseTypeArguments(); | |
if (!match(TokenType.parenL)) { | |
unexpected(); | |
} | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} | |
} | |
} | |
function tsTryParseExport() { | |
if (match(TokenType._import)) { | |
expect(TokenType._import); | |
tsParseImportEqualsDeclaration(); | |
return true; | |
} else if (eat(TokenType.eq)) { | |
parseExpression(); | |
semicolon(); | |
return true; | |
} else if (eatContextual(ContextualKeyword._as)) { | |
expectContextual(ContextualKeyword._namespace); | |
parseIdentifier(); | |
semicolon(); | |
return true; | |
} else { | |
if ( | |
isContextual(ContextualKeyword._type) && | |
lookaheadType() === TokenType.braceL | |
) { | |
next(); | |
} | |
return false; | |
} | |
} | |
function tsTryParseExportDefaultExpression() { | |
if ( | |
isContextual(ContextualKeyword._abstract) && | |
lookaheadType() === TokenType._class | |
) { | |
state.type = TokenType._abstract; | |
next(); | |
parseClass(true, true); | |
return true; | |
} | |
if (isContextual(ContextualKeyword._interface)) { | |
const oldIsType = pushTypeContext(2); | |
tsParseDeclaration(ContextualKeyword._interface, true); | |
popTypeContext(oldIsType); | |
return true; | |
} | |
return false; | |
} | |
function tsTryParseStatementContent() { | |
if (state.type === TokenType._const) { | |
const ahead = lookaheadTypeAndKeyword(); | |
if ( | |
ahead.type === TokenType.name && | |
ahead.contextualKeyword === ContextualKeyword._enum | |
) { | |
expect(TokenType._const); | |
expectContextual(ContextualKeyword._enum); | |
state.tokens[state.tokens.length - 1].type = TokenType._enum; | |
tsParseEnumDeclaration(); | |
return true; | |
} | |
} | |
return false; | |
} | |
function tsParseAccessModifier() { | |
tsParseModifier([ | |
ContextualKeyword._public, | |
ContextualKeyword._protected, | |
ContextualKeyword._private, | |
]); | |
} | |
function tsTryParseClassMemberWithIsStatic(isStatic, classContextId) { | |
let isAbstract = false; | |
let isReadonly = false; | |
while (true) { | |
const mod = tsParseModifier([ | |
ContextualKeyword._abstract, | |
ContextualKeyword._readonly, | |
ContextualKeyword._declare, | |
]); | |
if (mod == null) { | |
break; | |
} | |
if (mod === ContextualKeyword._readonly) { | |
isReadonly = true; | |
} | |
if (mod === ContextualKeyword._abstract) { | |
isAbstract = true; | |
} | |
} | |
if (!isAbstract && !isStatic) { | |
const found = tsTryParseIndexSignature(); | |
if (found) { | |
return true; | |
} | |
} | |
if (isReadonly) { | |
parseClassPropertyName(classContextId); | |
parsePostMemberNameModifiers(); | |
parseClassProperty(); | |
return true; | |
} | |
return false; | |
} | |
function tsParseIdentifierStatement(contextualKeyword) { | |
const matched = tsParseExpressionStatement(contextualKeyword); | |
if (!matched) { | |
semicolon(); | |
} | |
} | |
function tsParseExportDeclaration() { | |
const isDeclare = eatContextual(ContextualKeyword._declare); | |
if (isDeclare) { | |
state.tokens[state.tokens.length - 1].type = TokenType._declare; | |
} | |
let matchedDeclaration = false; | |
if (match(TokenType.name)) { | |
if (isDeclare) { | |
const oldIsType = pushTypeContext(2); | |
matchedDeclaration = tsTryParseExportDeclaration(); | |
popTypeContext(oldIsType); | |
} else { | |
matchedDeclaration = tsTryParseExportDeclaration(); | |
} | |
} | |
if (!matchedDeclaration) { | |
if (isDeclare) { | |
const oldIsType = pushTypeContext(2); | |
parseStatement(true); | |
popTypeContext(oldIsType); | |
} else { | |
parseStatement(true); | |
} | |
} | |
} | |
function tsAfterParseClassSuper(hasSuper) { | |
if (hasSuper && match(TokenType.lessThan)) { | |
tsParseTypeArguments(); | |
} | |
if (eatContextual(ContextualKeyword._implements)) { | |
state.tokens[state.tokens.length - 1].type = TokenType._implements; | |
const oldIsType = pushTypeContext(1); | |
tsParseHeritageClause(); | |
popTypeContext(oldIsType); | |
} | |
} | |
function tsStartParseObjPropValue() { | |
tsTryParseTypeParameters(); | |
} | |
function tsStartParseFunctionParams() { | |
tsTryParseTypeParameters(); | |
} | |
function tsAfterParseVarHead() { | |
const oldIsType = pushTypeContext(0); | |
eat(TokenType.bang); | |
tsTryParseTypeAnnotation(); | |
popTypeContext(oldIsType); | |
} | |
function tsStartParseAsyncArrowFromCallExpression() { | |
if (match(TokenType.colon)) { | |
tsParseTypeAnnotation(); | |
} | |
} | |
function tsParseMaybeAssign(noIn, isWithinParens) { | |
if (isJSXEnabled) { | |
return tsParseMaybeAssignWithJSX(noIn, isWithinParens); | |
} else { | |
return tsParseMaybeAssignWithoutJSX(noIn, isWithinParens); | |
} | |
} | |
function tsParseMaybeAssignWithJSX(noIn, isWithinParens) { | |
if (!match(TokenType.lessThan)) { | |
return baseParseMaybeAssign(noIn, isWithinParens); | |
} | |
const snapshot = state.snapshot(); | |
let wasArrow = baseParseMaybeAssign(noIn, isWithinParens); | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} else { | |
return wasArrow; | |
} | |
state.type = TokenType.typeParameterStart; | |
tsParseTypeParameters(); | |
wasArrow = baseParseMaybeAssign(noIn, isWithinParens); | |
if (!wasArrow) { | |
unexpected(); | |
} | |
return wasArrow; | |
} | |
function tsParseMaybeAssignWithoutJSX(noIn, isWithinParens) { | |
if (!match(TokenType.lessThan)) { | |
return baseParseMaybeAssign(noIn, isWithinParens); | |
} | |
const snapshot = state.snapshot(); | |
tsParseTypeParameters(); | |
const wasArrow = baseParseMaybeAssign(noIn, isWithinParens); | |
if (!wasArrow) { | |
unexpected(); | |
} | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} else { | |
return wasArrow; | |
} | |
return baseParseMaybeAssign(noIn, isWithinParens); | |
} | |
function tsParseArrow() { | |
if (match(TokenType.colon)) { | |
const snapshot = state.snapshot(); | |
tsParseTypeOrTypePredicateAnnotation(TokenType.colon); | |
if (canInsertSemicolon()) unexpected(); | |
if (!match(TokenType.arrow)) unexpected(); | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} | |
} | |
return eat(TokenType.arrow); | |
} | |
function tsParseAssignableListItemTypes() { | |
const oldIsType = pushTypeContext(0); | |
eat(TokenType.question); | |
tsTryParseTypeAnnotation(); | |
popTypeContext(oldIsType); | |
} | |
function tsParseMaybeDecoratorArguments() { | |
if (match(TokenType.lessThan)) { | |
tsParseTypeArguments(); | |
} | |
baseParseMaybeDecoratorArguments(); | |
} | |
function jsxReadToken() { | |
for (;;) { | |
if (state.pos >= input.length) { | |
unexpected("Unterminated JSX contents"); | |
return; | |
} | |
const ch = input.charCodeAt(state.pos); | |
switch (ch) { | |
case charCodes.lessThan: | |
case charCodes.leftCurlyBrace: | |
if (state.pos === state.start) { | |
if (ch === charCodes.lessThan) { | |
state.pos++; | |
finishToken(TokenType.jsxTagStart); | |
return; | |
} | |
getTokenFromCode(ch); | |
return; | |
} | |
finishToken(TokenType.jsxText); | |
return; | |
default: | |
state.pos++; | |
} | |
} | |
} | |
function jsxReadString(quote) { | |
state.pos++; | |
for (;;) { | |
if (state.pos >= input.length) { | |
unexpected("Unterminated string constant"); | |
return; | |
} | |
const ch = input.charCodeAt(state.pos); | |
if (ch === quote) { | |
state.pos++; | |
break; | |
} | |
state.pos++; | |
} | |
finishToken(TokenType.string); | |
} | |
function jsxReadWord() { | |
let ch; | |
do { | |
if (state.pos > input.length) { | |
unexpected("Unexpectedly reached the end of input."); | |
return; | |
} | |
ch = input.charCodeAt(++state.pos); | |
} while (IS_IDENTIFIER_CHAR[ch] || ch === charCodes.dash); | |
finishToken(TokenType.jsxName); | |
} | |
function jsxParseIdentifier() { | |
nextJSXTagToken(); | |
} | |
function jsxParseNamespacedName(identifierRole) { | |
jsxParseIdentifier(); | |
if (!eat(TokenType.colon)) { | |
state.tokens[state.tokens.length - 1].identifierRole = identifierRole; | |
return; | |
} | |
jsxParseIdentifier(); | |
} | |
function jsxParseElementName() { | |
jsxParseNamespacedName(IdentifierRole.Access); | |
while (match(TokenType.dot)) { | |
nextJSXTagToken(); | |
jsxParseIdentifier(); | |
} | |
} | |
function jsxParseAttributeValue() { | |
switch (state.type) { | |
case TokenType.braceL: | |
next(); | |
jsxParseExpressionContainer(); | |
nextJSXTagToken(); | |
return; | |
case TokenType.jsxTagStart: | |
jsxParseElement(); | |
nextJSXTagToken(); | |
return; | |
case TokenType.string: | |
nextJSXTagToken(); | |
return; | |
default: | |
unexpected( | |
"JSX value should be either an expression or a quoted JSX text" | |
); | |
} | |
} | |
function jsxParseSpreadChild() { | |
expect(TokenType.ellipsis); | |
parseExpression(); | |
} | |
function jsxParseExpressionContainer() { | |
if (match(TokenType.braceR)); | |
else { | |
parseExpression(); | |
} | |
} | |
function jsxParseAttribute() { | |
if (eat(TokenType.braceL)) { | |
expect(TokenType.ellipsis); | |
parseMaybeAssign(); | |
nextJSXTagToken(); | |
return; | |
} | |
jsxParseNamespacedName(IdentifierRole.ObjectKey); | |
if (match(TokenType.eq)) { | |
nextJSXTagToken(); | |
jsxParseAttributeValue(); | |
} | |
} | |
function jsxParseOpeningElement() { | |
if (match(TokenType.jsxTagEnd)) { | |
return false; | |
} | |
jsxParseElementName(); | |
if (isTypeScriptEnabled) { | |
tsTryParseJSXTypeArgument(); | |
} | |
while ( | |
!match(TokenType.slash) && | |
!match(TokenType.jsxTagEnd) && | |
!state.error | |
) { | |
jsxParseAttribute(); | |
} | |
const isSelfClosing = match(TokenType.slash); | |
if (isSelfClosing) { | |
nextJSXTagToken(); | |
} | |
return isSelfClosing; | |
} | |
function jsxParseClosingElement() { | |
if (match(TokenType.jsxTagEnd)) { | |
return; | |
} | |
jsxParseElementName(); | |
} | |
function jsxParseElementAt() { | |
const isSelfClosing = jsxParseOpeningElement(); | |
if (!isSelfClosing) { | |
nextJSXExprToken(); | |
while (true) { | |
switch (state.type) { | |
case TokenType.jsxTagStart: | |
nextJSXTagToken(); | |
if (match(TokenType.slash)) { | |
nextJSXTagToken(); | |
jsxParseClosingElement(); | |
return; | |
} | |
jsxParseElementAt(); | |
nextJSXExprToken(); | |
break; | |
case TokenType.jsxText: | |
nextJSXExprToken(); | |
break; | |
case TokenType.braceL: | |
next(); | |
if (match(TokenType.ellipsis)) { | |
jsxParseSpreadChild(); | |
nextJSXExprToken(); | |
} else { | |
jsxParseExpressionContainer(); | |
nextJSXExprToken(); | |
} | |
break; | |
default: | |
unexpected(); | |
return; | |
} | |
} | |
} | |
} | |
function jsxParseElement() { | |
nextJSXTagToken(); | |
jsxParseElementAt(); | |
} | |
function nextJSXTagToken() { | |
state.tokens.push(new Token()); | |
skipSpace(); | |
state.start = state.pos; | |
const code = input.charCodeAt(state.pos); | |
if (IS_IDENTIFIER_START[code]) { | |
jsxReadWord(); | |
} else if ( | |
code === charCodes.quotationMark || | |
code === charCodes.apostrophe | |
) { | |
jsxReadString(code); | |
} else { | |
++state.pos; | |
switch (code) { | |
case charCodes.greaterThan: | |
finishToken(TokenType.jsxTagEnd); | |
break; | |
case charCodes.lessThan: | |
finishToken(TokenType.jsxTagStart); | |
break; | |
case charCodes.slash: | |
finishToken(TokenType.slash); | |
break; | |
case charCodes.equalsTo: | |
finishToken(TokenType.eq); | |
break; | |
case charCodes.leftCurlyBrace: | |
finishToken(TokenType.braceL); | |
break; | |
case charCodes.dot: | |
finishToken(TokenType.dot); | |
break; | |
case charCodes.colon: | |
finishToken(TokenType.colon); | |
break; | |
default: | |
unexpected(); | |
} | |
} | |
} | |
function nextJSXExprToken() { | |
state.tokens.push(new Token()); | |
state.start = state.pos; | |
jsxReadToken(); | |
} | |
function typedParseConditional(noIn) { | |
if (match(TokenType.question)) { | |
const nextType = lookaheadType(); | |
if ( | |
nextType === TokenType.colon || | |
nextType === TokenType.comma || | |
nextType === TokenType.parenR | |
) { | |
return; | |
} | |
} | |
baseParseConditional(noIn); | |
} | |
function typedParseParenItem() { | |
if (eat(TokenType.question)) { | |
state.tokens[state.tokens.length - 1].isType = true; | |
} | |
if (match(TokenType.colon)) { | |
if (isTypeScriptEnabled) { | |
tsParseTypeAnnotation(); | |
} else if (isFlowEnabled) { | |
flowParseTypeAnnotation(); | |
} | |
} | |
} | |
class StopState { | |
constructor(stop) { | |
this.stop = stop; | |
} | |
} | |
function parseExpression(noIn = false) { | |
parseMaybeAssign(noIn); | |
if (match(TokenType.comma)) { | |
while (eat(TokenType.comma)) { | |
parseMaybeAssign(noIn); | |
} | |
} | |
} | |
function parseMaybeAssign(noIn = false, isWithinParens = false) { | |
if (isTypeScriptEnabled) { | |
return tsParseMaybeAssign(noIn, isWithinParens); | |
} else if (isFlowEnabled) { | |
return flowParseMaybeAssign(noIn, isWithinParens); | |
} else { | |
return baseParseMaybeAssign(noIn, isWithinParens); | |
} | |
} | |
function baseParseMaybeAssign(noIn, isWithinParens) { | |
if (match(TokenType._yield)) { | |
parseYield(); | |
return false; | |
} | |
if ( | |
match(TokenType.parenL) || | |
match(TokenType.name) || | |
match(TokenType._yield) | |
) { | |
state.potentialArrowAt = state.start; | |
} | |
const wasArrow = parseMaybeConditional(noIn); | |
if (isWithinParens) { | |
parseParenItem(); | |
} | |
if (state.type & TokenType.IS_ASSIGN) { | |
next(); | |
parseMaybeAssign(noIn); | |
return false; | |
} | |
return wasArrow; | |
} | |
function parseMaybeConditional(noIn) { | |
const wasArrow = parseExprOps(noIn); | |
if (wasArrow) { | |
return true; | |
} | |
parseConditional(noIn); | |
return false; | |
} | |
function parseConditional(noIn) { | |
if (isTypeScriptEnabled || isFlowEnabled) { | |
typedParseConditional(noIn); | |
} else { | |
baseParseConditional(noIn); | |
} | |
} | |
function baseParseConditional(noIn) { | |
if (eat(TokenType.question)) { | |
parseMaybeAssign(); | |
expect(TokenType.colon); | |
parseMaybeAssign(noIn); | |
} | |
} | |
function parseExprOps(noIn) { | |
const startTokenIndex = state.tokens.length; | |
const wasArrow = parseMaybeUnary(); | |
if (wasArrow) { | |
return true; | |
} | |
parseExprOp(startTokenIndex, -1, noIn); | |
return false; | |
} | |
function parseExprOp(startTokenIndex, minPrec, noIn) { | |
if ( | |
isTypeScriptEnabled && | |
(TokenType._in & TokenType.PRECEDENCE_MASK) > minPrec && | |
!hasPrecedingLineBreak() && | |
eatContextual(ContextualKeyword._as) | |
) { | |
state.tokens[state.tokens.length - 1].type = TokenType._as; | |
const oldIsType = pushTypeContext(1); | |
tsParseType(); | |
popTypeContext(oldIsType); | |
parseExprOp(startTokenIndex, minPrec, noIn); | |
return; | |
} | |
const prec = state.type & TokenType.PRECEDENCE_MASK; | |
if (prec > 0 && (!noIn || !match(TokenType._in))) { | |
if (prec > minPrec) { | |
const op = state.type; | |
next(); | |
if (op === TokenType.nullishCoalescing) { | |
state.tokens[ | |
state.tokens.length - 1 | |
].nullishStartIndex = startTokenIndex; | |
} | |
const rhsStartTokenIndex = state.tokens.length; | |
parseMaybeUnary(); | |
parseExprOp( | |
rhsStartTokenIndex, | |
op & TokenType.IS_RIGHT_ASSOCIATIVE ? prec - 1 : prec, | |
noIn | |
); | |
if (op === TokenType.nullishCoalescing) { | |
state.tokens[startTokenIndex].numNullishCoalesceStarts++; | |
state.tokens[state.tokens.length - 1].numNullishCoalesceEnds++; | |
} | |
parseExprOp(startTokenIndex, minPrec, noIn); | |
} | |
} | |
} | |
function parseMaybeUnary() { | |
if (isTypeScriptEnabled && !isJSXEnabled && eat(TokenType.lessThan)) { | |
tsParseTypeAssertion(); | |
return false; | |
} | |
if (state.type & TokenType.IS_PREFIX) { | |
next(); | |
parseMaybeUnary(); | |
return false; | |
} | |
const wasArrow = parseExprSubscripts(); | |
if (wasArrow) { | |
return true; | |
} | |
while (state.type & TokenType.IS_POSTFIX && !canInsertSemicolon()) { | |
if (state.type === TokenType.preIncDec) { | |
state.type = TokenType.postIncDec; | |
} | |
next(); | |
} | |
return false; | |
} | |
function parseExprSubscripts() { | |
const startTokenIndex = state.tokens.length; | |
const wasArrow = parseExprAtom(); | |
if (wasArrow) { | |
return true; | |
} | |
parseSubscripts(startTokenIndex); | |
if ( | |
state.tokens.length > startTokenIndex && | |
state.tokens[startTokenIndex].isOptionalChainStart | |
) { | |
state.tokens[state.tokens.length - 1].isOptionalChainEnd = true; | |
} | |
return false; | |
} | |
function parseSubscripts(startTokenIndex, noCalls = false) { | |
if (isFlowEnabled) { | |
flowParseSubscripts(startTokenIndex, noCalls); | |
} else { | |
baseParseSubscripts(startTokenIndex, noCalls); | |
} | |
} | |
function baseParseSubscripts(startTokenIndex, noCalls = false) { | |
const stopState = new StopState(false); | |
do { | |
parseSubscript(startTokenIndex, noCalls, stopState); | |
} while (!stopState.stop && !state.error); | |
} | |
function parseSubscript(startTokenIndex, noCalls, stopState) { | |
if (isTypeScriptEnabled) { | |
tsParseSubscript(startTokenIndex, noCalls, stopState); | |
} else if (isFlowEnabled) { | |
flowParseSubscript(startTokenIndex, noCalls, stopState); | |
} else { | |
baseParseSubscript(startTokenIndex, noCalls, stopState); | |
} | |
} | |
function baseParseSubscript(startTokenIndex, noCalls, stopState) { | |
if (!noCalls && eat(TokenType.doubleColon)) { | |
parseNoCallExpr(); | |
stopState.stop = true; | |
parseSubscripts(startTokenIndex, noCalls); | |
} else if (match(TokenType.questionDot)) { | |
state.tokens[startTokenIndex].isOptionalChainStart = true; | |
if (noCalls && lookaheadType() === TokenType.parenL) { | |
stopState.stop = true; | |
return; | |
} | |
next(); | |
state.tokens[state.tokens.length - 1].subscriptStartIndex = startTokenIndex; | |
if (eat(TokenType.bracketL)) { | |
parseExpression(); | |
expect(TokenType.bracketR); | |
} else if (eat(TokenType.parenL)) { | |
parseCallExpressionArguments(); | |
} else { | |
parseMaybePrivateName(); | |
} | |
} else if (eat(TokenType.dot)) { | |
state.tokens[state.tokens.length - 1].subscriptStartIndex = startTokenIndex; | |
parseMaybePrivateName(); | |
} else if (eat(TokenType.bracketL)) { | |
state.tokens[state.tokens.length - 1].subscriptStartIndex = startTokenIndex; | |
parseExpression(); | |
expect(TokenType.bracketR); | |
} else if (!noCalls && match(TokenType.parenL)) { | |
if (atPossibleAsync()) { | |
const snapshot = state.snapshot(); | |
const asyncStartTokenIndex = state.tokens.length; | |
next(); | |
state.tokens[ | |
state.tokens.length - 1 | |
].subscriptStartIndex = startTokenIndex; | |
const callContextId = getNextContextId(); | |
state.tokens[state.tokens.length - 1].contextId = callContextId; | |
parseCallExpressionArguments(); | |
state.tokens[state.tokens.length - 1].contextId = callContextId; | |
if (shouldParseAsyncArrow()) { | |
state.restoreFromSnapshot(snapshot); | |
stopState.stop = true; | |
state.scopeDepth++; | |
parseFunctionParams(); | |
parseAsyncArrowFromCallExpression(asyncStartTokenIndex); | |
} | |
} else { | |
next(); | |
state.tokens[ | |
state.tokens.length - 1 | |
].subscriptStartIndex = startTokenIndex; | |
const callContextId = getNextContextId(); | |
state.tokens[state.tokens.length - 1].contextId = callContextId; | |
parseCallExpressionArguments(); | |
state.tokens[state.tokens.length - 1].contextId = callContextId; | |
} | |
} else if (match(TokenType.backQuote)) { | |
parseTemplate(); | |
} else { | |
stopState.stop = true; | |
} | |
} | |
function atPossibleAsync() { | |
return ( | |
state.tokens[state.tokens.length - 1].contextualKeyword === | |
ContextualKeyword._async && !canInsertSemicolon() | |
); | |
} | |
function parseCallExpressionArguments() { | |
let first = true; | |
while (!eat(TokenType.parenR) && !state.error) { | |
if (first) { | |
first = false; | |
} else { | |
expect(TokenType.comma); | |
if (eat(TokenType.parenR)) { | |
break; | |
} | |
} | |
parseExprListItem(false); | |
} | |
} | |
function shouldParseAsyncArrow() { | |
return match(TokenType.colon) || match(TokenType.arrow); | |
} | |
function parseAsyncArrowFromCallExpression(startTokenIndex) { | |
if (isTypeScriptEnabled) { | |
tsStartParseAsyncArrowFromCallExpression(); | |
} else if (isFlowEnabled) { | |
flowStartParseAsyncArrowFromCallExpression(); | |
} | |
expect(TokenType.arrow); | |
parseArrowExpression(startTokenIndex); | |
} | |
function parseNoCallExpr() { | |
const startTokenIndex = state.tokens.length; | |
parseExprAtom(); | |
parseSubscripts(startTokenIndex, true); | |
} | |
function parseExprAtom() { | |
if (eat(TokenType.modulo)) { | |
parseIdentifier(); | |
return false; | |
} | |
if (match(TokenType.jsxText)) { | |
parseLiteral(); | |
return false; | |
} else if (match(TokenType.lessThan) && isJSXEnabled) { | |
state.type = TokenType.jsxTagStart; | |
jsxParseElement(); | |
next(); | |
return false; | |
} | |
const canBeArrow = state.potentialArrowAt === state.start; | |
switch (state.type) { | |
case TokenType.slash: | |
case TokenType.assign: | |
retokenizeSlashAsRegex(); | |
case TokenType._super: | |
case TokenType._this: | |
case TokenType.regexp: | |
case TokenType.num: | |
case TokenType.bigint: | |
case TokenType.decimal: | |
case TokenType.string: | |
case TokenType._null: | |
case TokenType._true: | |
case TokenType._false: | |
next(); | |
return false; | |
case TokenType._import: | |
next(); | |
if (match(TokenType.dot)) { | |
state.tokens[state.tokens.length - 1].type = TokenType.name; | |
next(); | |
parseIdentifier(); | |
} | |
return false; | |
case TokenType.name: { | |
const startTokenIndex = state.tokens.length; | |
const functionStart = state.start; | |
const contextualKeyword = state.contextualKeyword; | |
parseIdentifier(); | |
if (contextualKeyword === ContextualKeyword._await) { | |
parseAwait(); | |
return false; | |
} else if ( | |
contextualKeyword === ContextualKeyword._async && | |
match(TokenType._function) && | |
!canInsertSemicolon() | |
) { | |
next(); | |
parseFunction(functionStart, false); | |
return false; | |
} else if ( | |
canBeArrow && | |
!canInsertSemicolon() && | |
contextualKeyword === ContextualKeyword._async && | |
match(TokenType.name) | |
) { | |
state.scopeDepth++; | |
parseBindingIdentifier(false); | |
expect(TokenType.arrow); | |
parseArrowExpression(startTokenIndex); | |
return true; | |
} | |
if (canBeArrow && !canInsertSemicolon() && match(TokenType.arrow)) { | |
state.scopeDepth++; | |
markPriorBindingIdentifier(false); | |
expect(TokenType.arrow); | |
parseArrowExpression(startTokenIndex); | |
return true; | |
} | |
state.tokens[state.tokens.length - 1].identifierRole = | |
IdentifierRole.Access; | |
return false; | |
} | |
case TokenType._do: { | |
next(); | |
parseBlock(false); | |
return false; | |
} | |
case TokenType.parenL: { | |
const wasArrow = parseParenAndDistinguishExpression(canBeArrow); | |
return wasArrow; | |
} | |
case TokenType.bracketL: | |
next(); | |
parseExprList(TokenType.bracketR, true); | |
return false; | |
case TokenType.braceL: | |
parseObj(false, false); | |
return false; | |
case TokenType._function: | |
parseFunctionExpression(); | |
return false; | |
case TokenType.at: | |
parseDecorators(); | |
case TokenType._class: | |
parseClass(false); | |
return false; | |
case TokenType._new: | |
parseNew(); | |
return false; | |
case TokenType.backQuote: | |
parseTemplate(); | |
return false; | |
case TokenType.doubleColon: { | |
next(); | |
parseNoCallExpr(); | |
return false; | |
} | |
case TokenType.hash: { | |
const code = lookaheadCharCode(); | |
if (IS_IDENTIFIER_START[code] || code === charCodes.backslash) { | |
parseMaybePrivateName(); | |
} else { | |
next(); | |
} | |
return false; | |
} | |
default: | |
unexpected(); | |
return false; | |
} | |
} | |
function parseMaybePrivateName() { | |
eat(TokenType.hash); | |
parseIdentifier(); | |
} | |
function parseFunctionExpression() { | |
const functionStart = state.start; | |
parseIdentifier(); | |
if (eat(TokenType.dot)) { | |
parseIdentifier(); | |
} | |
parseFunction(functionStart, false); | |
} | |
function parseLiteral() { | |
next(); | |
} | |
function parseParenExpression() { | |
expect(TokenType.parenL); | |
parseExpression(); | |
expect(TokenType.parenR); | |
} | |
function parseParenAndDistinguishExpression(canBeArrow) { | |
const snapshot = state.snapshot(); | |
const startTokenIndex = state.tokens.length; | |
expect(TokenType.parenL); | |
let first = true; | |
while (!match(TokenType.parenR) && !state.error) { | |
if (first) { | |
first = false; | |
} else { | |
expect(TokenType.comma); | |
if (match(TokenType.parenR)) { | |
break; | |
} | |
} | |
if (match(TokenType.ellipsis)) { | |
parseRest(false); | |
parseParenItem(); | |
break; | |
} else { | |
parseMaybeAssign(false, true); | |
} | |
} | |
expect(TokenType.parenR); | |
if (canBeArrow && shouldParseArrow()) { | |
const wasArrow = parseArrow(); | |
if (wasArrow) { | |
state.restoreFromSnapshot(snapshot); | |
state.scopeDepth++; | |
parseFunctionParams(); | |
parseArrow(); | |
parseArrowExpression(startTokenIndex); | |
return true; | |
} | |
} | |
return false; | |
} | |
function shouldParseArrow() { | |
return match(TokenType.colon) || !canInsertSemicolon(); | |
} | |
function parseArrow() { | |
if (isTypeScriptEnabled) { | |
return tsParseArrow(); | |
} else if (isFlowEnabled) { | |
return flowParseArrow(); | |
} else { | |
return eat(TokenType.arrow); | |
} | |
} | |
function parseParenItem() { | |
if (isTypeScriptEnabled || isFlowEnabled) { | |
typedParseParenItem(); | |
} | |
} | |
function parseNew() { | |
expect(TokenType._new); | |
if (eat(TokenType.dot)) { | |
parseIdentifier(); | |
return; | |
} | |
parseNoCallExpr(); | |
eat(TokenType.questionDot); | |
parseNewArguments(); | |
} | |
function parseNewArguments() { | |
if (isTypeScriptEnabled) { | |
tsStartParseNewArguments(); | |
} else if (isFlowEnabled) { | |
flowStartParseNewArguments(); | |
} | |
if (eat(TokenType.parenL)) { | |
parseExprList(TokenType.parenR); | |
} | |
} | |
function parseTemplate() { | |
nextTemplateToken(); | |
nextTemplateToken(); | |
while (!match(TokenType.backQuote) && !state.error) { | |
expect(TokenType.dollarBraceL); | |
parseExpression(); | |
nextTemplateToken(); | |
nextTemplateToken(); | |
} | |
next(); | |
} | |
function parseObj(isPattern, isBlockScope) { | |
const contextId = getNextContextId(); | |
let first = true; | |
next(); | |
state.tokens[state.tokens.length - 1].contextId = contextId; | |
while (!eat(TokenType.braceR) && !state.error) { | |
if (first) { | |
first = false; | |
} else { | |
expect(TokenType.comma); | |
if (eat(TokenType.braceR)) { | |
break; | |
} | |
} | |
let isGenerator = false; | |
if (match(TokenType.ellipsis)) { | |
const previousIndex = state.tokens.length; | |
parseSpread(); | |
if (isPattern) { | |
if (state.tokens.length === previousIndex + 2) { | |
markPriorBindingIdentifier(isBlockScope); | |
} | |
if (eat(TokenType.braceR)) { | |
break; | |
} | |
} | |
continue; | |
} | |
if (!isPattern) { | |
isGenerator = eat(TokenType.star); | |
} | |
if (!isPattern && isContextual(ContextualKeyword._async)) { | |
if (isGenerator) unexpected(); | |
parseIdentifier(); | |
if ( | |
match(TokenType.colon) || | |
match(TokenType.parenL) || | |
match(TokenType.braceR) || | |
match(TokenType.eq) || | |
match(TokenType.comma) | |
); | |
else { | |
if (match(TokenType.star)) { | |
next(); | |
isGenerator = true; | |
} | |
parsePropertyName(contextId); | |
} | |
} else { | |
parsePropertyName(contextId); | |
} | |
parseObjPropValue(isPattern, isBlockScope, contextId); | |
} | |
state.tokens[state.tokens.length - 1].contextId = contextId; | |
} | |
function isGetterOrSetterMethod(isPattern) { | |
return ( | |
!isPattern && | |
(match(TokenType.string) || | |
match(TokenType.num) || | |
match(TokenType.bracketL) || | |
match(TokenType.name) || | |
!!(state.type & TokenType.IS_KEYWORD)) | |
); | |
} | |
function parseObjectMethod(isPattern, objectContextId) { | |
const functionStart = state.start; | |
if (match(TokenType.parenL)) { | |
if (isPattern) unexpected(); | |
parseMethod(functionStart, false); | |
return true; | |
} | |
if (isGetterOrSetterMethod(isPattern)) { | |
parsePropertyName(objectContextId); | |
parseMethod(functionStart, false); | |
return true; | |
} | |
return false; | |
} | |
function parseObjectProperty(isPattern, isBlockScope) { | |
if (eat(TokenType.colon)) { | |
if (isPattern) { | |
parseMaybeDefault(isBlockScope); | |
} else { | |
parseMaybeAssign(false); | |
} | |
return; | |
} | |
if (isPattern) { | |
state.tokens[state.tokens.length - 1].identifierRole = isBlockScope | |
? IdentifierRole.ObjectShorthandBlockScopedDeclaration | |
: IdentifierRole.ObjectShorthandFunctionScopedDeclaration; | |
} else { | |
state.tokens[state.tokens.length - 1].identifierRole = | |
IdentifierRole.ObjectShorthand; | |
} | |
parseMaybeDefault(isBlockScope, true); | |
} | |
function parseObjPropValue(isPattern, isBlockScope, objectContextId) { | |
if (isTypeScriptEnabled) { | |
tsStartParseObjPropValue(); | |
} else if (isFlowEnabled) { | |
flowStartParseObjPropValue(); | |
} | |
const wasMethod = parseObjectMethod(isPattern, objectContextId); | |
if (!wasMethod) { | |
parseObjectProperty(isPattern, isBlockScope); | |
} | |
} | |
function parsePropertyName(objectContextId) { | |
if (isFlowEnabled) { | |
flowParseVariance(); | |
} | |
if (eat(TokenType.bracketL)) { | |
state.tokens[state.tokens.length - 1].contextId = objectContextId; | |
parseMaybeAssign(); | |
expect(TokenType.bracketR); | |
state.tokens[state.tokens.length - 1].contextId = objectContextId; | |
} else { | |
if ( | |
match(TokenType.num) || | |
match(TokenType.string) || | |
match(TokenType.bigint) || | |
match(TokenType.decimal) | |
) { | |
parseExprAtom(); | |
} else { | |
parseMaybePrivateName(); | |
} | |
state.tokens[state.tokens.length - 1].identifierRole = | |
IdentifierRole.ObjectKey; | |
state.tokens[state.tokens.length - 1].contextId = objectContextId; | |
} | |
} | |
function parseMethod(functionStart, isConstructor) { | |
const funcContextId = getNextContextId(); | |
state.scopeDepth++; | |
const startTokenIndex = state.tokens.length; | |
const allowModifiers = isConstructor; | |
parseFunctionParams(allowModifiers, funcContextId); | |
parseFunctionBodyAndFinish(functionStart, funcContextId); | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push(new Scope(startTokenIndex, endTokenIndex, true)); | |
state.scopeDepth--; | |
} | |
function parseArrowExpression(startTokenIndex) { | |
parseFunctionBody(true); | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push(new Scope(startTokenIndex, endTokenIndex, true)); | |
state.scopeDepth--; | |
} | |
function parseFunctionBodyAndFinish(functionStart, funcContextId = 0) { | |
if (isTypeScriptEnabled) { | |
tsParseFunctionBodyAndFinish(functionStart, funcContextId); | |
} else if (isFlowEnabled) { | |
flowParseFunctionBodyAndFinish(funcContextId); | |
} else { | |
parseFunctionBody(false, funcContextId); | |
} | |
} | |
function parseFunctionBody(allowExpression, funcContextId = 0) { | |
const isExpression = allowExpression && !match(TokenType.braceL); | |
if (isExpression) { | |
parseMaybeAssign(); | |
} else { | |
parseBlock(true, true, funcContextId); | |
} | |
} | |
function parseExprList(close, allowEmpty = false) { | |
let first = true; | |
while (!eat(close) && !state.error) { | |
if (first) { | |
first = false; | |
} else { | |
expect(TokenType.comma); | |
if (eat(close)) break; | |
} | |
parseExprListItem(allowEmpty); | |
} | |
} | |
function parseExprListItem(allowEmpty) { | |
if (allowEmpty && match(TokenType.comma)); | |
else if (match(TokenType.ellipsis)) { | |
parseSpread(); | |
parseParenItem(); | |
} else if (match(TokenType.question)) { | |
next(); | |
} else { | |
parseMaybeAssign(false, true); | |
} | |
} | |
function parseIdentifier() { | |
next(); | |
state.tokens[state.tokens.length - 1].type = TokenType.name; | |
} | |
function parseAwait() { | |
parseMaybeUnary(); | |
} | |
function parseYield() { | |
next(); | |
if (!match(TokenType.semi) && !canInsertSemicolon()) { | |
eat(TokenType.star); | |
parseMaybeAssign(); | |
} | |
} | |
function isMaybeDefaultImport(lookahead) { | |
return ( | |
(lookahead.type === TokenType.name || | |
!!(lookahead.type & TokenType.IS_KEYWORD)) && | |
lookahead.contextualKeyword !== ContextualKeyword._from | |
); | |
} | |
function flowParseTypeInitialiser(tok) { | |
const oldIsType = pushTypeContext(0); | |
expect(tok || TokenType.colon); | |
flowParseType(); | |
popTypeContext(oldIsType); | |
} | |
function flowParsePredicate() { | |
expect(TokenType.modulo); | |
expectContextual(ContextualKeyword._checks); | |
if (eat(TokenType.parenL)) { | |
parseExpression(); | |
expect(TokenType.parenR); | |
} | |
} | |
function flowParseTypeAndPredicateInitialiser() { | |
const oldIsType = pushTypeContext(0); | |
expect(TokenType.colon); | |
if (match(TokenType.modulo)) { | |
flowParsePredicate(); | |
} else { | |
flowParseType(); | |
if (match(TokenType.modulo)) { | |
flowParsePredicate(); | |
} | |
} | |
popTypeContext(oldIsType); | |
} | |
function flowParseDeclareClass() { | |
next(); | |
flowParseInterfaceish(true); | |
} | |
function flowParseDeclareFunction() { | |
next(); | |
parseIdentifier(); | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
} | |
expect(TokenType.parenL); | |
flowParseFunctionTypeParams(); | |
expect(TokenType.parenR); | |
flowParseTypeAndPredicateInitialiser(); | |
semicolon(); | |
} | |
function flowParseDeclare() { | |
if (match(TokenType._class)) { | |
flowParseDeclareClass(); | |
} else if (match(TokenType._function)) { | |
flowParseDeclareFunction(); | |
} else if (match(TokenType._var)) { | |
flowParseDeclareVariable(); | |
} else if (eatContextual(ContextualKeyword._module)) { | |
if (eat(TokenType.dot)) { | |
flowParseDeclareModuleExports(); | |
} else { | |
flowParseDeclareModule(); | |
} | |
} else if (isContextual(ContextualKeyword._type)) { | |
flowParseDeclareTypeAlias(); | |
} else if (isContextual(ContextualKeyword._opaque)) { | |
flowParseDeclareOpaqueType(); | |
} else if (isContextual(ContextualKeyword._interface)) { | |
flowParseDeclareInterface(); | |
} else if (match(TokenType._export)) { | |
flowParseDeclareExportDeclaration(); | |
} else { | |
unexpected(); | |
} | |
} | |
function flowParseDeclareVariable() { | |
next(); | |
flowParseTypeAnnotatableIdentifier(); | |
semicolon(); | |
} | |
function flowParseDeclareModule() { | |
if (match(TokenType.string)) { | |
parseExprAtom(); | |
} else { | |
parseIdentifier(); | |
} | |
expect(TokenType.braceL); | |
while (!match(TokenType.braceR) && !state.error) { | |
if (match(TokenType._import)) { | |
next(); | |
parseImport(); | |
} else { | |
unexpected(); | |
} | |
} | |
expect(TokenType.braceR); | |
} | |
function flowParseDeclareExportDeclaration() { | |
expect(TokenType._export); | |
if (eat(TokenType._default)) { | |
if (match(TokenType._function) || match(TokenType._class)) { | |
flowParseDeclare(); | |
} else { | |
flowParseType(); | |
semicolon(); | |
} | |
} else if ( | |
match(TokenType._var) || | |
match(TokenType._function) || | |
match(TokenType._class) || | |
isContextual(ContextualKeyword._opaque) | |
) { | |
flowParseDeclare(); | |
} else if ( | |
match(TokenType.star) || | |
match(TokenType.braceL) || | |
isContextual(ContextualKeyword._interface) || | |
isContextual(ContextualKeyword._type) || | |
isContextual(ContextualKeyword._opaque) | |
) { | |
parseExport(); | |
} else { | |
unexpected(); | |
} | |
} | |
function flowParseDeclareModuleExports() { | |
expectContextual(ContextualKeyword._exports); | |
flowParseTypeAnnotation(); | |
semicolon(); | |
} | |
function flowParseDeclareTypeAlias() { | |
next(); | |
flowParseTypeAlias(); | |
} | |
function flowParseDeclareOpaqueType() { | |
next(); | |
flowParseOpaqueType(true); | |
} | |
function flowParseDeclareInterface() { | |
next(); | |
flowParseInterfaceish(); | |
} | |
function flowParseInterfaceish(isClass = false) { | |
flowParseRestrictedIdentifier(); | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
} | |
if (eat(TokenType._extends)) { | |
do { | |
flowParseInterfaceExtends(); | |
} while (!isClass && eat(TokenType.comma)); | |
} | |
if (isContextual(ContextualKeyword._mixins)) { | |
next(); | |
do { | |
flowParseInterfaceExtends(); | |
} while (eat(TokenType.comma)); | |
} | |
if (isContextual(ContextualKeyword._implements)) { | |
next(); | |
do { | |
flowParseInterfaceExtends(); | |
} while (eat(TokenType.comma)); | |
} | |
flowParseObjectType(isClass, false, isClass); | |
} | |
function flowParseInterfaceExtends() { | |
flowParseQualifiedTypeIdentifier(false); | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterInstantiation(); | |
} | |
} | |
function flowParseInterface() { | |
flowParseInterfaceish(); | |
} | |
function flowParseRestrictedIdentifier() { | |
parseIdentifier(); | |
} | |
function flowParseTypeAlias() { | |
flowParseRestrictedIdentifier(); | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
} | |
flowParseTypeInitialiser(TokenType.eq); | |
semicolon(); | |
} | |
function flowParseOpaqueType(declare) { | |
expectContextual(ContextualKeyword._type); | |
flowParseRestrictedIdentifier(); | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
} | |
if (match(TokenType.colon)) { | |
flowParseTypeInitialiser(TokenType.colon); | |
} | |
if (!declare) { | |
flowParseTypeInitialiser(TokenType.eq); | |
} | |
semicolon(); | |
} | |
function flowParseTypeParameter() { | |
flowParseVariance(); | |
flowParseTypeAnnotatableIdentifier(); | |
if (eat(TokenType.eq)) { | |
flowParseType(); | |
} | |
} | |
function flowParseTypeParameterDeclaration() { | |
const oldIsType = pushTypeContext(0); | |
if (match(TokenType.lessThan) || match(TokenType.typeParameterStart)) { | |
next(); | |
} else { | |
unexpected(); | |
} | |
do { | |
flowParseTypeParameter(); | |
if (!match(TokenType.greaterThan)) { | |
expect(TokenType.comma); | |
} | |
} while (!match(TokenType.greaterThan) && !state.error); | |
expect(TokenType.greaterThan); | |
popTypeContext(oldIsType); | |
} | |
function flowParseTypeParameterInstantiation() { | |
const oldIsType = pushTypeContext(0); | |
expect(TokenType.lessThan); | |
while (!match(TokenType.greaterThan) && !state.error) { | |
flowParseType(); | |
if (!match(TokenType.greaterThan)) { | |
expect(TokenType.comma); | |
} | |
} | |
expect(TokenType.greaterThan); | |
popTypeContext(oldIsType); | |
} | |
function flowParseInterfaceType() { | |
expectContextual(ContextualKeyword._interface); | |
if (eat(TokenType._extends)) { | |
do { | |
flowParseInterfaceExtends(); | |
} while (eat(TokenType.comma)); | |
} | |
flowParseObjectType(false, false, false); | |
} | |
function flowParseObjectPropertyKey() { | |
if (match(TokenType.num) || match(TokenType.string)) { | |
parseExprAtom(); | |
} else { | |
parseIdentifier(); | |
} | |
} | |
function flowParseObjectTypeIndexer() { | |
if (lookaheadType() === TokenType.colon) { | |
flowParseObjectPropertyKey(); | |
flowParseTypeInitialiser(); | |
} else { | |
flowParseType(); | |
} | |
expect(TokenType.bracketR); | |
flowParseTypeInitialiser(); | |
} | |
function flowParseObjectTypeInternalSlot() { | |
flowParseObjectPropertyKey(); | |
expect(TokenType.bracketR); | |
expect(TokenType.bracketR); | |
if (match(TokenType.lessThan) || match(TokenType.parenL)) { | |
flowParseObjectTypeMethodish(); | |
} else { | |
eat(TokenType.question); | |
flowParseTypeInitialiser(); | |
} | |
} | |
function flowParseObjectTypeMethodish() { | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
} | |
expect(TokenType.parenL); | |
while ( | |
!match(TokenType.parenR) && | |
!match(TokenType.ellipsis) && | |
!state.error | |
) { | |
flowParseFunctionTypeParam(); | |
if (!match(TokenType.parenR)) { | |
expect(TokenType.comma); | |
} | |
} | |
if (eat(TokenType.ellipsis)) { | |
flowParseFunctionTypeParam(); | |
} | |
expect(TokenType.parenR); | |
flowParseTypeInitialiser(); | |
} | |
function flowParseObjectTypeCallProperty() { | |
flowParseObjectTypeMethodish(); | |
} | |
function flowParseObjectType(allowStatic, allowExact, allowProto) { | |
let endDelim; | |
if (allowExact && match(TokenType.braceBarL)) { | |
expect(TokenType.braceBarL); | |
endDelim = TokenType.braceBarR; | |
} else { | |
expect(TokenType.braceL); | |
endDelim = TokenType.braceR; | |
} | |
while (!match(endDelim) && !state.error) { | |
if (allowProto && isContextual(ContextualKeyword._proto)) { | |
const lookahead = lookaheadType(); | |
if (lookahead !== TokenType.colon && lookahead !== TokenType.question) { | |
next(); | |
allowStatic = false; | |
} | |
} | |
if (allowStatic && isContextual(ContextualKeyword._static)) { | |
const lookahead = lookaheadType(); | |
if (lookahead !== TokenType.colon && lookahead !== TokenType.question) { | |
next(); | |
} | |
} | |
flowParseVariance(); | |
if (eat(TokenType.bracketL)) { | |
if (eat(TokenType.bracketL)) { | |
flowParseObjectTypeInternalSlot(); | |
} else { | |
flowParseObjectTypeIndexer(); | |
} | |
} else if (match(TokenType.parenL) || match(TokenType.lessThan)) { | |
flowParseObjectTypeCallProperty(); | |
} else { | |
if ( | |
isContextual(ContextualKeyword._get) || | |
isContextual(ContextualKeyword._set) | |
) { | |
const lookahead = lookaheadType(); | |
if ( | |
lookahead === TokenType.name || | |
lookahead === TokenType.string || | |
lookahead === TokenType.num | |
) { | |
next(); | |
} | |
} | |
flowParseObjectTypeProperty(); | |
} | |
flowObjectTypeSemicolon(); | |
} | |
expect(endDelim); | |
} | |
function flowParseObjectTypeProperty() { | |
if (match(TokenType.ellipsis)) { | |
expect(TokenType.ellipsis); | |
if (!eat(TokenType.comma)) { | |
eat(TokenType.semi); | |
} | |
if (match(TokenType.braceR)) { | |
return; | |
} | |
flowParseType(); | |
} else { | |
flowParseObjectPropertyKey(); | |
if (match(TokenType.lessThan) || match(TokenType.parenL)) { | |
flowParseObjectTypeMethodish(); | |
} else { | |
eat(TokenType.question); | |
flowParseTypeInitialiser(); | |
} | |
} | |
} | |
function flowObjectTypeSemicolon() { | |
if ( | |
!eat(TokenType.semi) && | |
!eat(TokenType.comma) && | |
!match(TokenType.braceR) && | |
!match(TokenType.braceBarR) | |
) { | |
unexpected(); | |
} | |
} | |
function flowParseQualifiedTypeIdentifier(initialIdAlreadyParsed) { | |
if (!initialIdAlreadyParsed) { | |
parseIdentifier(); | |
} | |
while (eat(TokenType.dot)) { | |
parseIdentifier(); | |
} | |
} | |
function flowParseGenericType() { | |
flowParseQualifiedTypeIdentifier(true); | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterInstantiation(); | |
} | |
} | |
function flowParseTypeofType() { | |
expect(TokenType._typeof); | |
flowParsePrimaryType(); | |
} | |
function flowParseTupleType() { | |
expect(TokenType.bracketL); | |
while (state.pos < input.length && !match(TokenType.bracketR)) { | |
flowParseType(); | |
if (match(TokenType.bracketR)) { | |
break; | |
} | |
expect(TokenType.comma); | |
} | |
expect(TokenType.bracketR); | |
} | |
function flowParseFunctionTypeParam() { | |
const lookahead = lookaheadType(); | |
if (lookahead === TokenType.colon || lookahead === TokenType.question) { | |
parseIdentifier(); | |
eat(TokenType.question); | |
flowParseTypeInitialiser(); | |
} else { | |
flowParseType(); | |
} | |
} | |
function flowParseFunctionTypeParams() { | |
while ( | |
!match(TokenType.parenR) && | |
!match(TokenType.ellipsis) && | |
!state.error | |
) { | |
flowParseFunctionTypeParam(); | |
if (!match(TokenType.parenR)) { | |
expect(TokenType.comma); | |
} | |
} | |
if (eat(TokenType.ellipsis)) { | |
flowParseFunctionTypeParam(); | |
} | |
} | |
function flowParsePrimaryType() { | |
let isGroupedType = false; | |
const oldNoAnonFunctionType = state.noAnonFunctionType; | |
switch (state.type) { | |
case TokenType.name: { | |
if (isContextual(ContextualKeyword._interface)) { | |
flowParseInterfaceType(); | |
return; | |
} | |
parseIdentifier(); | |
flowParseGenericType(); | |
return; | |
} | |
case TokenType.braceL: | |
flowParseObjectType(false, false, false); | |
return; | |
case TokenType.braceBarL: | |
flowParseObjectType(false, true, false); | |
return; | |
case TokenType.bracketL: | |
flowParseTupleType(); | |
return; | |
case TokenType.lessThan: | |
flowParseTypeParameterDeclaration(); | |
expect(TokenType.parenL); | |
flowParseFunctionTypeParams(); | |
expect(TokenType.parenR); | |
expect(TokenType.arrow); | |
flowParseType(); | |
return; | |
case TokenType.parenL: | |
next(); | |
if (!match(TokenType.parenR) && !match(TokenType.ellipsis)) { | |
if (match(TokenType.name)) { | |
const token = lookaheadType(); | |
isGroupedType = | |
token !== TokenType.question && token !== TokenType.colon; | |
} else { | |
isGroupedType = true; | |
} | |
} | |
if (isGroupedType) { | |
state.noAnonFunctionType = false; | |
flowParseType(); | |
state.noAnonFunctionType = oldNoAnonFunctionType; | |
if ( | |
state.noAnonFunctionType || | |
!( | |
match(TokenType.comma) || | |
(match(TokenType.parenR) && lookaheadType() === TokenType.arrow) | |
) | |
) { | |
expect(TokenType.parenR); | |
return; | |
} else { | |
eat(TokenType.comma); | |
} | |
} | |
flowParseFunctionTypeParams(); | |
expect(TokenType.parenR); | |
expect(TokenType.arrow); | |
flowParseType(); | |
return; | |
case TokenType.minus: | |
next(); | |
parseLiteral(); | |
return; | |
case TokenType.string: | |
case TokenType.num: | |
case TokenType._true: | |
case TokenType._false: | |
case TokenType._null: | |
case TokenType._this: | |
case TokenType._void: | |
case TokenType.star: | |
next(); | |
return; | |
default: | |
if (state.type === TokenType._typeof) { | |
flowParseTypeofType(); | |
return; | |
} else if (state.type & TokenType.IS_KEYWORD) { | |
next(); | |
state.tokens[state.tokens.length - 1].type = TokenType.name; | |
return; | |
} | |
} | |
unexpected(); | |
} | |
function flowParsePostfixType() { | |
flowParsePrimaryType(); | |
while (!canInsertSemicolon() && match(TokenType.bracketL)) { | |
expect(TokenType.bracketL); | |
expect(TokenType.bracketR); | |
} | |
} | |
function flowParsePrefixType() { | |
if (eat(TokenType.question)) { | |
flowParsePrefixType(); | |
} else { | |
flowParsePostfixType(); | |
} | |
} | |
function flowParseAnonFunctionWithoutParens() { | |
flowParsePrefixType(); | |
if (!state.noAnonFunctionType && eat(TokenType.arrow)) { | |
flowParseType(); | |
} | |
} | |
function flowParseIntersectionType() { | |
eat(TokenType.bitwiseAND); | |
flowParseAnonFunctionWithoutParens(); | |
while (eat(TokenType.bitwiseAND)) { | |
flowParseAnonFunctionWithoutParens(); | |
} | |
} | |
function flowParseUnionType() { | |
eat(TokenType.bitwiseOR); | |
flowParseIntersectionType(); | |
while (eat(TokenType.bitwiseOR)) { | |
flowParseIntersectionType(); | |
} | |
} | |
function flowParseType() { | |
flowParseUnionType(); | |
} | |
function flowParseTypeAnnotation() { | |
flowParseTypeInitialiser(); | |
} | |
function flowParseTypeAnnotatableIdentifier() { | |
parseIdentifier(); | |
if (match(TokenType.colon)) { | |
flowParseTypeAnnotation(); | |
} | |
} | |
function flowParseVariance() { | |
if (match(TokenType.plus) || match(TokenType.minus)) { | |
next(); | |
} | |
} | |
function flowParseFunctionBodyAndFinish(funcContextId) { | |
if (match(TokenType.colon)) { | |
flowParseTypeAndPredicateInitialiser(); | |
} | |
parseFunctionBody(false, funcContextId); | |
} | |
function flowParseSubscript(startTokenIndex, noCalls, stopState) { | |
if (match(TokenType.questionDot) && lookaheadType() === TokenType.lessThan) { | |
if (noCalls) { | |
stopState.stop = true; | |
return; | |
} | |
next(); | |
flowParseTypeParameterInstantiation(); | |
expect(TokenType.parenL); | |
parseCallExpressionArguments(); | |
return; | |
} else if (!noCalls && match(TokenType.lessThan)) { | |
const snapshot = state.snapshot(); | |
flowParseTypeParameterInstantiation(); | |
expect(TokenType.parenL); | |
parseCallExpressionArguments(); | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} else { | |
return; | |
} | |
} | |
baseParseSubscript(startTokenIndex, noCalls, stopState); | |
} | |
function flowStartParseNewArguments() { | |
if (match(TokenType.lessThan)) { | |
const snapshot = state.snapshot(); | |
flowParseTypeParameterInstantiation(); | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} | |
} | |
} | |
function flowTryParseStatement() { | |
if ( | |
match(TokenType.name) && | |
state.contextualKeyword === ContextualKeyword._interface | |
) { | |
const oldIsType = pushTypeContext(0); | |
next(); | |
flowParseInterface(); | |
popTypeContext(oldIsType); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function flowParseIdentifierStatement(contextualKeyword) { | |
if (contextualKeyword === ContextualKeyword._declare) { | |
if ( | |
match(TokenType._class) || | |
match(TokenType.name) || | |
match(TokenType._function) || | |
match(TokenType._var) || | |
match(TokenType._export) | |
) { | |
const oldIsType = pushTypeContext(1); | |
flowParseDeclare(); | |
popTypeContext(oldIsType); | |
} | |
} else if (match(TokenType.name)) { | |
if (contextualKeyword === ContextualKeyword._interface) { | |
const oldIsType = pushTypeContext(1); | |
flowParseInterface(); | |
popTypeContext(oldIsType); | |
} else if (contextualKeyword === ContextualKeyword._type) { | |
const oldIsType = pushTypeContext(1); | |
flowParseTypeAlias(); | |
popTypeContext(oldIsType); | |
} else if (contextualKeyword === ContextualKeyword._opaque) { | |
const oldIsType = pushTypeContext(1); | |
flowParseOpaqueType(false); | |
popTypeContext(oldIsType); | |
} | |
} | |
semicolon(); | |
} | |
function flowShouldParseExportDeclaration() { | |
return ( | |
isContextual(ContextualKeyword._type) || | |
isContextual(ContextualKeyword._interface) || | |
isContextual(ContextualKeyword._opaque) | |
); | |
} | |
function flowShouldDisallowExportDefaultSpecifier() { | |
return ( | |
match(TokenType.name) && | |
(state.contextualKeyword === ContextualKeyword._type || | |
state.contextualKeyword === ContextualKeyword._interface || | |
state.contextualKeyword === ContextualKeyword._opaque) | |
); | |
} | |
function flowParseExportDeclaration() { | |
if (isContextual(ContextualKeyword._type)) { | |
const oldIsType = pushTypeContext(1); | |
next(); | |
if (match(TokenType.braceL)) { | |
parseExportSpecifiers(); | |
parseExportFrom(); | |
} else { | |
flowParseTypeAlias(); | |
} | |
popTypeContext(oldIsType); | |
} else if (isContextual(ContextualKeyword._opaque)) { | |
const oldIsType = pushTypeContext(1); | |
next(); | |
flowParseOpaqueType(false); | |
popTypeContext(oldIsType); | |
} else if (isContextual(ContextualKeyword._interface)) { | |
const oldIsType = pushTypeContext(1); | |
next(); | |
flowParseInterface(); | |
popTypeContext(oldIsType); | |
} else { | |
parseStatement(true); | |
} | |
} | |
function flowShouldParseExportStar() { | |
return ( | |
match(TokenType.star) || | |
(isContextual(ContextualKeyword._type) && | |
lookaheadType() === TokenType.star) | |
); | |
} | |
function flowParseExportStar() { | |
if (eatContextual(ContextualKeyword._type)) { | |
const oldIsType = pushTypeContext(2); | |
baseParseExportStar(); | |
popTypeContext(oldIsType); | |
} else { | |
baseParseExportStar(); | |
} | |
} | |
function flowAfterParseClassSuper(hasSuper) { | |
if (hasSuper && match(TokenType.lessThan)) { | |
flowParseTypeParameterInstantiation(); | |
} | |
if (isContextual(ContextualKeyword._implements)) { | |
const oldIsType = pushTypeContext(0); | |
next(); | |
state.tokens[state.tokens.length - 1].type = TokenType._implements; | |
do { | |
flowParseRestrictedIdentifier(); | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterInstantiation(); | |
} | |
} while (eat(TokenType.comma)); | |
popTypeContext(oldIsType); | |
} | |
} | |
function flowStartParseObjPropValue() { | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
if (!match(TokenType.parenL)) unexpected(); | |
} | |
} | |
function flowParseAssignableListItemTypes() { | |
const oldIsType = pushTypeContext(0); | |
eat(TokenType.question); | |
if (match(TokenType.colon)) { | |
flowParseTypeAnnotation(); | |
} | |
popTypeContext(oldIsType); | |
} | |
function flowStartParseImportSpecifiers() { | |
if (match(TokenType._typeof) || isContextual(ContextualKeyword._type)) { | |
const lh = lookaheadTypeAndKeyword(); | |
if ( | |
isMaybeDefaultImport(lh) || | |
lh.type === TokenType.braceL || | |
lh.type === TokenType.star | |
) { | |
next(); | |
} | |
} | |
} | |
function flowParseImportSpecifier() { | |
const isTypeKeyword = | |
state.contextualKeyword === ContextualKeyword._type || | |
state.type === TokenType._typeof; | |
if (isTypeKeyword) { | |
next(); | |
} else { | |
parseIdentifier(); | |
} | |
if ( | |
isContextual(ContextualKeyword._as) && | |
!isLookaheadContextual(ContextualKeyword._as) | |
) { | |
parseIdentifier(); | |
if ( | |
isTypeKeyword && | |
!match(TokenType.name) && | |
!(state.type & TokenType.IS_KEYWORD) | |
); | |
else { | |
parseIdentifier(); | |
} | |
} else if ( | |
isTypeKeyword && | |
(match(TokenType.name) || !!(state.type & TokenType.IS_KEYWORD)) | |
) { | |
parseIdentifier(); | |
if (eatContextual(ContextualKeyword._as)) { | |
parseIdentifier(); | |
} | |
} | |
} | |
function flowStartParseFunctionParams() { | |
if (match(TokenType.lessThan)) { | |
const oldIsType = pushTypeContext(0); | |
flowParseTypeParameterDeclaration(); | |
popTypeContext(oldIsType); | |
} | |
} | |
function flowAfterParseVarHead() { | |
if (match(TokenType.colon)) { | |
flowParseTypeAnnotation(); | |
} | |
} | |
function flowStartParseAsyncArrowFromCallExpression() { | |
if (match(TokenType.colon)) { | |
const oldNoAnonFunctionType = state.noAnonFunctionType; | |
state.noAnonFunctionType = true; | |
flowParseTypeAnnotation(); | |
state.noAnonFunctionType = oldNoAnonFunctionType; | |
} | |
} | |
function flowParseMaybeAssign(noIn, isWithinParens) { | |
if (match(TokenType.lessThan)) { | |
const snapshot = state.snapshot(); | |
let wasArrow = baseParseMaybeAssign(noIn, isWithinParens); | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
state.type = TokenType.typeParameterStart; | |
} else { | |
return wasArrow; | |
} | |
const oldIsType = pushTypeContext(0); | |
flowParseTypeParameterDeclaration(); | |
popTypeContext(oldIsType); | |
wasArrow = baseParseMaybeAssign(noIn, isWithinParens); | |
if (wasArrow) { | |
return true; | |
} | |
unexpected(); | |
} | |
return baseParseMaybeAssign(noIn, isWithinParens); | |
} | |
function flowParseArrow() { | |
if (match(TokenType.colon)) { | |
const oldIsType = pushTypeContext(0); | |
const snapshot = state.snapshot(); | |
const oldNoAnonFunctionType = state.noAnonFunctionType; | |
state.noAnonFunctionType = true; | |
flowParseTypeAndPredicateInitialiser(); | |
state.noAnonFunctionType = oldNoAnonFunctionType; | |
if (canInsertSemicolon()) unexpected(); | |
if (!match(TokenType.arrow)) unexpected(); | |
if (state.error) { | |
state.restoreFromSnapshot(snapshot); | |
} | |
popTypeContext(oldIsType); | |
} | |
return eat(TokenType.arrow); | |
} | |
function flowParseSubscripts(startTokenIndex, noCalls = false) { | |
if ( | |
state.tokens[state.tokens.length - 1].contextualKeyword === | |
ContextualKeyword._async && | |
match(TokenType.lessThan) | |
) { | |
const snapshot = state.snapshot(); | |
const wasArrow = parseAsyncArrowWithTypeParameters(); | |
if (wasArrow && !state.error) { | |
return; | |
} | |
state.restoreFromSnapshot(snapshot); | |
} | |
baseParseSubscripts(startTokenIndex, noCalls); | |
} | |
function parseAsyncArrowWithTypeParameters() { | |
state.scopeDepth++; | |
const startTokenIndex = state.tokens.length; | |
parseFunctionParams(); | |
if (!parseArrow()) { | |
return false; | |
} | |
parseArrowExpression(startTokenIndex); | |
return true; | |
} | |
function parseTopLevel() { | |
parseBlockBody(TokenType.eof); | |
state.scopes.push(new Scope(0, state.tokens.length, true)); | |
if (state.scopeDepth !== 0) { | |
throw new Error(`Invalid scope depth at end of file: ${state.scopeDepth}`); | |
} | |
return new File(state.tokens, state.scopes); | |
} | |
function parseStatement(declaration) { | |
if (isFlowEnabled) { | |
if (flowTryParseStatement()) { | |
return; | |
} | |
} | |
if (match(TokenType.at)) { | |
parseDecorators(); | |
} | |
parseStatementContent(declaration); | |
} | |
function parseStatementContent(declaration) { | |
if (isTypeScriptEnabled) { | |
if (tsTryParseStatementContent()) { | |
return; | |
} | |
} | |
const starttype = state.type; | |
switch (starttype) { | |
case TokenType._break: | |
case TokenType._continue: | |
parseBreakContinueStatement(); | |
return; | |
case TokenType._debugger: | |
parseDebuggerStatement(); | |
return; | |
case TokenType._do: | |
parseDoStatement(); | |
return; | |
case TokenType._for: | |
parseForStatement(); | |
return; | |
case TokenType._function: | |
if (lookaheadType() === TokenType.dot) break; | |
if (!declaration) unexpected(); | |
parseFunctionStatement(); | |
return; | |
case TokenType._class: | |
if (!declaration) unexpected(); | |
parseClass(true); | |
return; | |
case TokenType._if: | |
parseIfStatement(); | |
return; | |
case TokenType._return: | |
parseReturnStatement(); | |
return; | |
case TokenType._switch: | |
parseSwitchStatement(); | |
return; | |
case TokenType._throw: | |
parseThrowStatement(); | |
return; | |
case TokenType._try: | |
parseTryStatement(); | |
return; | |
case TokenType._let: | |
case TokenType._const: | |
if (!declaration) unexpected(); | |
case TokenType._var: | |
parseVarStatement(starttype); | |
return; | |
case TokenType._while: | |
parseWhileStatement(); | |
return; | |
case TokenType.braceL: | |
parseBlock(); | |
return; | |
case TokenType.semi: | |
parseEmptyStatement(); | |
return; | |
case TokenType._export: | |
case TokenType._import: { | |
const nextType = lookaheadType(); | |
if (nextType === TokenType.parenL || nextType === TokenType.dot) { | |
break; | |
} | |
next(); | |
if (starttype === TokenType._import) { | |
parseImport(); | |
} else { | |
parseExport(); | |
} | |
return; | |
} | |
case TokenType.name: | |
if (state.contextualKeyword === ContextualKeyword._async) { | |
const functionStart = state.start; | |
const snapshot = state.snapshot(); | |
next(); | |
if (match(TokenType._function) && !canInsertSemicolon()) { | |
expect(TokenType._function); | |
parseFunction(functionStart, true); | |
return; | |
} else { | |
state.restoreFromSnapshot(snapshot); | |
} | |
} | |
} | |
const initialTokensLength = state.tokens.length; | |
parseExpression(); | |
let simpleName = null; | |
if (state.tokens.length === initialTokensLength + 1) { | |
const token = state.tokens[state.tokens.length - 1]; | |
if (token.type === TokenType.name) { | |
simpleName = token.contextualKeyword; | |
} | |
} | |
if (simpleName == null) { | |
semicolon(); | |
return; | |
} | |
if (eat(TokenType.colon)) { | |
parseLabeledStatement(); | |
} else { | |
parseIdentifierStatement(simpleName); | |
} | |
} | |
function parseDecorators() { | |
while (match(TokenType.at)) { | |
parseDecorator(); | |
} | |
} | |
function parseDecorator() { | |
next(); | |
if (eat(TokenType.parenL)) { | |
parseExpression(); | |
expect(TokenType.parenR); | |
} else { | |
parseIdentifier(); | |
while (eat(TokenType.dot)) { | |
parseIdentifier(); | |
} | |
} | |
parseMaybeDecoratorArguments(); | |
} | |
function parseMaybeDecoratorArguments() { | |
if (isTypeScriptEnabled) { | |
tsParseMaybeDecoratorArguments(); | |
} else { | |
baseParseMaybeDecoratorArguments(); | |
} | |
} | |
function baseParseMaybeDecoratorArguments() { | |
if (eat(TokenType.parenL)) { | |
parseCallExpressionArguments(); | |
} | |
} | |
function parseBreakContinueStatement() { | |
next(); | |
if (!isLineTerminator()) { | |
parseIdentifier(); | |
semicolon(); | |
} | |
} | |
function parseDebuggerStatement() { | |
next(); | |
semicolon(); | |
} | |
function parseDoStatement() { | |
next(); | |
parseStatement(false); | |
expect(TokenType._while); | |
parseParenExpression(); | |
eat(TokenType.semi); | |
} | |
function parseForStatement() { | |
state.scopeDepth++; | |
const startTokenIndex = state.tokens.length; | |
parseAmbiguousForStatement(); | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push(new Scope(startTokenIndex, endTokenIndex, false)); | |
state.scopeDepth--; | |
} | |
function parseAmbiguousForStatement() { | |
next(); | |
let forAwait = false; | |
if (isContextual(ContextualKeyword._await)) { | |
forAwait = true; | |
next(); | |
} | |
expect(TokenType.parenL); | |
if (match(TokenType.semi)) { | |
if (forAwait) { | |
unexpected(); | |
} | |
parseFor(); | |
return; | |
} | |
if ( | |
match(TokenType._var) || | |
match(TokenType._let) || | |
match(TokenType._const) | |
) { | |
const varKind = state.type; | |
next(); | |
parseVar(true, varKind); | |
if (match(TokenType._in) || isContextual(ContextualKeyword._of)) { | |
parseForIn(forAwait); | |
return; | |
} | |
parseFor(); | |
return; | |
} | |
parseExpression(true); | |
if (match(TokenType._in) || isContextual(ContextualKeyword._of)) { | |
parseForIn(forAwait); | |
return; | |
} | |
if (forAwait) { | |
unexpected(); | |
} | |
parseFor(); | |
} | |
function parseFunctionStatement() { | |
const functionStart = state.start; | |
next(); | |
parseFunction(functionStart, true); | |
} | |
function parseIfStatement() { | |
next(); | |
parseParenExpression(); | |
parseStatement(false); | |
if (eat(TokenType._else)) { | |
parseStatement(false); | |
} | |
} | |
function parseReturnStatement() { | |
next(); | |
if (!isLineTerminator()) { | |
parseExpression(); | |
semicolon(); | |
} | |
} | |
function parseSwitchStatement() { | |
next(); | |
parseParenExpression(); | |
state.scopeDepth++; | |
const startTokenIndex = state.tokens.length; | |
expect(TokenType.braceL); | |
while (!match(TokenType.braceR) && !state.error) { | |
if (match(TokenType._case) || match(TokenType._default)) { | |
const isCase = match(TokenType._case); | |
next(); | |
if (isCase) { | |
parseExpression(); | |
} | |
expect(TokenType.colon); | |
} else { | |
parseStatement(true); | |
} | |
} | |
next(); | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push(new Scope(startTokenIndex, endTokenIndex, false)); | |
state.scopeDepth--; | |
} | |
function parseThrowStatement() { | |
next(); | |
parseExpression(); | |
semicolon(); | |
} | |
function parseCatchClauseParam() { | |
parseBindingAtom(true); | |
if (isTypeScriptEnabled) { | |
tsTryParseTypeAnnotation(); | |
} | |
} | |
function parseTryStatement() { | |
next(); | |
parseBlock(); | |
if (match(TokenType._catch)) { | |
next(); | |
let catchBindingStartTokenIndex = null; | |
if (match(TokenType.parenL)) { | |
state.scopeDepth++; | |
catchBindingStartTokenIndex = state.tokens.length; | |
expect(TokenType.parenL); | |
parseCatchClauseParam(); | |
expect(TokenType.parenR); | |
} | |
parseBlock(); | |
if (catchBindingStartTokenIndex != null) { | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push( | |
new Scope(catchBindingStartTokenIndex, endTokenIndex, false) | |
); | |
state.scopeDepth--; | |
} | |
} | |
if (eat(TokenType._finally)) { | |
parseBlock(); | |
} | |
} | |
function parseVarStatement(kind) { | |
next(); | |
parseVar(false, kind); | |
semicolon(); | |
} | |
function parseWhileStatement() { | |
next(); | |
parseParenExpression(); | |
parseStatement(false); | |
} | |
function parseEmptyStatement() { | |
next(); | |
} | |
function parseLabeledStatement() { | |
parseStatement(true); | |
} | |
function parseIdentifierStatement(contextualKeyword) { | |
if (isTypeScriptEnabled) { | |
tsParseIdentifierStatement(contextualKeyword); | |
} else if (isFlowEnabled) { | |
flowParseIdentifierStatement(contextualKeyword); | |
} else { | |
semicolon(); | |
} | |
} | |
function parseBlock( | |
allowDirectives = false, | |
isFunctionScope = false, | |
contextId = 0 | |
) { | |
const startTokenIndex = state.tokens.length; | |
state.scopeDepth++; | |
expect(TokenType.braceL); | |
if (contextId) { | |
state.tokens[state.tokens.length - 1].contextId = contextId; | |
} | |
parseBlockBody(TokenType.braceR); | |
if (contextId) { | |
state.tokens[state.tokens.length - 1].contextId = contextId; | |
} | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push(new Scope(startTokenIndex, endTokenIndex, isFunctionScope)); | |
state.scopeDepth--; | |
} | |
function parseBlockBody(end) { | |
while (!eat(end) && !state.error) { | |
parseStatement(true); | |
} | |
} | |
function parseFor() { | |
expect(TokenType.semi); | |
if (!match(TokenType.semi)) { | |
parseExpression(); | |
} | |
expect(TokenType.semi); | |
if (!match(TokenType.parenR)) { | |
parseExpression(); | |
} | |
expect(TokenType.parenR); | |
parseStatement(false); | |
} | |
function parseForIn(forAwait) { | |
if (forAwait) { | |
eatContextual(ContextualKeyword._of); | |
} else { | |
next(); | |
} | |
parseExpression(); | |
expect(TokenType.parenR); | |
parseStatement(false); | |
} | |
function parseVar(isFor, kind) { | |
while (true) { | |
const isBlockScope = kind === TokenType._const || kind === TokenType._let; | |
parseVarHead(isBlockScope); | |
if (eat(TokenType.eq)) { | |
const eqIndex = state.tokens.length - 1; | |
parseMaybeAssign(isFor); | |
state.tokens[eqIndex].rhsEndIndex = state.tokens.length; | |
} | |
if (!eat(TokenType.comma)) { | |
break; | |
} | |
} | |
} | |
function parseVarHead(isBlockScope) { | |
parseBindingAtom(isBlockScope); | |
if (isTypeScriptEnabled) { | |
tsAfterParseVarHead(); | |
} else if (isFlowEnabled) { | |
flowAfterParseVarHead(); | |
} | |
} | |
function parseFunction(functionStart, isStatement, optionalId = false) { | |
if (match(TokenType.star)) { | |
next(); | |
} | |
if ( | |
isStatement && | |
!optionalId && | |
!match(TokenType.name) && | |
!match(TokenType._yield) | |
) { | |
unexpected(); | |
} | |
let nameScopeStartTokenIndex = null; | |
if (match(TokenType.name)) { | |
if (!isStatement) { | |
nameScopeStartTokenIndex = state.tokens.length; | |
state.scopeDepth++; | |
} | |
parseBindingIdentifier(false); | |
} | |
const startTokenIndex = state.tokens.length; | |
state.scopeDepth++; | |
parseFunctionParams(); | |
parseFunctionBodyAndFinish(functionStart); | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push(new Scope(startTokenIndex, endTokenIndex, true)); | |
state.scopeDepth--; | |
if (nameScopeStartTokenIndex !== null) { | |
state.scopes.push(new Scope(nameScopeStartTokenIndex, endTokenIndex, true)); | |
state.scopeDepth--; | |
} | |
} | |
function parseFunctionParams(allowModifiers = false, funcContextId = 0) { | |
if (isTypeScriptEnabled) { | |
tsStartParseFunctionParams(); | |
} else if (isFlowEnabled) { | |
flowStartParseFunctionParams(); | |
} | |
expect(TokenType.parenL); | |
if (funcContextId) { | |
state.tokens[state.tokens.length - 1].contextId = funcContextId; | |
} | |
parseBindingList( | |
TokenType.parenR, | |
false, | |
false, | |
allowModifiers, | |
funcContextId | |
); | |
if (funcContextId) { | |
state.tokens[state.tokens.length - 1].contextId = funcContextId; | |
} | |
} | |
function parseClass(isStatement, optionalId = false) { | |
const contextId = getNextContextId(); | |
next(); | |
state.tokens[state.tokens.length - 1].contextId = contextId; | |
state.tokens[state.tokens.length - 1].isExpression = !isStatement; | |
let nameScopeStartTokenIndex = null; | |
if (!isStatement) { | |
nameScopeStartTokenIndex = state.tokens.length; | |
state.scopeDepth++; | |
} | |
parseClassId(isStatement, optionalId); | |
parseClassSuper(); | |
const openBraceIndex = state.tokens.length; | |
parseClassBody(contextId); | |
if (state.error) { | |
return; | |
} | |
state.tokens[openBraceIndex].contextId = contextId; | |
state.tokens[state.tokens.length - 1].contextId = contextId; | |
if (nameScopeStartTokenIndex !== null) { | |
const endTokenIndex = state.tokens.length; | |
state.scopes.push( | |
new Scope(nameScopeStartTokenIndex, endTokenIndex, false) | |
); | |
state.scopeDepth--; | |
} | |
} | |
function isClassProperty() { | |
return ( | |
match(TokenType.eq) || | |
match(TokenType.semi) || | |
match(TokenType.braceR) || | |
match(TokenType.bang) || | |
match(TokenType.colon) | |
); | |
} | |
function isClassMethod() { | |
return match(TokenType.parenL) || match(TokenType.lessThan); | |
} | |
function parseClassBody(classContextId) { | |
expect(TokenType.braceL); | |
while (!eat(TokenType.braceR) && !state.error) { | |
if (eat(TokenType.semi)) { | |
continue; | |
} | |
if (match(TokenType.at)) { | |
parseDecorator(); | |
continue; | |
} | |
const memberStart = state.start; | |
parseClassMember(memberStart, classContextId); | |
} | |
} | |
function parseClassMember(memberStart, classContextId) { | |
if (isTypeScriptEnabled) { | |
eatContextual(ContextualKeyword._declare); | |
tsParseAccessModifier(); | |
eatContextual(ContextualKeyword._declare); | |
} | |
let isStatic = false; | |
if ( | |
match(TokenType.name) && | |
state.contextualKeyword === ContextualKeyword._static | |
) { | |
parseIdentifier(); | |
if (isClassMethod()) { | |
parseClassMethod(memberStart, false); | |
return; | |
} else if (isClassProperty()) { | |
parseClassProperty(); | |
return; | |
} | |
state.tokens[state.tokens.length - 1].type = TokenType._static; | |
isStatic = true; | |
} | |
parseClassMemberWithIsStatic(memberStart, isStatic, classContextId); | |
} | |
function parseClassMemberWithIsStatic(memberStart, isStatic, classContextId) { | |
if (isTypeScriptEnabled) { | |
if (tsTryParseClassMemberWithIsStatic(isStatic, classContextId)) { | |
return; | |
} | |
} | |
if (eat(TokenType.star)) { | |
parseClassPropertyName(classContextId); | |
parseClassMethod(memberStart, false); | |
return; | |
} | |
parseClassPropertyName(classContextId); | |
let isConstructor = false; | |
const token = state.tokens[state.tokens.length - 1]; | |
if (token.contextualKeyword === ContextualKeyword._constructor) { | |
isConstructor = true; | |
} | |
parsePostMemberNameModifiers(); | |
if (isClassMethod()) { | |
parseClassMethod(memberStart, isConstructor); | |
} else if (isClassProperty()) { | |
parseClassProperty(); | |
} else if ( | |
token.contextualKeyword === ContextualKeyword._async && | |
!isLineTerminator() | |
) { | |
state.tokens[state.tokens.length - 1].type = TokenType._async; | |
const isGenerator = match(TokenType.star); | |
if (isGenerator) { | |
next(); | |
} | |
parseClassPropertyName(classContextId); | |
parsePostMemberNameModifiers(); | |
parseClassMethod(memberStart, false); | |
} else if ( | |
(token.contextualKeyword === ContextualKeyword._get || | |
token.contextualKeyword === ContextualKeyword._set) && | |
!(isLineTerminator() && match(TokenType.star)) | |
) { | |
if (token.contextualKeyword === ContextualKeyword._get) { | |
state.tokens[state.tokens.length - 1].type = TokenType._get; | |
} else { | |
state.tokens[state.tokens.length - 1].type = TokenType._set; | |
} | |
parseClassPropertyName(classContextId); | |
parseClassMethod(memberStart, false); | |
} else if (isLineTerminator()) { | |
parseClassProperty(); | |
} else { | |
unexpected(); | |
} | |
} | |
function parseClassMethod(functionStart, isConstructor) { | |
if (isTypeScriptEnabled) { | |
tsTryParseTypeParameters(); | |
} else if (isFlowEnabled) { | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
} | |
} | |
parseMethod(functionStart, isConstructor); | |
} | |
function parseClassPropertyName(classContextId) { | |
parsePropertyName(classContextId); | |
} | |
function parsePostMemberNameModifiers() { | |
if (isTypeScriptEnabled) { | |
const oldIsType = pushTypeContext(0); | |
eat(TokenType.question); | |
popTypeContext(oldIsType); | |
} | |
} | |
function parseClassProperty() { | |
if (isTypeScriptEnabled) { | |
eat(TokenType.bang); | |
tsTryParseTypeAnnotation(); | |
} else if (isFlowEnabled) { | |
if (match(TokenType.colon)) { | |
flowParseTypeAnnotation(); | |
} | |
} | |
if (match(TokenType.eq)) { | |
const equalsTokenIndex = state.tokens.length; | |
next(); | |
parseMaybeAssign(); | |
state.tokens[equalsTokenIndex].rhsEndIndex = state.tokens.length; | |
} | |
semicolon(); | |
} | |
function parseClassId(isStatement, optionalId = false) { | |
if ( | |
isTypeScriptEnabled && | |
(!isStatement || optionalId) && | |
isContextual(ContextualKeyword._implements) | |
) { | |
return; | |
} | |
if (match(TokenType.name)) { | |
parseBindingIdentifier(true); | |
} | |
if (isTypeScriptEnabled) { | |
tsTryParseTypeParameters(); | |
} else if (isFlowEnabled) { | |
if (match(TokenType.lessThan)) { | |
flowParseTypeParameterDeclaration(); | |
} | |
} | |
} | |
function parseClassSuper() { | |
let hasSuper = false; | |
if (eat(TokenType._extends)) { | |
parseExprSubscripts(); | |
hasSuper = true; | |
} else { | |
hasSuper = false; | |
} | |
if (isTypeScriptEnabled) { | |
tsAfterParseClassSuper(hasSuper); | |
} else if (isFlowEnabled) { | |
flowAfterParseClassSuper(hasSuper); | |
} | |
} | |
function parseExport() { | |
const exportIndex = state.tokens.length - 1; | |
if (isTypeScriptEnabled) { | |
if (tsTryParseExport()) { | |
return; | |
} | |
} | |
if (shouldParseExportStar()) { | |
parseExportStar(); | |
} else if (isExportDefaultSpecifier()) { | |
parseIdentifier(); | |
if (match(TokenType.comma) && lookaheadType() === TokenType.star) { | |
expect(TokenType.comma); | |
expect(TokenType.star); | |
expectContextual(ContextualKeyword._as); | |
parseIdentifier(); | |
} else { | |
parseExportSpecifiersMaybe(); | |
} | |
parseExportFrom(); | |
} else if (eat(TokenType._default)) { | |
parseExportDefaultExpression(); | |
} else if (shouldParseExportDeclaration()) { | |
parseExportDeclaration(); | |
} else { | |
parseExportSpecifiers(); | |
parseExportFrom(); | |
} | |
state.tokens[exportIndex].rhsEndIndex = state.tokens.length; | |
} | |
function parseExportDefaultExpression() { | |
if (isTypeScriptEnabled) { | |
if (tsTryParseExportDefaultExpression()) { | |
return; | |
} | |
} | |
const functionStart = state.start; | |
if (eat(TokenType._function)) { | |
parseFunction(functionStart, true, true); | |
} else if ( | |
isContextual(ContextualKeyword._async) && | |
lookaheadType() === TokenType._function | |
) { | |
eatContextual(ContextualKeyword._async); | |
eat(TokenType._function); | |
parseFunction(functionStart, true, true); | |
} else if (match(TokenType._class)) { | |
parseClass(true, true); | |
} else if (match(TokenType.at)) { | |
parseDecorators(); | |
parseClass(true, true); | |
} else { | |
parseMaybeAssign(); | |
semicolon(); | |
} | |
} | |
function parseExportDeclaration() { | |
if (isTypeScriptEnabled) { | |
tsParseExportDeclaration(); | |
} else if (isFlowEnabled) { | |
flowParseExportDeclaration(); | |
} else { | |
parseStatement(true); | |
} | |
} | |
function isExportDefaultSpecifier() { | |
if (isTypeScriptEnabled && tsIsDeclarationStart()) { | |
return false; | |
} else if (isFlowEnabled && flowShouldDisallowExportDefaultSpecifier()) { | |
return false; | |
} | |
if (match(TokenType.name)) { | |
return state.contextualKeyword !== ContextualKeyword._async; | |
} | |
if (!match(TokenType._default)) { | |
return false; | |
} | |
const _next = nextTokenStart(); | |
const lookahead = lookaheadTypeAndKeyword(); | |
const hasFrom = | |
lookahead.type === TokenType.name && | |
lookahead.contextualKeyword === ContextualKeyword._from; | |
if (lookahead.type === TokenType.comma) { | |
return true; | |
} | |
if (hasFrom) { | |
const nextAfterFrom = input.charCodeAt(nextTokenStartSince(_next + 4)); | |
return ( | |
nextAfterFrom === charCodes.quotationMark || | |
nextAfterFrom === charCodes.apostrophe | |
); | |
} | |
return false; | |
} | |
function parseExportSpecifiersMaybe() { | |
if (eat(TokenType.comma)) { | |
parseExportSpecifiers(); | |
} | |
} | |
function parseExportFrom() { | |
if (eatContextual(ContextualKeyword._from)) { | |
parseExprAtom(); | |
} | |
semicolon(); | |
} | |
function shouldParseExportStar() { | |
if (isFlowEnabled) { | |
return flowShouldParseExportStar(); | |
} else { | |
return match(TokenType.star); | |
} | |
} | |
function parseExportStar() { | |
if (isFlowEnabled) { | |
flowParseExportStar(); | |
} else { | |
baseParseExportStar(); | |
} | |
} | |
function baseParseExportStar() { | |
expect(TokenType.star); | |
if (isContextual(ContextualKeyword._as)) { | |
parseExportNamespace(); | |
} else { | |
parseExportFrom(); | |
} | |
} | |
function parseExportNamespace() { | |
next(); | |
state.tokens[state.tokens.length - 1].type = TokenType._as; | |
parseIdentifier(); | |
parseExportSpecifiersMaybe(); | |
parseExportFrom(); | |
} | |
function shouldParseExportDeclaration() { | |
return ( | |
(isTypeScriptEnabled && tsIsDeclarationStart()) || | |
(isFlowEnabled && flowShouldParseExportDeclaration()) || | |
state.type === TokenType._var || | |
state.type === TokenType._const || | |
state.type === TokenType._let || | |
state.type === TokenType._function || | |
state.type === TokenType._class || | |
isContextual(ContextualKeyword._async) || | |
match(TokenType.at) | |
); | |
} | |
function parseExportSpecifiers() { | |
let first = true; | |
expect(TokenType.braceL); | |
while (!eat(TokenType.braceR) && !state.error) { | |
if (first) { | |
first = false; | |
} else { | |
expect(TokenType.comma); | |
if (eat(TokenType.braceR)) { | |
break; | |
} | |
} | |
parseIdentifier(); | |
state.tokens[state.tokens.length - 1].identifierRole = | |
IdentifierRole.ExportAccess; | |
if (eatContextual(ContextualKeyword._as)) { | |
parseIdentifier(); | |
} | |
} | |
} | |
function parseImport() { | |
if ( | |
isTypeScriptEnabled && | |
match(TokenType.name) && | |
lookaheadType() === TokenType.eq | |
) { | |
tsParseImportEqualsDeclaration(); | |
return; | |
} | |
if (isTypeScriptEnabled) { | |
eatContextual(ContextualKeyword._type); | |
} | |
if (match(TokenType.string)) { | |
parseExprAtom(); | |
} else { | |
parseImportSpecifiers(); | |
expectContextual(ContextualKeyword._from); | |
parseExprAtom(); | |
} | |
semicolon(); | |
} | |
function shouldParseDefaultImport() { | |
return match(TokenType.name); | |
} | |
function parseImportSpecifierLocal() { | |
parseImportedIdentifier(); | |
} | |
function parseImportSpecifiers() { | |
if (isFlowEnabled) { | |
flowStartParseImportSpecifiers(); | |
} | |
let first = true; | |
if (shouldParseDefaultImport()) { | |
parseImportSpecifierLocal(); | |
if (!eat(TokenType.comma)) return; | |
} | |
if (match(TokenType.star)) { | |
next(); | |
expectContextual(ContextualKeyword._as); | |
parseImportSpecifierLocal(); | |
return; | |
} | |
expect(TokenType.braceL); | |
while (!eat(TokenType.braceR) && !state.error) { | |
if (first) { | |
first = false; | |
} else { | |
if (eat(TokenType.colon)) { | |
unexpected( | |
"ES2015 named imports do not destructure. Use another statement for destructuring after the import." | |
); | |
} | |
expect(TokenType.comma); | |
if (eat(TokenType.braceR)) { | |
break; | |
} | |
} | |
parseImportSpecifier(); | |
} | |
} | |
function parseImportSpecifier() { | |
if (isFlowEnabled) { | |
flowParseImportSpecifier(); | |
return; | |
} | |
parseImportedIdentifier(); | |
if (isContextual(ContextualKeyword._as)) { | |
state.tokens[state.tokens.length - 1].identifierRole = | |
IdentifierRole.ImportAccess; | |
next(); | |
parseImportedIdentifier(); | |
} | |
} | |
function parseFile() { | |
if ( | |
state.pos === 0 && | |
input.charCodeAt(0) === charCodes.numberSign && | |
input.charCodeAt(1) === charCodes.exclamationMark | |
) { | |
skipLineComment(2); | |
} | |
nextToken(); | |
return parseTopLevel(); | |
} | |
class File { | |
constructor(tokens, scopes) { | |
this.tokens = tokens; | |
this.scopes = scopes; | |
} | |
} | |
function parse(input2, isJSXEnabled2, isTypeScriptEnabled2, isFlowEnabled2) { | |
if (isFlowEnabled2 && isTypeScriptEnabled2) { | |
throw new Error("Cannot combine flow and typescript plugins."); | |
} | |
initParser(input2, isJSXEnabled2, isTypeScriptEnabled2, isFlowEnabled2); | |
const result = parseFile(); | |
if (state.error) { | |
throw augmentError(state.error); | |
} | |
return result; | |
} | |
function isAsyncOperation(tokens) { | |
let index = tokens.currentIndex(); | |
let depth = 0; | |
const startToken = tokens.currentToken(); | |
do { | |
const token = tokens.tokens[index]; | |
if (token.isOptionalChainStart) { | |
depth++; | |
} | |
if (token.isOptionalChainEnd) { | |
depth--; | |
} | |
depth += token.numNullishCoalesceStarts; | |
depth -= token.numNullishCoalesceEnds; | |
if ( | |
token.contextualKeyword === ContextualKeyword._await && | |
token.identifierRole == null && | |
token.scopeDepth === startToken.scopeDepth | |
) { | |
return true; | |
} | |
index += 1; | |
} while (depth > 0 && index < tokens.tokens.length); | |
return false; | |
} | |
class TokenProcessor { | |
__init() { | |
this.resultCode = ""; | |
} | |
__init2() { | |
this.tokenIndex = 0; | |
} | |
constructor(code, tokens, isFlowEnabled2, helperManager) { | |
this.code = code; | |
this.tokens = tokens; | |
this.isFlowEnabled = isFlowEnabled2; | |
this.helperManager = helperManager; | |
TokenProcessor.prototype.__init.call(this); | |
TokenProcessor.prototype.__init2.call(this); | |
} | |
snapshot() { | |
return { resultCode: this.resultCode, tokenIndex: this.tokenIndex }; | |
} | |
restoreToSnapshot(snapshot) { | |
this.resultCode = snapshot.resultCode; | |
this.tokenIndex = snapshot.tokenIndex; | |
} | |
getResultCodeIndex() { | |
return this.resultCode.length; | |
} | |
reset() { | |
this.resultCode = ""; | |
this.tokenIndex = 0; | |
} | |
matchesContextualAtIndex(index, contextualKeyword) { | |
return ( | |
this.matches1AtIndex(index, TokenType.name) && | |
this.tokens[index].contextualKeyword === contextualKeyword | |
); | |
} | |
identifierNameAtIndex(index) { | |
return this.identifierNameForToken(this.tokens[index]); | |
} | |
identifierName() { | |
return this.identifierNameForToken(this.currentToken()); | |
} | |
identifierNameForToken(token) { | |
return this.code.slice(token.start, token.end); | |
} | |
rawCodeForToken(token) { | |
return this.code.slice(token.start, token.end); | |
} | |
stringValueAtIndex(index) { | |
return this.stringValueForToken(this.tokens[index]); | |
} | |
stringValue() { | |
return this.stringValueForToken(this.currentToken()); | |
} | |
stringValueForToken(token) { | |
return this.code.slice(token.start + 1, token.end - 1); | |
} | |
matches1AtIndex(index, t1) { | |
return this.tokens[index].type === t1; | |
} | |
matches2AtIndex(index, t1, t2) { | |
return this.tokens[index].type === t1 && this.tokens[index + 1].type === t2; | |
} | |
matches3AtIndex(index, t1, t2, t3) { | |
return ( | |
this.tokens[index].type === t1 && | |
this.tokens[index + 1].type === t2 && | |
this.tokens[index + 2].type === t3 | |
); | |
} | |
matches1(t1) { | |
return this.tokens[this.tokenIndex].type === t1; | |
} | |
matches2(t1, t2) { | |
return ( | |
this.tokens[this.tokenIndex].type === t1 && | |
this.tokens[this.tokenIndex + 1].type === t2 | |
); | |
} | |
matches3(t1, t2, t3) { | |
return ( | |
this.tokens[this.tokenIndex].type === t1 && | |
this.tokens[this.tokenIndex + 1].type === t2 && | |
this.tokens[this.tokenIndex + 2].type === t3 | |
); | |
} | |
matches4(t1, t2, t3, t4) { | |
return ( | |
this.tokens[this.tokenIndex].type === t1 && | |
this.tokens[this.tokenIndex + 1].type === t2 && | |
this.tokens[this.tokenIndex + 2].type === t3 && | |
this.tokens[this.tokenIndex + 3].type === t4 | |
); | |
} | |
matches5(t1, t2, t3, t4, t5) { | |
return ( | |
this.tokens[this.tokenIndex].type === t1 && | |
this.tokens[this.tokenIndex + 1].type === t2 && | |
this.tokens[this.tokenIndex + 2].type === t3 && | |
this.tokens[this.tokenIndex + 3].type === t4 && | |
this.tokens[this.tokenIndex + 4].type === t5 | |
); | |
} | |
matchesContextual(contextualKeyword) { | |
return this.matchesContextualAtIndex(this.tokenIndex, contextualKeyword); | |
} | |
matchesContextIdAndLabel(type, contextId) { | |
return this.matches1(type) && this.currentToken().contextId === contextId; | |
} | |
previousWhitespaceAndComments() { | |
let whitespaceAndComments = this.code.slice( | |
this.tokenIndex > 0 ? this.tokens[this.tokenIndex - 1].end : 0, | |
this.tokenIndex < this.tokens.length | |
? this.tokens[this.tokenIndex].start | |
: this.code.length | |
); | |
if (this.isFlowEnabled) { | |
whitespaceAndComments = whitespaceAndComments.replace(/@flow/g, ""); | |
} | |
return whitespaceAndComments; | |
} | |
replaceToken(newCode) { | |
this.resultCode += this.previousWhitespaceAndComments(); | |
this.appendTokenPrefix(); | |
this.resultCode += newCode; | |
this.appendTokenSuffix(); | |
this.tokenIndex++; | |
} | |
replaceTokenTrimmingLeftWhitespace(newCode) { | |
this.resultCode += this.previousWhitespaceAndComments().replace( | |
/[^\r\n]/g, | |
"" | |
); | |
this.appendTokenPrefix(); | |
this.resultCode += newCode; | |
this.appendTokenSuffix(); | |
this.tokenIndex++; | |
} | |
removeInitialToken() { | |
this.replaceToken(""); | |
} | |
removeToken() { | |
this.replaceTokenTrimmingLeftWhitespace(""); | |
} | |
copyExpectedToken(tokenType) { | |
if (this.tokens[this.tokenIndex].type !== tokenType) { | |
throw new Error(`Expected token ${tokenType}`); | |
} | |
this.copyToken(); | |
} | |
copyToken() { | |
this.resultCode += this.previousWhitespaceAndComments(); | |
this.appendTokenPrefix(); | |
this.resultCode += this.code.slice( | |
this.tokens[this.tokenIndex].start, | |
this.tokens[this.tokenIndex].end | |
); | |
this.appendTokenSuffix(); | |
this.tokenIndex++; | |
} | |
copyTokenWithPrefix(prefix) { | |
this.resultCode += this.previousWhitespaceAndComments(); | |
this.appendTokenPrefix(); | |
this.resultCode += prefix; | |
this.resultCode += this.code.slice( | |
this.tokens[this.tokenIndex].start, | |
this.tokens[this.tokenIndex].end | |
); | |
this.appendTokenSuffix(); | |
this.tokenIndex++; | |
} | |
appendTokenPrefix() { | |
const token = this.currentToken(); | |
if (token.numNullishCoalesceStarts || token.isOptionalChainStart) { | |
token.isAsyncOperation = isAsyncOperation(this); | |
} | |
if (token.numNullishCoalesceStarts) { | |
for (let i = 0; i < token.numNullishCoalesceStarts; i++) { | |
if (token.isAsyncOperation) { | |
this.resultCode += "await "; | |
this.resultCode += this.helperManager.getHelperName( | |
"asyncNullishCoalesce" | |
); | |
} else { | |
this.resultCode += this.helperManager.getHelperName( | |
"nullishCoalesce" | |
); | |
} | |
this.resultCode += "("; | |
} | |
} | |
if (token.isOptionalChainStart) { | |
if (token.isAsyncOperation) { | |
this.resultCode += "await "; | |
} | |
if ( | |
this.tokenIndex > 0 && | |
this.tokenAtRelativeIndex(-1).type === TokenType._delete | |
) { | |
if (token.isAsyncOperation) { | |
this.resultCode += this.helperManager.getHelperName( | |
"asyncOptionalChainDelete" | |
); | |
} else { | |
this.resultCode += this.helperManager.getHelperName( | |
"optionalChainDelete" | |
); | |
} | |
} else if (token.isAsyncOperation) { | |
this.resultCode += this.helperManager.getHelperName( | |
"asyncOptionalChain" | |
); | |
} else { | |
this.resultCode += this.helperManager.getHelperName("optionalChain"); | |
} | |
this.resultCode += "(["; | |
} | |
} | |
appendTokenSuffix() { | |
const token = this.currentToken(); | |
if (token.isOptionalChainEnd) { | |
this.resultCode += "])"; | |
} | |
if (token.numNullishCoalesceEnds) { | |
for (let i = 0; i < token.numNullishCoalesceEnds; i++) { | |
this.resultCode += "))"; | |
} | |
} | |
} | |
appendCode(code) { | |
this.resultCode += code; | |
} | |
currentToken() { | |
return this.tokens[this.tokenIndex]; | |
} | |
currentTokenCode() { | |
const token = this.currentToken(); | |
return this.code.slice(token.start, token.end); | |
} | |
tokenAtRelativeIndex(relativeIndex) { | |
return this.tokens[this.tokenIndex + relativeIndex]; | |
} | |
currentIndex() { | |
return this.tokenIndex; | |
} | |
nextToken() { | |
if (this.tokenIndex === this.tokens.length) { | |
throw new Error("Unexpectedly reached end of input."); | |
} | |
this.tokenIndex++; | |
} | |
previousToken() { | |
this.tokenIndex--; | |
} | |
finish() { | |
if (this.tokenIndex !== this.tokens.length) { | |
throw new Error( | |
"Tried to finish processing tokens before reaching the end." | |
); | |
} | |
this.resultCode += this.previousWhitespaceAndComments(); | |
return this.resultCode; | |
} | |
isAtEnd() { | |
return this.tokenIndex === this.tokens.length; | |
} | |
} | |
function getClassInfo(rootTransformer, tokens, nameManager) { | |
const snapshot = tokens.snapshot(); | |
const headerInfo = processClassHeader(tokens); | |
let constructorInitializerStatements = []; | |
const instanceInitializerNames = []; | |
const staticInitializerNames = []; | |
let constructorInsertPos = null; | |
const fields = []; | |
const rangesToRemove = []; | |
const classContextId = tokens.currentToken().contextId; | |
if (classContextId == null) { | |
throw new Error("Expected non-null class context ID on class open-brace."); | |
} | |
tokens.nextToken(); | |
while (!tokens.matchesContextIdAndLabel(TokenType.braceR, classContextId)) { | |
if ( | |
tokens.matchesContextual(ContextualKeyword._constructor) && | |
!tokens.currentToken().isType | |
) { | |
({ | |
constructorInitializerStatements, | |
constructorInsertPos, | |
} = processConstructor(tokens)); | |
} else if (tokens.matches1(TokenType.semi)) { | |
rangesToRemove.push({ | |
start: tokens.currentIndex(), | |
end: tokens.currentIndex() + 1, | |
}); | |
tokens.nextToken(); | |
} else if (tokens.currentToken().isType) { | |
tokens.nextToken(); | |
} else { | |
const statementStartIndex = tokens.currentIndex(); | |
let isStatic = false; | |
while (isAccessModifier(tokens.currentToken())) { | |
if (tokens.matches1(TokenType._static)) { | |
isStatic = true; | |
} | |
tokens.nextToken(); | |
} | |
if ( | |
tokens.matchesContextual(ContextualKeyword._constructor) && | |
!tokens.currentToken().isType | |
) { | |
({ | |
constructorInitializerStatements, | |
constructorInsertPos, | |
} = processConstructor(tokens)); | |
continue; | |
} | |
const nameStartIndex = tokens.currentIndex(); | |
skipFieldName(tokens); | |
if ( | |
tokens.matches1(TokenType.lessThan) || | |
tokens.matches1(TokenType.parenL) | |
) { | |
while (tokens.currentToken().contextId !== classContextId) { | |
tokens.nextToken(); | |
} | |
while (isAccessModifier(tokens.tokenAtRelativeIndex(-1))) { | |
tokens.previousToken(); | |
} | |
continue; | |
} | |
while (tokens.currentToken().isType) { | |
tokens.nextToken(); | |
} | |
if (tokens.matches1(TokenType.eq)) { | |
const equalsIndex = tokens.currentIndex(); | |
const valueEnd = tokens.currentToken().rhsEndIndex; | |
if (valueEnd == null) { | |
throw new Error("Expected rhsEndIndex on class field assignment."); | |
} | |
tokens.nextToken(); | |
while (tokens.currentIndex() < valueEnd) { | |
rootTransformer.processToken(); | |
} | |
let initializerName; | |
if (isStatic) { | |
initializerName = nameManager.claimFreeName("__initStatic"); | |
staticInitializerNames.push(initializerName); | |
} else { | |
initializerName = nameManager.claimFreeName("__init"); | |
instanceInitializerNames.push(initializerName); | |
} | |
fields.push({ | |
initializerName, | |
equalsIndex, | |
start: nameStartIndex, | |
end: tokens.currentIndex(), | |
}); | |
} else { | |
rangesToRemove.push({ | |
start: statementStartIndex, | |
end: tokens.currentIndex(), | |
}); | |
} | |
} | |
} | |
tokens.restoreToSnapshot(snapshot); | |
return { | |
headerInfo, | |
constructorInitializerStatements, | |
instanceInitializerNames, | |
staticInitializerNames, | |
constructorInsertPos, | |
fields, | |
rangesToRemove, | |
}; | |
} | |
function processClassHeader(tokens) { | |
const classToken = tokens.currentToken(); | |
const contextId = classToken.contextId; | |
if (contextId == null) { | |
throw new Error("Expected context ID on class token."); | |
} | |
const isExpression = classToken.isExpression; | |
if (isExpression == null) { | |
throw new Error("Expected isExpression on class token."); | |
} | |
let className = null; | |
let hasSuperclass = false; | |
tokens.nextToken(); | |
if (tokens.matches1(TokenType.name)) { | |
className = tokens.identifierName(); | |
} | |
while (!tokens.matchesContextIdAndLabel(TokenType.braceL, contextId)) { | |
if (tokens.matches1(TokenType._extends) && !tokens.currentToken().isType) { | |
hasSuperclass = true; | |
} | |
tokens.nextToken(); | |
} | |
return { isExpression, className, hasSuperclass }; | |
} | |
function processConstructor(tokens) { | |
const constructorInitializerStatements = []; | |
tokens.nextToken(); | |
const constructorContextId = tokens.currentToken().contextId; | |
if (constructorContextId == null) { | |
throw new Error( | |
"Expected context ID on open-paren starting constructor params." | |
); | |
} | |
while ( | |
!tokens.matchesContextIdAndLabel(TokenType.parenR, constructorContextId) | |
) { | |
if (tokens.currentToken().contextId === constructorContextId) { | |
tokens.nextToken(); | |
if (isAccessModifier(tokens.currentToken())) { | |
tokens.nextToken(); | |
while (isAccessModifier(tokens.currentToken())) { | |
tokens.nextToken(); | |
} | |
const token = tokens.currentToken(); | |
if (token.type !== TokenType.name) { | |
throw new Error( | |
"Expected identifier after access modifiers in constructor arg." | |
); | |
} | |
const name = tokens.identifierNameForToken(token); | |
constructorInitializerStatements.push(`this.${name} = ${name}`); | |
} | |
} else { | |
tokens.nextToken(); | |
} | |
} | |
tokens.nextToken(); | |
let constructorInsertPos = tokens.currentIndex(); | |
let foundSuperCall = false; | |
while ( | |
!tokens.matchesContextIdAndLabel(TokenType.braceR, constructorContextId) | |
) { | |
if ( | |
!foundSuperCall && | |
tokens.matches2(TokenType._super, TokenType.parenL) | |
) { | |
tokens.nextToken(); | |
const superCallContextId = tokens.currentToken().contextId; | |
if (superCallContextId == null) { | |
throw new Error("Expected a context ID on the super call"); | |
} | |
while ( | |
!tokens.matchesContextIdAndLabel(TokenType.parenR, superCallContextId) | |
) { | |
tokens.nextToken(); | |
} | |
constructorInsertPos = tokens.currentIndex(); | |
foundSuperCall = true; | |
} | |
tokens.nextToken(); | |
} | |
tokens.nextToken(); | |
return { constructorInitializerStatements, constructorInsertPos }; | |
} | |
function isAccessModifier(token) { | |
return [ | |
TokenType._async, | |
TokenType._get, | |
TokenType._set, | |
TokenType.plus, | |
TokenType.minus, | |
TokenType._readonly, | |
TokenType._static, | |
TokenType._public, | |
TokenType._private, | |
TokenType._protected, | |
TokenType._abstract, | |
TokenType.star, | |
TokenType._declare, | |
].includes(token.type); | |
} | |
function skipFieldName(tokens) { | |
if (tokens.matches1(TokenType.bracketL)) { | |
const startToken = tokens.currentToken(); | |
const classContextId = startToken.contextId; | |
if (classContextId == null) { | |
throw new Error( | |
"Expected class context ID on computed name open bracket." | |
); | |
} | |
while ( | |
!tokens.matchesContextIdAndLabel(TokenType.bracketR, classContextId) | |
) { | |
tokens.nextToken(); | |
} | |
tokens.nextToken(); | |
} else { | |
tokens.nextToken(); | |
} | |
} | |
function elideImportEquals(tokens) { | |
tokens.removeInitialToken(); | |
tokens.removeToken(); | |
tokens.removeToken(); | |
tokens.removeToken(); | |
if (tokens.matches1(TokenType.parenL)) { | |
tokens.removeToken(); | |
tokens.removeToken(); | |
tokens.removeToken(); | |
} else { | |
while (tokens.matches1(TokenType.dot)) { | |
tokens.removeToken(); | |
tokens.removeToken(); | |
} | |
} | |
} | |
const EMPTY_DECLARATION_INFO = { | |
typeDeclarations: new Set(), | |
valueDeclarations: new Set(), | |
}; | |
function getDeclarationInfo(tokens) { | |
const typeDeclarations = new Set(); | |
const valueDeclarations = new Set(); | |
for (let i = 0; i < tokens.tokens.length; i++) { | |
const token = tokens.tokens[i]; | |
if (token.type === TokenType.name && isTopLevelDeclaration(token)) { | |
if (token.isType) { | |
typeDeclarations.add(tokens.identifierNameForToken(token)); | |
} else { | |
valueDeclarations.add(tokens.identifierNameForToken(token)); | |
} | |
} | |
} | |
return { typeDeclarations, valueDeclarations }; | |
} | |
function shouldElideDefaultExport( | |
isTypeScriptTransformEnabled, | |
tokens, | |
declarationInfo | |
) { | |
if (!isTypeScriptTransformEnabled) { | |
return false; | |
} | |
const exportToken = tokens.currentToken(); | |
if (exportToken.rhsEndIndex == null) { | |
throw new Error("Expected non-null rhsEndIndex on export token."); | |
} | |
const numTokens = exportToken.rhsEndIndex - tokens.currentIndex(); | |
if ( | |
numTokens !== 3 && | |
!( | |
numTokens === 4 && | |
tokens.matches1AtIndex(exportToken.rhsEndIndex - 1, TokenType.semi) | |
) | |
) { | |
return false; | |
} | |
const identifierToken = tokens.tokenAtRelativeIndex(2); | |
if (identifierToken.type !== TokenType.name) { | |
return false; | |
} | |
const exportedName = tokens.identifierNameForToken(identifierToken); | |
return ( | |
declarationInfo.typeDeclarations.has(exportedName) && | |
!declarationInfo.valueDeclarations.has(exportedName) | |
); | |
} | |
class CJSImportTransformer extends Transformer { | |
__init() { | |
this.hadExport = false; | |
} | |
__init2() { | |
this.hadNamedExport = false; | |
} | |
__init3() { | |
this.hadDefaultExport = false; | |
} | |
constructor( | |
rootTransformer, | |
tokens, | |
importProcessor, | |
nameManager, | |
reactHotLoaderTransformer, | |
enableLegacyBabel5ModuleInterop, | |
isTypeScriptTransformEnabled | |
) { | |
super(); | |
this.rootTransformer = rootTransformer; | |
this.tokens = tokens; | |
this.importProcessor = importProcessor; | |
this.nameManager = nameManager; | |
this.reactHotLoaderTransformer = reactHotLoaderTransformer; | |
this.enableLegacyBabel5ModuleInterop = enableLegacyBabel5ModuleInterop; | |
this.isTypeScriptTransformEnabled = isTypeScriptTransformEnabled; | |
CJSImportTransformer.prototype.__init.call(this); | |
CJSImportTransformer.prototype.__init2.call(this); | |
CJSImportTransformer.prototype.__init3.call(this); | |
this.declarationInfo = isTypeScriptTransformEnabled | |
? getDeclarationInfo(tokens) | |
: EMPTY_DECLARATION_INFO; | |
} | |
getPrefixCode() { | |
let prefix = ""; | |
if (this.hadExport) { | |
prefix += 'Object.defineProperty(exports, "__esModule", {value: true});'; | |
} | |
return prefix; | |
} | |
getSuffixCode() { | |
if ( | |
this.enableLegacyBabel5ModuleInterop && | |
this.hadDefaultExport && | |
!this.hadNamedExport | |
) { | |
return "\nmodule.exports = exports.default;\n"; | |
} | |
return ""; | |
} | |
process() { | |
if (this.tokens.matches3(TokenType._import, TokenType.name, TokenType.eq)) { | |
return this.processImportEquals(); | |
} | |
if (this.tokens.matches1(TokenType._import)) { | |
this.processImport(); | |
return true; | |
} | |
if (this.tokens.matches2(TokenType._export, TokenType.eq)) { | |
this.tokens.replaceToken("module.exports"); | |
return true; | |
} | |
if ( | |
this.tokens.matches1(TokenType._export) && | |
!this.tokens.currentToken().isType | |
) { | |
this.hadExport = true; | |
return this.processExport(); | |
} | |
if (this.tokens.matches2(TokenType.name, TokenType.postIncDec)) { | |
if (this.processPostIncDec()) { | |
return true; | |
} | |
} | |
if ( | |
this.tokens.matches1(TokenType.name) || | |
this.tokens.matches1(TokenType.jsxName) | |
) { | |
return this.processIdentifier(); | |
} | |
if (this.tokens.matches1(TokenType.eq)) { | |
return this.processAssignment(); | |
} | |
if (this.tokens.matches1(TokenType.assign)) { | |
return this.processComplexAssignment(); | |
} | |
if (this.tokens.matches1(TokenType.preIncDec)) { | |
return this.processPreIncDec(); | |
} | |
return false; | |
} | |
processImportEquals() { | |
const importName = this.tokens.identifierNameAtIndex( | |
this.tokens.currentIndex() + 1 | |
); | |
if (this.importProcessor.isTypeName(importName)) { | |
elideImportEquals(this.tokens); | |
} else { | |
this.tokens.replaceToken("const"); | |
} | |
return true; | |
} | |
processImport() { | |
if (this.tokens.matches2(TokenType._import, TokenType.parenL)) { | |
this.tokens.replaceToken("Promise.resolve().then(() => require"); | |
const contextId = this.tokens.currentToken().contextId; | |
if (contextId == null) { | |
throw new Error("Expected context ID on dynamic import invocation."); | |
} | |
this.tokens.copyToken(); | |
while ( | |
!this.tokens.matchesContextIdAndLabel(TokenType.parenR, contextId) | |
) { | |
this.rootTransformer.processToken(); | |
} | |
this.tokens.replaceToken("))"); | |
return; | |
} | |
const wasOnlyTypes = this.removeImportAndDetectIfType(); | |
if (wasOnlyTypes) { | |
this.tokens.removeToken(); | |
} else { | |
const path = this.tokens.stringValue(); | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
this.importProcessor.claimImportCode(path) | |
); | |
this.tokens.appendCode(this.importProcessor.claimImportCode(path)); | |
} | |
if (this.tokens.matches1(TokenType.semi)) { | |
this.tokens.removeToken(); | |
} | |
} | |
removeImportAndDetectIfType() { | |
this.tokens.removeInitialToken(); | |
if ( | |
this.tokens.matchesContextual(ContextualKeyword._type) && | |
!this.tokens.matches1AtIndex( | |
this.tokens.currentIndex() + 1, | |
TokenType.comma | |
) && | |
!this.tokens.matchesContextualAtIndex( | |
this.tokens.currentIndex() + 1, | |
ContextualKeyword._from | |
) | |
) { | |
this.removeRemainingImport(); | |
return true; | |
} | |
if ( | |
this.tokens.matches1(TokenType.name) || | |
this.tokens.matches1(TokenType.star) | |
) { | |
this.removeRemainingImport(); | |
return false; | |
} | |
if (this.tokens.matches1(TokenType.string)) { | |
return false; | |
} | |
let foundNonType = false; | |
while (!this.tokens.matches1(TokenType.string)) { | |
if ( | |
(!foundNonType && this.tokens.matches1(TokenType.braceL)) || | |
this.tokens.matches1(TokenType.comma) | |
) { | |
this.tokens.removeToken(); | |
if ( | |
this.tokens.matches2(TokenType.name, TokenType.comma) || | |
this.tokens.matches2(TokenType.name, TokenType.braceR) || | |
this.tokens.matches4( | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.comma | |
) || | |
this.tokens.matches4( | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.braceR | |
) | |
) { | |
foundNonType = true; | |
} | |
} | |
this.tokens.removeToken(); | |
} | |
return !foundNonType; | |
} | |
removeRemainingImport() { | |
while (!this.tokens.matches1(TokenType.string)) { | |
this.tokens.removeToken(); | |
} | |
} | |
processIdentifier() { | |
const token = this.tokens.currentToken(); | |
if (token.shadowsGlobal) { | |
return false; | |
} | |
if (token.identifierRole === IdentifierRole.ObjectShorthand) { | |
return this.processObjectShorthand(); | |
} | |
if (token.identifierRole !== IdentifierRole.Access) { | |
return false; | |
} | |
const replacement = this.importProcessor.getIdentifierReplacement( | |
this.tokens.identifierNameForToken(token) | |
); | |
if (!replacement) { | |
return false; | |
} | |
let possibleOpenParenIndex = this.tokens.currentIndex() + 1; | |
while ( | |
possibleOpenParenIndex < this.tokens.tokens.length && | |
this.tokens.tokens[possibleOpenParenIndex].type === TokenType.parenR | |
) { | |
possibleOpenParenIndex++; | |
} | |
if (this.tokens.tokens[possibleOpenParenIndex].type === TokenType.parenL) { | |
if ( | |
this.tokens.tokenAtRelativeIndex(1).type === TokenType.parenL && | |
this.tokens.tokenAtRelativeIndex(-1).type !== TokenType._new | |
) { | |
this.tokens.replaceToken(`${replacement}.call(void 0, `); | |
this.tokens.removeToken(); | |
this.rootTransformer.processBalancedCode(); | |
this.tokens.copyExpectedToken(TokenType.parenR); | |
} else { | |
this.tokens.replaceToken(`(0, ${replacement})`); | |
} | |
} else { | |
this.tokens.replaceToken(replacement); | |
} | |
return true; | |
} | |
processObjectShorthand() { | |
const identifier = this.tokens.identifierName(); | |
const replacement = this.importProcessor.getIdentifierReplacement( | |
identifier | |
); | |
if (!replacement) { | |
return false; | |
} | |
this.tokens.replaceToken(`${identifier}: ${replacement}`); | |
return true; | |
} | |
processExport() { | |
if ( | |
this.tokens.matches2(TokenType._export, TokenType._enum) || | |
this.tokens.matches3(TokenType._export, TokenType._const, TokenType._enum) | |
) { | |
return false; | |
} | |
if (this.tokens.matches2(TokenType._export, TokenType._default)) { | |
this.processExportDefault(); | |
this.hadDefaultExport = true; | |
return true; | |
} | |
this.hadNamedExport = true; | |
if ( | |
this.tokens.matches2(TokenType._export, TokenType._var) || | |
this.tokens.matches2(TokenType._export, TokenType._let) || | |
this.tokens.matches2(TokenType._export, TokenType._const) | |
) { | |
this.processExportVar(); | |
return true; | |
} else if ( | |
this.tokens.matches2(TokenType._export, TokenType._function) || | |
this.tokens.matches3( | |
TokenType._export, | |
TokenType.name, | |
TokenType._function | |
) | |
) { | |
this.processExportFunction(); | |
return true; | |
} else if ( | |
this.tokens.matches2(TokenType._export, TokenType._class) || | |
this.tokens.matches3( | |
TokenType._export, | |
TokenType._abstract, | |
TokenType._class | |
) | |
) { | |
this.processExportClass(); | |
return true; | |
} else if (this.tokens.matches2(TokenType._export, TokenType.braceL)) { | |
this.processExportBindings(); | |
return true; | |
} else if (this.tokens.matches2(TokenType._export, TokenType.star)) { | |
this.processExportStar(); | |
return true; | |
} else if ( | |
this.tokens.matches3( | |
TokenType._export, | |
TokenType.name, | |
TokenType.braceL | |
) && | |
this.tokens.matchesContextualAtIndex( | |
this.tokens.currentIndex() + 1, | |
ContextualKeyword._type | |
) | |
) { | |
this.tokens.removeInitialToken(); | |
while (!this.tokens.matches1(TokenType.braceR)) { | |
this.tokens.removeToken(); | |
} | |
this.tokens.removeToken(); | |
if ( | |
this.tokens.matchesContextual(ContextualKeyword._from) && | |
this.tokens.matches1AtIndex( | |
this.tokens.currentIndex() + 1, | |
TokenType.string | |
) | |
) { | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
} | |
return true; | |
} else { | |
throw new Error("Unrecognized export syntax."); | |
} | |
} | |
processAssignment() { | |
const index = this.tokens.currentIndex(); | |
const identifierToken = this.tokens.tokens[index - 1]; | |
if (identifierToken.isType || identifierToken.type !== TokenType.name) { | |
return false; | |
} | |
if (identifierToken.shadowsGlobal) { | |
return false; | |
} | |
if (index >= 2 && this.tokens.matches1AtIndex(index - 2, TokenType.dot)) { | |
return false; | |
} | |
if ( | |
index >= 2 && | |
[TokenType._var, TokenType._let, TokenType._const].includes( | |
this.tokens.tokens[index - 2].type | |
) | |
) { | |
return false; | |
} | |
const assignmentSnippet = this.importProcessor.resolveExportBinding( | |
this.tokens.identifierNameForToken(identifierToken) | |
); | |
if (!assignmentSnippet) { | |
return false; | |
} | |
this.tokens.copyToken(); | |
this.tokens.appendCode(` ${assignmentSnippet} =`); | |
return true; | |
} | |
processComplexAssignment() { | |
const index = this.tokens.currentIndex(); | |
const identifierToken = this.tokens.tokens[index - 1]; | |
if (identifierToken.type !== TokenType.name) { | |
return false; | |
} | |
if (identifierToken.shadowsGlobal) { | |
return false; | |
} | |
if (index >= 2 && this.tokens.matches1AtIndex(index - 2, TokenType.dot)) { | |
return false; | |
} | |
const assignmentSnippet = this.importProcessor.resolveExportBinding( | |
this.tokens.identifierNameForToken(identifierToken) | |
); | |
if (!assignmentSnippet) { | |
return false; | |
} | |
this.tokens.appendCode(` = ${assignmentSnippet}`); | |
this.tokens.copyToken(); | |
return true; | |
} | |
processPreIncDec() { | |
const index = this.tokens.currentIndex(); | |
const identifierToken = this.tokens.tokens[index + 1]; | |
if (identifierToken.type !== TokenType.name) { | |
return false; | |
} | |
if (identifierToken.shadowsGlobal) { | |
return false; | |
} | |
if ( | |
index + 2 < this.tokens.tokens.length && | |
(this.tokens.matches1AtIndex(index + 2, TokenType.dot) || | |
this.tokens.matches1AtIndex(index + 2, TokenType.bracketL) || | |
this.tokens.matches1AtIndex(index + 2, TokenType.parenL)) | |
) { | |
return false; | |
} | |
const identifierName = this.tokens.identifierNameForToken(identifierToken); | |
const assignmentSnippet = this.importProcessor.resolveExportBinding( | |
identifierName | |
); | |
if (!assignmentSnippet) { | |
return false; | |
} | |
this.tokens.appendCode(`${assignmentSnippet} = `); | |
this.tokens.copyToken(); | |
return true; | |
} | |
processPostIncDec() { | |
const index = this.tokens.currentIndex(); | |
const identifierToken = this.tokens.tokens[index]; | |
const operatorToken = this.tokens.tokens[index + 1]; | |
if (identifierToken.type !== TokenType.name) { | |
return false; | |
} | |
if (identifierToken.shadowsGlobal) { | |
return false; | |
} | |
if (index >= 1 && this.tokens.matches1AtIndex(index - 1, TokenType.dot)) { | |
return false; | |
} | |
const identifierName = this.tokens.identifierNameForToken(identifierToken); | |
const assignmentSnippet = this.importProcessor.resolveExportBinding( | |
identifierName | |
); | |
if (!assignmentSnippet) { | |
return false; | |
} | |
const operatorCode = this.tokens.rawCodeForToken(operatorToken); | |
const base = | |
this.importProcessor.getIdentifierReplacement(identifierName) || | |
identifierName; | |
if (operatorCode === "++") { | |
this.tokens.replaceToken( | |
`(${base} = ${assignmentSnippet} = ${base} + 1, ${base} - 1)` | |
); | |
} else if (operatorCode === "--") { | |
this.tokens.replaceToken( | |
`(${base} = ${assignmentSnippet} = ${base} - 1, ${base} + 1)` | |
); | |
} else { | |
throw new Error(`Unexpected operator: ${operatorCode}`); | |
} | |
this.tokens.removeToken(); | |
return true; | |
} | |
processExportDefault() { | |
if ( | |
this.tokens.matches4( | |
TokenType._export, | |
TokenType._default, | |
TokenType._function, | |
TokenType.name | |
) || | |
this.tokens.matches5( | |
TokenType._export, | |
TokenType._default, | |
TokenType.name, | |
TokenType._function, | |
TokenType.name | |
) | |
) { | |
this.tokens.removeInitialToken(); | |
this.tokens.removeToken(); | |
const name = this.processNamedFunction(); | |
this.tokens.appendCode(` exports.default = ${name};`); | |
} else if ( | |
this.tokens.matches4( | |
TokenType._export, | |
TokenType._default, | |
TokenType._class, | |
TokenType.name | |
) || | |
this.tokens.matches5( | |
TokenType._export, | |
TokenType._default, | |
TokenType._abstract, | |
TokenType._class, | |
TokenType.name | |
) | |
) { | |
this.tokens.removeInitialToken(); | |
this.tokens.removeToken(); | |
if (this.tokens.matches1(TokenType._abstract)) { | |
this.tokens.removeToken(); | |
} | |
const name = this.rootTransformer.processNamedClass(); | |
this.tokens.appendCode(` exports.default = ${name};`); | |
} else if ( | |
this.tokens.matches3(TokenType._export, TokenType._default, TokenType.at) | |
) { | |
throw new Error( | |
"Export default statements with decorators are not yet supported." | |
); | |
} else if ( | |
shouldElideDefaultExport( | |
this.isTypeScriptTransformEnabled, | |
this.tokens, | |
this.declarationInfo | |
) | |
) { | |
this.tokens.removeInitialToken(); | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
} else if (this.reactHotLoaderTransformer) { | |
const defaultVarName = this.nameManager.claimFreeName("_default"); | |
this.tokens.replaceToken(`let ${defaultVarName}; exports.`); | |
this.tokens.copyToken(); | |
this.tokens.appendCode(` = ${defaultVarName} =`); | |
this.reactHotLoaderTransformer.setExtractedDefaultExportName( | |
defaultVarName | |
); | |
} else { | |
this.tokens.replaceToken("exports."); | |
this.tokens.copyToken(); | |
this.tokens.appendCode(" ="); | |
} | |
} | |
processExportVar() { | |
if (this.isSimpleExportVar()) { | |
this.processSimpleExportVar(); | |
} else { | |
this.processComplexExportVar(); | |
} | |
} | |
isSimpleExportVar() { | |
let tokenIndex = this.tokens.currentIndex(); | |
tokenIndex++; | |
tokenIndex++; | |
if (!this.tokens.matches1AtIndex(tokenIndex, TokenType.name)) { | |
return false; | |
} | |
tokenIndex++; | |
while ( | |
tokenIndex < this.tokens.tokens.length && | |
this.tokens.tokens[tokenIndex].isType | |
) { | |
tokenIndex++; | |
} | |
if (!this.tokens.matches1AtIndex(tokenIndex, TokenType.eq)) { | |
return false; | |
} | |
return true; | |
} | |
processSimpleExportVar() { | |
this.tokens.removeInitialToken(); | |
this.tokens.copyToken(); | |
const varName = this.tokens.identifierName(); | |
while (!this.tokens.matches1(TokenType.eq)) { | |
this.rootTransformer.processToken(); | |
} | |
const endIndex = this.tokens.currentToken().rhsEndIndex; | |
if (endIndex == null) { | |
throw new Error("Expected = token with an end index."); | |
} | |
while (this.tokens.currentIndex() < endIndex) { | |
this.rootTransformer.processToken(); | |
} | |
this.tokens.appendCode(`; exports.${varName} = ${varName}`); | |
} | |
processComplexExportVar() { | |
this.tokens.removeInitialToken(); | |
this.tokens.removeToken(); | |
const needsParens = this.tokens.matches1(TokenType.braceL); | |
if (needsParens) { | |
this.tokens.appendCode("("); | |
} | |
let depth = 0; | |
while (true) { | |
if ( | |
this.tokens.matches1(TokenType.braceL) || | |
this.tokens.matches1(TokenType.dollarBraceL) || | |
this.tokens.matches1(TokenType.bracketL) | |
) { | |
depth++; | |
this.tokens.copyToken(); | |
} else if ( | |
this.tokens.matches1(TokenType.braceR) || | |
this.tokens.matches1(TokenType.bracketR) | |
) { | |
depth--; | |
this.tokens.copyToken(); | |
} else if ( | |
depth === 0 && | |
!this.tokens.matches1(TokenType.name) && | |
!this.tokens.currentToken().isType | |
) { | |
break; | |
} else if (this.tokens.matches1(TokenType.eq)) { | |
const endIndex = this.tokens.currentToken().rhsEndIndex; | |
if (endIndex == null) { | |
throw new Error("Expected = token with an end index."); | |
} | |
while (this.tokens.currentIndex() < endIndex) { | |
this.rootTransformer.processToken(); | |
} | |
} else { | |
const token = this.tokens.currentToken(); | |
if (isDeclaration(token)) { | |
const name = this.tokens.identifierName(); | |
let replacement = this.importProcessor.getIdentifierReplacement(name); | |
if (replacement === null) { | |
throw new Error( | |
`Expected a replacement for ${name} in \`export var\` syntax.` | |
); | |
} | |
if (isObjectShorthandDeclaration(token)) { | |
replacement = `${name}: ${replacement}`; | |
} | |
this.tokens.replaceToken(replacement); | |
} else { | |
this.rootTransformer.processToken(); | |
} | |
} | |
} | |
if (needsParens) { | |
const endIndex = this.tokens.currentToken().rhsEndIndex; | |
if (endIndex == null) { | |
throw new Error("Expected = token with an end index."); | |
} | |
while (this.tokens.currentIndex() < endIndex) { | |
this.rootTransformer.processToken(); | |
} | |
this.tokens.appendCode(")"); | |
} | |
} | |
processExportFunction() { | |
this.tokens.replaceToken(""); | |
const name = this.processNamedFunction(); | |
this.tokens.appendCode(` exports.${name} = ${name};`); | |
} | |
processNamedFunction() { | |
if (this.tokens.matches1(TokenType._function)) { | |
this.tokens.copyToken(); | |
} else if (this.tokens.matches2(TokenType.name, TokenType._function)) { | |
if (!this.tokens.matchesContextual(ContextualKeyword._async)) { | |
throw new Error("Expected async keyword in function export."); | |
} | |
this.tokens.copyToken(); | |
this.tokens.copyToken(); | |
} | |
if (this.tokens.matches1(TokenType.star)) { | |
this.tokens.copyToken(); | |
} | |
if (!this.tokens.matches1(TokenType.name)) { | |
throw new Error("Expected identifier for exported function name."); | |
} | |
const name = this.tokens.identifierName(); | |
this.tokens.copyToken(); | |
if (this.tokens.currentToken().isType) { | |
this.tokens.removeInitialToken(); | |
while (this.tokens.currentToken().isType) { | |
this.tokens.removeToken(); | |
} | |
} | |
this.tokens.copyExpectedToken(TokenType.parenL); | |
this.rootTransformer.processBalancedCode(); | |
this.tokens.copyExpectedToken(TokenType.parenR); | |
this.rootTransformer.processPossibleTypeRange(); | |
this.tokens.copyExpectedToken(TokenType.braceL); | |
this.rootTransformer.processBalancedCode(); | |
this.tokens.copyExpectedToken(TokenType.braceR); | |
return name; | |
} | |
processExportClass() { | |
this.tokens.removeInitialToken(); | |
if (this.tokens.matches1(TokenType._abstract)) { | |
this.tokens.removeToken(); | |
} | |
const name = this.rootTransformer.processNamedClass(); | |
this.tokens.appendCode(` exports.${name} = ${name};`); | |
} | |
processExportBindings() { | |
this.tokens.removeInitialToken(); | |
this.tokens.removeToken(); | |
const exportStatements = []; | |
while (true) { | |
if (this.tokens.matches1(TokenType.braceR)) { | |
this.tokens.removeToken(); | |
break; | |
} | |
const localName = this.tokens.identifierName(); | |
let exportedName; | |
this.tokens.removeToken(); | |
if (this.tokens.matchesContextual(ContextualKeyword._as)) { | |
this.tokens.removeToken(); | |
exportedName = this.tokens.identifierName(); | |
this.tokens.removeToken(); | |
} else { | |
exportedName = localName; | |
} | |
if (!this.shouldElideExportedIdentifier(localName)) { | |
const newLocalName = this.importProcessor.getIdentifierReplacement( | |
localName | |
); | |
exportStatements.push( | |
`exports.${exportedName} = ${newLocalName || localName};` | |
); | |
} | |
if (this.tokens.matches1(TokenType.braceR)) { | |
this.tokens.removeToken(); | |
break; | |
} | |
if (this.tokens.matches2(TokenType.comma, TokenType.braceR)) { | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
break; | |
} else if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} else { | |
throw new Error( | |
`Unexpected token: ${JSON.stringify(this.tokens.currentToken())}` | |
); | |
} | |
} | |
if (this.tokens.matchesContextual(ContextualKeyword._from)) { | |
this.tokens.removeToken(); | |
const path = this.tokens.stringValue(); | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
this.importProcessor.claimImportCode(path) | |
); | |
} else { | |
this.tokens.appendCode(exportStatements.join(" ")); | |
} | |
if (this.tokens.matches1(TokenType.semi)) { | |
this.tokens.removeToken(); | |
} | |
} | |
processExportStar() { | |
this.tokens.removeInitialToken(); | |
while (!this.tokens.matches1(TokenType.string)) { | |
this.tokens.removeToken(); | |
} | |
const path = this.tokens.stringValue(); | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
this.importProcessor.claimImportCode(path) | |
); | |
if (this.tokens.matches1(TokenType.semi)) { | |
this.tokens.removeToken(); | |
} | |
} | |
shouldElideExportedIdentifier(name) { | |
return ( | |
this.isTypeScriptTransformEnabled && | |
!this.declarationInfo.valueDeclarations.has(name) | |
); | |
} | |
} | |
class ESMImportTransformer extends Transformer { | |
constructor( | |
tokens, | |
nameManager, | |
reactHotLoaderTransformer, | |
isTypeScriptTransformEnabled, | |
options | |
) { | |
super(); | |
this.tokens = tokens; | |
this.nameManager = nameManager; | |
this.reactHotLoaderTransformer = reactHotLoaderTransformer; | |
this.isTypeScriptTransformEnabled = isTypeScriptTransformEnabled; | |
this.nonTypeIdentifiers = isTypeScriptTransformEnabled | |
? getNonTypeIdentifiers(tokens, options) | |
: new Set(); | |
this.declarationInfo = isTypeScriptTransformEnabled | |
? getDeclarationInfo(tokens) | |
: EMPTY_DECLARATION_INFO; | |
} | |
process() { | |
if (this.tokens.matches3(TokenType._import, TokenType.name, TokenType.eq)) { | |
return this.processImportEquals(); | |
} | |
if (this.tokens.matches2(TokenType._export, TokenType.eq)) { | |
this.tokens.replaceToken("module.exports"); | |
return true; | |
} | |
if (this.tokens.matches1(TokenType._import)) { | |
return this.processImport(); | |
} | |
if (this.tokens.matches2(TokenType._export, TokenType._default)) { | |
return this.processExportDefault(); | |
} | |
if (this.tokens.matches2(TokenType._export, TokenType.braceL)) { | |
return this.processNamedExports(); | |
} | |
if ( | |
this.tokens.matches3( | |
TokenType._export, | |
TokenType.name, | |
TokenType.braceL | |
) && | |
this.tokens.matchesContextualAtIndex( | |
this.tokens.currentIndex() + 1, | |
ContextualKeyword._type | |
) | |
) { | |
this.tokens.removeInitialToken(); | |
while (!this.tokens.matches1(TokenType.braceR)) { | |
this.tokens.removeToken(); | |
} | |
this.tokens.removeToken(); | |
if ( | |
this.tokens.matchesContextual(ContextualKeyword._from) && | |
this.tokens.matches1AtIndex( | |
this.tokens.currentIndex() + 1, | |
TokenType.string | |
) | |
) { | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
} | |
return true; | |
} | |
return false; | |
} | |
processImportEquals() { | |
const importName = this.tokens.identifierNameAtIndex( | |
this.tokens.currentIndex() + 1 | |
); | |
if (this.isTypeName(importName)) { | |
elideImportEquals(this.tokens); | |
} else { | |
this.tokens.replaceToken("const"); | |
} | |
return true; | |
} | |
processImport() { | |
if (this.tokens.matches2(TokenType._import, TokenType.parenL)) { | |
return false; | |
} | |
const snapshot = this.tokens.snapshot(); | |
const allImportsRemoved = this.removeImportTypeBindings(); | |
if (allImportsRemoved) { | |
this.tokens.restoreToSnapshot(snapshot); | |
while (!this.tokens.matches1(TokenType.string)) { | |
this.tokens.removeToken(); | |
} | |
this.tokens.removeToken(); | |
if (this.tokens.matches1(TokenType.semi)) { | |
this.tokens.removeToken(); | |
} | |
} | |
return true; | |
} | |
removeImportTypeBindings() { | |
this.tokens.copyExpectedToken(TokenType._import); | |
if ( | |
this.tokens.matchesContextual(ContextualKeyword._type) && | |
!this.tokens.matches1AtIndex( | |
this.tokens.currentIndex() + 1, | |
TokenType.comma | |
) && | |
!this.tokens.matchesContextualAtIndex( | |
this.tokens.currentIndex() + 1, | |
ContextualKeyword._from | |
) | |
) { | |
return true; | |
} | |
if (this.tokens.matches1(TokenType.string)) { | |
this.tokens.copyToken(); | |
return false; | |
} | |
let foundNonTypeImport = false; | |
if (this.tokens.matches1(TokenType.name)) { | |
if (this.isTypeName(this.tokens.identifierName())) { | |
this.tokens.removeToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} | |
} else { | |
foundNonTypeImport = true; | |
this.tokens.copyToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.copyToken(); | |
} | |
} | |
} | |
if (this.tokens.matches1(TokenType.star)) { | |
if ( | |
this.isTypeName( | |
this.tokens.identifierNameAtIndex(this.tokens.currentIndex() + 2) | |
) | |
) { | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
} else { | |
foundNonTypeImport = true; | |
this.tokens.copyExpectedToken(TokenType.star); | |
this.tokens.copyExpectedToken(TokenType.name); | |
this.tokens.copyExpectedToken(TokenType.name); | |
} | |
} else if (this.tokens.matches1(TokenType.braceL)) { | |
this.tokens.copyToken(); | |
while (!this.tokens.matches1(TokenType.braceR)) { | |
if ( | |
this.tokens.matches3( | |
TokenType.name, | |
TokenType.name, | |
TokenType.comma | |
) || | |
this.tokens.matches3(TokenType.name, TokenType.name, TokenType.braceR) | |
) { | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} | |
} else if ( | |
this.tokens.matches5( | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.comma | |
) || | |
this.tokens.matches5( | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.braceR | |
) | |
) { | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} | |
} else if ( | |
this.tokens.matches2(TokenType.name, TokenType.comma) || | |
this.tokens.matches2(TokenType.name, TokenType.braceR) | |
) { | |
if (this.isTypeName(this.tokens.identifierName())) { | |
this.tokens.removeToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} | |
} else { | |
foundNonTypeImport = true; | |
this.tokens.copyToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.copyToken(); | |
} | |
} | |
} else if ( | |
this.tokens.matches4( | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.comma | |
) || | |
this.tokens.matches4( | |
TokenType.name, | |
TokenType.name, | |
TokenType.name, | |
TokenType.braceR | |
) | |
) { | |
if ( | |
this.isTypeName( | |
this.tokens.identifierNameAtIndex(this.tokens.currentIndex() + 2) | |
) | |
) { | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} | |
} else { | |
foundNonTypeImport = true; | |
this.tokens.copyToken(); | |
this.tokens.copyToken(); | |
this.tokens.copyToken(); | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.copyToken(); | |
} | |
} | |
} else { | |
throw new Error("Unexpected import form."); | |
} | |
} | |
this.tokens.copyExpectedToken(TokenType.braceR); | |
} | |
return !foundNonTypeImport; | |
} | |
isTypeName(name) { | |
return ( | |
this.isTypeScriptTransformEnabled && !this.nonTypeIdentifiers.has(name) | |
); | |
} | |
processExportDefault() { | |
if ( | |
shouldElideDefaultExport( | |
this.isTypeScriptTransformEnabled, | |
this.tokens, | |
this.declarationInfo | |
) | |
) { | |
this.tokens.removeInitialToken(); | |
this.tokens.removeToken(); | |
this.tokens.removeToken(); | |
return true; | |
} | |
const alreadyHasName = | |
this.tokens.matches4( | |
TokenType._export, | |
TokenType._default, | |
TokenType._function, | |
TokenType.name | |
) || | |
this.tokens.matches5( | |
TokenType._export, | |
TokenType._default, | |
TokenType.name, | |
TokenType._function, | |
TokenType.name | |
) || | |
this.tokens.matches4( | |
TokenType._export, | |
TokenType._default, | |
TokenType._class, | |
TokenType.name | |
) || | |
this.tokens.matches5( | |
TokenType._export, | |
TokenType._default, | |
TokenType._abstract, | |
TokenType._class, | |
TokenType.name | |
); | |
if (!alreadyHasName && this.reactHotLoaderTransformer) { | |
const defaultVarName = this.nameManager.claimFreeName("_default"); | |
this.tokens.replaceToken(`let ${defaultVarName}; export`); | |
this.tokens.copyToken(); | |
this.tokens.appendCode(` ${defaultVarName} =`); | |
this.reactHotLoaderTransformer.setExtractedDefaultExportName( | |
defaultVarName | |
); | |
return true; | |
} | |
return false; | |
} | |
processNamedExports() { | |
if (!this.isTypeScriptTransformEnabled) { | |
return false; | |
} | |
this.tokens.copyExpectedToken(TokenType._export); | |
this.tokens.copyExpectedToken(TokenType.braceL); | |
while (!this.tokens.matches1(TokenType.braceR)) { | |
if (!this.tokens.matches1(TokenType.name)) { | |
throw new Error("Expected identifier at the start of named export."); | |
} | |
if (this.shouldElideExportedName(this.tokens.identifierName())) { | |
while ( | |
!this.tokens.matches1(TokenType.comma) && | |
!this.tokens.matches1(TokenType.braceR) && | |
!this.tokens.isAtEnd() | |
) { | |
this.tokens.removeToken(); | |
} | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} | |
} else { | |
while ( | |
!this.tokens.matches1(TokenType.comma) && | |
!this.tokens.matches1(TokenType.braceR) && | |
!this.tokens.isAtEnd() | |
) { | |
this.tokens.copyToken(); | |
} | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.copyToken(); | |
} | |
} | |
} | |
this.tokens.copyExpectedToken(TokenType.braceR); | |
return true; | |
} | |
shouldElideExportedName(name) { | |
return ( | |
this.isTypeScriptTransformEnabled && | |
this.declarationInfo.typeDeclarations.has(name) && | |
!this.declarationInfo.valueDeclarations.has(name) | |
); | |
} | |
} | |
class FlowTransformer extends Transformer { | |
constructor(rootTransformer, tokens) { | |
super(); | |
this.rootTransformer = rootTransformer; | |
this.tokens = tokens; | |
} | |
process() { | |
return ( | |
this.rootTransformer.processPossibleArrowParamEnd() || | |
this.rootTransformer.processPossibleAsyncArrowWithTypeParams() || | |
this.rootTransformer.processPossibleTypeRange() | |
); | |
} | |
} | |
class NumericSeparatorTransformer extends Transformer { | |
constructor(tokens) { | |
super(); | |
this.tokens = tokens; | |
} | |
process() { | |
if (this.tokens.matches1(TokenType.num)) { | |
const code = this.tokens.currentTokenCode(); | |
if (code.includes("_")) { | |
this.tokens.replaceToken(code.replace(/_/g, "")); | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
class OptionalCatchBindingTransformer extends Transformer { | |
constructor(tokens, nameManager) { | |
super(); | |
this.tokens = tokens; | |
this.nameManager = nameManager; | |
} | |
process() { | |
if (this.tokens.matches2(TokenType._catch, TokenType.braceL)) { | |
this.tokens.copyToken(); | |
this.tokens.appendCode(` (${this.nameManager.claimFreeName("e")})`); | |
return true; | |
} | |
return false; | |
} | |
} | |
class OptionalChainingNullishTransformer extends Transformer { | |
constructor(tokens, nameManager) { | |
super(); | |
this.tokens = tokens; | |
this.nameManager = nameManager; | |
} | |
process() { | |
if (this.tokens.matches1(TokenType.nullishCoalescing)) { | |
const token2 = this.tokens.currentToken(); | |
if (this.tokens.tokens[token2.nullishStartIndex].isAsyncOperation) { | |
this.tokens.replaceTokenTrimmingLeftWhitespace(", async () => ("); | |
} else { | |
this.tokens.replaceTokenTrimmingLeftWhitespace(", () => ("); | |
} | |
return true; | |
} | |
if (this.tokens.matches1(TokenType._delete)) { | |
const nextToken2 = this.tokens.tokenAtRelativeIndex(1); | |
if (nextToken2.isOptionalChainStart) { | |
this.tokens.removeInitialToken(); | |
return true; | |
} | |
} | |
const token = this.tokens.currentToken(); | |
const chainStart = token.subscriptStartIndex; | |
if ( | |
chainStart != null && | |
this.tokens.tokens[chainStart].isOptionalChainStart && | |
this.tokens.tokenAtRelativeIndex(-1).type !== TokenType._super | |
) { | |
const param = this.nameManager.claimFreeName("_"); | |
let arrowStartSnippet; | |
if ( | |
chainStart > 0 && | |
this.tokens.matches1AtIndex(chainStart - 1, TokenType._delete) && | |
this.isLastSubscriptInChain() | |
) { | |
arrowStartSnippet = `${param} => delete ${param}`; | |
} else { | |
arrowStartSnippet = `${param} => ${param}`; | |
} | |
if (this.tokens.tokens[chainStart].isAsyncOperation) { | |
arrowStartSnippet = `async ${arrowStartSnippet}`; | |
} | |
if ( | |
this.tokens.matches2(TokenType.questionDot, TokenType.parenL) || | |
this.tokens.matches2(TokenType.questionDot, TokenType.lessThan) | |
) { | |
if (this.justSkippedSuper()) { | |
this.tokens.appendCode(".bind(this)"); | |
} | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
`, 'optionalCall', ${arrowStartSnippet}` | |
); | |
} else if ( | |
this.tokens.matches2(TokenType.questionDot, TokenType.bracketL) | |
) { | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
`, 'optionalAccess', ${arrowStartSnippet}` | |
); | |
} else if (this.tokens.matches1(TokenType.questionDot)) { | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
`, 'optionalAccess', ${arrowStartSnippet}.` | |
); | |
} else if (this.tokens.matches1(TokenType.dot)) { | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
`, 'access', ${arrowStartSnippet}.` | |
); | |
} else if (this.tokens.matches1(TokenType.bracketL)) { | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
`, 'access', ${arrowStartSnippet}[` | |
); | |
} else if (this.tokens.matches1(TokenType.parenL)) { | |
if (this.justSkippedSuper()) { | |
this.tokens.appendCode(".bind(this)"); | |
} | |
this.tokens.replaceTokenTrimmingLeftWhitespace( | |
`, 'call', ${arrowStartSnippet}(` | |
); | |
} else { | |
throw new Error("Unexpected subscript operator in optional chain."); | |
} | |
return true; | |
} | |
return false; | |
} | |
isLastSubscriptInChain() { | |
let depth = 0; | |
for (let i = this.tokens.currentIndex() + 1; ; i++) { | |
if (i >= this.tokens.tokens.length) { | |
throw new Error( | |
"Reached the end of the code while finding the end of the access chain." | |
); | |
} | |
if (this.tokens.tokens[i].isOptionalChainStart) { | |
depth++; | |
} else if (this.tokens.tokens[i].isOptionalChainEnd) { | |
depth--; | |
} | |
if (depth < 0) { | |
return true; | |
} | |
if (depth === 0 && this.tokens.tokens[i].subscriptStartIndex != null) { | |
return false; | |
} | |
} | |
} | |
justSkippedSuper() { | |
let depth = 0; | |
let index = this.tokens.currentIndex() - 1; | |
while (true) { | |
if (index < 0) { | |
throw new Error( | |
"Reached the start of the code while finding the start of the access chain." | |
); | |
} | |
if (this.tokens.tokens[index].isOptionalChainStart) { | |
depth--; | |
} else if (this.tokens.tokens[index].isOptionalChainEnd) { | |
depth++; | |
} | |
if (depth < 0) { | |
return false; | |
} | |
if ( | |
depth === 0 && | |
this.tokens.tokens[index].subscriptStartIndex != null | |
) { | |
return this.tokens.tokens[index - 1].type === TokenType._super; | |
} | |
index--; | |
} | |
} | |
} | |
class ReactDisplayNameTransformer extends Transformer { | |
constructor(rootTransformer, tokens, importProcessor, options) { | |
super(); | |
this.rootTransformer = rootTransformer; | |
this.tokens = tokens; | |
this.importProcessor = importProcessor; | |
this.options = options; | |
} | |
process() { | |
const startIndex = this.tokens.currentIndex(); | |
if (this.tokens.identifierName() === "createReactClass") { | |
const newName = | |
this.importProcessor && | |
this.importProcessor.getIdentifierReplacement("createReactClass"); | |
if (newName) { | |
this.tokens.replaceToken(`(0, ${newName})`); | |
} else { | |
this.tokens.copyToken(); | |
} | |
this.tryProcessCreateClassCall(startIndex); | |
return true; | |
} | |
if ( | |
this.tokens.matches3(TokenType.name, TokenType.dot, TokenType.name) && | |
this.tokens.identifierName() === "React" && | |
this.tokens.identifierNameAtIndex(this.tokens.currentIndex() + 2) === | |
"createClass" | |
) { | |
const newName = this.importProcessor | |
? this.importProcessor.getIdentifierReplacement("React") || "React" | |
: "React"; | |
if (newName) { | |
this.tokens.replaceToken(newName); | |
this.tokens.copyToken(); | |
this.tokens.copyToken(); | |
} else { | |
this.tokens.copyToken(); | |
this.tokens.copyToken(); | |
this.tokens.copyToken(); | |
} | |
this.tryProcessCreateClassCall(startIndex); | |
return true; | |
} | |
return false; | |
} | |
tryProcessCreateClassCall(startIndex) { | |
const displayName = this.findDisplayName(startIndex); | |
if (!displayName) { | |
return; | |
} | |
if (this.classNeedsDisplayName()) { | |
this.tokens.copyExpectedToken(TokenType.parenL); | |
this.tokens.copyExpectedToken(TokenType.braceL); | |
this.tokens.appendCode(`displayName: '${displayName}',`); | |
this.rootTransformer.processBalancedCode(); | |
this.tokens.copyExpectedToken(TokenType.braceR); | |
this.tokens.copyExpectedToken(TokenType.parenR); | |
} | |
} | |
findDisplayName(startIndex) { | |
if (startIndex < 2) { | |
return null; | |
} | |
if ( | |
this.tokens.matches2AtIndex(startIndex - 2, TokenType.name, TokenType.eq) | |
) { | |
return this.tokens.identifierNameAtIndex(startIndex - 2); | |
} | |
if ( | |
startIndex >= 2 && | |
this.tokens.tokens[startIndex - 2].identifierRole === | |
IdentifierRole.ObjectKey | |
) { | |
return this.tokens.identifierNameAtIndex(startIndex - 2); | |
} | |
if ( | |
this.tokens.matches2AtIndex( | |
startIndex - 2, | |
TokenType._export, | |
TokenType._default | |
) | |
) { | |
return this.getDisplayNameFromFilename(); | |
} | |
return null; | |
} | |
getDisplayNameFromFilename() { | |
const filePath = this.options.filePath || "unknown"; | |
const pathSegments = filePath.split("/"); | |
const filename = pathSegments[pathSegments.length - 1]; | |
const dotIndex = filename.lastIndexOf("."); | |
const baseFilename = | |
dotIndex === -1 ? filename : filename.slice(0, dotIndex); | |
if (baseFilename === "index" && pathSegments[pathSegments.length - 2]) { | |
return pathSegments[pathSegments.length - 2]; | |
} else { | |
return baseFilename; | |
} | |
} | |
classNeedsDisplayName() { | |
let index = this.tokens.currentIndex(); | |
if (!this.tokens.matches2(TokenType.parenL, TokenType.braceL)) { | |
return false; | |
} | |
const objectStartIndex = index + 1; | |
const objectContextId = this.tokens.tokens[objectStartIndex].contextId; | |
if (objectContextId == null) { | |
throw new Error("Expected non-null context ID on object open-brace."); | |
} | |
for (; index < this.tokens.tokens.length; index++) { | |
const token = this.tokens.tokens[index]; | |
if ( | |
token.type === TokenType.braceR && | |
token.contextId === objectContextId | |
) { | |
index++; | |
break; | |
} | |
if ( | |
this.tokens.identifierNameAtIndex(index) === "displayName" && | |
this.tokens.tokens[index].identifierRole === IdentifierRole.ObjectKey && | |
token.contextId === objectContextId | |
) { | |
return false; | |
} | |
} | |
if (index === this.tokens.tokens.length) { | |
throw new Error("Unexpected end of input when processing React class."); | |
} | |
return ( | |
this.tokens.matches1AtIndex(index, TokenType.parenR) || | |
this.tokens.matches2AtIndex(index, TokenType.comma, TokenType.parenR) | |
); | |
} | |
} | |
class ReactHotLoaderTransformer extends Transformer { | |
__init() { | |
this.extractedDefaultExportName = null; | |
} | |
constructor(tokens, filePath) { | |
super(); | |
this.tokens = tokens; | |
this.filePath = filePath; | |
ReactHotLoaderTransformer.prototype.__init.call(this); | |
} | |
setExtractedDefaultExportName(extractedDefaultExportName) { | |
this.extractedDefaultExportName = extractedDefaultExportName; | |
} | |
getPrefixCode() { | |
return ` | |
(function () { | |
var enterModule = require('react-hot-loader').enterModule; | |
enterModule && enterModule(module); | |
})();` | |
.replace(/\s+/g, " ") | |
.trim(); | |
} | |
getSuffixCode() { | |
const topLevelNames = new Set(); | |
for (const token of this.tokens.tokens) { | |
if ( | |
!token.isType && | |
isTopLevelDeclaration(token) && | |
token.identifierRole !== IdentifierRole.ImportDeclaration | |
) { | |
topLevelNames.add(this.tokens.identifierNameForToken(token)); | |
} | |
} | |
const namesToRegister = Array.from(topLevelNames).map((name) => ({ | |
variableName: name, | |
uniqueLocalName: name, | |
})); | |
if (this.extractedDefaultExportName) { | |
namesToRegister.push({ | |
variableName: this.extractedDefaultExportName, | |
uniqueLocalName: "default", | |
}); | |
} | |
return ` | |
;(function () { | |
var reactHotLoader = require('react-hot-loader').default; | |
var leaveModule = require('react-hot-loader').leaveModule; | |
if (!reactHotLoader) { | |
return; | |
} | |
${namesToRegister | |
.map( | |
({ variableName, uniqueLocalName }) => | |
` reactHotLoader.register(${variableName}, "${uniqueLocalName}", ${JSON.stringify( | |
this.filePath || "" | |
)});` | |
) | |
.join("\n")} | |
leaveModule(module); | |
})();`; | |
} | |
process() { | |
return false; | |
} | |
} | |
const RESERVED_WORDS = new Set([ | |
"break", | |
"case", | |
"catch", | |
"class", | |
"const", | |
"continue", | |
"debugger", | |
"default", | |
"delete", | |
"do", | |
"else", | |
"export", | |
"extends", | |
"finally", | |
"for", | |
"function", | |
"if", | |
"import", | |
"in", | |
"instanceof", | |
"new", | |
"return", | |
"super", | |
"switch", | |
"this", | |
"throw", | |
"try", | |
"typeof", | |
"var", | |
"void", | |
"while", | |
"with", | |
"yield", | |
"enum", | |
"implements", | |
"interface", | |
"let", | |
"package", | |
"private", | |
"protected", | |
"public", | |
"static", | |
"await", | |
]); | |
function isIdentifier(name) { | |
if (name.length === 0) { | |
return false; | |
} | |
if (!IS_IDENTIFIER_START[name.charCodeAt(0)]) { | |
return false; | |
} | |
for (let i = 1; i < name.length; i++) { | |
if (!IS_IDENTIFIER_CHAR[name.charCodeAt(i)]) { | |
return false; | |
} | |
} | |
return !RESERVED_WORDS.has(name); | |
} | |
class TypeScriptTransformer extends Transformer { | |
constructor(rootTransformer, tokens, isImportsTransformEnabled) { | |
super(); | |
this.rootTransformer = rootTransformer; | |
this.tokens = tokens; | |
this.isImportsTransformEnabled = isImportsTransformEnabled; | |
} | |
process() { | |
if ( | |
this.rootTransformer.processPossibleArrowParamEnd() || | |
this.rootTransformer.processPossibleAsyncArrowWithTypeParams() || | |
this.rootTransformer.processPossibleTypeRange() | |
) { | |
return true; | |
} | |
if ( | |
this.tokens.matches1(TokenType._public) || | |
this.tokens.matches1(TokenType._protected) || | |
this.tokens.matches1(TokenType._private) || | |
this.tokens.matches1(TokenType._abstract) || | |
this.tokens.matches1(TokenType._readonly) || | |
this.tokens.matches1(TokenType.nonNullAssertion) | |
) { | |
this.tokens.removeInitialToken(); | |
return true; | |
} | |
if ( | |
this.tokens.matches1(TokenType._enum) || | |
this.tokens.matches2(TokenType._const, TokenType._enum) | |
) { | |
this.processEnum(); | |
return true; | |
} | |
if ( | |
this.tokens.matches2(TokenType._export, TokenType._enum) || | |
this.tokens.matches3(TokenType._export, TokenType._const, TokenType._enum) | |
) { | |
this.processEnum(true); | |
return true; | |
} | |
return false; | |
} | |
processEnum(isExport = false) { | |
this.tokens.removeInitialToken(); | |
while ( | |
this.tokens.matches1(TokenType._const) || | |
this.tokens.matches1(TokenType._enum) | |
) { | |
this.tokens.removeToken(); | |
} | |
const enumName = this.tokens.identifierName(); | |
this.tokens.removeToken(); | |
if (isExport && !this.isImportsTransformEnabled) { | |
this.tokens.appendCode("export "); | |
} | |
this.tokens.appendCode(`var ${enumName}; (function (${enumName})`); | |
this.tokens.copyExpectedToken(TokenType.braceL); | |
this.processEnumBody(enumName); | |
this.tokens.copyExpectedToken(TokenType.braceR); | |
if (isExport && this.isImportsTransformEnabled) { | |
this.tokens.appendCode( | |
`)(${enumName} || (exports.${enumName} = ${enumName} = {}));` | |
); | |
} else { | |
this.tokens.appendCode(`)(${enumName} || (${enumName} = {}));`); | |
} | |
} | |
processEnumBody(enumName) { | |
let isPreviousValidIdentifier = false; | |
let lastValueReference = null; | |
while (true) { | |
if (this.tokens.matches1(TokenType.braceR)) { | |
break; | |
} | |
const nameToken = this.tokens.currentToken(); | |
let name; | |
let nameStringCode; | |
if (nameToken.type === TokenType.name) { | |
name = this.tokens.identifierNameForToken(nameToken); | |
nameStringCode = `"${name}"`; | |
} else if (nameToken.type === TokenType.string) { | |
name = this.tokens.stringValueForToken(nameToken); | |
nameStringCode = this.tokens.code.slice(nameToken.start, nameToken.end); | |
} else { | |
throw new Error( | |
"Expected name or string at beginning of enum element." | |
); | |
} | |
const isValidIdentifier = isIdentifier(name); | |
this.tokens.removeInitialToken(); | |
let valueIsString; | |
let valueCode; | |
if (this.tokens.matches1(TokenType.eq)) { | |
const rhsEndIndex = this.tokens.currentToken().rhsEndIndex; | |
if (rhsEndIndex == null) { | |
throw new Error("Expected rhsEndIndex on enum assign."); | |
} | |
this.tokens.removeToken(); | |
if ( | |
this.tokens.matches2(TokenType.string, TokenType.comma) || | |
this.tokens.matches2(TokenType.string, TokenType.braceR) | |
) { | |
valueIsString = true; | |
} | |
const startToken = this.tokens.currentToken(); | |
while (this.tokens.currentIndex() < rhsEndIndex) { | |
this.tokens.removeToken(); | |
} | |
valueCode = this.tokens.code.slice( | |
startToken.start, | |
this.tokens.tokenAtRelativeIndex(-1).end | |
); | |
} else { | |
valueIsString = false; | |
if (lastValueReference != null) { | |
if (isPreviousValidIdentifier) { | |
valueCode = `${lastValueReference} + 1`; | |
} else { | |
valueCode = `(${lastValueReference}) + 1`; | |
} | |
} else { | |
valueCode = "0"; | |
} | |
} | |
if (this.tokens.matches1(TokenType.comma)) { | |
this.tokens.removeToken(); | |
} | |
let valueReference; | |
if (isValidIdentifier) { | |
this.tokens.appendCode(`const ${name} = ${valueCode}; `); | |
valueReference = name; | |
} else { | |
valueReference = valueCode; | |
} | |
if (valueIsString) { | |
this.tokens.appendCode( | |
`${enumName}[${nameStringCode}] = ${valueReference};` | |
); | |
} else { | |
this.tokens.appendCode( | |
`${enumName}[${enumName}[${nameStringCode}] = ${valueReference}] = ${nameStringCode};` | |
); | |
} | |
lastValueReference = valueReference; | |
isPreviousValidIdentifier = isValidIdentifier; | |
} | |
} | |
} | |
class RootTransformer { | |
__init() { | |
this.transformers = []; | |
} | |
__init2() { | |
this.generatedVariables = []; | |
} | |
constructor( | |
sucraseContext, | |
transforms, | |
enableLegacyBabel5ModuleInterop, | |
options | |
) { | |
RootTransformer.prototype.__init.call(this); | |
RootTransformer.prototype.__init2.call(this); | |
this.nameManager = sucraseContext.nameManager; | |
this.helperManager = sucraseContext.helperManager; | |
const { tokenProcessor, importProcessor } = sucraseContext; | |
this.tokens = tokenProcessor; | |
this.isImportsTransformEnabled = transforms.includes("imports"); | |
this.isReactHotLoaderTransformEnabled = transforms.includes( | |
"react-hot-loader" | |
); | |
this.transformers.push( | |
new OptionalChainingNullishTransformer(tokenProcessor, this.nameManager) | |
); | |
this.transformers.push(new NumericSeparatorTransformer(tokenProcessor)); | |
this.transformers.push( | |
new OptionalCatchBindingTransformer(tokenProcessor, this.nameManager) | |
); | |
if (transforms.includes("jsx")) { | |
this.transformers.push( | |
new JSXTransformer( | |
this, | |
tokenProcessor, | |
importProcessor, | |
this.nameManager, | |
options | |
) | |
); | |
this.transformers.push( | |
new ReactDisplayNameTransformer( | |
this, | |
tokenProcessor, | |
importProcessor, | |
options | |
) | |
); | |
} | |
let reactHotLoaderTransformer = null; | |
if (transforms.includes("react-hot-loader")) { | |
if (!options.filePath) { | |
throw new Error( | |
"filePath is required when using the react-hot-loader transform." | |
); | |
} | |
reactHotLoaderTransformer = new ReactHotLoaderTransformer( | |
tokenProcessor, | |
options.filePath | |
); | |
this.transformers.push(reactHotLoaderTransformer); | |
} | |
if (transforms.includes("imports")) { | |
if (importProcessor === null) { | |
throw new Error( | |
"Expected non-null importProcessor with imports transform enabled." | |
); | |
} | |
this.transformers.push( | |
new CJSImportTransformer( | |
this, | |
tokenProcessor, | |
importProcessor, | |
this.nameManager, | |
reactHotLoaderTransformer, | |
enableLegacyBabel5ModuleInterop, | |
transforms.includes("typescript") | |
) | |
); | |
} else { | |
this.transformers.push( | |
new ESMImportTransformer( | |
tokenProcessor, | |
this.nameManager, | |
reactHotLoaderTransformer, | |
transforms.includes("typescript"), | |
options | |
) | |
); | |
} | |
if (transforms.includes("flow")) { | |
this.transformers.push(new FlowTransformer(this, tokenProcessor)); | |
} | |
if (transforms.includes("typescript")) { | |
this.transformers.push( | |
new TypeScriptTransformer( | |
this, | |
tokenProcessor, | |
transforms.includes("imports") | |
) | |
); | |
} | |
} | |
transform() { | |
this.tokens.reset(); | |
this.processBalancedCode(); | |
const shouldAddUseStrict = this.isImportsTransformEnabled; | |
let prefix = shouldAddUseStrict ? '"use strict";' : ""; | |
for (const transformer of this.transformers) { | |
prefix += transformer.getPrefixCode(); | |
} | |
prefix += this.helperManager.emitHelpers(); | |
prefix += this.generatedVariables.map((v) => ` var ${v};`).join(""); | |
let suffix = ""; | |
for (const transformer of this.transformers) { | |
suffix += transformer.getSuffixCode(); | |
} | |
let code = this.tokens.finish(); | |
if (code.startsWith("#!")) { | |
let newlineIndex = code.indexOf("\n"); | |
if (newlineIndex === -1) { | |
newlineIndex = code.length; | |
code += "\n"; | |
} | |
return ( | |
code.slice(0, newlineIndex + 1) + | |
prefix + | |
code.slice(newlineIndex + 1) + | |
suffix | |
); | |
} else { | |
return prefix + this.tokens.finish() + suffix; | |
} | |
} | |
processBalancedCode() { | |
let braceDepth = 0; | |
let parenDepth = 0; | |
while (!this.tokens.isAtEnd()) { | |
if ( | |
this.tokens.matches1(TokenType.braceL) || | |
this.tokens.matches1(TokenType.dollarBraceL) | |
) { | |
braceDepth++; | |
} else if (this.tokens.matches1(TokenType.braceR)) { | |
if (braceDepth === 0) { | |
return; | |
} | |
braceDepth--; | |
} | |
if (this.tokens.matches1(TokenType.parenL)) { | |
parenDepth++; | |
} else if (this.tokens.matches1(TokenType.parenR)) { | |
if (parenDepth === 0) { | |
return; | |
} | |
parenDepth--; | |
} | |
this.processToken(); | |
} | |
} | |
processToken() { | |
if (this.tokens.matches1(TokenType._class)) { | |
this.processClass(); | |
return; | |
} | |
for (const transformer of this.transformers) { | |
const wasProcessed = transformer.process(); | |
if (wasProcessed) { | |
return; | |
} | |
} | |
this.tokens.copyToken(); | |
} | |
processNamedClass() { | |
if (!this.tokens.matches2(TokenType._class, TokenType.name)) { | |
throw new Error("Expected identifier for exported class name."); | |
} | |
const name = this.tokens.identifierNameAtIndex( | |
this.tokens.currentIndex() + 1 | |
); | |
this.processClass(); | |
return name; | |
} | |
processClass() { | |
const classInfo = getClassInfo(this, this.tokens, this.nameManager); | |
const needsCommaExpression = | |
classInfo.headerInfo.isExpression && | |
classInfo.staticInitializerNames.length + | |
classInfo.instanceInitializerNames.length > | |
0; | |
let className = classInfo.headerInfo.className; | |
if (needsCommaExpression) { | |
className = this.nameManager.claimFreeName("_class"); | |
this.generatedVariables.push(className); | |
this.tokens.appendCode(` (${className} =`); | |
} | |
const classToken = this.tokens.currentToken(); | |
const contextId = classToken.contextId; | |
if (contextId == null) { | |
throw new Error("Expected class to have a context ID."); | |
} | |
this.tokens.copyExpectedToken(TokenType._class); | |
while (!this.tokens.matchesContextIdAndLabel(TokenType.braceL, contextId)) { | |
this.processToken(); | |
} | |
this.processClassBody(classInfo, className); | |
const staticInitializerStatements = classInfo.staticInitializerNames.map( | |
(name) => `${className}.${name}()` | |
); | |
if (needsCommaExpression) { | |
this.tokens.appendCode( | |
`, ${staticInitializerStatements | |
.map((s) => `${s}, `) | |
.join("")}${className})` | |
); | |
} else if (classInfo.staticInitializerNames.length > 0) { | |
this.tokens.appendCode( | |
` ${staticInitializerStatements.map((s) => `${s};`).join(" ")}` | |
); | |
} | |
} | |
processClassBody(classInfo, className) { | |
const { | |
headerInfo, | |
constructorInsertPos, | |
constructorInitializerStatements, | |
fields, | |
instanceInitializerNames, | |
rangesToRemove, | |
} = classInfo; | |
let fieldIndex = 0; | |
let rangeToRemoveIndex = 0; | |
const classContextId = this.tokens.currentToken().contextId; | |
if (classContextId == null) { | |
throw new Error("Expected non-null context ID on class."); | |
} | |
this.tokens.copyExpectedToken(TokenType.braceL); | |
if (this.isReactHotLoaderTransformEnabled) { | |
this.tokens.appendCode( | |
"__reactstandin__regenerateByEval(key, code) {this[key] = eval(code);}" | |
); | |
} | |
const needsConstructorInit = | |
constructorInitializerStatements.length + | |
instanceInitializerNames.length > | |
0; | |
if (constructorInsertPos === null && needsConstructorInit) { | |
const constructorInitializersCode = this.makeConstructorInitCode( | |
constructorInitializerStatements, | |
instanceInitializerNames, | |
className | |
); | |
if (headerInfo.hasSuperclass) { | |
const argsName = this.nameManager.claimFreeName("args"); | |
this.tokens.appendCode( | |
`constructor(...${argsName}) { super(...${argsName}); ${constructorInitializersCode}; }` | |
); | |
} else { | |
this.tokens.appendCode( | |
`constructor() { ${constructorInitializersCode}; }` | |
); | |
} | |
} | |
while ( | |
!this.tokens.matchesContextIdAndLabel(TokenType.braceR, classContextId) | |
) { | |
if ( | |
fieldIndex < fields.length && | |
this.tokens.currentIndex() === fields[fieldIndex].start | |
) { | |
let needsCloseBrace = false; | |
if (this.tokens.matches1(TokenType.bracketL)) { | |
this.tokens.copyTokenWithPrefix( | |
`${fields[fieldIndex].initializerName}() {this` | |
); | |
} else if ( | |
this.tokens.matches1(TokenType.string) || | |
this.tokens.matches1(TokenType.num) | |
) { | |
this.tokens.copyTokenWithPrefix( | |
`${fields[fieldIndex].initializerName}() {this[` | |
); | |
needsCloseBrace = true; | |
} else { | |
this.tokens.copyTokenWithPrefix( | |
`${fields[fieldIndex].initializerName}() {this.` | |
); | |
} | |
while (this.tokens.currentIndex() < fields[fieldIndex].end) { | |
if ( | |
needsCloseBrace && | |
this.tokens.currentIndex() === fields[fieldIndex].equalsIndex | |
) { | |
this.tokens.appendCode("]"); | |
} | |
this.processToken(); | |
} | |
this.tokens.appendCode("}"); | |
fieldIndex++; | |
} else if ( | |
rangeToRemoveIndex < rangesToRemove.length && | |
this.tokens.currentIndex() === rangesToRemove[rangeToRemoveIndex].start | |
) { | |
this.tokens.removeInitialToken(); | |
while ( | |
this.tokens.currentIndex() < rangesToRemove[rangeToRemoveIndex].end | |
) { | |
this.tokens.removeToken(); | |
} | |
rangeToRemoveIndex++; | |
} else if (this.tokens.currentIndex() === constructorInsertPos) { | |
this.tokens.copyToken(); | |
if (needsConstructorInit) { | |
this.tokens.appendCode( | |
`;${this.makeConstructorInitCode( | |
constructorInitializerStatements, | |
instanceInitializerNames, | |
className | |
)};` | |
); | |
} | |
this.processToken(); | |
} else { | |
this.processToken(); | |
} | |
} | |
this.tokens.copyExpectedToken(TokenType.braceR); | |
} | |
makeConstructorInitCode( | |
constructorInitializerStatements, | |
instanceInitializerNames, | |
className | |
) { | |
return [ | |
...constructorInitializerStatements, | |
...instanceInitializerNames.map( | |
(name) => `${className}.prototype.${name}.call(this)` | |
), | |
].join(";"); | |
} | |
processPossibleArrowParamEnd() { | |
if ( | |
this.tokens.matches2(TokenType.parenR, TokenType.colon) && | |
this.tokens.tokenAtRelativeIndex(1).isType | |
) { | |
let nextNonTypeIndex = this.tokens.currentIndex() + 1; | |
while (this.tokens.tokens[nextNonTypeIndex].isType) { | |
nextNonTypeIndex++; | |
} | |
if (this.tokens.matches1AtIndex(nextNonTypeIndex, TokenType.arrow)) { | |
this.tokens.removeInitialToken(); | |
while (this.tokens.currentIndex() < nextNonTypeIndex) { | |
this.tokens.removeToken(); | |
} | |
this.tokens.replaceTokenTrimmingLeftWhitespace(") =>"); | |
return true; | |
} | |
} | |
return false; | |
} | |
processPossibleAsyncArrowWithTypeParams() { | |
if ( | |
!this.tokens.matchesContextual(ContextualKeyword._async) && | |
!this.tokens.matches1(TokenType._async) | |
) { | |
return false; | |
} | |
const nextToken2 = this.tokens.tokenAtRelativeIndex(1); | |
if (nextToken2.type !== TokenType.lessThan || !nextToken2.isType) { | |
return false; | |
} | |
let nextNonTypeIndex = this.tokens.currentIndex() + 1; | |
while (this.tokens.tokens[nextNonTypeIndex].isType) { | |
nextNonTypeIndex++; | |
} | |
if (this.tokens.matches1AtIndex(nextNonTypeIndex, TokenType.parenL)) { | |
this.tokens.replaceToken("async ("); | |
this.tokens.removeInitialToken(); | |
while (this.tokens.currentIndex() < nextNonTypeIndex) { | |
this.tokens.removeToken(); | |
} | |
this.tokens.removeToken(); | |
this.processBalancedCode(); | |
this.processToken(); | |
return true; | |
} | |
return false; | |
} | |
processPossibleTypeRange() { | |
if (this.tokens.currentToken().isType) { | |
this.tokens.removeInitialToken(); | |
while (this.tokens.currentToken().isType) { | |
this.tokens.removeToken(); | |
} | |
return true; | |
} | |
return false; | |
} | |
} | |
function formatTokens(code, tokens) { | |
if (tokens.length === 0) { | |
return ""; | |
} | |
const tokenKeys = Object.keys(tokens[0]).filter( | |
(k) => | |
k !== "type" && | |
k !== "value" && | |
k !== "start" && | |
k !== "end" && | |
k !== "loc" | |
); | |
const typeKeys = Object.keys(tokens[0].type).filter( | |
(k) => k !== "label" && k !== "keyword" | |
); | |
const headings = ["Location", "Label", "Raw", ...tokenKeys, ...typeKeys]; | |
const lines = new LinesAndColumns(code); | |
const rows = [headings, ...tokens.map(getTokenComponents)]; | |
const padding = headings.map(() => 0); | |
for (const components of rows) { | |
for (let i = 0; i < components.length; i++) { | |
padding[i] = Math.max(padding[i], components[i].length); | |
} | |
} | |
return rows | |
.map((components) => | |
components.map((component, i) => component.padEnd(padding[i])).join(" ") | |
) | |
.join("\n"); | |
function getTokenComponents(token) { | |
const raw = code.slice(token.start, token.end); | |
return [ | |
formatRange(token.start, token.end), | |
formatTokenType(token.type), | |
truncate(String(raw), 14), | |
...tokenKeys.map((key) => formatValue(token[key], key)), | |
...typeKeys.map((key) => formatValue(token.type[key], key)), | |
]; | |
} | |
function formatValue(value, key) { | |
if (value === true) { | |
return key; | |
} else if (value === false || value === null) { | |
return ""; | |
} else { | |
return String(value); | |
} | |
} | |
function formatRange(start, end) { | |
return `${formatPos(start)}-${formatPos(end)}`; | |
} | |
function formatPos(pos) { | |
const location = lines.locationForIndex(pos); | |
if (!location) { | |
return "Unknown"; | |
} else { | |
return `${location.line + 1}:${location.column + 1}`; | |
} | |
} | |
} | |
function truncate(s, length) { | |
if (s.length > length) { | |
return `${s.slice(0, length - 3)}...`; | |
} else { | |
return s; | |
} | |
} | |
function getTSImportedNames(tokens) { | |
const importedNames = new Set(); | |
for (let i = 0; i < tokens.tokens.length; i++) { | |
if ( | |
tokens.matches1AtIndex(i, TokenType._import) && | |
!tokens.matches3AtIndex( | |
i, | |
TokenType._import, | |
TokenType.name, | |
TokenType.eq | |
) | |
) { | |
collectNamesForImport(tokens, i, importedNames); | |
} | |
} | |
return importedNames; | |
} | |
function collectNamesForImport(tokens, index, importedNames) { | |
index++; | |
if (tokens.matches1AtIndex(index, TokenType.parenL)) { | |
return; | |
} | |
if (tokens.matches1AtIndex(index, TokenType.name)) { | |
importedNames.add(tokens.identifierNameAtIndex(index)); | |
index++; | |
if (tokens.matches1AtIndex(index, TokenType.comma)) { | |
index++; | |
} | |
} | |
if (tokens.matches1AtIndex(index, TokenType.star)) { | |
index += 2; | |
importedNames.add(tokens.identifierNameAtIndex(index)); | |
index++; | |
} | |
if (tokens.matches1AtIndex(index, TokenType.braceL)) { | |
index++; | |
collectNamesForNamedImport(tokens, index, importedNames); | |
} | |
} | |
function collectNamesForNamedImport(tokens, index, importedNames) { | |
while (true) { | |
if (tokens.matches1AtIndex(index, TokenType.braceR)) { | |
return; | |
} | |
let name = tokens.identifierNameAtIndex(index); | |
index++; | |
if (tokens.matchesContextualAtIndex(index, ContextualKeyword._as)) { | |
index++; | |
name = tokens.identifierNameAtIndex(index); | |
index++; | |
} | |
importedNames.add(name); | |
if (tokens.matches2AtIndex(index, TokenType.comma, TokenType.braceR)) { | |
return; | |
} else if (tokens.matches1AtIndex(index, TokenType.braceR)) { | |
return; | |
} else if (tokens.matches1AtIndex(index, TokenType.comma)) { | |
index++; | |
} else { | |
throw new Error( | |
`Unexpected token: ${JSON.stringify(tokens.tokens[index])}` | |
); | |
} | |
} | |
} | |
function getVersion() { | |
return require("../package.json").version; | |
} | |
function transform(code, options) { | |
validateOptions(options); | |
try { | |
const sucraseContext = getSucraseContext(code, options); | |
const transformer = new RootTransformer( | |
sucraseContext, | |
options.transforms, | |
Boolean(options.enableLegacyBabel5ModuleInterop), | |
options | |
); | |
let result = { code: transformer.transform() }; | |
if (options.sourceMapOptions) { | |
if (!options.filePath) { | |
throw new Error( | |
"filePath must be specified when generating a source map." | |
); | |
} | |
result = { | |
...result, | |
sourceMap: computeSourceMap( | |
result.code, | |
options.filePath, | |
options.sourceMapOptions | |
), | |
}; | |
} | |
return result; | |
} catch (e) { | |
if (options.filePath) { | |
e.message = `Error transforming ${options.filePath}: ${e.message}`; | |
} | |
throw e; | |
} | |
} | |
function getFormattedTokens(code, options) { | |
const tokens = getSucraseContext(code, options).tokenProcessor.tokens; | |
return formatTokens(code, tokens); | |
} | |
function getSucraseContext(code, options) { | |
const isJSXEnabled2 = options.transforms.includes("jsx"); | |
const isTypeScriptEnabled2 = options.transforms.includes("typescript"); | |
const isFlowEnabled2 = options.transforms.includes("flow"); | |
const file = parse(code, isJSXEnabled2, isTypeScriptEnabled2, isFlowEnabled2); | |
const tokens = file.tokens; | |
const scopes = file.scopes; | |
const nameManager = new NameManager(code, tokens); | |
const helperManager = new HelperManager(nameManager); | |
const tokenProcessor = new TokenProcessor( | |
code, | |
tokens, | |
isFlowEnabled2, | |
helperManager | |
); | |
const enableLegacyTypeScriptModuleInterop = Boolean( | |
options.enableLegacyTypeScriptModuleInterop | |
); | |
let importProcessor = null; | |
if (options.transforms.includes("imports")) { | |
importProcessor = new CJSImportProcessor( | |
nameManager, | |
tokenProcessor, | |
enableLegacyTypeScriptModuleInterop, | |
options, | |
options.transforms.includes("typescript"), | |
helperManager | |
); | |
importProcessor.preprocessTokens(); | |
identifyShadowedGlobals( | |
tokenProcessor, | |
scopes, | |
importProcessor.getGlobalNames() | |
); | |
if (options.transforms.includes("typescript")) { | |
importProcessor.pruneTypeOnlyImports(); | |
} | |
} else if (options.transforms.includes("typescript")) { | |
identifyShadowedGlobals( | |
tokenProcessor, | |
scopes, | |
getTSImportedNames(tokenProcessor) | |
); | |
} | |
return { | |
tokenProcessor, | |
scopes, | |
nameManager, | |
importProcessor, | |
helperManager, | |
}; | |
} | |
self.addEventListener("install", (event) => { | |
event.waitUntil(self.skipWaiting()); | |
}); | |
self.addEventListener("activate", (event) => { | |
event.waitUntil(self.clients.claim()); | |
}); | |
self.addEventListener("fetch", (event) => { | |
event.respondWith( | |
fetch(event.request).then((response) => | |
event.request.method === "GET" && | |
/\.(jsx|ts|tsx)$/.test(event.request.url) | |
? response | |
.clone() | |
.text() | |
.then( | |
(content) => | |
new Response( | |
transform(content, { | |
transforms: [ | |
...(/\.(ts|tsx)$/.test(event.request.url) | |
? ["typescript"] | |
: []), | |
...(/\.(jsx|tsx)$/.test(event.request.url) | |
? ["jsx"] | |
: []), | |
], | |
}).code, | |
{ | |
headers: { | |
ETag: response.headers.get("ETag"), | |
"Content-Type": "text/javascript", | |
}, | |
} | |
) | |
) | |
.catch(() => response) | |
: response | |
) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment