Skip to content

Commit

Permalink
Revert "Remove flow"
Browse files Browse the repository at this point in the history
This reverts commit 2827ff6.
  • Loading branch information
amasad committed Mar 3, 2016
1 parent b88182c commit 3667527
Show file tree
Hide file tree
Showing 75 changed files with 542 additions and 278 deletions.
2 changes: 1 addition & 1 deletion packages/babel-cli/src/babel-doctor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ while (nodeModulesDirectories.length) {
let loc = nodeModulesDirectories.shift();
if (!fs.existsSync(loc)) continue;

let packagesNames = fs.readdirSync(loc);
let packagesNames: Array<string> = fs.readdirSync(loc);

for (let packageName of packagesNames) {
if (packageName[0] === ".") continue;
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-core/src/api/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import { transform } from "./node";
export * from "./node";

export function run(code, opts = {}) {
export function run(code: string, opts: Object = {}): any {
return new Function(transform(code, opts).code)();
}

export function load(url, callback, opts = {}, hold) {
export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) {
opts.filename = opts.filename || url;

let xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
Expand All @@ -32,7 +32,7 @@ export function load(url, callback, opts = {}, hold) {
}

function runScripts() {
let scripts = [];
let scripts: Array<Array<any> | Object> = [];
let types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
let index = 0;

Expand All @@ -53,7 +53,7 @@ function runScripts() {
* Load, transform, and execute all scripts.
*/

function run(script, i) {
function run(script: Object, i: number) {
let opts = {};

if (script.src) {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/api/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export let transformFromAst = pipeline.transformFromAst.bind(pipeline);

//

export function transformFile(filename, opts, callback) {
export function transformFile(filename: string, opts?: Object, callback: Function) {
if (isFunction(opts)) {
callback = opts;
opts = {};
Expand All @@ -69,7 +69,7 @@ export function transformFile(filename, opts, callback) {
});
}

export function transformFileSync(filename, opts = {}) {
export function transformFileSync(filename: string, opts?: Object = {}): string {
opts.filename = filename;
return transform(fs.readFileSync(filename, "utf8"), opts);
}
2 changes: 1 addition & 1 deletion packages/babel-core/src/helpers/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "path";

let relativeModules = {};

export default function (loc, relative = process.cwd()) {
export default function (loc: string, relative: string = process.cwd()): ?string {
// we're in the browser, probably
if (typeof Module === "object") return null;

Expand Down
4 changes: 3 additions & 1 deletion packages/babel-core/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ export default class Store extends Map {
this.dynamicData = {};
}

dynamicData: Object;

setDynamic(key, fn) {
this.dynamicData[key] = fn;
}

get(key) {
get(key: string): any {
if (this.has(key)) {
return super.get(key);
} else {
Expand Down
5 changes: 4 additions & 1 deletion packages/babel-core/src/tools/build-external-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ function buildHelpers(body, namespace, whitelist) {
));
});
}
export default function (whitelist, outputType = "global") {
export default function (
whitelist?: Array<string>,
outputType: "global" | "umd" | "var" = "global",
) {
let namespace = t.identifier("babelHelpers");

let builder = function (body) {
Expand Down
20 changes: 12 additions & 8 deletions packages/babel-core/src/transformation/file/logger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type File from "./index";
import buildDebug from "debug/node";

let verboseDebug = buildDebug("babel:verbose");
Expand All @@ -6,26 +7,29 @@ let generalDebug = buildDebug("babel");
let seenDeprecatedMessages = [];

export default class Logger {
constructor(file, filename) {
constructor(file: File, filename: string) {
this.filename = filename;
this.file = file;
}

_buildMessage(msg) {
filename: string;
file: File;

_buildMessage(msg: string): string {
let parts = `[BABEL] ${this.filename}`;
if (msg) parts += `: ${msg}`;
return parts;
}

warn(msg) {
warn(msg: string) {
console.warn(this._buildMessage(msg));
}

error(msg, Constructor = Error) {
error(msg: string, Constructor: typeof Error = Error): Error {
throw new Constructor(this._buildMessage(msg));
}

deprecate(msg) {
deprecate(msg: string) {
if (this.file.opts && this.file.opts.suppressDeprecationMessages) return;

msg = this._buildMessage(msg);
Expand All @@ -39,15 +43,15 @@ export default class Logger {
console.error(msg);
}

verbose(msg) {
verbose(msg: string) {
if (verboseDebug.enabled) verboseDebug(this._buildMessage(msg));
}

debug(msg) {
debug(msg: string) {
if (generalDebug.enabled) generalDebug(this._buildMessage(msg));
}

deopt(node, msg) {
deopt(node: Object, msg: string) {
this.debug(msg);
}
}
4 changes: 2 additions & 2 deletions packages/babel-core/src/transformation/file/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export let ImportDeclaration = {
specifiers
});

for (let specifier of path.get("specifiers")) {
for (let specifier of (path.get("specifiers"): Array<Object>)) {
let local = specifier.node.local.name;

if (specifier.isImportDefaultSpecifier()) {
Expand Down Expand Up @@ -77,7 +77,7 @@ export function ExportDeclaration(path, file) {
}

if (path.isExportNamedDeclaration() && node.specifiers) {
for (let specifier of node.specifiers) {
for (let specifier of (node.specifiers: Array<Object>)) {
let exported = specifier.exported.name;
exports.exported.push(exported);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint max-len: 0 */

import * as context from "../../../api/node";
import type Logger from "../logger";
import Plugin from "../../plugin";
import * as messages from "babel-messages";
import { normaliseOptions } from "./index";
Expand Down Expand Up @@ -32,19 +33,49 @@ function exists(filename) {
}
}

type PluginObject = {
pre?: Function;
post?: Function;
manipulateOptions?: Function;

visitor: ?{
[key: string]: Function | {
enter?: Function | Array<Function>;
exit?: Function | Array<Function>;
}
};
};

type MergeOptions = {
options?: Object,
extending?: Object,
alias: string,
loc?: string,
dirname?: string
};

export default class OptionManager {
constructor(log) {
constructor(log?: Logger) {
this.resolvedConfigs = [];
this.options = OptionManager.createBareOptions();
this.log = log;
}

resolvedConfigs: Array<string>;
options: Object;
log: ?Logger;

static memoisedPlugins: Array<{
container: Function;
plugin: Plugin;
}>;

static memoisePluginContainer(fn, loc, i, alias) {
for (let cache of OptionManager.memoisedPlugins) {
for (let cache of (OptionManager.memoisedPlugins: Array<Object>)) {
if (cache.container === fn) return cache.plugin;
}

let obj;
let obj: ?PluginObject;

if (typeof fn === "function") {
obj = fn(context);
Expand Down Expand Up @@ -125,7 +156,7 @@ export default class OptionManager {
});
}

addConfig(loc, key, json = json5) {
addConfig(loc: string, key?: string, json = json5): boolean {
if (this.resolvedConfigs.indexOf(loc) >= 0) {
return false;
}
Expand Down Expand Up @@ -167,7 +198,7 @@ export default class OptionManager {
alias,
loc,
dirname
}) {
}: MergeOptions) {
alias = alias || "foreign";
if (!rawOpts) return;

Expand Down Expand Up @@ -272,7 +303,7 @@ export default class OptionManager {
* Merges all presets into the main options in case we are not in the
* "pass per preset" mode. Otherwise, options are calculated per preset.
*/
mergePresets(presets, dirname) {
mergePresets(presets: Array<string | Object>, dirname: string) {
this.resolvePresets(presets, dirname, (presetOpts, presetLoc) => {
this.mergeOptions({
options: presetOpts,
Expand All @@ -287,7 +318,7 @@ export default class OptionManager {
* Resolves presets options which can be either direct object data,
* or a module name to require.
*/
resolvePresets(presets, dirname, onResolve) {
resolvePresets(presets: Array<string | Object>, dirname: string, onResolve?) {
return presets.map((val) => {
if (typeof val === "string") {
let presetLoc = resolve(`babel-preset-${val}`, dirname) || resolve(val, dirname);
Expand Down Expand Up @@ -376,7 +407,7 @@ export default class OptionManager {
}
}

init(opts = {}) {
init(opts: Object = {}): Object {
let filename = opts.filename;

// resolve all .babelrc files
Expand Down
8 changes: 7 additions & 1 deletion packages/babel-core/src/transformation/plugin-pass.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import type Plugin from "./plugin";
import Store from "../store";
import traverse from "babel-traverse";
import File from "./file";

export default class PluginPass extends Store {
constructor(file, plugin, options = {}) {
constructor(file: File, plugin: Plugin, options: Object = {}) {
super();
this.plugin = plugin;
this.file = file;
this.opts = options;
}

plugin: Plugin;
file: File;
opts: Object;

transform() {
let file = this.file;
file.log.debug(`Start transformer ${this.key}`);
Expand Down
29 changes: 28 additions & 1 deletion packages/babel-generator/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ export class CodeGenerator extends Printer {
this.map = new SourceMap(position, opts, code);
}

format: {
shouldPrintComment: (comment: string) => boolean;
retainLines: boolean;
comments: boolean;
auxiliaryCommentBefore: string;
auxiliaryCommentAfter: string;
compact: boolean | "auto";
minified: boolean;
quotes: "single" | "double";
concise: boolean;
indent: {
adjustMultilineComment: boolean;
style: string;
base: number;
}
};

auxiliaryCommentBefore: string;
auxiliaryCommentAfter: string;
whitespace: Whitespace;
position: Position;
map: SourceMap;
comments: Array<Object>;
tokens: Array<Object>;
opts: Object;
ast: Object;

/**
* Normalize generator options, setting defaults.
*
Expand Down Expand Up @@ -134,7 +161,7 @@ export class CodeGenerator extends Printer {
}
}

export default function (ast, opts, code) {
export default function (ast: Object, opts: Object, code: string): Object {
let gen = new CodeGenerator(ast, opts, code);
return gen.generate();
}
4 changes: 2 additions & 2 deletions packages/babel-generator/src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class Printer extends Buffer {
printMethod.call(this, node, parent);
}

printJoin(nodes, parent, opts = {}) {
printJoin(nodes: ?Array, parent: Object, opts = {}) {
if (!nodes || !nodes.length) return;

let len = nodes.length;
Expand Down Expand Up @@ -310,7 +310,7 @@ export default class Printer extends Buffer {
this.newline(this.whitespace.getNewlinesAfter(comment));
}

printComments(comments) {
printComments(comments?: Array<Object>) {
if (!comments || !comments.length) return;

for (let comment of comments) {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-generator/src/whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export default class Whitespace {
* Find a token between start and end.
*/

_findToken(test, start, end) {
_findToken(test: Function, start: number, end: number): number {
if (start >= end) return -1;
const middle = (start + end) >>> 1;
const match = test(this.tokens[middle]);
const match: number = test(this.tokens[middle]);
if (match < 0) {
return this._findToken(test, middle + 1, end);
} else if (match > 0) {
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-helper-bindify-decorators/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NodePath } from "babel-traverse";
import * as t from "babel-types";

export default function bindifyDecorators(decorators) {
export default function bindifyDecorators(decorators: Array<NodePath>): Array<NodePath> {
for (let decoratorPath of decorators) {
let decorator = decoratorPath.node;
let expression = decorator.expression;
Expand Down

0 comments on commit 3667527

Please sign in to comment.