Skip to content
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

describe a few compiler assumptions #2883

Merged
merged 6 commits into from Feb 6, 2018

Conversation

Skalman
Copy link
Contributor

@Skalman Skalman commented Feb 4, 2018

My addition rendered

I've created a new README section to describe some of the compiler assumptions. I'd appreciate any suggestions of clarifications.

In particular, I'm unsure about the factual accuracy of the last couple of bullet points:

  • Getting and setting properties on a plain object does not cause other side effects (using .watch() or Proxy).
  • Object properties are able to be added (not prevented with Object.defineProperty(), Object.defineProperties(), Object.freeze() or Object.preventExtensions()).

@kzc
Copy link
Contributor

kzc commented Feb 4, 2018

Since you're editing the README, could you please drop this in the Source Map section?

#2876 (comment)

Edit: perhaps under a new section called "Source Maps and Debugging" at the bottom of the README.

@alexlamsl
Copy link
Collaborator

@kzc if you are going to add that source map text, please combine it with https://github.com/mishoo/UglifyJS2#uglify-fast-minify-mode - no need to have more than one place describing non-default usage.

@Skalman other than missing .seal(), the rest LGTM.

@kzc
Copy link
Contributor

kzc commented Feb 5, 2018

"Uglify breaks debugging with source maps" is the single most frequently created issue in bundler wrapper projects. The explanation doesn't belong in the fast minify mode section - it's completely unrelated. It's up to @Skalman if he wants to add it.

@Skalman
Copy link
Contributor Author

Skalman commented Feb 5, 2018

I added the note on source maps to the bottom of the readme. Let me know if I should move it.

@kzc
Copy link
Contributor

kzc commented Feb 5, 2018

LGTM

README.md Outdated
`Error.prototype.stack` to be anything in particular.
- Getting and setting properties on a plain object does not cause other side effects
(using `.watch()` or `Proxy`).
- Object properties are able to be added (not prevented with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object properties can be added, removed and modified (or writeable as they call it).

are known to have an adverse effect on debugging with source maps. This is
expected as code is optimized and mappings are often simply not possible as
some code no longer exists. For highest fidelity in source map debugging
disable the Uglify `compress` option and just use `mangle`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just combine this with Uglify Fast Minify Mode above - no point having a seperate section talking about non-default option usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it is unrelated to Uglify Fast Minify. This source map debugging section would benefit with its own heading so it is externally linkable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexlamsl, I'm not sure I think that makes sense. That section doesn't include anything about source maps nor debugging.

To me it seems like multiple sections under "Miscellaneous" talk about non-default option usage, including Using native Uglify AST with minify(), ESTree / SpiderMonkey AST, and Use Acorn for parsing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes more sense to mention under Uglify Fast Minify that when somebody is terminally confused by a debugger, this option would also be useful.

I am against text dedicated to non-default usage in general because it will cause some people go for it based on misplaced beliefs, e.g. keep_infinity in #2743 - and then in return we get weird complaints when things don't work the way they expect it to, e.g. #2856

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that you're against any information on source maps? If the text were to be combined with an existing section, I'd suggest "CLI source map options".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options are provided and documented so that people can use them as they see fit. Source map use with uglify is extremely common - particularly when Uglify is used with bundlers.

This paragraphs warrants it own section with a heading as it is a frequently asked question. It may be underneath Uglify Fast Minify with a smaller heading if you prefer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that you're against any information on source maps?

Not at all - just not worth attracting unwarranted attention to it.

Source map use with uglify is extremely common.

Confusion when using a debugger isn't as common amongst programmers.

It may be underneath Uglify Fast Minify with a smaller heading if you prefer.

That would at least be better - thanks.

README.md Outdated

### Compiler assumptions

To allow for better optimizations, the compiler makes various assumptions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace the period at the end of the line with a colon.

README.md Outdated

To allow for better optimizations, the compiler makes various assumptions.

- `.toString()` and `.valueOf()` have not been overridden, and don't have side effects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString() can be overridden in new functions/classes - it just cannot have side effects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggestion for how to phrase this? My take:

.toString() and .valueOf() don't have side effects, and for built-in objects they have not been overridden.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... only if unsafe is not specified, though I guess that's covered under https://github.com/mishoo/UglifyJS2#the-unsafe-compress-option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a0d408e is good.

@kzc
Copy link
Contributor

kzc commented Feb 5, 2018

The section on unsafe is quite out of date. It should mention that the unsafe compress option is actually considered to be safe for sane code that does not modify builtin JavaScript functions and classes. For example, unsafe is not suitable for polyfills.

It also would be good to demonstrate an advanced unsafe test case in that section. For example:

$ cat test.js
var s = [ "C", "A", "T" ].join("_");
console.log(s.replace(/_/g, ""));
$ bin/uglifyjs test.js --toplevel -c unsafe,passes=2
console.log("CAT");

@Skalman
Copy link
Contributor Author

Skalman commented Feb 5, 2018

I'm not planning on adding information about unsafe at this point, but I agree that an update would be nice.

@kzc
Copy link
Contributor

kzc commented Feb 5, 2018

I'm not planning on adding information about unsafe at this point, but I agree that an update would be nice.

No worries. Leave that for someone else.

@kzc
Copy link
Contributor

kzc commented Feb 5, 2018

@alexlamsl OT - do you recall why these two functions were not included with unsafe?

$ echo 'console.log("Abc".toUpperCase(), "Xyz".toLowerCase());' | node0_10_41 
ABC xyz
$ echo 'console.log("Abc".toUpperCase(), "Xyz".toLowerCase());' | bin/uglifyjs -c unsafe
console.log("Abc".toUpperCase(),"Xyz".toLowerCase());

They both are available in node 0.10.

Do they throw or have some side effect or something?

@kzc
Copy link
Contributor

kzc commented Feb 5, 2018

Perhaps toUpperCase and toLowerCase are affected by the locale?

@alexlamsl
Copy link
Collaborator

alexlamsl commented Feb 5, 2018

@kzc Turkish i? 😏

Edit: looks like you've just figured it out 😉

@Skalman
Copy link
Contributor Author

Skalman commented Feb 5, 2018

@kzc
Copy link
Contributor

kzc commented Feb 5, 2018

They even mention Turkish explicitly :-)

The toLocaleLowerCase() method returns the value of the string converted to lower case according to any locale-specific case mappings. toLocaleLowerCase() does not affect the value of the string itself. In most cases, this will produce the same result as toLowerCase(), but for some locales, such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may be a different result.

@alexlamsl
Copy link
Collaborator

alexlamsl commented Feb 5, 2018

I remember seeing polyfill for toLoweCase() before. In any case, just found a list of these characters:
https://gist.github.com/barlas/760cbf77b31c6922d159

I'll test them on various platforms after some sleep – and if it turns out they all work as expected, then a PR for unsafe evaluate.

@alexlamsl alexlamsl merged commit cb0257d into mishoo:master Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants