type annotate babylon
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
/**
|
||||
* Based on the comment attachment algorithm used in espree and estraverse.
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
// A recursive descent parser operates by defining functions for all
|
||||
// syntactic elements, and recursively calling those, each function
|
||||
// advancing the input stream and returning an AST node. Precedence
|
||||
@@ -793,7 +795,7 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
|
||||
// normal function
|
||||
if (!isExpression && node.body.directives.length) {
|
||||
for (var directive of (node.body.directives: Array)) {
|
||||
for (var directive of (node.body.directives: Array<Object>)) {
|
||||
if (directive.value === "use strict") {
|
||||
checkLVal = true;
|
||||
checkLValStrict = true;
|
||||
@@ -809,7 +811,7 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
if (node.id) {
|
||||
this.checkLVal(node.id, true);
|
||||
}
|
||||
for (let param of (node.params: Array)) {
|
||||
for (let param of (node.params: Array<Object>)) {
|
||||
this.checkLVal(param, true, nameHash);
|
||||
}
|
||||
this.state.strict = oldStrict;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
import { reservedWords } from "../util/identifier";
|
||||
import { getOptions } from "../options";
|
||||
import Tokenizer from "../tokenizer";
|
||||
@@ -7,7 +9,7 @@ import Tokenizer from "../tokenizer";
|
||||
export const plugins = {};
|
||||
|
||||
export default class Parser extends Tokenizer {
|
||||
constructor(options, input) {
|
||||
constructor(options, input: string) {
|
||||
options = getOptions(options);
|
||||
super(options, input);
|
||||
|
||||
@@ -25,11 +27,11 @@ export default class Parser extends Tokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
hasFeature(name) {
|
||||
hasFeature(name: string): boolean {
|
||||
return !!this.options.features[name];
|
||||
}
|
||||
|
||||
extend(name, f) {
|
||||
extend(name: string, f: Function) {
|
||||
this[name] = f(this[name]);
|
||||
}
|
||||
|
||||
@@ -41,7 +43,13 @@ export default class Parser extends Tokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
parse() {
|
||||
parse(): {
|
||||
type: "File",
|
||||
program: {
|
||||
type: "Program",
|
||||
body: Array<Object>
|
||||
}
|
||||
} {
|
||||
let file = this.startNode();
|
||||
let program = this.startNode();
|
||||
this.nextToken();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
import { getLineInfo } from "../util/location";
|
||||
import Parser from "./index";
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
import { types as tt } from "../tokenizer/types";
|
||||
import Parser from "./index";
|
||||
import { reservedWords } from "../util/identifier";
|
||||
@@ -18,7 +20,7 @@ pp.toAssignable = function (node, isBinding) {
|
||||
|
||||
case "ObjectExpression":
|
||||
node.type = "ObjectPattern";
|
||||
for (let prop of (node.properties: Array)) {
|
||||
for (let prop of (node.properties: Array<Object>)) {
|
||||
if (prop.type === "SpreadProperty") continue;
|
||||
if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter");
|
||||
this.toAssignable(prop.value, isBinding);
|
||||
@@ -184,14 +186,14 @@ pp.checkLVal = function (expr, isBinding, checkClashes) {
|
||||
break;
|
||||
|
||||
case "ObjectPattern":
|
||||
for (let prop of (expr.properties: Array)) {
|
||||
for (let prop of (expr.properties: Array<Object>)) {
|
||||
if (prop.type === "Property") prop = prop.value;
|
||||
this.checkLVal(prop, isBinding, checkClashes);
|
||||
}
|
||||
break;
|
||||
|
||||
case "ArrayPattern":
|
||||
for (let elem of (expr.elements: Array)) {
|
||||
for (let elem of (expr.elements: Array<Object>)) {
|
||||
if (elem) this.checkLVal(elem, isBinding, checkClashes);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
import Parser from "./index";
|
||||
import { SourceLocation } from "../util/location";
|
||||
|
||||
@@ -5,15 +7,20 @@ import { SourceLocation } from "../util/location";
|
||||
|
||||
const pp = Parser.prototype;
|
||||
|
||||
export class Node {
|
||||
constructor(parser, pos, loc) {
|
||||
class Node {
|
||||
constructor(pos?: number, loc?: SourceLocation) {
|
||||
this.type = "";
|
||||
this.start = pos;
|
||||
this.end = 0;
|
||||
this.loc = new SourceLocation(loc);
|
||||
}
|
||||
|
||||
__clone() {
|
||||
type: string;
|
||||
start: ?number;
|
||||
end: number;
|
||||
loc: SourceLocation;
|
||||
|
||||
__clone(): Node {
|
||||
var node2 = new Node;
|
||||
for (var key in this) node2[key] = this[key];
|
||||
return node2;
|
||||
@@ -21,11 +28,11 @@ export class Node {
|
||||
}
|
||||
|
||||
pp.startNode = function () {
|
||||
return new Node(this, this.state.start, this.state.startLoc);
|
||||
return new Node(this.state.start, this.state.startLoc);
|
||||
};
|
||||
|
||||
pp.startNodeAt = function (pos, loc) {
|
||||
return new Node(this, pos, loc);
|
||||
return new Node(pos, loc);
|
||||
};
|
||||
|
||||
function finishNodeAt(node, type, pos, loc) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
import { types as tt } from "../tokenizer/types";
|
||||
import Parser from "./index";
|
||||
import { lineBreak } from "../util/whitespace";
|
||||
@@ -380,7 +382,7 @@ pp.parseEmptyStatement = function (node) {
|
||||
};
|
||||
|
||||
pp.parseLabeledStatement = function (node, maybeName, expr) {
|
||||
for (let label of (this.state.labels: Array)){
|
||||
for (let label of (this.state.labels: Array<Object>)){
|
||||
if (label.name === maybeName) {
|
||||
this.raise(expr.start, `Label '${maybeName}' is already declared`);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* @flow */
|
||||
|
||||
import { types as tt } from "../tokenizer/types";
|
||||
import Parser from "./index";
|
||||
import { lineBreak } from "../util/whitespace";
|
||||
|
||||
Reference in New Issue
Block a user