Tools: Resulting import statements uses JS reserved keywords

Created on 8 Sep 2017  路  9Comments  路  Source: Polymer/tools

For example:

import * as async from '../../polymer/lib/utils/async.js';

Ref https://github.com/PolymerElements/app-layout/issues/511

cc @justinfagnani @bicknellr

modulizer Medium Available Bug

Most helpful comment

async is technically not reserved - see demos above. async/await has already shipped in Chrome, and async can be used as an id.

All 9 comments

async doesn't actually appear to be a reserved word in the spec, even though async functions are definitely in there. I just talked with Adam and he mentioned that async should be an acceptable identifier. I think this is a JSC bug.

/index.html

<script type="module">
import * as async from "./mod.js";
console.log(async.a, async.b);
</script>

/mod.js

export const a = 1234;
export const b = 5678;

Isn't this only not a reserved keyword until we have fully implemented async/await? eg:

function getMeep() {
  return new Promise((resolve, reject) => {
    return 'meep';
  });
}

async function speak() {
  console.log(await getMeep());
}

async is technically not reserved - see demos above. async/await has already shipped in Chrome, and async can be used as an id.

You are absolutely correct (It's not planned to be reserved at all):
https://tc39.github.io/ecma262/#sec-keywords

But take it from a practical standpoint, let's try to fix some code with two occurrences of async, one is a regular function called async and the other is not a reserved keyword, but is a keyword before an anonymous arrow function:

  function async() {鈥 
  async () => {}

So while it is not a reserved keyword, it still might not be very friendly from a development standpoint.

I think there needs to be a bug report with WebKit (not sure how that works out nowadays). Sorry I missed your comment about one being filed!

But it would really help the polymer community gain more traction with 3.0 to minimize such barriers across non-conforming platforms without any added special considerations.

Yeah, I'd call using async as an identifier as unclear at best. We should avoid creating identifiers named after keywords, things that are kinda keywords but legal identifiers (like async, yield, await), and important built in values (like Element, window, global, self, undefined)

WebKit has fixed this issue (async can be used as an identifier) and is in Safari TP. Should this be closed then @rictic ?

Seems ok to close to me, though depending on what versions of Safari contain this bug we may still have to avoid async.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

emilbillberg picture emilbillberg  路  3Comments

lpellegr picture lpellegr  路  4Comments

Westbrook picture Westbrook  路  4Comments

marcushellberg picture marcushellberg  路  3Comments

idoshamun picture idoshamun  路  3Comments