diff --git a/.eslintrc.js b/.eslintrc.js index b2932680e..88d21bf78 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -235,7 +235,7 @@ module.exports = { functions: ["hasComment", "getComments"], }, "src/language-js/pragma.js", - "src/language-js/parse/postprocess.js", + "src/language-js/parse/postprocess/*.js", "src/language-js/parse/babel.js", "src/language-js/parse/meriyah.js", "src/language-js/parse/json.js", diff --git a/package.json b/package.json index eec595ef9..04ef618a3 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@babel/parser": "7.15.8", "@glimmer/syntax": "0.82.0", "@iarna/toml": "2.2.5", - "@typescript-eslint/typescript-estree": "4.32.0", + "@typescript-eslint/typescript-estree": "5.1.0", "angular-estree-parser": "2.5.0", "angular-html-parser": "1.8.0", "camelcase": "6.2.0", diff --git a/src/language-js/comments.js b/src/language-js/comments.js index 5bac9b1a8..d1eb48b03 100644 --- a/src/language-js/comments.js +++ b/src/language-js/comments.js @@ -460,7 +460,7 @@ function handleMethodNameComments({ (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "PropertyDefinition" || - enclosingNode.type === "TSAbstractClassProperty" || + enclosingNode.type === "TSAbstractPropertyDefinition" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "TSDeclareMethod" || enclosingNode.type === "MethodDefinition") diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 31f7b7a07..806021042 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -7,7 +7,7 @@ const { } = require("../../common/util.js"); const createParser = require("./utils/create-parser.js"); const createBabelParseError = require("./utils/create-babel-parse-error.js"); -const postprocess = require("./postprocess.js"); +const postprocess = require("./postprocess/index.js"); const jsonParsers = require("./json.js"); /** diff --git a/src/language-js/parse/espree.js b/src/language-js/parse/espree.js index 3aa3b79b0..2d3a558d7 100644 --- a/src/language-js/parse/espree.js +++ b/src/language-js/parse/espree.js @@ -4,7 +4,7 @@ const createError = require("../../common/parser-create-error.js"); const tryCombinations = require("../../utils/try-combinations.js"); const createParser = require("./utils/create-parser.js"); const replaceHashbang = require("./utils/replace-hashbang.js"); -const postprocess = require("./postprocess.js"); +const postprocess = require("./postprocess/index.js"); /** @type {import("espree").Options} */ const parseOptions = { diff --git a/src/language-js/parse/flow.js b/src/language-js/parse/flow.js index 5604ee1aa..c97d98447 100644 --- a/src/language-js/parse/flow.js +++ b/src/language-js/parse/flow.js @@ -3,7 +3,7 @@ const createError = require("../../common/parser-create-error.js"); const createParser = require("./utils/create-parser.js"); const replaceHashbang = require("./utils/replace-hashbang.js"); -const postprocess = require("./postprocess.js"); +const postprocess = require("./postprocess/index.js"); // https://github.com/facebook/flow/tree/master/packages/flow-parser#options const parseOptions = { diff --git a/src/language-js/parse/meriyah.js b/src/language-js/parse/meriyah.js index cb5d2c3ce..08f46b872 100644 --- a/src/language-js/parse/meriyah.js +++ b/src/language-js/parse/meriyah.js @@ -3,7 +3,7 @@ const createError = require("../../common/parser-create-error.js"); const tryCombinations = require("../../utils/try-combinations.js"); const createParser = require("./utils/create-parser.js"); -const postprocess = require("./postprocess.js"); +const postprocess = require("./postprocess/index.js"); // https://github.com/meriyah/meriyah/blob/4676f60b6c149d7082bde2c9147f9ae2359c8075/src/parser.ts#L185 const parseOptions = { diff --git a/src/language-js/parse/postprocess.js b/src/language-js/parse/postprocess/index.js similarity index 64% rename from src/language-js/parse/postprocess.js rename to src/language-js/parse/postprocess/index.js index b4fb50708..cdf537a9d 100644 --- a/src/language-js/parse/postprocess.js +++ b/src/language-js/parse/postprocess/index.js @@ -1,54 +1,18 @@ "use strict"; -const { - getLast, - getNextNonSpaceNonCommentCharacter, -} = require("../../common/util.js"); -const createError = require("../../common/parser-create-error.js"); -const { locStart, locEnd } = require("../loc.js"); -const { isTypeCastComment } = require("../comments.js"); +const { getLast } = require("../../../common/util.js"); +const { locStart, locEnd } = require("../../loc.js"); +const { isTypeCastComment } = require("../../comments.js"); +const visitNode = require("./visitNode.js"); +const { throwErrorForInvalidNodes } = require("./typescript.js"); function postprocess(ast, options) { - // Invalid decorators are removed since `@typescript-eslint/typescript-estree` v4 - // https://github.com/typescript-eslint/typescript-eslint/pull/2375 - if (options.parser === "typescript" && options.originalText.includes("@")) { - const { esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap } = - options.tsParseResult; - ast = visitNode(ast, (node) => { - const tsNode = esTreeNodeToTSNodeMap.get(node); - if (!tsNode) { - return; - } - const tsDecorators = tsNode.decorators; - if (!Array.isArray(tsDecorators)) { - return; - } - // `esTreeNodeToTSNodeMap.get(ClassBody)` and `esTreeNodeToTSNodeMap.get(ClassDeclaration)` has the same tsNode - const esTreeNode = tsNodeToESTreeNodeMap.get(tsNode); - if (esTreeNode !== node) { - return; - } - const esTreeDecorators = esTreeNode.decorators; - if ( - !Array.isArray(esTreeDecorators) || - esTreeDecorators.length !== tsDecorators.length || - tsDecorators.some((tsDecorator) => { - const esTreeDecorator = tsNodeToESTreeNodeMap.get(tsDecorator); - return ( - !esTreeDecorator || !esTreeDecorators.includes(esTreeDecorator) - ); - }) - ) { - const { start, end } = esTreeNode.loc; - throw createError( - "Leading decorators must be attached to a class declaration", - { - start: { line: start.line, column: start.column + 1 }, - end: { line: end.line, column: end.column + 1 }, - } - ); - } - }); + if ( + options.parser === "typescript" && + // decorators or abstract properties + /@|abstract/.test(options.originalText) + ) { + throwErrorForInvalidNodes(ast, options); } // Keep Babel's non-standard ParenthesizedExpression nodes only if they have Closure-style type cast comments. @@ -138,20 +102,6 @@ function postprocess(ast, options) { ]; break; } - case "ClassProperty": - // TODO: Temporary auto-generated node type. To remove when typescript-estree has proper support for private fields. - if ( - node.key && - node.key.type === "TSPrivateIdentifier" && - getNextNonSpaceNonCommentCharacter( - options.originalText, - node.key, - locEnd - ) === "?" - ) { - node.optional = true; - } - break; // For hack-style pipeline case "TopicReference": options.__isUsingHackPipeline = true; @@ -195,32 +145,6 @@ function transformChainExpression(node) { return node; } -function visitNode(node, fn) { - let entries; - - if (Array.isArray(node)) { - entries = node.entries(); - } else if ( - node && - typeof node === "object" && - typeof node.type === "string" - ) { - entries = Object.entries(node); - } else { - return node; - } - - for (const [key, child] of entries) { - node[key] = visitNode(child, fn); - } - - if (Array.isArray(node)) { - return node; - } - - return fn(node) || node; -} - function isUnbalancedLogicalTree(node) { return ( node.type === "LogicalExpression" && diff --git a/src/language-js/parse/postprocess/typescript.js b/src/language-js/parse/postprocess/typescript.js new file mode 100644 index 000000000..2ee9bcac2 --- /dev/null +++ b/src/language-js/parse/postprocess/typescript.js @@ -0,0 +1,80 @@ +"use strict"; + +const createError = require("../../../common/parser-create-error.js"); +const visitNode = require("./visitNode.js"); + +function throwSyntaxError(node, message) { + const { start, end } = node.loc; + throw createError(message, { + start: { line: start.line, column: start.column + 1 }, + end: { line: end.line, column: end.column + 1 }, + }); +} + +// Invalid decorators are removed since `@typescript-eslint/typescript-estree` v4 +// https://github.com/typescript-eslint/typescript-eslint/pull/2375 +function throwErrorForInvalidDecorator( + tsNode, + esTreeNode, + tsNodeToESTreeNodeMap +) { + const tsDecorators = tsNode.decorators; + if (!Array.isArray(tsDecorators)) { + return; + } + const esTreeDecorators = esTreeNode.decorators; + if ( + !Array.isArray(esTreeDecorators) || + esTreeDecorators.length !== tsDecorators.length || + tsDecorators.some((tsDecorator) => { + const esTreeDecorator = tsNodeToESTreeNodeMap.get(tsDecorator); + return !esTreeDecorator || !esTreeDecorators.includes(esTreeDecorator); + }) + ) { + throwSyntaxError( + esTreeNode, + "Leading decorators must be attached to a class declaration" + ); + } +} + +// Values of abstract property is removed since `@typescript-eslint/typescript-estree` v5 +// https://github.com/typescript-eslint/typescript-eslint/releases/tag/v5.0.0 +function throwErrorForInvalidAbstractProperty(tsNode, esTreeNode) { + const SYNTAX_KIND_PROPERTY_DEFINITION = 165; + const SYNTAX_KIND_ABSTRACT_KEYWORD = 126; + if ( + tsNode.kind !== SYNTAX_KIND_PROPERTY_DEFINITION || + (tsNode.modifiers && + !tsNode.modifiers.some( + (modifier) => modifier.kind === SYNTAX_KIND_ABSTRACT_KEYWORD + )) + ) { + return; + } + if (tsNode.initializer && esTreeNode.value === null) { + throwSyntaxError( + esTreeNode, + "Abstract property cannot have an initializer" + ); + } +} + +function throwErrorForInvalidNodes(ast, options) { + const { esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap } = + options.tsParseResult; + ast = visitNode(ast, (node) => { + const tsNode = esTreeNodeToTSNodeMap.get(node); + if (!tsNode) { + return; + } + const esTreeNode = tsNodeToESTreeNodeMap.get(tsNode); + if (esTreeNode !== node) { + return; + } + throwErrorForInvalidDecorator(tsNode, esTreeNode, tsNodeToESTreeNodeMap); + throwErrorForInvalidAbstractProperty(tsNode, esTreeNode); + }); +} + +module.exports = { throwErrorForInvalidNodes }; diff --git a/src/language-js/parse/postprocess/visitNode.js b/src/language-js/parse/postprocess/visitNode.js new file mode 100644 index 000000000..d916157e5 --- /dev/null +++ b/src/language-js/parse/postprocess/visitNode.js @@ -0,0 +1,29 @@ +"use strict"; + +function visitNode(node, fn) { + let entries; + + if (Array.isArray(node)) { + entries = node.entries(); + } else if ( + node && + typeof node === "object" && + typeof node.type === "string" + ) { + entries = Object.entries(node); + } else { + return node; + } + + for (const [key, child] of entries) { + node[key] = visitNode(child, fn); + } + + if (Array.isArray(node)) { + return node; + } + + return fn(node) || node; +} + +module.exports = visitNode; diff --git a/src/language-js/parse/typescript.js b/src/language-js/parse/typescript.js index fb15bf4e5..b3240918b 100644 --- a/src/language-js/parse/typescript.js +++ b/src/language-js/parse/typescript.js @@ -4,7 +4,7 @@ const createError = require("../../common/parser-create-error.js"); const tryCombinations = require("../../utils/try-combinations.js"); const createParser = require("./utils/create-parser.js"); const replaceHashbang = require("./utils/replace-hashbang.js"); -const postprocess = require("./postprocess.js"); +const postprocess = require("./postprocess/index.js"); /** @type {import("@typescript-eslint/typescript-estree").TSESTreeOptions} */ const parseOptions = { @@ -13,7 +13,6 @@ const parseOptions = { loc: true, range: true, comment: true, - useJSXTextNode: true, jsx: true, tokens: true, loggerFn: false, diff --git a/src/language-js/print/binaryish.js b/src/language-js/print/binaryish.js index e5f259e9b..1b71976c6 100644 --- a/src/language-js/print/binaryish.js +++ b/src/language-js/print/binaryish.js @@ -112,7 +112,7 @@ function printBinaryishExpression(path, options, print) { parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "PropertyDefinition" || - parent.type === "TSAbstractClassProperty" || + parent.type === "TSAbstractPropertyDefinition" || parent.type === "ClassPrivateProperty" || isObjectProperty(parent); diff --git a/src/language-js/print/class.js b/src/language-js/print/class.js index 017f9a36d..66ad25052 100644 --- a/src/language-js/print/class.js +++ b/src/language-js/print/class.js @@ -204,7 +204,7 @@ function printClassProperty(path, options, print) { if (node.static) { parts.push("static "); } - if (node.type === "TSAbstractClassProperty" || node.abstract) { + if (node.type === "TSAbstractPropertyDefinition" || node.abstract) { parts.push("abstract "); } if (node.override) { diff --git a/src/language-js/print/statement.js b/src/language-js/print/statement.js index c7573faf7..a5527760b 100644 --- a/src/language-js/print/statement.js +++ b/src/language-js/print/statement.js @@ -215,7 +215,7 @@ function shouldPrintSemicolonAfterClassProperty(node, nextNode) { switch (nextNode.type) { case "ClassProperty": case "PropertyDefinition": - case "TSAbstractClassProperty": + case "TSAbstractPropertyDefinition": return nextNode.computed; case "MethodDefinition": // Flow case "TSAbstractMethodDefinition": // TypeScript diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 748166ad7..9d5547775 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -113,7 +113,7 @@ function printTypescript(path, options, print) { case "TSAbstractMethodDefinition": case "TSDeclareMethod": return printClassMethod(path, options, print); - case "TSAbstractClassProperty": + case "TSAbstractPropertyDefinition": return printClassProperty(path, options, print); case "TSInterfaceHeritage": case "TSExpressionWithTypeArguments": // Babel AST @@ -486,9 +486,6 @@ function printTypescript(path, options, print) { return parts; } - // TODO: Temporary auto-generated node type. To remove when typescript-estree has proper support for private fields. - case "TSPrivateIdentifier": - return node.escapedText; case "TSConditionalType": return printTernary(path, options, print); diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 2db75d1e2..faf2aa6af 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -96,7 +96,7 @@ function genericPrint(path, options, print, args) { type === "ClassPrivateMethod" || type === "ClassProperty" || type === "PropertyDefinition" || - type === "TSAbstractClassProperty" || + type === "TSAbstractPropertyDefinition" || type === "ClassPrivateProperty" || type === "MethodDefinition" || type === "TSAbstractMethodDefinition" || diff --git a/src/language-js/utils.js b/src/language-js/utils.js index df1b02889..c7946bef7 100644 --- a/src/language-js/utils.js +++ b/src/language-js/utils.js @@ -708,8 +708,8 @@ function isStringPropSafeToUnquote(node, options) { // With `--strictPropertyInitialization`, TS treats properties with quoted names differently than unquoted ones. // See https://github.com/microsoft/TypeScript/pull/20075 !( - (options.parser === "typescript" || options.parser === "babel-ts") && - node.type === "ClassProperty" + (options.parser === "babel-ts" && node.type === "ClassProperty") || + (options.parser === "typescript" && node.type === "PropertyDefinition") )) || (isSimpleNumber(node.key.value) && String(Number(node.key.value)) === node.key.value && diff --git a/tests/format/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap index bea1eaebd..703b695cd 100644 --- a/tests/format/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap @@ -89,3 +89,12 @@ exports[`snippet: #5 [typescript] format 1`] = ` > 1 | let x6 =
>{\\"foo\\"}
; | ^" `; + +exports[`value-of-abstract-property.ts [typescript] format 1`] = ` +"Abstract property cannot have an initializer (2:3) + 1 | abstract class Foo { +> 2 | abstract prop = 3; + | ^^^^^^^^^^^^^^^^^^ + 3 | } + 4 |" +`; diff --git a/tests/format/misc/errors/typescript/value-of-abstract-property.ts b/tests/format/misc/errors/typescript/value-of-abstract-property.ts new file mode 100644 index 000000000..2347997ab --- /dev/null +++ b/tests/format/misc/errors/typescript/value-of-abstract-property.ts @@ -0,0 +1,3 @@ +abstract class Foo { + abstract prop = 3; +} diff --git a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap index 45f2edd13..faf67d5fe 100644 --- a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap @@ -60,6 +60,94 @@ class Bar { ================================================================================ `; +exports[`prettier-ignore-nested-unions.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +export type a = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + // prettier-ignore + | ( + | aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2 + ) + // baz + | baz1&baz2; + +export type b = + // foo + | foo1&foo2 + // bar + | bar1&bar2 + | ( + // prettier-ignore + | aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2 + ) + // baz + | baz1&baz2; + +=====================================output===================================== +export type a = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | ( + | aaaaaaaaaaaaa&1 + // b + | bbbbbbbbbbbbb&2 + ) + // baz + | (baz1 & baz2); + +export type b = + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + | ( + | // prettier-ignore + aaaaaaaaaaaaa&1 + // b + | (bbbbbbbbbbbbb & 2) + ) + // baz + | (baz1 & baz2); + +================================================================================ +`; + +exports[`prettier-ignore-parenthesized-type.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +type Foo = + // prettier-ignore + ( + aa + ); + +=====================================output===================================== +type Foo = + // prettier-ignore + ( + aa + ); + +================================================================================ +`; + exports[`tuple-labeled-ts.ts format 1`] = ` ====================================options===================================== parsers: ["babel-ts"] diff --git a/tests/format/typescript/union/prettier-ignore-nested-unions.ts b/tests/format/misc/typescript-babel-only/prettier-ignore-nested-unions.ts similarity index 100% rename from tests/format/typescript/union/prettier-ignore-nested-unions.ts rename to tests/format/misc/typescript-babel-only/prettier-ignore-nested-unions.ts diff --git a/tests/format/misc/typescript-babel-only/prettier-ignore-parenthesized-type.ts b/tests/format/misc/typescript-babel-only/prettier-ignore-parenthesized-type.ts new file mode 100644 index 000000000..df2685e43 --- /dev/null +++ b/tests/format/misc/typescript-babel-only/prettier-ignore-parenthesized-type.ts @@ -0,0 +1,5 @@ +type Foo = + // prettier-ignore + ( + aa + ); diff --git a/tests/format/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap index fec9b017c..d2b929a84 100644 --- a/tests/format/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap @@ -92,3 +92,23 @@ class Bar { ================================================================================ `; + +exports[`prettier-ignore-parenthesized-type.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type Foo = + // prettier-ignore + ( + aa + ); + +=====================================output===================================== +type Foo = + // prettier-ignore + aa; + +================================================================================ +`; diff --git a/tests/format/misc/typescript-only/prettier-ignore-parenthesized-type.ts b/tests/format/misc/typescript-only/prettier-ignore-parenthesized-type.ts new file mode 100644 index 000000000..df2685e43 --- /dev/null +++ b/tests/format/misc/typescript-only/prettier-ignore-parenthesized-type.ts @@ -0,0 +1,5 @@ +type Foo = + // prettier-ignore + ( + aa + ); diff --git a/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap index 3a32bd484..66fe20146 100644 --- a/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap @@ -44,9 +44,9 @@ exports[`abstractProperties.ts [babel-ts] format 1`] = ` 3 | private abstract b: 2; > 4 | static abstract c: 3; | ^ - 5 | - 6 | abstract private d = 4; - 7 | private abstract e = 5;" + 5 | abstract private ['g']; + 6 | private abstract ['h']; + 7 | static abstract ['i'];" `; exports[`abstractProperties.ts format 1`] = ` @@ -59,14 +59,9 @@ abstract class Foo { abstract private a: 1; private abstract b: 2; static abstract c: 3; - - abstract private d = 4; - private abstract e = 5; - static abstract f = 6; - - abstract private ['g'] = 4; - private abstract ['h'] = 5; - static abstract ['i'] = 6; + abstract private ['g']; + private abstract ['h']; + static abstract ['i']; } =====================================output===================================== @@ -74,50 +69,9 @@ abstract class Foo { private abstract a: 1; private abstract b: 2; static abstract c: 3; - - private abstract d = 4; - private abstract e = 5; - static abstract f = 6; - - private abstract ["g"] = 4; - private abstract ["h"] = 5; - static abstract ["i"] = 6; -} - -================================================================================ -`; - -exports[`abstractPropertiesWithBreaks.ts [babel-ts] format 1`] = ` -"Property 'foobar' cannot have an initializer because it is marked abstract. (2:29) - 1 | abstract class Foo { -> 2 | abstract private foobar = - | ^ - 3 | // comment to break - 4 | 1 + - 5 | // another comment to break" -`; - -exports[`abstractPropertiesWithBreaks.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -abstract class Foo { - abstract private foobar = - // comment to break - 1 + - // another comment to break - 2; -} - -=====================================output===================================== -abstract class Foo { - private abstract foobar = - // comment to break - 1 + - // another comment to break - 2; + private abstract ["g"]; + private abstract ["h"]; + static abstract ["i"]; } ================================================================================ diff --git a/tests/format/typescript/custom/abstract/abstractProperties.ts b/tests/format/typescript/custom/abstract/abstractProperties.ts index a533012f7..e68df8b2c 100644 --- a/tests/format/typescript/custom/abstract/abstractProperties.ts +++ b/tests/format/typescript/custom/abstract/abstractProperties.ts @@ -2,12 +2,7 @@ abstract class Foo { abstract private a: 1; private abstract b: 2; static abstract c: 3; - - abstract private d = 4; - private abstract e = 5; - static abstract f = 6; - - abstract private ['g'] = 4; - private abstract ['h'] = 5; - static abstract ['i'] = 6; + abstract private ['g']; + private abstract ['h']; + static abstract ['i']; } diff --git a/tests/format/typescript/custom/abstract/abstractPropertiesWithBreaks.ts b/tests/format/typescript/custom/abstract/abstractPropertiesWithBreaks.ts deleted file mode 100644 index d238f528e..000000000 --- a/tests/format/typescript/custom/abstract/abstractPropertiesWithBreaks.ts +++ /dev/null @@ -1,7 +0,0 @@ -abstract class Foo { - abstract private foobar = - // comment to break - 1 + - // another comment to break - 2; -} diff --git a/tests/format/typescript/union/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/union/__snapshots__/jsfmt.spec.js.snap index 3ab365a49..d623a2476 100644 --- a/tests/format/typescript/union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/union/__snapshots__/jsfmt.spec.js.snap @@ -188,72 +188,6 @@ export type a = ================================================================================ `; -exports[`prettier-ignore-nested-unions.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -export type a = - // foo - | foo1&foo2 - // bar - | bar1&bar2 - // prettier-ignore - | ( - | aaaaaaaaaaaaa&1 - // b - | bbbbbbbbbbbbb&2 - ) - // baz - | baz1&baz2; - -export type b = - // foo - | foo1&foo2 - // bar - | bar1&bar2 - | ( - // prettier-ignore - | aaaaaaaaaaaaa&1 - // b - | bbbbbbbbbbbbb&2 - ) - // baz - | baz1&baz2; - -=====================================output===================================== -export type a = - // foo - | (foo1 & foo2) - // bar - | (bar1 & bar2) - // prettier-ignore - | ( - | aaaaaaaaaaaaa&1 - // b - | bbbbbbbbbbbbb&2 - ) - // baz - | (baz1 & baz2); - -export type b = - // foo - | (foo1 & foo2) - // bar - | (bar1 & bar2) - | ( - | // prettier-ignore - aaaaaaaaaaaaa&1 - // b - | (bbbbbbbbbbbbb & 2) - ) - // baz - | (baz1 & baz2); - -================================================================================ -`; - exports[`union-parens.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/yarn.lock b/yarn.lock index 6317add7f..f373386cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1753,28 +1753,15 @@ "@typescript-eslint/types" "5.0.0" "@typescript-eslint/visitor-keys" "5.0.0" -"@typescript-eslint/types@4.32.0": - version "4.32.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.32.0.tgz#52c633c18da47aee09449144bf59565ab36df00d" - integrity sha512-LE7Z7BAv0E2UvqzogssGf1x7GPpUalgG07nGCBYb1oK4mFsOiFC/VrSMKbZQzFJdN2JL5XYmsx7C7FX9p9ns0w== - "@typescript-eslint/types@5.0.0": version "5.0.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.0.0.tgz#25d93f6d269b2d25fdc51a0407eb81ccba60eb0f" integrity sha512-dU/pKBUpehdEqYuvkojmlv0FtHuZnLXFBn16zsDmlFF3LXkOpkAQ2vrKc3BidIIve9EMH2zfTlxqw9XM0fFN5w== -"@typescript-eslint/typescript-estree@4.32.0": - version "4.32.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.32.0.tgz#db00ccc41ccedc8d7367ea3f50c6994b8efa9f3b" - integrity sha512-tRYCgJ3g1UjMw1cGG8Yn1KzOzNlQ6u1h9AmEtPhb5V5a1TmiHWcRyF/Ic+91M4f43QeChyYlVTcf3DvDTZR9vw== - dependencies: - "@typescript-eslint/types" "4.32.0" - "@typescript-eslint/visitor-keys" "4.32.0" - debug "^4.3.1" - globby "^11.0.3" - is-glob "^4.0.1" - semver "^7.3.5" - tsutils "^3.21.0" +"@typescript-eslint/types@5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.1.0.tgz#a8a75ddfc611660de6be17d3ad950302385607a9" + integrity sha512-sEwNINVxcB4ZgC6Fe6rUyMlvsB2jvVdgxjZEjQUQVlaSPMNamDOwO6/TB98kFt4sYYfNhdhTPBEQqNQZjMMswA== "@typescript-eslint/typescript-estree@5.0.0": version "5.0.0" @@ -1789,13 +1776,18 @@ semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/visitor-keys@4.32.0": - version "4.32.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.32.0.tgz#455ba8b51242f2722a497ffae29313f33b14cb7f" - integrity sha512-e7NE0qz8W+atzv3Cy9qaQ7BTLwWsm084Z0c4nIO2l3Bp6u9WIgdqCgyPyV5oSPDMIW3b20H59OOCmVk3jw3Ptw== +"@typescript-eslint/typescript-estree@5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.1.0.tgz#132aea34372df09decda961cb42457433aa6e83d" + integrity sha512-SSz+l9YrIIsW4s0ZqaEfnjl156XQ4VRmJsbA0ZE1XkXrD3cRpzuZSVCyqeCMR3EBjF27IisWakbBDGhGNIOvfQ== dependencies: - "@typescript-eslint/types" "4.32.0" - eslint-visitor-keys "^2.0.0" + "@typescript-eslint/types" "5.1.0" + "@typescript-eslint/visitor-keys" "5.1.0" + debug "^4.3.2" + globby "^11.0.4" + is-glob "^4.0.3" + semver "^7.3.5" + tsutils "^3.21.0" "@typescript-eslint/visitor-keys@5.0.0": version "5.0.0" @@ -1805,6 +1797,14 @@ "@typescript-eslint/types" "5.0.0" eslint-visitor-keys "^3.0.0" +"@typescript-eslint/visitor-keys@5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.1.0.tgz#e01a01b27eb173092705ae983aa1451bd1842630" + integrity sha512-uqNXepKBg81JVwjuqAxYrXa1Ql/YDzM+8g/pS+TCPxba0wZttl8m5DkrasbfnmJGHs4lQ2jTbcZ5azGhI7kK+w== + dependencies: + "@typescript-eslint/types" "5.1.0" + eslint-visitor-keys "^3.0.0" + "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" @@ -2751,7 +2751,7 @@ data-urls@^2.0.0: whatwg-mimetype "^2.3.0" whatwg-url "^8.0.0" -debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1: +debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b" integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw== @@ -3653,7 +3653,7 @@ globals@^13.6.0, globals@^13.9.0: dependencies: type-fest "^0.20.2" -globby@11.0.4, globby@^11.0.1, globby@^11.0.3: +globby@11.0.4, globby@^11.0.1, globby@^11.0.3, globby@^11.0.4: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg== @@ -3958,6 +3958,13 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3: dependencies: is-extglob "^2.1.1" +is-glob@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" + integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== + dependencies: + is-extglob "^2.1.1" + is-hexadecimal@^1.0.0: version "1.0.4" resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"