1 | /*
|
2 | Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
|
3 |
|
4 | Redistribution and use in source and binary forms, with or without
|
5 | modification, are permitted provided that the following conditions are met:
|
6 |
|
7 | * Redistributions of source code must retain the above copyright
|
8 | notice, this list of conditions and the following disclaimer.
|
9 | * Redistributions in binary form must reproduce the above copyright
|
10 | notice, this list of conditions and the following disclaimer in the
|
11 | documentation and/or other materials provided with the distribution.
|
12 |
|
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16 | ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
17 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23 | */
|
24 |
|
25 | var espree = require('espree');
|
26 |
|
27 | module.exports = function (code) {
|
28 | return espree.parse(code, {
|
29 |
|
30 | // attach range information to each node
|
31 | range: true,
|
32 |
|
33 | // attach line/column location information to each node
|
34 | loc: true,
|
35 |
|
36 | // create a top-level comments array containing all comments
|
37 | comments: true,
|
38 |
|
39 | // attach comments to the closest relevant node as leadingComments and
|
40 | // trailingComments
|
41 | attachComment: true,
|
42 |
|
43 | // create a top-level tokens array containing all tokens
|
44 | tokens: true,
|
45 |
|
46 | // try to continue parsing if an error is encountered, store errors in a
|
47 | // top-level errors array
|
48 | tolerant: true,
|
49 |
|
50 | // specify parsing features (default only has blockBindings: true)
|
51 | ecmaFeatures: {
|
52 |
|
53 | // enable parsing of arrow functions
|
54 | arrowFunctions: true,
|
55 |
|
56 | // enable parsing of let/const
|
57 | blockBindings: true,
|
58 |
|
59 | // enable parsing of destructured arrays and objects
|
60 | destructuring: true,
|
61 |
|
62 | // enable parsing of regular expression y flag
|
63 | regexYFlag: true,
|
64 |
|
65 | // enable parsing of regular expression u flag
|
66 | regexUFlag: true,
|
67 |
|
68 | // enable parsing of template strings
|
69 | templateStrings: true,
|
70 |
|
71 | // enable parsing of binary literals
|
72 | binaryLiterals: true,
|
73 |
|
74 | // enable parsing of ES6 octal literals
|
75 | octalLiterals: true,
|
76 |
|
77 | // enable parsing unicode code point escape sequences
|
78 | unicodeCodePointEscapes: true,
|
79 |
|
80 | // enable parsing of default parameters
|
81 | defaultParams: true,
|
82 |
|
83 | // enable parsing of rest parameters
|
84 | restParams: true,
|
85 |
|
86 | // enable parsing of for-of statement
|
87 | forOf: true,
|
88 |
|
89 | // enable parsing computed object literal properties
|
90 | objectLiteralComputedProperties: true,
|
91 |
|
92 | // enable parsing of shorthand object literal methods
|
93 | objectLiteralShorthandMethods: true,
|
94 |
|
95 | // enable parsing of shorthand object literal properties
|
96 | objectLiteralShorthandProperties: true,
|
97 |
|
98 | // Allow duplicate object literal properties (except '__proto__')
|
99 | objectLiteralDuplicateProperties: true,
|
100 |
|
101 | // enable parsing of generators/yield
|
102 | generators: true,
|
103 |
|
104 | // enable parsing spread operator
|
105 | spread: true,
|
106 |
|
107 | // enable parsing classes
|
108 | classes: true,
|
109 |
|
110 | // enable parsing of modules
|
111 | modules: true,
|
112 |
|
113 | // enable React JSX parsing
|
114 | jsx: true,
|
115 |
|
116 | // enable return in global scope
|
117 | globalReturn: true
|
118 | }
|
119 | });
|
120 | };
|
121 |
|
122 | /* vim: set sw=4 ts=4 et tw=80 : */
|