/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ /* 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 Ci = Components.interfaces; const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); const { require } = Cu.import("resource://devtools/shared/Loader.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 aSource * The source text content. * @param string aUrl [optional] * The source url. The AST nodes will be cached, so you can use this * identifier to avoid parsing the whole source again. */ get: function(aSource, aUrl = "") { // Try to use the cached AST nodes, to avoid useless parsing operations. if (this._cache.has(aUrl)) { return this._cache.get(aUrl); } // 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