Stop modifying the event data in onSerialReceive

This commit is contained in:
Melissa LeBlanc-Williams 2023-06-10 14:39:36 -07:00
parent 3b0652ccce
commit 5e768c19d0
3 changed files with 8 additions and 6 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "@adafruit/circuitpython-repl-js",
"version": "1.2.2",
"version": "1.2.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@adafruit/circuitpython-repl-js",
"version": "1.2.2",
"version": "1.2.3",
"license": "MIT",
"devDependencies": {}
}

View file

@ -3,7 +3,7 @@
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"version": "1.2.2",
"version": "1.2.3",
"description": "A JavaScript Module to help with interfacing to the REPL on CircuitPython Devices over serial",
"main": "repl.js",
"dependencies": {

View file

@ -102,15 +102,17 @@ export class REPL {
}
async onSerialReceive(e) {
// Prepend a partial token if it exists
// We don't want to modify e.data, so we make a copy of it
let data = e.data;
// Prepend a partial token if it exists
if (this._partialToken) {
e.data = this._partialToken + e.data;
data = this._partialToken + data;
this._partialToken = null;
}
// Tokenize the larger string and send to the parent
let tokens = this._tokenize(e.data);
let tokens = this._tokenize(data);
// Remove any partial tokens and store for the next serial data receive
if (tokens.length && this._hasPartialToken(tokens.slice(-1))) {