/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; const Cu = Components.utils; const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {}); const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); const { console } = require("resource://gre/modules/Console.jsm"); const DevToolsUtils = require("devtools/shared/DevToolsUtils"); XPCOMUtils.defineLazyModuleGetter(this, "Reflect", "resource://gre/modules/reflect.jsm"); this.EXPORTED_SYMBOLS = ["Parser", "ParserHelpers", "SyntaxTreeVisitor"]; /** * A JS parser using the reflection API. */ this.Parser = function Parser() { this._cache = new Map(); this.errors = []; this.logExceptions = true; }; Parser.prototype = { /** * Gets a collection of parser methods for a specified source. * * @param string source * The source text content. * @param string url [optional] * The source url. The AST nodes will be cached, so you can use this * identifier to avoid parsing the whole source again. */ get(source, url = "") { // Try to use the cached AST nodes, to avoid useless parsing operations. if (this._cache.has(url)) { return this._cache.get(url); } // The source may not necessarily be JS, in which case we need to extract // all the scripts. Fastest/easiest way is with a regular expression. // Don't worry, the rules of using a