Skip to content

Commit d0fe646

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 d0fe646

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/twig.core.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,17 +696,20 @@ 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 if (!phpStyleBooleansDefined) {
707+
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.');
705708
}
709+
}
706710

707-
return str;
708-
});
709-
}
711+
return str;
712+
});
710713

711714
if (!autoescape) {
712715
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)