/* -*- 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 { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm"); const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); const DevToolsUtils = require("devtools/shared/DevToolsUtils"); ChromeUtils.defineModuleGetter(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