Skip to content

Commit d02fed4

Browse files
martony38Robert Jackson
authored andcommitted
Fix bug when key attribute is a literal for debug macros (deprecate, assert, warn) (#80)
Fix bug when key attribute is a literal "key" attribute can be a Literal in which case we need to look for a "value" prop instead of "name" (https://babeljs.io/docs/en/babel-types#objectproperty)
1 parent 0bc6be2 commit d02fed4

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
(true && !(true) && console.warn('This is deprecated'));
2-
(true && !(false) && console.warn('Message without predicate'));
2+
(true && !(false) && console.warn('Message without predicate'));
3+
(true && !(true) && console.warn('This is deprecated with options'));
4+
5+
function wrappedDeprecate() {
6+
(true && !(true) && console.warn('This is also deprecated'));
7+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
(true && !(true) && console.warn('This is deprecated'));
2-
(true && !(false) && console.warn('Message without predicate'));
2+
(true && !(false) && console.warn('Message without predicate'));
3+
(true && !(true) && console.warn('This is deprecated with options'));
4+
5+
function wrappedDeprecate() {
6+
(true && !(true) && console.warn('This is also deprecated'));
7+
}

fixtures/deprecate-expansion/sample.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,15 @@ import { deprecate } from '@ember/debug-tools';
33

44
deprecate('This is deprecated', true);
55
deprecate('Message without predicate');
6+
deprecate('This is deprecated with options', true, {
7+
id: 'woot.options',
8+
until: '3.0.0',
9+
});
10+
function wrappedDeprecate() {
11+
deprecate(
12+
'This is also deprecated', true, {
13+
"id": "woot.wrapped",
14+
"until": "7.0.0",
15+
}
16+
);
17+
}

src/utils/builder.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,19 @@ module.exports = class Builder {
157157
validate: (expression, args) => {
158158
let meta = args[2];
159159

160-
if (meta && meta.properties && !meta.properties.some(prop => prop.key.name === 'id')) {
160+
if (
161+
meta &&
162+
meta.properties &&
163+
!meta.properties.some(prop => prop.key.name === 'id' || prop.key.value === 'id')
164+
) {
161165
throw new ReferenceError(`deprecate's meta information requires an "id" field.`);
162166
}
163167

164-
if (meta && meta.properties && !meta.properties.some(prop => prop.key.name === 'until')) {
168+
if (
169+
meta &&
170+
meta.properties &&
171+
!meta.properties.some(prop => prop.key.name === 'until' || prop.key.value === 'until')
172+
) {
165173
throw new ReferenceError(`deprecate's meta information requires an "until" field.`);
166174
}
167175
},

0 commit comments

Comments
 (0)