jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.31k stars 356 forks source link

SCRIPT1002: SCRIPT1002: Syntax error #105

Closed garthmountain closed 5 years ago

garthmountain commented 5 years ago

Hi Jake, Firstly, thank you for this package, much appreciated.

I've just upgraded from v2.1.3 to v4.0.3. This above error appears in my console window on app load, when testing in Edge, Chrome works fine. My app is Angular 7 (with service workers), running localhost. Selecting the error takes me to the js bundle and marks the error line as the first line of the code below:

async function* iterate(...args) {
    // tslint:disable-next-line:no-this-assignment
    let cursor = this;
    if (!(cursor instanceof IDBCursor)) {
        cursor = await cursor.openCursor(...args);
    }

The code in node_modules/idb/lib/async-iterators.ts looks like (my Webstorm shows a lint err on the 4th line (let cursor...)):

async function* iterate(this: IDBPObjectStore | IDBPIndex | IDBPCursor, ...args: any[]):
  AsyncIterableIterator<any> {
  // tslint:disable-next-line:no-this-assignment
  let cursor: typeof this | null = this;

  if (!(cursor instanceof IDBCursor)) {
    cursor = await (cursor as IDBPObjectStore | IDBPIndex).openCursor(...args);
  }

My code looks like:

import {openDB} from 'idb/with-async-ittr.js';
.
.
private openIDB(): Promise<any> {
    return openDB(this.dbName, this.dbVersion, {
      upgrade(db) {
...etc
.
.
public getAll<T>(store: Stores): Observable<T[]> {
...etc
this.openIDB().then(async db => {
        const transaction = db.transaction([store], 'readonly');
        for await (const cursor of transaction.store) {
         allStore.push(cursor.value);
        }
        return allStore;
      })
...etc
garthmountain commented 5 years ago

Ps. should have mentioned, the lint error is "expression expected"

jakearchibald commented 5 years ago

From https://github.com/jakearchibald/idb/blob/master/README.md#async-iterators

Async iterator support isn't included by default (Edge doesn't support them).