Previously in case a value for a referenced local was missing the string 'undefined' was inserted in the output EXCEPT if it was used in an expression like {{missingLocal ? 'yes' : 'no'}} when an exception is thrown.
This is inconsistent behavior
Silently generating string 'undefined' makes difficult to detect undesired behavior. A warning log or reference in the output makes it much more easier to detect.
I was tying to create a opportunity for developers to decide how to handle such situation.
The default behavior is changed: when strictMode is true (default) and leaving the new missingLocal option undefined, then the same "'foo' is not defined" exception is thrown as when a referenced value is missing in an expression
Setting strictMode false and leaving the new missingLocal option undefined results the previous result: undefined
Setting the new missingLocal option to a string will produce that string in the output regardless the value of strictMode. missingLocal can contain the placeholder {local} which will be replaced with the name of the missing local in the output. This solution allows to
Completely ignore missing locals by setting missingLocal to ""
Include the name of the missing local in the output to help detect the which value is missing in locals like "#Missing value: {local}"
See updated README and test cases
Types of Changes
What types of changes does your code introduce
[ ] Bug (non-breaking change which fixes an issue)
[ ] Feature (non-breaking change which adds functionality)
[x] Breaking Change (fix or feature which changes existing functionality)
[x] I have added tests that prove my fix is effective/works
[x] I have added necessary documentation (if appropriate)
[x] Any dependent changes are merged and published in downstream modules
Further Comments
If this is a large or complex change, kick off the discussion by explaining why
you chose the solution you did and what alternatives you considered, etc...
Proposed Changes
Previously in case a value for a referenced local was missing the string 'undefined' was inserted in the output EXCEPT if it was used in an expression like
{{missingLocal ? 'yes' : 'no'}}
when an exception is thrown.I was tying to create a opportunity for developers to decide how to handle such situation. The default behavior is changed: when
strictMode
is true (default) and leaving the newmissingLocal
optionundefined
, then the same "'foo' is not defined" exception is thrown as when a referenced value is missing in an expressionSetting
strictMode
false and leaving the newmissingLocal
optionundefined
results the previous result:undefined
Setting the new
missingLocal
option to a string will produce that string in the output regardless the value ofstrictMode
.missingLocal
can contain the placeholder{local}
which will be replaced with the name of the missing local in the output. This solution allows tomissingLocal
to""
locals
like "#Missing value: {local}"See updated README and test cases
Types of Changes
What types of changes does your code introduce
Checklist
Further Comments
If this is a large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
Reviewers: @mrmlnc, @jescalan, @michael-ciniawsky, @posthtml/collaborators