Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/export directives ignored when not at the start of line #4122

Open
msevcenko opened this issue Sep 13, 2023 · 2 comments
Open

import/export directives ignored when not at the start of line #4122

msevcenko opened this issue Sep 13, 2023 · 2 comments

Comments

@msevcenko
Copy link

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.

@niloc132
Copy link
Contributor

That does seem inconsistent, as the various goog.* patterns do not have that limitation, but it is explicitly documented as being different:

/**
* Pattern for matching import ... from './path/to/file'.
*
* <p>Unlike the goog.require() pattern above, this pattern does not allow multiple statements per
* line. The import/export <b>must</b> be at the beginning of the line to match.
*/
private static final Pattern ES6_MODULE_PATTERN =

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?

@msevcenko
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants