Skip to content

Commit 5220b0e

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 5220b0e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/twig.core.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,15 +698,17 @@ module.exports = function (Twig) {
698698
const {phpStyleBooleans} = this.options;
699699

700700
// Conform Javascript boolean to PHP boolean
701-
if (phpStyleBooleans) {
702-
output = output.map(str => {
703-
if (typeof str === 'boolean') {
701+
output = output.map(str => {
702+
if (typeof str === 'boolean') {
703+
if (phpStyleBooleans === undefined) {
704+
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.');
705+
} else if (phpStyleBooleans) {
704706
str = str ? '1' : '';
705707
}
708+
}
706709

707-
return str;
708-
});
709-
}
710+
return str;
711+
});
710712

711713
if (!autoescape) {
712714
return output.join('');

src/twig.exports.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +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-
phpStyleBooleans: params.phpStyleBooleans || false,
26+
// TODO: turn phpStyleBooleans on in the next major version
27+
phpStyleBooleans: undefined,
2728
rethrow: params.rethrow || false,
2829
namespaces: params.namespaces
2930
};
@@ -40,6 +41,10 @@ module.exports = function (Twig) {
4041
Twig.trace = params.trace;
4142
}
4243

44+
if (params.phpStyleBooleans !== undefined) {
45+
options.phpStyleBooleans = params.phpStyleBooleans;
46+
}
47+
4348
if (params.data !== undefined) {
4449
return Twig.Templates.parsers.twig({
4550
data: params.data,

0 commit comments

Comments
 (0)