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

Validate importKind and ensure code generation exists. #5110

Merged
merged 1 commit into from Jan 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/babel-generator/src/generators/modules.js
@@ -1,6 +1,11 @@
import * as t from "babel-types";

export function ImportSpecifier(node: Object) {
if (node.importKind === "type" || node.importKind === "typeof") {
this.word(node.importKind);
this.space();
}

this.print(node.imported, node);
if (node.local && node.local.name !== node.imported.name) {
this.space();
Expand Down
Expand Up @@ -97,6 +97,10 @@ import type { foo as bar } from "baz";
import type from "foo";
import type, { foo } from "bar";
import type * as namespace from "bar";
import { type Foo } from "bar";
import { typeof Foo } from "bar";
import { type Foo as Bar } from "bar";
import { typeof Foo as Bar } from "bar";
export type { foo };
export type { bar } from "bar";
export interface baz { p: number };
Expand Down
Expand Up @@ -101,6 +101,10 @@ import type { foo as bar } from "baz";
import type from "foo";
import type, { foo } from "bar";
import type * as namespace from "bar";
import { type Foo } from "bar";
import { typeof Foo } from "bar";
import { type Foo as Bar } from "bar";
import { typeof Foo as Bar } from "bar";
export type { foo };
export type { bar } from "bar";
export interface baz { p: number };
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-types/src/definitions/es2015.js
Expand Up @@ -227,6 +227,10 @@ defineType("ImportSpecifier", {
},
imported: {
validate: assertNodeType("Identifier")
},
importKind: {
// Handle Flowtype's extension "import {typeof foo} from"
validate: assertOneOf(null, "type", "typeof")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could do extensions to nodes in corresponding files. So that flow.js could extend ImportSpecifier. But for now there is no other way afaics.

}
}
});
Expand Down