-
-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReferenceError when trying to create a connection to device #630
Comments
This is caused by Angular compiler. For this code: class Base {
// @ts-expect-error
constructor(callback) {
callback();
}
}
class Derived extends Base {
constructor() {
super(async () => {
await Promise.resolve();
console.log(this);
});
}
}
new Derived(); In In any modern browser with native async function support, the above code will run fine. However, because Angular uses Zone.js to track async contexts, it must down-level compile async functions to generators. For the code above, the result is: var Base = class {
// @ts-expect-error
constructor(callback) {
callback();
}
};
var Derived = class extends Base {
constructor() {
super(() => __async(this, null, function* () {
yield Promise.resolve();
console.log(this);
}));
}
}; As The offending code is: ya-webadb/libraries/stream-extra/src/wrap-readable.ts Lines 57 to 71 in adfcc12
Similar TypeScript down-level compilation bug: |
Good news! Since Angular 18 it is possible to run Angular without zone.js. I can confirm that this library and all functionality does work on Angular 18+ with the following provider enabled: |
It should be possible to rewrite the code to work around that down-level compilation bug: class Base {
// @ts-expect-error
constructor(callback) {
callback();
}
}
class Derived extends Base {
constructor() {
super(() => Promise.resolve().then(async () => { console.log(this) }));
}
}
new Derived(); TypeScript produces this (I didn't check Angular compiler): "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
class Base {
// @ts-expect-error
constructor(callback) {
callback();
}
}
class Derived extends Base {
constructor() {
super(() => Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () { console.log(this); })));
}
}
new Derived(); You can patch your node_modules if needed (there might be more places need to be patched). I don't want to add intentionally bad code for a compiler bug. |
Issue Checklist
Library version
0.0.23
Environment
Windows, Chrome 123, Angular 17
Device
Android
Describe the bug
I'm using
Angular 17.3.2
TypeScript 5.4.2
node 18.19.1
running on
localhost:4200
after successfully getting a device object, the connect() call throws the error below
Steps to reproduce
AdbDaemonWebUsbDevice
objectconnect()
The text was updated successfully, but these errors were encountered: