From 3f13d2ec1b5ef6fe90ff42fcab5d7b4f442c1128 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 3 Oct 2019 20:24:03 +0800 Subject: [PATCH] Support typescript 3.6 (#6519) --- package.json | 6 +++--- scripts/build/config.js | 6 ++++++ src/language-js/clean.js | 9 +++++++++ .../types/union/__snapshots__/jsfmt.spec.js.snap | 2 ++ .../types/union/unionTypeEquivalence.ts | 1 + yarn.lock | 15 ++++++++------- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6939e59e..8783668a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "@babel/parser": "7.2.0", "@glimmer/syntax": "0.41.0", "@iarna/toml": "2.2.3", - "@typescript-eslint/typescript-estree": "1.11.0", + "@typescript-eslint/typescript-estree": "1.13.0", "angular-estree-parser": "1.1.5", "angular-html-parser": "1.2.0", "camelcase": "5.3.1", @@ -68,7 +68,7 @@ "resolve": "1.12.0", "semver": "6.3.0", "string-width": "3.1.0", - "typescript": "3.4.1", + "typescript": "3.6.3", "unicode-regex": "3.0.0", "unified": "6.1.6", "vnopts": "1.0.2", @@ -129,7 +129,7 @@ "lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly", "lint-docs": "prettylint {.,docs,website,website/blog}/*.md", "lint-dist": "eslint --no-eslintrc --no-ignore --env=browser \"dist/!(bin-prettier|index|third-party).js\"", - "build": "node --max-old-space-size=2048 ./scripts/build/build.js", + "build": "node --max-old-space-size=3072 ./scripts/build/build.js", "build-docs": "node ./scripts/build-docs.js", "check-deps": "node ./scripts/check-deps.js" } diff --git a/scripts/build/config.js b/scripts/build/config.js index 3ce5bff4..2fb42155 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -42,6 +42,12 @@ const parsers = [ replace: { // node v4 compatibility for @typescript-eslint/typescript-estree "(!unique.includes(raw))": "(unique.indexOf(raw) === -1)" + }, + commonjs: { + ignore: [ + // Optional package for TypeScript that logs ETW events (a Windows-only technology). + "@microsoft/typescript-etw" + ] } }, { diff --git a/src/language-js/clean.js b/src/language-js/clean.js index a9c1d8ad..b058c8cf 100644 --- a/src/language-js/clean.js +++ b/src/language-js/clean.js @@ -65,6 +65,15 @@ function clean(ast, newObj, parent) { return newObj.typeAnnotation; } + // (TypeScript) Bypass `& foo` and `| foo` into `foo` + // https://github.com/microsoft/TypeScript/issues/30995 + if ( + (ast.type === "TSIntersectionType" || ast.type === "TSUnionType") && + ast.types.length === 1 + ) { + return newObj.types[0]; + } + // We convert
to
if (ast.type === "JSXOpeningElement") { delete newObj.selfClosing; diff --git a/tests/typescript/conformance/types/union/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/conformance/types/union/__snapshots__/jsfmt.spec.js.snap index e9e5c74a..1271da85 100644 --- a/tests/typescript/conformance/types/union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/conformance/types/union/__snapshots__/jsfmt.spec.js.snap @@ -469,6 +469,7 @@ printWidth: 80 class C { } class D extends C { foo() { } } var x: C; +var x: | C; var x : C | D; // A | B is equivalent to B | A. @@ -491,6 +492,7 @@ class D extends C { foo() {} } var x: C; +var x: C; var x: C | D; // A | B is equivalent to B | A. diff --git a/tests/typescript/conformance/types/union/unionTypeEquivalence.ts b/tests/typescript/conformance/types/union/unionTypeEquivalence.ts index 821eb35d..b9c78c75 100644 --- a/tests/typescript/conformance/types/union/unionTypeEquivalence.ts +++ b/tests/typescript/conformance/types/union/unionTypeEquivalence.ts @@ -2,6 +2,7 @@ class C { } class D extends C { foo() { } } var x: C; +var x: | C; var x : C | D; // A | B is equivalent to B | A. diff --git a/yarn.lock b/yarn.lock index 2d434f41..0195c948 100644 --- a/yarn.lock +++ b/yarn.lock @@ -933,10 +933,10 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/typescript-estree@1.11.0": - version "1.11.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.11.0.tgz#b7b5782aab22e4b3b6d84633652c9f41e62d37d5" - integrity sha512-fquUHF5tAx1sM2OeRCC7wVxFd1iMELWMGCzOSmJ3pLzArj9+kRixdlC4d5MncuzXpjEqc6045p3KwM0o/3FuUA== +"@typescript-eslint/typescript-estree@1.13.0": + version "1.13.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.13.0.tgz#8140f17d0f60c03619798f1d628b8434913dc32e" + integrity sha512-b5rCmd2e6DCC6tCTN9GSUAuxdYwCM/k/2wdjHGrIRGPSJotWMCe/dGpi66u42bhuh8q3QBzqM4TMA1GUUCJvdw== dependencies: lodash.unescape "4.0.1" semver "5.5.0" @@ -7184,9 +7184,10 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@3.4.1: - version "3.4.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.1.tgz#b6691be11a881ffa9a05765a205cb7383f3b63c6" +typescript@3.6.3: + version "3.6.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da" + integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw== uglify-js@^3.1.4: version "3.6.0"