From 66d9b266e8048130bdae3063085f5baf9168b3be Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Thu, 16 Nov 2017 09:54:57 -0200 Subject: [PATCH] Skip assertDoc calls in production (#3268) --- scripts/build/rollup.index.config.js | 3 ++- src/doc-builders.js | 36 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/scripts/build/rollup.index.config.js b/scripts/build/rollup.index.config.js index ff44b853..7847cf5c 100644 --- a/scripts/build/rollup.index.config.js +++ b/scripts/build/rollup.index.config.js @@ -16,7 +16,8 @@ export default Object.assign(baseConfig, { // with rollup the module is turned into a plain function located directly // in index.js so `module.parent` does not exist. Defaulting to `module` // instead seems to work. - "module.parent": "(module.parent || module)" + "module.parent": "(module.parent || module)", + "process.env.NODE_ENV": JSON.stringify("production") }), json(), resolve({ preferBuiltins: true }), diff --git a/src/doc-builders.js b/src/doc-builders.js index 92f8c7d2..d99c6f47 100644 --- a/src/doc-builders.js +++ b/src/doc-builders.js @@ -12,7 +12,9 @@ function assertDoc(val) { } function concat(parts) { - parts.forEach(assertDoc); + if (process.env.NODE_ENV !== "production") { + parts.forEach(assertDoc); + } // We cannot do this until we change `printJSXElement` to not // access the internals of a document directly. @@ -24,13 +26,17 @@ function concat(parts) { } function indent(contents) { - assertDoc(contents); + if (process.env.NODE_ENV !== "production") { + assertDoc(contents); + } return { type: "indent", contents }; } function align(n, contents) { - assertDoc(contents); + if (process.env.NODE_ENV !== "production") { + assertDoc(contents); + } return { type: "align", contents, n }; } @@ -38,7 +44,9 @@ function align(n, contents) { function group(contents, opts) { opts = opts || {}; - assertDoc(contents); + if (process.env.NODE_ENV !== "production") { + assertDoc(contents); + } return { type: "group", @@ -56,24 +64,30 @@ function conditionalGroup(states, opts) { } function fill(parts) { - parts.forEach(assertDoc); + if (process.env.NODE_ENV !== "production") { + parts.forEach(assertDoc); + } return { type: "fill", parts }; } function ifBreak(breakContents, flatContents) { - if (breakContents) { - assertDoc(breakContents); - } - if (flatContents) { - assertDoc(flatContents); + if (process.env.NODE_ENV !== "production") { + if (breakContents) { + assertDoc(breakContents); + } + if (flatContents) { + assertDoc(flatContents); + } } return { type: "if-break", breakContents, flatContents }; } function lineSuffix(contents) { - assertDoc(contents); + if (process.env.NODE_ENV !== "production") { + assertDoc(contents); + } return { type: "line-suffix", contents }; }