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

rewriteThis in helper-module-transforms misses computed class elements #10784

Open
JLHwung opened this issue Nov 30, 2019 · 1 comment
Open

rewriteThis in helper-module-transforms misses computed class elements #10784

JLHwung opened this issue Nov 30, 2019 · 1 comment

Comments

@JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Nov 30, 2019

Bug Report

Current Behavior
The transformed code does not throw an expected error.

Input Code

export class C { [this.name]() {} }

Expected behavior/code
The transformed code should throw can not read property name of undefined. Because this is the top level context, which is undefined if the source type is module.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "plugins": ["@babel/plugin-transform-modules-commonjs"]
}

Environment


  System:
    OS: macOS 10.15.1
  Binaries:
    Node: 13.1.0 - /usr/local/bin/node
    Yarn: 1.19.2 - /usr/local/bin/yarn
    npm: 6.12.1 - /usr/local/bin/npm
  Monorepos:
    Lerna: 3.19.0
  npmPackages:
    @babel/cli: ^7.7.0 => 7.7.0 
    @babel/core: ^7.7.2 => 7.7.2 
    @babel/eslint-plugin-development: ^1.0.1 => 1.0.1 
    @babel/plugin-proposal-class-properties: ^7.7.0 => 7.7.0 
    @babel/plugin-proposal-export-namespace-from: ^7.5.2 => 7.5.2 
    @babel/plugin-proposal-nullish-coalescing-operator: ^7.4.4 => 7.4.4 
    @babel/plugin-proposal-numeric-separator: ^7.2.0 => 7.2.0 
    @babel/plugin-proposal-object-rest-spread: ^7.7.4 => 7.7.4 
    @babel/plugin-proposal-optional-chaining: ^7.6.0 => 7.6.0 
    @babel/plugin-transform-flow-strip-types: ^7.7.4 => 7.7.4 
    @babel/plugin-transform-for-of: ^7.7.4 => 7.7.4 
    @babel/plugin-transform-modules-commonjs: ^7.7.0 => 7.7.0 
    @babel/plugin-transform-runtime: ^7.6.2 => 7.6.2 
    @babel/preset-env: ^7.7.1 => 7.7.1 
    @babel/preset-flow: ^7.0.0 => 7.0.0 
    @babel/register: ^7.7.0 => 7.7.0 
    @babel/runtime: ^7.7.2 => 7.7.2 
    babel-eslint: ^11.0.0-beta.1 => 11.0.0-beta.1 
    babel-jest: ^24.9.0 => 24.9.0 
    babel-plugin-transform-charcodes: ^0.2.0 => 0.2.0 
    eslint: ^6.0.1 => 6.0.1 
    eslint-config-babel: ^9.0.0 => 9.0.0 
    gulp-babel: ^8.0.0 => 8.0.0 
    jest: ^24.9.0 => 24.9.0 
    lerna: ^3.19.0 => 3.19.0 
    rollup-plugin-babel: ^4.0.0 => 4.3.3 

Possible Solution

  1. Should traverse computed ClassMethod
  2. requeue the key child of ClassProperty if it is computed. This step is to fix the following case
export class C { [this.name] = 42 }
@babel-bot

This comment has been minimized.

Copy link
Collaborator

@babel-bot babel-bot commented Nov 30, 2019

Hey @JLHwung! 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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.