diff --git a/changelog_unreleased/javascript/17363.md b/changelog_unreleased/javascript/17363.md new file mode 100644 index 000000000..deb1374ca --- /dev/null +++ b/changelog_unreleased/javascript/17363.md @@ -0,0 +1,5 @@ +#### Removed support for experimental `Records & Tuples` (#17363 by @fisker) + +The the ES proposal [JavaScript Records & Tuples Proposal](https://github.com/tc39/proposal-record-tuple) has been withdrawn. + +- [Disclaimer about non-standard syntax](https://prettier.io/docs/en/rationale.html#disclaimer-about-non-standard-syntax) diff --git a/src/language-js/clean.js b/src/language-js/clean.js index e62450369..690fbda35 100644 --- a/src/language-js/clean.js +++ b/src/language-js/clean.js @@ -1,5 +1,5 @@ import { - isArrayOrTupleExpression, + isArrayExpression, isNumericLiteral, isStringLiteral, } from "./utils/index.js"; @@ -145,7 +145,7 @@ function clean(original, cloned, parent) { ] of cloned.expression.arguments[0].properties.entries()) { switch (astProps[index].key.name) { case "styles": - if (isArrayOrTupleExpression(prop.value)) { + if (isArrayExpression(prop.value)) { removeTemplateElementsValue(prop.value.elements[0]); } break; diff --git a/src/language-js/comments/handle-comments.js b/src/language-js/comments/handle-comments.js index a890e1b01..b9a89e671 100644 --- a/src/language-js/comments/handle-comments.js +++ b/src/language-js/comments/handle-comments.js @@ -861,9 +861,7 @@ const assignmentLikeNodeTypes = new Set([ ]); const complexExprNodeTypes = new Set([ "ObjectExpression", - "RecordExpression", "ArrayExpression", - "TupleExpression", "TemplateLiteral", "TaggedTemplateExpression", "ObjectTypeAnnotation", diff --git a/src/language-js/embed/utils.js b/src/language-js/embed/utils.js index 7406a11de..9737a34c7 100644 --- a/src/language-js/embed/utils.js +++ b/src/language-js/embed/utils.js @@ -1,7 +1,7 @@ import { CommentCheckFlags, hasComment, - isArrayOrTupleExpression, + isArrayExpression, isObjectProperty, } from "../utils/index.js"; @@ -40,7 +40,7 @@ function isAngularComponentStyles(path) { return ( path.match( isTemplateLiteral, - (node, name) => isArrayOrTupleExpression(node) && name === "elements", + (node, name) => isArrayExpression(node) && name === "elements", isObjectPropertyNamedStyles, ...angularComponentObjectExpressionPredicates, ) || diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 40c512f37..ba7307542 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -6,7 +6,7 @@ import { getPrecedence, hasNakedLeftSide, hasNode, - isArrayOrTupleExpression, + isArrayExpression, isBinaryCastExpression, isBitwiseOperator, isCallExpression, @@ -15,7 +15,7 @@ import { isMemberExpression, isNullishCoalescing, isNumericLiteral, - isObjectOrRecordExpression, + isObjectExpression, isObjectProperty, isUnionType, shouldFlatten, @@ -946,7 +946,7 @@ function needsParens(path, options) { (parent.type === "ObjectProperty" && // Preserve parens for compatibility with AngularJS expressions !node.extra?.parenthesized) || - isArrayOrTupleExpression(parent) || + isArrayExpression(parent) || (key === "arguments" && isCallExpression(parent)) || (key === "right" && parent.type === "NGPipeExpression") || (key === "property" && parent.type === "MemberExpression") || @@ -962,7 +962,7 @@ function needsParens(path, options) { (key === "left" && parent.type === "BinaryExpression" && parent.operator === "<") || - (!isArrayOrTupleExpression(parent) && + (!isArrayExpression(parent) && parent.type !== "ArrowFunctionExpression" && parent.type !== "AssignmentExpression" && parent.type !== "AssignmentPattern" && @@ -1076,7 +1076,7 @@ function includesFunctionTypeInObjectType(node) { } function endsWithRightBracket(node) { - return isObjectOrRecordExpression(node); + return isObjectExpression(node); } /** diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 877e5c49e..16e8d2ff7 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -45,7 +45,6 @@ const parseOptions = { "sourcePhaseImports", "deferredImportEvaluation", ["optionalChainingAssign", { version: "2023-07" }], - "recordAndTuple", ], tokens: true, ranges: true, diff --git a/src/language-js/print/array.js b/src/language-js/print/array.js index fa6c45340..4d9f8e0c5 100644 --- a/src/language-js/print/array.js +++ b/src/language-js/print/array.js @@ -16,9 +16,9 @@ import { locEnd, locStart } from "../loc.js"; import { CommentCheckFlags, hasComment, - isArrayOrTupleExpression, + isArrayExpression, isNumericLiteral, - isObjectOrRecordExpression, + isObjectExpression, isSignedNumericLiteral, shouldPrintComma, } from "../utils/index.js"; @@ -44,7 +44,6 @@ function printEmptyArrayElements(path, options, openBracket, closeBracket) { /* - `ArrayExpression` -- `TupleExpression` - `ArrayPattern` - `TSTupleType`(TypeScript) - `TupleTypeAnnotation`(Flow) @@ -54,7 +53,7 @@ function printArray(path, options, print) { /** @type{Doc[]} */ const parts = []; - const openBracket = node.type === "TupleExpression" ? "#[" : "["; + const openBracket = "["; const closeBracket = "]"; const elementsProperty = // TODO: Remove `types` when babel changes AST of `TupleTypeAnnotation` @@ -92,10 +91,7 @@ function printArray(path, options, print) { elements.length > 1 && elements.every((element, i, elements) => { const elementType = element?.type; - if ( - !isArrayOrTupleExpression(element) && - !isObjectOrRecordExpression(element) - ) { + if (!isArrayExpression(element) && !isObjectExpression(element)) { return false; } @@ -104,9 +100,7 @@ function printArray(path, options, print) { return false; } - const itemsKey = isArrayOrTupleExpression(element) - ? "elements" - : "properties"; + const itemsKey = isArrayExpression(element) ? "elements" : "properties"; return element[itemsKey] && element[itemsKey].length > 1; }); @@ -161,7 +155,7 @@ function printArray(path, options, print) { function isConciselyPrintedArray(node, options) { return ( - isArrayOrTupleExpression(node) && + isArrayExpression(node) && node.elements.length > 1 && node.elements.every( (element) => diff --git a/src/language-js/print/arrow-function.js b/src/language-js/print/arrow-function.js index 27fde8293..8f7069fd0 100644 --- a/src/language-js/print/arrow-function.js +++ b/src/language-js/print/arrow-function.js @@ -20,11 +20,11 @@ import { getFunctionParameters, hasComment, hasLeadingOwnLineComment, - isArrayOrTupleExpression, + isArrayExpression, isBinaryish, isCallLikeExpression, isJsxElement, - isObjectOrRecordExpression, + isObjectExpression, isTemplateOnItsOwnLine, shouldPrintComma, startsWithNoLookaheadToken, @@ -226,8 +226,8 @@ function printArrowFunctionSignature(path, options, print, args) { */ function mayBreakAfterShortPrefix(functionBody, bodyDoc, options) { return ( - isArrayOrTupleExpression(functionBody) || - isObjectOrRecordExpression(functionBody) || + isArrayExpression(functionBody) || + isObjectExpression(functionBody) || functionBody.type === "ArrowFunctionExpression" || functionBody.type === "DoExpression" || functionBody.type === "BlockStatement" || diff --git a/src/language-js/print/binaryish.js b/src/language-js/print/binaryish.js index 4cd85975f..1be3aeb71 100644 --- a/src/language-js/print/binaryish.js +++ b/src/language-js/print/binaryish.js @@ -19,12 +19,12 @@ import { CommentCheckFlags, hasComment, hasLeadingOwnLineComment, - isArrayOrTupleExpression, + isArrayExpression, isBinaryish, isCallExpression, isJsxElement, isMemberExpression, - isObjectOrRecordExpression, + isObjectExpression, isObjectProperty, shouldFlatten, } from "../utils/index.js"; @@ -359,14 +359,11 @@ function shouldInlineLogicalExpression(node) { return false; } - if ( - isObjectOrRecordExpression(node.right) && - node.right.properties.length > 0 - ) { + if (isObjectExpression(node.right) && node.right.properties.length > 0) { return true; } - if (isArrayOrTupleExpression(node.right) && node.right.elements.length > 0) { + if (isArrayExpression(node.right) && node.right.elements.length > 0) { return true; } diff --git a/src/language-js/print/call-arguments.js b/src/language-js/print/call-arguments.js index 826beb594..c7cbaea59 100644 --- a/src/language-js/print/call-arguments.js +++ b/src/language-js/print/call-arguments.js @@ -17,7 +17,7 @@ import { getCallArgumentSelector, getFunctionParameters, hasComment, - isArrayOrTupleExpression, + isArrayExpression, isBinaryCastExpression, isBinaryish, isCallExpression, @@ -26,7 +26,7 @@ import { isJsxElement, isLongCurriedCallExpression, isNextLineEmpty, - isObjectOrRecordExpression, + isObjectExpression, isObjectProperty, isRegExpLiteral, isSimpleCallArgument, @@ -192,10 +192,9 @@ function printCallArguments(path, options, print) { function couldExpandArg(arg, arrowChainRecursion = false) { return ( - (isObjectOrRecordExpression(arg) && + (isObjectExpression(arg) && (arg.properties.length > 0 || hasComment(arg))) || - (isArrayOrTupleExpression(arg) && - (arg.elements.length > 0 || hasComment(arg))) || + (isArrayExpression(arg) && (arg.elements.length > 0 || hasComment(arg))) || (arg.type === "TSTypeAssertion" && couldExpandArg(arg.expression)) || (isBinaryCastExpression(arg) && couldExpandArg(arg.expression)) || arg.type === "FunctionExpression" || @@ -219,8 +218,8 @@ function couldExpandArg(arg, arrowChainRecursion = false) { (arg.body.type === "BlockStatement" || (arg.body.type === "ArrowFunctionExpression" && couldExpandArg(arg.body, true)) || - isObjectOrRecordExpression(arg.body) || - isArrayOrTupleExpression(arg.body) || + isObjectExpression(arg.body) || + isArrayExpression(arg.body) || (!arrowChainRecursion && (isCallExpression(arg.body) || arg.body.type === "ConditionalExpression")) || @@ -251,7 +250,7 @@ function shouldExpandLastArg(args, argDocs, options) { // useMemo(() => func(), [foo, bar, baz]) (args.length !== 2 || penultimateArg.type !== "ArrowFunctionExpression" || - !isArrayOrTupleExpression(lastArg)) && + !isArrayExpression(lastArg)) && !(args.length > 1 && isConciselyPrintedArray(lastArg, options)) ); } diff --git a/src/language-js/print/estree.js b/src/language-js/print/estree.js index 7f0adfe18..2c4dd94c9 100644 --- a/src/language-js/print/estree.js +++ b/src/language-js/print/estree.js @@ -15,13 +15,13 @@ import { locEnd, locStart } from "../loc.js"; import { CommentCheckFlags, hasComment, - isArrayOrTupleExpression, + isArrayExpression, isCallExpression, isLiteral, isMemberExpression, isMethod, isNextLineEmpty, - isObjectOrRecordExpression, + isObjectExpression, needsHardlineAfterDanglingComment, startsWithNoLookaheadToken, } from "../utils/index.js"; @@ -117,8 +117,8 @@ function printEstree(path, options, print, args) { case "ParenthesizedExpression": { const shouldHug = !hasComment(node.expression) && - (isObjectOrRecordExpression(node.expression) || - isArrayOrTupleExpression(node.expression)); + (isObjectExpression(node.expression) || + isArrayExpression(node.expression)); if (shouldHug) { return ["(", print("expression"), ")"]; } @@ -249,7 +249,6 @@ function printEstree(path, options, print, args) { case "ObjectExpression": case "ObjectPattern": - case "RecordExpression": return printObject(path, options, print); case "Property": if (isMethod(node)) { @@ -266,7 +265,6 @@ function printEstree(path, options, print, args) { return ["@", print("expression")]; case "ArrayExpression": case "ArrayPattern": - case "TupleExpression": return printArray(path, options, print); case "SequenceExpression": { const { parent } = path; diff --git a/src/language-js/print/function-parameters.js b/src/language-js/print/function-parameters.js index 8c8273dbd..50e9d8b27 100644 --- a/src/language-js/print/function-parameters.js +++ b/src/language-js/print/function-parameters.js @@ -16,10 +16,10 @@ import { getFunctionParameters, hasComment, hasRestParameter, - isArrayOrTupleExpression, + isArrayExpression, isFlowObjectTypePropertyAFunction, isNextLineEmpty, - isObjectOrRecordExpression, + isObjectExpression, isObjectType, isSimpleType, isTestCall, @@ -185,9 +185,9 @@ function shouldHugTheOnlyFunctionParameter(node) { (parameter.left.type === "ObjectPattern" || parameter.left.type === "ArrayPattern") && (parameter.right.type === "Identifier" || - (isObjectOrRecordExpression(parameter.right) && + (isObjectExpression(parameter.right) && parameter.right.properties.length === 0) || - (isArrayOrTupleExpression(parameter.right) && + (isArrayExpression(parameter.right) && parameter.right.elements.length === 0)))) ); } diff --git a/src/language-js/print/jsx.js b/src/language-js/print/jsx.js index b4a8e27b8..a2a705491 100644 --- a/src/language-js/print/jsx.js +++ b/src/language-js/print/jsx.js @@ -30,11 +30,11 @@ import { CommentCheckFlags, hasComment, hasNodeIgnoreComment, - isArrayOrTupleExpression, + isArrayExpression, isBinaryish, isCallExpression, isJsxElement, - isObjectOrRecordExpression, + isObjectExpression, isStringLiteral, } from "../utils/index.js"; @@ -487,7 +487,6 @@ function separatorWithWhitespace( const NO_WRAP_PARENTS = new Set([ "ArrayExpression", - "TupleExpression", "JSXAttribute", "JSXElement", "JSXExpressionContainer", @@ -565,8 +564,8 @@ function printJsxExpressionContainer(path, options, print) { const shouldInline = (node, parent) => node.type === "JSXEmptyExpression" || (!hasComment(node) && - (isArrayOrTupleExpression(node) || - isObjectOrRecordExpression(node) || + (isArrayExpression(node) || + isObjectExpression(node) || node.type === "ArrowFunctionExpression" || (node.type === "AwaitExpression" && (shouldInline(node.argument, node) || diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index cffedfe6a..38a11b83e 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -107,8 +107,7 @@ function printObject(path, options, print) { : node.type === "TSInterfaceBody" || node.type === "TSTypeLiteral" ? ifBreak(semi, ";") : ","; - const leftBrace = - node.type === "RecordExpression" ? "#{" : node.exact ? "{|" : "{"; + const leftBrace = node.exact ? "{|" : "{"; const rightBrace = node.exact ? "|}" : "}"; /** @type {Doc[]} */ diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 50ca6583c..1d81ab98f 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -8,8 +8,8 @@ import { } from "../../document/builders.js"; import UnexpectedNodeError from "../../utils/unexpected-node-error.js"; import { - isArrayOrTupleExpression, - isObjectOrRecordExpression, + isArrayExpression, + isObjectExpression, shouldPrintComma, } from "../utils/index.js"; import isTsKeywordType from "../utils/is-ts-keyword-type.js"; @@ -75,8 +75,8 @@ function printTypescript(path, options, print) { return "this"; case "TSTypeAssertion": { const shouldBreakAfterCast = !( - isArrayOrTupleExpression(node.expression) || - isObjectOrRecordExpression(node.expression) + isArrayExpression(node.expression) || + isObjectExpression(node.expression) ); const castGroup = group([ diff --git a/src/language-js/traverse/visitor-keys.evaluate.js b/src/language-js/traverse/visitor-keys.evaluate.js index ba4661481..f461dcfc8 100644 --- a/src/language-js/traverse/visitor-keys.evaluate.js +++ b/src/language-js/traverse/visitor-keys.evaluate.js @@ -94,6 +94,9 @@ const visitorKeys = Object.fromEntries( ]), ); +// Babel will remove these in v8 https://github.com/babel/babel/pull/17242 +delete visitorKeys.TupleExpression; +delete visitorKeys.RecordExpression; // Babel will remove this in v8 delete visitorKeys.DecimalLiteral; // Won't exist since we use `createImportExpressions` when parsing with babel diff --git a/src/language-js/utils/index.js b/src/language-js/utils/index.js index 3eba6553e..dc0f1c135 100644 --- a/src/language-js/utils/index.js +++ b/src/language-js/utils/index.js @@ -102,15 +102,11 @@ const isExportDeclaration = createTypeCheckFunction([ "DeclareExportAllDeclaration", ]); -const isArrayOrTupleExpression = createTypeCheckFunction([ - "ArrayExpression", - "TupleExpression", -]); - -const isObjectOrRecordExpression = createTypeCheckFunction([ - "ObjectExpression", - "RecordExpression", -]); +// These two functions exists because we used support `recordAndTuple` +// Feel free to check `node.type` instead +// https://github.com/prettier/prettier/pull/17363 +const isArrayExpression = createTypeCheckFunction(["ArrayExpression"]); +const isObjectExpression = createTypeCheckFunction(["ObjectExpression"]); /** * @param {Estree.Node} node @@ -615,14 +611,14 @@ function isSimpleCallArgument(node, depth = 2) { ); } - if (isObjectOrRecordExpression(node)) { + if (isObjectExpression(node)) { return node.properties.every( (p) => !p.computed && (p.shorthand || (p.value && isChildSimple(p.value))), ); } - if (isArrayOrTupleExpression(node)) { + if (isArrayExpression(node)) { return node.elements.every((x) => x === null || isChildSimple(x)); } @@ -1091,7 +1087,7 @@ export { hasNodeIgnoreComment, hasRestParameter, identity, - isArrayOrTupleExpression, + isArrayExpression, isBinaryCastExpression, isBinaryish, isBitwiseOperator, @@ -1113,7 +1109,7 @@ export { isNextLineEmpty, isNullishCoalescing, isNumericLiteral, - isObjectOrRecordExpression, + isObjectExpression, isObjectProperty, isObjectType, isPrettierIgnoreComment, diff --git a/tests/format/js/arrays/__snapshots__/format.test.js.snap b/tests/format/js/arrays/__snapshots__/format.test.js.snap index 804e9cfd9..7ef86cea0 100644 --- a/tests/format/js/arrays/__snapshots__/format.test.js.snap +++ b/tests/format/js/arrays/__snapshots__/format.test.js.snap @@ -1,5 +1,35 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`array-and-tuple.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +a = [ + [1,2], + [1,2], +] + +a = [ + {a, b}, + {a, b}, +] + +=====================================output===================================== +a = [ + [1, 2], + [1, 2], +]; + +a = [ + { a, b }, + { a, b }, +]; + +================================================================================ +`; + exports[`empty.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] @@ -1003,112 +1033,3 @@ _ = [ ================================================================================ `; - -exports[`tuple-and-record.js [acorn] format 1`] = ` -"Unexpected character '[' (7:4) - 5 | - 6 | a = [ -> 7 | #[1,2], - | ^ - 8 | #[1,2], - 9 | ] - 10 | -Cause: Unexpected character '[' (7:3)" -`; - -exports[`tuple-and-record.js [espree] format 1`] = ` -"Unexpected character '[' (7:4) - 5 | - 6 | a = [ -> 7 | #[1,2], - | ^ - 8 | #[1,2], - 9 | ] - 10 | -Cause: Unexpected character '['" -`; - -exports[`tuple-and-record.js [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (7:3) - 5 | - 6 | a = [ -> 7 | #[1,2], - | ^ - 8 | #[1,2], - 9 | ] - 10 |" -`; - -exports[`tuple-and-record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (7:3) - 5 | - 6 | a = [ -> 7 | #[1,2], - | ^ - 8 | #[1,2], - 9 | ] - 10 | -Cause: [7:2-7:3]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js [typescript] format 1`] = ` -"Invalid character. (7:3) - 5 | - 6 | a = [ -> 7 | #[1,2], - | ^ - 8 | #[1,2], - 9 | ] - 10 | -Cause: Invalid character." -`; - -exports[`tuple-and-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "flow", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -a = [ - [1,2], - [1,2], -] - -a = [ - #[1,2], - #[1,2], -] - -a = [ - {a, b}, - {a, b}, -] - -a = [ - #{a, b}, - #{a, b}, -] - -=====================================output===================================== -a = [ - [1, 2], - [1, 2], -]; - -a = [ - #[1, 2], - #[1, 2], -]; - -a = [ - { a, b }, - { a, b }, -]; - -a = [ - #{ a, b }, - #{ a, b }, -]; - -================================================================================ -`; diff --git a/tests/format/js/arrays/array-and-tuple.js b/tests/format/js/arrays/array-and-tuple.js new file mode 100644 index 000000000..babac9fa9 --- /dev/null +++ b/tests/format/js/arrays/array-and-tuple.js @@ -0,0 +1,9 @@ +a = [ + [1,2], + [1,2], +] + +a = [ + {a, b}, + {a, b}, +] diff --git a/tests/format/js/arrays/format.test.js b/tests/format/js/arrays/format.test.js index 1086afd5f..67c251cce 100644 --- a/tests/format/js/arrays/format.test.js +++ b/tests/format/js/arrays/format.test.js @@ -1,9 +1 @@ -const errors = { - acorn: ["tuple-and-record.js"], - espree: ["tuple-and-record.js"], - meriyah: ["tuple-and-record.js"], - typescript: ["tuple-and-record.js"], - flow: ["tuple-and-record.js"], -}; - -runFormatTest(import.meta, ["babel", "flow", "typescript"], { errors }); +runFormatTest(import.meta, ["babel", "flow", "typescript"]); diff --git a/tests/format/js/arrays/tuple-and-record.js b/tests/format/js/arrays/tuple-and-record.js deleted file mode 100644 index 984ee8f33..000000000 --- a/tests/format/js/arrays/tuple-and-record.js +++ /dev/null @@ -1,19 +0,0 @@ -a = [ - [1,2], - [1,2], -] - -a = [ - #[1,2], - #[1,2], -] - -a = [ - {a, b}, - {a, b}, -] - -a = [ - #{a, b}, - #{a, b}, -] diff --git a/tests/format/js/arrows/__snapshots__/format.test.js.snap b/tests/format/js/arrows/__snapshots__/format.test.js.snap index 590cffc23..91388aeea 100644 --- a/tests/format/js/arrows/__snapshots__/format.test.js.snap +++ b/tests/format/js/arrows/__snapshots__/format.test.js.snap @@ -1,5 +1,81 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`array-and-object.js - {"arrowParens":"always"} format 1`] = ` +====================================options===================================== +arrowParens: "always" +parsers: ["babel", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +const fn12 = (a) => (b) => (c) => (d) => (e) => + ({ foo: bar, bar: baz, baz: foo }); + +map(() => ([ + // comment + foo +])); + +map(() => ({ + // comment + foo +})); + +=====================================output===================================== +const fn12 = (a) => (b) => (c) => (d) => (e) => ({ + foo: bar, + bar: baz, + baz: foo, +}); + +map(() => [ + // comment + foo, +]); + +map(() => ({ + // comment + foo, +})); + +================================================================================ +`; + +exports[`array-and-object.js - {"arrowParens":"avoid"} format 1`] = ` +====================================options===================================== +arrowParens: "avoid" +parsers: ["babel", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +const fn12 = (a) => (b) => (c) => (d) => (e) => + ({ foo: bar, bar: baz, baz: foo }); + +map(() => ([ + // comment + foo +])); + +map(() => ({ + // comment + foo +})); + +=====================================output===================================== +const fn12 = a => b => c => d => e => ({ foo: bar, bar: baz, baz: foo }); + +map(() => [ + // comment + foo, +]); + +map(() => ({ + // comment + foo, +})); + +================================================================================ +`; + exports[`arrow_function_expression.js - {"arrowParens":"always"} format 1`] = ` ====================================options===================================== arrowParens: "always" @@ -4527,229 +4603,3 @@ foo(a => b => (0, 1)); ================================================================================ `; - -exports[`tuple-and-record.js - {"arrowParens":"always"} [acorn] format 1`] = ` -"Identifier 'fn12' has already been declared (4:7) - 2 | ({ foo: bar, bar: baz, baz: foo }); - 3 | -> 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => - | ^ - 5 | (#{ foo: bar, bar: baz, baz: foo }); - 6 | - 7 | map(() => ([ -Cause: Identifier 'fn12' has already been declared (4:6)" -`; - -exports[`tuple-and-record.js - {"arrowParens":"always"} [espree] format 1`] = ` -"Identifier 'fn12' has already been declared (4:7) - 2 | ({ foo: bar, bar: baz, baz: foo }); - 3 | -> 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => - | ^ - 5 | (#{ foo: bar, bar: baz, baz: foo }); - 6 | - 7 | map(() => ([ -Cause: Identifier 'fn12' has already been declared" -`; - -exports[`tuple-and-record.js - {"arrowParens":"always"} [meriyah] format 1`] = ` -"'#' not followed by identifier (5:4) - 3 | - 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => -> 5 | (#{ foo: bar, bar: baz, baz: foo }); - | ^ - 6 | - 7 | map(() => ([ - 8 | // comment -Cause: [5:3-5:4]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js - {"arrowParens":"always"} [typescript] format 1`] = ` -"Invalid character. (5:4) - 3 | - 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => -> 5 | (#{ foo: bar, bar: baz, baz: foo }); - | ^ - 6 | - 7 | map(() => ([ - 8 | // comment -Cause: Invalid character." -`; - -exports[`tuple-and-record.js - {"arrowParens":"always"} format 1`] = ` -====================================options===================================== -arrowParens: "always" -parsers: ["babel", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -const fn12 = (a) => (b) => (c) => (d) => (e) => - ({ foo: bar, bar: baz, baz: foo }); - -const fn12 = (a) => (b) => (c) => (d) => (e) => - (#{ foo: bar, bar: baz, baz: foo }); - -map(() => ([ - // comment - foo -])); - -map(() => (#[ - // comment - foo -])); - -map(() => ({ - // comment - foo -})); - -map(() => (#{ - // comment - foo -})); - -=====================================output===================================== -const fn12 = (a) => (b) => (c) => (d) => (e) => ({ - foo: bar, - bar: baz, - baz: foo, -}); - -const fn12 = (a) => (b) => (c) => (d) => (e) => #{ - foo: bar, - bar: baz, - baz: foo, -}; - -map(() => [ - // comment - foo, -]); - -map(() => #[ - // comment - foo, -]); - -map(() => ({ - // comment - foo, -})); - -map(() => #{ - // comment - foo, -}); - -================================================================================ -`; - -exports[`tuple-and-record.js - {"arrowParens":"avoid"} [acorn] format 1`] = ` -"Identifier 'fn12' has already been declared (4:7) - 2 | ({ foo: bar, bar: baz, baz: foo }); - 3 | -> 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => - | ^ - 5 | (#{ foo: bar, bar: baz, baz: foo }); - 6 | - 7 | map(() => ([ -Cause: Identifier 'fn12' has already been declared (4:6)" -`; - -exports[`tuple-and-record.js - {"arrowParens":"avoid"} [espree] format 1`] = ` -"Identifier 'fn12' has already been declared (4:7) - 2 | ({ foo: bar, bar: baz, baz: foo }); - 3 | -> 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => - | ^ - 5 | (#{ foo: bar, bar: baz, baz: foo }); - 6 | - 7 | map(() => ([ -Cause: Identifier 'fn12' has already been declared" -`; - -exports[`tuple-and-record.js - {"arrowParens":"avoid"} [meriyah] format 1`] = ` -"'#' not followed by identifier (5:4) - 3 | - 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => -> 5 | (#{ foo: bar, bar: baz, baz: foo }); - | ^ - 6 | - 7 | map(() => ([ - 8 | // comment -Cause: [5:3-5:4]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js - {"arrowParens":"avoid"} [typescript] format 1`] = ` -"Invalid character. (5:4) - 3 | - 4 | const fn12 = (a) => (b) => (c) => (d) => (e) => -> 5 | (#{ foo: bar, bar: baz, baz: foo }); - | ^ - 6 | - 7 | map(() => ([ - 8 | // comment -Cause: Invalid character." -`; - -exports[`tuple-and-record.js - {"arrowParens":"avoid"} format 1`] = ` -====================================options===================================== -arrowParens: "avoid" -parsers: ["babel", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -const fn12 = (a) => (b) => (c) => (d) => (e) => - ({ foo: bar, bar: baz, baz: foo }); - -const fn12 = (a) => (b) => (c) => (d) => (e) => - (#{ foo: bar, bar: baz, baz: foo }); - -map(() => ([ - // comment - foo -])); - -map(() => (#[ - // comment - foo -])); - -map(() => ({ - // comment - foo -})); - -map(() => (#{ - // comment - foo -})); - -=====================================output===================================== -const fn12 = a => b => c => d => e => ({ foo: bar, bar: baz, baz: foo }); - -const fn12 = a => b => c => d => e => #{ foo: bar, bar: baz, baz: foo }; - -map(() => [ - // comment - foo, -]); - -map(() => #[ - // comment - foo, -]); - -map(() => ({ - // comment - foo, -})); - -map(() => #{ - // comment - foo, -}); - -================================================================================ -`; diff --git a/tests/format/js/arrows/array-and-object.js b/tests/format/js/arrows/array-and-object.js new file mode 100644 index 000000000..b923ebe58 --- /dev/null +++ b/tests/format/js/arrows/array-and-object.js @@ -0,0 +1,12 @@ +const fn12 = (a) => (b) => (c) => (d) => (e) => + ({ foo: bar, bar: baz, baz: foo }); + +map(() => ([ + // comment + foo +])); + +map(() => ({ + // comment + foo +})); diff --git a/tests/format/js/arrows/format.test.js b/tests/format/js/arrows/format.test.js index fc6857d82..863a6c138 100644 --- a/tests/format/js/arrows/format.test.js +++ b/tests/format/js/arrows/format.test.js @@ -1,15 +1,2 @@ -const errors = { - acorn: ["tuple-and-record.js"], - espree: ["tuple-and-record.js"], - meriyah: ["tuple-and-record.js"], - typescript: ["tuple-and-record.js"], - flow: ["tuple-and-record.js"], -}; -runFormatTest(import.meta, ["babel", "typescript"], { - arrowParens: "always", - errors, -}); -runFormatTest(import.meta, ["babel", "typescript"], { - arrowParens: "avoid", - errors, -}); +runFormatTest(import.meta, ["babel", "typescript"], { arrowParens: "always" }); +runFormatTest(import.meta, ["babel", "typescript"], { arrowParens: "avoid" }); diff --git a/tests/format/js/arrows/tuple-and-record.js b/tests/format/js/arrows/tuple-and-record.js deleted file mode 100644 index 1865604fc..000000000 --- a/tests/format/js/arrows/tuple-and-record.js +++ /dev/null @@ -1,25 +0,0 @@ -const fn12 = (a) => (b) => (c) => (d) => (e) => - ({ foo: bar, bar: baz, baz: foo }); - -const fn12 = (a) => (b) => (c) => (d) => (e) => - (#{ foo: bar, bar: baz, baz: foo }); - -map(() => ([ - // comment - foo -])); - -map(() => (#[ - // comment - foo -])); - -map(() => ({ - // comment - foo -})); - -map(() => (#{ - // comment - foo -})); diff --git a/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap b/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap index 611091975..b3b5e40b7 100644 --- a/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap +++ b/tests/format/js/babel-plugins/__snapshots__/format.test.js.snap @@ -2239,100 +2239,6 @@ class Counter extends HTMLElement { ================================================================================ `; -exports[`record-tuple-record.js [acorn] format 1`] = ` -"Unexpected character '{' (1:18) -> 1 | const record1 = #{ - | ^ - 2 | a: 1, - 3 | b: 2, - 4 | c: 3, -Cause: Unexpected character '{' (1:17)" -`; - -exports[`record-tuple-record.js [espree] format 1`] = ` -"Unexpected character '{' (1:18) -> 1 | const record1 = #{ - | ^ - 2 | a: 1, - 3 | b: 2, - 4 | c: 3, -Cause: Unexpected character '{'" -`; - -exports[`record-tuple-record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:17) -> 1 | const record1 = #{ - | ^ - 2 | a: 1, - 3 | b: 2, - 4 | c: 3, -Cause: [1:16-1:17]: '#' not followed by identifier" -`; - -exports[`record-tuple-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "babel-ts", "babel-flow"] -printWidth: 80 - | printWidth -=====================================input====================================== -const record1 = #{ - a: 1, - b: 2, - c: 3, -}; - -const record2 = #{...record1, b: 5}; - -=====================================output===================================== -const record1 = #{ - a: 1, - b: 2, - c: 3, -}; - -const record2 = #{ ...record1, b: 5 }; - -================================================================================ -`; - -exports[`record-tuple-tuple.js [acorn] format 1`] = ` -"Unexpected character '[' (1:17) -> 1 | const tuple1 = #[1, 2, 3]; - | ^ - 2 | -Cause: Unexpected character '[' (1:16)" -`; - -exports[`record-tuple-tuple.js [espree] format 1`] = ` -"Unexpected character '[' (1:17) -> 1 | const tuple1 = #[1, 2, 3]; - | ^ - 2 | -Cause: Unexpected character '['" -`; - -exports[`record-tuple-tuple.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:16) -> 1 | const tuple1 = #[1, 2, 3]; - | ^ - 2 | -Cause: [1:15-1:16]: '#' not followed by identifier" -`; - -exports[`record-tuple-tuple.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "babel-ts", "babel-flow"] -printWidth: 80 - | printWidth -=====================================input====================================== -const tuple1 = #[1, 2, 3]; - -=====================================output===================================== -const tuple1 = #[1, 2, 3]; - -================================================================================ -`; - exports[`regex-v-flag.js format 1`] = ` ====================================options===================================== parsers: ["babel", "babel-ts", "babel-flow"] diff --git a/tests/format/js/babel-plugins/format.test.js b/tests/format/js/babel-plugins/format.test.js index 7ac7aa658..c9b3dca66 100644 --- a/tests/format/js/babel-plugins/format.test.js +++ b/tests/format/js/babel-plugins/format.test.js @@ -16,8 +16,6 @@ runFormatTest(import.meta, ["babel", "babel-ts", "babel-flow"], { "pipeline-operator-fsharp.js", "pipeline-operator-minimal.js", "pipeline-operator-hack.js", - "record-tuple-record.js", - "record-tuple-tuple.js", "throw-expressions.js", "typescript.js", "v8intrinsic.js", @@ -42,8 +40,6 @@ runFormatTest(import.meta, ["babel", "babel-ts", "babel-flow"], { "pipeline-operator-fsharp.js", "pipeline-operator-minimal.js", "pipeline-operator-hack.js", - "record-tuple-record.js", - "record-tuple-tuple.js", "throw-expressions.js", "typescript.js", "v8intrinsic.js", @@ -68,8 +64,6 @@ runFormatTest(import.meta, ["babel", "babel-ts", "babel-flow"], { "pipeline-operator-fsharp.js", "pipeline-operator-minimal.js", "pipeline-operator-hack.js", - "record-tuple-record.js", - "record-tuple-tuple.js", "throw-expressions.js", "typescript.js", "v8intrinsic.js", diff --git a/tests/format/js/babel-plugins/record-tuple-record.js b/tests/format/js/babel-plugins/record-tuple-record.js deleted file mode 100644 index 097878f37..000000000 --- a/tests/format/js/babel-plugins/record-tuple-record.js +++ /dev/null @@ -1,7 +0,0 @@ -const record1 = #{ - a: 1, - b: 2, - c: 3, -}; - -const record2 = #{...record1, b: 5}; diff --git a/tests/format/js/babel-plugins/record-tuple-tuple.js b/tests/format/js/babel-plugins/record-tuple-tuple.js deleted file mode 100644 index b98e3b8a2..000000000 --- a/tests/format/js/babel-plugins/record-tuple-tuple.js +++ /dev/null @@ -1 +0,0 @@ -const tuple1 = #[1, 2, 3]; diff --git a/tests/format/js/binary-expressions/__snapshots__/format.test.js.snap b/tests/format/js/binary-expressions/__snapshots__/format.test.js.snap index fc3b495bc..34ffaa6bb 100644 --- a/tests/format/js/binary-expressions/__snapshots__/format.test.js.snap +++ b/tests/format/js/binary-expressions/__snapshots__/format.test.js.snap @@ -1,5 +1,66 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`array-and-object.js - {"experimentalOperatorPosition":"start"} format 1`] = ` +====================================options===================================== +experimentalOperatorPosition: "start" +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +foo = foo || [ + // comment + a, +] + +foo = foo || { + // comment + a, +} + +=====================================output===================================== +foo = foo || [ + // comment + a, +]; + +foo = foo || { + // comment + a, +}; + +================================================================================ +`; + +exports[`array-and-object.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +foo = foo || [ + // comment + a, +] + +foo = foo || { + // comment + a, +} + +=====================================output===================================== +foo = foo || [ + // comment + a, +]; + +foo = foo || { + // comment + a, +}; + +================================================================================ +`; + exports[`arrow.js - {"experimentalOperatorPosition":"start"} format 1`] = ` ====================================options===================================== experimentalOperatorPosition: "start" @@ -2365,225 +2426,6 @@ foo( ================================================================================ `; -exports[`tuple-and-record.js [acorn] format 1`] = ` -"Unexpected character '[' (6:15) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: Unexpected character '[' (6:14)" -`; - -exports[`tuple-and-record.js [espree] format 1`] = ` -"Unexpected character '[' (6:15) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: Unexpected character '['" -`; - -exports[`tuple-and-record.js [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (6:14) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ]" -`; - -exports[`tuple-and-record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (6:14) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: [6:13-6:14]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js [typescript] format 1`] = ` -"Invalid character. (6:14) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: Invalid character." -`; - -exports[`tuple-and-record.js - {"experimentalOperatorPosition":"start"} [acorn] format 1`] = ` -"Unexpected character '[' (6:15) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: Unexpected character '[' (6:14)" -`; - -exports[`tuple-and-record.js - {"experimentalOperatorPosition":"start"} [espree] format 1`] = ` -"Unexpected character '[' (6:15) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: Unexpected character '['" -`; - -exports[`tuple-and-record.js - {"experimentalOperatorPosition":"start"} [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (6:14) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ]" -`; - -exports[`tuple-and-record.js - {"experimentalOperatorPosition":"start"} [meriyah] format 1`] = ` -"'#' not followed by identifier (6:14) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: [6:13-6:14]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js - {"experimentalOperatorPosition":"start"} [typescript] format 1`] = ` -"Invalid character. (6:14) - 4 | ] - 5 | -> 6 | foo = foo || #[ - | ^ - 7 | // comment - 8 | a, - 9 | ] -Cause: Invalid character." -`; - -exports[`tuple-and-record.js - {"experimentalOperatorPosition":"start"} format 1`] = ` -====================================options===================================== -experimentalOperatorPosition: "start" -parsers: ["babel", "flow", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -foo = foo || [ - // comment - a, -] - -foo = foo || #[ - // comment - a, -] - -foo = foo || { - // comment - a, -} - -foo = foo || #{ - // comment - a, -} - -=====================================output===================================== -foo = foo || [ - // comment - a, -]; - -foo = foo || #[ - // comment - a, -]; - -foo = foo || { - // comment - a, -}; - -foo = foo || #{ - // comment - a, -}; - -================================================================================ -`; - -exports[`tuple-and-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "flow", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -foo = foo || [ - // comment - a, -] - -foo = foo || #[ - // comment - a, -] - -foo = foo || { - // comment - a, -} - -foo = foo || #{ - // comment - a, -} - -=====================================output===================================== -foo = foo || [ - // comment - a, -]; - -foo = foo || #[ - // comment - a, -]; - -foo = foo || { - // comment - a, -}; - -foo = foo || #{ - // comment - a, -}; - -================================================================================ -`; - exports[`unary.js - {"experimentalOperatorPosition":"start"} format 1`] = ` ====================================options===================================== experimentalOperatorPosition: "start" diff --git a/tests/format/js/binary-expressions/array-and-object.js b/tests/format/js/binary-expressions/array-and-object.js new file mode 100644 index 000000000..0f6514d94 --- /dev/null +++ b/tests/format/js/binary-expressions/array-and-object.js @@ -0,0 +1,9 @@ +foo = foo || [ + // comment + a, +] + +foo = foo || { + // comment + a, +} diff --git a/tests/format/js/binary-expressions/format.test.js b/tests/format/js/binary-expressions/format.test.js index 64e74116f..51d943b41 100644 --- a/tests/format/js/binary-expressions/format.test.js +++ b/tests/format/js/binary-expressions/format.test.js @@ -1,13 +1,4 @@ -const errors = { - acorn: ["tuple-and-record.js"], - espree: ["tuple-and-record.js"], - meriyah: ["tuple-and-record.js"], - typescript: ["tuple-and-record.js"], - flow: ["tuple-and-record.js"], -}; - -runFormatTest(import.meta, ["babel", "flow", "typescript"], { errors }); +runFormatTest(import.meta, ["babel", "flow", "typescript"]); runFormatTest(import.meta, ["babel", "flow", "typescript"], { - errors, experimentalOperatorPosition: "start", }); diff --git a/tests/format/js/binary-expressions/tuple-and-record.js b/tests/format/js/binary-expressions/tuple-and-record.js deleted file mode 100644 index 6590e94e6..000000000 --- a/tests/format/js/binary-expressions/tuple-and-record.js +++ /dev/null @@ -1,19 +0,0 @@ -foo = foo || [ - // comment - a, -] - -foo = foo || #[ - // comment - a, -] - -foo = foo || { - // comment - a, -} - -foo = foo || #{ - // comment - a, -} diff --git a/tests/format/js/class-extends/__snapshots__/format.test.js.snap b/tests/format/js/class-extends/__snapshots__/format.test.js.snap index dd13b0806..94614163d 100644 --- a/tests/format/js/class-extends/__snapshots__/format.test.js.snap +++ b/tests/format/js/class-extends/__snapshots__/format.test.js.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`array-and-object.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class A extends {} {} + +class C extends [] {} + +=====================================output===================================== +class A extends ({}) {} + +class C extends [] {} + +================================================================================ +`; + exports[`complex.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] @@ -173,79 +191,3 @@ x = class extends (++b) {}; ================================================================================ `; - -exports[`tuple-and-record.js [acorn] format 1`] = ` -"Unexpected character '{' (2:18) - 1 | class A extends {} {} -> 2 | class B extends #{} {} - | ^ - 3 | - 4 | class C extends [] {} - 5 | class D extends #[] {} -Cause: Unexpected character '{' (2:17)" -`; - -exports[`tuple-and-record.js [espree] format 1`] = ` -"Unexpected character '{' (2:18) - 1 | class A extends {} {} -> 2 | class B extends #{} {} - | ^ - 3 | - 4 | class C extends [] {} - 5 | class D extends #[] {} -Cause: Unexpected character '{'" -`; - -exports[`tuple-and-record.js [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (2:17) - 1 | class A extends {} {} -> 2 | class B extends #{} {} - | ^ - 3 | - 4 | class C extends [] {} - 5 | class D extends #[] {}" -`; - -exports[`tuple-and-record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (2:17) - 1 | class A extends {} {} -> 2 | class B extends #{} {} - | ^ - 3 | - 4 | class C extends [] {} - 5 | class D extends #[] {} -Cause: [2:16-2:17]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js [typescript] format 1`] = ` -"Invalid character. (2:17) - 1 | class A extends {} {} -> 2 | class B extends #{} {} - | ^ - 3 | - 4 | class C extends [] {} - 5 | class D extends #[] {} -Cause: Invalid character." -`; - -exports[`tuple-and-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "flow", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -class A extends {} {} -class B extends #{} {} - -class C extends [] {} -class D extends #[] {} - -=====================================output===================================== -class A extends ({}) {} -class B extends #{} {} - -class C extends [] {} -class D extends #[] {} - -================================================================================ -`; diff --git a/tests/format/js/class-extends/array-and-object.js b/tests/format/js/class-extends/array-and-object.js new file mode 100644 index 000000000..ce27bd33f --- /dev/null +++ b/tests/format/js/class-extends/array-and-object.js @@ -0,0 +1,3 @@ +class A extends {} {} + +class C extends [] {} diff --git a/tests/format/js/class-extends/format.test.js b/tests/format/js/class-extends/format.test.js index fe257e619..67c251cce 100644 --- a/tests/format/js/class-extends/format.test.js +++ b/tests/format/js/class-extends/format.test.js @@ -1,9 +1 @@ -runFormatTest(import.meta, ["babel", "flow", "typescript"], { - errors: { - acorn: ["tuple-and-record.js"], - espree: ["tuple-and-record.js"], - meriyah: ["tuple-and-record.js"], - typescript: ["tuple-and-record.js"], - flow: ["tuple-and-record.js"], - }, -}); +runFormatTest(import.meta, ["babel", "flow", "typescript"]); diff --git a/tests/format/js/class-extends/tuple-and-record.js b/tests/format/js/class-extends/tuple-and-record.js deleted file mode 100644 index 2adf77c40..000000000 --- a/tests/format/js/class-extends/tuple-and-record.js +++ /dev/null @@ -1,5 +0,0 @@ -class A extends {} {} -class B extends #{} {} - -class C extends [] {} -class D extends #[] {} diff --git a/tests/format/js/comments-closure-typecast/__snapshots__/format.test.js.snap b/tests/format/js/comments-closure-typecast/__snapshots__/format.test.js.snap index 1014fd61c..795619367 100644 --- a/tests/format/js/comments-closure-typecast/__snapshots__/format.test.js.snap +++ b/tests/format/js/comments-closure-typecast/__snapshots__/format.test.js.snap @@ -1,5 +1,43 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`array-and-object.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +foo = /** @type A */ ({ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ ([ + // comment + width, + height, + ...margins, +]); + +=====================================output===================================== +foo = /** @type A */ ({ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ ([ + // comment + width, + height, + ...margins, +]); + +================================================================================ +`; + exports[`binary-expr.js format 1`] = ` ====================================options===================================== parsers: ["babel"] @@ -640,72 +678,6 @@ class Foo extends /** @type {string} */ (Bar) {} ================================================================================ `; -exports[`tuple-and-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -foo = /** @type A */ ({ - // comment - width, - height, - ...margins, -}); - -foo = /** @type A */ (#{ - // comment - width, - height, - ...margins, -}); - -foo = /** @type A */ ([ - // comment - width, - height, - ...margins, -]); - -foo = /** @type A */ (#[ - // comment - width, - height, - ...margins, -]); - -=====================================output===================================== -foo = /** @type A */ ({ - // comment - width, - height, - ...margins, -}); - -foo = /** @type A */ (#{ - // comment - width, - height, - ...margins, -}); - -foo = /** @type A */ ([ - // comment - width, - height, - ...margins, -]); - -foo = /** @type A */ (#[ - // comment - width, - height, - ...margins, -]); - -================================================================================ -`; - exports[`ways-to-specify-type.js format 1`] = ` ====================================options===================================== parsers: ["babel"] diff --git a/tests/format/js/comments-closure-typecast/array-and-object.js b/tests/format/js/comments-closure-typecast/array-and-object.js new file mode 100644 index 000000000..7bf32e2d0 --- /dev/null +++ b/tests/format/js/comments-closure-typecast/array-and-object.js @@ -0,0 +1,13 @@ +foo = /** @type A */ ({ + // comment + width, + height, + ...margins, +}); + +foo = /** @type A */ ([ + // comment + width, + height, + ...margins, +]); diff --git a/tests/format/js/comments-closure-typecast/tuple-and-record.js b/tests/format/js/comments-closure-typecast/tuple-and-record.js deleted file mode 100644 index e7986be1f..000000000 --- a/tests/format/js/comments-closure-typecast/tuple-and-record.js +++ /dev/null @@ -1,27 +0,0 @@ -foo = /** @type A */ ({ - // comment - width, - height, - ...margins, -}); - -foo = /** @type A */ (#{ - // comment - width, - height, - ...margins, -}); - -foo = /** @type A */ ([ - // comment - width, - height, - ...margins, -]); - -foo = /** @type A */ (#[ - // comment - width, - height, - ...margins, -]); diff --git a/tests/format/js/comments/__snapshots__/format.test.js.snap b/tests/format/js/comments/__snapshots__/format.test.js.snap index a59217907..d0452304f 100644 --- a/tests/format/js/comments/__snapshots__/format.test.js.snap +++ b/tests/format/js/comments/__snapshots__/format.test.js.snap @@ -366,6 +366,67 @@ else /* foo */ foo.split; ================================================================================ `; +exports[`array-and-object.js - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +let object = // Comment +{ + key: 'value' +} + +let array = // Comment +[ + 'value' +] + +=====================================output===================================== +let object = + // Comment + { + key: "value", + } + +let array = + // Comment + ["value"] + +================================================================================ +`; + +exports[`array-and-object.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +let object = // Comment +{ + key: 'value' +} + +let array = // Comment +[ + 'value' +] + +=====================================output===================================== +let object = + // Comment + { + key: "value", + }; + +let array = + // Comment + ["value"]; + +================================================================================ +`; + exports[`arrow.js - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] @@ -6464,225 +6525,6 @@ try { ================================================================================ `; -exports[`tuple-and-record.js [acorn] format 1`] = ` -"Unexpected character '{' (7:2) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: Unexpected character '{' (7:1)" -`; - -exports[`tuple-and-record.js [espree] format 1`] = ` -"Unexpected character '{' (7:2) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: Unexpected character '{'" -`; - -exports[`tuple-and-record.js [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (7:1) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 |" -`; - -exports[`tuple-and-record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (7:1) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: [7:0-7:1]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js [typescript] format 1`] = ` -"Invalid character. (7:1) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: Invalid character." -`; - -exports[`tuple-and-record.js - {"semi":false} [acorn] format 1`] = ` -"Unexpected character '{' (7:2) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: Unexpected character '{' (7:1)" -`; - -exports[`tuple-and-record.js - {"semi":false} [espree] format 1`] = ` -"Unexpected character '{' (7:2) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: Unexpected character '{'" -`; - -exports[`tuple-and-record.js - {"semi":false} [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (7:1) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 |" -`; - -exports[`tuple-and-record.js - {"semi":false} [meriyah] format 1`] = ` -"'#' not followed by identifier (7:1) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: [7:0-7:1]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js - {"semi":false} [typescript] format 1`] = ` -"Invalid character. (7:1) - 5 | - 6 | let record = // Comment -> 7 | #{ - | ^ - 8 | key: 'value' - 9 | } - 10 | -Cause: Invalid character." -`; - -exports[`tuple-and-record.js - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["babel", "flow", "typescript"] -printWidth: 80 -semi: false - | printWidth -=====================================input====================================== -let object = // Comment -{ - key: 'value' -} - -let record = // Comment -#{ - key: 'value' -} - -let array = // Comment -[ - 'value' -] - -let tuple = // Comment -#[ - 'value' -] - -=====================================output===================================== -let object = - // Comment - { - key: "value", - } - -let record = - // Comment - #{ - key: "value", - } - -let array = - // Comment - ["value"] - -let tuple = - // Comment - #["value"] - -================================================================================ -`; - -exports[`tuple-and-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "flow", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -let object = // Comment -{ - key: 'value' -} - -let record = // Comment -#{ - key: 'value' -} - -let array = // Comment -[ - 'value' -] - -let tuple = // Comment -#[ - 'value' -] - -=====================================output===================================== -let object = - // Comment - { - key: "value", - }; - -let record = - // Comment - #{ - key: "value", - }; - -let array = - // Comment - ["value"]; - -let tuple = - // Comment - #["value"]; - -================================================================================ -`; - exports[`variable_declarator.js - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] diff --git a/tests/format/js/comments/array-and-object.js b/tests/format/js/comments/array-and-object.js new file mode 100644 index 000000000..f09ef750f --- /dev/null +++ b/tests/format/js/comments/array-and-object.js @@ -0,0 +1,9 @@ +let object = // Comment +{ + key: 'value' +} + +let array = // Comment +[ + 'value' +] diff --git a/tests/format/js/comments/format.test.js b/tests/format/js/comments/format.test.js index 46b96f124..f72cc9a11 100644 --- a/tests/format/js/comments/format.test.js +++ b/tests/format/js/comments/format.test.js @@ -6,16 +6,5 @@ const fixtures = { ], }; -const errors = { - acorn: ["tuple-and-record.js"], - espree: ["tuple-and-record.js"], - meriyah: ["tuple-and-record.js"], - typescript: ["tuple-and-record.js"], - flow: ["tuple-and-record.js"], -}; - -runFormatTest(fixtures, ["babel", "flow", "typescript"], { errors }); -runFormatTest(fixtures, ["babel", "flow", "typescript"], { - semi: false, - errors, -}); +runFormatTest(fixtures, ["babel", "flow", "typescript"]); +runFormatTest(fixtures, ["babel", "flow", "typescript"], { semi: false }); diff --git a/tests/format/js/comments/tuple-and-record.js b/tests/format/js/comments/tuple-and-record.js deleted file mode 100644 index cd560095f..000000000 --- a/tests/format/js/comments/tuple-and-record.js +++ /dev/null @@ -1,19 +0,0 @@ -let object = // Comment -{ - key: 'value' -} - -let record = // Comment -#{ - key: 'value' -} - -let array = // Comment -[ - 'value' -] - -let tuple = // Comment -#[ - 'value' -] diff --git a/tests/format/js/function-single-destructuring/__snapshots__/format.test.js.snap b/tests/format/js/function-single-destructuring/__snapshots__/format.test.js.snap index d56eb9d72..679013d86 100644 --- a/tests/format/js/function-single-destructuring/__snapshots__/format.test.js.snap +++ b/tests/format/js/function-single-destructuring/__snapshots__/format.test.js.snap @@ -108,6 +108,62 @@ promise.then( ================================================================================ `; +exports[`array-and-object.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +function StatelessFunctionalComponent1({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +} = {}) { +} + +function StatelessFunctionalComponent3([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +] = []) { +} + +=====================================output===================================== +function StatelessFunctionalComponent1({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +} = {}) {} + +function StatelessFunctionalComponent3([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = "", + items = [], +] = []) {} + +================================================================================ +`; + exports[`object.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow"] @@ -234,152 +290,3 @@ class C { ================================================================================ `; - -exports[`tuple-and-record.js [acorn] format 1`] = ` -"Unexpected character '{' (22:6) - 20 | title = '', - 21 | items = [], -> 22 | } = #{}) { - | ^ - 23 | } - 24 | - 25 | function StatelessFunctionalComponent3([ -Cause: Unexpected character '{' (22:5)" -`; - -exports[`tuple-and-record.js [espree] format 1`] = ` -"Unexpected character '{' (22:6) - 20 | title = '', - 21 | items = [], -> 22 | } = #{}) { - | ^ - 23 | } - 24 | - 25 | function StatelessFunctionalComponent3([ -Cause: Unexpected character '{'" -`; - -exports[`tuple-and-record.js [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (22:5) - 20 | title = '', - 21 | items = [], -> 22 | } = #{}) { - | ^ - 23 | } - 24 | - 25 | function StatelessFunctionalComponent3([" -`; - -exports[`tuple-and-record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (22:5) - 20 | title = '', - 21 | items = [], -> 22 | } = #{}) { - | ^ - 23 | } - 24 | - 25 | function StatelessFunctionalComponent3([ -Cause: [22:4-22:5]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "flow"] -printWidth: 80 - | printWidth -=====================================input====================================== -function StatelessFunctionalComponent1({ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -} = {}) { -} - -function StatelessFunctionalComponent2({ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -} = #{}) { -} - -function StatelessFunctionalComponent3([ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -] = []) { -} - -function StatelessFunctionalComponent4([ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -] = #[]) { -} - -=====================================output===================================== -function StatelessFunctionalComponent1({ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = "", - items = [], -} = {}) {} - -function StatelessFunctionalComponent2({ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = "", - items = [], -} = #{}) {} - -function StatelessFunctionalComponent3([ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = "", - items = [], -] = []) {} - -function StatelessFunctionalComponent4([ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = "", - items = [], -] = #[]) {} - -================================================================================ -`; diff --git a/tests/format/js/function-single-destructuring/array-and-object.js b/tests/format/js/function-single-destructuring/array-and-object.js new file mode 100644 index 000000000..45f2c94a7 --- /dev/null +++ b/tests/format/js/function-single-destructuring/array-and-object.js @@ -0,0 +1,23 @@ +function StatelessFunctionalComponent1({ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +} = {}) { +} + +function StatelessFunctionalComponent3([ + isActive = true, + onFiltersUpdated = () => null, + onSelect = () => null, + onSubmitAndDeselect = () => null, + onCancel = () => null, + searchFilters = null, + title = '', + items = [], +] = []) { +} diff --git a/tests/format/js/function-single-destructuring/format.test.js b/tests/format/js/function-single-destructuring/format.test.js index 8cdc0d182..784b99177 100644 --- a/tests/format/js/function-single-destructuring/format.test.js +++ b/tests/format/js/function-single-destructuring/format.test.js @@ -1,9 +1 @@ -const errors = { - acorn: ["tuple-and-record.js"], - espree: ["tuple-and-record.js"], - meriyah: ["tuple-and-record.js"], - typescript: ["tuple-and-record.js"], - flow: ["tuple-and-record.js"], -}; - -runFormatTest(import.meta, ["babel", "flow"], { errors }); +runFormatTest(import.meta, ["babel", "flow"]); diff --git a/tests/format/js/function-single-destructuring/tuple-and-record.js b/tests/format/js/function-single-destructuring/tuple-and-record.js deleted file mode 100644 index 4fbf5bdd0..000000000 --- a/tests/format/js/function-single-destructuring/tuple-and-record.js +++ /dev/null @@ -1,47 +0,0 @@ -function StatelessFunctionalComponent1({ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -} = {}) { -} - -function StatelessFunctionalComponent2({ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -} = #{}) { -} - -function StatelessFunctionalComponent3([ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -] = []) { -} - -function StatelessFunctionalComponent4([ - isActive = true, - onFiltersUpdated = () => null, - onSelect = () => null, - onSubmitAndDeselect = () => null, - onCancel = () => null, - searchFilters = null, - title = '', - items = [], -] = #[]) { -} diff --git a/tests/format/js/method-chain/__snapshots__/format.test.js.snap b/tests/format/js/method-chain/__snapshots__/format.test.js.snap index 9c38e05ac..300367832 100644 --- a/tests/format/js/method-chain/__snapshots__/format.test.js.snap +++ b/tests/format/js/method-chain/__snapshots__/format.test.js.snap @@ -28,6 +28,24 @@ foo(a--).bar().leet(); ================================================================================ `; +exports[`array-and-object.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +foo.a().b().c([n, o]) + +foo.a().b().c({n, o}) + +=====================================output===================================== +foo.a().b().c([n, o]); + +foo.a().b().c({ n, o }); + +================================================================================ +`; + exports[`assignment-lhs.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] @@ -1565,79 +1583,3 @@ const sel = this.connections ================================================================================ `; - -exports[`tuple-and-record.js [acorn] format 1`] = ` -"Unexpected character '[' (2:16) - 1 | foo.a().b().c([n, o]) -> 2 | foo.a().b().c(#[n, o]) - | ^ - 3 | - 4 | foo.a().b().c({n, o}) - 5 | foo.a().b().c(#{n, o}) -Cause: Unexpected character '[' (2:15)" -`; - -exports[`tuple-and-record.js [espree] format 1`] = ` -"Unexpected character '[' (2:16) - 1 | foo.a().b().c([n, o]) -> 2 | foo.a().b().c(#[n, o]) - | ^ - 3 | - 4 | foo.a().b().c({n, o}) - 5 | foo.a().b().c(#{n, o}) -Cause: Unexpected character '['" -`; - -exports[`tuple-and-record.js [flow] format 1`] = ` -"Unexpected token \`#\`, expected an identifier (2:15) - 1 | foo.a().b().c([n, o]) -> 2 | foo.a().b().c(#[n, o]) - | ^ - 3 | - 4 | foo.a().b().c({n, o}) - 5 | foo.a().b().c(#{n, o})" -`; - -exports[`tuple-and-record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (2:15) - 1 | foo.a().b().c([n, o]) -> 2 | foo.a().b().c(#[n, o]) - | ^ - 3 | - 4 | foo.a().b().c({n, o}) - 5 | foo.a().b().c(#{n, o}) -Cause: [2:14-2:15]: '#' not followed by identifier" -`; - -exports[`tuple-and-record.js [typescript] format 1`] = ` -"Invalid character. (2:15) - 1 | foo.a().b().c([n, o]) -> 2 | foo.a().b().c(#[n, o]) - | ^ - 3 | - 4 | foo.a().b().c({n, o}) - 5 | foo.a().b().c(#{n, o}) -Cause: Invalid character." -`; - -exports[`tuple-and-record.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "flow", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -foo.a().b().c([n, o]) -foo.a().b().c(#[n, o]) - -foo.a().b().c({n, o}) -foo.a().b().c(#{n, o}) - -=====================================output===================================== -foo.a().b().c([n, o]); -foo.a().b().c(#[n, o]); - -foo.a().b().c({ n, o }); -foo.a().b().c(#{ n, o }); - -================================================================================ -`; diff --git a/tests/format/js/method-chain/array-and-object.js b/tests/format/js/method-chain/array-and-object.js new file mode 100644 index 000000000..8aeb9cf04 --- /dev/null +++ b/tests/format/js/method-chain/array-and-object.js @@ -0,0 +1,3 @@ +foo.a().b().c([n, o]) + +foo.a().b().c({n, o}) diff --git a/tests/format/js/method-chain/format.test.js b/tests/format/js/method-chain/format.test.js index 1086afd5f..67c251cce 100644 --- a/tests/format/js/method-chain/format.test.js +++ b/tests/format/js/method-chain/format.test.js @@ -1,9 +1 @@ -const errors = { - acorn: ["tuple-and-record.js"], - espree: ["tuple-and-record.js"], - meriyah: ["tuple-and-record.js"], - typescript: ["tuple-and-record.js"], - flow: ["tuple-and-record.js"], -}; - -runFormatTest(import.meta, ["babel", "flow", "typescript"], { errors }); +runFormatTest(import.meta, ["babel", "flow", "typescript"]); diff --git a/tests/format/js/method-chain/tuple-and-record.js b/tests/format/js/method-chain/tuple-and-record.js deleted file mode 100644 index b4dee6aa5..000000000 --- a/tests/format/js/method-chain/tuple-and-record.js +++ /dev/null @@ -1,5 +0,0 @@ -foo.a().b().c([n, o]) -foo.a().b().c(#[n, o]) - -foo.a().b().c({n, o}) -foo.a().b().c(#{n, o}) diff --git a/tests/format/js/record/__snapshots__/format.test.js.snap b/tests/format/js/record/__snapshots__/format.test.js.snap deleted file mode 100644 index 8535fc7a7..000000000 --- a/tests/format/js/record/__snapshots__/format.test.js.snap +++ /dev/null @@ -1,348 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`computed.js [acorn] format 1`] = ` -"Unexpected character '{' (2:9) - 1 | const key = "a"; -> 2 | assert(#{ [key]: 1 } === #{ a: 1 }) - | ^ - 3 | assert(#{ [key.toUpperCase()]: 1 } === #{ A: 1 }) - 4 | - 5 | assert(#{ [true]: 1 } === #{ true: 1 }) -Cause: Unexpected character '{' (2:8)" -`; - -exports[`computed.js [espree] format 1`] = ` -"Unexpected character '{' (2:9) - 1 | const key = "a"; -> 2 | assert(#{ [key]: 1 } === #{ a: 1 }) - | ^ - 3 | assert(#{ [key.toUpperCase()]: 1 } === #{ A: 1 }) - 4 | - 5 | assert(#{ [true]: 1 } === #{ true: 1 }) -Cause: Unexpected character '{'" -`; - -exports[`computed.js [meriyah] format 1`] = ` -"'#' not followed by identifier (2:8) - 1 | const key = "a"; -> 2 | assert(#{ [key]: 1 } === #{ a: 1 }) - | ^ - 3 | assert(#{ [key.toUpperCase()]: 1 } === #{ A: 1 }) - 4 | - 5 | assert(#{ [true]: 1 } === #{ true: 1 }) -Cause: [2:7-2:8]: '#' not followed by identifier" -`; - -exports[`computed.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -const key = "a"; -assert(#{ [key]: 1 } === #{ a: 1 }) -assert(#{ [key.toUpperCase()]: 1 } === #{ A: 1 }) - -assert(#{ [true]: 1 } === #{ true: 1 }) -assert(#{ [true]: 1 } === #{ ["true"]: 1 }) - -assert(#{ [1 + 1]: "two" } === #{ 2: "two" }) -assert(#{ [9 + 1]: "ten" } === #{ ["10"]: "ten" }) - -=====================================output===================================== -const key = "a"; -assert(#{ [key]: 1 } === #{ a: 1 }); -assert(#{ [key.toUpperCase()]: 1 } === #{ A: 1 }); - -assert(#{ [true]: 1 } === #{ true: 1 }); -assert(#{ [true]: 1 } === #{ ["true"]: 1 }); - -assert(#{ [1 + 1]: "two" } === #{ 2: "two" }); -assert(#{ [9 + 1]: "ten" } === #{ ["10"]: "ten" }); - -================================================================================ -`; - -exports[`destructuring.js [acorn] format 1`] = ` -"Unexpected character '{' (1:19) -> 1 | const { a, b } = #{ a: 1, b: 2 }; - | ^ - 2 | assert(a === 1); - 3 | assert(b === 2); - 4 | -Cause: Unexpected character '{' (1:18)" -`; - -exports[`destructuring.js [espree] format 1`] = ` -"Unexpected character '{' (1:19) -> 1 | const { a, b } = #{ a: 1, b: 2 }; - | ^ - 2 | assert(a === 1); - 3 | assert(b === 2); - 4 | -Cause: Unexpected character '{'" -`; - -exports[`destructuring.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:18) -> 1 | const { a, b } = #{ a: 1, b: 2 }; - | ^ - 2 | assert(a === 1); - 3 | assert(b === 2); - 4 | -Cause: [1:17-1:18]: '#' not followed by identifier" -`; - -exports[`destructuring.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -const { a, b } = #{ a: 1, b: 2 }; -assert(a === 1); -assert(b === 2); - -const { a, ...rest } = #{ a: 1, b: 2, c: 3 }; -assert(a === 1); -assert(typeof rest === "object"); -assert(rest.b === 2); -assert(rest.c === 3); - -=====================================output===================================== -const { a, b } = #{ a: 1, b: 2 }; -assert(a === 1); -assert(b === 2); - -const { a, ...rest } = #{ a: 1, b: 2, c: 3 }; -assert(a === 1); -assert(typeof rest === "object"); -assert(rest.b === 2); -assert(rest.c === 3); - -================================================================================ -`; - -exports[`record.js [acorn] format 1`] = ` -"Unexpected character '{' (1:18) -> 1 | const record1 = #{ - | ^ - 2 | a: 1, - 3 | b: 2, - 4 | c: 3, -Cause: Unexpected character '{' (1:17)" -`; - -exports[`record.js [espree] format 1`] = ` -"Unexpected character '{' (1:18) -> 1 | const record1 = #{ - | ^ - 2 | a: 1, - 3 | b: 2, - 4 | c: 3, -Cause: Unexpected character '{'" -`; - -exports[`record.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:17) -> 1 | const record1 = #{ - | ^ - 2 | a: 1, - 3 | b: 2, - 4 | c: 3, -Cause: [1:16-1:17]: '#' not followed by identifier" -`; - -exports[`record.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -const record1 = #{ - a: 1, - b: 2, - c: 3, -}; - -const record2 = #{...record1, b: 5}; - -assert(record1.a === 1); -assert(record1["a"] === 1); -assert(record1 !== record2); -assert(record2 === #{ a: 1, c: 3, b: 5 }); -assert(record1?.a === 1); -assert(record1?.d === undefined); -assert(record1?.d ?? 5 === 5); -assert(record1.d?.a === undefined); - -=====================================output===================================== -const record1 = #{ - a: 1, - b: 2, - c: 3, -}; - -const record2 = #{ ...record1, b: 5 }; - -assert(record1.a === 1); -assert(record1["a"] === 1); -assert(record1 !== record2); -assert(record2 === #{ a: 1, c: 3, b: 5 }); -assert(record1?.a === 1); -assert(record1?.d === undefined); -assert(record1?.d ?? 5 === 5); -assert(record1.d?.a === undefined); - -================================================================================ -`; - -exports[`shorthand.js [acorn] format 1`] = ` -"Unexpected character '{' (2:17) - 1 | const url = "https://github.com/tc39/proposal-record-tuple"; -> 2 | const record = #{ url } - | ^ - 3 | console.log(record.url) // https://github.com/tc39/proposal-record-tuple - 4 | -Cause: Unexpected character '{' (2:16)" -`; - -exports[`shorthand.js [espree] format 1`] = ` -"Unexpected character '{' (2:17) - 1 | const url = "https://github.com/tc39/proposal-record-tuple"; -> 2 | const record = #{ url } - | ^ - 3 | console.log(record.url) // https://github.com/tc39/proposal-record-tuple - 4 | -Cause: Unexpected character '{'" -`; - -exports[`shorthand.js [meriyah] format 1`] = ` -"'#' not followed by identifier (2:16) - 1 | const url = "https://github.com/tc39/proposal-record-tuple"; -> 2 | const record = #{ url } - | ^ - 3 | console.log(record.url) // https://github.com/tc39/proposal-record-tuple - 4 | -Cause: [2:15-2:16]: '#' not followed by identifier" -`; - -exports[`shorthand.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -const url = "https://github.com/tc39/proposal-record-tuple"; -const record = #{ url } -console.log(record.url) // https://github.com/tc39/proposal-record-tuple - -=====================================output===================================== -const url = "https://github.com/tc39/proposal-record-tuple"; -const record = #{ url }; -console.log(record.url); // https://github.com/tc39/proposal-record-tuple - -================================================================================ -`; - -exports[`spread.js [acorn] format 1`] = ` -"Unexpected character '{' (1:19) -> 1 | const formData = #{ title: "Implement all the things" } - | ^ - 2 | const taskNow = #{ id: 42, status: "WIP", ...formData } - 3 | const taskLater = #{ ...taskNow, status: "DONE" } - 4 | -Cause: Unexpected character '{' (1:18)" -`; - -exports[`spread.js [espree] format 1`] = ` -"Unexpected character '{' (1:19) -> 1 | const formData = #{ title: "Implement all the things" } - | ^ - 2 | const taskNow = #{ id: 42, status: "WIP", ...formData } - 3 | const taskLater = #{ ...taskNow, status: "DONE" } - 4 | -Cause: Unexpected character '{'" -`; - -exports[`spread.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:18) -> 1 | const formData = #{ title: "Implement all the things" } - | ^ - 2 | const taskNow = #{ id: 42, status: "WIP", ...formData } - 3 | const taskLater = #{ ...taskNow, status: "DONE" } - 4 | -Cause: [1:17-1:18]: '#' not followed by identifier" -`; - -exports[`spread.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -const formData = #{ title: "Implement all the things" } -const taskNow = #{ id: 42, status: "WIP", ...formData } -const taskLater = #{ ...taskNow, status: "DONE" } - -// A reminder: The ordering of keys in record literals does not affect equality (and is not retained) -assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 }) - -=====================================output===================================== -const formData = #{ title: "Implement all the things" }; -const taskNow = #{ id: 42, status: "WIP", ...formData }; -const taskLater = #{ ...taskNow, status: "DONE" }; - -// A reminder: The ordering of keys in record literals does not affect equality (and is not retained) -assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 }); - -================================================================================ -`; - -exports[`syntax.js [acorn] format 1`] = ` -"Unexpected character '{' (1:2) -> 1 | #{} - | ^ - 2 | #{ a: 1, b: 2 } - 3 | #{ a: 1, b: #[2, 3, #{ c: 4 }] } - 4 | -Cause: Unexpected character '{' (1:1)" -`; - -exports[`syntax.js [espree] format 1`] = ` -"Unexpected character '{' (1:2) -> 1 | #{} - | ^ - 2 | #{ a: 1, b: 2 } - 3 | #{ a: 1, b: #[2, 3, #{ c: 4 }] } - 4 | -Cause: Unexpected character '{'" -`; - -exports[`syntax.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:1) -> 1 | #{} - | ^ - 2 | #{ a: 1, b: 2 } - 3 | #{ a: 1, b: #[2, 3, #{ c: 4 }] } - 4 | -Cause: [1:0-1:1]: '#' not followed by identifier" -`; - -exports[`syntax.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -#{} -#{ a: 1, b: 2 } -#{ a: 1, b: #[2, 3, #{ c: 4 }] } - -=====================================output===================================== -#{}; -#{ a: 1, b: 2 }; -#{ a: 1, b: #[2, 3, #{ c: 4 }] }; - -================================================================================ -`; diff --git a/tests/format/js/record/computed.js b/tests/format/js/record/computed.js deleted file mode 100644 index d5aed608a..000000000 --- a/tests/format/js/record/computed.js +++ /dev/null @@ -1,9 +0,0 @@ -const key = "a"; -assert(#{ [key]: 1 } === #{ a: 1 }) -assert(#{ [key.toUpperCase()]: 1 } === #{ A: 1 }) - -assert(#{ [true]: 1 } === #{ true: 1 }) -assert(#{ [true]: 1 } === #{ ["true"]: 1 }) - -assert(#{ [1 + 1]: "two" } === #{ 2: "two" }) -assert(#{ [9 + 1]: "ten" } === #{ ["10"]: "ten" }) diff --git a/tests/format/js/record/destructuring.js b/tests/format/js/record/destructuring.js deleted file mode 100644 index 05acf3444..000000000 --- a/tests/format/js/record/destructuring.js +++ /dev/null @@ -1,9 +0,0 @@ -const { a, b } = #{ a: 1, b: 2 }; -assert(a === 1); -assert(b === 2); - -const { a, ...rest } = #{ a: 1, b: 2, c: 3 }; -assert(a === 1); -assert(typeof rest === "object"); -assert(rest.b === 2); -assert(rest.c === 3); diff --git a/tests/format/js/record/format.test.js b/tests/format/js/record/format.test.js deleted file mode 100644 index e59778563..000000000 --- a/tests/format/js/record/format.test.js +++ /dev/null @@ -1,3 +0,0 @@ -runFormatTest(import.meta, ["babel"], { - errors: { acorn: true, espree: true, meriyah: true }, -}); diff --git a/tests/format/js/record/record.js b/tests/format/js/record/record.js deleted file mode 100644 index 256134e93..000000000 --- a/tests/format/js/record/record.js +++ /dev/null @@ -1,16 +0,0 @@ -const record1 = #{ - a: 1, - b: 2, - c: 3, -}; - -const record2 = #{...record1, b: 5}; - -assert(record1.a === 1); -assert(record1["a"] === 1); -assert(record1 !== record2); -assert(record2 === #{ a: 1, c: 3, b: 5 }); -assert(record1?.a === 1); -assert(record1?.d === undefined); -assert(record1?.d ?? 5 === 5); -assert(record1.d?.a === undefined); diff --git a/tests/format/js/record/shorthand.js b/tests/format/js/record/shorthand.js deleted file mode 100644 index 29eee1361..000000000 --- a/tests/format/js/record/shorthand.js +++ /dev/null @@ -1,3 +0,0 @@ -const url = "https://github.com/tc39/proposal-record-tuple"; -const record = #{ url } -console.log(record.url) // https://github.com/tc39/proposal-record-tuple diff --git a/tests/format/js/record/spread.js b/tests/format/js/record/spread.js deleted file mode 100644 index 31bfe0c76..000000000 --- a/tests/format/js/record/spread.js +++ /dev/null @@ -1,6 +0,0 @@ -const formData = #{ title: "Implement all the things" } -const taskNow = #{ id: 42, status: "WIP", ...formData } -const taskLater = #{ ...taskNow, status: "DONE" } - -// A reminder: The ordering of keys in record literals does not affect equality (and is not retained) -assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 }) diff --git a/tests/format/js/record/syntax.js b/tests/format/js/record/syntax.js deleted file mode 100644 index 14db6d07b..000000000 --- a/tests/format/js/record/syntax.js +++ /dev/null @@ -1,3 +0,0 @@ -#{} -#{ a: 1, b: 2 } -#{ a: 1, b: #[2, 3, #{ c: 4 }] } diff --git a/tests/format/js/tuple/__snapshots__/format.test.js.snap b/tests/format/js/tuple/__snapshots__/format.test.js.snap deleted file mode 100644 index 087d3c260..000000000 --- a/tests/format/js/tuple/__snapshots__/format.test.js.snap +++ /dev/null @@ -1,263 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`destructuring.js [acorn] format 1`] = ` -"Unexpected character '[' (1:17) -> 1 | const [a, b] = #[1, 2]; - | ^ - 2 | assert(a === 1); - 3 | assert(b === 2); - 4 | -Cause: Unexpected character '[' (1:16)" -`; - -exports[`destructuring.js [espree] format 1`] = ` -"Unexpected character '[' (1:17) -> 1 | const [a, b] = #[1, 2]; - | ^ - 2 | assert(a === 1); - 3 | assert(b === 2); - 4 | -Cause: Unexpected character '['" -`; - -exports[`destructuring.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:16) -> 1 | const [a, b] = #[1, 2]; - | ^ - 2 | assert(a === 1); - 3 | assert(b === 2); - 4 | -Cause: [1:15-1:16]: '#' not followed by identifier" -`; - -exports[`destructuring.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -const [a, b] = #[1, 2]; -assert(a === 1); -assert(b === 2); - -const [a, ...rest] = #[1, 2, 3]; -assert(a === 1); -assert(Array.isArray(rest)); -assert(rest[0] === 2); -assert(rest[1] === 3); - -=====================================output===================================== -const [a, b] = #[1, 2]; -assert(a === 1); -assert(b === 2); - -const [a, ...rest] = #[1, 2, 3]; -assert(a === 1); -assert(Array.isArray(rest)); -assert(rest[0] === 2); -assert(rest[1] === 3); - -================================================================================ -`; - -exports[`invalid-tuple-holes.js [__babel_estree] format 1`] = ` -"Unexpected token ','. (1:4) -> 1 | #[,] - | ^ - 2 | -Cause: Unexpected token ','. (1:3)" -`; - -exports[`invalid-tuple-holes.js [acorn] format 1`] = ` -"Unexpected character '[' (1:2) -> 1 | #[,] - | ^ - 2 | -Cause: Unexpected character '[' (1:1)" -`; - -exports[`invalid-tuple-holes.js [babel] format 1`] = ` -"Unexpected token ','. (1:4) -> 1 | #[,] - | ^ - 2 | -Cause: Unexpected token ','. (1:3)" -`; - -exports[`invalid-tuple-holes.js [espree] format 1`] = ` -"Unexpected character '[' (1:2) -> 1 | #[,] - | ^ - 2 | -Cause: Unexpected character '['" -`; - -exports[`invalid-tuple-holes.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:1) -> 1 | #[,] - | ^ - 2 | -Cause: [1:0-1:1]: '#' not followed by identifier" -`; - -exports[`syntax.js [acorn] format 1`] = ` -"Unexpected character '[' (1:2) -> 1 | #[] - | ^ - 2 | #[1, 2] - 3 | #[1, 2, #{ a: 3 }] - 4 | -Cause: Unexpected character '[' (1:1)" -`; - -exports[`syntax.js [espree] format 1`] = ` -"Unexpected character '[' (1:2) -> 1 | #[] - | ^ - 2 | #[1, 2] - 3 | #[1, 2, #{ a: 3 }] - 4 | -Cause: Unexpected character '['" -`; - -exports[`syntax.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:1) -> 1 | #[] - | ^ - 2 | #[1, 2] - 3 | #[1, 2, #{ a: 3 }] - 4 | -Cause: [1:0-1:1]: '#' not followed by identifier" -`; - -exports[`syntax.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -#[] -#[1, 2] -#[1, 2, #{ a: 3 }] - -=====================================output===================================== -#[]; -#[1, 2]; -#[1, 2, #{ a: 3 }]; - -================================================================================ -`; - -exports[`tuple.js [acorn] format 1`] = ` -"Unexpected character '[' (1:17) -> 1 | const tuple1 = #[1, 2, 3]; - | ^ - 2 | - 3 | assert(tuple1[0] === 1); - 4 | -Cause: Unexpected character '[' (1:16)" -`; - -exports[`tuple.js [espree] format 1`] = ` -"Unexpected character '[' (1:17) -> 1 | const tuple1 = #[1, 2, 3]; - | ^ - 2 | - 3 | assert(tuple1[0] === 1); - 4 | -Cause: Unexpected character '['" -`; - -exports[`tuple.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:16) -> 1 | const tuple1 = #[1, 2, 3]; - | ^ - 2 | - 3 | assert(tuple1[0] === 1); - 4 | -Cause: [1:15-1:16]: '#' not followed by identifier" -`; - -exports[`tuple.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -const tuple1 = #[1, 2, 3]; - -assert(tuple1[0] === 1); - -const tuple2 = tuple1.with(0, 2); -assert(tuple1 !== tuple2); -assert(tuple2 === #[2, 2, 3]); - -const tuple3 = #[1, ...tuple2]; -assert(tuple3 === #[1, 2, 2, 3]); - -const tuple4 = tuple3.pushed(4); -assert(tuple4 === #[1, 2, 2, 3, 4]); - -assert(tuple4.first() === 1); -const tuple5 = tuple4.popped(); -assert(tuple5 === #[2, 2, 3, 4]); - -=====================================output===================================== -const tuple1 = #[1, 2, 3]; - -assert(tuple1[0] === 1); - -const tuple2 = tuple1.with(0, 2); -assert(tuple1 !== tuple2); -assert(tuple2 === #[2, 2, 3]); - -const tuple3 = #[1, ...tuple2]; -assert(tuple3 === #[1, 2, 2, 3]); - -const tuple4 = tuple3.pushed(4); -assert(tuple4 === #[1, 2, 2, 3, 4]); - -assert(tuple4.first() === 1); -const tuple5 = tuple4.popped(); -assert(tuple5 === #[2, 2, 3, 4]); - -================================================================================ -`; - -exports[`tuple-trailing-comma.js [acorn] format 1`] = ` -"Unexpected character '[' (1:2) -> 1 | #[1,] - | ^ - 2 | -Cause: Unexpected character '[' (1:1)" -`; - -exports[`tuple-trailing-comma.js [espree] format 1`] = ` -"Unexpected character '[' (1:2) -> 1 | #[1,] - | ^ - 2 | -Cause: Unexpected character '['" -`; - -exports[`tuple-trailing-comma.js [meriyah] format 1`] = ` -"'#' not followed by identifier (1:1) -> 1 | #[1,] - | ^ - 2 | -Cause: [1:0-1:1]: '#' not followed by identifier" -`; - -exports[`tuple-trailing-comma.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -#[1,] - -=====================================output===================================== -#[1]; - -================================================================================ -`; diff --git a/tests/format/js/tuple/destructuring.js b/tests/format/js/tuple/destructuring.js deleted file mode 100644 index 94404a53a..000000000 --- a/tests/format/js/tuple/destructuring.js +++ /dev/null @@ -1,9 +0,0 @@ -const [a, b] = #[1, 2]; -assert(a === 1); -assert(b === 2); - -const [a, ...rest] = #[1, 2, 3]; -assert(a === 1); -assert(Array.isArray(rest)); -assert(rest[0] === 2); -assert(rest[1] === 3); diff --git a/tests/format/js/tuple/format.test.js b/tests/format/js/tuple/format.test.js deleted file mode 100644 index 307027797..000000000 --- a/tests/format/js/tuple/format.test.js +++ /dev/null @@ -1,9 +0,0 @@ -runFormatTest(import.meta, ["babel"], { - errors: { - babel: ["invalid-tuple-holes.js"], - __babel_estree: ["invalid-tuple-holes.js"], - acorn: true, - espree: true, - meriyah: true, - }, -}); diff --git a/tests/format/js/tuple/invalid-tuple-holes.js b/tests/format/js/tuple/invalid-tuple-holes.js deleted file mode 100644 index 621be6b2e..000000000 --- a/tests/format/js/tuple/invalid-tuple-holes.js +++ /dev/null @@ -1 +0,0 @@ -#[,] diff --git a/tests/format/js/tuple/syntax.js b/tests/format/js/tuple/syntax.js deleted file mode 100644 index cb60aecba..000000000 --- a/tests/format/js/tuple/syntax.js +++ /dev/null @@ -1,3 +0,0 @@ -#[] -#[1, 2] -#[1, 2, #{ a: 3 }] diff --git a/tests/format/js/tuple/tuple-trailing-comma.js b/tests/format/js/tuple/tuple-trailing-comma.js deleted file mode 100644 index 3e938abaf..000000000 --- a/tests/format/js/tuple/tuple-trailing-comma.js +++ /dev/null @@ -1 +0,0 @@ -#[1,] diff --git a/tests/format/js/tuple/tuple.js b/tests/format/js/tuple/tuple.js deleted file mode 100644 index dcddf8b94..000000000 --- a/tests/format/js/tuple/tuple.js +++ /dev/null @@ -1,17 +0,0 @@ -const tuple1 = #[1, 2, 3]; - -assert(tuple1[0] === 1); - -const tuple2 = tuple1.with(0, 2); -assert(tuple1 !== tuple2); -assert(tuple2 === #[2, 2, 3]); - -const tuple3 = #[1, ...tuple2]; -assert(tuple3 === #[1, 2, 2, 3]); - -const tuple4 = tuple3.pushed(4); -assert(tuple4 === #[1, 2, 2, 3, 4]); - -assert(tuple4.first() === 1); -const tuple5 = tuple4.popped(); -assert(tuple5 === #[2, 2, 3, 4]); diff --git a/tests/format/jsx/tuple/__snapshots__/format.test.js.snap b/tests/format/jsx/tuple/__snapshots__/format.test.js.snap deleted file mode 100644 index 6fcc346a0..000000000 --- a/tests/format/jsx/tuple/__snapshots__/format.test.js.snap +++ /dev/null @@ -1,61 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`tuple.js [acorn] format 1`] = ` -"Unexpected character '[' (6:6) - 4 | ] - 5 | -> 6 | a = #[ - | ^ - 7 |
, - 8 |
, - 9 | ] -Cause: Unexpected character '[' (6:5)" -`; - -exports[`tuple.js [espree] format 1`] = ` -"Unexpected character '[' (6:6) - 4 | ] - 5 | -> 6 | a = #[ - | ^ - 7 |
, - 8 |
, - 9 | ] -Cause: Unexpected character '['" -`; - -exports[`tuple.js [meriyah] format 1`] = ` -"'#' not followed by identifier (6:5) - 4 | ] - 5 | -> 6 | a = #[ - | ^ - 7 |
, - 8 |
, - 9 | ] -Cause: [6:4-6:5]: '#' not followed by identifier" -`; - -exports[`tuple.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -a = [ -
, -
, -] - -a = #[ -
, -
, -] - -=====================================output===================================== -a = [
,
]; - -a = #[
,
]; - -================================================================================ -`; diff --git a/tests/format/jsx/tuple/format.test.js b/tests/format/jsx/tuple/format.test.js deleted file mode 100644 index 8d7f12ea1..000000000 --- a/tests/format/jsx/tuple/format.test.js +++ /dev/null @@ -1,7 +0,0 @@ -runFormatTest(import.meta, ["babel"], { - errors: { - acorn: ["tuple.js"], - espree: ["tuple.js"], - meriyah: ["tuple.js"], - }, -}); diff --git a/tests/format/jsx/tuple/tuple.js b/tests/format/jsx/tuple/tuple.js deleted file mode 100644 index d9414e3be..000000000 --- a/tests/format/jsx/tuple/tuple.js +++ /dev/null @@ -1,9 +0,0 @@ -a = [ -
, -
, -] - -a = #[ -
, -
, -] diff --git a/tests/format/misc/errors/js/__snapshots__/format.test.js.snap b/tests/format/misc/errors/js/__snapshots__/format.test.js.snap index f6e769761..6b9096a87 100644 --- a/tests/format/misc/errors/js/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/__snapshots__/format.test.js.snap @@ -145,10 +145,9 @@ Cause: Unexpected token (5:11)" `; exports[`snippet: #7 [babel] format 1`] = ` -"Unexpected token (1:7) +"Unexpected token. (1:7) > 1 | const #{ a, b } = #{ a: 1, b: 2 }; - | ^ -Cause: Unexpected token (1:6)" + | ^" `; exports[`snippet: #8 [babel] format 1`] = ` @@ -159,10 +158,10 @@ Cause: Unexpected token (1:6)" `; exports[`snippet: #9 [babel] format 1`] = ` -"Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'. (1:1) +"Unexpected token (1:2) > 1 | [| 1 |] - | ^ -Cause: Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'. (1:0)" + | ^ +Cause: Unexpected token (1:1)" `; exports[`snippet: #10 [babel] format 1`] = ` diff --git a/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap b/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap index 884cbce19..d05c147d5 100644 --- a/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/js/record/__snapshots__/format.test.js.snap @@ -8,10 +8,9 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #0 [babel] format 1`] = ` -"Only properties and spread elements are allowed in record definitions. (1:3) +"Unexpected token. (1:1) > 1 | #{a() {}} - | ^ -Cause: Only properties and spread elements are allowed in record definitions. (1:2)" + | ^" `; exports[`snippet: #0 [espree] format 1`] = ` @@ -36,10 +35,9 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #1 [babel] format 1`] = ` -"Only properties and spread elements are allowed in record definitions. (1:3) +"Unexpected token. (1:1) > 1 | #{async b() {}} - | ^ -Cause: Only properties and spread elements are allowed in record definitions. (1:2)" + | ^" `; exports[`snippet: #1 [espree] format 1`] = ` @@ -64,10 +62,9 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #2 [babel] format 1`] = ` -"Only properties and spread elements are allowed in record definitions. (1:3) +"Unexpected token. (1:1) > 1 | #{get c() {}} - | ^ -Cause: Only properties and spread elements are allowed in record definitions. (1:2)" + | ^" `; exports[`snippet: #2 [espree] format 1`] = ` @@ -92,10 +89,9 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #3 [babel] format 1`] = ` -"Only properties and spread elements are allowed in record definitions. (1:3) +"Unexpected token. (1:1) > 1 | #{set d(_) {}} - | ^ -Cause: Only properties and spread elements are allowed in record definitions. (1:2)" + | ^" `; exports[`snippet: #3 [espree] format 1`] = ` @@ -120,10 +116,9 @@ Cause: Unexpected character '{' (1:1)" `; exports[`snippet: #4 [babel] format 1`] = ` -"Only properties and spread elements are allowed in record definitions. (1:3) +"Unexpected token. (1:1) > 1 | #{*e() {}} - | ^ -Cause: Only properties and spread elements are allowed in record definitions. (1:2)" + | ^" `; exports[`snippet: #4 [espree] format 1`] = ` diff --git a/tests/format/typescript/cast/__snapshots__/format.test.js.snap b/tests/format/typescript/cast/__snapshots__/format.test.js.snap index b46abb429..29bdf2ec3 100644 --- a/tests/format/typescript/cast/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/cast/__snapshots__/format.test.js.snap @@ -1,5 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`array-and-object.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +breakAfterCast = | undefined>(permissions)[receiverType]; + +testObjLiteral = | undefined>{ prop1: "myPropVal" }; + +=====================================output===================================== +breakAfterCast = | undefined>( + (permissions)[receiverType] +); + +testObjLiteral = | undefined>{ prop1: "myPropVal" }; + +================================================================================ +`; + exports[`as-const.ts format 1`] = ` ====================================options===================================== parsers: ["babel-ts", "typescript"] @@ -375,40 +395,3 @@ function* g() { ================================================================================ `; - -exports[`tuple-and-record.ts [typescript] format 1`] = ` -"Invalid character. (2:74) - 1 | breakAfterCast = | undefined>(permissions)[receiverType]; -> 2 | breakAfterCast = | undefined>(permissions)(#[receiverType]); - | ^ - 3 | - 4 | testObjLiteral = | undefined>{ prop1: "myPropVal" }; - 5 | testObjLiteral = | undefined>#{ prop1: "myPropVal" }; -Cause: Invalid character." -`; - -exports[`tuple-and-record.ts format 1`] = ` -====================================options===================================== -parsers: ["babel-ts", "typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -breakAfterCast = | undefined>(permissions)[receiverType]; -breakAfterCast = | undefined>(permissions)(#[receiverType]); - -testObjLiteral = | undefined>{ prop1: "myPropVal" }; -testObjLiteral = | undefined>#{ prop1: "myPropVal" }; - -=====================================output===================================== -breakAfterCast = | undefined>( - (permissions)[receiverType] -); -breakAfterCast = | undefined>( - (permissions)(#[receiverType]) -); - -testObjLiteral = | undefined>{ prop1: "myPropVal" }; -testObjLiteral = | undefined>#{ prop1: "myPropVal" }; - -================================================================================ -`; diff --git a/tests/format/typescript/cast/array-and-object.ts b/tests/format/typescript/cast/array-and-object.ts new file mode 100644 index 000000000..28d508a57 --- /dev/null +++ b/tests/format/typescript/cast/array-and-object.ts @@ -0,0 +1,3 @@ +breakAfterCast = | undefined>(permissions)[receiverType]; + +testObjLiteral = | undefined>{ prop1: "myPropVal" }; diff --git a/tests/format/typescript/cast/format.test.js b/tests/format/typescript/cast/format.test.js index 3e152f333..083abcf04 100644 --- a/tests/format/typescript/cast/format.test.js +++ b/tests/format/typescript/cast/format.test.js @@ -1,3 +1 @@ -runFormatTest(import.meta, ["babel-ts", "typescript"], { - errors: { typescript: ["tuple-and-record.ts"] }, -}); +runFormatTest(import.meta, ["babel-ts", "typescript"]); diff --git a/tests/format/typescript/cast/tuple-and-record.ts b/tests/format/typescript/cast/tuple-and-record.ts deleted file mode 100644 index 5ca4db06c..000000000 --- a/tests/format/typescript/cast/tuple-and-record.ts +++ /dev/null @@ -1,5 +0,0 @@ -breakAfterCast = | undefined>(permissions)[receiverType]; -breakAfterCast = | undefined>(permissions)(#[receiverType]); - -testObjLiteral = | undefined>{ prop1: "myPropVal" }; -testObjLiteral = | undefined>#{ prop1: "myPropVal" }; diff --git a/tests/unit/__snapshots__/visitor-keys.js.snap b/tests/unit/__snapshots__/visitor-keys.js.snap index 8bfe97f92..702675cd5 100644 --- a/tests/unit/__snapshots__/visitor-keys.js.snap +++ b/tests/unit/__snapshots__/visitor-keys.js.snap @@ -700,9 +700,6 @@ exports[`visitor keys estree 1`] = ` "id", "qualification", ], - "RecordExpression": [ - "properties", - ], "RegExpLiteral": [], "RestElement": [ "argument", @@ -1047,9 +1044,6 @@ exports[`visitor keys estree 1`] = ` "finalizer", "handler", ], - "TupleExpression": [ - "elements", - ], "TupleTypeAnnotation": [ "elementTypes", "types",