[Bug] Undefined variable used inside `common/ManagedReference.common.js`
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 890
- Avg merge
- 2h 11m
- Merged PRs (30d)
- 10
Description
**Describe the bug**
When manually enable Jint's `strict mode` for perf optimization that is described at https://github.com/sebastienros/jint#performance.
`docfx build` command failed to apply template by referencing not defined variable (`langs`).
if default [Sloppy Mode](https://developer.mozilla.org/en/docs/Glossary/Sloppy_mode) it's evaluated as `undefined`
and some code is always skipped.
**To Reproduce**
1. Enable Jint strict mode. by modifying following [this code](https://github.com/dotnet/docfx/blob/b683722a1164ed75dda7b9e37c43f1dc0ff3f94f/src/Docfx.Build.Engine/TemplateProcessors/Preprocessors/TemplateJintPreprocessor.cs#L191)
to `var engine = new Jint.Engine(options =>{ options.Strict(); });`
3. Run `docfx build` command.
4. Verify following error log recorded.
```
Error: Error transforming model "C:\Users\admin\AppData\Local\Temp\docfx\rawmodel\api\BuildFromAssembly.Class1.raw.json"
generated from "obj/api/BuildFromAssembly.Class1.yml" using "ManagedReference.html.primary.js". Error running Transform
function inside template preprocessor: langs is not defined
```
**How to fix problems**
This error occurred by following code.
https://github.com/dotnet/docfx/blob/main/templates/common/ManagedReference.common.js#L223-L246
In `handleItem` function.
`langs` variable should be referenced with `vm.langs`.
**Expected behavior**
Build successfully completed when running under strict mode.
It seems following metadata are defined. But not used by any template.
- hideTitleType
- hideSubtitle
**Additional context**
In addition to enabling `Strict Mode`.
It might be safer to disable `Eval` functionality. (Default: Enabled)
```
var engine = new Jint.Engine(options =>
{
options.Strict();
options.DisableStringCompilation(true);
});
```
Contributor guide
Assessment
This issue has not been assessed yet.