refactor(massageAst): move target props to corresponding plugins (#4430)

master
Ika 2018-05-08 10:48:29 +08:00 committed by GitHub
parent 218abba141
commit df3eb0cf68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 26 deletions

View File

@ -3,6 +3,12 @@
const htmlTagNames = require("html-tag-names");
function clean(ast, newObj) {
["raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(
name => {
delete newObj[name];
}
);
if (
ast.type === "media-query" ||
ast.type === "media-query-list" ||

View File

@ -1,6 +1,17 @@
"use strict";
function clean(ast, newObj, parent) {
[
"leadingComments",
"trailingComments",
"extra",
"start",
"end",
"flags"
].forEach(name => {
delete newObj[name];
});
// We remove extra `;` and add them when needed
if (ast.type === "EmptyStatement") {
return null;

View File

@ -796,6 +796,8 @@ function clamp(value, min, max) {
}
function clean(ast, newObj, parent) {
delete newObj.position;
// for codeblock
if (ast.type === "code") {
delete newObj.value;

View File

@ -31,6 +31,8 @@ function genericPrint(path, options, print) {
}
const clean = (ast, newObj) => {
delete newObj.start;
delete newObj.end;
delete newObj.contentStart;
delete newObj.contentEnd;
};

View File

@ -16,32 +16,6 @@ function massageAST(ast, options, parent) {
}
}
[
"loc",
"range",
"raw",
"comments",
"leadingComments",
"trailingComments",
"extra",
"start",
"end",
"tokens",
"flags",
"raws",
"sourceIndex",
"id",
"source",
"before",
"after",
"trailingComma",
"parent",
"prev",
"position"
].forEach(name => {
delete newObj[name];
});
if (options.printer.massageAstNode) {
const result = options.printer.massageAstNode(ast, newObj, parent);
if (result === null) {