Skip to content
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

Babel fails to transpile class Foo { [someSymbol]: Foo; } #9189

Closed
jedwards1211 opened this issue Dec 14, 2018 · 1 comment · Fixed by #9190
Closed

Babel fails to transpile class Foo { [someSymbol]: Foo; } #9189

jedwards1211 opened this issue Dec 14, 2018 · 1 comment · Fixed by #9190
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@jedwards1211
Copy link
Contributor

jedwards1211 commented Dec 14, 2018

Bug Report

Notes
The following similar cases work:

  • class Foo { [someSymbol]: Bar }
  • class Foo { notASymbol: Foo }

The following cases fail:

  • class Foo { [someSymbol]: Foo }
  • class Foo { [someSymbol]: Array<Foo> }
  • class Foo { [someSymbol]: Foo.Bar }

Current Behavior

$ babel src/Test.js 
TypeError: Property id of GenericTypeAnnotation expected node to be of a type ["Identifier"] but instead got "SequenceExpression"
    at Object.validate (/Users/andy/flow-runtime/node_modules/@babel/types/lib/definitions/utils.js:129:13)
    at Object.validate (/Users/andy/flow-runtime/node_modules/@babel/types/lib/validators/validate.js:17:9)
    at NodePath._replaceWith (/Users/andy/flow-runtime/node_modules/@babel/traverse/lib/path/replacement.js:194:9)
    at NodePath.replaceWith (/Users/andy/flow-runtime/node_modules/@babel/traverse/lib/path/replacement.js:178:8)
    at Object.ReferencedIdentifier (/Users/andy/flow-runtime/node_modules/@babel/helper-create-class-features-plugin/lib/misc.js:66:12)
    at Object.newFn (/Users/andy/flow-runtime/node_modules/@babel/traverse/lib/visitors.js:230:17)
    at NodePath._call (/Users/andy/flow-runtime/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/Users/andy/flow-runtime/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/andy/flow-runtime/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/Users/andy/flow-runtime/node_modules/@babel/traverse/lib/context.js:118:16)

Input Code

/* @flow */
  
const ParentSymbol = Symbol();

class TypeContext {
  [ParentSymbol]: TypeContext;
}

Expected behavior/code
Transpiling succeeds

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    ["@babel/preset-env", {
      "targets": {
        "browsers": ["last 2 versions"]
      },
    }],
    "@babel/preset-react",
    "@babel/preset-flow"
  ],
  "plugins": [
    ["@babel/plugin-proposal-class-properties"]
  ]
}

Environment

  • Babel version(s): [7.2.0]
  • Node/npm version: [10.10.0]
  • OS: [macOS 10.14.1]
  • Monorepo: [Lerna]
  • How you are using Babel: all of the above (cli, register, and loader)
@babel-bot
Copy link
Collaborator

Hey @jedwards1211! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

jedwards1211 added a commit to jedwards1211/babel that referenced this issue Dec 14, 2018
…nericTypeAnnotation

Fix babel#9189

Obviously this code is intended to throw an error if someone tries to reference a class before it's defined, like:
```js
class Foo {
  someField = Foo;
}
```
But there's no problem with referencing the class in a type annotation before it's defined, and this is often necessary for tree structures:
```js
class Foo {
  [someSymbol]: Foo;
}
```
jedwards1211 added a commit to jedwards1211/babel that referenced this issue Dec 14, 2018
…nericTypeAnnotation

fix babel#9189

Obviously this code is intended to throw an error if someone tries to reference a class before it's defined, like:
```js
class Foo {
  someField = Foo;
}
```
But there's no problem with referencing the class in a type annotation before it's defined, and this is often necessary for tree structures:
```js
class Foo {
  [someSymbol]: Foo;
}
```
jedwards1211 added a commit to jedwards1211/babel that referenced this issue Dec 14, 2018
…nericTypeAnnotation

fix babel#9189

Obviously this code is intended to throw an error if someone tries to reference a class before it's defined, like:
```js
class Foo {
  someField = Foo;
}
```
But there's no problem with referencing the class in a type annotation before it's defined, and this is often necessary for tree structures:
```js
class Foo {
  [someSymbol]: Foo;
}
```
jedwards1211 added a commit to jedwards1211/babel that referenced this issue Dec 15, 2018
…peAnnotation

fix babel#9189

Obviously this code is intended to throw an error if someone tries to reference a class before it's defined, like:
```js
class Foo {
  someField = Foo;
}
```
But there's no problem with referencing the class in a type annotation before it's defined, and this is often necessary for tree structures:
```js
class Foo {
  [someSymbol]: Foo;
}
```
nicolo-ribaudo pushed a commit that referenced this issue Dec 15, 2018
…peAnnotation (#9190)

fix #9189

Obviously this code is intended to throw an error if someone tries to reference a class before it's defined, like:
```js
class Foo {
  someField = Foo;
}
```
But there's no problem with referencing the class in a type annotation before it's defined, and this is often necessary for tree structures:
```js
class Foo {
  [someSymbol]: Foo;
}
```
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 16, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
2 participants