jmrocela / munchjs

munch.js is a utility that rewrites classes and ids in CSS, HTML, and JavaScript files in order to save precious bytes and obfuscate your code. based on http://htmlmuncher.com
http://jmrocela.github.io/munchjs/
MIT License
85 stars 12 forks source link

["Solved"] missing setters parameters in jQuery`s JSDom lib #25

Open rafaelnco opened 8 years ago

rafaelnco commented 8 years ago

All the following functions can be found in jsdom level1/core.js file and fire an error when munchjs is executed.

level1/core.js:

set nodeName() { throw new core.DOMException();},
...
set lastChild() { throw new core.DOMException();},
...
set childNodes() { throw new core.DOMException();},
...
 set nextSibling() { throw new core.DOMException();},
...

Is there anyone who can help me with this?

Thanks in advance

arlusf commented 8 years ago

Generally speaking, you can't munch stuff that calls another library unless that can also be munched at the same time (does not always work, some things can't be munched properly with the current implementation). If what you use is already minimized, you should not spend too much time munching if it isn't working right. There is a way to exclude a list of keywords, if this makes sense for your situation? For instance, in the case of jquery there is a known list of keywords to exclude for everything to function properly. This is all from memory, I hope I have not made too much of an error. Regards, Arlus

On Sun, Jan 17, 2016 at 9:00 AM, Rafael Natã notifications@github.com wrote:

All the following functions can be found in jsdom level1/core.js file and fire an error when munchjs is executed.

level1/core.js:

set nodeName() { throw new core.DOMException();}, ... set lastChild() { throw new core.DOMException();}, ... set childNodes() { throw new core.DOMException();}, ... set nextSibling() { throw new core.DOMException();}, ...

Is there anyone who can help me with this?

Thanks in advance

— Reply to this email directly or view it on GitHub https://github.com/jmrocela/munchjs/issues/25.

arlusf commented 8 years ago

Also, there is one basic fix to munch that others have published, it is the same in every case because it is needed. I can't remember but maybe did you also contribute to the repo?

On Mon, Jan 18, 2016 at 12:44 AM, Arlus Potter arlus.fp@gmail.com wrote:

On the other hand, munch does not recognize the full set of keywords, only the mostly used ones. If you wish to add support for more keywords, that is possible.

On Mon, Jan 18, 2016 at 12:40 AM, Arlus Potter arlus.fp@gmail.com wrote:

Generally speaking, you can't munch stuff that calls another library unless that can also be munched at the same time (does not always work, some things can't be munched properly with the current implementation). If what you use is already minimized, you should not spend too much time munching if it isn't working right. There is a way to exclude a list of keywords, if this makes sense for your situation? For instance, in the case of jquery there is a known list of keywords to exclude for everything to function properly. This is all from memory, I hope I have not made too much of an error. Regards, Arlus

On Sun, Jan 17, 2016 at 9:00 AM, Rafael Natã notifications@github.com wrote:

All the following functions can be found in jsdom level1/core.js file and fire an error when munchjs is executed.

level1/core.js:

set nodeName() { throw new core.DOMException();}, ... set lastChild() { throw new core.DOMException();}, ... set childNodes() { throw new core.DOMException();}, ... set nextSibling() { throw new core.DOMException();}, ...

Is there anyone who can help me with this?

Thanks in advance

— Reply to this email directly or view it on GitHub https://github.com/jmrocela/munchjs/issues/25.

arlusf commented 8 years ago

I could take a look at a short example of the error if you like. With the munch command, the example munched file and the munched library file.

On Mon, Jan 18, 2016 at 12:48 AM, Arlus Potter arlus.fp@gmail.com wrote:

Also, there is one basic fix to munch that others have published, it is the same in every case because it is needed. I can't remember but maybe did you also contribute to the repo?

On Mon, Jan 18, 2016 at 12:44 AM, Arlus Potter arlus.fp@gmail.com wrote:

On the other hand, munch does not recognize the full set of keywords, only the mostly used ones. If you wish to add support for more keywords, that is possible.

On Mon, Jan 18, 2016 at 12:40 AM, Arlus Potter arlus.fp@gmail.com wrote:

Generally speaking, you can't munch stuff that calls another library unless that can also be munched at the same time (does not always work, some things can't be munched properly with the current implementation). If what you use is already minimized, you should not spend too much time munching if it isn't working right. There is a way to exclude a list of keywords, if this makes sense for your situation? For instance, in the case of jquery there is a known list of keywords to exclude for everything to function properly. This is all from memory, I hope I have not made too much of an error. Regards, Arlus

On Sun, Jan 17, 2016 at 9:00 AM, Rafael Natã notifications@github.com wrote:

All the following functions can be found in jsdom level1/core.js file and fire an error when munchjs is executed.

level1/core.js:

set nodeName() { throw new core.DOMException();}, ... set lastChild() { throw new core.DOMException();}, ... set childNodes() { throw new core.DOMException();}, ... set nextSibling() { throw new core.DOMException();}, ...

Is there anyone who can help me with this?

Thanks in advance

— Reply to this email directly or view it on GitHub https://github.com/jmrocela/munchjs/issues/25.

rafaelnco commented 8 years ago

**TL;DR: I'm actually referring to the jquery 1.8.3 lib used by munchjs, not about munching jquery! Also, I'm using 2 fixes:

  1. I've modified jsdom's source code, adding the required parameters (mentioned here)
  2. I've modified munchjs souce code, adding the fix described here**

Hey @arlusf, thank you very much for your interest! I've detailed the issue here. I guess you've misinterpreted my issue with jQuery, as I'm referring to the one used internally by munchjs and, more specifically, to the jsdom 0.6.5 lib used by jquery 1.8.3, which is used by munch js. So, I'm not really talking about munching jquery, but instead I'm talking about the jquery 1.8.3 lib used by munchjs. Sorry for all this confusion!

Here's my current scenario:

$ cd ~
$ git clone https://github.com/jmrocela/munchjs.git
$ npm install -g .

note the . at the end of the line

note:

    "jquery": "~1.8.3",
    "jsdom": "~0.6.5"
$ cd /w/quickstart/src
$ munch --view index.html

The output is:

/usr/lib/node_modules/munch/node_modules/jquery/node_modules/jsdom/lib/jsdom/level1/core.js:418
set nodeName() { throw new core.DOMException();},
              ^^

SyntaxError: Setter must have exactly one formal parameter.
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/node_modules/munch/node_modules/jquery/node_modules/jsdom/lib/jsdom/level2/core.js:1:94)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
rafaelnco commented 8 years ago

Also, I have not contributed to the repo yet but got many ideas to extending munchjs.rewriteJsString regexes!

rafaelnco commented 8 years ago

I've solved this by manually entering the missing parameters in the setters functions.