Skip to content

Commit

Permalink
fix: declare name in flowParseInterfaceish
Browse files Browse the repository at this point in the history
- Set BIND_LEXICAL to interfaceish
- Set BIND_VAR to DeclareClass
- Enter SCOPE_VAR for DeclareModule
  • Loading branch information
JLHwung committed Jul 16, 2019
1 parent ed18966 commit bbe8b3f
Show file tree
Hide file tree
Showing 19 changed files with 522 additions and 111 deletions.
Expand Up @@ -11,13 +11,13 @@ declare class A { static [ indexer: number]: string }
declare class A { static () : number }
declare class B { (): number }
declare class A mixins B<T>, C {}
declare type A = string
declare type A1 = string
declare type T<U> = { [k:string]: U }
declare type B = {
declare type B1 = {
fn?: (foo: string) => void,
}
declare interface I { foo: string }
declare interface I<T> { foo: T }
declare interface I1 { foo: string }
declare interface I2<T> { foo: T }
declare module.exports: { foo: string }
declare opaque type Foo<T>: Bar<T>;
declare opaque type ID;
Expand Down
Expand Up @@ -22,17 +22,17 @@ declare class B {
(): number
}
declare class A mixins B<T>, C {}
declare type A = string;
declare type A1 = string;
declare type T<U> = {
[k: string]: U
};
declare type B = {
declare type B1 = {
fn?: (foo: string) => void
};
declare interface I {
declare interface I1 {
foo: string
}
declare interface I<T> {
declare interface I2<T> {
foo: T
}
declare module.exports: {
Expand Down
Expand Up @@ -5,10 +5,10 @@ type T2 = { +p: T };
type T3 = { -p: T };
type T4 = { +[k:K]: V };
type T5 = { -[k:K]: V };
interface I { +p: T }
interface I { -p: T }
interface I { +[k:K]: V }
interface I { -[k:K]: V }
interface I1 { +p: T }
interface I2 { -p: T }
interface I3 { +[k:K]: V }
interface I4 { -[k:K]: V }
declare class I { +p: T }
declare class I { -p: T }
declare class I { +[k:K]: V }
Expand Down
Expand Up @@ -15,16 +15,16 @@ type T4 = {
type T5 = {
-[k: K]: V
};
interface I {
interface I1 {
+p: T
}
interface I {
interface I2 {
-p: T
}
interface I {
interface I3 {
+[k: K]: V
}
interface I {
interface I4 {
-[k: K]: V
}
declare class I {
Expand Down
@@ -1,7 +1,7 @@
declare class C { static [[foo]]: T }
declare class C { [[foo]]: T }
interface I { [[foo]]: X }
interface I { [[foo]](): X }
interface I1 { [[foo]]: X }
interface I2 { [[foo]](): X }
type T1 = { [[foo]]: X }
type T2 = { [[foo]](): X }
type T3 = { [[foo]]?: X }
Expand Up @@ -4,10 +4,10 @@ declare class C {
declare class C {
[[foo]]: T
}
interface I {
interface I1 {
[[foo]]: X
}
interface I {
interface I2 {
[[foo]]() => X
}
type T1 = {
Expand Down
@@ -1,7 +1,7 @@
interface A {
interface A1 {
@@iterator(): Iterator<File>;
}

interface A {
interface A2 {
@@asyncIterator(): Iterator<File>;
}
@@ -1,6 +1,6 @@
interface A {
interface A1 {
@@iterator(): Iterator<File>
}
interface A {
interface A2 {
@@asyncIterator(): Iterator<File>
}
10 changes: 6 additions & 4 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -14,8 +14,9 @@ import {
type BindingTypes,
BIND_NONE,
BIND_LEXICAL,
BIND_VAR,
SCOPE_ARROW,
SCOPE_OTHER,
SCOPE_VAR,
} from "../util/scopeflags";

const reservedTypes = [
Expand Down Expand Up @@ -182,7 +183,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>

flowParseDeclareClass(node: N.FlowDeclareClass): N.FlowDeclareClass {
this.next();
this.flowParseInterfaceish(node, /*isClass*/ true);
this.flowParseInterfaceish(node, /*isClass*/ true, BIND_VAR);
return this.finishNode(node, "DeclareClass");
}

Expand Down Expand Up @@ -275,7 +276,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

flowParseDeclareModule(node: N.FlowDeclareModule): N.FlowDeclareModule {
this.scope.enter(SCOPE_OTHER);
this.scope.enter(SCOPE_VAR);

if (this.match(tt.string)) {
node.id = this.parseExprAtom();
Expand Down Expand Up @@ -459,9 +460,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
flowParseInterfaceish(
node: N.FlowDeclare,
isClass?: boolean = false,
bindKind = BIND_LEXICAL,
): void {
node.id = this.flowParseRestrictedIdentifier(/*liberal*/ !isClass);
this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start);
this.scope.declareName(node.id.name, bindKind, node.id.start);

if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
Expand Down
@@ -1,3 +1,8 @@
interface Foo {}
declare class C1 {}
declare interface I1 {}
declare type T1 = number;

export type { Foo }
interface I2 {}
type T2 = number;

export type { C1, I1, I2, T1, T2 }

0 comments on commit bbe8b3f

Please sign in to comment.