1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var ASTCache =
|
13 |
|
14 | function () {
|
15 | function ASTCache(config) {
|
16 | this._documents = new Map();
|
17 | this._baseDir = config.baseDir;
|
18 | this._parse = require("./GraphQLCompilerProfiler").instrument(config.parse, 'ASTCache.parseFn');
|
19 | }
|
20 |
|
21 |
|
22 | var _proto = ASTCache.prototype;
|
23 |
|
24 | _proto.documents = function documents() {
|
25 | return require("immutable").Map(this._documents);
|
26 | };
|
27 |
|
28 |
|
29 | _proto.parseFiles = function parseFiles(files) {
|
30 | var _this = this;
|
31 |
|
32 | var documents = require("immutable").Map();
|
33 |
|
34 | files.forEach(function (file) {
|
35 | if (!file.exists) {
|
36 | _this._documents["delete"](file.relPath);
|
37 |
|
38 | return;
|
39 | }
|
40 |
|
41 | var doc = function () {
|
42 | try {
|
43 | return _this._parse(_this._baseDir, file);
|
44 | } catch (error) {
|
45 | throw new Error("Parse error: ".concat(error, " in \"").concat(file.relPath, "\""));
|
46 | }
|
47 | }();
|
48 |
|
49 | if (!doc) {
|
50 | _this._documents["delete"](file.relPath);
|
51 |
|
52 | return;
|
53 | }
|
54 |
|
55 | documents = documents.set(file.relPath, doc);
|
56 |
|
57 | _this._documents.set(file.relPath, doc);
|
58 | });
|
59 | return documents;
|
60 | };
|
61 |
|
62 | return ASTCache;
|
63 | }();
|
64 |
|
65 | module.exports = ASTCache; |
\ | No newline at end of file |