Skip to content

[Bug]: Array.prototype.at parse wrong with babel/cli #112

Open
@lyz810

Description

@lyz810

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

case 1(wrong result)

function test() {
    this.array = [];
    var lastIndexOfArray = this.array.at(-1);
}

output:

import "core-js/modules/esnext.string.at.js"; // should be import "core-js/modules/es.array.at.js"

function test() {
  this.array = [];
  var lastIndexOfArray = this.array.at(-1);
}

case 2 (wrong result)

function test() {
    var array = [];
    var lastIndexOfArray = array.at(-1);
}

output(same as input, no core-js added):
function test() {
  var array = [];
  var lastIndexOfArray = array.at(-1);
}

case 3(parse as expected)

function test() {
    var string = '123';
    var lastIndexOfString = string.at(-1);
}

output:
import "core-js/modules/esnext.string.at.js";

function test() {
  var string = '123';
  var lastIndexOfString = string.at(-1);
}

case 4(parse as expected)

function test() {
    this.string = '123';
    var lastIndexOfString = string.at(-1);
}

output:
import "core-js/modules/esnext.string.at.js";

function test() {
  this.string = '123';
  var lastIndexOfString = string.at(-1);
}

Configuration file name

No response

Configuration

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "modules": false,
        "useBuiltIns": "usage",
        "targets": {
          "chrome": 43,
          "ios": 9,
          "edge": 80,
          "firefox": 60
        },
        "corejs": {
          "proposals": true,
          "version": 3
        }
      }
    ],
    "@babel/preset-react"
  ]
}

Current and expected behavior

add corejs es.array.at.js, not esnext.string.at.js

recognize Array.prototype.at

Environment

System:
OS: macOS 11.6.1
Binaries:
Node: 16.13.0 - /usr/local/bin/node
npm: 8.1.0 - /usr/local/bin/npm
npmPackages:
@babel/cli: ^7.16.8 => 7.16.8
@babel/core: ^7.16.7 => 7.16.7
@babel/eslint-parser: ^7.16.5 => 7.16.5
@babel/plugin-proposal-decorators: ^7.16.7 => 7.16.7
@babel/plugin-transform-runtime: ^7.16.8 => 7.16.8
@babel/preset-env: ^7.16.8 => 7.16.8
@babel/preset-react: ^7.16.7 => 7.16.7
@babel/preset-typescript: ^7.16.7 => 7.16.7
@babel/runtime: ^7.16.7 => 7.16.7
babel-jest: ^27.4.6 => 27.4.6
babel-preset-const-enum: ^1.0.0 => 1.0.0
eslint: ^8.6.0 => 8.6.0
jest: ^27.4.7 => 27.4.7

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions