Skip to content

esnext features not transpiled within method declarations in object literals with spread elements #16765

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

Closed
Yogu opened this issue Jun 27, 2017 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@Yogu
Copy link
Contributor

Yogu commented Jun 27, 2017

TypeScript Version: 2.4.0

compilerOptions.target = ES5

Code

const obj = {};
const a = {
    ...obj,
    prop() {
        return {
            ...obj,
            metadata: 213
        }
    }
};

Expected behavior:

It compiles and transpiles the object spread operator to a call to Object.assign.

Actual behavior:

The object spread operator is not transpiled but simply kept. This can lead to the following error:

 TypeError: Cannot read property 'kind' of undefined
    at visitObjectLiteralExpression (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:56775:34)
    at visitJavaScript (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:55245:28)
    at visitor (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:55182:24)
    at visitNode (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:49197:23)
    at Object.visitEachChild (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:49479:46)
    at visitReturnStatement (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:55345:23)
    at visitJavaScript (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:55293:28)
    at visitor (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:55182:24)
    at Object.visitNodes (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:49248:48)
    at transformFunctionBody (C:\_myplace\next\graphql-proxy\node_modules\typescript\lib\typescript.js:56282:44)

Problem source:

The esnext transformer cuts off at method declarations within object literals that have an spread element, thus it never sees the inner object literal node.

@Yogu Yogu changed the title TypeError: Cannot read property 'kind' of undefined (object spread in literal) esnext features not transpiled within method declarations in object literals with spread elements Jun 27, 2017
Yogu added a commit to Yogu/TypeScript that referenced this issue Jun 27, 2017
Object literal elements that are neither spread elements, nor property assignments would not have visitNode called on them. Therefore, the esnext transformer would not be called on them and their children.

Fixes microsoft#16765.
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 27, 2017
Yogu added a commit to Yogu/TypeScript that referenced this issue Jun 27, 2017
Object literal elements that are neither spread elements, nor property assignments would not have visitNode called on them. Therefore, the esnext transformer would not be called on them and their children.

Fixes microsoft#16765.
Yogu added a commit to Yogu/TypeScript that referenced this issue Jun 27, 2017
@DanielRosenwasser DanielRosenwasser modified the milestones: TypeScript 2.5, Community Jun 27, 2017
@DanielRosenwasser DanielRosenwasser added the Help Wanted You can do this label Jun 28, 2017
@DanielRosenwasser DanielRosenwasser modified the milestones: TypeScript 2.5, Community Jun 28, 2017
Yogu added a commit to Yogu/TypeScript that referenced this issue Jun 28, 2017
Object literal elements that are neither spread elements, nor property assignments would not have visitNode called on them. Therefore, the esnext transformer would not be called on them and their children.

Fixes microsoft#16765.
Yogu added a commit to Yogu/TypeScript that referenced this issue Jun 28, 2017
Yogu added a commit to Yogu/TypeScript that referenced this issue Jul 5, 2017
Yogu added a commit to Yogu/TypeScript that referenced this issue Aug 13, 2017
Object literal elements that are neither spread elements, nor property assignments would not have visitNode called on them. Therefore, the esnext transformer would not be called on them and their children.

Fixes microsoft#16765.
Yogu added a commit to Yogu/TypeScript that referenced this issue Aug 13, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.5.1, TypeScript 2.5 Aug 16, 2017
@DanielRosenwasser
Copy link
Member

I currently can't repro this in master, but the PR should still be taken for the regression test.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 24, 2017
rbuckton pushed a commit that referenced this issue Aug 24, 2017
Object literal elements that are neither spread elements, nor property assignments would not have visitNode called on them. Therefore, the esnext transformer would not be called on them and their children.

Fixes #16765.
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

5 participants