Skip to content

Commit 65ae930

Browse files
authored
Merge pull request #63 from rwjblue/loosen-if-statement-parent-condition
Cleanup / fix some svelte related functionality.
2 parents 42b1ddf + 97fa9ba commit 65ae930

File tree

7 files changed

+36
-11
lines changed

7 files changed

+36
-11
lines changed

fixtures/development-svelte-builds/expectation6.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ if (DEPRECATED_PARTIALS) {
1111
};
1212
}
1313

14+
if (DEPRECATED_PARTIALS && someOtherThing()) {
15+
throw new Error('You indicated you don\'t have any deprecations, however you are relying on DEPRECATED_PARTIALS.');
16+
17+
doStuff();
18+
}
19+
1420
export let ObjectController;
1521
if (DEPRECATED_CONTROLLERS) {
1622
ObjectController = class {

fixtures/development-svelte-builds/expectation7.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ if (DEPRECATED_PARTIALS) {
1111
};
1212
}
1313

14+
if (DEPRECATED_PARTIALS && someOtherThing()) {
15+
throw new Error("You indicated you don't have any deprecations, however you are relying on DEPRECATED_PARTIALS.");
16+
doStuff();
17+
}
18+
1419
export let ObjectController;
1520

1621
if (DEPRECATED_CONTROLLERS) {

fixtures/development-svelte-builds/sample.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if (DEPRECATED_PARTIALS) {
99
};
1010
}
1111

12+
if (DEPRECATED_PARTIALS && someOtherThing()) {
13+
doStuff();
14+
}
15+
1216
export let ObjectController;
1317
if (DEPRECATED_CONTROLLERS) {
1418
ObjectController = class {

fixtures/production-svelte-builds/expectation6.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if (false) {
99
};
1010
}
1111

12+
if (false && someOtherThing()) {
13+
doStuff();
14+
}
15+
1216
export let ObjectController;
1317
if (true) {
1418
ObjectController = class {

fixtures/production-svelte-builds/expectation7.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if (false) {
99
};
1010
}
1111

12+
if (false && someOtherThing()) {
13+
doStuff();
14+
}
15+
1216
export let ObjectController;
1317

1418
if (true) {

fixtures/production-svelte-builds/sample.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if (DEPRECATED_PARTIALS) {
99
};
1010
}
1111

12+
if (DEPRECATED_PARTIALS && someOtherThing()) {
13+
doStuff();
14+
}
15+
1216
export let ObjectController;
1317
if (DEPRECATED_CONTROLLERS) {
1418
ObjectController = class {
@@ -22,4 +26,4 @@ export default class TheThingToReplaceControllers {
2226
constructor() {
2327
this.isNew = true;
2428
}
25-
}
29+
}

src/utils/macros.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ module.exports = class Macros {
9898
if (binding !== undefined) {
9999
binding.referencePaths.forEach(p => {
100100
let t = builder.t;
101-
if (envFlags.DEBUG) {
102-
if (svelteMap[source][flag] === false) {
103-
if (!p.parentPath.isIfStatement()) {
104-
return;
105-
}
106-
let consequent = p.parentPath.get('consequent');
101+
// in debug builds add an error after a conditional (to ensure if the
102+
// specific branch is taken, an error is thrown)
103+
if (envFlags.DEBUG && svelteMap[source][flag] === false) {
104+
let parentIfStatement = p.find(p => p.isIfStatement());
105+
if (parentIfStatement) {
106+
let consequent = parentIfStatement.get('consequent');
107107
consequent.unshiftContainer(
108108
'body',
109109
t.throwStatement(
@@ -115,10 +115,8 @@ module.exports = class Macros {
115115
)
116116
);
117117
}
118-
} else {
119-
if (p.parentPath.isIfStatement()) {
120-
p.replaceWith(t.booleanLiteral(svelteMap[source][flag]));
121-
}
118+
} else if (envFlags.DEBUG === false) {
119+
p.replaceWith(t.booleanLiteral(svelteMap[source][flag]));
122120
}
123121
});
124122

0 commit comments

Comments
 (0)