Refactor shouldPrintComma logic for angular (#7507)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-02-14 13:21:46 +03:00
1 parent b26d66feb3
commit 4bac066146
4 files changed
+2 -187

No files matched your search

+1 -1
View File
@@ -1021,7 +1021,7 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
if (options.parser === "angular") {
const ngTextToDoc = (code, opts) =>
// angular does not allow trailing comma
textToDoc(code, { trailingComma: "none", ...opts });
textToDoc(code, { ...opts, trailingComma: "none" });
/**
* *directive="angularDirective"
-10
View File
@@ -120,16 +120,6 @@ const {
let uid = 0;
function shouldPrintComma(options, level) {
// angular does not allow trailing comma
if (
options.parser === "__ng_interpolation" ||
options.parser === "__ng_action" ||
options.parser === "__ng_binding" ||
options.parser === "__ng_directive"
) {
return false;
}
level = level || "es5";
switch (options.trailingComma) {
@@ -21,47 +21,6 @@ trailingComma: "none"
================================================================================
`;
exports[`logical-expression.ng 2`] = `
====================================options=====================================
parsers: ["__ng_interpolation"]
printWidth: 80
| printWidth
=====================================input======================================
[
advancedSearchService.patientInformationFieldsRow2 && advancedSearchService.patientInformationFieldsRow2.indexOf(advancedSearchService.formElementData.customFieldList[i].customFieldType) !== -1
]
=====================================output=====================================
[
advancedSearchService.patientInformationFieldsRow2 &&
advancedSearchService.patientInformationFieldsRow2.indexOf(
advancedSearchService.formElementData.customFieldList[i].customFieldType
) !== -1
]
================================================================================
`;
exports[`logical-expression.ng 3`] = `
====================================options=====================================
parsers: ["__ng_interpolation"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
[
advancedSearchService.patientInformationFieldsRow2 && advancedSearchService.patientInformationFieldsRow2.indexOf(advancedSearchService.formElementData.customFieldList[i].customFieldType) !== -1
]
=====================================output=====================================
[
advancedSearchService.patientInformationFieldsRow2 &&
advancedSearchService.patientInformationFieldsRow2.indexOf(
advancedSearchService.formElementData.customFieldList[i].customFieldType
) !== -1
]
================================================================================
`;
exports[`pipe-expression.ng 1`] = `
====================================options=====================================
parsers: ["__ng_interpolation"]
@@ -128,136 +87,3 @@ trailingComma: "none"
]
================================================================================
`;
exports[`pipe-expression.ng 2`] = `
====================================options=====================================
parsers: ["__ng_interpolation"]
printWidth: 80
| printWidth
=====================================input======================================
[
a ? (b | c : d) : (e | f : g),
a | b | c | d,
((a | b) | c) | d,
a | b:(c | d),
{ a: b | c },
(a + b) | c,
(a | b) + c,
fn(a | b),
a?.b(c | d),
a[b | c],
($students | async).items,
($students | async)(),
myData | myPipe:'arg1':'arg2':'arg3',
value
| pipeA: {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
} : {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
}
| aaa,
(hideLinqPanel ? "ReportSelection.HideShowLabel_Show.String" : "ReportSelection.HideShowLabel_Hide.String") | localize:(localizationSection)
]
=====================================output=====================================
[
a ? (b | c: d) : (e | f: g),
a | b | c | d,
a | b | c | d,
a | b: (c | d),
{ a: b | c },
a + b | c,
(a | b) + c,
fn(a | b),
a?.b(c | d),
a[b | c],
($students | async).items,
($students | async)(),
myData | myPipe: "arg1":"arg2":"arg3",
value
| pipeA
: {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
}
: {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
}
| aaa,
(hideLinqPanel
? "ReportSelection.HideShowLabel_Show.String"
: "ReportSelection.HideShowLabel_Hide.String"
) | localize: localizationSection
]
================================================================================
`;
exports[`pipe-expression.ng 3`] = `
====================================options=====================================
parsers: ["__ng_interpolation"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
[
a ? (b | c : d) : (e | f : g),
a | b | c | d,
((a | b) | c) | d,
a | b:(c | d),
{ a: b | c },
(a + b) | c,
(a | b) + c,
fn(a | b),
a?.b(c | d),
a[b | c],
($students | async).items,
($students | async)(),
myData | myPipe:'arg1':'arg2':'arg3',
value
| pipeA: {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
} : {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
}
| aaa,
(hideLinqPanel ? "ReportSelection.HideShowLabel_Show.String" : "ReportSelection.HideShowLabel_Hide.String") | localize:(localizationSection)
]
=====================================output=====================================
[
a ? (b | c: d) : (e | f: g),
a | b | c | d,
a | b | c | d,
a | b: (c | d),
{ a: b | c },
a + b | c,
(a | b) + c,
fn(a | b),
a?.b(c | d),
a[b | c],
($students | async).items,
($students | async)(),
myData | myPipe: "arg1":"arg2":"arg3",
value
| pipeA
: {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
}
: {
keyA: reallySuperLongValue,
keyB: shortValue | pipeB | pipeC: valueToPipeC
}
| aaa,
(hideLinqPanel
? "ReportSelection.HideShowLabel_Show.String"
: "ReportSelection.HideShowLabel_Hide.String"
) | localize: localizationSection
]
================================================================================
`;
+1 -2
View File
@@ -1,3 +1,2 @@
// We always pass {trailingComma: "none"} when printing
run_spec(__dirname, ["__ng_interpolation"], { trailingComma: "none" });
run_spec(__dirname, ["__ng_interpolation"]);
run_spec(__dirname, ["__ng_interpolation"], { trailingComma: "all" });