diff --git a/package.json b/package.json index 23a2dd87a3ee..13c179418346 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dependencies": { "@angular/compiler": "11.2.6", "@babel/code-frame": "7.12.13", - "@babel/parser": "7.13.10", + "@babel/parser": "7.13.11", "@glimmer/syntax": "0.77.3", "@iarna/toml": "2.2.5", "@typescript-eslint/typescript-estree": "4.16.1", diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 9a71c934a8af..c49a818e97c7 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -457,8 +457,14 @@ function printTypescript(path, options, print) { if (node.isExport) { parts.push("export "); } + + parts.push("import "); + + if (node.importKind && node.importKind !== "value") { + parts.push(node.importKind, " "); + } + parts.push( - "import ", path.call(print, "id"), " = ", path.call(print, "moduleReference") diff --git a/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap b/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap index 45f2edd1376c..61aa2f761a7e 100644 --- a/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap @@ -81,3 +81,43 @@ type T = [x: A]; ================================================================================ `; + +exports[`type-import-equals-declaration.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +import type A = require("foo"); +export import type = require("A"); + +import type +A = require("A"); + +import +type +a = require("a"); + +export import +type +B = require("B"); + +export +import +type +b = require("b"); + +=====================================output===================================== +import type A = require("foo"); +export import type = require("A"); + +import type A = require("A"); + +import type a = require("a"); + +export import type B = require("B"); + +export import type b = require("b"); + +================================================================================ +`; diff --git a/tests/misc/typescript-babel-only/type-import-equals-declaration.ts b/tests/misc/typescript-babel-only/type-import-equals-declaration.ts new file mode 100644 index 000000000000..acdf20f77610 --- /dev/null +++ b/tests/misc/typescript-babel-only/type-import-equals-declaration.ts @@ -0,0 +1,18 @@ +import type A = require("foo"); +export import type = require("A"); + +import type +A = require("A"); + +import +type +a = require("a"); + +export import +type +B = require("B"); + +export +import +type +b = require("b"); diff --git a/yarn.lock b/yarn.lock index efe20e11a249..94a6bc42f18c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -283,10 +283,10 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@7.13.10", "@babel/parser@^7.1.0", "@babel/parser@^7.12.13", "@babel/parser@^7.13.0", "@babel/parser@^7.13.10": - version "7.13.10" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.13.10.tgz#8f8f9bf7b3afa3eabd061f7a5bcdf4fec3c48409" - integrity sha512-0s7Mlrw9uTWkYua7xWr99Wpk2bnGa0ANleKfksYAES8LpWH4gW1OUr42vqKNf0us5UQNfru2wPqMqRITzq/SIQ== +"@babel/parser@7.13.11", "@babel/parser@^7.1.0", "@babel/parser@^7.12.13", "@babel/parser@^7.13.0", "@babel/parser@^7.13.10": + version "7.13.11" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.13.11.tgz#f93ebfc99d21c1772afbbaa153f47e7ce2f50b88" + integrity sha512-PhuoqeHoO9fc4ffMEVk4qb/w/s2iOSWohvbHxLtxui0eBg3Lg5gN1U8wp1V1u61hOWkPQJJyJzGH6Y+grwkq8Q== "@babel/plugin-proposal-async-generator-functions@^7.13.8": version "7.13.8"