# All files / src/parser import.js

100% Statements 11/11
100% Branches 2/2
100% Functions 1/1
100% Lines 11/11

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    28x
    28x

    14x
    14x

    14x
    1x

    13x

    13x
    13x

    13x

    13x

     // @flow
    import Syntax from "../Syntax";
    import expression from "./expression";

    import type Context from "./context";
    import type { NodeType } from "../flow/types";

    export default function parseImport(ctx: Context): NodeType {
      const baseNode = ctx.startNode();
      ctx.eat(["import"]);

      if (!ctx.eat(["{"])) {
        throw ctx.syntaxError("expected {");
      }

      const fields = expression(ctx);

      ctx.expect(["}"]);
      ctx.expect(["from"]);

      const module = expression(ctx);

      return ctx.endNode({ ...baseNode, params: [fields, module] }, Syntax.Import);
    }