Skip to content

Commit 1942f4f

Browse files
Show deprecation notice when phpStyleBooleans is not defined and a boolean is encountered.
Co-Authored-By: Will Rowe <[email protected]>
1 parent 2bbd5ea commit 1942f4f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/twig.core.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,17 +696,22 @@ module.exports = function (Twig) {
696696
Twig.output = function (output) {
697697
const {autoescape} = this.options;
698698
const {phpStyleBooleans} = this.options;
699+
const {phpStyleBooleansDefined} = this.options;
699700

700701
// Conform Javascript boolean to PHP boolean
701-
if (phpStyleBooleans) {
702-
output = output.map(str => {
703-
if (typeof str === 'boolean') {
702+
output = output.map(str => {
703+
if (typeof str === 'boolean') {
704+
if (phpStyleBooleans) {
704705
str = str ? '1' : '';
706+
} else {
707+
if (!phpStyleBooleansDefined) {
708+
console.warn('Deprecation notice: `phpStyleBooleans` is not defined, output differs from PHP behavior, in future versions this behavior will be changed to PHP style booleans.');
709+
}
705710
}
711+
}
706712

707-
return str;
708-
});
709-
}
713+
return str;
714+
});
710715

711716
if (!autoescape) {
712717
return output.join('');

src/twig.exports.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module.exports = function (Twig) {
2323
// TODO: turn autoscape on in the next major version
2424
autoescape: (params.autoescape !== null && params.autoescape) || false,
2525
allowInlineIncludes: params.allowInlineIncludes || false,
26+
// TODO: turn phpStyleBooleans on in the next major version
27+
phpStyleBooleansDefined: params.phpStyleBooleans !== undefined,
2628
phpStyleBooleans: params.phpStyleBooleans || false,
2729
rethrow: params.rethrow || false,
2830
namespaces: params.namespaces

0 commit comments

Comments
 (0)