forked from eslint/typescript-eslint-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.js
65 lines (47 loc) · 1.77 KB
/
parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @fileoverview Tests for tokenize().
* @author Nicholas C. Zakas
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var assert = require("chai").assert,
parser = require("../../parser"),
tester = require("./tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("parse()", function() {
describe("basic functionality", function() {
it("should parse an empty string", function() {
assert.deepEqual(parser.parse("").body, []);
assert.deepEqual(parser.parse("", {}).body, []);
});
});
describe("modules", function() {
it("should have correct column number when strict mode error occurs", function() {
try {
parser.parse("function fn(a, a) {\n}", { sourceType: "module" });
} catch (err) {
assert.equal(err.column, 16);
}
});
});
describe("general", function() {
it("should output tokens, comments, locs, and ranges when called with those options", function() {
var ast = parser.parse("let foo = bar;", {
ecmaFeatures: {
blockBindings: true
},
comment: true,
tokens: true,
range: true,
loc: true
});
assert.deepEqual(tester.getRaw(ast), require("../fixtures/parse/all-pieces.json"));
});
});
});