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

[DOCS beta] debug functions are removed from prod build in apps #16330

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions packages/ember-debug/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,24 @@ if (DEBUG) {

if (DEBUG) {
/**
Define an assertion that will throw an exception if the condition is not met.
Verify that a certain expectation is met, or throw a exception otherwise.

* In a production build, this method is defined as an empty function (NOP).
Uses of this method in Ember itself are stripped from the ember.prod.js build.
This is useful for communicating assumptions in the code to other human
readers as well as catching bugs that accidentally violates these
expectations.

Assertions are removed from production builds, so they can be freely added
for documentation and debugging purposes without worries of incuring any
performance penalty. However, because of that, they should not be used for
checks that could reasonably fail during normal usage. Furthermore, care
should be taken to avoid accidentally relying on side-effects produced from
evaluating the condition itself, since the code will not run in production.

```javascript
import { assert } from '@ember/debug';

// Test for truthiness
assert('Must pass a valid object', obj);
assert('Must pass a string', typeof str === 'string');

// Fail unconditionally
assert('This code path should never be run');
Expand All @@ -85,9 +93,9 @@ if (DEBUG) {
@method assert
@static
@for @ember/debug
@param {String} desc A description of the assertion. This will become
the text of the Error thrown if the assertion fails.
@param {Boolean} test Must be truthy for the assertion to pass. If
@param {String} description Describes the expectation. This will become the
text of the Error thrown if the assertion fails.
@param {Boolean} condition Must be truthy for the assertion to pass. If
falsy, an exception will be thrown.
@public
@since 1.0.0
Expand All @@ -101,8 +109,9 @@ if (DEBUG) {
/**
Display a debug notice.

* In a production build, this method is defined as an empty function (NOP).
Uses of this method in Ember itself are stripped from the ember.prod.js build.
Calls to this function are removed from production builds, so they can be
freely added for documentation and debugging purposes without worries of
incuring any performance penalty.

```javascript
import { debug } from '@ember/debug';
Expand All @@ -123,8 +132,9 @@ if (DEBUG) {
/**
Display an info notice.

* In a production build, this method is defined as an empty function (NOP).
Uses of this method in Ember itself are stripped from the ember.prod.js build.
Calls to this function are removed from production builds, so they can be
freely added for documentation and debugging purposes without worries of
incuring any performance penalty.

@method info
@private
Expand All @@ -144,7 +154,9 @@ if (DEBUG) {
Display a deprecation warning with the provided message and a stack trace
(Chrome and Firefox only) when the assigned method is called.

* In a production build, this method is defined as an empty function (NOP).
Calls to this function are removed from production builds, so they can be
freely added for documentation and debugging purposes without worries of
incuring any performance penalty.

```javascript
import { deprecateFunc } from '@ember/application/deprecations';
Expand Down Expand Up @@ -185,8 +197,9 @@ if (DEBUG) {
/**
Run a function meant for debugging.

* In a production build, this method is defined as an empty function (NOP).
Uses of this method in Ember itself are stripped from the ember.prod.js build.
Calls to this function are removed from production builds, so they can be
freely added for documentation and debugging purposes without worries of
incuring any performance penalty.

```javascript
import Component from '@ember/component';
Expand Down