/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {}); 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 = []; }; 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