Skip to content

Async Fn with fat arrows fail when it contains an object spread #12203

Description

@intellix

TypeScript Version: 2.2.0-dev.20161112

An async function returning an object with an object spread creates the yield but the wrapping function isn't a generator:

Code

function rootConnection(name: string) {
  return {
    resolve: async (context, args) => {
      const { objects } = await apiService.getMany(name);
      return {
        ...connectionFromArray(objects, args)
      };
    }
  };
}
rootConnection('test');

Compiled into:

function rootConnection(name) {
    return __assign({ resolve: (context, args) => {
            const { objects } = yield apiService.getMany(name);
            return __assign({}, connectionFromArray(objects, args));
        } });
}
rootConnection('test');

If I remove the object spread, the compiled code creates a generator wrapper for the yield

Code

function rootConnection(name: string) {
  return {
    resolve: async (context, args) => {
      const { objects } = await apiService.getMany(name);
      return {
        // ...connectionFromArray(objects, args)
      };
    }
  };
}
rootConnection('test');

Compiled into:

function rootConnection(name) {
    return {
        resolve: (context, args) => __awaiter(this, void 0, void 0, function* () {
            const { objects } = yield apiService.getMany(name);
            return {};
        })
    };
}
rootConnection('test');

Expected behavior:
Generator to wrap the yield

Actual behavior:
No generator, so get an error that yield is a strict reserved word:

const { objects } = yield apiService.getMany(name);
                    ^^^^^
SyntaxError: Unexpected strict mode reserved word

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions