New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubles with UglifyJS #7

Closed
kud opened this Issue Oct 5, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@kud

kud commented Oct 5, 2017

I just added your lib to my app as I need it. And after some checks, I just saw that Uglify does not like this line in my app:

/***/ (function(module, exports, __webpack_require__) {

"use strict";

module.exports = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);


/***/ }),

which is your lib.

I've got this error:

ERROR in index.884a774e80700a169db9.js from UglifyJs
Unexpected token: operator (>) [index.884a774e80700a169db9.js:75386,22]

I know it's not directly the fault of this lib but do you have any idea why I've got this problem?

@kud

This comment has been minimized.

Show comment
Hide comment
@kud

kud Oct 5, 2017

Apparently it's because arrow func aren't supported and babel doesn't compile external libs, so => doesn't work. I'll check that.

kud commented Oct 5, 2017

Apparently it's because arrow func aren't supported and babel doesn't compile external libs, so => doesn't work. I'll check that.

@kud

This comment has been minimized.

Show comment
Hide comment
@kud

kud Oct 5, 2017

Okay, that's it.

My babel config compiles my code from es6 or es7 to es5 but not external libs.

So for the moment, I've created a lib/index.js file and have:

const strictUriEncode = (str) => {
 return encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`)
}

export { strictUriEncode }

:D

kud commented Oct 5, 2017

Okay, that's it.

My babel config compiles my code from es6 or es7 to es5 but not external libs.

So for the moment, I've created a lib/index.js file and have:

const strictUriEncode = (str) => {
 return encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`)
}

export { strictUriEncode }

:D

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva Oct 5, 2017

Owner

We aim for Node.js, not the browser. You can find a more detailed explanation here sindresorhus/ama#446.

If you use Webpack, check out babel-engine-plugin, which transpiles only the dependencies that needs to be transpiled.

Owner

kevva commented Oct 5, 2017

We aim for Node.js, not the browser. You can find a more detailed explanation here sindresorhus/ama#446.

If you use Webpack, check out babel-engine-plugin, which transpiles only the dependencies that needs to be transpiled.

@kevva kevva closed this Oct 5, 2017

@kud

This comment has been minimized.

Show comment
Hide comment
@kud

kud Oct 5, 2017

I understand your point of view but I wanted to use your lib as https://github.com/sindresorhus/query-string already uses it and it works like a charm in my browser.

I'll check babel-engine-plugin thanks.

By the way, it's a bit shame not to support browser no? as

1/ it's exactly the same code
2/ it's quite the point of npm/browserify, etc

Anyway thank you for your time! :)

kud commented Oct 5, 2017

I understand your point of view but I wanted to use your lib as https://github.com/sindresorhus/query-string already uses it and it works like a charm in my browser.

I'll check babel-engine-plugin thanks.

By the way, it's a bit shame not to support browser no? as

1/ it's exactly the same code
2/ it's quite the point of npm/browserify, etc

Anyway thank you for your time! :)

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva Oct 6, 2017

Owner

In this case, it's more an issue with Uglify not supporting anything but ES5 code than anything else. The code should work in the browser out of the box.

Owner

kevva commented Oct 6, 2017

In this case, it's more an issue with Uglify not supporting anything but ES5 code than anything else. The code should work in the browser out of the box.

@kud

This comment has been minimized.

Show comment
Hide comment
@kud

kud Oct 6, 2017

You're perfectly right. Thank you. :)

kud commented Oct 6, 2017

You're perfectly right. Thank you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment