Move format definition into Printer.

This commit is contained in:
Logan Smyth 2016-07-14 23:42:11 -07:00
parent 0d5cbe6102
commit a3c99278ba
2 changed files with 20 additions and 18 deletions

View File

@ -2,6 +2,7 @@ import detectIndent from "detect-indent";
import SourceMap from "./source-map";
import * as messages from "babel-messages";
import Printer from "./printer";
import type {Format} from "./printer";
/**
* Babel's code generator, turns an ast into code, maintaining sourcemaps,
@ -20,23 +21,6 @@ class Generator extends Printer {
this.ast = ast;
}
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;
}
};
ast: Object;
/**
@ -60,7 +44,7 @@ class Generator extends Printer {
* - If `opts.compact = "auto"` and the code is over 100KB, `compact` will be set to `true`.
*/
function normalizeOptions(code, opts, tokens) {
function normalizeOptions(code, opts, tokens): Format {
let style = " ";
if (code && typeof code === "string") {
let indent = detectIndent(code).indent;

View File

@ -6,6 +6,23 @@ import * as n from "./node";
import Whitespace from "./whitespace";
import * as t from "babel-types";
export type 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;
}
};
export default class Printer {
constructor(format, map, tokens) {
this.format = format || {};
@ -13,6 +30,7 @@ export default class Printer {
this._whitespace = tokens.length > 0 ? new Whitespace(tokens) : null;
}
format: Format;
insideAux: boolean = false;
inForStatementInitCounter: number = 0;