Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missingLocal option to define how to handle missing local value #138

Merged
merged 2 commits into from
Dec 20, 2022

Conversation

b-gyula
Copy link
Contributor

@b-gyula b-gyula commented Nov 7, 2022

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.

  1. This is inconsistent behavior
  2. 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

  1. Completely ignore missing locals by setting missingLocal to ""
  2. 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)
  • Breaking Change (fix or feature which changes existing functionality)

Checklist

  • I have read the CONTRIBUTING guide
  • Lint and unit tests pass with my changes
  • I have added tests that prove my fix is effective/works
  • I have added necessary documentation (if appropriate)
  • 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...

Reviewers: @mrmlnc, @jescalan, @michael-ciniawsky, @posthtml/collaborators

…case of missing local value

- `ignoreTag` will not remove the tag itself if it is simple like `<input>`
- placeholder in `missingLocal` replaced to `local`
@b-gyula b-gyula changed the title - Added missingLocal option to define how to handle missing local value Added missingLocal option to define how to handle missing local value Nov 7, 2022
@Scrum Scrum merged commit 278b7b0 into posthtml:master Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants