Skip to content

Commit 32c776d

Browse files
authored
Merge pull request #67 from rwjblue/refactorzzzz
Unify flag handling...
2 parents 3f8de25 + d4496e6 commit 32c776d

File tree

17 files changed

+447
-461
lines changed

17 files changed

+447
-461
lines changed

README.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,43 @@ This provides debug macros and feature flagging.
44

55
## Setup
66

7-
The plugin takes 5 types options: `envFlags`, `features`, `debugTools`, `externalizeHelpers` and `svelte`. The `importSpecifier` is used as a hint to this plugin as to where macros are being imported and completely configurable by the host. Like Babel you can supply your own helpers using the `externalizeHelpers` options.
7+
The plugin takes 4 types options: `flags`, `svelte`, `debugTools`, and
8+
`externalizeHelpers`. The `importSpecifier` is used as a hint to this plugin as
9+
to where macros are being imported and completely configurable by the host.
10+
11+
Like Babel you can supply your own helpers using the `externalizeHelpers`
12+
options.
813

914
```js
1015
{
1116
plugins: [
1217
['babel-debug-macros', {
13-
// @required
14-
envFlags: {
15-
source: '@ember/env-flags',
16-
flags: { DEBUG: true }
17-
},
1818
// @required
1919
debugTools: {
20+
isDebug: true,
2021
source: 'debug-tools',
2122
// @optional
2223
assertPredicateIndex: 0
2324
},
24-
// @optional
25-
features: {
26-
name: 'ember-source',
27-
source: '@ember/features',
28-
flags: { FEATURE_A: false, FEATURE_B: true, DEPRECATED_CONTROLLERS: "2.12.0" }
29-
},
25+
26+
flags: [
27+
{ source: '@ember/env-flags', flags: { DEBUG: true } },
28+
{
29+
name: 'ember-source',
30+
source: '@ember/features',
31+
flags: {
32+
FEATURE_A: false,
33+
FEATURE_B: true,
34+
DEPRECATED_CONTROLLERS: "2.12.0"
35+
}
36+
}
37+
],
38+
3039
// @optional
3140
svelte: {
3241
'ember-source': "2.15.0"
3342
},
43+
3444
// @optional
3545
externalizeHelpers: {
3646
module: true,
@@ -66,12 +76,12 @@ woot();
6676
Transforms to:
6777

6878
```javascript
69-
if (true) {
79+
if (true /* DEBUG */) {
7080
console.log('Hello from debug');
7181
}
7282

7383
let woot;
74-
if (false) {
84+
if (false /* FEATURE_A */) {
7585
woot = () => 'woot';
7686
} else if (true) {
7787
woot = () => 'toow';
@@ -141,7 +151,9 @@ let foo = 2;
141151

142152
## Externalized Helpers
143153

144-
When you externalize helpers you must provide runtime implementations for the above macros. An expansion will still occur, however we will emit references to those runtime helpers.
154+
When you externalize helpers you must provide runtime implementations for the
155+
above macros. An expansion will still occur, however we will emit references to
156+
those runtime helpers.
145157

146158
A global expansion looks like the following:
147159

@@ -173,26 +185,28 @@ Expands into:
173185

174186
# Svelte
175187

176-
Svelte allows for consumers to opt into stripping deprecated code from your dependecies. By adding a package name and minimum version that contains no deprecations, that code will be compiled away.
188+
Svelte allows for consumers to opt into stripping deprecated code from your
189+
dependecies. By adding a package name and minimum version that contains no
190+
deprecations, that code will be compiled away.
177191

178-
For example, consider you are on `[email protected]` and you have no deprecations. All deprecated code in `ember-source` that is `<=2.10.0` will be removed.
192+
For example, consider you are on `[email protected]` and you have no
193+
deprecations. All deprecated code in `ember-source` that is `<=2.10.0` will be
194+
removed.
179195

180196
```
181-
...
197+
182198
svelte: {
183199
"ember-source": "2.10.0"
184200
}
185-
...
201+
186202
```
187203

188-
Now if you bump to `[email protected]` you may encounter new deprecations. The workflow would then be to clear out all deprecations and then bump the version in the `svelte` options.
204+
Now if you bump to `[email protected]` you may encounter new deprecations.
205+
The workflow would then be to clear out all deprecations and then bump the
206+
version in the `svelte` options.
189207

190208
```
191209
svelte: {
192210
"ember-source": "2.11.0"
193211
}
194212
```
195-
196-
# Hygenic
197-
198-
As you may notice that we inject `DEBUG` into the code when we expand the macro. We guarantee that the binding is unique when injected and follow the local binding name if it is imported directly.

fixtures/debug-flag/expectation6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22

3-
if (true) {
3+
if (true /* DEBUG */) {
44
console.log('woot');
55
}

fixtures/debug-flag/expectation7.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
if (true) {
1+
if (true
2+
/* DEBUG */
3+
) {
24
console.log('woot');
35
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
if (true) {
3+
if (true /* DEBUG */) {
44
doStuff();
55
}
66

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
if (true) {
1+
if (true
2+
/* DEBUG */
3+
) {
24
doStuff();
35
}
46

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22

33
let testing;
4-
if (false) {
4+
if (false /* TESTING */) {
55
testing = 'WOOT';
66
}
77

88
let debug;
9-
if (true) {
9+
if (true /* DEBUG */) {
1010
debug = 'DEBUG';
1111
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
let testing;
22

3-
if (false) {
3+
if (false
4+
/* TESTING */
5+
) {
46
testing = 'WOOT';
57
}
68

79
let debug;
810

9-
if (true) {
11+
if (true
12+
/* DEBUG */
13+
) {
1014
debug = 'DEBUG';
1115
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11

22

33
let a;
4-
if (false) {
4+
if (false /* FEATURE_A */) {
55
a = () => console.log('hello');
6-
} else if (true) {
6+
} else if (true /* FEATURE_B */) {
77
a = () => console.log('bye');
88
}
99

10-
if (!false) {
10+
if (!false /* FEATURE_A */) {
1111
console.log('stuff');
1212
}
1313

14-
a = false ? 'hello' : 'bye';
14+
a = false /* FEATURE_A */ ? 'hello' : 'bye';
1515

16-
if (false && window.foo && window.bar) {
16+
if (false /* FEATURE_A */ && window.foo && window.bar) {
1717
console.log('wheeee');
1818
}
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
let a;
22

3-
if (false) {
3+
if (false
4+
/* FEATURE_A */
5+
) {
46
a = () => console.log('hello');
5-
} else if (true) {
7+
} else if (true
8+
/* FEATURE_B */
9+
) {
610
a = () => console.log('bye');
711
}
812

9-
if (!false) {
13+
if (!false
14+
/* FEATURE_A */
15+
) {
1016
console.log('stuff');
1117
}
1218

13-
a = false ? 'hello' : 'bye';
19+
a = false
20+
/* FEATURE_A */
21+
? 'hello' : 'bye';
1422

15-
if (false && window.foo && window.bar) {
23+
if (false
24+
/* FEATURE_A */
25+
&& window.foo && window.bar) {
1626
console.log('wheeee');
1727
}

fixtures/runtime-feature-flags/expectation6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FEATURE_B } from '@ember/features';
22

3-
if (true) {
3+
if (true /* FEATURE_A */) {
44
console.log('woot');
55
}
66

0 commit comments

Comments
 (0)