Run AST_COMPARE test for verifyParsers too (#8966)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-08-19 21:26:33 +08:00
1 parent 36c35be210
commit d1a9d7420b
2 files changed
+50 -12

No files matched your search

+30 -2
View File
@@ -24,7 +24,12 @@ function clean(ast, newObj, parent) {
}
if (ast.type === "BigIntLiteral") {
newObj.value = newObj.value.toLowerCase();
if (newObj.value) {
newObj.value = newObj.value.toLowerCase();
}
if (newObj.bigint) {
newObj.bigint = newObj.bigint.toLowerCase();
}
}
if (ast.type === "DecimalLiteral") {
@@ -42,7 +47,8 @@ function clean(ast, newObj, parent) {
}
if (
ast.type === "JSXExpressionContainer" &&
ast.expression.type === "Literal" &&
(ast.expression.type === "Literal" ||
ast.expression.type === "StringLiteral") &&
ast.expression.value === " "
) {
return null;
@@ -88,6 +94,8 @@ function clean(ast, newObj, parent) {
ast.type === "ObjectProperty" ||
ast.type === "MethodDefinition" ||
ast.type === "ClassProperty" ||
ast.type === "ClassMethod" ||
ast.type === "TSDeclareMethod" ||
ast.type === "TSPropertySignature" ||
ast.type === "ObjectTypeProperty") &&
typeof ast.key === "object" &&
@@ -138,6 +146,16 @@ function clean(ast, newObj, parent) {
newObj.value.expression.quasis.forEach((q) => delete q.value);
}
// We change quotes
if (
ast.type === "JSXAttribute" &&
ast.value &&
ast.value.type === "Literal" &&
/["']|"|'/.test(ast.value.value)
) {
newObj.value.value = newObj.value.value.replace(/["']|"|'/g, '"');
}
// Angular Components: Inline HTML template and Inline CSS styles
const expression = ast.expression || ast.callee;
if (
@@ -205,6 +223,16 @@ function clean(ast, newObj, parent) {
) {
newObj.quasis.forEach((quasi) => delete quasi.value);
}
// TODO: check parser
// `flow` and `typescript` don't have `leadingComments`
if (!ast.leadingComments) {
newObj.quasis.forEach((quasi) => {
if (quasi.value) {
delete quasi.value.cooked;
}
});
}
}
if (ast.type === "InterpreterDirective") {
+20 -10
View File
@@ -247,20 +247,30 @@ global.run_spec = (fixtures, parsers, options) => {
for (const parser of verifyParsers) {
const verifyOptions = { ...firstFormat.options, parser };
const verifyFormat = () => format(firstFormat.input, verifyOptions);
const runVerifyFormat = () => format(firstFormat.input, verifyOptions);
test(`verify (${parser})`, () => {
if (shouldThrowOnVerify(name, verifyOptions)) {
expect(verifyFormat).toThrow(
if (shouldThrowOnVerify(name, verifyOptions)) {
test(`verify (${parser})`, () => {
expect(runVerifyFormat).toThrow(
TEST_STANDALONE ? undefined : SyntaxError
);
return;
}
});
} else {
const verifyFormat = runVerifyFormat();
test(`verify (${parser})`, () => {
expect(verifyFormat.eolVisualizedOutput).toEqual(
firstFormat.eolVisualizedOutput
);
});
const { eolVisualizedOutput: verifyOutput } = verifyFormat();
const { eolVisualizedOutput: firstOutput } = firstFormat;
expect(verifyOutput).toEqual(firstOutput);
});
if (AST_COMPARE && verifyFormat.changed && code.trim()) {
test(`verify AST (${parser})`, () => {
const originalAst = parse(verifyFormat.input, verifyOptions);
const formattedAst = parse(verifyFormat.output, verifyOptions);
expect(originalAst).toEqual(formattedAst);
});
}
}
}
const isUnstableTest = isUnstable(filename, formatOptions);