Skip to content

Commit ce71a5c

Browse files
author
Robert Jackson
committed
Always replace svelte flag with boolean value in non-debug builds.
1 parent 42b1ddf commit ce71a5c

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed

fixtures/development-svelte-builds/expectation6.js

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

14+
if (DEPRECATED_PARTIALS && someOtherThing()) {
15+
doStuff();
16+
}
17+
1418
export let ObjectController;
1519
if (DEPRECATED_CONTROLLERS) {
1620
ObjectController = class {

fixtures/development-svelte-builds/expectation7.js

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

14+
if (DEPRECATED_PARTIALS && someOtherThing()) {
15+
doStuff();
16+
}
17+
1418
export let ObjectController;
1519

1620
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: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ 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-
}
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+
if (p.parentPath.isIfStatement()) {
106105
let consequent = p.parentPath.get('consequent');
107106
consequent.unshiftContainer(
108107
'body',
@@ -115,10 +114,8 @@ module.exports = class Macros {
115114
)
116115
);
117116
}
118-
} else {
119-
if (p.parentPath.isIfStatement()) {
120-
p.replaceWith(t.booleanLiteral(svelteMap[source][flag]));
121-
}
117+
} else if (envFlags.DEBUG === false) {
118+
p.replaceWith(t.booleanLiteral(svelteMap[source][flag]));
122119
}
123120
});
124121

0 commit comments

Comments
 (0)