madskristensen / BundlerMinifier

Visual Studio extension
Other
616 stars 173 forks source link

Not able to minify JavaScript with arrow function #489

Open rexxon-chuah opened 4 years ago

rexxon-chuah commented 4 years ago

Installed product versions

Description

Add a JavaScript with the following content:

class Person {
    function1 = () => {
        console.log("Hello, I am function1");
    }
}

BunderMinifier failed to minify the above code snippet. However, the minify works when the function1is rewritten in normal function syntax.

Steps to recreate

  1. Simply minify the above code snippet.

Current behavior

Two errors shown in Error List window.

(Bundler & Minifier) Expected '{': => (Bundler & Minifier) Expected '}'

Expected behavior

BundlerMinifier should be able to minify the arrow function.

jtsom commented 4 years ago

I just ran into this, but the error window had a very unhelpful Error:0 Stack Empty error.

TheoVC commented 4 years ago

I don't think your syntax is correct... variables should not be declared in class scope (yet) it should be...

class Person {
   constructor(){
     this.function1 = () => {
        console.log("Hello, I am function1");
    }
  }
}
TheoVC commented 4 years ago

or even better

class Person {
   function1(){
        console.log("Hello, I am function1");
    }
}
GitHubStan commented 4 years ago

I have this code that is being minified: const facilityId = vm.selectedFacility.FacilityId; const facilityData = deviceSettingForFacilities[facilityId].value; const record = facilityData.find((({ DeviceId }) => DeviceId === deviceId));

This is the minified code: const r=u.selectedFacility.FacilityId,f=e[r].value,o=f.find({DeviceId:n}=>n===i);

That produces this JavaScript error in Chrome: Uncaught SyntaxError: Malformed arrow function parameter list

In the minified code, adding in the parenthesis around {DeviceId:n}, like this ({DeviceId:n}), makes the error go away. Is there a work-around for this?

TheoVC commented 4 years ago

maybe ommiting the deconstruction..

const record = facilityData.find(((obj) => obj.DeviceId === deviceId));

or update the bundler minifier to last version, you have to update de extension manually. I don't know why the author do not upload new version to marketplace. http://vsixgallery.com/extension/a0ae318b-4f07-4f71-93cb-f21d3f03c6d3/,

jtsom commented 4 years ago

I have the version shown on that page - 3.2.447 - and get the "Error 0" error (if "source map" is enabled on a file), but it's a NuGet package, not an extension.