Skip to content

Commit

Permalink
Skip assertDoc calls in production (#3268)
Browse files Browse the repository at this point in the history
  • Loading branch information
duailibe committed Nov 16, 2017
1 parent b959801 commit 66d9b26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
3 changes: 2 additions & 1 deletion scripts/build/rollup.index.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
36 changes: 25 additions & 11 deletions src/doc-builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -24,21 +26,27 @@ 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 };
}

function group(contents, opts) {
opts = opts || {};

assertDoc(contents);
if (process.env.NODE_ENV !== "production") {
assertDoc(contents);
}

return {
type: "group",
Expand All @@ -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 };
}

Expand Down

0 comments on commit 66d9b26

Please sign in to comment.