UNPKG

1.68 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt
7 * The complete set of authors may be found at
8 * http://polymer.github.io/AUTHORS.txt
9 * The complete set of contributors may be found at
10 * http://polymer.github.io/CONTRIBUTORS.txt
11 * Code distributed by Google as part of the polymer project is also
12 * subject to an additional IP rights grant found at
13 * http://polymer.github.io/PATENTS.txt
14 */
15Object.defineProperty(exports, "__esModule", { value: true });
16const document_1 = require("../parser/document");
17class ParsedJsonDocument extends document_1.ParsedDocument {
18 constructor() {
19 super(...arguments);
20 this.type = 'json';
21 }
22 visit(visitors) {
23 this._visit(this.ast, visitors);
24 }
25 _visit(node, visitors) {
26 for (const visitor of visitors) {
27 visitor.visit(node);
28 }
29 if (Array.isArray(node)) {
30 for (const value of node) {
31 this._visit(value, visitors);
32 }
33 }
34 else if (typeof node === 'object' && node !== null) {
35 for (const value of Object.values(node)) {
36 this._visit(value, visitors);
37 }
38 }
39 }
40 _sourceRangeForNode(_node) {
41 throw new Error('Not Implemented.');
42 }
43 stringify(options = {}) {
44 const { prettyPrint = true, indent = 2 } = options;
45 return JSON.stringify(this.ast, null, prettyPrint ? indent : 0);
46 }
47}
48exports.ParsedJsonDocument = ParsedJsonDocument;
49//# sourceMappingURL=json-document.js.map
\No newline at end of file