mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.71k stars 846 forks source link

Variables used before declaration #649

Closed xor-gate closed 2 years ago

xor-gate commented 2 years ago

I'm using ejs.min.js latest v3.1.6 release in combination with the Qt 6 QJSEngine (written in C++) and we get the following warnings:

QWARN  : TestJTemplate::simpleTemplate() qt.qml.compiler: file:file:ejs.min.js:1:496 Variable "u" is used before its declaration at 1:734.
QWARN  : TestJTemplate::simpleTemplate() qt.qml.compiler: file:file:ejs.min.js:1:505 Variable "u" is used before its declaration at 1:734.
QWARN  : TestJTemplate::simpleTemplate() qt.qml.compiler: file:file:ejs.min.js:1:15908 Variable "substr" is used before its declaration at 1:18754.

As the file is minified it is difficult to point to the correct line in the source file. But this warning should be easy fixed if running a javascript linter over the ejs sourcecode. I'm not experienced in the javascript development ecosystem so not sure which linters are available. Hope this is issue information is clear enough.

mde commented 2 years ago

This is strange, because we do lint the source code. It's part of the build process. I have no idea why you are seeing those errors. Perhaps Qt doesn't know how to deal with minified source?

xor-gate commented 2 years ago

I have tried with the non-minified released js (same 3.1.6 version). The result the same:

QWARN  : TestJTemplate::simpleTemplate() qt.qml.compiler: file:file:ejs.min.js:1:499 Variable "u" is used before its declaration at 1:737.
QWARN  : TestJTemplate::simpleTemplate() qt.qml.compiler: file:file:ejs.min.js:1:508 Variable "u" is used before its declaration at 1:737.
QWARN  : TestJTemplate::simpleTemplate() qt.qml.compiler: file:file:ejs.min.js:1216:23 Variable "substr" is used before its declaration at 1422:5.

If i look in the sourcecode on line 1422: var substr = 'ab'.substr(-1) === 'b'

indeed on line 1216 substr is used:

      trailingSlash = substr(path, -1) === '/';

Probably the build file is not linted and Qt javascript engine is right.

I'm not experienced with javascript and according to the reference <text>.substr() function is available and the substr function is declared by ejs.

xor-gate commented 2 years ago

The weird thing is the variable "u" could not be found by manually looking at those reported warning lines.

xor-gate commented 2 years ago

It's no big deal, probably it is due to some oddities with the Qt 6 javascript engine. Thanks for your time, I will close it as its only a warning.