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

Allow keywords to be used in type annotations #9184

Merged
merged 1 commit into from
Dec 15, 2018
Merged

Allow keywords to be used in type annotations #9184

merged 1 commit into from
Dec 15, 2018

Conversation

danez
Copy link
Member

@danez danez commented Dec 14, 2018

Q                       A
Fixed Issues?
Patch: Bug Fix? y
Major: Breaking Change? n
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This allows keywords to be used as type annotations like

function foo(a:function, b: switch) {}

Flow does also not error in this cases.

@danez danez added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: flow labels Dec 14, 2018
@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9614/

@jedwards1211
Copy link
Contributor

jedwards1211 commented Dec 14, 2018

@danez it does error in recent versions, even though the parser (questionably) accepts it:

$ flow
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ test.js:3:29

Cannot resolve name switch.

     1 // @flow
     2
     3 function foo(a:function, b: switch) {}
     4

It doesn't allow switch in a TypeAlias anyway so I think supporting keyword type annotations is debatable:

$ flow
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ test.js:3:6

Unexpected token switch

     1 // @flow
     2
     3 type switch = number
     4 function foo(a:function, b: switch) {}
     5

@nicolo-ribaudo
Copy link
Member

import type { s as switch, f as function } from "module";

function foo(a:function, b: switch) {}

Perfectly valid code 😛

@jedwards1211
Copy link
Contributor

jedwards1211 commented Dec 14, 2018

Just imagine if JS didn't have any reserved words 😄, like Fortran

import { as as default } from "module"

class class {
  async async() {
    function const() { }
    const function = let('foo') = () => { function(function) {...} }
    function().function(function)
    let switch = 'blah', case = 'blah', break = 'argh!'
    let await = () => ...
    await = await await()
    switch (switch) {
      case case: return break
      case default: return await
      default: return case
    }
  }
}

@danez danez merged commit 5cb3899 into babel:master Dec 15, 2018
@danez danez deleted the fix-flow-keywords branch December 15, 2018 20:51
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: flow outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants