!nameHasComments || _n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
// string literal with newlines
var _shouldBreak = _n.attributes && _n.attributes.some(function (attr) {
return attr.value && isStringLiteral(attr.value) && attr.value.value.includes("\n");
});
return group$1(concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), concat$4([indent$2(concat$4(path$$1.map(function (attr) {
return concat$4([line$3, print(attr)]);
}, "attributes"))), _n.selfClosing ? line$3 : bracketSameLine ? ">" : softline$1]), _n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
shouldBreak: _shouldBreak
});
}
case "JSXClosingElement":
return concat$4(["", path$$1.call(print, "name"), ">"]);
case "JSXOpeningFragment":
case "JSXClosingFragment":
{
var hasComment = n.comments && n.comments.length;
var hasOwnLineComment = hasComment && !n.comments.every(comments$3.isBlockComment);
var isOpeningFragment = n.type === "JSXOpeningFragment";
return concat$4([isOpeningFragment ? "<" : "", indent$2(concat$4([hasOwnLineComment ? hardline$3 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path$$1, options, true)])), hasOwnLineComment ? hardline$3 : "", ">"]);
}
case "JSXText":
/* istanbul ignore next */
throw new Error("JSXTest should be handled by JSXElement");
case "JSXEmptyExpression":
{
var requiresHardline = n.comments && !n.comments.every(comments$3.isBlockComment);
return concat$4([comments.printDanglingComments(path$$1, options,
/* sameIndent */
!requiresHardline), requiresHardline ? hardline$3 : ""]);
}
case "ClassBody":
if (!n.comments && n.body.length === 0) {
return "{}";
}
return concat$4(["{", n.body.length > 0 ? indent$2(concat$4([hardline$3, path$$1.call(function (bodyPath) {
return printStatementSequence(bodyPath, options, print);
}, "body")])) : comments.printDanglingComments(path$$1, options), hardline$3, "}"]);
case "ClassProperty":
case "TSAbstractClassProperty":
case "ClassPrivateProperty":
{
if (n.decorators && n.decorators.length !== 0) {
parts.push(printDecorators(path$$1, options, print));
}
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.static) {
parts.push("static ");
}
if (n.type === "TSAbstractClassProperty") {
parts.push("abstract ");
}
if (n.readonly) {
parts.push("readonly ");
}
var variance = getFlowVariance(n);
if (variance) {
parts.push(variance);
}
if (n.computed) {
parts.push("[", path$$1.call(print, "key"), "]");
} else {
parts.push(printPropertyKey(path$$1, options, print));
}
parts.push(printOptionalToken(path$$1));
parts.push(printTypeAnnotation(path$$1, options, print));
if (n.value) {
parts.push(" =", printAssignmentRight(n.key, n.value, path$$1.call(print, "value"), options));
}
parts.push(semi);
return group$1(concat$4(parts));
}
case "ClassDeclaration":
case "ClassExpression":
case "TSAbstractClassDeclaration":
if (isNodeStartingWithDeclare(n, options)) {
parts.push("declare ");
}
parts.push(concat$4(printClass(path$$1, options, print)));
return concat$4(parts);
case "TSInterfaceHeritage":
parts.push(path$$1.call(print, "expression"));
if (n.typeParameters) {
parts.push(path$$1.call(print, "typeParameters"));
}
return concat$4(parts);
case "TemplateElement":
return join$2(literalline$1, n.value.raw.split(/\r?\n/g));
case "TemplateLiteral":
{
var expressions = path$$1.map(print, "expressions");
var _parentNode = path$$1.getParentNode();
/**
* describe.each`table`(name, fn)
* describe.only.each`table`(name, fn)
* describe.skip.each`table`(name, fn)
* test.each`table`(name, fn)
* test.only.each`table`(name, fn)
* test.skip.each`table`(name, fn)
*
* Ref: https://github.com/facebook/jest/pull/6102
*/
var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
if (_parentNode.type === "TaggedTemplateExpression" && _parentNode.quasi === n && _parentNode.tag.type === "MemberExpression" && _parentNode.tag.property.type === "Identifier" && _parentNode.tag.property.name === "each" && (_parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.name) || _parentNode.tag.object.type === "MemberExpression" && _parentNode.tag.object.property.type === "Identifier" && (_parentNode.tag.object.property.name === "only" || _parentNode.tag.object.property.name === "skip") && _parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.object.name))) {
/**
* a | b | expected
* ${1} | ${1} | ${2}
* ${1} | ${2} | ${3}
* ${2} | ${1} | ${3}
*/
var headerNames = n.quasis[0].value.raw.trim().split(/\s*\|\s*/);
if (headerNames.length > 1 || headerNames.some(function (headerName) {
return headerName.length !== 0;
})) {
var stringifiedExpressions = expressions.map(function (doc$$2) {
return "${" + printDocToString$2(doc$$2, Object.assign({}, options, {
printWidth: Infinity,
endOfLine: "lf"
})).formatted + "}";
});
var tableBody = [{
hasLineBreak: false,
cells: []
}];
for (var _i = 1; _i < n.quasis.length; _i++) {
var row = tableBody[tableBody.length - 1];
var correspondingExpression = stringifiedExpressions[_i - 1];
row.cells.push(correspondingExpression);
if (correspondingExpression.indexOf("\n") !== -1) {
row.hasLineBreak = true;
}
if (n.quasis[_i].value.raw.indexOf("\n") !== -1) {
tableBody.push({
hasLineBreak: false,
cells: []
});
}
}
var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
return Math.max(maxColumnCount, row.cells.length);
}, headerNames.length);
var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
return 0;
});
var table = [{
cells: headerNames
}].concat(tableBody.filter(function (row) {
return row.cells.length !== 0;
}));
table.filter(function (row) {
return !row.hasLineBreak;
}).forEach(function (row) {
row.cells.forEach(function (cell, index) {
maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$2(cell));
});
});
parts.push("`", indent$2(concat$4([hardline$3, join$2(hardline$3, table.map(function (row) {
return join$2(" | ", row.cells.map(function (cell, index) {
return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$2(cell));
}));
}))])), hardline$3, "`");
return concat$4(parts);
}
}
parts.push("`");
path$$1.each(function (childPath) {
var i = childPath.getName();
parts.push(print(childPath));
if (i < expressions.length) {
// For a template literal of the following form:
// `someQuery {
// ${call({
// a,
// b,
// })}
// }`
// the expression is on its own line (there is a \n in the previous
// quasi literal), therefore we want to indent the JavaScript
// expression inside at the beginning of ${ instead of the beginning
// of the `.
var tabWidth = options.tabWidth;
var quasi = childPath.getValue();
var indentSize = getIndentSize$1(quasi.value.raw, tabWidth);
var _printed2 = expressions[i];
if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression") {
_printed2 = concat$4([indent$2(concat$4([softline$1, _printed2])), softline$1]);
}
var aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$1(-Infinity, _printed2) : addAlignmentToDoc$2(_printed2, indentSize, tabWidth);
parts.push(group$1(concat$4(["${", aligned, lineSuffixBoundary$1, "}"])));
}
}, "quasis");
parts.push("`");
return concat$4(parts);
}
// These types are unprintable because they serve as abstract
// supertypes for other (printable) types.
case "TaggedTemplateExpression":
return concat$4([path$$1.call(print, "tag"), path$$1.call(print, "typeParameters"), path$$1.call(print, "quasi")]);
case "Node":
case "Printable":
case "SourceLocation":
case "Position":
case "Statement":
case "Function":
case "Pattern":
case "Expression":
case "Declaration":
case "Specifier":
case "NamedSpecifier":
case "Comment":
case "MemberTypeAnnotation": // Flow
case "Type":
/* istanbul ignore next */
throw new Error("unprintable type: " + JSON.stringify(n.type));
// Type Annotations for Facebook Flow, typically stripped out or
// transformed away before printing.
case "TypeAnnotation":
case "TSTypeAnnotation":
if (n.typeAnnotation) {
return path$$1.call(print, "typeAnnotation");
}
/* istanbul ignore next */
return "";
case "TSTupleType":
case "TupleTypeAnnotation":
{
var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
return group$1(concat$4(["[", indent$2(concat$4([softline$1, printArrayItems(path$$1, options, typesField, print)])), // TypeScript doesn't support trailing commas in tuple types
n.type === "TSTupleType" ? "" : ifBreak$1(shouldPrintComma(options) ? "," : ""), comments.printDanglingComments(path$$1, options,
/* sameIndent */
true), softline$1, "]"]));
}
case "ExistsTypeAnnotation":
return "*";
case "EmptyTypeAnnotation":
return "empty";
case "AnyTypeAnnotation":
return "any";
case "MixedTypeAnnotation":
return "mixed";
case "ArrayTypeAnnotation":
return concat$4([path$$1.call(print, "elementType"), "[]"]);
case "BooleanTypeAnnotation":
return "boolean";
case "BooleanLiteralTypeAnnotation":
return "" + n.value;
case "DeclareClass":
return printFlowDeclaration(path$$1, printClass(path$$1, options, print));
case "TSDeclareFunction":
// For TypeScript the TSDeclareFunction node shares the AST
// structure with FunctionDeclaration
return concat$4([n.declare ? "declare " : "", printFunctionDeclaration(path$$1, print, options), semi]);
case "DeclareFunction":
return printFlowDeclaration(path$$1, ["function ", path$$1.call(print, "id"), n.predicate ? " " : "", path$$1.call(print, "predicate"), semi]);
case "DeclareModule":
return printFlowDeclaration(path$$1, ["module ", path$$1.call(print, "id"), " ", path$$1.call(print, "body")]);
case "DeclareModuleExports":
return printFlowDeclaration(path$$1, ["module.exports", ": ", path$$1.call(print, "typeAnnotation"), semi]);
case "DeclareVariable":
return printFlowDeclaration(path$$1, ["var ", path$$1.call(print, "id"), semi]);
case "DeclareExportAllDeclaration":
return concat$4(["declare export * from ", path$$1.call(print, "source")]);
case "DeclareExportDeclaration":
return concat$4(["declare ", printExportDeclaration(path$$1, options, print)]);
case "DeclareOpaqueType":
case "OpaqueType":
{
parts.push("opaque type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
if (n.supertype) {
parts.push(": ", path$$1.call(print, "supertype"));
}
if (n.impltype) {
parts.push(" = ", path$$1.call(print, "impltype"));
}
parts.push(semi);
if (n.type === "DeclareOpaqueType") {
return printFlowDeclaration(path$$1, parts);
}
return concat$4(parts);
}
case "FunctionTypeAnnotation":
case "TSFunctionType":
{
// FunctionTypeAnnotation is ambiguous:
// declare function foo(a: B): void; OR
// var A: (a: B) => void;
var _parent7 = path$$1.getParentNode(0);
var _parentParent2 = path$$1.getParentNode(1);
var _parentParentParent = path$$1.getParentNode(2);
var isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || !((_parent7.type === "ObjectTypeProperty" || _parent7.type === "ObjectTypeInternalSlot") && !getFlowVariance(_parent7) && !_parent7.optional && options.locStart(_parent7) === options.locStart(n) || _parent7.type === "ObjectTypeCallProperty" || _parentParentParent && _parentParentParent.type === "DeclareFunction");
var needsColon = isArrowFunctionTypeAnnotation && (_parent7.type === "TypeAnnotation" || _parent7.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
// printing ":" as part of the expression and it would put parenthesis
// around :(
var needsParens = needsColon && isArrowFunctionTypeAnnotation && (_parent7.type === "TypeAnnotation" || _parent7.type === "TSTypeAnnotation") && _parentParent2.type === "ArrowFunctionExpression";
if (isObjectTypePropertyAFunction(_parent7, options)) {
isArrowFunctionTypeAnnotation = true;
needsColon = true;
}
if (needsParens) {
parts.push("(");
}
parts.push(printFunctionParams(path$$1, print, options,
/* expandArg */
false,
/* printTypeParams */
true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
// needs to be added separately.
if (n.returnType || n.predicate || n.typeAnnotation) {
parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path$$1.call(print, "returnType"), path$$1.call(print, "predicate"), path$$1.call(print, "typeAnnotation"));
}
if (needsParens) {
parts.push(")");
}
return group$1(concat$4(parts));
}
case "TSRestType":
return concat$4(["...", path$$1.call(print, "typeAnnotation")]);
case "TSOptionalType":
return concat$4([path$$1.call(print, "typeAnnotation"), "?"]);
case "FunctionTypeParam":
return concat$4([path$$1.call(print, "name"), printOptionalToken(path$$1), n.name ? ": " : "", path$$1.call(print, "typeAnnotation")]);
case "GenericTypeAnnotation":
return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
case "DeclareInterface":
case "InterfaceDeclaration":
case "InterfaceTypeAnnotation":
{
if (n.type === "DeclareInterface" || isNodeStartingWithDeclare(n, options)) {
parts.push("declare ");
}
parts.push("interface");
if (n.type === "DeclareInterface" || n.type === "InterfaceDeclaration") {
parts.push(" ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
}
if (n["extends"].length > 0) {
parts.push(group$1(indent$2(concat$4([line$3, "extends ", (n.extends.length === 1 ? identity$1 : indent$2)(join$2(concat$4([",", line$3]), path$$1.map(print, "extends")))]))));
}
parts.push(" ", path$$1.call(print, "body"));
return group$1(concat$4(parts));
}
case "ClassImplements":
case "InterfaceExtends":
return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
case "TSClassImplements":
return concat$4([path$$1.call(print, "expression"), path$$1.call(print, "typeParameters")]);
case "TSIntersectionType":
case "IntersectionTypeAnnotation":
{
var types = path$$1.map(print, "types");
var result = [];
var wasIndented = false;
for (var _i2 = 0; _i2 < types.length; ++_i2) {
if (_i2 === 0) {
result.push(types[_i2]);
} else if (isObjectType(n.types[_i2 - 1]) && isObjectType(n.types[_i2])) {
// If both are objects, don't indent
result.push(concat$4([" & ", wasIndented ? indent$2(types[_i2]) : types[_i2]]));
} else if (!isObjectType(n.types[_i2 - 1]) && !isObjectType(n.types[_i2])) {
// If no object is involved, go to the next line if it breaks
result.push(indent$2(concat$4([" &", line$3, types[_i2]])));
} else {
// If you go from object to non-object or vis-versa, then inline it
if (_i2 > 1) {
wasIndented = true;
}
result.push(" & ", _i2 > 1 ? indent$2(types[_i2]) : types[_i2]);
}
}
return group$1(concat$4(result));
}
case "TSUnionType":
case "UnionTypeAnnotation":
{
// single-line variation
// A | B | C
// multi-line variation
// | A
// | B
// | C
var _parent8 = path$$1.getParentNode(); // If there's a leading comment, the parent is doing the indentation
var shouldIndent = _parent8.type !== "TypeParameterInstantiation" && _parent8.type !== "TSTypeParameterInstantiation" && _parent8.type !== "GenericTypeAnnotation" && _parent8.type !== "TSTypeReference" && _parent8.type !== "TSTypeAssertion" && !(_parent8.type === "FunctionTypeParam" && !_parent8.name) && !((_parent8.type === "TypeAlias" || _parent8.type === "VariableDeclarator" || _parent8.type === "TSTypeAliasDeclaration") && hasLeadingOwnLineComment(options.originalText, n, options)); // {
// a: string
// } | null | void
// should be inlined and not be printed in the multi-line variant
var shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
// | child1
// // comment
// | child2
var _printed3 = path$$1.map(function (typePath) {
var printedType = typePath.call(print);
if (!shouldHug) {
printedType = align$1(2, printedType);
}
return comments.printComments(typePath, function () {
return printedType;
}, options);
}, "types");
if (shouldHug) {
return join$2(" | ", _printed3);
}
var shouldAddStartLine = shouldIndent && !hasLeadingOwnLineComment(options.originalText, n, options);
var code = concat$4([ifBreak$1(concat$4([shouldAddStartLine ? line$3 : "", "| "])), join$2(concat$4([line$3, "| "]), _printed3)]);
var hasParens;
if (n.type === "TSUnionType") {
var greatGrandParent = path$$1.getParentNode(2);
var greatGreatGrandParent = path$$1.getParentNode(3);
hasParens = greatGrandParent && greatGrandParent.type === "TSParenthesizedType" && greatGreatGrandParent && (greatGreatGrandParent.type === "TSUnionType" || greatGreatGrandParent.type === "TSIntersectionType");
} else {
hasParens = needsParens_1(path$$1, options);
}
if (hasParens) {
return group$1(concat$4([indent$2(code), softline$1]));
}
return group$1(shouldIndent ? indent$2(code) : code);
}
case "NullableTypeAnnotation":
return concat$4(["?", path$$1.call(print, "typeAnnotation")]);
case "TSNullKeyword":
case "NullLiteralTypeAnnotation":
return "null";
case "ThisTypeAnnotation":
return "this";
case "NumberTypeAnnotation":
return "number";
case "ObjectTypeCallProperty":
if (n.static) {
parts.push("static ");
}
parts.push(path$$1.call(print, "value"));
return concat$4(parts);
case "ObjectTypeIndexer":
{
var _variance = getFlowVariance(n);
return concat$4([_variance || "", "[", path$$1.call(print, "id"), n.id ? ": " : "", path$$1.call(print, "key"), "]: ", path$$1.call(print, "value")]);
}
case "ObjectTypeProperty":
{
var _variance2 = getFlowVariance(n);
var modifier = "";
if (n.proto) {
modifier = "proto ";
} else if (n.static) {
modifier = "static ";
}
return concat$4([modifier, isGetterOrSetter(n) ? n.kind + " " : "", _variance2 || "", printPropertyKey(path$$1, options, print), printOptionalToken(path$$1), isFunctionNotation(n, options) ? "" : ": ", path$$1.call(print, "value")]);
}
case "QualifiedTypeIdentifier":
return concat$4([path$$1.call(print, "qualification"), ".", path$$1.call(print, "id")]);
case "StringLiteralTypeAnnotation":
return nodeStr(n, options);
case "NumberLiteralTypeAnnotation":
assert.strictEqual(typeof n.value, "number");
if (n.extra != null) {
return printNumber$1(n.extra.raw);
}
return printNumber$1(n.raw);
case "StringTypeAnnotation":
return "string";
case "DeclareTypeAlias":
case "TypeAlias":
{
if (n.type === "DeclareTypeAlias" || isNodeStartingWithDeclare(n, options)) {
parts.push("declare ");
}
var _printed4 = printAssignmentRight(n.id, n.right, path$$1.call(print, "right"), options);
parts.push("type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"), " =", _printed4, semi);
return group$1(concat$4(parts));
}
case "TypeCastExpression":
{
var value = path$$1.getValue(); // Flow supports a comment syntax for specifying type annotations: https://flow.org/en/docs/types/comments/.
// Unfortunately, its parser doesn't differentiate between comment annotations and regular
// annotations when producing an AST. So to preserve parentheses around type casts that use
// the comment syntax, we need to hackily read the source itself to see if the code contains
// a type annotation comment.
//
// Note that we're able to use the normal whitespace regex here because the Flow parser has
// already deemed this AST node to be a type cast. Only the Babel parser needs the
// non-line-break whitespace regex, which is why hasFlowShorthandAnnotationComment() is
// implemented differently.
var commentSyntax = value && value.typeAnnotation && value.typeAnnotation.range && options.originalText.substring(value.typeAnnotation.range[0]).match(/^\/\*\s*:/);
return concat$4(["(", path$$1.call(print, "expression"), commentSyntax ? " /*" : "", ": ", path$$1.call(print, "typeAnnotation"), commentSyntax ? " */" : "", ")"]);
}
case "TypeParameterDeclaration":
case "TypeParameterInstantiation":
{
var _value = path$$1.getValue();
var commentStart = _value.range ? options.originalText.substring(0, _value.range[0]).lastIndexOf("/*") : -1; // As noted in the TypeCastExpression comments above, we're able to use a normal whitespace regex here
// because we know for sure that this is a type definition.
var _commentSyntax = commentStart >= 0 && options.originalText.substring(commentStart).match(/^\/\*\s*::/);
if (_commentSyntax) {
return concat$4(["/*:: ", printTypeParameters(path$$1, options, print, "params"), " */"]);
}
return printTypeParameters(path$$1, options, print, "params");
}
case "TSTypeParameterDeclaration":
case "TSTypeParameterInstantiation":
return printTypeParameters(path$$1, options, print, "params");
case "TSTypeParameter":
case "TypeParameter":
{
var _parent9 = path$$1.getParentNode();
if (_parent9.type === "TSMappedType") {
parts.push("[", path$$1.call(print, "name"));
if (n.constraint) {
parts.push(" in ", path$$1.call(print, "constraint"));
}
parts.push("]");
return concat$4(parts);
}
var _variance3 = getFlowVariance(n);
if (_variance3) {
parts.push(_variance3);
}
parts.push(path$$1.call(print, "name"));
if (n.bound) {
parts.push(": ");
parts.push(path$$1.call(print, "bound"));
}
if (n.constraint) {
parts.push(" extends ", path$$1.call(print, "constraint"));
}
if (n["default"]) {
parts.push(" = ", path$$1.call(print, "default"));
}
return concat$4(parts);
}
case "TypeofTypeAnnotation":
return concat$4(["typeof ", path$$1.call(print, "argument")]);
case "VoidTypeAnnotation":
return "void";
case "InferredPredicate":
return "%checks";
// Unhandled types below. If encountered, nodes of these types should
// be either left alone or desugared into AST types that are fully
// supported by the pretty-printer.
case "DeclaredPredicate":
return concat$4(["%checks(", path$$1.call(print, "value"), ")"]);
case "TSAbstractKeyword":
return "abstract";
case "TSAnyKeyword":
return "any";
case "TSAsyncKeyword":
return "async";
case "TSBooleanKeyword":
return "boolean";
case "TSBigIntKeyword":
return "bigint";
case "TSConstKeyword":
return "const";
case "TSDeclareKeyword":
return "declare";
case "TSExportKeyword":
return "export";
case "TSNeverKeyword":
return "never";
case "TSNumberKeyword":
return "number";
case "TSObjectKeyword":
return "object";
case "TSProtectedKeyword":
return "protected";
case "TSPrivateKeyword":
return "private";
case "TSPublicKeyword":
return "public";
case "TSReadonlyKeyword":
return "readonly";
case "TSSymbolKeyword":
return "symbol";
case "TSStaticKeyword":
return "static";
case "TSStringKeyword":
return "string";
case "TSUndefinedKeyword":
return "undefined";
case "TSUnknownKeyword":
return "unknown";
case "TSVoidKeyword":
return "void";
case "TSAsExpression":
return concat$4([path$$1.call(print, "expression"), " as ", path$$1.call(print, "typeAnnotation")]);
case "TSArrayType":
return concat$4([path$$1.call(print, "elementType"), "[]"]);
case "TSPropertySignature":
{
if (n.export) {
parts.push("export ");
}
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.static) {
parts.push("static ");
}
if (n.readonly) {
parts.push("readonly ");
}
if (n.computed) {
parts.push("[");
}
parts.push(printPropertyKey(path$$1, options, print));
if (n.computed) {
parts.push("]");
}
parts.push(printOptionalToken(path$$1));
if (n.typeAnnotation) {
parts.push(": ");
parts.push(path$$1.call(print, "typeAnnotation"));
} // This isn't valid semantically, but it's in the AST so we can print it.
if (n.initializer) {
parts.push(" = ", path$$1.call(print, "initializer"));
}
return concat$4(parts);
}
case "TSParameterProperty":
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.export) {
parts.push("export ");
}
if (n.static) {
parts.push("static ");
}
if (n.readonly) {
parts.push("readonly ");
}
parts.push(path$$1.call(print, "parameter"));
return concat$4(parts);
case "TSTypeReference":
return concat$4([path$$1.call(print, "typeName"), printTypeParameters(path$$1, options, print, "typeParameters")]);
case "TSTypeQuery":
return concat$4(["typeof ", path$$1.call(print, "exprName")]);
case "TSParenthesizedType":
{
return path$$1.call(print, "typeAnnotation");
}
case "TSIndexSignature":
{
var _parent10 = path$$1.getParentNode();
return concat$4([n.export ? "export " : "", n.accessibility ? concat$4([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", n.parameters ? concat$4(path$$1.map(print, "parameters")) : "", "]: ", path$$1.call(print, "typeAnnotation"), _parent10.type === "ClassBody" ? semi : ""]);
}
case "TSTypePredicate":
return concat$4([path$$1.call(print, "parameterName"), " is ", path$$1.call(print, "typeAnnotation")]);
case "TSNonNullExpression":
return concat$4([path$$1.call(print, "expression"), "!"]);
case "TSThisType":
return "this";
case "TSImportType":
return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path$$1.call(print, "parameter"), ")", !n.qualifier ? "" : concat$4([".", path$$1.call(print, "qualifier")]), printTypeParameters(path$$1, options, print, "typeParameters")]);
case "TSLiteralType":
return path$$1.call(print, "literal");
case "TSIndexedAccessType":
return concat$4([path$$1.call(print, "objectType"), "[", path$$1.call(print, "indexType"), "]"]);
case "TSConstructSignatureDeclaration":
case "TSCallSignatureDeclaration":
case "TSConstructorType":
{
if (n.type !== "TSCallSignatureDeclaration") {
parts.push("new ");
}
parts.push(group$1(printFunctionParams(path$$1, print, options,
/* expandArg */
false,
/* printTypeParams */
true)));
if (n.returnType) {
var isType = n.type === "TSConstructorType";
parts.push(isType ? " => " : ": ", path$$1.call(print, "returnType"));
}
return concat$4(parts);
}
case "TSTypeOperator":
return concat$4([n.operator, " ", path$$1.call(print, "typeAnnotation")]);
case "TSMappedType":
return group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, n.readonly ? concat$4([getTypeScriptMappedTypeModifier(n.readonly, "readonly"), " "]) : "", printTypeScriptModifiers(path$$1, options, print), path$$1.call(print, "typeParameter"), n.optional ? getTypeScriptMappedTypeModifier(n.optional, "?") : "", ": ", path$$1.call(print, "typeAnnotation")])), comments.printDanglingComments(path$$1, options,
/* sameIndent */
true), options.bracketSpacing ? line$3 : softline$1, "}"]));
case "TSMethodSignature":
parts.push(n.accessibility ? concat$4([n.accessibility, " "]) : "", n.export ? "export " : "", n.static ? "static " : "", n.readonly ? "readonly " : "", n.computed ? "[" : "", path$$1.call(print, "key"), n.computed ? "]" : "", printOptionalToken(path$$1), printFunctionParams(path$$1, print, options,
/* expandArg */
false,
/* printTypeParams */
true));
if (n.returnType) {
parts.push(": ", path$$1.call(print, "returnType"));
}
return group$1(concat$4(parts));
case "TSNamespaceExportDeclaration":
parts.push("export as namespace ", path$$1.call(print, "id"));
if (options.semi) {
parts.push(";");
}
return group$1(concat$4(parts));
case "TSEnumDeclaration":
if (isNodeStartingWithDeclare(n, options)) {
parts.push("declare ");
}
if (n.modifiers) {
parts.push(printTypeScriptModifiers(path$$1, options, print));
}
if (n.const) {
parts.push("const ");
}
parts.push("enum ", path$$1.call(print, "id"), " ");
if (n.members.length === 0) {
parts.push(group$1(concat$4(["{", comments.printDanglingComments(path$$1, options), softline$1, "}"])));
} else {
parts.push(group$1(concat$4(["{", indent$2(concat$4([hardline$3, printArrayItems(path$$1, options, "members", print), shouldPrintComma(options, "es5") ? "," : ""])), comments.printDanglingComments(path$$1, options,
/* sameIndent */
true), hardline$3, "}"])));
}
return concat$4(parts);
case "TSEnumMember":
parts.push(path$$1.call(print, "id"));
if (n.initializer) {
parts.push(" = ", path$$1.call(print, "initializer"));
}
return concat$4(parts);
case "TSImportEqualsDeclaration":
if (n.isExport) {
parts.push("export ");
}
parts.push("import ", path$$1.call(print, "id"), " = ", path$$1.call(print, "moduleReference"));
if (options.semi) {
parts.push(";");
}
return group$1(concat$4(parts));
case "TSExternalModuleReference":
return concat$4(["require(", path$$1.call(print, "expression"), ")"]);
case "TSModuleDeclaration":
{
var _parent11 = path$$1.getParentNode();
var isExternalModule = isLiteral(n.id);
var parentIsDeclaration = _parent11.type === "TSModuleDeclaration";
var bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
if (parentIsDeclaration) {
parts.push(".");
} else {
if (n.declare === true) {
parts.push("declare ");
}
parts.push(printTypeScriptModifiers(path$$1, options, print));
var textBetweenNodeAndItsId = options.originalText.slice(options.locStart(n), options.locStart(n.id)); // Global declaration looks like this:
// (declare)? global { ... }
var isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(textBetweenNodeAndItsId);
if (!isGlobalDeclaration) {
parts.push(isExternalModule || /(^|\s)module(\s|$)/.test(textBetweenNodeAndItsId) ? "module " : "namespace ");
}
}
parts.push(path$$1.call(print, "id"));
if (bodyIsDeclaration) {
parts.push(path$$1.call(print, "body"));
} else if (n.body) {
parts.push(" ", group$1(path$$1.call(print, "body")));
} else {
parts.push(semi);
}
return concat$4(parts);
}
case "PrivateName":
return concat$4(["#", path$$1.call(print, "id")]);
case "TSConditionalType":
return printTernaryOperator(path$$1, options, print, {
beforeParts: function beforeParts() {
return [path$$1.call(print, "checkType"), " ", "extends", " ", path$$1.call(print, "extendsType")];
},
afterParts: function afterParts() {
return [];
},
shouldCheckJsx: false,
conditionalNodeType: "TSConditionalType",
consequentNodePropertyName: "trueType",
alternateNodePropertyName: "falseType",
testNodePropertyName: "checkType",
breakNested: true
});
case "TSInferType":
return concat$4(["infer", " ", path$$1.call(print, "typeParameter")]);
case "InterpreterDirective":
parts.push("#!", n.value, hardline$3);
if (isNextLineEmpty$2(options.originalText, n, options)) {
parts.push(hardline$3);
}
return concat$4(parts);
case "NGRoot":
return concat$4([].concat(path$$1.call(print, "node"), !n.node.comments || n.node.comments.length === 0 ? [] : concat$4([" //", n.node.comments[0].value.trimRight()])));
case "NGChainedExpression":
return group$1(join$2(concat$4([";", line$3]), path$$1.map(function (childPath) {
return hasNgSideEffect(childPath) ? print(childPath) : concat$4(["(", print(childPath), ")"]);
}, "expressions")));
case "NGEmptyExpression":
return "";
case "NGQuotedExpression":
return concat$4([n.prefix, ":", n.value]);
case "NGMicrosyntax":
return concat$4(path$$1.map(function (childPath, index) {
return concat$4([index === 0 ? "" : isNgForOf(childPath.getValue(), index, n) ? " " : concat$4([";", line$3]), print(childPath)]);
}, "body"));
case "NGMicrosyntaxKey":
return /^[a-z_$][a-z0-9_$]*(-[a-z_$][a-z0-9_$])*$/i.test(n.name) ? n.name : JSON.stringify(n.name);
case "NGMicrosyntaxExpression":
return concat$4([path$$1.call(print, "expression"), n.alias === null ? "" : concat$4([" as ", path$$1.call(print, "alias")])]);
case "NGMicrosyntaxKeyedExpression":
{
var index = path$$1.getName();
var _parentNode2 = path$$1.getParentNode();
var shouldNotPrintColon = isNgForOf(n, index, _parentNode2) || (index === 1 && (n.key.name === "then" || n.key.name === "else") || index === 2 && n.key.name === "else" && _parentNode2.body[index - 1].type === "NGMicrosyntaxKeyedExpression" && _parentNode2.body[index - 1].key.name === "then") && _parentNode2.body[0].type === "NGMicrosyntaxExpression";
return concat$4([path$$1.call(print, "key"), shouldNotPrintColon ? " " : ": ", path$$1.call(print, "expression")]);
}
case "NGMicrosyntaxLet":
return concat$4(["let ", path$$1.call(print, "key"), n.value === null ? "" : concat$4([" = ", path$$1.call(print, "value")])]);
case "NGMicrosyntaxAs":
return concat$4([path$$1.call(print, "key"), " as ", path$$1.call(print, "alias")]);
default:
/* istanbul ignore next */
throw new Error("unknown type: " + JSON.stringify(n.type));
}
}
function isNgForOf(node, index, parentNode) {
return node.type === "NGMicrosyntaxKeyedExpression" && node.key.name === "of" && index === 1 && parentNode.body[0].type === "NGMicrosyntaxLet" && parentNode.body[0].value === null;
}
/** identify if an angular expression seems to have side effects */
function hasNgSideEffect(path$$1) {
return hasNode(path$$1.getValue(), function (node) {
switch (node.type) {
case undefined:
return false;
case "CallExpression":
case "OptionalCallExpression":
case "AssignmentExpression":
return true;
}
});
}
function printStatementSequence(path$$1, options, print) {
var printed = [];
var bodyNode = path$$1.getNode();
var isClass = bodyNode.type === "ClassBody";
path$$1.map(function (stmtPath, i) {
var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
// "statements," it's safer simply to skip them.
/* istanbul ignore if */
if (!stmt) {
return;
} // Skip printing EmptyStatement nodes to avoid leaving stray
// semicolons lying around.
if (stmt.type === "EmptyStatement") {
return;
}
var stmtPrinted = print(stmtPath);
var text = options.originalText;
var parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
// don't prepend the only JSX element in a program with semicolon
if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
if (stmt.comments && stmt.comments.some(function (comment) {
return comment.leading;
})) {
parts.push(print(stmtPath, {
needsSemi: true
}));
} else {
parts.push(";", stmtPrinted);
}
} else {
parts.push(stmtPrinted);
}
if (!options.semi && isClass) {
if (classPropMayCauseASIProblems(stmtPath)) {
parts.push(";");
} else if (stmt.type === "ClassProperty") {
var nextChild = bodyNode.body[i + 1];
if (classChildNeedsASIProtection(nextChild)) {
parts.push(";");
}
}
}
if (isNextLineEmpty$2(text, stmt, options) && !isLastStatement(stmtPath)) {
parts.push(hardline$3);
}
printed.push(concat$4(parts));
});
return join$2(hardline$3, printed);
}
function printPropertyKey(path$$1, options, print) {
var node = path$$1.getNode();
var key = node.key;
if (key.type === "Identifier" && !node.computed && options.parser === "json") {
// a -> "a"
return path$$1.call(function (keyPath) {
return comments.printComments(keyPath, function () {
return JSON.stringify(key.name);
}, options);
}, "key");
}
if (isStringLiteral(key) && isIdentifierName(key.value) && !node.computed && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty")) {
// 'a' -> a
return path$$1.call(function (keyPath) {
return comments.printComments(keyPath, function () {
return key.value;
}, options);
}, "key");
}
return path$$1.call(print, "key");
}
function printMethod(path$$1, options, print) {
var node = path$$1.getNode();
var semi = options.semi ? ";" : "";
var kind = node.kind;
var parts = [];
if (node.type === "ObjectMethod" || node.type === "ClassMethod" || node.type === "ClassPrivateMethod") {
node.value = node;
}
if (node.value.async) {
parts.push("async ");
}
if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
if (node.value.generator) {
parts.push("*");
}
} else {
assert.ok(kind === "get" || kind === "set");
parts.push(kind, " ");
}
var key = printPropertyKey(path$$1, options, print);
if (node.computed) {
key = concat$4(["[", key, "]"]);
}
parts.push(key, concat$4(path$$1.call(function (valuePath) {
return [printFunctionTypeParameters(valuePath, options, print), group$1(concat$4([printFunctionParams(valuePath, print, options), printReturnType(valuePath, print, options)]))];
}, "value")));
if (!node.value.body || node.value.body.length === 0) {
parts.push(semi);
} else {
parts.push(" ", path$$1.call(print, "value", "body"));
}
return concat$4(parts);
}
function couldGroupArg(arg) {
return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertion" || arg.type === "TSAsExpression" || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && !arg.returnType && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode(arg.body));
}
function shouldGroupLastArg(args) {
var lastArg = getLast$4(args);
var penultimateArg = getPenultimate$1(args);
return !hasLeadingComment(lastArg) && !hasTrailingComment(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
// disable last element expansion.
!penultimateArg || penultimateArg.type !== lastArg.type);
}
function shouldGroupFirstArg(args) {
if (args.length !== 2) {
return false;
}
var firstArg = args[0];
var secondArg = args[1];
return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && secondArg.type !== "FunctionExpression" && secondArg.type !== "ArrowFunctionExpression" && secondArg.type !== "ConditionalExpression" && !couldGroupArg(secondArg);
}
function isSimpleFlowType(node) {
var flowTypeAnnotations = ["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"];
return node && flowTypeAnnotations.indexOf(node.type) !== -1 && !(node.type === "GenericTypeAnnotation" && node.typeParameters);
}
var functionCompositionFunctionNames = new Set(["pipe", // RxJS, Ramda
"pipeP", // Ramda
"pipeK", // Ramda
"compose", // Ramda, Redux
"composeFlipped", // Not from any library, but common in Haskell, so supported
"composeP", // Ramda
"composeK", // Ramda
"flow", // Lodash
"flowRight", // Lodash
"connect", // Redux
"createSelector" // Reselect
]);
var ordinaryMethodNames = new Set(["connect" // GObject, MongoDB
]);
function isFunctionCompositionFunction(node) {
switch (node.type) {
case "OptionalMemberExpression":
case "MemberExpression":
{
return isFunctionCompositionFunction(node.property) && !ordinaryMethodNames.has(node.property.name);
}
case "Identifier":
{
return functionCompositionFunctionNames.has(node.name);
}
case "StringLiteral":
case "Literal":
{
return functionCompositionFunctionNames.has(node.value);
}
}
}
function printArgumentsList(path$$1, options, print) {
var node = path$$1.getValue();
var args = node.arguments;
if (args.length === 0) {
return concat$4(["(", comments.printDanglingComments(path$$1, options,
/* sameIndent */
true), ")"]);
} // useEffect(() => { ... }, [foo, bar, baz])
if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].params.length === 0 && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.find(function (arg) {
return arg.leadingComments || arg.trailingComments;
})) {
return concat$4(["(", path$$1.call(print, "arguments", 0), ", ", path$$1.call(print, "arguments", 1), ")"]);
}
var anyArgEmptyLine = false;
var hasEmptyLineFollowingFirstArg = false;
var lastArgIndex = args.length - 1;
var printedArguments = path$$1.map(function (argPath, index) {
var arg = argPath.getNode();
var parts = [print(argPath)];
if (index === lastArgIndex) {// do nothing
} else if (isNextLineEmpty$2(options.originalText, arg, options)) {
if (index === 0) {
hasEmptyLineFollowingFirstArg = true;
}
anyArgEmptyLine = true;
parts.push(",", hardline$3, hardline$3);
} else {
parts.push(",", line$3);
}
return concat$4(parts);
}, "arguments");
var maybeTrailingComma = shouldPrintComma(options, "all") ? "," : "";
function allArgsBrokenOut() {
return group$1(concat$4(["(", indent$2(concat$4([line$3, concat$4(printedArguments)])), maybeTrailingComma, line$3, ")"]), {
shouldBreak: true
});
} // We want to get
// pipe(
// x => x + 1,
// x => x - 1
// )
// here, but not
// process.stdout.pipe(socket)
if (isFunctionCompositionFunction(node.callee) && args.length > 1) {
return allArgsBrokenOut();
}
var shouldGroupFirst = shouldGroupFirstArg(args);
var shouldGroupLast = shouldGroupLastArg(args);
if (shouldGroupFirst || shouldGroupLast) {
var shouldBreak = (shouldGroupFirst ? printedArguments.slice(1).some(willBreak$1) : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine; // We want to print the last argument with a special flag
var printedExpanded;
var i = 0;
path$$1.each(function (argPath) {
if (shouldGroupFirst && i === 0) {
printedExpanded = [concat$4([argPath.call(function (p) {
return print(p, {
expandFirstArg: true
});
}), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$3 : line$3, hasEmptyLineFollowingFirstArg ? hardline$3 : ""])].concat(printedArguments.slice(1));
}
if (shouldGroupLast && i === args.length - 1) {
printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(function (p) {
return print(p, {
expandLastArg: true
});
}));
}
i++;
}, "arguments");
var somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
return concat$4([somePrintedArgumentsWillBreak ? breakParent$2 : "", conditionalGroup$1([concat$4([ifBreak$1(indent$2(concat$4(["(", softline$1, concat$4(printedExpanded)])), concat$4(["(", concat$4(printedExpanded)])), somePrintedArgumentsWillBreak ? concat$4([ifBreak$1(maybeTrailingComma), softline$1]) : "", ")"]), shouldGroupFirst ? concat$4(["(", group$1(printedExpanded[0], {
shouldBreak: true
}), concat$4(printedExpanded.slice(1)), ")"]) : concat$4(["(", concat$4(printedArguments.slice(0, -1)), group$1(getLast$4(printedExpanded), {
shouldBreak: true
}), ")"]), allArgsBrokenOut()], {
shouldBreak
})]);
}
return group$1(concat$4(["(", indent$2(concat$4([softline$1, concat$4(printedArguments)])), ifBreak$1(shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]), {
shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
});
}
function printTypeAnnotation(path$$1, options, print) {
var node = path$$1.getValue();
if (!node.typeAnnotation) {
return "";
}
var parentNode = path$$1.getParentNode();
var isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
var isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
if (isFlowAnnotationComment(options.originalText, node.typeAnnotation, options)) {
return concat$4([" /*: ", path$$1.call(print, "typeAnnotation"), " */"]);
}
return concat$4([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path$$1.call(print, "typeAnnotation")]);
}
function printFunctionTypeParameters(path$$1, options, print) {
var fun = path$$1.getValue();
if (fun.typeArguments) {
return path$$1.call(print, "typeArguments");
}
if (fun.typeParameters) {
return path$$1.call(print, "typeParameters");
}
return "";
}
function printFunctionParams(path$$1, print, options, expandArg, printTypeParams) {
var fun = path$$1.getValue();
var paramsField = fun.parameters ? "parameters" : "params";
var typeParams = printTypeParams ? printFunctionTypeParameters(path$$1, options, print) : "";
var printed = [];
if (fun[paramsField]) {
printed = path$$1.map(print, paramsField);
}
if (fun.rest) {
printed.push(concat$4(["...", path$$1.call(print, "rest")]));
}
if (printed.length === 0) {
return concat$4([typeParams, "(", comments.printDanglingComments(path$$1, options,
/* sameIndent */
true, function (comment) {
return getNextNonSpaceNonCommentCharacter$1(options.originalText, comment, options.locEnd) === ")";
}), ")"]);
}
var lastParam = getLast$4(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
// params of the first/last argument, we dont want the arguments to break and instead
// want the whole expression to be on a new line.
//
// Good: Bad:
// verylongcall( verylongcall((
// (a, b) => { a,
// } b,
// }) ) => {
// })
if (expandArg && !(fun[paramsField] && fun[paramsField].some(function (n) {
return n.comments;
}))) {
return group$1(concat$4([removeLines$1(typeParams), "(", join$2(", ", printed.map(removeLines$1)), ")"]));
} // Single object destructuring should hug
//
// function({
// a,
// b,
// c
// }) {}
if (shouldHugArguments(fun)) {
return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
}
var parent = path$$1.getParentNode(); // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
if (isTestCall(parent)) {
return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
}
var isFlowShorthandWithOneArg = (isObjectTypePropertyAFunction(parent, options) || isTypeAnnotationAFunction(parent, options) || parent.type === "TypeAlias" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || parent.type === "IntersectionTypeAnnotation" || parent.type === "FunctionTypeAnnotation" && parent.returnType === fun) && fun[paramsField].length === 1 && fun[paramsField][0].name === null && fun[paramsField][0].typeAnnotation && fun.typeParameters === null && isSimpleFlowType(fun[paramsField][0].typeAnnotation) && !fun.rest;
if (isFlowShorthandWithOneArg) {
if (options.arrowParens === "always") {
return concat$4(["(", concat$4(printed), ")"]);
}
return concat$4(printed);
}
var canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
return concat$4([typeParams, "(", indent$2(concat$4([softline$1, join$2(concat$4([",", line$3]), printed)])), ifBreak$1(canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]);
}
function shouldPrintParamsWithoutParens(path$$1, options) {
if (options.arrowParens === "always") {
return false;
}
if (options.arrowParens === "avoid") {
var node = path$$1.getValue();
return canPrintParamsWithoutParens(node);
} // Fallback default; should be unreachable
return false;
}
function canPrintParamsWithoutParens(node) {
return node.params.length === 1 && !node.rest && !node.typeParameters && !hasDanglingComments(node) && node.params[0].type === "Identifier" && !node.params[0].typeAnnotation && !node.params[0].comments && !node.params[0].optional && !node.predicate && !node.returnType;
}
function printFunctionDeclaration(path$$1, print, options) {
var n = path$$1.getValue();
var parts = [];
if (n.async) {
parts.push("async ");
}
parts.push("function");
if (n.generator) {
parts.push("*");
}
if (n.id) {
parts.push(" ", path$$1.call(print, "id"));
}
parts.push(printFunctionTypeParameters(path$$1, options, print), group$1(concat$4([printFunctionParams(path$$1, print, options), printReturnType(path$$1, print, options)])), n.body ? " " : "", path$$1.call(print, "body"));
return concat$4(parts);
}
function printObjectMethod(path$$1, options, print) {
var objMethod = path$$1.getValue();
var parts = [];
if (objMethod.async) {
parts.push("async ");
}
if (objMethod.generator) {
parts.push("*");
}
if (objMethod.method || objMethod.kind === "get" || objMethod.kind === "set") {
return printMethod(path$$1, options, print);
}
var key = printPropertyKey(path$$1, options, print);
if (objMethod.computed) {
parts.push("[", key, "]");
} else {
parts.push(key);
}
parts.push(printFunctionTypeParameters(path$$1, options, print), group$1(concat$4([printFunctionParams(path$$1, print, options), printReturnType(path$$1, print, options)])), " ", path$$1.call(print, "body"));
return concat$4(parts);
}
function printReturnType(path$$1, print, options) {
var n = path$$1.getValue();
var returnType = path$$1.call(print, "returnType");
if (n.returnType && isFlowAnnotationComment(options.originalText, n.returnType, options)) {
return concat$4([" /*: ", returnType, " */"]);
}
var parts = [returnType]; // prepend colon to TypeScript type annotation
if (n.returnType && n.returnType.typeAnnotation) {
parts.unshift(": ");
}
if (n.predicate) {
// The return type will already add the colon, but otherwise we
// need to do it ourselves
parts.push(n.returnType ? " " : ": ", path$$1.call(print, "predicate"));
}
return concat$4(parts);
}
function printExportDeclaration(path$$1, options, print) {
var decl = path$$1.getValue();
var semi = options.semi ? ";" : "";
var parts = ["export "];
var isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
if (isDefault) {
parts.push("default ");
}
parts.push(comments.printDanglingComments(path$$1, options,
/* sameIndent */
true));
if (needsHardlineAfterDanglingComment(decl)) {
parts.push(hardline$3);
}
if (decl.declaration) {
parts.push(path$$1.call(print, "declaration"));
if (isDefault && decl.declaration.type !== "ClassDeclaration" && decl.declaration.type !== "FunctionDeclaration" && decl.declaration.type !== "TSAbstractClassDeclaration" && decl.declaration.type !== "TSInterfaceDeclaration" && decl.declaration.type !== "DeclareClass" && decl.declaration.type !== "DeclareFunction" && decl.declaration.type !== "TSDeclareFunction") {
parts.push(semi);
}
} else {
if (decl.specifiers && decl.specifiers.length > 0) {
var specifiers = [];
var defaultSpecifiers = [];
var namespaceSpecifiers = [];
path$$1.each(function (specifierPath) {
var specifierType = path$$1.getValue().type;
if (specifierType === "ExportSpecifier") {
specifiers.push(print(specifierPath));
} else if (specifierType === "ExportDefaultSpecifier") {
defaultSpecifiers.push(print(specifierPath));
} else if (specifierType === "ExportNamespaceSpecifier") {
namespaceSpecifiers.push(concat$4(["* as ", print(specifierPath)]));
}
}, "specifiers");
var isNamespaceFollowed = namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
var isDefaultFollowed = defaultSpecifiers.length !== 0 && (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
parts.push(decl.exportKind === "type" ? "type " : "", concat$4(defaultSpecifiers), concat$4([isDefaultFollowed ? ", " : ""]), concat$4(namespaceSpecifiers), concat$4([isNamespaceFollowed ? ", " : ""]), specifiers.length !== 0 ? group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, join$2(concat$4([",", line$3]), specifiers)])), ifBreak$1(shouldPrintComma(options) ? "," : ""), options.bracketSpacing ? line$3 : softline$1, "}"])) : "");
} else {
parts.push("{}");
}
if (decl.source) {
parts.push(" from ", path$$1.call(print, "source"));
}
parts.push(semi);
}
return concat$4(parts);
}
function printFlowDeclaration(path$$1, parts) {
var parentExportDecl = getParentExportDeclaration$1(path$$1);
if (parentExportDecl) {
assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
} else {
// If the parent node has type DeclareExportDeclaration, then it
// will be responsible for printing the "declare" token. Otherwise
// it needs to be printed with this non-exported declaration node.
parts.unshift("declare ");
}
return concat$4(parts);
}
function getFlowVariance(path$$1) {
if (!path$$1.variance) {
return null;
} // Babel 7.0 currently uses variance node type, and flow should
// follow suit soon:
// https://github.com/babel/babel/issues/4722
var variance = path$$1.variance.kind || path$$1.variance;
switch (variance) {
case "plus":
return "+";
case "minus":
return "-";
default:
/* istanbul ignore next */
return variance;
}
}
function printTypeScriptModifiers(path$$1, options, print) {
var n = path$$1.getValue();
if (!n.modifiers || !n.modifiers.length) {
return "";
}
return concat$4([join$2(" ", path$$1.map(print, "modifiers")), " "]);
}
function printTypeParameters(path$$1, options, print, paramsKey) {
var n = path$$1.getValue();
if (!n[paramsKey]) {
return "";
} // for TypeParameterDeclaration typeParameters is a single node
if (!Array.isArray(n[paramsKey])) {
return path$$1.call(print, paramsKey);
}
var grandparent = path$$1.getNode(2);
var isParameterInTestCall = grandparent != null && isTestCall(grandparent);
var shouldInline = isParameterInTestCall || n[paramsKey].length === 0 || n[paramsKey].length === 1 && (shouldHugType(n[paramsKey][0]) || n[paramsKey][0].type === "GenericTypeAnnotation" && shouldHugType(n[paramsKey][0].id) || n[paramsKey][0].type === "TSTypeReference" && shouldHugType(n[paramsKey][0].typeName) || n[paramsKey][0].type === "NullableTypeAnnotation");
if (shouldInline) {
return concat$4(["<", join$2(", ", path$$1.map(print, paramsKey)), ">"]);
}
return group$1(concat$4(["<", indent$2(concat$4([softline$1, join$2(concat$4([",", line$3]), path$$1.map(print, paramsKey))])), ifBreak$1(options.parser !== "typescript" && shouldPrintComma(options, "all") ? "," : ""), softline$1, ">"]));
}
function printClass(path$$1, options, print) {
var n = path$$1.getValue();
var parts = [];
if (n.type === "TSAbstractClassDeclaration") {
parts.push("abstract ");
}
parts.push("class");
if (n.id) {
parts.push(" ", path$$1.call(print, "id"));
}
parts.push(path$$1.call(print, "typeParameters"));
var partsGroup = [];
if (n.superClass) {
var printed = concat$4(["extends ", path$$1.call(print, "superClass"), path$$1.call(print, "superTypeParameters")]); // Keep old behaviour of extends in same line
// If there is only on extends and there are not comments
if ((!n.implements || n.implements.length === 0) && (!n.superClass.comments || n.superClass.comments.length === 0)) {
parts.push(concat$4([" ", path$$1.call(function (superClass) {
return comments.printComments(superClass, function () {
return printed;
}, options);
}, "superClass")]));
} else {
partsGroup.push(group$1(concat$4([line$3, path$$1.call(function (superClass) {
return comments.printComments(superClass, function () {
return printed;
}, options);
}, "superClass")])));
}
} else if (n.extends && n.extends.length > 0) {
parts.push(" extends ", join$2(", ", path$$1.map(print, "extends")));
}
if (n["mixins"] && n["mixins"].length > 0) {
partsGroup.push(line$3, "mixins ", group$1(indent$2(join$2(concat$4([",", line$3]), path$$1.map(print, "mixins")))));
}
if (n["implements"] && n["implements"].length > 0) {
partsGroup.push(line$3, "implements", group$1(indent$2(concat$4([line$3, join$2(concat$4([",", line$3]), path$$1.map(print, "implements"))]))));
}
if (partsGroup.length > 0) {
parts.push(group$1(indent$2(concat$4(partsGroup))));
}
if (n.body && n.body.comments && hasLeadingOwnLineComment(options.originalText, n.body, options)) {
parts.push(hardline$3);
} else {
parts.push(" ");
}
parts.push(path$$1.call(print, "body"));
return parts;
}
function printOptionalToken(path$$1) {
var node = path$$1.getValue();
if (!node.optional) {
return "";
}
if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
return "?.";
}
return "?";
}
function printMemberLookup(path$$1, options, print) {
var property = path$$1.call(print, "property");
var n = path$$1.getValue();
var optional = printOptionalToken(path$$1);
if (!n.computed) {
return concat$4([optional, ".", property]);
}
if (!n.property || isNumericLiteral(n.property)) {
return concat$4([optional, "[", property, "]"]);
}
return group$1(concat$4([optional, "[", indent$2(concat$4([softline$1, property])), softline$1, "]"]));
}
function printBindExpressionCallee(path$$1, options, print) {
return concat$4(["::", path$$1.call(print, "callee")]);
} // We detect calls on member expressions specially to format a
// common pattern better. The pattern we are looking for is this:
//
// arr
// .map(x => x + 1)
// .filter(x => x > 10)
// .some(x => x % 2)
//
// The way it is structured in the AST is via a nested sequence of
// MemberExpression and CallExpression. We need to traverse the AST
// and make groups out of it to print it in the desired way.
function printMemberChain(path$$1, options, print) {
// The first phase is to linearize the AST by traversing it down.
//
// a().b()
// has the following AST structure:
// CallExpression(MemberExpression(CallExpression(Identifier)))
// and we transform it into
// [Identifier, CallExpression, MemberExpression, CallExpression]
var printedNodes = []; // Here we try to retain one typed empty line after each call expression or
// the first group whether it is in parentheses or not
function shouldInsertEmptyLineAfter(node) {
var originalText = options.originalText;
var nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$2(originalText, node, options);
var nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
// line after that parenthesis
if (nextChar == ")") {
return isNextLineEmptyAfterIndex$1(originalText, nextCharIndex + 1, options);
}
return isNextLineEmpty$2(originalText, node, options);
}
function rec(path$$1) {
var node = path$$1.getValue();
if ((node.type === "CallExpression" || node.type === "OptionalCallExpression") && (isMemberish(node.callee) || node.callee.type === "CallExpression" || node.callee.type === "OptionalCallExpression")) {
printedNodes.unshift({
node: node,
printed: concat$4([comments.printComments(path$$1, function () {
return concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
}, options), shouldInsertEmptyLineAfter(node) ? hardline$3 : ""])
});
path$$1.call(function (callee) {
return rec(callee);
}, "callee");
} else if (isMemberish(node)) {
printedNodes.unshift({
node: node,
needsParens: needsParens_1(path$$1, options),
printed: comments.printComments(path$$1, function () {
return node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup(path$$1, options, print) : printBindExpressionCallee(path$$1, options, print);
}, options)
});
path$$1.call(function (object) {
return rec(object);
}, "object");
} else if (node.type === "TSNonNullExpression") {
printedNodes.unshift({
node: node,
printed: comments.printComments(path$$1, function () {
return "!";
}, options)
});
path$$1.call(function (expression) {
return rec(expression);
}, "expression");
} else {
printedNodes.unshift({
node: node,
printed: path$$1.call(print)
});
}
} // Note: the comments of the root node have already been printed, so we
// need to extract this first call without printing them as they would
// if handled inside of the recursive call.
var node = path$$1.getValue();
printedNodes.unshift({
node,
printed: concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)])
});
path$$1.call(function (callee) {
return rec(callee);
}, "callee"); // Once we have a linear list of printed nodes, we want to create groups out
// of it.
//
// a().b.c().d().e
// will be grouped as
// [
// [Identifier, CallExpression],
// [MemberExpression, MemberExpression, CallExpression],
// [MemberExpression, CallExpression],
// [MemberExpression],
// ]
// so that we can print it as
// a()
// .b.c()
// .d()
// .e
// The first group is the first node followed by
// - as many CallExpression as possible
// < fn()()() >.something()
// - as many array acessors as possible
// < fn()[0][1][2] >.something()
// - then, as many MemberExpression as possible but the last one
// < this.items >.something()
var groups = [];
var currentGroup = [printedNodes[0]];
var i = 1;
for (; i < printedNodes.length; ++i) {
if (printedNodes[i].node.type === "TSNonNullExpression" || printedNodes[i].node.type === "OptionalCallExpression" || printedNodes[i].node.type === "CallExpression" || (printedNodes[i].node.type === "MemberExpression" || printedNodes[i].node.type === "OptionalMemberExpression") && printedNodes[i].node.computed && isNumericLiteral(printedNodes[i].node.property)) {
currentGroup.push(printedNodes[i]);
} else {
break;
}
}
if (printedNodes[0].node.type !== "CallExpression" && printedNodes[0].node.type !== "OptionalCallExpression") {
for (; i + 1 < printedNodes.length; ++i) {
if (isMemberish(printedNodes[i].node) && isMemberish(printedNodes[i + 1].node)) {
currentGroup.push(printedNodes[i]);
} else {
break;
}
}
}
groups.push(currentGroup);
currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
// a sequence of CallExpression. To compute it, we keep adding things to the
// group until we has seen a CallExpression in the past and reach a
// MemberExpression
var hasSeenCallExpression = false;
for (; i < printedNodes.length; ++i) {
if (hasSeenCallExpression && isMemberish(printedNodes[i].node)) {
// [0] should be appended at the end of the group instead of the
// beginning of the next one
if (printedNodes[i].node.computed && isNumericLiteral(printedNodes[i].node.property)) {
currentGroup.push(printedNodes[i]);
continue;
}
groups.push(currentGroup);
currentGroup = [];
hasSeenCallExpression = false;
}
if (printedNodes[i].node.type === "CallExpression" || printedNodes[i].node.type === "OptionalCallExpression") {
hasSeenCallExpression = true;
}
currentGroup.push(printedNodes[i]);
if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(function (comment) {
return comment.trailing;
})) {
groups.push(currentGroup);
currentGroup = [];
hasSeenCallExpression = false;
}
}
if (currentGroup.length > 0) {
groups.push(currentGroup);
} // There are cases like Object.keys(), Observable.of(), _.values() where
// they are the subject of all the chained calls and therefore should
// be kept on the same line:
//
// Object.keys(items)
// .filter(x => x)
// .map(x => x)
//
// In order to detect those cases, we use an heuristic: if the first
// node is an identifier with the name starting with a capital
// letter or just a sequence of _$. The rationale is that they are
// likely to be factories.
function isFactory(name) {
return /^[A-Z]|^[_$]+$/.test(name);
} // In case the Identifier is shorter than tab width, we can keep the
// first call in a single line, if it's an ExpressionStatement.
//
// d3.scaleLinear()
// .domain([0, 100])
// .range([0, width]);
//
function isShort(name) {
return name.length <= options.tabWidth;
}
function shouldNotWrap(groups) {
var parent = path$$1.getParentNode();
var isExpression = parent && parent.type === "ExpressionStatement";
var hasComputed = groups[1].length && groups[1][0].node.computed;
if (groups[0].length === 1) {
var firstNode = groups[0][0].node;
return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpression && isShort(firstNode.name) || hasComputed);
}
var lastNode = getLast$4(groups[0]).node;
return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
}
var shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
function printGroup(printedGroup) {
var result = [];
for (var _i3 = 0; _i3 < printedGroup.length; _i3++) {
// Checks if the next node (i.e. the parent node) needs parens
// and print accordingly
if (printedGroup[_i3 + 1] && printedGroup[_i3 + 1].needsParens) {
result.push("(", printedGroup[_i3].printed, printedGroup[_i3 + 1].printed, ")");
_i3++;
} else {
result.push(printedGroup[_i3].printed);
}
}
return concat$4(result);
}
function printIndentedGroup(groups) {
if (groups.length === 0) {
return "";
}
return indent$2(group$1(concat$4([hardline$3, join$2(hardline$3, groups.map(printGroup))])));
}
var printedGroups = groups.map(printGroup);
var oneLine = concat$4(printedGroups);
var cutoff = shouldMerge ? 3 : 2;
var flatGroups = groups.slice(0, cutoff).reduce(function (res, group) {
return res.concat(group);
}, []);
var hasComment = flatGroups.slice(1, -1).some(function (node) {
return hasLeadingComment(node.node);
}) || flatGroups.slice(0, -1).some(function (node) {
return hasTrailingComment(node.node);
}) || groups[cutoff] && hasLeadingComment(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
// render everything concatenated together.
if (groups.length <= cutoff && !hasComment) {
return group$1(oneLine);
} // Find out the last node in the first group and check if it has an
// empty line after
var lastNodeBeforeIndent = getLast$4(shouldMerge ? groups.slice(1, 2)[0] : groups[0]).node;
var shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "CallExpression" && lastNodeBeforeIndent.type !== "OptionalCallExpression" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
var expanded = concat$4([printGroup(groups[0]), shouldMerge ? concat$4(groups.slice(1, 2).map(printGroup)) : "", shouldHaveEmptyLineBeforeIndent ? hardline$3 : "", printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))]);
var callExpressions = printedNodes.map(function (_ref) {
var node = _ref.node;
return node;
}).filter(isCallOrOptionalCallExpression); // We don't want to print in one line if there's:
// * A comment.
// * 3 or more chained calls.
// * Any group but the last one has a hard line.
// If the last group is a function it's okay to inline if it fits.
if (hasComment || callExpressions.length >= 3 || printedGroups.slice(0, -1).some(willBreak$1) ||
/**
* scopes.filter(scope => scope.value !== '').map((scope, i) => {
* // multi line content
* })
*/
function (lastGroupDoc, lastGroupNode) {
return isCallOrOptionalCallExpression(lastGroupNode) && willBreak$1(lastGroupDoc);
}(getLast$4(printedGroups), getLast$4(getLast$4(groups)).node) && callExpressions.slice(0, -1).some(function (n) {
return n.arguments.some(isFunctionOrArrowExpression);
})) {
return group$1(expanded);
}
return concat$4([// We only need to check `oneLine` because if `expanded` is chosen
// that means that the parent group has already been broken
// naturally
willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$2 : "", conditionalGroup$1([oneLine, expanded])]);
}
function isCallOrOptionalCallExpression(node) {
return node.type === "CallExpression" || node.type === "OptionalCallExpression";
}
function isJSXNode(node) {
return node.type === "JSXElement" || node.type === "JSXFragment";
}
function isEmptyJSXElement(node) {
if (node.children.length === 0) {
return true;
}
if (node.children.length > 1) {
return false;
} // if there is one text child and does not contain any meaningful text
// we can treat the element as empty.
var child = node.children[0];
return isLiteral(child) && !isMeaningfulJSXText(child);
} // Only space, newline, carriage return, and tab are treated as whitespace
// inside JSX.
var jsxWhitespaceChars = " \n\r\t";
var containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]");
var matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)"); // Meaningful if it contains non-whitespace characters,
// or it contains whitespace without a new line.
function isMeaningfulJSXText(node) {
return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
}
function conditionalExpressionChainContainsJSX(node) {
return Boolean(getConditionalChainContents(node).find(isJSXNode));
} // If we have nested conditional expressions, we want to print them in JSX mode
// if there's at least one JSXElement somewhere in the tree.
//
// A conditional expression chain like this should be printed in normal mode,
// because there aren't JSXElements anywhere in it:
//
// isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
//
// But a conditional expression chain like this should be printed in JSX mode,
// because there is a JSXElement in the last ConditionalExpression:
//
// isA ? "A" : isB ? "B" : isC ? "C" :
Unknown;
//
// This type of ConditionalExpression chain is structured like this in the AST:
//
// ConditionalExpression {
// test: ...,
// consequent: ...,
// alternate: ConditionalExpression {
// test: ...,
// consequent: ...,
// alternate: ConditionalExpression {
// test: ...,
// consequent: ...,
// alternate: ...,
// }
// }
// }
//
// We want to traverse over that shape and convert it into a flat structure so
// that we can find if there's a JSXElement somewhere inside.
function getConditionalChainContents(node) {
// Given this code:
//
// // Using a ConditionalExpression as the consequent is uncommon, but should
// // be handled.
// A ? B : C ? D : E ? F ? G : H : I
//
// which has this AST:
//
// ConditionalExpression {
// test: Identifier(A),
// consequent: Identifier(B),
// alternate: ConditionalExpression {
// test: Identifier(C),
// consequent: Identifier(D),
// alternate: ConditionalExpression {
// test: Identifier(E),
// consequent: ConditionalExpression {
// test: Identifier(F),
// consequent: Identifier(G),
// alternate: Identifier(H),
// },
// alternate: Identifier(I),
// }
// }
// }
//
// we should return this Array:
//
// [
// Identifier(A),
// Identifier(B),
// Identifier(C),
// Identifier(D),
// Identifier(E),
// Identifier(F),
// Identifier(G),
// Identifier(H),
// Identifier(I)
// ];
//
// This loses the information about whether each node was the test,
// consequent, or alternate, but we don't care about that here- we are only
// flattening this structure to find if there's any JSXElements inside.
var nonConditionalExpressions = [];
function recurse(node) {
if (node.type === "ConditionalExpression") {
recurse(node.test);
recurse(node.consequent);
recurse(node.alternate);
} else {
nonConditionalExpressions.push(node);
}
}
recurse(node);
return nonConditionalExpressions;
} // Detect an expression node representing `{" "}`
function isJSXWhitespaceExpression(node) {
return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
}
function separatorNoWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
if (isFacebookTranslationTag) {
return "";
}
if (childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement) {
return child.length === 1 ? softline$1 : hardline$3;
}
return softline$1;
}
function separatorWithWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
if (isFacebookTranslationTag) {
return hardline$3;
}
if (child.length === 1) {
return childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement ? hardline$3 : softline$1;
}
return hardline$3;
} // JSX Children are strange, mostly for two reasons:
// 1. JSX reads newlines into string values, instead of skipping them like JS
// 2. up to one whitespace between elements within a line is significant,
// but not between lines.
//
// Leading, trailing, and lone whitespace all need to
// turn themselves into the rather ugly `{' '}` when breaking.
//
// We print JSX using the `fill` doc primitive.
// This requires that we give it an array of alternating
// content and whitespace elements.
// To ensure this we add dummy `""` content elements as needed.
function printJSXChildren(path$$1, options, print, jsxWhitespace, isFacebookTranslationTag) {
var n = path$$1.getValue();
var children = []; // using `map` instead of `each` because it provides `i`
path$$1.map(function (childPath, i) {
var child = childPath.getValue();
if (isLiteral(child)) {
var text = rawText(child); // Contains a non-whitespace character
if (isMeaningfulJSXText(child)) {
var words = text.split(matchJsxWhitespaceRegex); // Starts with whitespace
if (words[0] === "") {
children.push("");
words.shift();
if (/\n/.test(words[0])) {
var next = n.children[i + 1];
children.push(separatorWithWhitespace(isFacebookTranslationTag, words[1], child, next));
} else {
children.push(jsxWhitespace);
}
words.shift();
}
var endWhitespace; // Ends with whitespace
if (getLast$4(words) === "") {
words.pop();
endWhitespace = words.pop();
} // This was whitespace only without a new line.
if (words.length === 0) {
return;
}
words.forEach(function (word, i) {
if (i % 2 === 1) {
children.push(line$3);
} else {
children.push(word);
}
});
if (endWhitespace !== undefined) {
if (/\n/.test(endWhitespace)) {
var _next = n.children[i + 1];
children.push(separatorWithWhitespace(isFacebookTranslationTag, getLast$4(children), child, _next));
} else {
children.push(jsxWhitespace);
}
} else {
var _next2 = n.children[i + 1];
children.push(separatorNoWhitespace(isFacebookTranslationTag, getLast$4(children), child, _next2));
}
} else if (/\n/.test(text)) {
// Keep (up to one) blank line between tags/expressions/text.
// Note: We don't keep blank lines between text elements.
if (text.match(/\n/g).length > 1) {
children.push("");
children.push(hardline$3);
}
} else {
children.push("");
children.push(jsxWhitespace);
}
} else {
var printedChild = print(childPath);
children.push(printedChild);
var _next3 = n.children[i + 1];
var directlyFollowedByMeaningfulText = _next3 && isMeaningfulJSXText(_next3);
if (directlyFollowedByMeaningfulText) {
var firstWord = rawText(_next3).trim().split(matchJsxWhitespaceRegex)[0];
children.push(separatorNoWhitespace(isFacebookTranslationTag, firstWord, child, _next3));
} else {
children.push(hardline$3);
}
}
}, "children");
return children;
} // JSX expands children from the inside-out, instead of the outside-in.
// This is both to break children before attributes,
// and to ensure that when children break, their parents do as well.
//
// Any element that is written without any newlines and fits on a single line
// is left that way.
// Not only that, any user-written-line containing multiple JSX siblings
// should also be kept on one line if possible,
// so each user-written-line is wrapped in its own group.
//
// Elements that contain newlines or don't fit on a single line (recursively)
// are fully-split, using hardline and shouldBreak: true.
//
// To support that case properly, all leading and trailing spaces
// are stripped from the list of children, and replaced with a single hardline.
function printJSXElement(path$$1, options, print) {
var n = path$$1.getValue(); // Turn
into
if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
n.openingElement.selfClosing = true;
return path$$1.call(print, "openingElement");
}
var openingLines = n.type === "JSXElement" ? path$$1.call(print, "openingElement") : path$$1.call(print, "openingFragment");
var closingLines = n.type === "JSXElement" ? path$$1.call(print, "closingElement") : path$$1.call(print, "closingFragment");
if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
return concat$4([openingLines, concat$4(path$$1.map(print, "children")), closingLines]);
} // Convert `{" "}` to text nodes containing a space.
// This makes it easy to turn them into `jsxWhitespace` which
// can then print as either a space or `{" "}` when breaking.
n.children = n.children.map(function (child) {
if (isJSXWhitespaceExpression(child)) {
return {
type: "JSXText",
value: " ",
raw: " "
};
}
return child;
});
var containsTag = n.children.filter(isJSXNode).length > 0;
var containsMultipleExpressions = n.children.filter(function (child) {
return child.type === "JSXExpressionContainer";
}).length > 1;
var containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
var forcedBreak = willBreak$1(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
var rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
var jsxWhitespace = ifBreak$1(concat$4([rawJsxWhitespace, softline$1]), " ");
var isFacebookTranslationTag = n.openingElement && n.openingElement.name && n.openingElement.name.name === "fbt";
var children = printJSXChildren(path$$1, options, print, jsxWhitespace, isFacebookTranslationTag);
var containsText = n.children.filter(function (child) {
return isMeaningfulJSXText(child);
}).length > 0; // We can end up we multiple whitespace elements with empty string
// content between them.
// We need to remove empty whitespace and softlines before JSX whitespace
// to get the correct output.
for (var i = children.length - 2; i >= 0; i--) {
var isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
var isPairOfHardlines = children[i] === hardline$3 && children[i + 1] === "" && children[i + 2] === hardline$3;
var isLineFollowedByJSXWhitespace = (children[i] === softline$1 || children[i] === hardline$3) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
var isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$1 || children[i + 2] === hardline$3);
var isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
var isPairOfHardOrSoftLines = children[i] === softline$1 && children[i + 1] === "" && children[i + 2] === hardline$3 || children[i] === hardline$3 && children[i + 1] === "" && children[i + 2] === softline$1;
if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace || isPairOfHardOrSoftLines) {
children.splice(i, 2);
} else if (isJSXWhitespaceFollowedByLine) {
children.splice(i + 1, 2);
}
} // Trim trailing lines (or empty strings)
while (children.length && (isLineNext$1(getLast$4(children)) || isEmpty$1(getLast$4(children)))) {
children.pop();
} // Trim leading lines (or empty strings)
while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
children.shift();
children.shift();
} // Tweak how we format children if outputting this element over multiple lines.
// Also detect whether we will force this element to output over multiple lines.
var multilineChildren = [];
children.forEach(function (child, i) {
// There are a number of situations where we need to ensure we display
// whitespace as `{" "}` when outputting this element over multiple lines.
if (child === jsxWhitespace) {
if (i === 1 && children[i - 1] === "") {
if (children.length === 2) {
// Solitary whitespace
multilineChildren.push(rawJsxWhitespace);
return;
} // Leading whitespace
multilineChildren.push(concat$4([rawJsxWhitespace, hardline$3]));
return;
} else if (i === children.length - 1) {
// Trailing whitespace
multilineChildren.push(rawJsxWhitespace);
return;
} else if (children[i - 1] === "" && children[i - 2] === hardline$3) {
// Whitespace after line break
multilineChildren.push(rawJsxWhitespace);
return;
}
}
multilineChildren.push(child);
if (willBreak$1(child)) {
forcedBreak = true;
}
}); // If there is text we use `fill` to fit as much onto each line as possible.
// When there is no text (just tags and expressions) we use `group`
// to output each on a separate line.
var content = containsText ? fill$2(multilineChildren) : group$1(concat$4(multilineChildren), {
shouldBreak: true
});
var multiLineElem = group$1(concat$4([openingLines, indent$2(concat$4([hardline$3, content])), hardline$3, closingLines]));
if (forcedBreak) {
return multiLineElem;
}
return conditionalGroup$1([group$1(concat$4([openingLines, concat$4(children), closingLines])), multiLineElem]);
}
function maybeWrapJSXElementInParens(path$$1, elem) {
var parent = path$$1.getParentNode();
if (!parent) {
return elem;
}
var NO_WRAP_PARENTS = {
ArrayExpression: true,
JSXAttribute: true,
JSXElement: true,
JSXExpressionContainer: true,
JSXFragment: true,
ExpressionStatement: true,
CallExpression: true,
OptionalCallExpression: true,
ConditionalExpression: true,
JsExpressionRoot: true
};
if (NO_WRAP_PARENTS[parent.type]) {
return elem;
}
var shouldBreak = matchAncestorTypes$1(path$$1, ["ArrowFunctionExpression", "CallExpression", "JSXExpressionContainer"]);
return group$1(concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, elem])), softline$1, ifBreak$1(")")]), {
shouldBreak
});
}
function isBinaryish(node) {
return node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression";
}
function isMemberish(node) {
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && node.object;
}
function shouldInlineLogicalExpression(node) {
if (node.type !== "LogicalExpression") {
return false;
}
if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
return true;
}
if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
return true;
}
if (isJSXNode(node.right)) {
return true;
}
return false;
} // For binary expressions to be consistent, we need to group
// subsequent operators with the same precedence level under a single
// group. Otherwise they will be nested such that some of them break
// onto new lines but not all. Operators with the same precedence
// level should either all break or not. Because we group them by
// precedence level and the AST is structured based on precedence
// level, things are naturally broken up correctly, i.e. `&&` is
// broken before `+`.
function printBinaryishExpressions(path$$1, print, options, isNested, isInsideParenthesis) {
var parts = [];
var node = path$$1.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
if (isBinaryish(node)) {
// Put all operators with the same precedence level in the same
// group. The reason we only need to do this with the `left`
// expression is because given an expression like `1 + 2 - 3`, it
// is always parsed like `((1 + 2) - 3)`, meaning the `left` side
// is where the rest of the expression will exist. Binary
// expressions on the right side mean they have a difference
// precedence level and should be treated as a separate group, so
// print them normally. (This doesn't hold for the `**` operator,
// which is unique in that it is right-associative.)
if (shouldFlatten$1(node.operator, node.left.operator)) {
// Flatten them out by recursively calling this function.
parts = parts.concat(path$$1.call(function (left) {
return printBinaryishExpressions(left, print, options,
/* isNested */
true, isInsideParenthesis);
}, "left"));
} else {
parts.push(path$$1.call(print, "left"));
}
var shouldInline = shouldInlineLogicalExpression(node);
var lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment(options.originalText, node.right, options);
var operator = node.type === "NGPipeExpression" ? "|" : node.operator;
var rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$1(indent$2(concat$4([softline$1, ": ", join$2(concat$4([softline$1, ":", ifBreak$1(" ")]), path$$1.map(print, "arguments").map(function (arg) {
return align$1(2, group$1(arg));
}))]))) : "";
var right = shouldInline ? concat$4([operator, " ", path$$1.call(print, "right"), rightSuffix]) : concat$4([lineBeforeOperator ? softline$1 : "", operator, lineBeforeOperator ? " " : line$3, path$$1.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
// in order to avoid having a small right part like -1 be on its own line.
var parent = path$$1.getParentNode();
var shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
parts.push(" ", shouldGroup ? group$1(right) : right); // The root comments are already printed, but we need to manually print
// the other ones since we don't call the normal print on BinaryExpression,
// only for the left and right parts
if (isNested && node.comments) {
parts = comments.printComments(path$$1, function () {
return concat$4(parts);
}, options);
}
} else {
// Our stopping case. Simply print the node normally.
parts.push(path$$1.call(print));
}
return parts;
}
function printAssignmentRight(leftNode, rightNode, printedRight, options) {
if (hasLeadingOwnLineComment(options.originalText, rightNode, options)) {
return indent$2(concat$4([hardline$3, printedRight]));
}
var canBreak = isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode) || rightNode.type === "ConditionalExpression" && isBinaryish(rightNode.test) && !shouldInlineLogicalExpression(rightNode.test) || rightNode.type === "StringLiteralTypeAnnotation" || rightNode.type === "ClassExpression" && rightNode.decorators && rightNode.decorators.length || (leftNode.type === "Identifier" || isStringLiteral(leftNode) || leftNode.type === "MemberExpression") && (isStringLiteral(rightNode) || isMemberExpressionChain(rightNode)) && // do not put values on a separate line from the key in json
options.parser !== "json" && options.parser !== "json5";
if (canBreak) {
return group$1(indent$2(concat$4([line$3, printedRight])));
}
return concat$4([" ", printedRight]);
}
function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
if (!rightNode) {
return printedLeft;
}
var printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
return group$1(concat$4([printedLeft, operator, printed]));
}
function adjustClause(node, clause, forceSpace) {
if (node.type === "EmptyStatement") {
return ";";
}
if (node.type === "BlockStatement" || forceSpace) {
return concat$4([" ", clause]);
}
return indent$2(concat$4([line$3, clause]));
}
function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
var raw = rawText(node);
var isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
return printString$1(raw, options, isDirectiveLiteral);
}
function printRegex(node) {
var flags = node.flags.split("").sort().join("");
return `/${node.pattern}/${flags}`;
}
function isLastStatement(path$$1) {
var parent = path$$1.getParentNode();
if (!parent) {
return true;
}
var node = path$$1.getValue();
var body = (parent.body || parent.consequent).filter(function (stmt) {
return stmt.type !== "EmptyStatement";
});
return body && body[body.length - 1] === node;
}
function hasLeadingComment(node) {
return node.comments && node.comments.some(function (comment) {
return comment.leading;
});
}
function hasTrailingComment(node) {
return node.comments && node.comments.some(function (comment) {
return comment.trailing;
});
}
function hasLeadingOwnLineComment(text, node, options) {
if (isJSXNode(node)) {
return hasNodeIgnoreComment$1(node);
}
var res = node.comments && node.comments.some(function (comment) {
return comment.leading && hasNewline$2(text, options.locEnd(comment));
});
return res;
}
function hasNakedLeftSide(node) {
return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression" || node.type === "ConditionalExpression" || node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || node.type === "UpdateExpression" && !node.prefix || node.type === "TSNonNullExpression";
}
function isFlowAnnotationComment(text, typeAnnotation, options) {
var start = options.locStart(typeAnnotation);
var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
}
function getLeftSide(node) {
if (node.expressions) {
return node.expressions[0];
}
return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
}
function getLeftSidePathName(path$$1, node) {
if (node.expressions) {
return ["expressions", 0];
}
if (node.left) {
return ["left"];
}
if (node.test) {
return ["test"];
}
if (node.object) {
return ["object"];
}
if (node.callee) {
return ["callee"];
}
if (node.tag) {
return ["tag"];
}
if (node.argument) {
return ["argument"];
}
if (node.expression) {
return ["expression"];
}
throw new Error("Unexpected node has no left side", node);
}
function exprNeedsASIProtection(path$$1, options) {
var node = path$$1.getValue();
var maybeASIProblem = needsParens_1(path$$1, options) || node.type === "ParenthesizedExpression" || node.type === "TypeCastExpression" || node.type === "ArrowFunctionExpression" && !shouldPrintParamsWithoutParens(path$$1, options) || node.type === "ArrayExpression" || node.type === "ArrayPattern" || node.type === "UnaryExpression" && node.prefix && (node.operator === "+" || node.operator === "-") || node.type === "TemplateLiteral" || node.type === "TemplateElement" || isJSXNode(node) || node.type === "BindExpression" && !node.object || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
if (maybeASIProblem) {
return true;
}
if (!hasNakedLeftSide(node)) {
return false;
}
return path$$1.call.apply(path$$1, [function (childPath) {
return exprNeedsASIProtection(childPath, options);
}].concat(getLeftSidePathName(path$$1, node)));
}
function stmtNeedsASIProtection(path$$1, options) {
var node = path$$1.getNode();
if (node.type !== "ExpressionStatement") {
return false;
}
return path$$1.call(function (childPath) {
return exprNeedsASIProtection(childPath, options);
}, "expression");
}
function classPropMayCauseASIProblems(path$$1) {
var node = path$$1.getNode();
if (node.type !== "ClassProperty") {
return false;
}
var name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
// so isn't properly tested yet.
if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
return true;
}
}
function classChildNeedsASIProtection(node) {
if (!node) {
return;
}
if (node.static || node.accessibility // TypeScript
) {
return false;
}
if (!node.computed) {
var name = node.key && node.key.name;
if (name === "in" || name === "instanceof") {
return true;
}
}
switch (node.type) {
case "ClassProperty":
case "TSAbstractClassProperty":
return node.computed;
case "MethodDefinition": // Flow
case "TSAbstractMethodDefinition": // TypeScript
case "ClassMethod":
case "ClassPrivateMethod":
{
// Babel
var isAsync = node.value ? node.value.async : node.async;
var isGenerator = node.value ? node.value.generator : node.generator;
if (isAsync || node.kind === "get" || node.kind === "set") {
return false;
}
if (node.computed || isGenerator) {
return true;
}
return false;
}
default:
/* istanbul ignore next */
return false;
}
} // This recurses the return argument, looking for the first token
// (the leftmost leaf node) and, if it (or its parents) has any
// leadingComments, returns true (so it can be wrapped in parens).
function returnArgumentHasLeadingComment(options, argument) {
if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
return true;
}
if (hasNakedLeftSide(argument)) {
var leftMost = argument;
var newLeftMost;
while (newLeftMost = getLeftSide(leftMost)) {
leftMost = newLeftMost;
if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
return true;
}
}
}
return false;
}
function isMemberExpressionChain(node) {
if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
return false;
}
if (node.object.type === "Identifier") {
return true;
}
return isMemberExpressionChain(node.object);
} // Hack to differentiate between the following two which have the same ast
// type T = { method: () => void };
// type T = { method(): void };
function isObjectTypePropertyAFunction(node, options) {
return (node.type === "ObjectTypeProperty" || node.type === "ObjectTypeInternalSlot") && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
} // TODO: This is a bad hack and we need a better way to distinguish between
// arrow functions and otherwise
function isFunctionNotation(node, options) {
return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
}
function isGetterOrSetter(node) {
return node.kind === "get" || node.kind === "set";
}
function sameLocStart(nodeA, nodeB, options) {
return options.locStart(nodeA) === options.locStart(nodeB);
} // Hack to differentiate between the following two which have the same ast
// declare function f(a): void;
// var f: (a) => void;
function isTypeAnnotationAFunction(node, options) {
return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
}
function isNodeStartingWithDeclare(node, options) {
if (!(options.parser === "flow" || options.parser === "typescript")) {
return false;
}
return options.originalText.slice(0, options.locStart(node)).match(/declare[ \t]*$/) || options.originalText.slice(node.range[0], node.range[1]).startsWith("declare ");
}
function shouldHugType(node) {
if (isSimpleFlowType(node) || isObjectType(node)) {
return true;
}
if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
var voidCount = node.types.filter(function (n) {
return n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword";
}).length;
var objectCount = node.types.filter(function (n) {
return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference";
}).length;
if (node.types.length - 1 === voidCount && objectCount > 0) {
return true;
}
}
return false;
}
function shouldHugArguments(fun) {
return fun && fun.params && fun.params.length === 1 && !fun.params[0].comments && (fun.params[0].type === "ObjectPattern" || fun.params[0].type === "ArrayPattern" || fun.params[0].type === "Identifier" && fun.params[0].typeAnnotation && (fun.params[0].typeAnnotation.type === "TypeAnnotation" || fun.params[0].typeAnnotation.type === "TSTypeAnnotation") && isObjectType(fun.params[0].typeAnnotation.typeAnnotation) || fun.params[0].type === "FunctionTypeParam" && isObjectType(fun.params[0].typeAnnotation) || fun.params[0].type === "AssignmentPattern" && (fun.params[0].left.type === "ObjectPattern" || fun.params[0].left.type === "ArrayPattern") && (fun.params[0].right.type === "Identifier" || fun.params[0].right.type === "ObjectExpression" && fun.params[0].right.properties.length === 0 || fun.params[0].right.type === "ArrayExpression" && fun.params[0].right.elements.length === 0)) && !fun.rest;
}
function templateLiteralHasNewLines(template) {
return template.quasis.some(function (quasi) {
return quasi.value.raw.includes("\n");
});
}
function isTemplateOnItsOwnLine(n, text, options) {
return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$2(text, options.locStart(n), {
backwards: true
});
}
function printArrayItems(path$$1, options, printPath, print) {
var printedElements = [];
var separatorParts = [];
path$$1.each(function (childPath) {
printedElements.push(concat$4(separatorParts));
printedElements.push(group$1(print(childPath)));
separatorParts = [",", line$3];
if (childPath.getValue() && isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
separatorParts.push(softline$1);
}
}, printPath);
return concat$4(printedElements);
}
function hasDanglingComments(node) {
return node.comments && node.comments.some(function (comment) {
return !comment.leading && !comment.trailing;
});
}
function needsHardlineAfterDanglingComment(node) {
if (!node.comments) {
return false;
}
var lastDanglingComment = getLast$4(node.comments.filter(function (comment) {
return !comment.leading && !comment.trailing;
}));
return lastDanglingComment && !comments$3.isBlockComment(lastDanglingComment);
}
function isLiteral(node) {
return node.type === "BooleanLiteral" || node.type === "DirectiveLiteral" || node.type === "Literal" || node.type === "NullLiteral" || node.type === "NumericLiteral" || node.type === "RegExpLiteral" || node.type === "StringLiteral" || node.type === "TemplateLiteral" || node.type === "TSTypeLiteral" || node.type === "JSXText";
}
function isNumericLiteral(node) {
return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
}
function isStringLiteral(node) {
return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
}
function isObjectType(n) {
return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
}
var unitTestRe = /^(skip|[fx]?(it|describe|test))$/; // eg; `describe("some string", (done) => {})`
function isTestCall(n, parent) {
if (n.type !== "CallExpression") {
return false;
}
if (n.arguments.length === 1) {
if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
return isFunctionOrArrowExpression(n.arguments[0]);
}
if (isUnitTestSetUp(n)) {
return isAngularTestWrapper(n.arguments[0]);
}
} else if (n.arguments.length === 2 || n.arguments.length === 3) {
if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
// it("name", () => { ... }, 2500)
if (n.arguments[2] && !isNumericLiteral(n.arguments[2])) {
return false;
}
return (n.arguments.length === 2 ? isFunctionOrArrowExpression(n.arguments[1]) : isFunctionOrArrowExpressionWithBody(n.arguments[1]) && n.arguments[1].params.length <= 1) || isAngularTestWrapper(n.arguments[1]);
}
}
return false;
}
function isSkipOrOnlyBlock(node) {
return (node.callee.type === "MemberExpression" || node.callee.type === "OptionalMemberExpression") && node.callee.object.type === "Identifier" && node.callee.property.type === "Identifier" && unitTestRe.test(node.callee.object.name) && (node.callee.property.name === "only" || node.callee.property.name === "skip");
}
function isTemplateLiteral(node) {
return node.type === "TemplateLiteral";
} // `inject` is used in AngularJS 1.x, `async` in Angular 2+
// example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
function isAngularTestWrapper(node) {
return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject" || node.callee.name === "fakeAsync");
}
function isFunctionOrArrowExpression(node) {
return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
}
function isFunctionOrArrowExpressionWithBody(node) {
return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement";
}
function isUnitTestSetUp(n) {
var unitTestSetUpRe = /^(before|after)(Each|All)$/;
return n.callee.type === "Identifier" && unitTestSetUpRe.test(n.callee.name) && n.arguments.length === 1;
}
function isTheOnlyJSXElementInMarkdown(options, path$$1) {
if (options.parentParser !== "markdown" && options.parentParser !== "mdx") {
return false;
}
var node = path$$1.getNode();
if (!node.expression || !isJSXNode(node.expression)) {
return false;
}
var parent = path$$1.getParentNode();
return parent.type === "Program" && parent.body.length == 1;
}
function willPrintOwnComments(path$$1) {
var node = path$$1.getValue();
var parent = path$$1.getParentNode();
return (node && (isJSXNode(node) || hasFlowShorthandAnnotationComment(node) || parent && parent.type === "CallExpression" && (hasFlowAnnotationComment(node.leadingComments) || hasFlowAnnotationComment(node.trailingComments))) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && !hasIgnoreComment$1(path$$1);
}
function canAttachComment(node) {
return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import" && !(node.callee && node.callee.type === "Import");
}
function printComment$1(commentPath, options) {
var comment = commentPath.getValue();
switch (comment.type) {
case "CommentBlock":
case "Block":
{
if (isIndentableBlockComment(comment)) {
var printed = printIndentableBlockComment(comment); // We need to prevent an edge case of a previous trailing comment
// printed as a `lineSuffix` which causes the comments to be
// interleaved. See https://github.com/prettier/prettier/issues/4412
if (comment.trailing && !hasNewline$2(options.originalText, options.locStart(comment), {
backwards: true
})) {
return concat$4([hardline$3, printed]);
}
return printed;
}
var isInsideFlowComment = options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
}
case "CommentLine":
case "Line":
// Print shebangs with the proper comment characters
if (options.originalText.slice(options.locStart(comment)).startsWith("#!")) {
return "#!" + comment.value.trimRight();
}
return "//" + comment.value.trimRight();
default:
throw new Error("Not a comment: " + JSON.stringify(comment));
}
}
function isIndentableBlockComment(comment) {
// If the comment has multiple lines and every line starts with a star
// we can fix the indentation of each line. The stars in the `/*` and
// `*/` delimiters are not included in the comment value, so add them
// back first.
var lines = `*${comment.value}*`.split("\n");
return lines.length > 1 && lines.every(function (line) {
return line.trim()[0] === "*";
});
}
function printIndentableBlockComment(comment) {
var lines = comment.value.split("\n");
return concat$4(["/*", join$2(hardline$3, lines.map(function (line, index) {
return index === 0 ? line.trimRight() : " " + (index < lines.length - 1 ? line.trim() : line.trimLeft());
})), "*/"]);
}
function rawText(node) {
return node.extra ? node.extra.raw : node.raw;
}
function identity$1(x) {
return x;
}
var printerEstree = {
preprocess: preprocess_1,
print: genericPrint,
embed: embed_1,
insertPragma,
massageAstNode: clean_1,
hasPrettierIgnore,
willPrintOwnComments,
canAttachComment,
printComment: printComment$1,
isBlockComment: comments$3.isBlockComment,
handleComments: {
ownLine: comments$3.handleOwnLineComment,
endOfLine: comments$3.handleEndOfLineComment,
remaining: comments$3.handleRemainingComment
}
};
var _require$$0$builders$2 = doc.builders;
var concat$7 = _require$$0$builders$2.concat;
var hardline$5 = _require$$0$builders$2.hardline;
var indent$4 = _require$$0$builders$2.indent;
var join$5 = _require$$0$builders$2.join;
function genericPrint$1(path$$1, options, print) {
var node = path$$1.getValue();
switch (node.type) {
case "JsonRoot":
return concat$7([path$$1.call(print, "node"), hardline$5]);
case "ArrayExpression":
return node.elements.length === 0 ? "[]" : concat$7(["[", indent$4(concat$7([hardline$5, join$5(concat$7([",", hardline$5]), path$$1.map(print, "elements"))])), hardline$5, "]"]);
case "ObjectExpression":
return node.properties.length === 0 ? "{}" : concat$7(["{", indent$4(concat$7([hardline$5, join$5(concat$7([",", hardline$5]), path$$1.map(print, "properties"))])), hardline$5, "}"]);
case "ObjectProperty":
return concat$7([path$$1.call(print, "key"), ": ", path$$1.call(print, "value")]);
case "UnaryExpression":
return concat$7([node.operator === "+" ? "" : node.operator, path$$1.call(print, "argument")]);
case "NullLiteral":
return "null";
case "BooleanLiteral":
return node.value ? "true" : "false";
case "StringLiteral":
case "NumericLiteral":
return JSON.stringify(node.value);
case "Identifier":
return JSON.stringify(node.name);
default:
/* istanbul ignore next */
throw new Error("unknown type: " + JSON.stringify(node.type));
}
}
function clean$2(node, newNode
/*, parent*/
) {
delete newNode.start;
delete newNode.end;
delete newNode.extra;
delete newNode.loc;
delete newNode.comments;
if (node.type === "Identifier") {
return {
type: "StringLiteral",
value: node.name
};
}
if (node.type === "UnaryExpression" && node.operator === "+") {
return newNode.argument;
}
}
var printerEstreeJson = {
preprocess: preprocess_1,
print: genericPrint$1,
massageAstNode: clean$2
};
var CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
var commonOptions = {
bracketSpacing: {
since: "0.0.0",
category: CATEGORY_COMMON,
type: "boolean",
default: true,
description: "Print spaces between brackets.",
oppositeDescription: "Do not print spaces between brackets."
},
singleQuote: {
since: "0.0.0",
category: CATEGORY_COMMON,
type: "boolean",
default: false,
description: "Use single quotes instead of double quotes."
},
proseWrap: {
since: "1.8.2",
category: CATEGORY_COMMON,
type: "choice",
default: [{
since: "1.8.2",
value: true
}, {
since: "1.9.0",
value: "preserve"
}],
description: "How to wrap prose.",
choices: [{
since: "1.9.0",
value: "always",
description: "Wrap prose if it exceeds the print width."
}, {
since: "1.9.0",
value: "never",
description: "Do not wrap prose."
}, {
since: "1.9.0",
value: "preserve",
description: "Wrap prose as-is."
}, {
value: false,
deprecated: "1.9.0",
redirect: "never"
}, {
value: true,
deprecated: "1.9.0",
redirect: "always"
}]
}
};
var CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
var options$3 = {
arrowParens: {
since: "1.9.0",
category: CATEGORY_JAVASCRIPT,
type: "choice",
default: "avoid",
description: "Include parentheses around a sole arrow function parameter.",
choices: [{
value: "avoid",
description: "Omit parens when possible. Example: `x => x`"
}, {
value: "always",
description: "Always include parens. Example: `(x) => x`"
}]
},
bracketSpacing: commonOptions.bracketSpacing,
jsxBracketSameLine: {
since: "0.17.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
default: false,
description: "Put > on the last line instead of at a new line."
},
semi: {
since: "1.0.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
default: true,
description: "Print semicolons.",
oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
},
singleQuote: commonOptions.singleQuote,
jsxSingleQuote: {
since: "1.15.0",
category: CATEGORY_JAVASCRIPT,
type: "boolean",
default: false,
description: "Use single quotes in JSX."
},
trailingComma: {
since: "0.0.0",
category: CATEGORY_JAVASCRIPT,
type: "choice",
default: [{
since: "0.0.0",
value: false
}, {
since: "0.19.0",
value: "none"
}],
description: "Print trailing commas wherever possible when multi-line.",
choices: [{
value: "none",
description: "No trailing commas."
}, {
value: "es5",
description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
}, {
value: "all",
description: "Trailing commas wherever possible (including function arguments)."
}, {
value: true,
deprecated: "0.19.0",
redirect: "es5"
}, {
value: false,
deprecated: "0.19.0",
redirect: "none"
}]
}
};
var createLanguage = function createLanguage(linguistData, _ref) {
var extend = _ref.extend,
override = _ref.override;
var language = {};
for (var key in linguistData) {
var newKey = key === "languageId" ? "linguistLanguageId" : key;
language[newKey] = linguistData[key];
}
if (extend) {
for (var _key in extend) {
language[_key] = (language[_key] || []).concat(extend[_key]);
}
}
for (var _key2 in override) {
language[_key2] = override[_key2];
}
return language;
};
var name$1 = "JavaScript";
var type = "programming";
var tmScope = "source.js";
var aceMode = "javascript";
var codemirrorMode = "javascript";
var codemirrorMimeType = "text/javascript";
var color = "#f1e05a";
var aliases = ["js", "node"];
var extensions = [".js", "._js", ".bones", ".es", ".es6", ".frag", ".gs", ".jake", ".jsb", ".jscad", ".jsfl", ".jsm", ".jss", ".mjs", ".njs", ".pac", ".sjs", ".ssjs", ".xsjs", ".xsjslib"];
var filenames = ["Jakefile"];
var interpreters = ["node"];
var languageId = 183;
var javascript = {
name: name$1,
type: type,
tmScope: tmScope,
aceMode: aceMode,
codemirrorMode: codemirrorMode,
codemirrorMimeType: codemirrorMimeType,
color: color,
aliases: aliases,
extensions: extensions,
filenames: filenames,
interpreters: interpreters,
languageId: languageId
};
var javascript$1 = Object.freeze({
name: name$1,
type: type,
tmScope: tmScope,
aceMode: aceMode,
codemirrorMode: codemirrorMode,
codemirrorMimeType: codemirrorMimeType,
color: color,
aliases: aliases,
extensions: extensions,
filenames: filenames,
interpreters: interpreters,
languageId: languageId,
default: javascript
});
var name$2 = "JSX";
var type$1 = "programming";
var group$3 = "JavaScript";
var extensions$1 = [".jsx"];
var tmScope$1 = "source.js.jsx";
var aceMode$1 = "javascript";
var codemirrorMode$1 = "jsx";
var codemirrorMimeType$1 = "text/jsx";
var languageId$1 = 178;
var jsx = {
name: name$2,
type: type$1,
group: group$3,
extensions: extensions$1,
tmScope: tmScope$1,
aceMode: aceMode$1,
codemirrorMode: codemirrorMode$1,
codemirrorMimeType: codemirrorMimeType$1,
languageId: languageId$1
};
var jsx$1 = Object.freeze({
name: name$2,
type: type$1,
group: group$3,
extensions: extensions$1,
tmScope: tmScope$1,
aceMode: aceMode$1,
codemirrorMode: codemirrorMode$1,
codemirrorMimeType: codemirrorMimeType$1,
languageId: languageId$1,
default: jsx
});
var name$3 = "TypeScript";
var type$2 = "programming";
var color$1 = "#2b7489";
var aliases$1 = ["ts"];
var extensions$2 = [".ts", ".tsx"];
var tmScope$2 = "source.ts";
var aceMode$2 = "typescript";
var codemirrorMode$2 = "javascript";
var codemirrorMimeType$2 = "application/typescript";
var languageId$2 = 378;
var typescript = {
name: name$3,
type: type$2,
color: color$1,
aliases: aliases$1,
extensions: extensions$2,
tmScope: tmScope$2,
aceMode: aceMode$2,
codemirrorMode: codemirrorMode$2,
codemirrorMimeType: codemirrorMimeType$2,
languageId: languageId$2
};
var typescript$1 = Object.freeze({
name: name$3,
type: type$2,
color: color$1,
aliases: aliases$1,
extensions: extensions$2,
tmScope: tmScope$2,
aceMode: aceMode$2,
codemirrorMode: codemirrorMode$2,
codemirrorMimeType: codemirrorMimeType$2,
languageId: languageId$2,
default: typescript
});
var name$4 = "JSON";
var type$3 = "data";
var tmScope$3 = "source.json";
var group$4 = "JavaScript";
var aceMode$3 = "json";
var codemirrorMode$3 = "javascript";
var codemirrorMimeType$3 = "application/json";
var searchable = false;
var extensions$3 = [".json", ".avsc", ".geojson", ".gltf", ".JSON-tmLanguage", ".jsonl", ".tfstate", ".tfstate.backup", ".topojson", ".webapp", ".webmanifest"];
var filenames$1 = [".arcconfig", ".htmlhintrc", ".tern-config", ".tern-project", "composer.lock", "mcmod.info"];
var languageId$3 = 174;
var json$2 = {
name: name$4,
type: type$3,
tmScope: tmScope$3,
group: group$4,
aceMode: aceMode$3,
codemirrorMode: codemirrorMode$3,
codemirrorMimeType: codemirrorMimeType$3,
searchable: searchable,
extensions: extensions$3,
filenames: filenames$1,
languageId: languageId$3
};
var json$3 = Object.freeze({
name: name$4,
type: type$3,
tmScope: tmScope$3,
group: group$4,
aceMode: aceMode$3,
codemirrorMode: codemirrorMode$3,
codemirrorMimeType: codemirrorMimeType$3,
searchable: searchable,
extensions: extensions$3,
filenames: filenames$1,
languageId: languageId$3,
default: json$2
});
var name$5 = "JSON with Comments";
var type$4 = "data";
var group$5 = "JSON";
var tmScope$4 = "source.js";
var aceMode$4 = "javascript";
var codemirrorMode$4 = "javascript";
var codemirrorMimeType$4 = "text/javascript";
var aliases$2 = ["jsonc"];
var extensions$4 = [".sublime-build", ".sublime-commands", ".sublime-completions", ".sublime-keymap", ".sublime-macro", ".sublime-menu", ".sublime-mousemap", ".sublime-project", ".sublime-settings", ".sublime-theme", ".sublime-workspace", ".sublime_metrics", ".sublime_session"];
var filenames$2 = [".babelrc", ".eslintrc.json", ".jscsrc", ".jshintrc", ".jslintrc", "tsconfig.json"];
var languageId$4 = 423;
var jsonWithComments = {
name: name$5,
type: type$4,
group: group$5,
tmScope: tmScope$4,
aceMode: aceMode$4,
codemirrorMode: codemirrorMode$4,
codemirrorMimeType: codemirrorMimeType$4,
aliases: aliases$2,
extensions: extensions$4,
filenames: filenames$2,
languageId: languageId$4
};
var jsonWithComments$1 = Object.freeze({
name: name$5,
type: type$4,
group: group$5,
tmScope: tmScope$4,
aceMode: aceMode$4,
codemirrorMode: codemirrorMode$4,
codemirrorMimeType: codemirrorMimeType$4,
aliases: aliases$2,
extensions: extensions$4,
filenames: filenames$2,
languageId: languageId$4,
default: jsonWithComments
});
var name$6 = "JSON5";
var type$5 = "data";
var extensions$5 = [".json5"];
var tmScope$5 = "source.js";
var aceMode$5 = "javascript";
var codemirrorMode$5 = "javascript";
var codemirrorMimeType$5 = "application/json";
var languageId$5 = 175;
var json5 = {
name: name$6,
type: type$5,
extensions: extensions$5,
tmScope: tmScope$5,
aceMode: aceMode$5,
codemirrorMode: codemirrorMode$5,
codemirrorMimeType: codemirrorMimeType$5,
languageId: languageId$5
};
var json5$1 = Object.freeze({
name: name$6,
type: type$5,
extensions: extensions$5,
tmScope: tmScope$5,
aceMode: aceMode$5,
codemirrorMode: codemirrorMode$5,
codemirrorMimeType: codemirrorMimeType$5,
languageId: languageId$5,
default: json5
});
var require$$0$21 = ( javascript$1 && javascript ) || javascript$1;
var require$$1$8 = ( jsx$1 && jsx ) || jsx$1;
var require$$2$10 = ( typescript$1 && typescript ) || typescript$1;
var require$$3$3 = ( json$3 && json$2 ) || json$3;
var require$$4$2 = ( jsonWithComments$1 && jsonWithComments ) || jsonWithComments$1;
var require$$5$1 = ( json5$1 && json5 ) || json5$1;
var languages = [createLanguage(require$$0$21, {
override: {
since: "0.0.0",
parsers: ["babel", "flow"],
vscodeLanguageIds: ["javascript"]
},
extend: {
interpreters: ["nodejs"]
}
}), createLanguage(require$$0$21, {
override: {
name: "Flow",
since: "0.0.0",
parsers: ["babel", "flow"],
vscodeLanguageIds: ["javascript"],
aliases: [],
filenames: [],
extensions: [".js.flow"]
}
}), createLanguage(require$$1$8, {
override: {
since: "0.0.0",
parsers: ["babel", "flow"],
vscodeLanguageIds: ["javascriptreact"]
}
}), createLanguage(require$$2$10, {
override: {
since: "1.4.0",
parsers: ["typescript"],
vscodeLanguageIds: ["typescript", "typescriptreact"]
}
}), createLanguage(require$$3$3, {
override: {
name: "JSON.stringify",
since: "1.13.0",
parsers: ["json-stringify"],
vscodeLanguageIds: ["json"],
extensions: [],
// .json file defaults to json instead of json-stringify
filenames: ["package.json", "package-lock.json", "composer.json"]
}
}), createLanguage(require$$3$3, {
override: {
since: "1.5.0",
parsers: ["json"],
vscodeLanguageIds: ["json"]
},
extend: {
filenames: [".prettierrc"]
}
}), createLanguage(require$$4$2, {
override: {
since: "1.5.0",
parsers: ["json"],
vscodeLanguageIds: ["jsonc"]
},
extend: {
filenames: [".eslintrc"]
}
}), createLanguage(require$$5$1, {
override: {
since: "1.13.0",
parsers: ["json5"],
vscodeLanguageIds: ["json5"]
}
})];
var printers = {
estree: printerEstree,
"estree-json": printerEstreeJson
};
var languageJs = {
languages,
options: options$3,
printers
};
var index$12 = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "command", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "legend", "li", "link", "listing", "main", "map", "mark", "marquee", "math", "menu", "menuitem", "meta", "meter", "multicol", "nav", "nextid", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "pre", "progress", "q", "rb", "rbc", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp"];
var htmlTagNames = Object.freeze({
default: index$12
});
var htmlTagNames$1 = ( htmlTagNames && index$12 ) || htmlTagNames;
function clean$3(ast, newObj, parent) {
["raw", // front-matter
"raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(function (name) {
delete newObj[name];
});
if (ast.type === "yaml") {
delete newObj.value;
} // --insert-pragma
if (ast.type === "css-comment" && parent.type === "css-root" && parent.nodes.length !== 0 && ( // first non-front-matter comment
parent.nodes[0] === ast || (parent.nodes[0].type === "yaml" || parent.nodes[0].type === "toml") && parent.nodes[1] === ast)) {
/**
* something
*
* @format
*/
delete newObj.text; // standalone pragma
if (/^\*\s*@(format|prettier)\s*$/.test(ast.text)) {
return null;
}
}
if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
delete newObj.value;
}
if (ast.type === "css-rule") {
delete newObj.params;
}
if (ast.type === "selector-combinator") {
newObj.value = newObj.value.replace(/\s+/g, " ");
}
if (ast.type === "media-feature") {
newObj.value = newObj.value.replace(/ /g, "");
}
if (ast.type === "value-word" && (ast.isColor && ast.isHex || ["initial", "inherit", "unset", "revert"].indexOf(newObj.value.replace().toLowerCase()) !== -1) || ast.type === "media-feature" || ast.type === "selector-root-invalid" || ast.type === "selector-pseudo") {
newObj.value = newObj.value.toLowerCase();
}
if (ast.type === "css-decl") {
newObj.prop = newObj.prop.toLowerCase();
}
if (ast.type === "css-atrule" || ast.type === "css-import") {
newObj.name = newObj.name.toLowerCase();
}
if (ast.type === "value-number") {
newObj.unit = newObj.unit.toLowerCase();
}
if ((ast.type === "media-feature" || ast.type === "media-keyword" || ast.type === "media-type" || ast.type === "media-unknown" || ast.type === "media-url" || ast.type === "media-value" || ast.type === "selector-attribute" || ast.type === "selector-string" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "value-string") && newObj.value) {
newObj.value = cleanCSSStrings(newObj.value);
}
if (ast.type === "selector-attribute") {
newObj.attribute = newObj.attribute.trim();
if (newObj.namespace) {
if (typeof newObj.namespace === "string") {
newObj.namespace = newObj.namespace.trim();
if (newObj.namespace.length === 0) {
newObj.namespace = true;
}
}
}
if (newObj.value) {
newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
delete newObj.quoted;
}
}
if ((ast.type === "media-value" || ast.type === "media-type" || ast.type === "value-number" || ast.type === "selector-root-invalid" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "selector-tag") && newObj.value) {
newObj.value = newObj.value.replace(/([\d.eE+-]+)([a-zA-Z]*)/g, function (match, numStr, unit) {
var num = Number(numStr);
return isNaN(num) ? match : num + unit.toLowerCase();
});
}
if (ast.type === "selector-tag") {
var lowercasedValue = ast.value.toLowerCase();
if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
newObj.value = lowercasedValue;
}
if (["from", "to"].indexOf(lowercasedValue) !== -1) {
newObj.value = lowercasedValue;
}
} // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
delete newObj.value;
} // Workaround for SCSS nested properties
if (ast.type === "selector-unknown") {
delete newObj.value;
}
}
function cleanCSSStrings(value) {
return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
}
var clean_1$2 = clean$3;
var _require$$0$builders$3 = doc.builders;
var hardline$7 = _require$$0$builders$3.hardline;
var literalline$3 = _require$$0$builders$3.literalline;
var concat$9 = _require$$0$builders$3.concat;
var markAsRoot$1 = _require$$0$builders$3.markAsRoot;
var mapDoc$4 = doc.utils.mapDoc;
function embed$2(path$$1, print, textToDoc
/*, options */
) {
var node = path$$1.getValue();
if (node.type === "yaml") {
return markAsRoot$1(concat$9(["---", hardline$7, node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
parser: "yaml"
})) : "", "---", hardline$7]));
}
return null;
function replaceNewlinesWithLiterallines(doc$$2) {
return mapDoc$4(doc$$2, function (currentDoc) {
return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$9(currentDoc.split(/(\n)/g).map(function (v, i) {
return i % 2 === 0 ? v : literalline$3;
})) : currentDoc;
});
}
}
var embed_1$2 = embed$2;
var DELIMITER_MAP = {
"---": "yaml",
"+++": "toml"
};
function parse$5(text) {
var delimiterRegex = Object.keys(DELIMITER_MAP).map(escapeStringRegexp).join("|");
var match = text.match( // trailing spaces after delimiters are allowed
new RegExp(`^(${delimiterRegex})[^\\n\\S]*\\n(?:([\\s\\S]*?)\\n)?\\1[^\\n\\S]*(\\n|$)`));
if (match === null) {
return {
frontMatter: null,
content: text
};
}
var raw = match[0].replace(/\n$/, "");
var delimiter = match[1];
var value = match[2];
return {
frontMatter: {
type: DELIMITER_MAP[delimiter],
value,
raw
},
content: match[0].replace(/[^\n]/g, " ") + text.slice(match[0].length)
};
}
var frontMatter = parse$5;
function hasPragma$1(text) {
return pragma.hasPragma(frontMatter(text).content);
}
function insertPragma$3(text) {
var _parseFrontMatter = frontMatter(text),
frontMatter$$1 = _parseFrontMatter.frontMatter,
content = _parseFrontMatter.content;
return (frontMatter$$1 ? frontMatter$$1.raw + "\n\n" : "") + pragma.insertPragma(content);
}
var pragma$2 = {
hasPragma: hasPragma$1,
insertPragma: insertPragma$3
};
var colorAdjusterFunctions = ["red", "green", "blue", "alpha", "a", "rgb", "hue", "h", "saturation", "s", "lightness", "l", "whiteness", "w", "blackness", "b", "tint", "shade", "blend", "blenda", "contrast", "hsl", "hsla", "hwb", "hwba"];
function getAncestorCounter(path$$1, typeOrTypes) {
var types = [].concat(typeOrTypes);
var counter = -1;
var ancestorNode;
while (ancestorNode = path$$1.getParentNode(++counter)) {
if (types.indexOf(ancestorNode.type) !== -1) {
return counter;
}
}
return -1;
}
function getAncestorNode$1(path$$1, typeOrTypes) {
var counter = getAncestorCounter(path$$1, typeOrTypes);
return counter === -1 ? null : path$$1.getParentNode(counter);
}
function getPropOfDeclNode$1(path$$1) {
var declAncestorNode = getAncestorNode$1(path$$1, "css-decl");
return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
}
function isSCSS$1(parser, text) {
var hasExplicitParserChoice = parser === "less" || parser === "scss";
var IS_POSSIBLY_SCSS = /(\w\s*: [^}:]+|#){|@import[^\n]+(url|,)/;
return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
}
function isWideKeywords$1(value) {
return ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== -1;
}
function isKeyframeAtRuleKeywords$1(path$$1, value) {
var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].indexOf(value.toLowerCase()) !== -1;
}
function maybeToLowerCase$1(value) {
return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
}
function insideValueFunctionNode$1(path$$1, functionName) {
var funcAncestorNode = getAncestorNode$1(path$$1, "value-func");
return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
}
function insideICSSRuleNode$1(path$$1) {
var ruleAncestorNode = getAncestorNode$1(path$$1, "css-rule");
return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
}
function insideAtRuleNode$1(path$$1, atRuleNameOrAtRuleNames) {
var atRuleNames = [].concat(atRuleNameOrAtRuleNames);
var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
return atRuleAncestorNode && atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1;
}
function insideURLFunctionInImportAtRuleNode$1(path$$1) {
var node = path$$1.getValue();
var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
}
function isURLFunctionNode$1(node) {
return node.type === "value-func" && node.value.toLowerCase() === "url";
}
function isLastNode$1(path$$1, node) {
var parentNode = path$$1.getParentNode();
if (!parentNode) {
return false;
}
var nodes = parentNode.nodes;
return nodes && nodes.indexOf(node) === nodes.length - 1;
}
function isHTMLTag$1(value) {
return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
}
function isDetachedRulesetDeclarationNode$1(node) {
// If a Less file ends up being parsed with the SCSS parser, Less
// variable declarations will be parsed as atrules with names ending
// with a colon, so keep the original case then.
if (!node.selector) {
return false;
}
return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
}
function isForKeywordNode$1(node) {
return node.type === "value-word" && ["from", "through", "end"].indexOf(node.value) !== -1;
}
function isIfElseKeywordNode$1(node) {
return node.type === "value-word" && ["and", "or", "not"].indexOf(node.value) !== -1;
}
function isEachKeywordNode$1(node) {
return node.type === "value-word" && node.value === "in";
}
function isMultiplicationNode$1(node) {
return node.type === "value-operator" && node.value === "*";
}
function isDivisionNode$1(node) {
return node.type === "value-operator" && node.value === "/";
}
function isAdditionNode$1(node) {
return node.type === "value-operator" && node.value === "+";
}
function isSubtractionNode$1(node) {
return node.type === "value-operator" && node.value === "-";
}
function isModuloNode(node) {
return node.type === "value-operator" && node.value === "%";
}
function isMathOperatorNode$1(node) {
return isMultiplicationNode$1(node) || isDivisionNode$1(node) || isAdditionNode$1(node) || isSubtractionNode$1(node) || isModuloNode(node);
}
function isEqualityOperatorNode$1(node) {
return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1;
}
function isRelationalOperatorNode$1(node) {
return node.type === "value-word" && ["<", ">", "<=", ">="].indexOf(node.value) !== -1;
}
function isSCSSControlDirectiveNode$1(node) {
return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1;
}
function isSCSSNestedPropertyNode(node) {
if (!node.selector) {
return false;
}
return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
}
function isDetachedRulesetCallNode$1(node) {
return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
}
function isTemplatePlaceholderNode$1(node) {
return node.name.startsWith("prettier-placeholder");
}
function isTemplatePropNode$1(node) {
return node.prop.startsWith("@prettier-placeholder");
}
function isPostcssSimpleVarNode$1(currentNode, nextNode) {
return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
}
function hasComposesNode$1(node) {
return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
}
function hasParensAroundNode$1(node) {
return node.value && node.value.group && node.value.group.group && node.value.group.group.type === "value-paren_group" && node.value.group.group.open !== null && node.value.group.group.close !== null;
}
function hasEmptyRawBefore$1(node) {
return node.raws && node.raws.before === "";
}
function isKeyValuePairNode$1(node) {
return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
}
function isKeyValuePairInParenGroupNode(node) {
return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode$1(node.groups[0]);
}
function isSCSSMapItemNode$1(path$$1) {
var node = path$$1.getValue(); // Ignore empty item (i.e. `$key: ()`)
if (node.groups.length === 0) {
return false;
}
var parentParentNode = path$$1.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
return false;
}
var declNode = getAncestorNode$1(path$$1, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
return true;
} // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
if (isKeyValuePairInParenGroupNode(parentParentNode)) {
return true;
} // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
if (parentParentNode.type === "value-func") {
return true;
}
return false;
}
function isInlineValueCommentNode$1(node) {
return node.type === "value-comment" && node.inline;
}
function isHashNode$1(node) {
return node.type === "value-word" && node.value === "#";
}
function isLeftCurlyBraceNode$1(node) {
return node.type === "value-word" && node.value === "{";
}
function isRightCurlyBraceNode$1(node) {
return node.type === "value-word" && node.value === "}";
}
function isWordNode$1(node) {
return ["value-word", "value-atword"].indexOf(node.type) !== -1;
}
function isColonNode$1(node) {
return node.type === "value-colon";
}
function isMediaAndSupportsKeywords$1(node) {
return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
}
function isColorAdjusterFuncNode$1(node) {
if (node.type !== "value-func") {
return false;
}
return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
}
var utils$6 = {
getAncestorCounter,
getAncestorNode: getAncestorNode$1,
getPropOfDeclNode: getPropOfDeclNode$1,
maybeToLowerCase: maybeToLowerCase$1,
insideValueFunctionNode: insideValueFunctionNode$1,
insideICSSRuleNode: insideICSSRuleNode$1,
insideAtRuleNode: insideAtRuleNode$1,
insideURLFunctionInImportAtRuleNode: insideURLFunctionInImportAtRuleNode$1,
isKeyframeAtRuleKeywords: isKeyframeAtRuleKeywords$1,
isHTMLTag: isHTMLTag$1,
isWideKeywords: isWideKeywords$1,
isSCSS: isSCSS$1,
isLastNode: isLastNode$1,
isSCSSControlDirectiveNode: isSCSSControlDirectiveNode$1,
isDetachedRulesetDeclarationNode: isDetachedRulesetDeclarationNode$1,
isRelationalOperatorNode: isRelationalOperatorNode$1,
isEqualityOperatorNode: isEqualityOperatorNode$1,
isMultiplicationNode: isMultiplicationNode$1,
isDivisionNode: isDivisionNode$1,
isAdditionNode: isAdditionNode$1,
isSubtractionNode: isSubtractionNode$1,
isModuloNode,
isMathOperatorNode: isMathOperatorNode$1,
isEachKeywordNode: isEachKeywordNode$1,
isForKeywordNode: isForKeywordNode$1,
isURLFunctionNode: isURLFunctionNode$1,
isIfElseKeywordNode: isIfElseKeywordNode$1,
hasComposesNode: hasComposesNode$1,
hasParensAroundNode: hasParensAroundNode$1,
hasEmptyRawBefore: hasEmptyRawBefore$1,
isSCSSNestedPropertyNode,
isDetachedRulesetCallNode: isDetachedRulesetCallNode$1,
isTemplatePlaceholderNode: isTemplatePlaceholderNode$1,
isTemplatePropNode: isTemplatePropNode$1,
isPostcssSimpleVarNode: isPostcssSimpleVarNode$1,
isKeyValuePairNode: isKeyValuePairNode$1,
isKeyValuePairInParenGroupNode,
isSCSSMapItemNode: isSCSSMapItemNode$1,
isInlineValueCommentNode: isInlineValueCommentNode$1,
isHashNode: isHashNode$1,
isLeftCurlyBraceNode: isLeftCurlyBraceNode$1,
isRightCurlyBraceNode: isRightCurlyBraceNode$1,
isWordNode: isWordNode$1,
isColonNode: isColonNode$1,
isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1,
isColorAdjusterFuncNode: isColorAdjusterFuncNode$1
};
var insertPragma$2 = pragma$2.insertPragma;
var printNumber$2 = util$1.printNumber;
var printString$2 = util$1.printString;
var hasIgnoreComment$2 = util$1.hasIgnoreComment;
var hasNewline$3 = util$1.hasNewline;
var isNextLineEmpty$3 = utilShared.isNextLineEmpty;
var _require$$3$builders = doc.builders;
var concat$8 = _require$$3$builders.concat;
var join$6 = _require$$3$builders.join;
var line$5 = _require$$3$builders.line;
var hardline$6 = _require$$3$builders.hardline;
var softline$3 = _require$$3$builders.softline;
var group$6 = _require$$3$builders.group;
var fill$3 = _require$$3$builders.fill;
var indent$5 = _require$$3$builders.indent;
var dedent$3 = _require$$3$builders.dedent;
var ifBreak$2 = _require$$3$builders.ifBreak;
var removeLines$2 = doc.utils.removeLines;
var getAncestorNode = utils$6.getAncestorNode;
var getPropOfDeclNode = utils$6.getPropOfDeclNode;
var maybeToLowerCase = utils$6.maybeToLowerCase;
var insideValueFunctionNode = utils$6.insideValueFunctionNode;
var insideICSSRuleNode = utils$6.insideICSSRuleNode;
var insideAtRuleNode = utils$6.insideAtRuleNode;
var insideURLFunctionInImportAtRuleNode = utils$6.insideURLFunctionInImportAtRuleNode;
var isKeyframeAtRuleKeywords = utils$6.isKeyframeAtRuleKeywords;
var isHTMLTag = utils$6.isHTMLTag;
var isWideKeywords = utils$6.isWideKeywords;
var isSCSS = utils$6.isSCSS;
var isLastNode = utils$6.isLastNode;
var isSCSSControlDirectiveNode = utils$6.isSCSSControlDirectiveNode;
var isDetachedRulesetDeclarationNode = utils$6.isDetachedRulesetDeclarationNode;
var isRelationalOperatorNode = utils$6.isRelationalOperatorNode;
var isEqualityOperatorNode = utils$6.isEqualityOperatorNode;
var isMultiplicationNode = utils$6.isMultiplicationNode;
var isDivisionNode = utils$6.isDivisionNode;
var isAdditionNode = utils$6.isAdditionNode;
var isSubtractionNode = utils$6.isSubtractionNode;
var isMathOperatorNode = utils$6.isMathOperatorNode;
var isEachKeywordNode = utils$6.isEachKeywordNode;
var isForKeywordNode = utils$6.isForKeywordNode;
var isURLFunctionNode = utils$6.isURLFunctionNode;
var isIfElseKeywordNode = utils$6.isIfElseKeywordNode;
var hasComposesNode = utils$6.hasComposesNode;
var hasParensAroundNode = utils$6.hasParensAroundNode;
var hasEmptyRawBefore = utils$6.hasEmptyRawBefore;
var isKeyValuePairNode = utils$6.isKeyValuePairNode;
var isDetachedRulesetCallNode = utils$6.isDetachedRulesetCallNode;
var isTemplatePlaceholderNode = utils$6.isTemplatePlaceholderNode;
var isTemplatePropNode = utils$6.isTemplatePropNode;
var isPostcssSimpleVarNode = utils$6.isPostcssSimpleVarNode;
var isSCSSMapItemNode = utils$6.isSCSSMapItemNode;
var isInlineValueCommentNode = utils$6.isInlineValueCommentNode;
var isHashNode = utils$6.isHashNode;
var isLeftCurlyBraceNode = utils$6.isLeftCurlyBraceNode;
var isRightCurlyBraceNode = utils$6.isRightCurlyBraceNode;
var isWordNode = utils$6.isWordNode;
var isColonNode = utils$6.isColonNode;
var isMediaAndSupportsKeywords = utils$6.isMediaAndSupportsKeywords;
var isColorAdjusterFuncNode = utils$6.isColorAdjusterFuncNode;
function shouldPrintComma$1(options) {
switch (options.trailingComma) {
case "all":
case "es5":
return true;
case "none":
default:
return false;
}
}
function genericPrint$2(path$$1, options, print) {
var node = path$$1.getValue();
/* istanbul ignore if */
if (!node) {
return "";
}
if (typeof node === "string") {
return node;
}
switch (node.type) {
case "yaml":
case "toml":
return concat$8([node.raw, hardline$6]);
case "css-root":
{
var nodes = printNodeSequence(path$$1, options, print);
if (nodes.parts.length) {
return concat$8([nodes, hardline$6]);
}
return nodes;
}
case "css-comment":
{
if (node.raws.content) {
return node.raws.content;
}
var text = options.originalText.slice(options.locStart(node), options.locEnd(node));
var rawText = node.raws.text || node.text; // Workaround a bug where the location is off.
// https://github.com/postcss/postcss-scss/issues/63
if (text.indexOf(rawText) === -1) {
if (node.raws.inline) {
return concat$8(["// ", rawText]);
}
return concat$8(["/* ", rawText, " */"]);
}
return text;
}
case "css-rule":
{
return concat$8([path$$1.call(print, "selector"), node.important ? " !important" : "", node.nodes ? concat$8([" {", node.nodes.length > 0 ? indent$5(concat$8([hardline$6, printNodeSequence(path$$1, options, print)])) : "", hardline$6, "}", isDetachedRulesetDeclarationNode(node) ? ";" : ""]) : ";"]);
}
case "css-decl":
{
var parentNode = path$$1.getParentNode();
return concat$8([node.raws.before.replace(/[\s;]/g, ""), insideICSSRuleNode(path$$1) ? node.prop : maybeToLowerCase(node.prop), node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(), node.extend ? "" : " ", hasComposesNode(node) ? removeLines$2(path$$1.call(print, "value")) : path$$1.call(print, "value"), node.raws.important ? node.raws.important.replace(/\s*!\s*important/i, " !important") : node.important ? " !important" : "", node.raws.scssDefault ? node.raws.scssDefault.replace(/\s*!default/i, " !default") : node.scssDefault ? " !default" : "", node.raws.scssGlobal ? node.raws.scssGlobal.replace(/\s*!global/i, " !global") : node.scssGlobal ? " !global" : "", node.nodes ? concat$8([" {", indent$5(concat$8([softline$3, printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : isTemplatePropNode(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
}
case "css-atrule":
{
var _parentNode = path$$1.getParentNode();
return concat$8(["@", // If a Less file ends up being parsed with the SCSS parser, Less
// variable declarations will be parsed as at-rules with names ending
// with a colon, so keep the original case then.
isDetachedRulesetCallNode(node) || node.name.endsWith(":") ? node.name : maybeToLowerCase(node.name), node.params ? concat$8([isDetachedRulesetCallNode(node) ? "" : isTemplatePlaceholderNode(node) && /^\s*\n/.test(node.raws.afterName) ? /^\s*\n\s*\n/.test(node.raws.afterName) ? concat$8([hardline$6, hardline$6]) : hardline$6 : " ", path$$1.call(print, "params")]) : "", node.selector ? indent$5(concat$8([" ", path$$1.call(print, "selector")])) : "", node.value ? group$6(concat$8([" ", path$$1.call(print, "value"), isSCSSControlDirectiveNode(node) ? hasParensAroundNode(node) ? " " : line$5 : ""])) : node.name === "else" ? " " : "", node.nodes ? concat$8([isSCSSControlDirectiveNode(node) ? "" : " ", "{", indent$5(concat$8([node.nodes.length > 0 ? softline$3 : "", printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : isTemplatePlaceholderNode(node) && !_parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
}
// postcss-media-query-parser
case "media-query-list":
{
var parts = [];
path$$1.each(function (childPath) {
var node = childPath.getValue();
if (node.type === "media-query" && node.value === "") {
return;
}
parts.push(childPath.call(print));
}, "nodes");
return group$6(indent$5(join$6(line$5, parts)));
}
case "media-query":
{
return concat$8([join$6(" ", path$$1.map(print, "nodes")), isLastNode(path$$1, node) ? "" : ","]);
}
case "media-type":
{
return adjustNumbers(adjustStrings(node.value, options));
}
case "media-feature-expression":
{
if (!node.nodes) {
return node.value;
}
return concat$8(["(", concat$8(path$$1.map(print, "nodes")), ")"]);
}
case "media-feature":
{
return maybeToLowerCase(adjustStrings(node.value.replace(/ +/g, " "), options));
}
case "media-colon":
{
return concat$8([node.value, " "]);
}
case "media-value":
{
return adjustNumbers(adjustStrings(node.value, options));
}
case "media-keyword":
{
return adjustStrings(node.value, options);
}
case "media-url":
{
return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
}
case "media-unknown":
{
return node.value;
}
// postcss-selector-parser
case "selector-root":
{
return group$6(concat$8([insideAtRuleNode(path$$1, "custom-selector") ? concat$8([getAncestorNode(path$$1, "css-atrule").customSelector, line$5]) : "", join$6(concat$8([",", insideAtRuleNode(path$$1, ["extend", "custom-selector", "nest"]) ? line$5 : hardline$6]), path$$1.map(print, "nodes"))]));
}
case "selector-selector":
{
return group$6(indent$5(concat$8(path$$1.map(print, "nodes"))));
}
case "selector-comment":
{
return node.value;
}
case "selector-string":
{
return adjustStrings(node.value, options);
}
case "selector-tag":
{
var _parentNode2 = path$$1.getParentNode();
var index = _parentNode2 && _parentNode2.nodes.indexOf(node);
var prevNode = index && _parentNode2.nodes[index - 1];
return concat$8([node.namespace ? concat$8([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", prevNode.type === "selector-nesting" ? node.value : adjustNumbers(isHTMLTag(node.value) || isKeyframeAtRuleKeywords(path$$1, node.value) ? node.value.toLowerCase() : node.value)]);
}
case "selector-id":
{
return concat$8(["#", node.value]);
}
case "selector-class":
{
return concat$8([".", adjustNumbers(adjustStrings(node.value, options))]);
}
case "selector-attribute":
{
return concat$8(["[", node.namespace ? concat$8([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.attribute.trim(), node.operator ? node.operator : "", node.value ? quoteAttributeValue(adjustStrings(node.value.trim(), options), options) : "", node.insensitive ? " i" : "", "]"]);
}
case "selector-combinator":
{
if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
var _parentNode3 = path$$1.getParentNode();
var _leading = _parentNode3.type === "selector-selector" && _parentNode3.nodes[0] === node ? "" : line$5;
return concat$8([_leading, node.value, isLastNode(path$$1, node) ? "" : " "]);
}
var leading = node.value.trim().startsWith("(") ? line$5 : "";
var value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$5;
return concat$8([leading, value]);
}
case "selector-universal":
{
return concat$8([node.namespace ? concat$8([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.value]);
}
case "selector-pseudo":
{
return concat$8([maybeToLowerCase(node.value), node.nodes && node.nodes.length > 0 ? concat$8(["(", join$6(", ", path$$1.map(print, "nodes")), ")"]) : ""]);
}
case "selector-nesting":
{
return node.value;
}
case "selector-unknown":
{
var ruleAncestorNode = getAncestorNode(path$$1, "css-rule"); // Nested SCSS property
if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
return adjustNumbers(adjustStrings(maybeToLowerCase(node.value), options));
}
return node.value;
}
// postcss-values-parser
case "value-value":
case "value-root":
{
return path$$1.call(print, "group");
}
case "value-comment":
{
return concat$8([node.inline ? "//" : "/*", node.value, node.inline ? "" : "*/"]);
}
case "value-comma_group":
{
var _parentNode4 = path$$1.getParentNode();
var parentParentNode = path$$1.getParentNode(1);
var declAncestorProp = getPropOfDeclNode(path$$1);
var isGridValue = declAncestorProp && _parentNode4.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
var atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
var isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode(atRuleAncestorNode);
var printed = path$$1.map(print, "groups");
var _parts = [];
var insideURLFunction = insideValueFunctionNode(path$$1, "url");
var insideSCSSInterpolationInString = false;
var didBreak = false;
for (var i = 0; i < node.groups.length; ++i) {
_parts.push(printed[i]); // Ignore value inside `url()`
if (insideURLFunction) {
continue;
}
var iPrevNode = node.groups[i - 1];
var iNode = node.groups[i];
var iNextNode = node.groups[i + 1];
var iNextNextNode = node.groups[i + 2]; // Ignore after latest node (i.e. before semicolon)
if (!iNextNode) {
continue;
} // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
var isStartSCSSinterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
var isEndingSCSSinterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
if (isStartSCSSinterpolationInString || isEndingSCSSinterpolationInString) {
insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
continue;
}
if (insideSCSSInterpolationInString) {
continue;
} // Ignore colon (i.e. `:`)
if (isColonNode(iNode) || isColonNode(iNextNode)) {
continue;
} // Ignore `@` in Less (i.e. `@@var;`)
if (iNode.type === "value-atword" && iNode.value === "") {
continue;
} // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
if (iNode.value === "~") {
continue;
} // Ignore escape `\`
if (iNode.value && iNode.value.indexOf("\\") !== -1 && iNextNode && iNextNode.type !== "value-comment") {
continue;
} // Ignore escaped `/`
if (iPrevNode && iPrevNode.value && iPrevNode.value.indexOf("\\") === iPrevNode.value.length - 1 && iNode.type === "value-operator" && iNode.value === "/") {
continue;
} // Ignore `\` (i.e. `$variable: \@small;`)
if (iNode.value === "\\") {
continue;
} // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
if (isPostcssSimpleVarNode(iNode, iNextNode)) {
continue;
} // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
if (isHashNode(iNode) || isLeftCurlyBraceNode(iNode) || isRightCurlyBraceNode(iNextNode) || isLeftCurlyBraceNode(iNextNode) && hasEmptyRawBefore(iNextNode) || isRightCurlyBraceNode(iNode) && hasEmptyRawBefore(iNextNode)) {
continue;
} // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
if (iNode.value === "--" && isHashNode(iNextNode)) {
continue;
} // Formatting math operations
var isMathOperator = isMathOperatorNode(iNode);
var isNextMathOperator = isMathOperatorNode(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
// (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
// (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
if ((isMathOperator && isHashNode(iNextNode) || isNextMathOperator && isRightCurlyBraceNode(iNode)) && hasEmptyRawBefore(iNextNode)) {
continue;
} // Print spaces before and after addition and subtraction math operators as is in `calc` function
// due to the fact that it is not valid syntax
// (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
if (insideValueFunctionNode(path$$1, "calc") && (isAdditionNode(iNode) || isAdditionNode(iNextNode) || isSubtractionNode(iNode) || isSubtractionNode(iNextNode)) && hasEmptyRawBefore(iNextNode)) {
continue;
} // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
// Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
var isColorAdjusterNode = (isAdditionNode(iNode) || isSubtractionNode(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode(parentParentNode) && !hasEmptyRawBefore(iNextNode);
var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode(iNextNextNode) || iNode.type === "value-func" || isWordNode(iNode);
var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode(iPrevNode); // Formatting `/`, `+`, `-` sign
if (!(isMultiplicationNode(iNextNode) || isMultiplicationNode(iNode)) && !insideValueFunctionNode(path$$1, "calc") && !isColorAdjusterNode && (isDivisionNode(iNextNode) && !requireSpaceBeforeOperator || isDivisionNode(iNode) && !requireSpaceAfterOperator || isAdditionNode(iNextNode) && !requireSpaceBeforeOperator || isAdditionNode(iNode) && !requireSpaceAfterOperator || isSubtractionNode(iNextNode) || isSubtractionNode(iNode)) && (hasEmptyRawBefore(iNextNode) || isMathOperator && (!iPrevNode || iPrevNode && isMathOperatorNode(iPrevNode)))) {
continue;
} // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
if (isInlineValueCommentNode(iNode)) {
_parts.push(hardline$6);
continue;
} // Handle keywords in SCSS control directive
if (isControlDirective && (isEqualityOperatorNode(iNextNode) || isRelationalOperatorNode(iNextNode) || isIfElseKeywordNode(iNextNode) || isEachKeywordNode(iNode) || isForKeywordNode(iNode))) {
_parts.push(" ");
continue;
} // At-rule `namespace` should be in one line
if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
_parts.push(" ");
continue;
} // Formatting `grid` property
if (isGridValue) {
if (iNode.source && iNextNode.source && iNode.source.start.line !== iNextNode.source.start.line) {
_parts.push(hardline$6);
didBreak = true;
} else {
_parts.push(" ");
}
continue;
} // Add `space` before next math operation
// Note: `grip` property have `/` delimiter and it is not math operation, so
// `grid` property handles above
if (isNextMathOperator) {
_parts.push(" ");
continue;
} // Be default all values go through `line`
_parts.push(line$5);
}
if (didBreak) {
_parts.unshift(hardline$6);
}
if (isControlDirective) {
return group$6(indent$5(concat$8(_parts)));
} // Indent is not needed for import url when url is very long
// and node has two groups
// when type is value-comma_group
// example @import url("verylongurl") projection,tv
if (insideURLFunctionInImportAtRuleNode(path$$1)) {
return group$6(fill$3(_parts));
}
return group$6(indent$5(fill$3(_parts)));
}
case "value-paren_group":
{
var _parentNode5 = path$$1.getParentNode();
if (_parentNode5 && isURLFunctionNode(_parentNode5) && (node.groups.length === 1 || node.groups.length > 0 && node.groups[0].type === "value-comma_group" && node.groups[0].groups.length > 0 && node.groups[0].groups[0].type === "value-word" && node.groups[0].groups[0].value.startsWith("data:"))) {
return concat$8([node.open ? path$$1.call(print, "open") : "", join$6(",", path$$1.map(print, "groups")), node.close ? path$$1.call(print, "close") : ""]);
}
if (!node.open) {
var _printed = path$$1.map(print, "groups");
var res = [];
for (var _i = 0; _i < _printed.length; _i++) {
if (_i !== 0) {
res.push(concat$8([",", line$5]));
}
res.push(_printed[_i]);
}
return group$6(indent$5(fill$3(res)));
}
var isSCSSMapItem = isSCSSMapItemNode(path$$1);
return group$6(concat$8([node.open ? path$$1.call(print, "open") : "", indent$5(concat$8([softline$3, join$6(concat$8([",", line$5]), path$$1.map(function (childPath) {
var node = childPath.getValue();
var printed = print(childPath); // Key/Value pair in open paren already indented
if (isKeyValuePairNode(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
printed.contents.contents.parts[1] = group$6(printed.contents.contents.parts[1]);
return group$6(dedent$3(printed));
}
return printed;
}, "groups"))])), ifBreak$2(isSCSS(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma$1(options) ? "," : ""), softline$3, node.close ? path$$1.call(print, "close") : ""]), {
shouldBreak: isSCSSMapItem
});
}
case "value-func":
{
return concat$8([node.value, insideAtRuleNode(path$$1, "supports") && isMediaAndSupportsKeywords(node) ? " " : "", path$$1.call(print, "group")]);
}
case "value-paren":
{
return node.value;
}
case "value-number":
{
return concat$8([printCssNumber(node.value), maybeToLowerCase(node.unit)]);
}
case "value-operator":
{
return node.value;
}
case "value-word":
{
if (node.isColor && node.isHex || isWideKeywords(node.value)) {
return node.value.toLowerCase();
}
return node.value;
}
case "value-colon":
{
return concat$8([node.value, // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
insideValueFunctionNode(path$$1, "url") ? "" : line$5]);
}
case "value-comma":
{
return concat$8([node.value, " "]);
}
case "value-string":
{
return printString$2(node.raws.quote + node.value + node.raws.quote, options);
}
case "value-atword":
{
return concat$8(["@", node.value]);
}
case "value-unicode-range":
{
return node.value;
}
case "value-unknown":
{
return node.value;
}
default:
/* istanbul ignore next */
throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
}
}
function printNodeSequence(path$$1, options, print) {
var node = path$$1.getValue();
var parts = [];
var i = 0;
path$$1.map(function (pathChild) {
var prevNode = node.nodes[i - 1];
if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
var childNode = pathChild.getValue();
parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
} else {
parts.push(pathChild.call(print));
}
if (i !== node.nodes.length - 1) {
if (node.nodes[i + 1].type === "css-comment" && !hasNewline$3(options.originalText, options.locStart(node.nodes[i + 1]), {
backwards: true
}) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml" || node.nodes[i + 1].type === "css-atrule" && node.nodes[i + 1].name === "else" && node.nodes[i].type !== "css-comment") {
parts.push(" ");
} else {
parts.push(hardline$6);
if (isNextLineEmpty$3(options.originalText, pathChild.getValue(), options) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml") {
parts.push(hardline$6);
}
}
}
i++;
}, "nodes");
return concat$8(parts);
}
var STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
var NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
var STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
var WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
var ADJUST_NUMBERS_REGEX = RegExp(STRING_REGEX.source + `|` + `(${WORD_PART_REGEX.source})?` + `(${NUMBER_REGEX.source})` + `(${STANDARD_UNIT_REGEX.source})?`, "g");
function adjustStrings(value, options) {
return value.replace(STRING_REGEX, function (match) {
return printString$2(match, options);
});
}
function quoteAttributeValue(value, options) {
var quote = options.singleQuote ? "'" : '"';
return value.includes('"') || value.includes("'") ? value : quote + value + quote;
}
function adjustNumbers(value) {
return value.replace(ADJUST_NUMBERS_REGEX, function (match, quote, wordPart, number, unit) {
return !wordPart && number ? (wordPart || "") + printCssNumber(number) + maybeToLowerCase(unit || "") : match;
});
}
function printCssNumber(rawNumber) {
return printNumber$2(rawNumber) // Remove trailing `.0`.
.replace(/\.0(?=$|e)/, "");
}
var printerPostcss = {
print: genericPrint$2,
embed: embed_1$2,
insertPragma: insertPragma$2,
hasPrettierIgnore: hasIgnoreComment$2,
massageAstNode: clean_1$2
};
var options$6 = {
singleQuote: commonOptions.singleQuote
};
var name$7 = "CSS";
var type$6 = "markup";
var tmScope$6 = "source.css";
var aceMode$6 = "css";
var codemirrorMode$6 = "css";
var codemirrorMimeType$6 = "text/css";
var color$2 = "#563d7c";
var extensions$6 = [".css"];
var languageId$6 = 50;
var css$2 = {
name: name$7,
type: type$6,
tmScope: tmScope$6,
aceMode: aceMode$6,
codemirrorMode: codemirrorMode$6,
codemirrorMimeType: codemirrorMimeType$6,
color: color$2,
extensions: extensions$6,
languageId: languageId$6
};
var css$3 = Object.freeze({
name: name$7,
type: type$6,
tmScope: tmScope$6,
aceMode: aceMode$6,
codemirrorMode: codemirrorMode$6,
codemirrorMimeType: codemirrorMimeType$6,
color: color$2,
extensions: extensions$6,
languageId: languageId$6,
default: css$2
});
var name$8 = "PostCSS";
var type$7 = "markup";
var tmScope$7 = "source.postcss";
var group$7 = "CSS";
var extensions$7 = [".pcss"];
var aceMode$7 = "text";
var languageId$7 = 262764437;
var postcss = {
name: name$8,
type: type$7,
tmScope: tmScope$7,
group: group$7,
extensions: extensions$7,
aceMode: aceMode$7,
languageId: languageId$7
};
var postcss$1 = Object.freeze({
name: name$8,
type: type$7,
tmScope: tmScope$7,
group: group$7,
extensions: extensions$7,
aceMode: aceMode$7,
languageId: languageId$7,
default: postcss
});
var name$9 = "Less";
var type$8 = "markup";
var group$8 = "CSS";
var extensions$8 = [".less"];
var tmScope$8 = "source.css.less";
var aceMode$8 = "less";
var codemirrorMode$7 = "css";
var codemirrorMimeType$7 = "text/css";
var languageId$8 = 198;
var less = {
name: name$9,
type: type$8,
group: group$8,
extensions: extensions$8,
tmScope: tmScope$8,
aceMode: aceMode$8,
codemirrorMode: codemirrorMode$7,
codemirrorMimeType: codemirrorMimeType$7,
languageId: languageId$8
};
var less$1 = Object.freeze({
name: name$9,
type: type$8,
group: group$8,
extensions: extensions$8,
tmScope: tmScope$8,
aceMode: aceMode$8,
codemirrorMode: codemirrorMode$7,
codemirrorMimeType: codemirrorMimeType$7,
languageId: languageId$8,
default: less
});
var name$10 = "SCSS";
var type$9 = "markup";
var tmScope$9 = "source.scss";
var group$9 = "CSS";
var aceMode$9 = "scss";
var codemirrorMode$8 = "css";
var codemirrorMimeType$8 = "text/x-scss";
var extensions$9 = [".scss"];
var languageId$9 = 329;
var scss = {
name: name$10,
type: type$9,
tmScope: tmScope$9,
group: group$9,
aceMode: aceMode$9,
codemirrorMode: codemirrorMode$8,
codemirrorMimeType: codemirrorMimeType$8,
extensions: extensions$9,
languageId: languageId$9
};
var scss$1 = Object.freeze({
name: name$10,
type: type$9,
tmScope: tmScope$9,
group: group$9,
aceMode: aceMode$9,
codemirrorMode: codemirrorMode$8,
codemirrorMimeType: codemirrorMimeType$8,
extensions: extensions$9,
languageId: languageId$9,
default: scss
});
var require$$0$23 = ( css$3 && css$2 ) || css$3;
var require$$1$9 = ( postcss$1 && postcss ) || postcss$1;
var require$$2$11 = ( less$1 && less ) || less$1;
var require$$3$4 = ( scss$1 && scss ) || scss$1;
var languages$1 = [createLanguage(require$$0$23, {
override: {
since: "1.4.0",
parsers: ["css"],
vscodeLanguageIds: ["css"]
}
}), createLanguage(require$$1$9, {
override: {
since: "1.4.0",
parsers: ["css"],
vscodeLanguageIds: ["postcss"]
},
extend: {
extensions: [".postcss"]
}
}), createLanguage(require$$2$11, {
override: {
since: "1.4.0",
parsers: ["less"],
vscodeLanguageIds: ["less"]
}
}), createLanguage(require$$3$4, {
override: {
since: "1.4.0",
parsers: ["scss"],
vscodeLanguageIds: ["scss"]
}
})];
var printers$1 = {
postcss: printerPostcss
};
var languageCss = {
languages: languages$1,
options: options$6,
printers: printers$1
};
var _require$$0$builders$4 = doc.builders;
var concat$10 = _require$$0$builders$4.concat;
var join$7 = _require$$0$builders$4.join;
var softline$4 = _require$$0$builders$4.softline;
var hardline$8 = _require$$0$builders$4.hardline;
var line$6 = _require$$0$builders$4.line;
var group$10 = _require$$0$builders$4.group;
var indent$6 = _require$$0$builders$4.indent;
var ifBreak$3 = _require$$0$builders$4.ifBreak; // http://w3c.github.io/html/single-page.html#void-elements
var voidTags = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]; // Formatter based on @glimmerjs/syntax's built-in test formatter:
// https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
function print(path$$1, options, print) {
var n = path$$1.getValue();
/* istanbul ignore if*/
if (!n) {
return "";
}
switch (n.type) {
case "Program":
{
return group$10(join$7(softline$4, path$$1.map(print, "body").filter(function (text) {
return text !== "";
})));
}
case "ElementNode":
{
var tagFirstChar = n.tag[0];
var isLocal = n.tag.indexOf(".") !== -1;
var isGlimmerComponent = tagFirstChar.toUpperCase() === tagFirstChar || isLocal;
var hasChildren = n.children.length > 0;
var isVoid = isGlimmerComponent && !hasChildren || voidTags.indexOf(n.tag) !== -1;
var closeTag = isVoid ? concat$10([" />", softline$4]) : ">";
var _getParams = function _getParams(path$$1, print) {
return indent$6(concat$10([n.attributes.length ? line$6 : "", join$7(line$6, path$$1.map(print, "attributes")), n.modifiers.length ? line$6 : "", join$7(line$6, path$$1.map(print, "modifiers")), n.comments.length ? line$6 : "", join$7(line$6, path$$1.map(print, "comments"))]));
}; // The problem here is that I want to not break at all if the children
// would not break but I need to force an indent, so I use a hardline.
/**
* What happens now:
*
* Hello
*
* ==>
*
Hello
* This is due to me using hasChildren to decide to put the hardline in.
* I would rather use a {DOES THE WHOLE THING NEED TO BREAK}
*/
return concat$10([group$10(concat$10(["<", n.tag, _getParams(path$$1, print), n.blockParams.length ? ` as |${n.blockParams.join(" ")}|` : "", ifBreak$3(softline$4, ""), closeTag])), group$10(concat$10([indent$6(join$7(softline$4, [""].concat(path$$1.map(print, "children")))), ifBreak$3(hasChildren ? hardline$8 : "", ""), !isVoid ? concat$10(["", n.tag, ">"]) : ""]))]);
}
case "BlockStatement":
{
var pp = path$$1.getParentNode(1);
var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
var hasElseIf = n.inverse && n.inverse.body[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
var indentElse = hasElseIf ? function (a) {
return a;
} : indent$6;
if (n.inverse) {
return concat$10([isElseIf ? concat$10(["{{else ", printPathParams(path$$1, print), "}}"]) : printOpenBlock(path$$1, print), indent$6(concat$10([hardline$8, path$$1.call(print, "program")])), n.inverse && !hasElseIf ? concat$10([hardline$8, "{{else}}"]) : "", n.inverse ? indentElse(concat$10([hardline$8, path$$1.call(print, "inverse")])) : "", isElseIf ? "" : concat$10([hardline$8, printCloseBlock(path$$1, print)])]);
} else if (isElseIf) {
return concat$10([concat$10(["{{else ", printPathParams(path$$1, print), "}}"]), indent$6(concat$10([hardline$8, path$$1.call(print, "program")]))]);
}
/**
* I want this boolean to be: if params are going to cause a break,
* not that it has params.
*/
var hasParams = n.params.length > 0 || n.hash.pairs.length > 0;
var _hasChildren = n.program.body.length > 0;
return concat$10([printOpenBlock(path$$1, print), group$10(concat$10([indent$6(concat$10([softline$4, path$$1.call(print, "program")])), hasParams && _hasChildren ? hardline$8 : softline$4, printCloseBlock(path$$1, print)]))]);
}
case "ElementModifierStatement":
case "MustacheStatement":
{
var _pp = path$$1.getParentNode(1);
var isConcat = _pp && _pp.type === "ConcatStatement";
return group$10(concat$10([n.escaped === false ? "{{{" : "{{", printPathParams(path$$1, print), isConcat ? "" : softline$4, n.escaped === false ? "}}}" : "}}"]));
}
case "SubExpression":
{
var params = getParams(path$$1, print);
var printedParams = params.length > 0 ? indent$6(concat$10([line$6, group$10(join$7(line$6, params))])) : "";
return group$10(concat$10(["(", printPath(path$$1, print), printedParams, softline$4, ")"]));
}
case "AttrNode":
{
var isText = n.value.type === "TextNode";
if (isText && n.value.loc.start.column === n.value.loc.end.column) {
return concat$10([n.name]);
}
var quote = isText ? '"' : "";
return concat$10([n.name, "=", quote, path$$1.call(print, "value"), quote]);
}
case "ConcatStatement":
{
return concat$10(['"', group$10(indent$6(join$7(softline$4, path$$1.map(function (partPath) {
return print(partPath);
}, "parts").filter(function (a) {
return a !== "";
})))), '"']);
}
case "Hash":
{
return concat$10([join$7(line$6, path$$1.map(print, "pairs"))]);
}
case "HashPair":
{
return concat$10([n.key, "=", path$$1.call(print, "value")]);
}
case "TextNode":
{
var leadingSpace = "";
var trailingSpace = ""; // preserve a space inside of an attribute node where whitespace present, when next to mustache statement.
var inAttrNode = path$$1.stack.indexOf("attributes") >= 0;
if (inAttrNode) {
var parentNode = path$$1.getParentNode(0);
var _isConcat = parentNode.type === "ConcatStatement";
if (_isConcat) {
var parts = parentNode.parts;
var partIndex = parts.indexOf(n);
if (partIndex > 0) {
var partType = parts[partIndex - 1].type;
var isMustache = partType === "MustacheStatement";
if (isMustache) {
leadingSpace = " ";
}
}
if (partIndex < parts.length - 1) {
var _partType = parts[partIndex + 1].type;
var _isMustache = _partType === "MustacheStatement";
if (_isMustache) {
trailingSpace = " ";
}
}
}
}
return n.chars.replace(/^\s+/, leadingSpace).replace(/\s+$/, trailingSpace);
}
case "MustacheCommentStatement":
{
var dashes = n.value.indexOf("}}") > -1 ? "--" : "";
return concat$10(["{{!", dashes, n.value, dashes, "}}"]);
}
case "PathExpression":
{
return n.original;
}
case "BooleanLiteral":
{
return String(n.value);
}
case "CommentStatement":
{
return concat$10([""]);
}
case "StringLiteral":
{
return printStringLiteral(n.value, options);
}
case "NumberLiteral":
{
return String(n.value);
}
case "UndefinedLiteral":
{
return "undefined";
}
case "NullLiteral":
{
return "null";
}
/* istanbul ignore next */
default:
throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
}
}
/**
* Prints a string literal with the correct surrounding quotes based on
* `options.singleQuote` and the number of escaped quotes contained in
* the string literal. This function is the glimmer equivalent of `printString`
* in `common/util`, but has differences because of the way escaped characters
* are treated in hbs string literals.
* @param {string} stringLiteral - the string literal value
* @param {object} options - the prettier options object
*/
function printStringLiteral(stringLiteral, options) {
var double = {
quote: '"',
regex: /"/g
};
var single = {
quote: "'",
regex: /'/g
};
var preferred = options.singleQuote ? single : double;
var alternate = preferred === single ? double : single;
var shouldUseAlternateQuote = false; // If `stringLiteral` contains at least one of the quote preferred for
// enclosing the string, we might want to enclose with the alternate quote
// instead, to minimize the number of escaped quotes.
if (stringLiteral.includes(preferred.quote) || stringLiteral.includes(alternate.quote)) {
var numPreferredQuotes = (stringLiteral.match(preferred.regex) || []).length;
var numAlternateQuotes = (stringLiteral.match(alternate.regex) || []).length;
shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
}
var enclosingQuote = shouldUseAlternateQuote ? alternate : preferred;
var escapedStringLiteral = stringLiteral.replace(enclosingQuote.regex, `\\${enclosingQuote.quote}`);
return `${enclosingQuote.quote}${escapedStringLiteral}${enclosingQuote.quote}`;
}
function printPath(path$$1, print) {
return path$$1.call(print, "path");
}
function getParams(path$$1, print) {
var node = path$$1.getValue();
var parts = [];
if (node.params.length > 0) {
parts = parts.concat(path$$1.map(print, "params"));
}
if (node.hash && node.hash.pairs.length > 0) {
parts.push(path$$1.call(print, "hash"));
}
return parts;
}
function printPathParams(path$$1, print) {
var parts = [];
parts.push(printPath(path$$1, print));
parts = parts.concat(getParams(path$$1, print));
return indent$6(group$10(join$7(line$6, parts)));
}
function printBlockParams(path$$1) {
var block = path$$1.getValue();
if (!block.program || !block.program.blockParams.length) {
return "";
}
return concat$10([" as |", block.program.blockParams.join(" "), "|"]);
}
function printOpenBlock(path$$1, print) {
return group$10(concat$10(["{{#", printPathParams(path$$1, print), printBlockParams(path$$1), softline$4, "}}"]));
}
function printCloseBlock(path$$1, print) {
return concat$10(["{{/", path$$1.call(print, "path"), "}}"]);
}
function clean$5(ast, newObj) {
delete newObj.loc; // (Glimmer/HTML) ignore TextNode whitespace
if (ast.type === "TextNode") {
if (ast.chars.replace(/\s+/, "") === "") {
return null;
}
newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
}
}
var printerGlimmer = {
print,
massageAstNode: clean$5
};
var name$11 = "Handlebars";
var type$10 = "markup";
var group$11 = "HTML";
var aliases$3 = ["hbs", "htmlbars"];
var extensions$10 = [".handlebars", ".hbs"];
var tmScope$10 = "text.html.handlebars";
var aceMode$10 = "handlebars";
var languageId$10 = 155;
var handlebars = {
name: name$11,
type: type$10,
group: group$11,
aliases: aliases$3,
extensions: extensions$10,
tmScope: tmScope$10,
aceMode: aceMode$10,
languageId: languageId$10
};
var handlebars$1 = Object.freeze({
name: name$11,
type: type$10,
group: group$11,
aliases: aliases$3,
extensions: extensions$10,
tmScope: tmScope$10,
aceMode: aceMode$10,
languageId: languageId$10,
default: handlebars
});
var require$$0$24 = ( handlebars$1 && handlebars ) || handlebars$1;
var languages$2 = [createLanguage(require$$0$24, {
override: {
since: null,
// unreleased
parsers: ["glimmer"],
vscodeLanguageIds: ["handlebars"]
}
})];
var printers$2 = {
glimmer: printerGlimmer
};
var languageHandlebars = {
languages: languages$2,
printers: printers$2
};
function hasPragma$2(text) {
return /^\s*#[^\n\S]*@(format|prettier)\s*(\n|$)/.test(text);
}
function insertPragma$5(text) {
return "# @format\n\n" + text;
}
var pragma$4 = {
hasPragma: hasPragma$2,
insertPragma: insertPragma$5
};
var _require$$0$builders$5 = doc.builders;
var concat$11 = _require$$0$builders$5.concat;
var join$8 = _require$$0$builders$5.join;
var hardline$9 = _require$$0$builders$5.hardline;
var line$7 = _require$$0$builders$5.line;
var softline$5 = _require$$0$builders$5.softline;
var group$12 = _require$$0$builders$5.group;
var indent$7 = _require$$0$builders$5.indent;
var ifBreak$4 = _require$$0$builders$5.ifBreak;
var hasIgnoreComment$3 = util$1.hasIgnoreComment;
var isNextLineEmpty$4 = utilShared.isNextLineEmpty;
var insertPragma$4 = pragma$4.insertPragma;
function genericPrint$3(path$$1, options, print) {
var n = path$$1.getValue();
if (!n) {
return "";
}
if (typeof n === "string") {
return n;
}
switch (n.kind) {
case "Document":
{
var parts = [];
path$$1.map(function (pathChild, index) {
parts.push(concat$11([pathChild.call(print)]));
if (index !== n.definitions.length - 1) {
parts.push(hardline$9);
if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
parts.push(hardline$9);
}
}
}, "definitions");
return concat$11([concat$11(parts), hardline$9]);
}
case "OperationDefinition":
{
var hasOperation = options.originalText[options.locStart(n)] !== "{";
var hasName = !!n.name;
return concat$11([hasOperation ? n.operation : "", hasOperation && hasName ? concat$11([" ", path$$1.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "variableDefinitions"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? !hasOperation && !hasName ? "" : " " : "", path$$1.call(print, "selectionSet")]);
}
case "FragmentDefinition":
{
return concat$11(["fragment ", path$$1.call(print, "name"), " on ", path$$1.call(print, "typeCondition"), printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
}
case "SelectionSet":
{
return concat$11(["{", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (selectionsPath) {
return printSequence(selectionsPath, options, print);
}, "selections"))])), hardline$9, "}"]);
}
case "Field":
{
return group$12(concat$11([n.alias ? concat$11([path$$1.call(print, "alias"), ": "]) : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
return printSequence(argsPath, options, print);
}, "arguments"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? " " : "", path$$1.call(print, "selectionSet")]));
}
case "Name":
{
return n.value;
}
case "StringValue":
{
if (n.block) {
return concat$11(['"""', hardline$9, join$8(hardline$9, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$9, '"""']);
}
return concat$11(['"', n.value.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\n"), '"']);
}
case "IntValue":
case "FloatValue":
case "EnumValue":
{
return n.value;
}
case "BooleanValue":
{
return n.value ? "true" : "false";
}
case "NullValue":
{
return "null";
}
case "Variable":
{
return concat$11(["$", path$$1.call(print, "name")]);
}
case "ListValue":
{
return group$12(concat$11(["[", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "values"))])), softline$5, "]"]));
}
case "ObjectValue":
{
return group$12(concat$11(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "fields"))])), softline$5, ifBreak$4("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"]));
}
case "ObjectField":
case "Argument":
{
return concat$11([path$$1.call(print, "name"), ": ", path$$1.call(print, "value")]);
}
case "Directive":
{
return concat$11(["@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
return printSequence(argsPath, options, print);
}, "arguments"))])), softline$5, ")"])) : ""]);
}
case "NamedType":
{
return path$$1.call(print, "name");
}
case "VariableDefinition":
{
return concat$11([path$$1.call(print, "variable"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$11([" = ", path$$1.call(print, "defaultValue")]) : ""]);
}
case "TypeExtensionDefinition":
{
return concat$11(["extend ", path$$1.call(print, "definition")]);
}
case "ObjectTypeExtension":
case "ObjectTypeDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path$$1.call(print, "name"), n.interfaces.length > 0 ? concat$11([" implements ", join$8(determineInterfaceSeparator(options.originalText.substr(options.locStart(n), options.locEnd(n))), path$$1.map(print, "interfaces"))]) : "", printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (fieldsPath) {
return printSequence(fieldsPath, options, print);
}, "fields"))])), hardline$9, "}"]) : ""]);
}
case "FieldDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
return printSequence(argsPath, options, print);
}, "arguments"))])), softline$5, ")"])) : "", ": ", path$$1.call(print, "type"), printDirectives(path$$1, print, n)]);
}
case "DirectiveDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", "directive ", "@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
return printSequence(argsPath, options, print);
}, "arguments"))])), softline$5, ")"])) : "", concat$11([" on ", join$8(" | ", path$$1.map(print, "locations"))])]);
}
case "EnumTypeExtension":
case "EnumTypeDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.values.length > 0 ? concat$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (valuesPath) {
return printSequence(valuesPath, options, print);
}, "values"))])), hardline$9, "}"]) : ""]);
}
case "EnumValueDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
}
case "InputValueDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? n.description.block ? hardline$9 : line$7 : "", path$$1.call(print, "name"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$11([" = ", path$$1.call(print, "defaultValue")]) : "", printDirectives(path$$1, print, n)]);
}
case "InputObjectTypeExtension":
case "InputObjectTypeDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (fieldsPath) {
return printSequence(fieldsPath, options, print);
}, "fields"))])), hardline$9, "}"]) : ""]);
}
case "SchemaDefinition":
{
return concat$11(["schema", printDirectives(path$$1, print, n), " {", n.operationTypes.length > 0 ? indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (opsPath) {
return printSequence(opsPath, options, print);
}, "operationTypes"))])) : "", hardline$9, "}"]);
}
case "OperationTypeDefinition":
{
return concat$11([path$$1.call(print, "operation"), ": ", path$$1.call(print, "type")]);
}
case "InterfaceTypeExtension":
case "InterfaceTypeDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (fieldsPath) {
return printSequence(fieldsPath, options, print);
}, "fields"))])), hardline$9, "}"]) : ""]);
}
case "FragmentSpread":
{
return concat$11(["...", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
}
case "InlineFragment":
{
return concat$11(["...", n.typeCondition ? concat$11([" on ", path$$1.call(print, "typeCondition")]) : "", printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
}
case "UnionTypeExtension":
case "UnionTypeDefinition":
{
return group$12(concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", group$12(concat$11([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.types.length > 0 ? concat$11([" =", ifBreak$4("", " "), indent$7(concat$11([ifBreak$4(concat$11([line$7, " "])), join$8(concat$11([line$7, "| "]), path$$1.map(print, "types"))]))]) : ""]))]));
}
case "ScalarTypeExtension":
case "ScalarTypeDefinition":
{
return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
}
case "NonNullType":
{
return concat$11([path$$1.call(print, "type"), "!"]);
}
case "ListType":
{
return concat$11(["[", path$$1.call(print, "type"), "]"]);
}
default:
/* istanbul ignore next */
throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
}
}
function printDirectives(path$$1, print, n) {
if (n.directives.length === 0) {
return "";
}
return concat$11([" ", group$12(indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", " "), softline$5]), path$$1.map(print, "directives"))])))]);
}
function printSequence(sequencePath, options, print) {
var count = sequencePath.getValue().length;
return sequencePath.map(function (path$$1, i) {
var printed = print(path$$1);
if (isNextLineEmpty$4(options.originalText, path$$1.getValue(), options) && i < count - 1) {
return concat$11([printed, hardline$9]);
}
return printed;
});
}
function canAttachComment$1(node) {
return node.kind && node.kind !== "Comment";
}
function printComment$2(commentPath) {
var comment = commentPath.getValue();
if (comment.kind === "Comment") {
return "#" + comment.value.trimRight();
}
throw new Error("Not a comment: " + JSON.stringify(comment));
}
function determineInterfaceSeparator(originalSource) {
var start = originalSource.indexOf("implements");
if (start === -1) {
throw new Error("Must implement interfaces: " + originalSource);
}
var end = originalSource.indexOf("{");
if (end === -1) {
end = originalSource.length;
}
return originalSource.substr(start, end).includes("&") ? " & " : ", ";
}
function clean$6(node, newNode
/*, parent*/
) {
delete newNode.loc;
delete newNode.comments;
}
var printerGraphql = {
print: genericPrint$3,
massageAstNode: clean$6,
hasPrettierIgnore: hasIgnoreComment$3,
insertPragma: insertPragma$4,
printComment: printComment$2,
canAttachComment: canAttachComment$1
};
var options$9 = {
bracketSpacing: commonOptions.bracketSpacing
};
var name$12 = "GraphQL";
var type$11 = "data";
var extensions$11 = [".graphql", ".gql"];
var tmScope$11 = "source.graphql";
var aceMode$11 = "text";
var languageId$11 = 139;
var graphql = {
name: name$12,
type: type$11,
extensions: extensions$11,
tmScope: tmScope$11,
aceMode: aceMode$11,
languageId: languageId$11
};
var graphql$1 = Object.freeze({
name: name$12,
type: type$11,
extensions: extensions$11,
tmScope: tmScope$11,
aceMode: aceMode$11,
languageId: languageId$11,
default: graphql
});
var require$$0$25 = ( graphql$1 && graphql ) || graphql$1;
var languages$3 = [createLanguage(require$$0$25, {
override: {
since: "1.5.0",
parsers: ["graphql"],
vscodeLanguageIds: ["graphql"]
}
})];
var printers$3 = {
graphql: printerGraphql
};
var languageGraphql = {
languages: languages$3,
options: options$9,
printers: printers$3
};
var json$6 = {"cjkPattern":"[\\u02ea-\\u02eb\\u1100-\\u11ff\\u2e80-\\u2e99\\u2e9b-\\u2ef3\\u2f00-\\u2fd5\\u3000-\\u303f\\u3041-\\u3096\\u3099-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312e\\u3131-\\u318e\\u3190-\\u3191\\u3196-\\u31ba\\u31c0-\\u31e3\\u31f0-\\u321e\\u322a-\\u3247\\u3260-\\u327e\\u328a-\\u32b0\\u32c0-\\u32cb\\u32d0-\\u32fe\\u3300-\\u3370\\u337b-\\u337f\\u33e0-\\u33fe\\u3400-\\u4db5\\u4e00-\\u9fea\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufe10-\\ufe1f\\ufe30-\\ufe6f\\uff00-\\uffef]|[\\ud840-\\ud868\\ud86a-\\ud86c\\ud86f-\\ud872\\ud874-\\ud879][\\udc00-\\udfff]|\\ud82c[\\udc00-\\udd1e]|\\ud83c[\\ude00\\ude50-\\ude51]|\\ud869[\\udc00-\\uded6\\udf00-\\udfff]|\\ud86d[\\udc00-\\udf34\\udf40-\\udfff]|\\ud86e[\\udc00-\\udc1d\\udc20-\\udfff]|\\ud873[\\udc00-\\udea1\\udeb0-\\udfff]|\\ud87a[\\udc00-\\udfe0]|\\ud87e[\\udc00-\\ude1d]","kPattern":"[\\u1100-\\u11ff\\u3001-\\u3003\\u3008-\\u3011\\u3013-\\u301f\\u302e-\\u3030\\u3037\\u30fb\\u3131-\\u318e\\u3200-\\u321e\\u3260-\\u327e\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\ufe45-\\ufe46\\uff61-\\uff65\\uffa0-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc]","punctuationPattern":"[\\u0021-\\u002f\\u003a-\\u0040\\u005b-\\u0060\\u007b-\\u007e\\u00a1\\u00a7\\u00ab\\u00b6-\\u00b7\\u00bb\\u00bf\\u037e\\u0387\\u055a-\\u055f\\u0589-\\u058a\\u05be\\u05c0\\u05c3\\u05c6\\u05f3-\\u05f4\\u0609-\\u060a\\u060c-\\u060d\\u061b\\u061e-\\u061f\\u066a-\\u066d\\u06d4\\u0700-\\u070d\\u07f7-\\u07f9\\u0830-\\u083e\\u085e\\u0964-\\u0965\\u0970\\u09fd\\u0af0\\u0df4\\u0e4f\\u0e5a-\\u0e5b\\u0f04-\\u0f12\\u0f14\\u0f3a-\\u0f3d\\u0f85\\u0fd0-\\u0fd4\\u0fd9-\\u0fda\\u104a-\\u104f\\u10fb\\u1360-\\u1368\\u1400\\u166d-\\u166e\\u169b-\\u169c\\u16eb-\\u16ed\\u1735-\\u1736\\u17d4-\\u17d6\\u17d8-\\u17da\\u1800-\\u180a\\u1944-\\u1945\\u1a1e-\\u1a1f\\u1aa0-\\u1aa6\\u1aa8-\\u1aad\\u1b5a-\\u1b60\\u1bfc-\\u1bff\\u1c3b-\\u1c3f\\u1c7e-\\u1c7f\\u1cc0-\\u1cc7\\u1cd3\\u2010-\\u2027\\u2030-\\u2043\\u2045-\\u2051\\u2053-\\u205e\\u207d-\\u207e\\u208d-\\u208e\\u2308-\\u230b\\u2329-\\u232a\\u2768-\\u2775\\u27c5-\\u27c6\\u27e6-\\u27ef\\u2983-\\u2998\\u29d8-\\u29db\\u29fc-\\u29fd\\u2cf9-\\u2cfc\\u2cfe-\\u2cff\\u2d70\\u2e00-\\u2e2e\\u2e30-\\u2e49\\u3001-\\u3003\\u3008-\\u3011\\u3014-\\u301f\\u3030\\u303d\\u30a0\\u30fb\\ua4fe-\\ua4ff\\ua60d-\\ua60f\\ua673\\ua67e\\ua6f2-\\ua6f7\\ua874-\\ua877\\ua8ce-\\ua8cf\\ua8f8-\\ua8fa\\ua8fc\\ua92e-\\ua92f\\ua95f\\ua9c1-\\ua9cd\\ua9de-\\ua9df\\uaa5c-\\uaa5f\\uaade-\\uaadf\\uaaf0-\\uaaf1\\uabeb\\ufd3e-\\ufd3f\\ufe10-\\ufe19\\ufe30-\\ufe52\\ufe54-\\ufe61\\ufe63\\ufe68\\ufe6a-\\ufe6b\\uff01-\\uff03\\uff05-\\uff0a\\uff0c-\\uff0f\\uff1a-\\uff1b\\uff1f-\\uff20\\uff3b-\\uff3d\\uff3f\\uff5b\\uff5d\\uff5f-\\uff65]|\\ud800[\\udd00-\\udd02\\udf9f\\udfd0]|\\ud801[\\udd6f]|\\ud802[\\udc57\\udd1f\\udd3f\\ude50-\\ude58\\ude7f\\udef0-\\udef6\\udf39-\\udf3f\\udf99-\\udf9c]|\\ud804[\\udc47-\\udc4d\\udcbb-\\udcbc\\udcbe-\\udcc1\\udd40-\\udd43\\udd74-\\udd75\\uddc5-\\uddc9\\uddcd\\udddb\\udddd-\\udddf\\ude38-\\ude3d\\udea9]|\\ud805[\\udc4b-\\udc4f\\udc5b\\udc5d\\udcc6\\uddc1-\\uddd7\\ude41-\\ude43\\ude60-\\ude6c\\udf3c-\\udf3e]|\\ud806[\\ude3f-\\ude46\\ude9a-\\ude9c\\ude9e-\\udea2]|\\ud807[\\udc41-\\udc45\\udc70-\\udc71]|\\ud809[\\udc70-\\udc74]|\\ud81a[\\ude6e-\\ude6f\\udef5\\udf37-\\udf3b\\udf44]|\\ud82f[\\udc9f]|\\ud836[\\ude87-\\ude8b]|\\ud83a[\\udd5e-\\udd5f]"};
var cjkPattern = json$6.cjkPattern;
var kPattern = json$6.kPattern;
var punctuationPattern$1 = json$6.punctuationPattern;
var getLast$5 = util$1.getLast;
var INLINE_NODE_TYPES$1 = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
var INLINE_NODE_WRAPPER_TYPES$1 = INLINE_NODE_TYPES$1.concat(["tableCell", "paragraph", "heading"]);
var kRegex = new RegExp(kPattern);
var punctuationRegex = new RegExp(punctuationPattern$1);
/**
* split text into whitespaces and words
* @param {string} text
* @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
*/
function splitText$1(text, options) {
var KIND_NON_CJK = "non-cjk";
var KIND_CJ_LETTER = "cj-letter";
var KIND_K_LETTER = "k-letter";
var KIND_CJK_PUNCTUATION = "cjk-punctuation";
var nodes = [];
(options.proseWrap === "preserve" ? text : text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")).split(/([ \t\n]+)/).forEach(function (token, index, tokens) {
// whitespace
if (index % 2 === 1) {
nodes.push({
type: "whitespace",
value: /\n/.test(token) ? "\n" : " "
});
return;
} // word separated by whitespace
if ((index === 0 || index === tokens.length - 1) && token === "") {
return;
}
token.split(new RegExp(`(${cjkPattern})`)).forEach(function (innerToken, innerIndex, innerTokens) {
if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
return;
} // non-CJK word
if (innerIndex % 2 === 0) {
if (innerToken !== "") {
appendNode({
type: "word",
value: innerToken,
kind: KIND_NON_CJK,
hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
hasTrailingPunctuation: punctuationRegex.test(getLast$5(innerToken))
});
}
return;
} // CJK character
appendNode(punctuationRegex.test(innerToken) ? {
type: "word",
value: innerToken,
kind: KIND_CJK_PUNCTUATION,
hasLeadingPunctuation: true,
hasTrailingPunctuation: true
} : {
type: "word",
value: innerToken,
kind: kRegex.test(innerToken) ? KIND_K_LETTER : KIND_CJ_LETTER,
hasLeadingPunctuation: false,
hasTrailingPunctuation: false
});
});
});
return nodes;
function appendNode(node) {
var lastNode = getLast$5(nodes);
if (lastNode && lastNode.type === "word") {
if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJ_LETTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJ_LETTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) {
nodes.push({
type: "whitespace",
value: " "
});
} else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
![lastNode.value, node.value].some(function (value) {
return /\u3000/.test(value);
})) {
nodes.push({
type: "whitespace",
value: ""
});
}
}
nodes.push(node);
function isBetween(kind1, kind2) {
return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
}
}
}
function getOrderedListItemInfo$1(orderListItem, originalText) {
var _originalText$slice$m = originalText.slice(orderListItem.position.start.offset, orderListItem.position.end.offset).match(/^\s*(\d+)(\.|\))(\s*)/),
_originalText$slice$m2 = _slicedToArray(_originalText$slice$m, 4),
numberText = _originalText$slice$m2[1],
marker = _originalText$slice$m2[2],
leadingSpaces = _originalText$slice$m2[3];
return {
numberText,
marker,
leadingSpaces
};
} // workaround for https://github.com/remarkjs/remark/issues/351
// leading and trailing newlines are stripped by remark
function getFencedCodeBlockValue$2(node, originalText) {
var text = originalText.slice(node.position.start.offset, node.position.end.offset);
var leadingSpaceCount = text.match(/^\s*/)[0].length;
var replaceRegex = new RegExp(`^\\s{0,${leadingSpaceCount}}`);
var lineContents = text.split("\n");
var markerStyle = text[leadingSpaceCount]; // ` or ~
var marker = text.slice(leadingSpaceCount).match(new RegExp(`^[${markerStyle}]+`))[0]; // https://spec.commonmark.org/0.28/#example-104: Closing fences may be indented by 0-3 spaces
// https://spec.commonmark.org/0.28/#example-93: The closing code fence must be at least as long as the opening fence
var hasEndMarker = new RegExp(`^\\s{0,3}${marker}`).test(lineContents[lineContents.length - 1].slice(getIndent(lineContents.length - 1)));
return lineContents.slice(1, hasEndMarker ? -1 : undefined).map(function (x, i) {
return x.slice(getIndent(i + 1)).replace(replaceRegex, "");
}).join("\n");
function getIndent(lineIndex) {
return node.position.indent[lineIndex - 1] - 1;
}
}
function mapAst(ast, handler) {
return function preorder(node, index, parentStack) {
parentStack = parentStack || [];
var newNode = Object.assign({}, handler(node, index, parentStack));
if (newNode.children) {
newNode.children = newNode.children.map(function (child, index) {
return preorder(child, index, [newNode].concat(parentStack));
});
}
return newNode;
}(ast, null, null);
}
var utils$8 = {
mapAst,
splitText: splitText$1,
punctuationPattern: punctuationPattern$1,
getFencedCodeBlockValue: getFencedCodeBlockValue$2,
getOrderedListItemInfo: getOrderedListItemInfo$1,
INLINE_NODE_TYPES: INLINE_NODE_TYPES$1,
INLINE_NODE_WRAPPER_TYPES: INLINE_NODE_WRAPPER_TYPES$1
};
var _require$$0$builders$7 = doc.builders;
var hardline$11 = _require$$0$builders$7.hardline;
var literalline$5 = _require$$0$builders$7.literalline;
var concat$13 = _require$$0$builders$7.concat;
var markAsRoot$3 = _require$$0$builders$7.markAsRoot;
var mapDoc$6 = doc.utils.mapDoc;
var getFencedCodeBlockValue$1 = utils$8.getFencedCodeBlockValue;
function embed$4(path$$1, print, textToDoc, options) {
var node = path$$1.getValue();
if (node.type === "code" && node.lang !== null) {
// only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
var langMatch = node.lang.match(/^[A-Za-z0-9_-]+/);
var lang = langMatch ? langMatch[0] : "";
var parser = getParserName(lang);
if (parser) {
var styleUnit = options.__inJsTemplate ? "~" : "`";
var style = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
var doc$$2 = textToDoc(getFencedCodeBlockValue$1(node, options.originalText), {
parser
});
return markAsRoot$3(concat$13([style, node.lang, hardline$11, replaceNewlinesWithLiterallines(doc$$2), style]));
}
}
if (node.type === "yaml") {
return markAsRoot$3(concat$13(["---", hardline$11, node.value && node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
parser: "yaml"
})) : "", "---"]));
} // MDX
switch (node.type) {
case "importExport":
return textToDoc(node.value, {
parser: "babel"
});
case "jsx":
return textToDoc(node.value, {
parser: "__js_expression"
});
}
return null;
function getParserName(lang) {
var supportInfo = support.getSupportInfo(null, {
plugins: options.plugins
});
var language = supportInfo.languages.find(function (language) {
return language.name.toLowerCase() === lang || language.aliases && language.aliases.indexOf(lang) !== -1 || language.extensions && language.extensions.find(function (ext) {
return ext.substring(1) === lang;
});
});
if (language) {
return language.parsers[0];
}
return null;
}
function replaceNewlinesWithLiterallines(doc$$2) {
return mapDoc$6(doc$$2, function (currentDoc) {
return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$13(currentDoc.split(/(\n)/g).map(function (v, i) {
return i % 2 === 0 ? v : literalline$5;
})) : currentDoc;
});
}
}
var embed_1$4 = embed$4;
var pragma$6 = createCommonjsModule(function (module) {
"use strict";
var pragmas = ["format", "prettier"];
function startWithPragma(text) {
var pragma = `@(${pragmas.join("|")})`;
var regex = new RegExp([``, ``].join("|"), "m");
var matched = text.match(regex);
return matched && matched.index === 0;
}
module.exports = {
startWithPragma,
hasPragma: function hasPragma(text) {
return startWithPragma(frontMatter(text).content.trimLeft());
},
insertPragma: function insertPragma(text) {
var extracted = frontMatter(text);
var pragma = ``;
return extracted.frontMatter ? `${extracted.frontMatter.raw}\n\n${pragma}\n\n${extracted.content}` : `${pragma}\n\n${extracted.content}`;
}
};
});
var getOrderedListItemInfo$2 = utils$8.getOrderedListItemInfo;
var mapAst$1 = utils$8.mapAst;
var splitText$2 = utils$8.splitText; // 0x0 ~ 0x10ffff
var isSingleCharRegex = /^([\u0000-\uffff]|[\ud800-\udbff][\udc00-\udfff])$/;
function preprocess$2(ast, options) {
ast = restoreUnescapedCharacter(ast, options);
ast = mergeContinuousTexts(ast);
ast = transformInlineCode(ast);
ast = transformIndentedCodeblockAndMarkItsParentList(ast, options);
ast = markAlignedList(ast, options);
ast = splitTextIntoSentences(ast, options);
ast = transformImportExport(ast);
ast = mergeContinuousImportExport(ast);
return ast;
}
function transformImportExport(ast) {
return mapAst$1(ast, function (node) {
if (node.type !== "import" && node.type !== "export") {
return node;
}
return Object.assign({}, node, {
type: "importExport"
});
});
}
function transformInlineCode(ast) {
return mapAst$1(ast, function (node) {
if (node.type !== "inlineCode") {
return node;
}
return Object.assign({}, node, {
value: node.value.replace(/\s+/g, " ")
});
});
}
function restoreUnescapedCharacter(ast, options) {
return mapAst$1(ast, function (node) {
return node.type !== "text" ? node : Object.assign({}, node, {
value: node.value !== "*" && node.value !== "_" && node.value !== "$" && // handle these cases in printer
isSingleCharRegex.test(node.value) && node.position.end.offset - node.position.start.offset !== node.value.length ? options.originalText.slice(node.position.start.offset, node.position.end.offset) : node.value
});
});
}
function mergeContinuousImportExport(ast) {
return mergeChildren(ast, function (prevNode, node) {
return prevNode.type === "importExport" && node.type === "importExport";
}, function (prevNode, node) {
return {
type: "importExport",
value: prevNode.value + "\n\n" + node.value,
position: {
start: prevNode.position.start,
end: node.position.end
}
};
});
}
function mergeChildren(ast, shouldMerge, mergeNode) {
return mapAst$1(ast, function (node) {
if (!node.children) {
return node;
}
var children = node.children.reduce(function (current, child) {
var lastChild = current[current.length - 1];
if (lastChild && shouldMerge(lastChild, child)) {
current.splice(-1, 1, mergeNode(lastChild, child));
} else {
current.push(child);
}
return current;
}, []);
return Object.assign({}, node, {
children
});
});
}
function mergeContinuousTexts(ast) {
return mergeChildren(ast, function (prevNode, node) {
return prevNode.type === "text" && node.type === "text";
}, function (prevNode, node) {
return {
type: "text",
value: prevNode.value + node.value,
position: {
start: prevNode.position.start,
end: node.position.end
}
};
});
}
function splitTextIntoSentences(ast, options) {
return mapAst$1(ast, function (node, index, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
parentNode = _ref2[0];
if (node.type !== "text") {
return node;
}
var value = node.value;
if (parentNode.type === "paragraph") {
if (index === 0) {
value = value.trimLeft();
}
if (index === parentNode.children.length - 1) {
value = value.trimRight();
}
}
return {
type: "sentence",
position: node.position,
children: splitText$2(value, options)
};
});
}
function transformIndentedCodeblockAndMarkItsParentList(ast, options) {
return mapAst$1(ast, function (node, index, parentStack) {
if (node.type === "code") {
// the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
var isIndented = /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset));
node.isIndented = isIndented;
if (isIndented) {
for (var i = 0; i < parentStack.length; i++) {
var parent = parentStack[i]; // no need to check checked items
if (parent.hasIndentedCodeblock) {
break;
}
if (parent.type === "list") {
parent.hasIndentedCodeblock = true;
}
}
}
}
return node;
});
}
function markAlignedList(ast, options) {
return mapAst$1(ast, function (node, index, parentStack) {
if (node.type === "list" && node.children.length !== 0) {
// if one of its parents is not aligned, it's not possible to be aligned in sub-lists
for (var i = 0; i < parentStack.length; i++) {
var parent = parentStack[i];
if (parent.type === "list" && !parent.isAligned) {
node.isAligned = false;
return node;
}
}
node.isAligned = isAligned(node);
}
return node;
});
function getListItemStart(listItem) {
return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1;
}
function isAligned(list) {
if (!list.ordered) {
/**
* - 123
* - 123
*/
return true;
}
var _list$children = _slicedToArray(list.children, 2),
firstItem = _list$children[0],
secondItem = _list$children[1];
var firstInfo = getOrderedListItemInfo$2(firstItem, options.originalText);
if (firstInfo.leadingSpaces.length > 1) {
/**
* 1. 123
*
* 1. 123
* 1. 123
*/
return true;
}
var firstStart = getListItemStart(firstItem);
if (firstStart === -1) {
/**
* 1.
*
* 1.
* 1.
*/
return false;
}
if (list.children.length === 1) {
/**
* aligned:
*
* 11. 123
*
* not aligned:
*
* 1. 123
*/
return firstStart % options.tabWidth === 0;
}
var secondStart = getListItemStart(secondItem);
if (firstStart !== secondStart) {
/**
* 11. 123
* 1. 123
*
* 1. 123
* 11. 123
*/
return false;
}
if (firstStart % options.tabWidth === 0) {
/**
* 11. 123
* 12. 123
*/
return true;
}
/**
* aligned:
*
* 11. 123
* 1. 123
*
* not aligned:
*
* 1. 123
* 2. 123
*/
var secondInfo = getOrderedListItemInfo$2(secondItem, options.originalText);
return secondInfo.leadingSpaces.length > 1;
}
}
var preprocess_1$2 = preprocess$2;
var _require$$0$builders$6 = doc.builders;
var concat$12 = _require$$0$builders$6.concat;
var join$9 = _require$$0$builders$6.join;
var line$8 = _require$$0$builders$6.line;
var literalline$4 = _require$$0$builders$6.literalline;
var markAsRoot$2 = _require$$0$builders$6.markAsRoot;
var hardline$10 = _require$$0$builders$6.hardline;
var softline$6 = _require$$0$builders$6.softline;
var fill$4 = _require$$0$builders$6.fill;
var align$2 = _require$$0$builders$6.align;
var indent$8 = _require$$0$builders$6.indent;
var group$13 = _require$$0$builders$6.group;
var mapDoc$5 = doc.utils.mapDoc;
var printDocToString$3 = doc.printer.printDocToString;
var getFencedCodeBlockValue = utils$8.getFencedCodeBlockValue;
var getOrderedListItemInfo = utils$8.getOrderedListItemInfo;
var splitText = utils$8.splitText;
var punctuationPattern = utils$8.punctuationPattern;
var INLINE_NODE_TYPES = utils$8.INLINE_NODE_TYPES;
var INLINE_NODE_WRAPPER_TYPES = utils$8.INLINE_NODE_WRAPPER_TYPES;
var replaceEndOfLineWith$1 = util$1.replaceEndOfLineWith;
var TRAILING_HARDLINE_NODES = ["importExport"];
var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
function genericPrint$4(path$$1, options, print) {
var node = path$$1.getValue();
if (shouldRemainTheSameContent(path$$1)) {
return concat$12(splitText(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(function (node) {
return node.type === "word" ? node.value : node.value === "" ? "" : printLine(path$$1, node.value, options);
}));
}
switch (node.type) {
case "root":
if (node.children.length === 0) {
return "";
}
return concat$12([normalizeDoc(printRoot(path$$1, options, print)), TRAILING_HARDLINE_NODES.indexOf(getLastDescendantNode(node).type) === -1 ? hardline$10 : ""]);
case "paragraph":
return printChildren(path$$1, options, print, {
postprocessor: fill$4
});
case "sentence":
return printChildren(path$$1, options, print);
case "word":
return node.value.replace(/[*$]/g, "\\$&") // escape all `*` and `$` (math)
.replace(new RegExp([`(^|${punctuationPattern})(_+)`, `(_+)(${punctuationPattern}|$)`].join("|"), "g"), function (_, text1, underscore1, underscore2, text2) {
return (underscore1 ? `${text1}${underscore1}` : `${underscore2}${text2}`).replace(/_/g, "\\_");
});
// escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
case "whitespace":
{
var parentNode = path$$1.getParentNode();
var index = parentNode.children.indexOf(node);
var nextNode = parentNode.children[index + 1];
var proseWrap = // leading char that may cause different syntax
nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value) ? "never" : options.proseWrap;
return printLine(path$$1, node.value, {
proseWrap
});
}
case "emphasis":
{
var _parentNode = path$$1.getParentNode();
var _index = _parentNode.children.indexOf(node);
var prevNode = _parentNode.children[_index - 1];
var _nextNode = _parentNode.children[_index + 1];
var hasPrevOrNextWord = // `1*2*3` is considered emphais but `1_2_3` is not
prevNode && prevNode.type === "sentence" && prevNode.children.length > 0 && util$1.getLast(prevNode.children).type === "word" && !util$1.getLast(prevNode.children).hasTrailingPunctuation || _nextNode && _nextNode.type === "sentence" && _nextNode.children.length > 0 && _nextNode.children[0].type === "word" && !_nextNode.children[0].hasLeadingPunctuation;
var style = hasPrevOrNextWord || getAncestorNode$2(path$$1, "emphasis") ? "*" : "_";
return concat$12([style, printChildren(path$$1, options, print), style]);
}
case "strong":
return concat$12(["**", printChildren(path$$1, options, print), "**"]);
case "delete":
return concat$12(["~~", printChildren(path$$1, options, print), "~~"]);
case "inlineCode":
{
var backtickCount = util$1.getMaxContinuousCount(node.value, "`");
var _style = backtickCount === 1 ? "``" : "`";
var gap = backtickCount ? " " : "";
return concat$12([_style, gap, node.value, gap, _style]);
}
case "link":
switch (options.originalText[node.position.start.offset]) {
case "<":
{
var mailto = "mailto:";
var url = //
is parsed as { url: "mailto:hello@example.com" }
node.url.startsWith(mailto) && options.originalText.slice(node.position.start.offset + 1, node.position.start.offset + 1 + mailto.length) !== mailto ? node.url.slice(mailto.length) : node.url;
return concat$12(["<", url, ">"]);
}
case "[":
return concat$12(["[", printChildren(path$$1, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
default:
return options.originalText.slice(node.position.start.offset, node.position.end.offset);
}
case "image":
return concat$12(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
case "blockquote":
return concat$12(["> ", align$2("> ", printChildren(path$$1, options, print))]);
case "heading":
return concat$12(["#".repeat(node.depth) + " ", printChildren(path$$1, options, print)]);
case "code":
{
if (node.isIndented) {
// indented code block
var alignment = " ".repeat(4);
return align$2(alignment, concat$12([alignment, concat$12(replaceEndOfLineWith$1(node.value, hardline$10))]));
} // fenced code block
var styleUnit = options.__inJsTemplate ? "~" : "`";
var _style2 = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
return concat$12([_style2, node.lang || "", hardline$10, concat$12(replaceEndOfLineWith$1(getFencedCodeBlockValue(node, options.originalText), hardline$10)), hardline$10, _style2]);
}
case "yaml":
case "toml":
return options.originalText.slice(node.position.start.offset, node.position.end.offset);
case "html":
{
var _parentNode2 = path$$1.getParentNode();
var value = _parentNode2.type === "root" && util$1.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
var isHtmlComment = /^$/.test(value);
return concat$12(replaceEndOfLineWith$1(value, isHtmlComment ? hardline$10 : markAsRoot$2(literalline$4)));
}
case "list":
{
var nthSiblingIndex = getNthListSiblingIndex(node, path$$1.getParentNode());
var isGitDiffFriendlyOrderedList = node.ordered && node.children.length > 1 && +getOrderedListItemInfo(node.children[1], options.originalText).numberText === 1;
return printChildren(path$$1, options, print, {
processor: function processor(childPath, index) {
var prefix = getPrefix();
return concat$12([prefix, align$2(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
function getPrefix() {
var rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* ";
return node.isAligned ||
/* workaround for https://github.com/remarkjs/remark/issues/315 */
node.hasIndentedCodeblock ? alignListPrefix(rawPrefix, options) : rawPrefix;
}
}
});
}
case "thematicBreak":
{
var counter = getAncestorCounter$1(path$$1, "list");
if (counter === -1) {
return "---";
}
var _nthSiblingIndex = getNthListSiblingIndex(path$$1.getParentNode(counter), path$$1.getParentNode(counter + 1));
return _nthSiblingIndex % 2 === 0 ? "***" : "---";
}
case "linkReference":
return concat$12(["[", printChildren(path$$1, options, print), "]", node.referenceType === "full" ? concat$12(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
case "imageReference":
switch (node.referenceType) {
case "full":
return concat$12(["![", node.alt || "", "][", node.identifier, "]"]);
default:
return concat$12(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
}
case "definition":
{
var lineOrSpace = options.proseWrap === "always" ? line$8 : " ";
return group$13(concat$12([concat$12(["[", node.identifier, "]:"]), indent$8(concat$12([lineOrSpace, printUrl(node.url), node.title === null ? "" : concat$12([lineOrSpace, printTitle(node.title, options, false)])]))]));
}
case "footnote":
return concat$12(["[^", printChildren(path$$1, options, print), "]"]);
case "footnoteReference":
return concat$12(["[^", node.identifier, "]"]);
case "footnoteDefinition":
{
var _nextNode2 = path$$1.getParentNode().children[path$$1.getName() + 1];
var shouldInlineFootnote = node.children.length === 1 && node.children[0].type === "paragraph" && (options.proseWrap === "never" || options.proseWrap === "preserve" && node.children[0].position.start.line === node.children[0].position.end.line);
return concat$12(["[^", node.identifier, "]: ", shouldInlineFootnote ? printChildren(path$$1, options, print) : group$13(concat$12([align$2(" ".repeat(options.tabWidth), printChildren(path$$1, options, print, {
processor: function processor(childPath, index) {
return index === 0 ? group$13(concat$12([softline$6, softline$6, childPath.call(print)])) : childPath.call(print);
}
})), _nextNode2 && _nextNode2.type === "footnoteDefinition" ? softline$6 : ""]))]);
}
case "table":
return printTable(path$$1, options, print);
case "tableCell":
return printChildren(path$$1, options, print);
case "break":
return /\s/.test(options.originalText[node.position.start.offset]) ? concat$12([" ", markAsRoot$2(literalline$4)]) : concat$12(["\\", hardline$10]);
case "liquidNode":
return concat$12(replaceEndOfLineWith$1(node.value, hardline$10));
// MDX
case "importExport":
case "jsx":
return node.value;
// fallback to the original text if multiparser failed
case "math":
return concat$12(["$$", hardline$10, node.value ? concat$12([concat$12(replaceEndOfLineWith$1(node.value, hardline$10)), hardline$10]) : "", "$$"]);
case "inlineMath":
{
// remark-math trims content but we don't want to remove whitespaces
// since it's very possible that it's recognized as math accidentally
return options.originalText.slice(options.locStart(node), options.locEnd(node));
}
case "tableRow": // handled in "table"
case "listItem": // handled in "list"
default:
throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
}
}
function printListItem(path$$1, options, print, listPrefix) {
var node = path$$1.getValue();
var prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
return concat$12([prefix, printChildren(path$$1, options, print, {
processor: function processor(childPath, index) {
if (index === 0 && childPath.getValue().type !== "list") {
return align$2(" ".repeat(prefix.length), childPath.call(print));
}
var alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
);
return concat$12([alignment, align$2(alignment, childPath.call(print))]);
}
})]);
}
function alignListPrefix(prefix, options) {
var additionalSpaces = getAdditionalSpaces();
return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
);
function getAdditionalSpaces() {
var restSpaces = prefix.length % options.tabWidth;
return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
}
}
function getNthListSiblingIndex(node, parentNode) {
return getNthSiblingIndex(node, parentNode, function (siblingNode) {
return siblingNode.ordered === node.ordered;
});
}
function getNthSiblingIndex(node, parentNode, condition) {
condition = condition || function () {
return true;
};
var index = -1;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = parentNode.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var childNode = _step.value;
if (childNode.type === node.type && condition(childNode)) {
index++;
} else {
index = -1;
}
if (childNode === node) {
return index;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
function getAncestorCounter$1(path$$1, typeOrTypes) {
var types = [].concat(typeOrTypes);
var counter = -1;
var ancestorNode;
while (ancestorNode = path$$1.getParentNode(++counter)) {
if (types.indexOf(ancestorNode.type) !== -1) {
return counter;
}
}
return -1;
}
function getAncestorNode$2(path$$1, typeOrTypes) {
var counter = getAncestorCounter$1(path$$1, typeOrTypes);
return counter === -1 ? null : path$$1.getParentNode(counter);
}
function printLine(path$$1, value, options) {
if (options.proseWrap === "preserve" && value === "\n") {
return hardline$10;
}
var isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path$$1, SINGLE_LINE_NODE_TYPES);
return value !== "" ? isBreakable ? line$8 : " " : isBreakable ? softline$6 : "";
}
function printTable(path$$1, options, print) {
var node = path$$1.getValue();
var contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
path$$1.map(function (rowPath) {
var rowContents = [];
rowPath.map(function (cellPath) {
rowContents.push(printDocToString$3(cellPath.call(print), options).formatted);
}, "children");
contents.push(rowContents);
}, "children");
var columnMaxWidths = contents.reduce(function (currentWidths, rowContents) {
return currentWidths.map(function (width, columnIndex) {
return Math.max(width, util$1.getStringWidth(rowContents[columnIndex]));
});
}, contents[0].map(function () {
return 3;
}) // minimum width = 3 (---, :--, :-:, --:)
);
return join$9(hardline$10, [printRow(contents[0]), printSeparator(), join$9(hardline$10, contents.slice(1).map(printRow))]);
function printSeparator() {
return concat$12(["| ", join$9(" | ", columnMaxWidths.map(function (width, index) {
switch (node.align[index]) {
case "left":
return ":" + "-".repeat(width - 1);
case "right":
return "-".repeat(width - 1) + ":";
case "center":
return ":" + "-".repeat(width - 2) + ":";
default:
return "-".repeat(width);
}
})), " |"]);
}
function printRow(rowContents) {
return concat$12(["| ", join$9(" | ", rowContents.map(function (rowContent, columnIndex) {
switch (node.align[columnIndex]) {
case "right":
return alignRight(rowContent, columnMaxWidths[columnIndex]);
case "center":
return alignCenter(rowContent, columnMaxWidths[columnIndex]);
default:
return alignLeft(rowContent, columnMaxWidths[columnIndex]);
}
})), " |"]);
}
function alignLeft(text, width) {
return concat$12([text, " ".repeat(width - util$1.getStringWidth(text))]);
}
function alignRight(text, width) {
return concat$12([" ".repeat(width - util$1.getStringWidth(text)), text]);
}
function alignCenter(text, width) {
var spaces = width - util$1.getStringWidth(text);
var left = Math.floor(spaces / 2);
var right = spaces - left;
return concat$12([" ".repeat(left), text, " ".repeat(right)]);
}
}
function printRoot(path$$1, options, print) {
/** @typedef {{ index: number, offset: number }} IgnorePosition */
/** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
var ignoreRanges = [];
/** @type {IgnorePosition | null} */
var ignoreStart = null;
var children = path$$1.getValue().children;
children.forEach(function (childNode, index) {
switch (isPrettierIgnore(childNode)) {
case "start":
if (ignoreStart === null) {
ignoreStart = {
index,
offset: childNode.position.end.offset
};
}
break;
case "end":
if (ignoreStart !== null) {
ignoreRanges.push({
start: ignoreStart,
end: {
index,
offset: childNode.position.start.offset
}
});
ignoreStart = null;
}
break;
default:
// do nothing
break;
}
});
return printChildren(path$$1, options, print, {
processor: function processor(childPath, index) {
if (ignoreRanges.length !== 0) {
var ignoreRange = ignoreRanges[0];
if (index === ignoreRange.start.index) {
return concat$12([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
}
if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
return false;
}
if (index === ignoreRange.end.index) {
ignoreRanges.shift();
return false;
}
}
return childPath.call(print);
}
});
}
function printChildren(path$$1, options, print, events$$1) {
events$$1 = events$$1 || {};
var postprocessor = events$$1.postprocessor || concat$12;
var processor = events$$1.processor || function (childPath) {
return childPath.call(print);
};
var node = path$$1.getValue();
var parts = [];
var lastChildNode;
path$$1.map(function (childPath, index) {
var childNode = childPath.getValue();
var result = processor(childPath, index);
if (result !== false) {
var data = {
parts,
prevNode: lastChildNode,
parentNode: node,
options
};
if (!shouldNotPrePrintHardline(childNode, data)) {
parts.push(hardline$10);
if (lastChildNode && TRAILING_HARDLINE_NODES.indexOf(lastChildNode.type) !== -1) {
if (shouldPrePrintTripleHardline(childNode, data)) {
parts.push(hardline$10);
}
} else {
if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
parts.push(hardline$10);
}
if (shouldPrePrintTripleHardline(childNode, data)) {
parts.push(hardline$10);
}
}
}
parts.push(result);
lastChildNode = childNode;
}
}, "children");
return postprocessor(parts);
}
function getLastDescendantNode(node) {
var current = node;
while (current.children && current.children.length !== 0) {
current = current.children[current.children.length - 1];
}
return current;
}
/** @return {false | 'next' | 'start' | 'end'} */
function isPrettierIgnore(node) {
if (node.type !== "html") {
return false;
}
var match = node.value.match(/^$/);
return match === null ? false : match[1] ? match[1] : "next";
}
function shouldNotPrePrintHardline(node, data) {
var isFirstNode = data.parts.length === 0;
var isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1;
var isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1;
return isFirstNode || isInlineNode || isInlineHTML;
}
function shouldPrePrintDoubleHardline(node, data) {
var isSequence = (data.prevNode && data.prevNode.type) === node.type;
var isSiblingNode = isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1;
var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
}
function shouldPrePrintTripleHardline(node, data) {
var isPrevNodeList = data.prevNode && data.prevNode.type === "list";
var isIndentedCode = node.type === "code" && node.isIndented;
return isPrevNodeList && isIndentedCode;
}
function shouldRemainTheSameContent(path$$1) {
var ancestorNode = getAncestorNode$2(path$$1, ["linkReference", "imageReference"]);
return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
}
function normalizeDoc(doc$$2) {
return mapDoc$5(doc$$2, function (currentDoc) {
if (!currentDoc.parts) {
return currentDoc;
}
if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
return currentDoc.parts[0];
}
var parts = [];
currentDoc.parts.forEach(function (part) {
if (part.type === "concat") {
parts.push.apply(parts, part.parts);
} else if (part !== "") {
parts.push(part);
}
});
return Object.assign({}, currentDoc, {
parts: normalizeParts(parts)
});
});
}
function printUrl(url, dangerousCharOrChars) {
var dangerousChars = [" "].concat(dangerousCharOrChars || []);
return new RegExp(dangerousChars.map(function (x) {
return `\\${x}`;
}).join("|")).test(url) ? `<${url}>` : url;
}
function printTitle(title, options, printSpace) {
if (printSpace == null) {
printSpace = true;
}
if (!title) {
return "";
}
if (printSpace) {
return " " + printTitle(title, options, false);
}
if (title.includes('"') && title.includes("'") && !title.includes(")")) {
return `(${title})`; // avoid escaped quotes
} // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
var singleCount = title.split("'").length - 1;
var doubleCount = title.split('"').length - 1;
var quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
return `${quote}${title}${quote}`;
}
function normalizeParts(parts) {
return parts.reduce(function (current, part) {
var lastPart = util$1.getLast(current);
if (typeof lastPart === "string" && typeof part === "string") {
current.splice(-1, 1, lastPart + part);
} else {
current.push(part);
}
return current;
}, []);
}
function clamp(value, min, max) {
return value < min ? min : value > max ? max : value;
}
function clean$7(ast, newObj, parent) {
delete newObj.position;
delete newObj.raw; // front-matter
// for codeblock
if (ast.type === "code" || ast.type === "yaml" || ast.type === "import" || ast.type === "export" || ast.type === "jsx") {
delete newObj.value;
}
if (ast.type === "list") {
delete newObj.isAligned;
} // texts can be splitted or merged
if (ast.type === "text") {
return null;
}
if (ast.type === "inlineCode") {
newObj.value = ast.value.replace(/[ \t\n]+/g, " ");
} // for insert pragma
if (parent && parent.type === "root" && parent.children.length > 0 && (parent.children[0] === ast || (parent.children[0].type === "yaml" || parent.children[0].type === "toml") && parent.children[1] === ast) && ast.type === "html" && pragma$6.startWithPragma(ast.value)) {
return null;
}
}
function hasPrettierIgnore$1(path$$1) {
var index = +path$$1.getName();
if (index === 0) {
return false;
}
var prevNode = path$$1.getParentNode().children[index - 1];
return isPrettierIgnore(prevNode) === "next";
}
var printerMarkdown = {
preprocess: preprocess_1$2,
print: genericPrint$4,
embed: embed_1$4,
massageAstNode: clean$7,
hasPrettierIgnore: hasPrettierIgnore$1,
insertPragma: pragma$6.insertPragma
};
var options$12 = {
proseWrap: commonOptions.proseWrap,
singleQuote: commonOptions.singleQuote
};
var name$13 = "Markdown";
var type$12 = "prose";
var aliases$4 = ["pandoc"];
var aceMode$12 = "markdown";
var codemirrorMode$9 = "gfm";
var codemirrorMimeType$9 = "text/x-gfm";
var wrap = true;
var extensions$12 = [".md", ".markdown", ".mdown", ".mdwn", ".mkd", ".mkdn", ".mkdown", ".ronn", ".workbook"];
var tmScope$12 = "source.gfm";
var languageId$12 = 222;
var markdown = {
name: name$13,
type: type$12,
aliases: aliases$4,
aceMode: aceMode$12,
codemirrorMode: codemirrorMode$9,
codemirrorMimeType: codemirrorMimeType$9,
wrap: wrap,
extensions: extensions$12,
tmScope: tmScope$12,
languageId: languageId$12
};
var markdown$1 = Object.freeze({
name: name$13,
type: type$12,
aliases: aliases$4,
aceMode: aceMode$12,
codemirrorMode: codemirrorMode$9,
codemirrorMimeType: codemirrorMimeType$9,
wrap: wrap,
extensions: extensions$12,
tmScope: tmScope$12,
languageId: languageId$12,
default: markdown
});
var require$$0$28 = ( markdown$1 && markdown ) || markdown$1;
var languages$4 = [createLanguage(require$$0$28, {
override: {
since: "1.8.0",
parsers: ["remark"],
vscodeLanguageIds: ["markdown"]
},
extend: {
filenames: ["README"]
}
}), createLanguage({
name: "MDX",
extensions: [".mdx"]
}, // TODO: use linguist data
{
override: {
since: "1.15.0",
parsers: ["mdx"],
vscodeLanguageIds: ["mdx"]
}
})];
var printers$4 = {
mdast: printerMarkdown
};
var languageMarkdown = {
languages: languages$4,
options: options$12,
printers: printers$4
};
var clean$8 = function clean(ast, newNode) {
delete newNode.sourceSpan;
delete newNode.startSourceSpan;
delete newNode.endSourceSpan;
delete newNode.nameSpan;
delete newNode.valueSpan;
if (ast.type === "text" || ast.type === "comment") {
return null;
} // may be formatted by multiparser
if (ast.type === "yaml" || ast.type === "toml") {
return null;
}
if (ast.type === "attribute") {
delete newNode.value;
}
if (ast.type === "docType") {
delete newNode.value;
}
};
var a = ["accesskey", "charset", "coords", "download", "href", "hreflang", "name", "ping", "referrerpolicy", "rel", "rev", "shape", "tabindex", "target", "type"];
var abbr = ["title"];
var applet = ["align", "alt", "archive", "code", "codebase", "height", "hspace", "name", "object", "vspace", "width"];
var area = ["accesskey", "alt", "coords", "download", "href", "hreflang", "nohref", "ping", "referrerpolicy", "rel", "shape", "tabindex", "target", "type"];
var audio = ["autoplay", "controls", "crossorigin", "loop", "muted", "preload", "src"];
var base$2 = ["href", "target"];
var basefont = ["color", "face", "size"];
var bdo = ["dir"];
var blockquote = ["cite"];
var body = ["alink", "background", "bgcolor", "link", "text", "vlink"];
var br = ["clear"];
var button = ["accesskey", "autofocus", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "name", "tabindex", "type", "value"];
var canvas = ["height", "width"];
var caption = ["align"];
var col = ["align", "char", "charoff", "span", "valign", "width"];
var colgroup = ["align", "char", "charoff", "span", "valign", "width"];
var data$1 = ["value"];
var del = ["cite", "datetime"];
var details = ["open"];
var dfn = ["title"];
var dialog = ["open"];
var dir = ["compact"];
var div = ["align"];
var dl = ["compact"];
var embed$7 = ["height", "src", "type", "width"];
var fieldset = ["disabled", "form", "name"];
var font = ["color", "face", "size"];
var form = ["accept", "accept-charset", "action", "autocomplete", "enctype", "method", "name", "novalidate", "target"];
var frame = ["frameborder", "longdesc", "marginheight", "marginwidth", "name", "noresize", "scrolling", "src"];
var frameset = ["cols", "rows"];
var h1 = ["align"];
var h2 = ["align"];
var h3 = ["align"];
var h4 = ["align"];
var h5 = ["align"];
var h6 = ["align"];
var head = ["profile"];
var hr = ["align", "noshade", "size", "width"];
var html = ["manifest", "version"];
var iframe = ["align", "allowfullscreen", "allowpaymentrequest", "allowusermedia", "frameborder", "height", "longdesc", "marginheight", "marginwidth", "name", "referrerpolicy", "sandbox", "scrolling", "src", "srcdoc", "width"];
var img = ["align", "alt", "border", "crossorigin", "decoding", "height", "hspace", "ismap", "longdesc", "name", "referrerpolicy", "sizes", "src", "srcset", "usemap", "vspace", "width"];
var input = ["accept", "accesskey", "align", "alt", "autocomplete", "autofocus", "checked", "dirname", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "height", "ismap", "list", "max", "maxlength", "min", "minlength", "multiple", "name", "pattern", "placeholder", "readonly", "required", "size", "src", "step", "tabindex", "title", "type", "usemap", "value", "width"];
var ins = ["cite", "datetime"];
var isindex = ["prompt"];
var label = ["accesskey", "for", "form"];
var legend = ["accesskey", "align"];
var li = ["type", "value"];
var link$1 = ["as", "charset", "color", "crossorigin", "href", "hreflang", "integrity", "media", "nonce", "referrerpolicy", "rel", "rev", "sizes", "target", "title", "type"];
var map = ["name"];
var menu = ["compact"];
var meta = ["charset", "content", "http-equiv", "name", "scheme"];
var meter = ["high", "low", "max", "min", "optimum", "value"];
var object = ["align", "archive", "border", "classid", "codebase", "codetype", "data", "declare", "form", "height", "hspace", "name", "standby", "tabindex", "type", "typemustmatch", "usemap", "vspace", "width"];
var ol = ["compact", "reversed", "start", "type"];
var optgroup = ["disabled", "label"];
var option = ["disabled", "label", "selected", "value"];
var output = ["for", "form", "name"];
var p = ["align"];
var param = ["name", "type", "value", "valuetype"];
var pre = ["width"];
var progress = ["max", "value"];
var q = ["cite"];
var script = ["async", "charset", "crossorigin", "defer", "integrity", "language", "nomodule", "nonce", "referrerpolicy", "src", "type"];
var select = ["autocomplete", "autofocus", "disabled", "form", "multiple", "name", "required", "size", "tabindex"];
var slot = ["name"];
var source = ["media", "sizes", "src", "srcset", "type"];
var style = ["media", "nonce", "title", "type"];
var table = ["align", "bgcolor", "border", "cellpadding", "cellspacing", "frame", "rules", "summary", "width"];
var tbody = ["align", "char", "charoff", "valign"];
var td = ["abbr", "align", "axis", "bgcolor", "char", "charoff", "colspan", "headers", "height", "nowrap", "rowspan", "scope", "valign", "width"];
var textarea = ["accesskey", "autocomplete", "autofocus", "cols", "dirname", "disabled", "form", "maxlength", "minlength", "name", "placeholder", "readonly", "required", "rows", "tabindex", "wrap"];
var tfoot = ["align", "char", "charoff", "valign"];
var th = ["abbr", "align", "axis", "bgcolor", "char", "charoff", "colspan", "headers", "height", "nowrap", "rowspan", "scope", "valign", "width"];
var thead = ["align", "char", "charoff", "valign"];
var time = ["datetime"];
var tr = ["align", "bgcolor", "char", "charoff", "valign"];
var track = ["default", "kind", "label", "src", "srclang"];
var ul = ["compact", "type"];
var video = ["autoplay", "controls", "crossorigin", "height", "loop", "muted", "playsinline", "poster", "preload", "src", "width"];
var index$13 = {
a: a,
abbr: abbr,
applet: applet,
area: area,
audio: audio,
base: base$2,
basefont: basefont,
bdo: bdo,
blockquote: blockquote,
body: body,
br: br,
button: button,
canvas: canvas,
caption: caption,
col: col,
colgroup: colgroup,
data: data$1,
del: del,
details: details,
dfn: dfn,
dialog: dialog,
dir: dir,
div: div,
dl: dl,
embed: embed$7,
fieldset: fieldset,
font: font,
form: form,
frame: frame,
frameset: frameset,
h1: h1,
h2: h2,
h3: h3,
h4: h4,
h5: h5,
h6: h6,
head: head,
hr: hr,
html: html,
iframe: iframe,
img: img,
input: input,
ins: ins,
isindex: isindex,
label: label,
legend: legend,
li: li,
link: link$1,
map: map,
menu: menu,
meta: meta,
meter: meter,
object: object,
ol: ol,
optgroup: optgroup,
option: option,
output: output,
p: p,
param: param,
pre: pre,
progress: progress,
q: q,
script: script,
select: select,
slot: slot,
source: source,
style: style,
table: table,
tbody: tbody,
td: td,
textarea: textarea,
tfoot: tfoot,
th: th,
thead: thead,
time: time,
tr: tr,
track: track,
ul: ul,
video: video,
"*": ["accesskey", "autocapitalize", "class", "contenteditable", "dir", "draggable", "hidden", "id", "inputmode", "is", "itemid", "itemprop", "itemref", "itemscope", "itemtype", "lang", "nonce", "slot", "spellcheck", "style", "tabindex", "title", "translate"]
};
var htmlElementAttributes = Object.freeze({
a: a,
abbr: abbr,
applet: applet,
area: area,
audio: audio,
base: base$2,
basefont: basefont,
bdo: bdo,
blockquote: blockquote,
body: body,
br: br,
button: button,
canvas: canvas,
caption: caption,
col: col,
colgroup: colgroup,
data: data$1,
del: del,
details: details,
dfn: dfn,
dialog: dialog,
dir: dir,
div: div,
dl: dl,
embed: embed$7,
fieldset: fieldset,
font: font,
form: form,
frame: frame,
frameset: frameset,
h1: h1,
h2: h2,
h3: h3,
h4: h4,
h5: h5,
h6: h6,
head: head,
hr: hr,
html: html,
iframe: iframe,
img: img,
input: input,
ins: ins,
isindex: isindex,
label: label,
legend: legend,
li: li,
link: link$1,
map: map,
menu: menu,
meta: meta,
meter: meter,
object: object,
ol: ol,
optgroup: optgroup,
option: option,
output: output,
p: p,
param: param,
pre: pre,
progress: progress,
q: q,
script: script,
select: select,
slot: slot,
source: source,
style: style,
table: table,
tbody: tbody,
td: td,
textarea: textarea,
tfoot: tfoot,
th: th,
thead: thead,
time: time,
tr: tr,
track: track,
ul: ul,
video: video,
default: index$13
});
var json$9 = {"CSS_DISPLAY_TAGS":{"area":"none","base":"none","basefont":"none","datalist":"none","head":"none","link":"none","meta":"none","noembed":"none","noframes":"none","param":"none","rp":"none","script":"none","source":"block","style":"none","template":"inline","track":"block","title":"none","html":"block","body":"block","address":"block","blockquote":"block","center":"block","div":"block","figure":"block","figcaption":"block","footer":"block","form":"block","header":"block","hr":"block","legend":"block","listing":"block","main":"block","p":"block","plaintext":"block","pre":"block","xmp":"block","slot":"contents","ruby":"ruby","rt":"ruby-text","article":"block","aside":"block","h1":"block","h2":"block","h3":"block","h4":"block","h5":"block","h6":"block","hgroup":"block","nav":"block","section":"block","dir":"block","dd":"block","dl":"block","dt":"block","ol":"block","ul":"block","li":"list-item","table":"table","caption":"table-caption","colgroup":"table-column-group","col":"table-column","thead":"table-header-group","tbody":"table-row-group","tfoot":"table-footer-group","tr":"table-row","td":"table-cell","th":"table-cell","fieldset":"block","button":"inline-block","video":"inline-block","audio":"inline-block"},"CSS_DISPLAY_DEFAULT":"inline","CSS_WHITE_SPACE_TAGS":{"listing":"pre","plaintext":"pre","pre":"pre","xmp":"pre","nobr":"nowrap","table":"initial","textarea":"pre-wrap"},"CSS_WHITE_SPACE_DEFAULT":"normal"};
var htmlElementAttributes$1 = ( htmlElementAttributes && index$13 ) || htmlElementAttributes;
var CSS_DISPLAY_TAGS = json$9.CSS_DISPLAY_TAGS;
var CSS_DISPLAY_DEFAULT = json$9.CSS_DISPLAY_DEFAULT;
var CSS_WHITE_SPACE_TAGS = json$9.CSS_WHITE_SPACE_TAGS;
var CSS_WHITE_SPACE_DEFAULT = json$9.CSS_WHITE_SPACE_DEFAULT;
var HTML_TAGS = arrayToMap(htmlTagNames$1);
var HTML_ELEMENT_ATTRIBUTES = mapObject(htmlElementAttributes$1, arrayToMap);
function arrayToMap(array) {
var map = Object.create(null);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var value = _step.value;
map[value] = true;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return map;
}
function mapObject(object, fn) {
var newObject = Object.create(null);
var _arr = Object.keys(object);
for (var _i = 0; _i < _arr.length; _i++) {
var key = _arr[_i];
newObject[key] = fn(object[key], key);
}
return newObject;
}
function shouldPreserveContent$1(node, options) {
if (node.type === "element" && node.fullName === "template" && node.attrMap.lang && node.attrMap.lang !== "html") {
return true;
} // unterminated node in ie conditional comment
// e.g.
if (node.type === "ieConditionalComment" && node.lastChild && !node.lastChild.isSelfClosing && !node.lastChild.endSourceSpan) {
return true;
} // incomplete html in ie conditional comment
// e.g.
if (node.type === "ieConditionalComment" && !node.complete) {
return true;
} // top-level elements (excluding ,