mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-09-11 14:46:37 +03:00
Summary: Release notes: none This generates a tree graph of how all the components in the React reconciliation process get handled. It will massively help debugging what did or did not get inlined/evaluated. The data is also added to snapshots to further improve regression testing too. Closes https://github.com/facebook/prepack/pull/1509 Differential Revision: D7115923 Pulled By: trueadm fbshipit-source-id: 4d17dccc52b324c9a0a59a5864066345ae7ec097
79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
/* @flow */
|
|
|
|
// NOTE:
|
|
// put the input fb-www file in ${root}/fb-www/input.js
|
|
// the compiled file will be saved to ${root}/fb-www/output.js
|
|
|
|
let prepackSources = require("../lib/prepack-node.js").prepackSources;
|
|
let path = require("path");
|
|
let { readFile, writeFile } = require("fs");
|
|
let { promisify } = require("util");
|
|
let readFileAsync = promisify(readFile);
|
|
let writeFileAsync = promisify(writeFile);
|
|
|
|
let prepackOptions = {
|
|
compatibility: "fb-www",
|
|
internalDebug: true,
|
|
serialize: true,
|
|
uniqueSuffix: "",
|
|
maxStackDepth: 100,
|
|
reactEnabled: true,
|
|
reactOutput: "jsx",
|
|
inlineExpressions: true,
|
|
omitInvariants: true,
|
|
abstractEffectsInAdditionalFunctions: true,
|
|
simpleClosures: true,
|
|
};
|
|
let inputPath = path.resolve("fb-www/input.js");
|
|
let outputPath = path.resolve("fb-www/output.js");
|
|
|
|
function compileSource(source) {
|
|
let serialized = prepackSources([{ filePath: "", fileContents: source, sourceMapContents: "" }], prepackOptions);
|
|
return {
|
|
// $FlowFixMe: reactStatistics do exist as we're passing reactEnabled in config
|
|
stats: serialized.reactStatistics,
|
|
code: serialized.code,
|
|
};
|
|
}
|
|
|
|
async function compileFile() {
|
|
let source = await readFileAsync(inputPath, "utf8");
|
|
let { stats, code } = await compileSource(source);
|
|
await writeFileAsync(outputPath, code);
|
|
return stats;
|
|
}
|
|
|
|
function printReactEvaluationGraph(evaluatedRootNode, depth) {
|
|
if (Array.isArray(evaluatedRootNode)) {
|
|
for (let child of evaluatedRootNode) {
|
|
printReactEvaluationGraph(child, depth);
|
|
}
|
|
} else {
|
|
let line = `- ${evaluatedRootNode.name} (${evaluatedRootNode.status.toLowerCase()})`;
|
|
console.log(line.padStart(line.length + depth));
|
|
printReactEvaluationGraph(evaluatedRootNode.children, depth + 2);
|
|
}
|
|
}
|
|
|
|
compileFile()
|
|
.then(result => {
|
|
console.log("\nCompilation complete!");
|
|
console.log(`Optimized Trees: ${result.optimizedTrees}`);
|
|
console.log(`Inlined Components: ${result.inlinedComponents}\n`);
|
|
console.log(`Evaluated Tree:`);
|
|
printReactEvaluationGraph(result.evaluatedRootNodes, 0);
|
|
})
|
|
.catch(e => {
|
|
console.error(e.natickStack || e.stack);
|
|
process.exit(1);
|
|
});
|