2

I am trying to resolve warnings I get when using the closure compiler to minify my TypeScript application, using my tsconfig.json.

My current configuration:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "noImplicitAny": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "outFile": "app.js",
    "sourceMap": true
  },
  "files": [ ... ]
}

However I am getting the following warning, for the use of the keywords delete, finally and abstract:

WARNING - Keywords and reserved words are not allowed as unquoted property names in older versions of JavaScript. If you are targeting newer versions of JavaScript, set the appropriate language_in option.

I did see the answer, How can I set the language_in option for the Closure compiler? which suggests using --compiler_flags="--language_in=ECMASCRIPT5" to resolve, but that's what I thought "target": "es5" was doing in my tsconfig.json?

So despite having target set, and I can see no other configuration options to the effect of language_in having read the tsconfig.json spec, I am unsure how to resolve.

Obviously, I could quote the property names, or ignore the warnings, but I wish to resolve the warnings, as I don't target older browsers.

Community
  • 1
  • 1
Scott
  • 21,211
  • 8
  • 65
  • 72

2 Answers2

1

tsconfig.json is used by the TypeScript compiler, shoving Closure compiler options in there ain't gonna work, and the Closure compiler wouldn't know what to do with the tsconfig.json anyway. The input to the Closure compiler should be JavaScript (ES3, ES5, or ES6), not TypeScript, so you need to set up your build process to compile your TypeScript source to JavaScript, and then feed the JavaScript to the Closure compiler. In the question you've linked the options to the Closure compiler are passed on the commandline when invoking it.

Vadim Macagon
  • 14,463
  • 2
  • 52
  • 45
  • While I appreciate you couldn't load the `tsconfig.json` into the Closure compiler directly. I wrongly thought the TypeScript compiler passed options onto the Closure compiler (as built-in minification support). But as it transpired the process was being run by a separate file watching in the WebStorm IDE, even though the IDE reported the error as originating from the TypeScript Compiler. – Scott Feb 02 '16 at 17:45
1

I had wrongly assumed that the TypeScript compiler used the Closure compiler to minify the resultant JavaScript file(s) after compilation, because these error were logged in the WebStorm IDE as output from the TypeScript compiler. So WebStorm threw my down the wrong path.

But the error message is from a separate Closure compiler file watcher which would have run after the TypeScript compiler ran.

Changing the tsconfig.json options therefore did also effect the output, making me think the process was connected.

Having tracked down the file watcher, I can modify the options in there using the compiler flag, noted in the question.

Scott
  • 21,211
  • 8
  • 65
  • 72