var MethodDefinition = function(symbol, opt_docHelper, opt_refHelper) {
  MemberDefinition.call(this, symbol, opt_docHelper, opt_refHelper);
  var dd = this.getDefinitionDescritions();

  if (tsumekusaJsdoc.hasParam(symbol)) {
    var paramsDefinition = this.createParametersDefinition(symbol);
    dd.addChild(paramsDefinition.getElement());
  }
  if (tsumekusaJsdoc.hasReturn(symbol)) {
    var returnsDefinition = this.createReturnsDefinition(symbol);
    dd.addChild(returnsDefinition.getElement());
  }
};
Exemple #2
0
ConkittyParser.prototype.readJS = function readJS(indent, noRaw) {
    var ch,
        ch2,
        ch3,
        ret,
        val = [];

    this.inStringOrJS = true;

    if (!indent) {
        ch = this.nextChar();
        if (ch.val !== '(') {
            throw new ConkittyErrors.UnexpectedSymbol(this);
        }

        ret = new ConkittyCommandPart(ConkittyTypes.JAVASCRIPT, this);

        var brackets,
            inString = false,
            inRegExp = false,
            raw = false;

        brackets = 1;

        ch2 = this.nextChar();
        ch3 = this.nextChar();

        if (!noRaw && ch2.val === '(' && ch3.val === '(') {
            raw = true;
        } else {
            this.pushBack(2);
        }

        ch = this.nextChar();
        while (!ch.EOF) {
            if (!inString && !inRegExp) {
                if (ch.val === '(') {
                    brackets++;
                } else if (ch.val === ')') {
                    brackets--;
                    // Avoiding this: (((   function(){})(   ))).
                    if (brackets === 0) {
                        ch2 = this.nextChar();
                        ch3 = this.nextChar();
                        if (raw && (ch2.val !== ')' || ch3.val !== ')')) {
                            this.pushBack(2);
                            brackets += 2;
                            raw = false;
                            val.unshift('((');
                        } else {
                            if (!raw) { this.pushBack(2); }
                            break;
                        }
                    }
                } else if (ch.val === '"' || ch.val === "'") { //eslint-disable-line quotes
                    inString = ch.val;
                } else if (ch.val === '/') {
                    // inRegExp = true;
                }
            } else if (inString) {
                ch2 = this.nextChar(true);
                if (ch.val === '\\' && (ch2.val === '\\' || ch2.val === inString)) {
                    val.push('\\');
                    ch = this.nextChar();
                } else if (ch.val === inString) {
                    inString = false;
                }
            } else { // inRegExp.
                if (ch.val === '\\') {
                    val.push('\\');
                    ch = this.nextChar();
                } else if (ch.val === '/') {
                    inRegExp = false;
                }
            }

            if (ch.val) {
                val.push(ch.val);
            } else if (ch.EOL && !ch.EOF) {
                val.push('\n');
            } else {
                break;
            }
            ch = this.nextChar();
        }

        if (ch.EOF) {
            throw new ConkittyErrors.UnterminatedPart(ret);
        }

        val = val.join('');

        if (!strip(val)) {
            throw new ConkittyErrors.JSParseError('Empty expression', this, ret.lineAt, ret.charAt);
        }

        ret.raw = raw;
        ret.expr = true;
        ret.value = val;
    } else {
        var newIndent,
            i;

        this.skipEmptyLines();
        ret = new ConkittyCommandPart(ConkittyTypes.JAVASCRIPT, this);

        while (((newIndent = this.getIndent())) > indent) {
            this.pushBack(newIndent);

            for (i = 0; i < indent; i++) {
                this.nextChar();
            }

            while (!((ch = this.nextChar())).EOL) {
                val.push(ch.val);
            }

            i = 0;
            ch2 = null;
            while (!ch.EOF && ch.EOL) {
                val.push('\n');
                i = this.skipWhitespaces();
                ch = ch2 = this.nextChar();
            }

            if (ch2 && !ch2.EOF) {
                this.pushBack(i + 1);
            }
        }

        this.pushBack(newIndent + 1);

        val = val.join('');

        ret.raw = false;
        ret.expr = false;
        ret.value = val;

        if (!strip(val)) {
            throw new ConkittyErrors.JSParseError('Empty expression', this, ret.lineAt, ret.charAt);
        }
    }

    try {
        val = (indent ? utils.parseJSFunction : utils.parseJSExpression)(val);
        if (val[1].length === 1 && val[1][0][0] === 'function') {
            // Check if function has name or arguments in use.
            ret.isFunc = val[1][0][1] || val[1][0][2].length > 0 || utils.hasReturn(val[1][0][3]);
            if (!ret.isFunc) {
                // It is just a wrapper, function name is not used, arguments,
                // are not used, and no return statement — extract just body
                // to be able to merge it with other bodies.
                val[1] = val[1][0][3];
                ret.value = utils.adjustJS(val);
            }
        } else {
            ret.isFunc = false;
        }
    } catch(e) {
        throw new ConkittyErrors.JSParseError(
            e.message,
            this,
            ret.lineAt + e.line - 2,
            (indent || e.line > 2 ? (indent || 0) - 1 : ret.charAt + (ret.raw ? 2 : 0)) + e.col
        );
    }

    this.inStringOrJS = false;

    return ret;
};