Microbundle: Mangling function prototypes (AKA class methods) possible?

Created on 3 Jan 2019  Â·  6Comments  Â·  Source: developit/microbundle

This may be a better question for terser, but seeing as I'm using it through microbundle, I figured I'd start here. 😅

With the current (undocumented) mangling options available in microbundle, is it possible to tell terser to mangle Function prototypes? (To be clear, this is how I'm writing it, but I know it turns back into a pumpkin/Function once buble makes its pass.)

class Hello {
  constructor(name) {
    this.name = name;
  }

  sayName() {
    console.log(this.allCaps_(this.name));
  }

  allCaps_(str) { // I want *this* to get mangled away
    return str.toUpperCase();
  }
}

I tried to add this to my package.json but had no luck. (If the problem is my regex I shall live in shame forever.)

{
  "mangle": {
    "regex": "/_$/"
  }
}
question

All 6 comments

FWIW — I could get it to hulk smash everything by passing this in, so at a minimum I've found one way to reach into that Function and mangle away, now just have to stop it from smashing everything. 😎

{
  "mangle": {}
}

May have figured it out?

I think my extra slashes were doing it. This finally took:

{
  "mangle": {
    "regex": "_$"
  }
}

oh yeah, you probably don't want those slashes in a string

I've added docs to the readme explaining this :)

@developit Awesome, thanks!

Though I have noticed something I don't quite understand — I get an empty file called mangle.json output into my root directory, but (so far) I've never seen it be anything other than {}. Should it be doing that at all? Should I be committing it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wcastand picture wcastand  Â·  16Comments

phryneas picture phryneas  Â·  12Comments

scttcper picture scttcper  Â·  11Comments

pBread picture pBread  Â·  15Comments

smithki picture smithki  Â·  19Comments