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

[Tree Shaking] Automatically mark known globals as pure. #1791

Closed
hyrious opened this issue Nov 22, 2021 · 1 comment
Closed

[Tree Shaking] Automatically mark known globals as pure. #1791

hyrious opened this issue Nov 22, 2021 · 1 comment

Comments

@hyrious
Copy link

hyrious commented Nov 22, 2021

Maybe tree-shaking can do more with this feature:

var a = new Map() // same as..
var a = /*@__PURE__*/new Map()

There's a list in rollup describing the info.

@evanw
Copy link
Owner

evanw commented Nov 24, 2021

Treating Map as pure is incorrect when map takes an argument. Rollup generates incorrect code by following the rules you linked to. For example, the following code is incorrectly deleted by Rollup even though it has side effects:

const x = new Map({
  [Symbol.iterator]() {
    return {
      next() {
        console.log('side effect')
        return { done: true }
      }
    }
  }
})

Here's a link to this code in Rollup's REPL.

Edit: Filed as a bug with Rollup here: rollup/rollup#4282.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants