ES6 modules

95 views
Skip to first unread message

Jimmy Hastings

unread,
May 24, 2018, 8:22:49 PM5/24/18
to chromi...@chromium.org, mich...@chromium.org, dpa...@chromium.org
https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/es6_chromium.md#modules

They've been supported in Chrome since M61.  Seems like an elegant way to organize code if you're in an environment where you can make it work (Not having non-module code that needs to depend on you).  I made it work for a self-contained component extension.  A module author would need to add
  "parserOptions": {
    "sourceType": "module",
  },
to an .eslintrc to make the presubmits happy.  js2g tests can be shoehorned to work with it by having it import an html file that contains something like
<script type="module">
  import * as devtools from './devtools.js';
  window.devtools = devtools;
</script>
That seems like the least work infrastructure-wise, but if desired it could be made more elegant.

Discuss!

-Jimmy

dpapad

unread,
May 24, 2018, 8:56:31 PM5/24/18
to Chromium-dev, mich...@chromium.org, dpa...@chromium.org
The title of this thread is probably a bit too generic. See previous ES6 styleguide proposal threads as examples for template literals, arrow functions, new static methods, default parameters.
The main issues to figure out when proposing a new ES6 feature are
  • Does any part of our related toolchain breaks as a result of it (for example closure compiler, uglify, crisper, polymer-bundler, eslint, clang-format, PRESUBMIT checks)?
  • Which platforms that Chromium runs support that feature (does iOS for example support it)? If not there needs to be a note in the styleguide (sometimes even a PRESUBMIT check), to prevent such usage.
Overall, I think using ES6 modules is positive, so personally I support it, but we need to figure out whether anything breaks by doing so.

Hope this helps,
Thank you,
Demetrios

Mike Frysinger

unread,
May 25, 2018, 4:23:00 AM5/25/18
to Demetrios Papadopoulos, chromium-dev, Michael Giuffrida

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/d30ac84f-62e9-4450-810b-aed64516609d%40chromium.org.

Michael Giuffrida

unread,
May 25, 2018, 4:29:54 AM5/25/18
to Mike Frysinger, Demetrios Papadopoulos, chromium-dev, Michael Giuffrida
I'm not too concerned with the Google style guide's take on ES6 modules because Google practically treats the Closure library like a built-in, so they don't need modules due to universal goog.module and goog.require statements.

Mike Frysinger

unread,
May 25, 2018, 4:35:19 AM5/25/18
to Michael Giuffrida, Demetrios Papadopoulos, chromium-dev
https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/web.md#JavaScript
> Style
> See the Google JavaScript Style Guide.

a proposal to deviate from the agreed upon style guide should clearly explain why the deviation is acceptable.
-mike

jhas...@chromium.org

unread,
May 25, 2018, 12:35:43 PM5/25/18
to Chromium-dev, mich...@chromium.org, dpa...@chromium.org
Style guide deviation: It seems like an acceptable deviation because we don't have to deal with cross-browser compatibility, so only we only need to worry about Chrome's semantics, which have been implemented for 7 versions now.  Furthermore, Closure library is basically a built-in with normal google code, so there's no reason for it there.
Related toolchain: I'm not super familiar with all the tools, so I don't know if it breaks any related toolchains.  I know that It compiles and runs fine in the way I did it, and it works with es style presubmits with the .eslintrc.
Platforms: It's a feature of the browser and v8, not the OS?  I'm not sure why it wouldn't be supported on iOS.  I might be missing something.

Sylvain Defresne

unread,
May 25, 2018, 12:45:22 PM5/25/18
to jhas...@chromium.org, Chromium-dev, mich...@chromium.org, Demetrios Papadopoulos
Chrome on iOS uses WKWebView to render html/javascript, not v8. So basically if uses what Safari does support on iOS, not what v8 supports.
-- Sylvain

PhistucK

unread,
May 25, 2018, 12:47:53 PM5/25/18
to jhas...@chromium.org, Chromium-dev, Michael Giuffrida, Demetrios Papadopoulos
Chrome for iOS is really a skinned Safari. It uses WKWebView and not Blink or V8, so it supports whatever WKWebView supports.
Modules were introduced around iOS 10.3, so any Chrome version that can run on earlier iOS versions, would fail to run native module code.

PhistucK


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/faf84f7b-ba11-4959-aebe-7b2d3c4ca668%40chromium.org.

PhistucK

unread,
May 25, 2018, 12:49:46 PM5/25/18
to Sylvain Defresne, jhas...@chromium.org, Chromium-dev, Michael Giuffrida, Demetrios Papadopoulos
Unfortunately, even WKWebKit does not fully support everything that Safari supports (well, this is plaguing Android Web View as well), so always make sure it works in WKWebKit, even if it works in Safari.

PhistucK


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

Jimmy Hastings

unread,
May 25, 2018, 3:54:01 PM5/25/18
to phis...@gmail.com, sdef...@chromium.org, chromi...@chromium.org, mich...@chromium.org, dpa...@chromium.org
(Changing subject per dpapad's suggestion)

Does anyone have an iOS device they can test on?  This seems like a knowable problem, even though none of the compatibility tables I found list Chrome on iOS.

Should it be found not to work, any objection to saying it's allowed in desktop-only code?

kai zhu

unread,
May 26, 2018, 6:58:28 AM5/26/18
to Chromium-dev, es-discuss
adding people from es-di...@mozilla.org into the loop, to give us insight on the state of es6-module adoption.


Michael Giuffrida

unread,
May 31, 2018, 1:16:39 AM5/31/18
to Chromium-dev, es-di...@mozilla.org
Interestingly, clang-format does not wrap long import lines: https://chromium-review.googlesource.com/c/chromium/src/+/1071230/6/chrome/browser/resources/chromeos/assessmentassistant/background/locking.js#7

Any particular reason import/export lines shouldn't wrap?
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.

Jimmy Hastings

unread,
May 31, 2018, 8:10:17 PM5/31/18
to mich...@chromium.org, chromi...@chromium.org, es-di...@mozilla.org
I think in general import statements are a different kind of thing than code, and wrapping them does not improve understanding.  Looking through Chromium code, I only found one example of an import statement exceeding the line length without wrapping, and no examples of it wrapping.  That said, it's not very important to me.

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to a topic in the Google Groups "Chromium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/a/chromium.org/d/topic/chromium-dev/grGmTTAxOg0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/3539dbdc-c143-480c-ae33-527489aca08c%40chromium.org.
Reply all
Reply to author
Forward
0 new messages