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

FR: inline values even when the whole object is required #1098

Open
samouri opened this issue Oct 26, 2021 · 1 comment
Open

FR: inline values even when the whole object is required #1098

samouri opened this issue Oct 26, 2021 · 1 comment
Labels
compress Issue in the compression step discussion

Comments

@samouri
Copy link

samouri commented Oct 26, 2021

summary
I noticed that terser chooses not to inline values for objects where the whole object is retained.
Is that intentional?

For example given this the below input terser will aggressively inline the value.
Input:

var CardSuits = {
  HEARTS: 'hearts',
  DIAMONDS: 'diamonds',
  SPADES: 'spades',
  CLUBS: 'clubs',
};

console.log(CardSuits.HEARTS);

Output:

console.log('hearts');

Given input that requires the whole object be retained, terser will not inline.
Input:

var CardSuits = {
  HEARTS: 'hearts',
  DIAMONDS: 'diamonds',
  SPADES: 'spades',
  CLUBS: 'clubs',
};

console.log(CardSuits.HEARTS);
function printSuits(s) {
  for (const k in CardSuits) {
    console.log(k);
  }
}

printSuits();

Output:

var o = {
    HEARTS: "hearts",
    DIAMONDS: "diamonds",
    SPADES: "spades",
    CLUBS: "clubs"
};

console.log(o.HEARTS), function(s) {
    for (const s in o) console.log(s);
}();
@samouri samouri changed the title FR: inline values even when the whole object deopts FR: inline values even when the whole object is required Oct 26, 2021
@jridgewell jridgewell added compress Issue in the compression step discussion labels Oct 26, 2021
@samouri
Copy link
Author

samouri commented Oct 26, 2021

The ideal end state is likely to inline when the length of the value is <= the property name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compress Issue in the compression step discussion
Projects
None yet
Development

No branches or pull requests

2 participants