Revert "Remove Flow annotations and pragmas"
This reverts commit 4252244d06b225ab26a02d52c04f9940a3e4d6a2.
This commit is contained in:
parent
9a180797c0
commit
b5315d4b27
@ -1,8 +1,15 @@
|
||||
/* @flow */
|
||||
// A second optional argument can be given to further configure
|
||||
// the parser process. These options are recognized:
|
||||
|
||||
|
||||
export const defaultOptions = {
|
||||
export const defaultOptions: {
|
||||
sourceType: string,
|
||||
allowReturnOutsideFunction: boolean,
|
||||
allowImportExportEverywhere: boolean,
|
||||
allowSuperOutsideMethod: boolean,
|
||||
plugins: Array<string>,
|
||||
strictMode: any
|
||||
} = {
|
||||
// Source type ("script" or "module") for different semantics
|
||||
sourceType: "script",
|
||||
// When enabled, a return at the top level is not considered an
|
||||
@ -21,7 +28,7 @@ export const defaultOptions = {
|
||||
|
||||
// Interpret and default an options object
|
||||
|
||||
export function getOptions(opts) {
|
||||
export function getOptions(opts?: Object): Object {
|
||||
let options = {};
|
||||
for (let key in defaultOptions) {
|
||||
options[key] = opts && key in opts ? opts[key] : defaultOptions[key];
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
/**
|
||||
@ -118,7 +119,7 @@ pp.processComment = function (node) {
|
||||
// result in an empty array, and if so, the array must be
|
||||
// deleted.
|
||||
node.leadingComments = this.state.leadingComments.slice(0, i);
|
||||
if (node.leadingComments.length === 0) {
|
||||
if ((node.leadingComments: Array<any>).length === 0) {
|
||||
node.leadingComments = null;
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
|
||||
import { reservedWords } from "../util/identifier";
|
||||
import { getOptions } from "../options";
|
||||
@ -6,7 +7,7 @@ import Tokenizer from "../tokenizer";
|
||||
export const plugins = {};
|
||||
|
||||
export default class Parser extends Tokenizer {
|
||||
constructor(options, input) {
|
||||
constructor(options: Object, input: string) {
|
||||
options = getOptions(options);
|
||||
super(options, input);
|
||||
|
||||
@ -22,15 +23,15 @@ export default class Parser extends Tokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
hasPlugin(name) {
|
||||
hasPlugin(name: string): boolean {
|
||||
return !!(this.plugins["*"] || this.plugins[name]);
|
||||
}
|
||||
|
||||
extend(name, f) {
|
||||
extend(name: string, f: Function) {
|
||||
this[name] = f(this[name]);
|
||||
}
|
||||
|
||||
loadPlugins(plugins) {
|
||||
loadPlugins(plugins: Array<string>): Object {
|
||||
let pluginMap = {};
|
||||
|
||||
if (plugins.indexOf("flow") >= 0) {
|
||||
@ -51,7 +52,13 @@ export default class Parser extends Tokenizer {
|
||||
return pluginMap;
|
||||
}
|
||||
|
||||
parse() {
|
||||
parse(): {
|
||||
type: "File",
|
||||
program: {
|
||||
type: "Program",
|
||||
body: Array<Object>
|
||||
}
|
||||
} {
|
||||
let file = this.startNode();
|
||||
let program = this.startNode();
|
||||
this.nextToken();
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
|
||||
import { types as tt } from "../tokenizer/types";
|
||||
import Parser from "./index";
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
|
||||
// The algorithm used to determine whether a regexp can appear at a
|
||||
// given point in the program is loosely based on sweet.js' approach.
|
||||
@ -7,16 +8,27 @@ import { types as tt } from "./types";
|
||||
import { lineBreak } from "../util/whitespace";
|
||||
|
||||
export class TokContext {
|
||||
constructor(token, isExpr, preserveSpace, override) {
|
||||
constructor(
|
||||
token: string,
|
||||
isExpr?: boolean,
|
||||
preserveSpace?: boolean,
|
||||
override?: Function,
|
||||
) {
|
||||
this.token = token;
|
||||
this.isExpr = !!isExpr;
|
||||
this.preserveSpace = !!preserveSpace;
|
||||
this.override = override;
|
||||
}
|
||||
|
||||
token: string;
|
||||
isExpr: boolean;
|
||||
preserveSpace: boolean;
|
||||
override: ?Function;
|
||||
}
|
||||
|
||||
export const types = {
|
||||
export const types: {
|
||||
[key: string]: TokContext;
|
||||
} = {
|
||||
b_stat: new TokContext("{", false),
|
||||
b_expr: new TokContext("{", true),
|
||||
b_tmpl: new TokContext("${", true),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint indent: 0 */
|
||||
|
||||
import type { TokenType } from "./types";
|
||||
import { isIdentifierStart, isIdentifierChar, isKeyword } from "../util/identifier";
|
||||
import { types as tt, keywords as keywordTypes } from "./types";
|
||||
import { types as ct } from "./context";
|
||||
@ -21,6 +22,11 @@ export class Token {
|
||||
this.loc = new SourceLocation(state.startLoc, state.endLoc);
|
||||
}
|
||||
|
||||
type: TokenType;
|
||||
value: any;
|
||||
start: number;
|
||||
end: number;
|
||||
loc: SourceLocation;
|
||||
}
|
||||
|
||||
// ## Tokenizer
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* @flow */
|
||||
|
||||
// Matches a whole line break (where CRLF is considered a single
|
||||
// line break). Used to count lines.
|
||||
@ -5,7 +6,7 @@
|
||||
export const lineBreak = /\r\n?|\n|\u2028|\u2029/;
|
||||
export const lineBreakG = new RegExp(lineBreak.source, "g");
|
||||
|
||||
export function isNewLine(code) {
|
||||
export function isNewLine(code: number): boolean {
|
||||
return code === 10 || code === 13 || code === 0x2028 || code === 0x2029;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user