Skip to content

Import incorrect polyfills when use Array.prototype.includes and Array.prototype.at #7083

@Lancernix

Description

@Lancernix

Describe the bug

It seems swc imports incorrect polyfills when use Array.prototype.includes and Array.prototype.at.

Input code

const a = [1,2,3,4].includes(6);
const b = [2,3,4,5].at(-1);

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es3",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    "targets": "chrome 40",
    "mode": "usage",
    "coreJs": "3",
    "shippedProposals": true
  }
}

Playground link

https://play.swc.rs/?version=1.3.40&code=H4sIAAAAAAAAA0vOzysuUUhUsFWINtQx0jHWMYnVy8xLzilNSS3WMNO05koGK0gCKQBL65jG6iWWaOgaAuUANpZCiD0AAAA%3D&config=H4sIAAAAAAAAA0WO0QrCMAxFf0XyvAdB8WGfIAj%2BQumyrbI2JenEUfrvpnWytyT35HAzvMRCnyEaFuQ6yRaS%2BUAPaL0Ryy4m6BTT02gWwdJBMjxhqohcNFuIBPe0A%2B%2BCG7dqsuQjo8gRmTAtf7KoyNOw1kOGtEVswhuUw7H%2FOXnsYOJVdwzv9tNqqB7szOTxdD1Dc1bTKmZCXS0x3itTm8rsYsThyRRJ1P0TlvIFj0tslAcBAAA%3D

Expected behavior

import "core-js/modules/es.array.includes.js";
import "core-js/modules/esnext.array.at.js";
var a = [1,2,3,4].includes(6);
var b = [2,3,4,5].at(-1);

Actual behavior

import "core-js/modules/es.array.includes.js";
import "core-js/modules/es.string.includes.js";
import "core-js/modules/esnext.string.at.js";
var a = [1,2,3,4].includes(6);
var b = [2,3,4,5].at(-1);

Version

1.3.40

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions