Skip to content

Functions, when exported later, then called, are unnecessairly inlined #1328

Open

Description

@tristan-f-r

Given the following:

function a() {
  return {
    some: "data"
  };
}

export const b = a()

export const c = a;

Terser will output the following code:

function a(){return{some:"data"}}export const b={some:"data"};export const c=a;

Expected:

function a(){return{some:"data"}}export const b=a();export const c=a;

Activity

  1. tristan-f-r commented on Dec 30, 2022

    @tristan-f-r
    Author
  2. changed the title [-]Functions when exported later, then called, are unnecessairly inlined[/-] [+]Functions, when exported later, then called, are unnecessairly inlined[/+] on Dec 30, 2022
  3. fabiosantoscode commented on Jan 2, 2023

    @fabiosantoscode
    Collaborator

    Interesting!

    This is a consequence of dead code elimination being 2-step: inline, then remove.

    If those 2 steps don't agree (inline thinks t() will be removed), it can cause duplicate code sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions