Code Monkey home page Code Monkey logo

Comments (6)

Andarist avatar Andarist commented on May 19, 2024 1

@evan-scott-zocdoc If you want to use it on webpack's output I guess you are using it on application+lib bundle, due to the fact that it's probably a much bigger codebase than a single library I advise caution - but ofc you probably know that this is somewhat a little bit dangerous transform.

Tree-shaking is prevented mainly in cases of:

  • function calls, heavy fp usage (compose, curried functions etc) - latter should be quite safely fixed by this plugin
  • static properties, most common use case being classes - this one is out of scope of this plugin, I'm working (nearly finished) on the PR to babel which should improve the situation for those (will be available in future babel@7-betas)

And ofc enabling ModuleConcatenationPlugin can improve things quite a lot (worth noting this for other readers, you probably already know what :))

from babel-plugin-annotate-pure-calls.

Andarist avatar Andarist commented on May 19, 2024

1st issue reported by the community member 🎉

I guess leadingComments property is not set on the node (speaking totally from my gut, im in a travel on a mobile, havent checked the source code). I can guard against that ofc, but it's pretty interesting why this is not set. Thought it's always there, I remember someone mentioning something about similar case on Babel's Slack - need to dig into this.

Could you paste in the minimal repro file? Would love to examine how Babel handles it and of course to write a test for this.

from babel-plugin-annotate-pure-calls.

evan-scott-zocdoc avatar evan-scott-zocdoc commented on May 19, 2024

I think this would be enough?

const test = 'hello world';

/* eslint-disable babel/new-cap */
export default test;

from babel-plugin-annotate-pure-calls.

Andarist avatar Andarist commented on May 19, 2024

Fixed on the master (targeting babel@6) and released. Didn't make any changes to the babel-7 branch, because this deserves a fix upstream in babel itself IMHO. The situation should be normalized, even babel's typings does not make those fields optional.

Thanks for the report! Would love to hear how (where?) do you use the plugin.

from babel-plugin-annotate-pure-calls.

evan-scott-zocdoc avatar evan-scott-zocdoc commented on May 19, 2024

Thanks @Andarist, I'll try out the change.

I'm attempting to use this plugin as a way of overcoming the fact that webpack 3's treeshaking is broken.

from babel-plugin-annotate-pure-calls.

evan-scott-zocdoc avatar evan-scott-zocdoc commented on May 19, 2024

And ofc enabling ModuleConcatenationPlugin can improve things quite a lot

Definitely, we've been using that for a few months.

The specific target I'm trying to treeshake more efficiently is the so-called "re-export file", e.g. an index file that imports from many other files and re-exports under different names. In many cases, a person will import that index and destructure out a specific export, but all the other exports end up coming along for the ride anyway.

// index.js
export { default as a } from './a';
export { default as b } from './b';
export { default as c } from './c';

// some other file
import { a } from 'index.js';

// ideally b and c would be treeshaken

from babel-plugin-annotate-pure-calls.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.