closure-compiler
closure-compiler copied to clipboard
import/export directives ignored when not at the start of line
When debugging problems with unresolved import paths, it turned out that parsing import directives is triggered only when the directive actually starts the line:
JsFileRegexParser:347 (in version 20220601)
if (line.startsWith("import") || line.startsWith("export")) {
If you put whitespace before the import directive, it is just ignored.
Not sure if this is correct and/or intentional, in any case it is rather unexpected.
That does seem inconsistent, as the various goog.*
patterns do not have that limitation, but it is explicitly documented as being different:
https://github.com/google/closure-compiler/blob/31018cb5b34f87d3ba519617be9e99eae7bb35de/src/com/google/javascript/jscomp/deps/JsFileRegexParser.java#L58-L64
The comment seems to suggest (but doesn't outright state) that this is to keep only one statement per line, but then goes on to say that it must be at the start of the line. Perhaps leading whitespace could be acceptable, while still keeping one statement per line?
Ok, just a strange glitch.
Not sure what are the exact consequences of ignoring the directive. Sometimes only the fact that the desired function (minification) actually works. Because processing the directive (in an environment when it cannot be resolved) is often something that user does not want or expect.
And AFAIK, processing static directives cannot be suppressed, can it? Only processing of the dynamic directives can be suppressed with --allow_dynamic_import
, right?