handlebars-lang / handlebars-lang/handlebars.js

Strict mode has seemingly no effect on partials

Open
#1,708 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
18.7k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

Before filing issues, please check the following points first:

- [x] Please don't open issues for security issues. Instead, file a report at https://www.npmjs.com/advisories/report?package=handlebars
- [x] Have a look at https://github.com/wycats/handlebars.js/blob/master/CONTRIBUTING.md
- [x] Read the FAQ at https://github.com/wycats/handlebars.js/blob/master/FAQ.md
- [ ] Use the jsfiddle-template at https://jsfiddle.net/4nbwjaqz/4/ to reproduce problems or bugs
(I put together an example on runkit before i realized you had a base fiddle, hopefully thats alright.

This will probably help you to get a solution faster.
For bugs, it would be great to have a PR with a failing test-case.

## The issue:
When using strict mode and passing a parameter into a partial, no error is thrown when that value is missing.

### Example
See this running example here: https://runkit.com/jemarjones/handlebars-strict-mode-partials
```
const Handlebars = require("handlebars");
Handlebars.registerPartial('myPartial', 'Hello {{name}}')
const template = Handlebars.compile('{{>myPartial name=name}}', {strict: true})
console.log(template({name: 'World'})) // 'Hello World'
// ^ Good, makes sense.

console.log(template({})) // 'Hello '
// ^ This should be throwing an error

const template2 = Handlebars.compile('{{name}}', {strict: true})
console.log(template2({})) // "name" not defined in [object Object]
// ^ Not the best error message, but it does work when the missing value is used in the base template at least.
```

Contributor guide

Open the contributing guide

Research direction

Start with the minimal example using Handlebars.registerPartial and Handlebars.compile(..., {strict: true}), comparing the partial case with the base-template case. Reproduce the missing-value behavior, then add a failing test showing that strict mode should report the absent partial parameter while preserving the successful rendering case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.