From f4bcb13d4153fe48d837ea18ac026558aba5ea36 Mon Sep 17 00:00:00 2001 From: Ika Date: Thu, 4 Apr 2019 15:32:54 +0800 Subject: [PATCH] feat(typescript): support TS 3.4 (#6027) - add support for `readonly` operator - `as const` was already supported, added tests to ensure no regression --- CHANGELOG.unreleased.md | 14 ++++++++++++++ package.json | 4 ++-- .../__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ tests/typescript_cast/as-const.ts | 1 + .../__snapshots__/jsfmt.spec.js.snap | 16 ++++++++++++++++ tests/typescript_readonly/array.ts | 2 ++ yarn.lock | 16 ++++++++-------- 7 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 tests/typescript_cast/as-const.ts create mode 100644 tests/typescript_readonly/array.ts diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 2238ad04..bb4ea1b0 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -238,3 +238,17 @@ Examples: // Output (Prettier master)
``` + +- TypeScript: Support `readonly` operator ([#6027] by [@ikatyang]) + + + ```ts + // Input + declare const array: readonly number[]; + + // Output (Prettier stable) + // SyntaxError: ',' expected. + + // Output (Prettier master) + declare const array: readonly number[]; + ``` diff --git a/package.json b/package.json index 6ae32f7b..918b9a5a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "@babel/parser": "7.2.0", "@glimmer/syntax": "0.30.3", "@iarna/toml": "2.0.0", - "@typescript-eslint/typescript-estree": "1.1.0", + "@typescript-eslint/typescript-estree": "1.6.0", "angular-estree-parser": "1.1.5", "angular-html-parser": "1.2.0", "camelcase": "4.1.0", @@ -67,7 +67,7 @@ "resolve": "1.5.0", "semver": "5.4.1", "string-width": "3.0.0", - "typescript": "3.2.2", + "typescript": "3.4.1", "unicode-regex": "2.0.0", "unified": "6.1.6", "vnopts": "1.0.2", diff --git a/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap index 9f2b9b4b..3e8e28a1 100644 --- a/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_cast/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`as-const.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +let x = '123' as const; + +=====================================output===================================== +let x = "123" as const; + +================================================================================ +`; + exports[`generic-cast.ts 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript_cast/as-const.ts b/tests/typescript_cast/as-const.ts new file mode 100644 index 00000000..6abc070d --- /dev/null +++ b/tests/typescript_cast/as-const.ts @@ -0,0 +1 @@ +let x = '123' as const; diff --git a/tests/typescript_readonly/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_readonly/__snapshots__/jsfmt.spec.js.snap index 4b76105e..1c885aae 100644 --- a/tests/typescript_readonly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_readonly/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`array.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +declare const array: readonly number[]; +declare const tuple: readonly [number, number]; + +=====================================output===================================== +declare const array: readonly number[]; +declare const tuple: readonly [number, number]; + +================================================================================ +`; + exports[`readonly.ts 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript_readonly/array.ts b/tests/typescript_readonly/array.ts new file mode 100644 index 00000000..ce5fc1ce --- /dev/null +++ b/tests/typescript_readonly/array.ts @@ -0,0 +1,2 @@ +declare const array: readonly number[]; +declare const tuple: readonly [number, number]; diff --git a/yarn.lock b/yarn.lock index f942c43c..5dc16936 100644 --- a/yarn.lock +++ b/yarn.lock @@ -674,10 +674,10 @@ version "5.5.0" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-5.5.0.tgz#146c2a29ee7d3bae4bf2fcb274636e264c813c45" -"@typescript-eslint/typescript-estree@1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.1.0.tgz#31f19e7197814cb3e609f2822ad6003b6e326470" - integrity sha512-eABnKqJVv0Mm5uYon8Xw61SXldvOhWKDQdoZqsJ/YqEa9XvWV1URXdRvTOW8GLsKo4X3Un7pHKqKZhfbbUEGww== +"@typescript-eslint/typescript-estree@1.6.0": + version "1.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.6.0.tgz#6cf43a07fee08b8eb52e4513b428c8cdc9751ef0" + integrity sha512-A4CanUwfaG4oXobD5y7EXbsOHjCwn8tj1RDd820etpPAjH+Icjc2K9e/DQM1Hac5zH2BSy+u6bjvvF2wwREvYA== dependencies: lodash.unescape "4.0.1" semver "5.5.0" @@ -5784,10 +5784,10 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@3.2.2: - version "3.2.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5" - integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg== +typescript@3.4.1: + version "3.4.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.1.tgz#b6691be11a881ffa9a05765a205cb7383f3b63c6" + integrity sha512-3NSMb2VzDQm8oBTLH6Nj55VVtUEpe/rgkIzMir0qVoLyjDZlnMBva0U6vDiV3IH+sl/Yu6oP5QwsAQtHPmDd2Q== ua-parser-js@^0.7.9: version "0.7.17"