From 245a7ad7c9265353f0b14aba286117741e14bf59 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Sun, 4 Mar 2018 12:07:02 -0800 Subject: [PATCH] Add "node-react" compatibility mode Summary: Release notes: adds "node-react" compatibility mode Adds the "node-react" compatibility mode, which is like "fb-www", but doesn't contain the internal FB mocks. This mode is ideal for library authors who might want to experiment with the features of the React compiler in an environment that has basic React/Relay mocks as well as `require` and `module.exports` partial support. I'll be adding relevant documentation for this on the wiki too. Closes https://github.com/facebook/prepack/pull/1528 Differential Revision: D7149660 Pulled By: trueadm fbshipit-source-id: 3f00fa01bb881722b270393a27f817911c5a5256 --- src/globals.js | 2 +- src/intrinsics/fb-www/global.js | 4 +++- src/options.js | 19 +++++++++++++++++-- website/js/repl.js | 4 ++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/globals.js b/src/globals.js index d8627769f..2a180f378 100644 --- a/src/globals.js +++ b/src/globals.js @@ -20,7 +20,7 @@ export default function(realm: Realm): Realm { if (realm.isCompatibleWith("browser")) { initializeDOMGlobals(realm); } - if (realm.isCompatibleWith("fb-www")) { + if (realm.isCompatibleWith("fb-www") || realm.isCompatibleWith("node-react")) { initializeDOMGlobals(realm); initializeReactMocks(realm); } diff --git a/src/intrinsics/fb-www/global.js b/src/intrinsics/fb-www/global.js index a7381d9f4..3478b5fac 100644 --- a/src/intrinsics/fb-www/global.js +++ b/src/intrinsics/fb-www/global.js @@ -86,5 +86,7 @@ export default function(realm: Realm): void { configurable: true, }); - createFbMocks(realm, global); + if (realm.isCompatibleWith("fb-www")) { + createFbMocks(realm, global); + } } diff --git a/src/options.js b/src/options.js index df9b6f99f..aa1bf0a2b 100644 --- a/src/options.js +++ b/src/options.js @@ -11,8 +11,23 @@ import type { ErrorHandler } from "./errors.js"; -export type Compatibility = "browser" | "jsc-600-1-4-17" | "mobile" | "node-source-maps" | "node-cli" | "fb-www"; -export const CompatibilityValues = ["browser", "jsc-600-1-4-17", "mobile", "node-source-maps", "node-cli", "fb-www"]; +export type Compatibility = + | "browser" + | "jsc-600-1-4-17" + | "mobile" + | "node-source-maps" + | "node-cli" + | "fb-www" + | "node-react"; +export const CompatibilityValues = [ + "browser", + "jsc-600-1-4-17", + "mobile", + "node-source-maps", + "node-cli", + "fb-www", + "node-react", +]; export type ReactOutputTypes = "create-element" | "jsx" | "bytecode"; export const ReactOutputValues = ["create-element", "jsx", "bytecode"]; diff --git a/website/js/repl.js b/website/js/repl.js index 8acc3c362..60b660d68 100644 --- a/website/js/repl.js +++ b/website/js/repl.js @@ -40,8 +40,8 @@ var optionsConfig = [ { type: "choice", name: "compatibility", - choices: ["browser", "jsc-600-1-4-17", "node-source-maps", "node-cli", "fb-wwww"], - defaultVal: "browser", + choices: ["browser", "jsc-600-1-4-17", "node-source-maps", "node-cli", "node-react"], + defaultVal: "node-react", description: "The target environment for Prepack" }, {