(code, syntax)
| 97 | } |
| 98 | |
| 99 | function testParse(code, syntax) { |
| 100 | 'use strict'; |
| 101 | var expected, tree, actual, options, i, len, nodes; |
| 102 | |
| 103 | options = { |
| 104 | jsx: true, |
| 105 | comment: (typeof syntax.comments !== 'undefined'), |
| 106 | range: true, |
| 107 | loc: true, |
| 108 | tokens: true, |
| 109 | raw: true, |
| 110 | tolerant: (typeof syntax.errors !== 'undefined'), |
| 111 | source: null, |
| 112 | sourceType: syntax.sourceType |
| 113 | }; |
| 114 | |
| 115 | if (options.comment) { |
| 116 | options.attachComment = hasAttachedComment(syntax); |
| 117 | } |
| 118 | |
| 119 | if (typeof syntax.tokens !== 'undefined') { |
| 120 | if (syntax.tokens.length > 0) { |
| 121 | options.range = (typeof syntax.tokens[0].range !== 'undefined'); |
| 122 | options.loc = (typeof syntax.tokens[0].loc !== 'undefined'); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if (typeof syntax.comments !== 'undefined') { |
| 127 | if (syntax.comments.length > 0) { |
| 128 | options.range = (typeof syntax.comments[0].range !== 'undefined'); |
| 129 | options.loc = (typeof syntax.comments[0].loc !== 'undefined'); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (options.loc) { |
| 134 | options.source = syntax.loc.source; |
| 135 | } |
| 136 | |
| 137 | syntax = sortedObject(syntax); |
| 138 | expected = JSON.stringify(syntax, null, 4); |
| 139 | try { |
| 140 | // Some variations of the options. |
| 141 | tree = esprima.parse(code, { jsx: options.jsx, tolerant: options.tolerant, sourceType: options.sourceType }); |
| 142 | tree = esprima.parse(code, { jsx: options.jsx, tolerant: options.tolerant, sourceType: options.sourceType, range: true }); |
| 143 | tree = esprima.parse(code, { jsx: options.jsx, tolerant: options.tolerant, sourceType: options.sourceType, loc: true }); |
| 144 | |
| 145 | tree = (options.sourceType === 'script') ? esprima.parseScript(code, options) : esprima.parseModule(code, options); |
| 146 | esprima.parse(code, options); |
| 147 | |
| 148 | if (options.tolerant) { |
| 149 | for (i = 0, len = tree.errors.length; i < len; i += 1) { |
| 150 | tree.errors[i] = errorToObject(tree.errors[i]); |
| 151 | } |
| 152 | } |
| 153 | tree = sortedObject(tree); |
| 154 | actual = JSON.stringify(tree, null, 4); |
| 155 | |
| 156 | // Only to ensure that there is no error when using string object. |
no test coverage detected
searching dependent graphs…