Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,26 @@ To enable fast minify mode with the API use:
```js
UglifyJS.minify(code, { compress: false, mangle: true });
```

### Compiler assumptions

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

Copy link
Copy Markdown
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.


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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a0d408e is good.

- `undefined`, `NaN` and `Infinity` have not been externally redefined.
- `arguments.callee`, `arguments.caller` and `Function.prototype.caller` are not used.
- The code doesn't expect the contents of `Function.prototype.toString()` or
`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
Copy Markdown
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).

`Object.defineProperty()`, `Object.defineProperties()`, `Object.freeze()`,
`Object.preventExtensions()` or `Object.seal()`).

### Source maps and debugging

Various `compress` transforms that simplify, rearrange, inline and remove code
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.