Skip to content

Commit ed02f75

Browse files
author
Robert Jackson
committed
Update predicate based macros replace predicate when prefixing with it.
For `deprecate` and `assert` (when `assertPredicateIndex` is specified), there is no need to duplicate the predicate. With this input: ```js deprecate('message here', (() => true)()); ``` Before this change we would output: ```js (true && !((() => true))()) && deprecate('message here', (() => true)()); ``` After this change we output: ```js (true && !((() => true))()) && deprecate('message here', false); ```
1 parent f23b1ee commit ed02f75

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
(true && !((() => true)()) && console.assert((() => true)(), 'This is an assertion'));
1+
(true && !((() => true)()) && console.assert(false, 'This is an assertion'));
22
(true && !(false) && console.assert(false, 'This is an assertion 2'));

fixtures/ember-cli-babel-config/expectation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ if (true) {
55
}
66

77
(true && Ember.warn('This is a warning'));
8-
(true && !(foo) && Ember.assert('Hahahaha', foo));
9-
(true && !(true) && Ember.deprecate('This thing is donzo', true, {
8+
(true && !(foo) && Ember.assert('Hahahaha', false));
9+
(true && !(true) && Ember.deprecate('This thing is donzo', false, {
1010
id: 'donzo',
1111
until: '4.0.0',
1212
url: 'http://example.com'

fixtures/global-external-helpers/expectation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(true && __debugHelpers__.warn('This is a warning'));
22
(true && __debugHelpers__.assert('Hahahaha', foo));
3-
(true && !(true) && __debugHelpers__.deprecate('This thing is donzo', true, {
3+
(true && !(true) && __debugHelpers__.deprecate('This thing is donzo', false, {
44
id: 'donzo',
55
until: '4.0.0',
66
url: 'http://example.com'

fixtures/retain-module-external-helpers/expectation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { warn, assert, deprecate } from '@ember/debug-tools';
22

33
(true && warn('This is a warning'));
44
(true && assert('Hahahaha', false));
5-
(true && !(true) && deprecate('This thing is donzo', true, {
5+
(true && !(true) && deprecate('This thing is donzo', false, {
66
id: 'donzo',
77
until: '4.0.0',
88
url: 'http://example.com'

src/lib/utils/builder.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,34 @@ export default class Builder {
1616
*
1717
* ($DEBUG && console.assert($PREDICATE, $MESSAGE));
1818
*
19-
* or
19+
* or (when `assertPredicateIndex` specified)
20+
*
21+
* ($DEBUG && $PREDICATE && console.assert(false, $MESSAGE));
22+
*
23+
* or (`{ externalizeHelpers: { module: true } }`)
2024
*
2125
* ($DEBUG && assert($PREDICATE, $MESSAGE));
2226
*
23-
* or
27+
* or (when `{ externalizeHelpers: { module: true }, debugTools: { source: '...', assertPredicateIndex: 0 } }` specified)
28+
*
29+
* ($DEBUG && $PREDICATE && assert(false, $MESSAGE));
30+
*
31+
* or (when `{ externalizeHelpers: { global: '$GLOBLA_NS' }` specified)
2432
*
2533
* ($DEBUG && $GLOBAL_NS.assert($PREDICATE, $MESSAGE));
34+
*
35+
* or (when `{ externalizeHelpers: { global: '$GLOBLA_NS' }, debugTools: { source: '...', assertPredicateIndex: 0 } }` specified)
36+
*
37+
* ($DEBUG && $PREDICATE && $GLOBAL_NS.assert(false, $MESSAGE));
2638
*/
2739
assert(path) {
2840
let predicate;
2941
if (this.assertPredicateIndex !== undefined) {
3042
predicate = (expression, args) => {
31-
return args[this.assertPredicateIndex];
43+
let predicate = args[this.assertPredicateIndex];
44+
args[this.assertPredicateIndex] = this.t.identifier('false');
45+
46+
return predicate;
3247
};
3348
}
3449

@@ -134,15 +149,20 @@ export default class Builder {
134149
*
135150
* or
136151
*
137-
* ($DEBUG && $PREDICATE && deprecate($MESSAGE, $PREDICATE, { $ID, $URL, $UNTIL }));
152+
* ($DEBUG && $PREDICATE && deprecate($MESSAGE, false, { $ID, $URL, $UNTIL }));
138153
*
139154
* or
140155
*
141-
* ($DEBUG && $PREDICATE && $GLOBAL_NS.deprecate($MESSAGE, $PREDICATE, { $ID, $URL, $UNTIL }));
156+
* ($DEBUG && $PREDICATE && $GLOBAL_NS.deprecate($MESSAGE, false, { $ID, $URL, $UNTIL }));
142157
*/
143158
deprecate(path) {
144159
this._createMacroExpression(path, {
145-
predicate: (expression, args) => args[1],
160+
predicate: (expression, args) => {
161+
let [, predicate] = args;
162+
args[1] = this.t.identifier('false');
163+
164+
return predicate;
165+
},
146166

147167
buildConsoleAPI: (expression, args) => {
148168
let [message] = args;

0 commit comments

Comments
 (0)