module()

in lib/parser.js [115:177]


  module() {
    var annotation;
    if (this.is(Tag.ANNOTATION)) {
      annotation = this.look;
      this.move();
    }

    const imports = [];

    while (this.is(Tag.IMPORT)) {
      const begin = this.getIndex();
      this.move();
      let innerPath;
      if(this.is(Tag.STRING)) {
        innerPath = this.look.string;
        this.move();
      }
      let alias = this.look;
      let end = this.getIndex();
      this.match(Tag.ID);
      if(innerPath) {
        alias.innerPath = innerPath;
      }
      // import A.B as AB
      if (this.look.tag === '.') {
        this.move();
        const mainModule = alias.lexeme;
        alias = this.look;
        end = this.getIndex();
        const module = alias.lexeme;
        this.match(Tag.ID);
        if(this.isWord(Tag.ID, 'as')) {
          this.move();
          alias = this.look;
          this.match(Tag.ID);
          end = this.getIndex();
        }
        alias.mainModule = mainModule;
        alias.module = module;
      }
      imports.push(alias);
      if (this.is(';')) {
        end = this.getIndex();
        this.move();
      }
      alias.tokenRange = [begin, end];
    }

    let extendOn;
    if (this.is(Tag.EXTENDS)) {
      extendOn = this.extends();
    }

    return {
      annotation: annotation,
      imports: imports,
      extends: extendOn,
      type: 'module',
      moduleBody: this.moduleBody(),
      comments: this.comments,
      notes: this.notes,
    };
  }