38 Commits

Author SHA1 Message Date
Conrad Irwin
2de16b8cb0 [loose parser] Fix interpretation of f."
Before this the ast produced by parse_dammit crashed in the following
code, as Uglify correctly noticed that f."" is invalid.

    sample = 'f."';

    loose = require('acorn/acorn_loose');
    uglify = require('uglify-js');

    out = new uglify.OutputStream();
    ast = loose.parse_dammit(sample);
    ast = uglify.AST_Node.from_mozilla_ast(ast);
    ast.print(out);
    // TypeError: Cannot call method 'toString' of undefined
    // member_exp.computed = false && member_exp.property == ""

    console.log(out.toString());

After this the round-tripped AST looks like: `t.✖;"";`, which is
consistent with how `foo.{` is parsed.

I also considered making it parse as t[""], but as this only turns up in
the wild when people try to use multiline strings, I felt it was better
to be obviously wrong.
2014-04-17 23:03:18 +02:00
Marijn Haverbeke
4869ccfa55 Prevent loose parser from tripping on invalid regexps
Issue #39
2014-03-25 17:45:58 +01:00
Marijn Haverbeke
93124c9eb8 Don't export Node from loose parser, reuse existing Node's proto
Issue #92
2014-03-25 17:31:03 +01:00
Marijn Haverbeke
e5439847fd Rename remaining *_t constructors to something sane 2014-03-25 17:29:17 +01:00
David Bonnet
7b9a46710d Renamed node_t to Node and exported it
This is to let programmers extend the Node object with utility methods
2014-03-25 17:23:30 +01:00
Marijn Haverbeke
d973261940 [loose parser] Make sure VariableDeclaration nodes have at least one decl
Closes marijnh/tern#255
2013-12-09 17:55:16 +01:00
Marijn Haverbeke
356e0be759 Add directSourceFile option 2013-10-15 13:08:56 +02:00
Marijn Haverbeke
2ace0fa8dc Further refine parseExprList indentation heuristic
Closes marijnh/tern#221
2013-08-27 12:52:02 +02:00
Jürg Lehni
097b4162da Pass on 'this' as root scope, for better inclusion of Acorn inside Paper.js
Use same approach as Esprima.
2013-07-26 08:59:07 +02:00
Marijn Haverbeke
328d0e514c Linting 2013-07-08 09:07:10 +02:00
Marijn Haverbeke
2372b12df7 [loose parser] Refine closing heuristic for expression lists
Issue marijnh/tern#171
2013-06-10 18:02:17 +02:00
Marijn Haverbeke
3ca3aa5a25 Run a lint pass, clean up lots of small issues 2013-06-10 16:52:22 +02:00
Marijn Haverbeke
6fe123947b Prefix keywords with underscore in tokTypes object 2013-06-10 15:47:29 +02:00
Marijn Haverbeke
6dd35f870a [loose parser] Fix bug in continued-expression closing
When the continued expression sat on column 1 after a non-whitespace char,
the heuristic would consider it the start of the line, even though it wasn't.

Issue marijnh/tern#141
2013-05-15 12:03:00 +02:00
Marijn Haverbeke
9eee5300db [loose parser] Less aggressive termination heuristic for comma-separated lists
See https://github.com/marijnh/tern/issues/118
2013-05-08 15:21:25 +02:00
Marijn Haverbeke
4d8eeabf52 In browser loader, refer to global object as 'this', not 'self'
Closes #41
2013-05-08 15:16:06 +02:00
Marijn Haverbeke
f3c70d76ef Remove assignment to non-existing var 2013-04-03 15:05:00 +02:00
Marijn Haverbeke
cc12062b9c [loose parser] Fix a whole bunch of issues in the options.locations support
Closes #40
2013-04-02 13:47:50 +02:00
Marijn Haverbeke
62bc3641af Use a single .handler property on TryStatements
As the wiki page for the spec currently seems to prescribe.
2013-04-02 09:30:35 +02:00
Paul Harper
a6b3034e71 [loose parser] More fixes to locations 2013-03-27 10:57:48 +01:00
Marijn Haverbeke
76be1f8eee Make Acorn work with AMD modules
(Hopefully)
2013-03-17 22:56:49 +01:00
Paul Harper
559518acc8 .parse_dammit() now recognizes the locations option, and will add a loc object to the ast nodes as .parse() does 2013-03-17 22:07:14 +01:00
Marijn Haverbeke
72d2fc2644 Fix start offset of block nodes 2013-02-20 10:48:36 +01:00
Marijn Haverbeke
782259bea1 [loose parser] Fix bug where peeked tokens persist across parses 2013-02-14 14:05:54 +01:00
Marijn Haverbeke
76c41d3a71 [loose parser] Improve closing heuristic in parseExprList 2013-02-06 13:47:05 +01:00
Marijn Haverbeke
82980794a9 Fix bug in expression-terminating heuristic
Dedented tokens should only end an expression if they are actually the first
token on the line.

This to prevent code like this from going wrong:

    x = (function(..) {
      blah();
    })(); // <-- indented same as start of expression
2013-02-05 13:49:51 +01:00
Marijn Haverbeke
1de79a277c [loose parser] Refine block-closing heuristics, add expression-continuing heuristics 2013-01-28 16:43:19 +01:00
Marijn Haverbeke
e95c4cce50 Add walk.findNodeAt utility 2013-01-28 13:00:08 +01:00
Marijn Haverbeke
17a0094694 [loose parser] Improve recovery from unterminated strings and regexps 2013-01-17 15:01:13 +01:00
Marijn Haverbeke
f8bcc75378 [loose parser] Fix typo 2013-01-17 14:49:20 +01:00
Marijn Haverbeke
e130dc3fbb [loose parser] Use ✖ rather than question mark for placeholders
This way, attempts to re-parse the pretty-printed code won't
be confused by the question marks.
2013-01-17 14:45:16 +01:00
Marijn Haverbeke
207bf64e8d [loose parser] Revise strategy for forcing token consumption
It's easier and more flexible to simply handle it at the call site.
2013-01-17 14:44:00 +01:00
Marijn Haverbeke
b8ec8aab2c [loose parser] Fix bug in argument list parsing 2013-01-17 14:17:22 +01:00
Marijn Haverbeke
1d974ce2b6 [loose parser] Several small tweaks 2013-01-16 19:09:06 +01:00
Marijn Haverbeke
d08144c1d7 [loose parser] Support tabSize option 2013-01-16 17:53:37 +01:00
Marijn Haverbeke
3981dfa133 [loose parser] Add note about imprecision 2013-01-16 17:43:27 +01:00
Marijn Haverbeke
a2788f8864 [loose parser] Make expect check two tokens ahead if it fails to find its target 2013-01-16 17:38:56 +01:00
Marijn Haverbeke
038e438949 Add a loose parser
For getting a halfway meaningful AST out of code that may contain
syntax errors.

Use case: analyzing code as the user is editing it.
2013-01-16 17:27:28 +01:00