File size: 3,095 Bytes
979bf48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
0 && (module.exports = {
    FAST_REFRESH_RUNTIME_RELOAD: null,
    createBinaryHmrMessageData: null
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    FAST_REFRESH_RUNTIME_RELOAD: function() {
        return FAST_REFRESH_RUNTIME_RELOAD;
    },
    createBinaryHmrMessageData: function() {
        return createBinaryHmrMessageData;
    }
});
const _invarianterror = require("../../shared/lib/invariant-error");
const _hotreloadertypes = require("./hot-reloader-types");
const FAST_REFRESH_RUNTIME_RELOAD = 'Fast Refresh had to perform a full reload due to a runtime error.';
const textEncoder = new TextEncoder();
function createBinaryHmrMessageData(message) {
    switch(message.type){
        case _hotreloadertypes.HMR_MESSAGE_SENT_TO_BROWSER.ERRORS_TO_SHOW_IN_BROWSER:
            {
                const { serializedErrors } = message;
                const totalLength = 1 + serializedErrors.length;
                const data = new Uint8Array(totalLength);
                const view = new DataView(data.buffer);
                view.setUint8(0, _hotreloadertypes.HMR_MESSAGE_SENT_TO_BROWSER.ERRORS_TO_SHOW_IN_BROWSER);
                data.set(serializedErrors, 1);
                return data;
            }
        case _hotreloadertypes.HMR_MESSAGE_SENT_TO_BROWSER.REACT_DEBUG_CHUNK:
            {
                const { requestId, chunk } = message;
                const requestIdBytes = textEncoder.encode(requestId);
                const requestIdLength = requestIdBytes.length;
                if (requestIdLength > 255) {
                    throw Object.defineProperty(new _invarianterror.InvariantError('Request ID is too long for the binary HMR message.'), "__NEXT_ERROR_CODE", {
                        value: "E805",
                        enumerable: false,
                        configurable: true
                    });
                }
                const chunkLength = chunk ? chunk.length : 0;
                const totalLength = 2 + requestIdLength + chunkLength;
                const data = new Uint8Array(totalLength);
                const view = new DataView(data.buffer);
                view.setUint8(0, _hotreloadertypes.HMR_MESSAGE_SENT_TO_BROWSER.REACT_DEBUG_CHUNK);
                view.setUint8(1, requestIdLength);
                textEncoder.encodeInto(requestId, data.subarray(2, 2 + requestIdLength));
                if (chunk) {
                    data.set(chunk, 2 + requestIdLength);
                }
                return data;
            }
        default:
            {
                throw Object.defineProperty(new _invarianterror.InvariantError(`Invalid binary HMR message of type ${message.type}`), "__NEXT_ERROR_CODE", {
                    value: "E809",
                    enumerable: false,
                    configurable: true
                });
            }
    }
}

//# sourceMappingURL=messages.js.map