Skip to content

Await insert break ASI #33522

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

Closed
Kingwl opened this issue Sep 20, 2019 · 6 comments · Fixed by #34627
Closed

Await insert break ASI #33522

Kingwl opened this issue Sep 20, 2019 · 6 comments · Fixed by #34627
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@Kingwl
Copy link
Contributor

Kingwl commented Sep 20, 2019

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

async function foo () {
  const a: Promise<any> = f()
  a./*here*/
}

Expected behavior:

;(await a).xxx

Actual behavior:

async function foo () {
  const a: Promise<any> = f()
  (await a).xxx // asi broken here
}

Playground Link:

https://twitter.com/Luxcium/status/1174602967053471744

Related Issues:

@fatcerberus
Copy link

await a.xxx

That wouldn't be the right thing to do because it would be parsed as await (a.xxx) and a is a promise. Which is why the await is being added in the first place. 😄

@Kingwl
Copy link
Contributor Author

Kingwl commented Sep 20, 2019

friendly ping @andrewbranch
Could you give some suggestions please?I cannot find some existed things about ASI detection....

@Luxcium
Copy link

Luxcium commented Sep 20, 2019

My issue was open there
I provided code example of my actual issue

But in fact as I am coding I am relying on the linter to add semis on save and if autocompletion add parenthesis it should also take care of not becoming continuation of previous line... await by itself or code by itself will not cause problems because of the automatic semi insertion but a set of parenthesis added on the fly change this behaviour and become continuation of previous line...

in most cases it probably requires to add a semi when autocompleting with a set of parenthesis but some edge cases might implies not doing it but I am not sure why if the parenthesis would have been the continuation of previous line I assume it would have been added by the person not as a completion in that context I think

@Luxcium
Copy link

Luxcium commented Sep 20, 2019

It’s nice because now automatic completion implement not only then/catch/finally but also of the « then resolved promises » by adding an await inside a set of parenthesis then a dot and then the other possibility

(async _=>{
const some:any  = await a;
const something:any = some.xxx('do something')
})()

now autocomplete and save you of assigning to an intermediary variable

(async _=>{
const something:any = (await a).xxx('do something');
})()

If you don’t need to say save to a variable/const then

This ...

(async _=>{
  const a: Promise<any> = f()
  (await a).xxx('do something') // asi broken here
})()

... is the same as this:

(async _=>{
  const a: Promise<any> = f()(await a).xxx('do something') // asi broken here
})()

@andrewbranch
Copy link
Member

@Kingwl I added a lot of ASI logic in #33402; does that look helpful?

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Sep 20, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.0 milestone Sep 20, 2019
@Kingwl
Copy link
Contributor Author

Kingwl commented Oct 21, 2019

Hi all, sadly I’m not 100% sure what could i do....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants