Commit Graph

73 Commits

Author SHA1 Message Date
kzc
4d2f7d83af Fix handling of "use asm" when no command line flags are passed to uglifyjs. SCOPE_IS_NEEDED is unconditionally true now. Refactored floating point literal parsing to be more in keeping with the AST class design. 2015-10-07 13:10:53 -04:00
Mihai Bazon
99233c44cc No longer use vm to load code.
Improves performance 2x on node > 0.10.

Ref #636
2015-09-24 17:58:51 +03:00
Mihai Bazon
33528002b4 Fix wrap_commonjs to include code first
(code could have directives, i.e. "use strict")
2015-09-24 17:58:51 +03:00
Mihai Bazon
fbbaa42ee5 Add option to preserve/enforce string quote style
`-q 0` (default) use single or double quotes such as to minimize the number of
 bytes (prefers double quotes when both will do); this is the previous
 behavior.

`-q 1` -- always use single quotes

`-q 2` -- always use double quotes

`-q 3` or just `-q` -- always use the original quotes.

Related codegen option: `quote_style`.

Close #495
Close #460

Some `yargs` guru please tell me why `uglifyjs --help` doesn't display the
help string for `-q` / `--quotes`, and why it doesn't output the expected
argument types anymore, like good old `optimist` did.
2015-01-27 22:26:27 +02:00
Ingvar Stepanyan
ae5366a31d Track ending lines/columns; fix end locations in Mozilla AST. 2015-01-06 11:32:41 +01:00
Mihai Bazon
6b23cbc852 AST_Do nodes: walk body before condition 2015-01-06 12:29:07 +02:00
Arnavion
e2e09d5754 Allow colons in the pairs passed to AST_Toplevel.wrap_enclose 2014-03-22 18:02:21 -07:00
Mihai Bazon
8f35a363d9 AST_Catch shouldn't really inherit from AST_Scope. Fix #363
I hereby acknowledge that figure_out_scope has become a mess.
2013-12-05 13:30:29 +02:00
Mihai Bazon
d2190c2bf3 Properly scope catch identifier when --screw-ie8
Fix #344
2013-11-28 16:43:30 +02:00
Mihai Bazon
c5ed2292bf Fix parsing setters/getters (allow keywords for name).
The "key" property was always "set" or "get", which didn't make much sense.
Now it'll be the actual name of the setter/getter (AST_Node), and the
AST_Accessor object itself, which represents the function, won't store any
name.

Close #319
2013-10-30 11:50:22 +02:00
Mihai Bazon
cb9d16fbe4 minor 2013-09-06 09:52:56 +03:00
Mihai Bazon
5d8da864c5 Fix names. 2013-09-02 19:38:00 +03:00
Mihai Bazon
85b527ba3d Disallow continue referring to a non-IterationStatement. Fix #287
Simplifies handling of labels (their definition/references can be easily
figured out at parse time, no need to do it in `figure_out_scope`).
2013-09-02 19:36:16 +03:00
Mihai Bazon
02a84385a0 Don't swap binary ops when "use asm" is in effect.
Refs #167
2013-06-07 12:52:09 +03:00
Jake Harding
478bf4dbdd Add support for enclose option. Closes #139. 2013-03-24 11:11:23 +02:00
David Glasser
1529ab965a Fix output for arrays containing undefined values.
1b6bcca7 was a first attempt at this. That commit made Uglify stop replacing
holes with undefined, but instead it started replacing undefined with
holes. This is slightly problematic, because there is a difference between a
hole and an undefined value. More problematically, it changed [1,undefined] to
[1,] which generally doesn't even parse as a hole (just as a trailing comma), so
it didn't even preserve the length of the array!

Instead, parse holes as their own special AST node which prints invisibly.
2013-01-17 11:36:10 +02:00
Mihai Bazon
13c4dfcabd fix #55 2012-11-24 10:02:08 +02:00
Mihai Bazon
1e5e13ed81 AST_LabelRef no longer inherits from AST_SymbolRef 2012-11-08 15:39:14 +02:00
Mihai Bazon
5276a4a873 add AST_Accessor and AST_SymbolAccessor node types
AST_Accessor will represent the function for a setter or getter.  Since they
are not mangleable, and they should not introduce a name in scope, we have a
new node for their name (AST_SymbolAccessor) which doesn't inherit from
AST_SymbolDeclaration.

fix #37
2012-11-07 12:43:27 +02:00
Mihai Bazon
30faaf13ed more sequence optimizations (lift some sequences above binary/unary expressions so that we can avoid parens) 2012-10-22 11:58:06 +03:00
Mihai Bazon
afb7faa6fa more optimizations for some break/continue cases 2012-10-18 15:14:57 +03:00
Mihai Bazon
1b6f8d463f remove the $self hack
operations are destructive anyway, so there's no point to clone the nodes in
the transformer.  speed++
2012-10-12 11:07:35 +03:00
Mihai Bazon
72cb5328ee fix in_boolean_context() (two tests were broken) 2012-10-12 10:49:41 +03:00
Mihai Bazon
172aa7a93c cleanup
- use prototype-less objects where feasible (minor speed improvement)
- get rid of HOP
2012-10-11 11:07:42 +03:00
Mihai Bazon
9cdaed9860 fix node name 2012-10-10 23:16:40 +03:00
Mihai Bazon
dacce1b1fa seems cleaner if AST_Label doesn't inherit from AST_SymbolDeclaration 2012-10-10 11:37:51 +03:00
Mihai Bazon
f26f3b44bc small improvements in wrap_commonjs:
- use MAP.splice instead of a BlockStatement to inject code (avoids some
  warnings in the linter)
- use the original symbol in exports, so that we get the proper source mapping
2012-10-10 11:28:05 +03:00
Mihai Bazon
a84d07e312 add AST_Infinity node 2012-10-09 18:35:53 +03:00
Mihai Bazon
1b0aab2ce9 added $propdoc to AST nodes and some cleanups
hopefully we can make the AST documentation self-generating
2012-10-09 18:20:39 +03:00
Mihai Bazon
9ead49641d minor AST cleanup (AST_BlockStatement may inherit from AST_Block) 2012-10-09 13:59:17 +03:00
Mihai Bazon
e1862cd36f add --ast-help
displays a rather cruel description of the AST classes, derived
directly from the node definitions.
2012-10-09 13:21:21 +03:00
Mihai Bazon
dd8286bce1 added --self to easily get a browser-runnable version of UglifyJS 2012-10-08 12:55:18 +03:00
Mihai Bazon
11863d6f9a more cleanup (dropped AST_SwitchBlock) 2012-10-03 15:52:31 +03:00
Mihai Bazon
3412498795 AST cleanup (dropped AST_StatementBase) 2012-10-03 15:41:11 +03:00
Mihai Bazon
e1098b04a7 "use strict"; 2012-10-02 12:45:58 +03:00
Mihai Bazon
347160c631 add AST_SymbolConst for names defined with const 2012-10-02 12:22:39 +03:00
Mihai Bazon
896444482a minor 2012-09-28 11:12:47 +03:00
Mihai Bazon
a24e7ee976 checkpoint (refactoring, WIP) 2012-09-26 12:16:16 +03:00
Mihai Bazon
a83b28503f properly drop mutually-referring declarations that are not otherwise
referenced and have no side effects
2012-09-23 12:47:34 +03:00
Mihai Bazon
5491e1d7b1 better support for multiple input files:
- use a single AST_Toplevel node for all files
- keep original source filename in the tokens
2012-09-21 14:19:05 +03:00
Mihai Bazon
a4d2340c73 fixed label scope/mangling 2012-09-18 19:26:46 +03:00
Mihai Bazon
3da0ac4897 support for directives 2012-09-18 13:21:09 +03:00
Mihai Bazon
21968285e8 added AST_NaN (output as 0/0) 2012-09-18 10:53:46 +03:00
Mihai Bazon
4e0262bdfb figure out label targets 2012-09-15 16:05:17 +03:00
Mihai Bazon
924aa58060 more optimizations that v1 does and some cleanups
- a = a + x ==> a+=x
- joining consecutive var statements (hoisting is not always desirable)
- x == false ==> x == 0, x != true ==> x != 1
- x, x ==> x; x = exp(), x ==> x = exp()
- discarding useless break-s
2012-09-14 15:36:38 +03:00
Mihai Bazon
8e82d8d94c fixed some mess with symbols/scope
- all symbols now have a `thedef` property which is a SymbolDef object,
  instead of the `uniq` that we had before (pointing to the first occurrence
  of the name as declaration).

- for undeclared symbols we still create a SymbolDef object in the toplevel
  scope but mark it "undeclared"

- we can now call figure_out_scope after squeezing, which is useful in order
  not to mangle names that were dropped by the squeezer
2012-09-11 15:42:28 +03:00
Mihai Bazon
43c75c9248 checkpoint 2012-09-07 18:55:13 +03:00
Mihai Bazon
b77574ea1c fixed tests (need to drop the toplevel block in "expected" if it's a single statement) 2012-09-07 11:22:01 +03:00
Mihai Bazon
8633b0073f cleaned up usage of AST_BlockStatement
The following nodes were instances of AST_BlockStatement: AST_Scope,
AST_SwitchBlock, AST_SwitchBranch.  Also, AST_Try, AST_Catch, AST_Finally
were having a body instanceof AST_BlockStatement.

Overloading the meaning of AST_BlockStatement this way turned out to be a
mess; we now have an AST_Block class that is the base class for things
having a block of statements (might or might not be bracketed).  The
`this.body` of AST_Scope, AST_Try, AST_Catch, AST_Finally is now an array of
statements (as they inherit from AST_Block).

Avoiding calling superclass's _walk function in walkers (turns out we walked
a node multiple times).
2012-09-05 11:39:43 +03:00
Mihai Bazon
f702264617 jumps, try and definitions are statements too 2012-09-03 12:39:02 +03:00