Giter Site home page Giter Site logo

Problems Uglifying the code about deepdash HOT 9 CLOSED

yurigor avatar yurigor commented on May 19, 2024
Problems Uglifying the code

from deepdash.

Comments (9)

YuriGor avatar YuriGor commented on May 19, 2024

Hi, yeah, my linter also has complained about this...
But as you see, I heavily rely on variables from surrounding closure - it would be a pain to extract this function.
How do you think, if I'll create it like
let forChildren = function(....
will everybody be happy with it?

from deepdash.

richtera avatar richtera commented on May 19, 2024

The only thing I could think of is to put the function at the root of the parent function as a generator to add additional closures on it.

function genForChildren(options, deps, callback, currentObj, currentParents, /* put other closures here */) {
        return function forChildren(children, cp, scp) {
          if (children && _.isObject(children)) {
            _.forOwn(children, function(childValue, childKey) {
              var childPath = (path || []).concat( (cp || []), [childKey]);
              var strChildPath =
                options.pathFormat == 'array'
                  ? pathToString([childKey], strPath || '', scp || '')
                  : undefined;
              iterate({
                value: childValue,
                callback: callback,
                options: options,
                key: childKey,
                path: childPath,
                strPath: strChildPath,
                depth: depth + 1,
                parent: currentObj,
                parents: currentParents,
                obj: obj,
                childrenPath: cp,
                strChildrenPath: scp,
              });
            });
          }
        }
}

and then generate the function when you need it.
const fn = genForChildren(...)
I am sure there are a lot of different ways to this, but I agree this is something of a pain in the "strict" rule for javascript.

from deepdash.

YuriGor avatar YuriGor commented on May 19, 2024

Ok, I will see in a few days what can I do
(hope it's not show stopper for you)

from deepdash.

richtera avatar richtera commented on May 19, 2024

Currently I had to remove it from my project because I couldn't figure out a way to make it work in my webpack setup :-(

from deepdash.

YuriGor avatar YuriGor commented on May 19, 2024

Do you use deepdash-es with a webpack?

from deepdash.

richtera avatar richtera commented on May 19, 2024

I have not, I could check. Basically what happened was that our build suddenly broke and I traced it down to this module. I figured it would be good to know on your side and I have looked for a quick fix on my side. Will definitely check the -es version, we were using just "npm install deepdash" but I did not specifically configure webpack to use the es files. Thanks for all your help.

from deepdash.

YuriGor avatar YuriGor commented on May 19, 2024

I don't know if it will help with uglifier, but probably it should:
this 'strict' mode is actually added to cjs build by Rollup, and there is no strict directive in es version.
So hope uglifier will take it easier this time.

Another good reason to use es version is theoretically supported tree shaking.

btw I am going to fix this issue, maybe just by instructing rollup to not make things harder or I'll find some time for refactoring

from deepdash.

YuriGor avatar YuriGor commented on May 19, 2024

Could you, please share your config for uglifyi?
I tried here:
https://skalman.github.io/UglifyJS-online/
and with default options, it works well
If I set strict: true,
it fails on trailing comma in a literal object, not on in scope function declaration.

from deepdash.

YuriGor avatar YuriGor commented on May 19, 2024

Hey, I tried to replace function declaration by assignment it to variable and eslint was satisfied.
I don't think it will help in your case but let's try)
Another solution for you is to adjust uglifier setting and turn 'strict' option off (does it really brings any benefit?)
Anyway, I need to do great refactoring, maybe replace recursion by loop, etc,
so I will not try fix this particular issue, but will keep it in mind)

from deepdash.

Related Issues (20)

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.