05-19-2019 08:52 - edited 05-19-2019 08:53
05-19-2019 08:52 - edited 05-19-2019 08:53
Hello
While developing a watchface, I found out that the declaration of const variables is not enforced later on.
For example:
const foo = "foo"; foo = "bar"; console.log(foo);
Will print "bar" (since the declaration is transpiled to "var foo")
I'm not familiar enough with the Javascript ecosystem.
Is there a way to enforce a syntax check during the build?
05-20-2019 11:53 - edited 05-20-2019 11:54
05-20-2019 11:53 - edited 05-20-2019 11:54
Found out a solution that is working for my particular case:
module.exports = { "env": { "browser": true, "es6": true }, "extends": "eslint:recommended", "globals": { }, "parserOptions": { "ecmaVersion": 2018, "sourceType": "module" }, "rules": { "no-console": "off",
// unused vars should be stripped by the transpile step "no-unused-vars": "warn", } };
07-20-2019 05:17
07-20-2019 05:17
The watch only supports ES5, which predates const being added to JavaScript. If you use const in companion/settings, it'll behave as you expect.
In the future, we might be able to detect at compile time with the help of TypeScript when you've attempted to modify a const value.