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

Multi-line ES6 import #2175

Closed
supersteves opened this issue Nov 28, 2016 · 10 comments
Closed

Multi-line ES6 import #2175

supersteves opened this issue Nov 28, 2016 · 10 comments

Comments

@supersteves
Copy link
Contributor

import {
    something,
    somethingElse,
    inFactAVeryLongList,
    ofLotsOfThings,
    whichIsUglyOnOneLine
} from "./MyAllPurposeUtil";

This doesn't get picked up by the regex import scanning in Closure Compiler, because it assumes each statement is one per line:

https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/deps/JsFileParser.java#L41

Probably tough to fix. But also something that can be hard to diagnose.

Easy workaround:

import {
    ...
} from "./MyAllPurposeUtil";
import "./MyAllPurposeUtil"; // tell CC about this dep
@ChadKillingsworth
Copy link
Collaborator

Regex parsing for ES6 modules is causing problems in other areas. I'm going to discuss it at the meeting this afternoon to figure out options.

@MatrixFrog
Copy link
Contributor

@shicks am I remembering correctly that we decided to make this a one-line regex instead of multi-line for simplicity/speed? I think the style guide says not to wrap the line but projects outside of Google are likely not to follow our style guide.

@ChadKillingsworth
Copy link
Collaborator

@shicks Is this just when using the deps package? It looks like the ProcessEs6Modules properly adds the deps information.

@supersteves
Copy link
Contributor Author

That's right, I only came across this when relying upon the deps package result. It correctly builds providing the deps haven't been dropped.

@shicks
Copy link
Member

shicks commented Nov 29, 2016 via email

@supersteves
Copy link
Contributor Author

Alternative workaround:

import { something, somethingElse, inFactAVeryLongList } from "./MyAllPurposeUtil";
import { ofLotsOfThings, whichIsUglyOnOneLine } from "./MyAllPurposeUtil";

@supersteves
Copy link
Contributor Author

Perhaps the deps parser could detect an unclosed import statement and emit a warning.

@ChadKillingsworth
Copy link
Collaborator

To my knowledge, the deps package has little use outside of Google. Changing it is also difficult for an external contributor for all the reasons @shicks listed.

I looked into what would be required to change this and don't have the bandwidth to tackle it. Since this doesn't affect full compilations in any way, It's not a priority for me right now.

@timdawborn
Copy link
Contributor

I realise this is a stale ticket now, but this worked with STRICT dependency mode for a while and then stopped working again. The v20170521 release was the latest working release. It'd be really nice to not have to change our entire codebase to not use multi-line imports just so we can use a newer Closure release :/

Repro:

$ cat foo.js
export const FOO = 1;
export const BAR = 2;

$ cat entry-single.js
import { BAR, FOO } from './foo.js';

export const BAZ = FOO + BAR;

$ cat entry-multi.js
import {
  BAR,
  FOO,
} from './foo.js';

export const BAZ = FOO + BAR;

$ for j in $(find . -name '*.jar' | sort); do echo $j; java -jar $j --js foo.js --js entry-single.js --entry_point entry-single.js --js_output_file /dev/null --dependency_mode STRICT; done
./v20170423.jar
./v20170521.jar
./v20170626.jar
./v20170806.jar
./v20170910.jar

$ for j in $(find . -name '*.jar' | sort); do echo $j; java -jar $j --js foo.js --js entry-multi.js --entry_point entry-multi.js --js_output_file /dev/null --dependency_mode STRICT; done
./v20170423.jar
./v20170521.jar
./v20170626.jar
entry-multi.js:1: ERROR - required "module$foo" namespace never provided
import {
^^^^^^^^

1 error(s), 0 warning(s)
./v20170806.jar
entry-multi.js:1: ERROR - required "module$foo" namespace never provided
import {
^^^^^^^^

1 error(s), 0 warning(s)
./v20170910.jar
entry-multi.js:1: ERROR - required "module$foo" namespace never provided
import {
^^^^^^^^

1 error(s), 0 warning(s)

@ChadKillingsworth
Copy link
Collaborator

This was fixed by #2641

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

5 participants