Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/tools/ts/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 4 kB image not shown  

Quelle  build_paths.js

  Sprache: JAVA
 

/* 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";

/**
 * Build: <srcdir>/tools/@types/generated/tspaths.json, and
 *        <srcdir>/tools/@types/generated/lib.gecko.modules.d.ts
 *
 * from:  various import forms in all *.js and *.mjs sources.
 */


const fs = require("fs");
const path = require("path");
const { fixed } = require("./config/fixed_paths.js");

const HEADER = `/**
 * NOTE: Do not modify this file by hand.
 * Content was generated by running "mach ts paths".
 */

`;

const IGNORE = [
  /\.git/,
  /\.hg/,
  /node_modules/,
  /^obj.*/,
  /test262/,
  // eslint-plugin-mozilla isn't part of Gecko/Firefox code, but runs tests
  // simulating imports that we don't need to define in the paths.
  /eslint-plugin-mozilla/,
];
const IMPORT =
  /(?<!@)(\bimport |import\(|require\(|\.(importESModule|defineESModuleGetters?|declareLazy|defineLazy)\()[^;]+/gm;
// TypeScript imports have no `;` so cannot be included in the IMPORT regular
// expression. Therefore we have a separate expression to handle the TypeScript
// specific imports which will be within comments.
const TYPESCRIPT_IMPORT =
  /\/\*\*?\s*@import\s.*?\s+from\s+["'][^"']+["']\s*\*\//gm;
const URI = /("|')((resource|chrome|moz-src):\/\/[\w\d\/_.-]+\.m?js)\1/gm;

function ignore(filePath) {
  return IGNORE.some(re => filePath.match(re));
}

// Scan the root dir for *.js and *.mjs files, recursivelly.
function scan(root, dir, files) {
  for (let file of fs.readdirSync(`${root}/${dir}`, { withFileTypes: true })) {
    if (file.isDirectory() && !ignore(dir + file.name)) {
      scan(root, `${dir}${file.name}/`, files);
    } else if (file.name.match(/\.(x?html|m?js)$/)) {
      files.push(dir + file.name);
    }
  }
}

// Emit path mapping for all found module URIs.
function emitPaths(files, uris, modules, relativeBasePath) {
  /** @type {Record<string, string[]>} */
  let paths = {};
  for (let uri of [...uris].sort()) {
    // Fixed URIs need to go at the end, with their own URIs
    if (uri in fixed) {
      continue;
    }
    let parts = uri.split("/");
    let filePath = "";
    let matches;

    // Check for a substitution .d.ts file from processed/generated sources.
    let sub = parts.at(-1).replace(/\.(m)?js$/, ".d.$1ts");
    if (fs.existsSync(`${__dirname}/../@types/subs/${sub}`)) {
      paths[uri] = [`${relativeBasePath}/tools/@types/subs/${sub}`];
      continue;
    }

    // Starting with just the file name, add each path part going backwards.
    do {
      filePath = "/" + parts.pop() + filePath;
      matches = files.filter(f => f.endsWith(filePath));
      // While multiple files match, add parts used for filtering.
    } while (matches.length > 1 && parts.length);

    // Unique match is almost certainy correct.
    if (matches.length === 1) {
      paths[uri] = [`${relativeBasePath}/${matches[0]}`];
    } else {
      // URI matched more than one, or failed to match any file.
      console.warn("[WARN]", uri);
      modules.delete(uri);
    }
  }

  for (let [uri, fixedPaths] of Object.entries(fixed)) {
    // console.log(uri, fixedPaths);
    paths[uri] = fixedPaths?.map(p => `${relativeBasePath}/${p}`);
  }
  return JSON.stringify({ compilerOptions: { paths } }, null2) + "\n";
}

// Emit type mapping for all modules imported via lazy getters.
function emitLazy(modules) {
  let lines = [HEADER];
  lines.push("export interface Modules {");
  for (let uri of [...modules].sort()) {
    lines.push(`  "${uri}"typeof import("${uri}"),`);
  }
  lines.push("}\n");
  return lines.join("\n");
}

function main(root_dir, paths_json, lib_lazy) {
  let files = [];
  scan(root_dir, "", files);

  let uris = new Set();
  let modules = new Set();

  for (let file of files) {
    let src = fs.readFileSync(`${root_dir}/${file}`, "utf-8");

    for (let [exp, , method] of [
      ...src.matchAll(IMPORT),
      ...src.matchAll(TYPESCRIPT_IMPORT),
    ]) {
      for (let [, , uri, proto] of exp.matchAll(URI)) {
        if (proto !== "moz-src") {
          uris.add(uri);
        }
        if (method?.match(/importESModule|ModuleGetter|Lazy/)) {
          modules.add(uri);
        }
      }
    }
  }

  let json = emitPaths(
    files,
    uris,
    modules,
    path.relative(path.dirname(paths_json), root_dir).replaceAll("\\""/")
  );
  console.log(`[INFO] ${paths_json} (${json.length.toLocaleString()} bytes)`);
  fs.writeFileSync(paths_json, json);

  let lib = emitLazy(modules);
  console.log(`[INFO] ${lib_lazy} (${lib.length.toLocaleString()} bytes)`);
  fs.writeFileSync(lib_lazy, lib);
}

main(...process.argv.slice(2));

Messung V0.5 in Prozent
C=84 H=88 G=85

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.