Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip assertDoc calls in production #3268

Merged
merged 4 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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