closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

import with assert not recognised by linter

Open nielm opened this issue 4 years ago • 3 comments

The syntax to import JSON modules uses module import assertions, recently added to JS and HTML specs, and supported by Chrome

(ref: tc39/proposal-json-modules, crbug.com/1132413, crbug.com/v8/10958)

import json_object_name from './some_file.json' assert {type : 'json'};

This is not recognised by the JS linter:

Parse error. Semi-colon expected
import shortlink_patterns from './some_file.json' assert {type : 'json'};
                                                  ^

nielm avatar Oct 19 '21 16:10 nielm

Same

ERROR - [JSC_PARSE_ERROR] Parse error. Semi-colon expected
 import ABI from './abi.json' assert { type: "json" }

wellgamer789 avatar Oct 16 '22 03:10 wellgamer789

Fair warning: The closure-compiler team is not likely to prioritize this because:

  1. Problems with supporting ES6 import / export have led us to deprioritize support for it and recommend using goog.module() and goog.require() instead.
  2. We have never intended to support linting of JSON files.
  3. Even if we had really good support for ES6 import / export, it would still be a feature request to allow it to handle import of non-JS-module files.

Sorry.

brad4d avatar Oct 17 '22 18:10 brad4d

Just to clarify, this bug/FR is just so that the linter recognises the ES6 import statement for json files, not to actually import and lint the JSON.

But I understand that the linter is part of the compiler, so it would technically need the closure compiler to handle ES6 JSON imports...

Thanks for the feedback.

nielm avatar Oct 19 '22 09:10 nielm