diff --git a/package.json b/package.json index 37547a90b..b4efcf10d 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@babel/parser": "7.18.0", "@glimmer/syntax": "0.84.2", "@iarna/toml": "2.2.5", - "@typescript-eslint/typescript-estree": "5.20.0", + "@typescript-eslint/typescript-estree": "5.26.0", "acorn": "8.7.0", "acorn-jsx": "5.3.2", "angular-estree-parser": "2.5.0", @@ -82,7 +82,7 @@ "semver": "7.3.7", "string-width": "5.0.1", "strip-ansi": "7.0.1", - "typescript": "4.6.3", + "typescript": "4.7.2", "unicode-regex": "3.0.0", "unified": "9.2.1", "vnopts": "1.0.2", diff --git a/src/language-js/parse/postprocess/typescript.js b/src/language-js/parse/postprocess/typescript.js index 39a71708f..6817084ab 100644 --- a/src/language-js/parse/postprocess/typescript.js +++ b/src/language-js/parse/postprocess/typescript.js @@ -41,7 +41,7 @@ function throwErrorForInvalidDecorator( // 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 = 166; + const SYNTAX_KIND_PROPERTY_DEFINITION = 167; const SYNTAX_KIND_ABSTRACT_KEYWORD = 126; if ( tsNode.kind !== SYNTAX_KIND_PROPERTY_DEFINITION || diff --git a/src/language-js/print/type-annotation.js b/src/language-js/print/type-annotation.js index 6b8ad87f7..c7613fc31 100644 --- a/src/language-js/print/type-annotation.js +++ b/src/language-js/print/type-annotation.js @@ -311,6 +311,16 @@ function printIndexedAccessType(path, options, print) { return [print("objectType"), leftDelimiter, print("indexType"), "]"]; } +// `TSJSDocNullableType`, `TSJSDocNonNullableType` +function printJSDocType(path, print, token) { + const node = path.getValue(); + return [ + node.postfix ? "" : token, + print("typeAnnotation"), + node.postfix ? token : "", + ]; +} + module.exports = { printOpaqueType, printTypeAlias, @@ -320,4 +330,5 @@ module.exports = { printTupleType, printIndexedAccessType, shouldHugType, + printJSDocType, }; diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 1a1dad4d2..32942f2d7 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -49,6 +49,7 @@ const { printFunctionType, printTupleType, printIndexedAccessType, + printJSDocType, } = require("./type-annotation.js"); function printTypescript(path, options, print) { @@ -517,9 +518,9 @@ function printTypescript(path, options, print) { case "TSJSDocUnknownType": return "?"; case "TSJSDocNullableType": - return ["?", print("typeAnnotation")]; + return printJSDocType(path, print, /* token */ "?"); case "TSJSDocNonNullableType": - return ["!", print("typeAnnotation")]; + return printJSDocType(path, print, /* token */ "!"); case "TSInstantiationExpression": return [print("expression"), print("typeParameters")]; default: diff --git a/tests/format/typescript/error-recovery/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/error-recovery/__snapshots__/jsfmt.spec.js.snap index e70791f7c..b6d8a92f9 100644 --- a/tests/format/typescript/error-recovery/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/error-recovery/__snapshots__/jsfmt.spec.js.snap @@ -411,10 +411,10 @@ let h: !(string | number); let a: *; function b(x: ?) {} let c: ?string; -let d: ?string; +let d: string?; let e: ?(string | number); let f: !string; -let g: !string; +let g: string!; let h: !(string | number); ================================================================================ @@ -449,10 +449,10 @@ let h: !(string | number); let a: *; function b(x: ?) {} let c: ?string; -let d: ?string; +let d: string?; let e: ?(string | number); let f: !string; -let g: !string; +let g: string!; let h: !(string | number); ================================================================================ @@ -477,10 +477,10 @@ let h: !(string | number); let a: *; function b(x: ?) {} let c: ?string; -let d: ?string; +let d: string?; let e: ?(string | number); let f: !string; -let g: !string; +let g: string!; let h: !(string | number); ================================================================================ diff --git a/yarn.lock b/yarn.lock index ff035cf08..11c2f1955 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1761,6 +1761,11 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.20.0.tgz#fa39c3c2aa786568302318f1cb51fcf64258c20c" integrity sha512-+d8wprF9GyvPwtoB4CxBAR/s0rpP25XKgnOvMf/gMXYDvlUC3rPFHupdTQ/ow9vn7UDe5rX02ovGYQbv/IUCbg== +"@typescript-eslint/types@5.26.0": + version "5.26.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.26.0.tgz#cb204bb154d3c103d9cc4d225f311b08219469f3" + integrity sha512-8794JZFE1RN4XaExLWLI2oSXsVImNkl79PzTOOWt9h0UHROwJedNOD2IJyfL0NbddFllcktGIO2aOu10avQQyA== + "@typescript-eslint/typescript-estree@5.20.0": version "5.20.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.20.0.tgz#ab73686ab18c8781bbf249c9459a55dc9417d6b0" @@ -1774,6 +1779,19 @@ semver "^7.3.5" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.26.0": + version "5.26.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.26.0.tgz#16cbceedb0011c2ed4f607255f3ee1e6e43b88c3" + integrity sha512-EyGpw6eQDsfD6jIqmXP3rU5oHScZ51tL/cZgFbFBvWuCwrIptl+oueUZzSmLtxFuSOQ9vDcJIs+279gnJkfd1w== + dependencies: + "@typescript-eslint/types" "5.26.0" + "@typescript-eslint/visitor-keys" "5.26.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/utils@5.20.0", "@typescript-eslint/utils@^5.10.0": version "5.20.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.20.0.tgz#b8e959ed11eca1b2d5414e12417fd94cae3517a5" @@ -1794,6 +1812,14 @@ "@typescript-eslint/types" "5.20.0" eslint-visitor-keys "^3.0.0" +"@typescript-eslint/visitor-keys@5.26.0": + version "5.26.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.26.0.tgz#7195f756e367f789c0e83035297c45b417b57f57" + integrity sha512-wei+ffqHanYDOQgg/fS6Hcar6wAWv0CUPQ3TZzOWd2BLfgP539rb49bwua8WRAs7R6kOSLn82rfEu2ro6Llt8Q== + dependencies: + "@typescript-eslint/types" "5.26.0" + eslint-visitor-keys "^3.3.0" + abab@^2.0.3, abab@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a" @@ -2597,6 +2623,13 @@ debug@^3.2.7: dependencies: ms "^2.1.1" +debug@^4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + decimal.js@^10.2.1: version "10.3.1" resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.3.1.tgz#d8c3a444a9c6774ba60ca6ad7261c3a94fd5e783" @@ -3536,7 +3569,7 @@ globals@^13.6.0, globals@^13.9.0: dependencies: type-fest "^0.20.2" -globby@^11.0.1, globby@^11.0.4: +globby@^11.0.1, globby@^11.0.4, globby@^11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== @@ -5835,7 +5868,7 @@ semver@7.3.5: dependencies: lru-cache "^6.0.0" -semver@7.3.7, semver@^7.3.2, semver@^7.3.5, semver@^7.3.6: +semver@7.3.7, semver@^7.3.2, semver@^7.3.5, semver@^7.3.6, semver@^7.3.7: version "7.3.7" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f" integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g== @@ -6371,10 +6404,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@4.6.3: - version "4.6.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c" - integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw== +typescript@4.7.2: + version "4.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.2.tgz#1f9aa2ceb9af87cca227813b4310fff0b51593c4" + integrity sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A== unbox-primitive@^1.0.1: version "1.0.1"